[376] | 1 | #include "stdafx.h"
|
---|
| 2 |
|
---|
| 3 | #include <Source.h>
|
---|
| 4 | #include <Class.h>
|
---|
| 5 | #include <Compiler.h>
|
---|
| 6 | #include <NamespaceSupporter.h>
|
---|
| 7 |
|
---|
| 8 | #include "../common.h"
|
---|
| 9 | #ifdef _AMD64_
|
---|
[485] | 10 | #include "../../compiler_x64/opcode.h"
|
---|
[376] | 11 | #else
|
---|
[484] | 12 | #include "../../compiler_x86/opcode.h"
|
---|
[376] | 13 | #endif
|
---|
| 14 |
|
---|
| 15 |
|
---|
| 16 | class CLoopRefCheck{
|
---|
| 17 | char **names;
|
---|
| 18 | int num;
|
---|
| 19 | void init(){
|
---|
| 20 | int i;
|
---|
| 21 | for(i=0;i<num;i++){
|
---|
| 22 | free(names[i]);
|
---|
| 23 | }
|
---|
| 24 | free(names);
|
---|
| 25 | }
|
---|
| 26 | public:
|
---|
| 27 | CLoopRefCheck()
|
---|
| 28 | {
|
---|
| 29 | names=(char **)malloc(1);
|
---|
| 30 | num=0;
|
---|
| 31 | }
|
---|
| 32 | ~CLoopRefCheck()
|
---|
| 33 | {
|
---|
| 34 | init();
|
---|
| 35 | }
|
---|
| 36 | void add(const char *lpszInheritsClass)
|
---|
| 37 | {
|
---|
| 38 | names=(char **)realloc(names,(num+1)*sizeof(char *));
|
---|
| 39 | names[num]=(char *)malloc(lstrlen(lpszInheritsClass)+1);
|
---|
| 40 | lstrcpy(names[num],lpszInheritsClass);
|
---|
| 41 | num++;
|
---|
| 42 | }
|
---|
| 43 | void del(const char *lpszInheritsClass)
|
---|
| 44 | {
|
---|
| 45 | int i;
|
---|
| 46 | for(i=0;i<num;i++){
|
---|
| 47 | if(lstrcmp(names[i],lpszInheritsClass)==0){
|
---|
| 48 | free(names[i]);
|
---|
| 49 | break;
|
---|
| 50 | }
|
---|
| 51 | }
|
---|
| 52 | if(i!=num){
|
---|
| 53 | num--;
|
---|
| 54 | for(;i<num;i++){
|
---|
| 55 | names[i]=names[i+1];
|
---|
| 56 | }
|
---|
| 57 | }
|
---|
| 58 | }
|
---|
| 59 | BOOL check(const CClass &inheritsClass) const
|
---|
| 60 | {
|
---|
| 61 | //ループ継承チェック
|
---|
| 62 | int i;
|
---|
| 63 | for(i=0;i<num;i++){
|
---|
| 64 | if( inheritsClass.GetName() == names[i] ){
|
---|
| 65 | return 1;
|
---|
| 66 | }
|
---|
| 67 | }
|
---|
| 68 | return 0;
|
---|
| 69 | }
|
---|
| 70 | };
|
---|
| 71 | CLoopRefCheck *pobj_LoopRefCheck;
|
---|
| 72 |
|
---|
| 73 |
|
---|
| 74 | void Classes::CollectClassesForNameOnly( const BasicSource &source )
|
---|
| 75 | {
|
---|
| 76 | int i, i2;
|
---|
| 77 | char temporary[VN_SIZE];
|
---|
| 78 |
|
---|
| 79 | // 名前空間管理
|
---|
| 80 | NamespaceScopes &namespaceScopes = compiler.GetNamespaceSupporter().GetLivingNamespaceScopes();
|
---|
| 81 | namespaceScopes.clear();
|
---|
| 82 |
|
---|
| 83 | // Importsされた名前空間の管理
|
---|
| 84 | NamespaceScopesCollection &importedNamespaces = compiler.GetNamespaceSupporter().GetImportedNamespaces();
|
---|
| 85 | importedNamespaces.clear();
|
---|
| 86 |
|
---|
| 87 | for(i=0;;i++){
|
---|
| 88 | if(source[i]=='\0') break;
|
---|
| 89 |
|
---|
| 90 | if( source[i] == 1 && source[i+1] == ESC_NAMESPACE ){
|
---|
| 91 | for(i+=2,i2=0;;i2++,i++){
|
---|
| 92 | if( IsCommandDelimitation( source[i] ) ){
|
---|
| 93 | temporary[i2]=0;
|
---|
| 94 | break;
|
---|
| 95 | }
|
---|
| 96 | temporary[i2]=source[i];
|
---|
| 97 | }
|
---|
| 98 | namespaceScopes.push_back( temporary );
|
---|
| 99 |
|
---|
| 100 | continue;
|
---|
| 101 | }
|
---|
| 102 | else if( source[i] == 1 && source[i+1] == ESC_ENDNAMESPACE ){
|
---|
| 103 | if( namespaceScopes.size() <= 0 ){
|
---|
[465] | 104 | compiler.errorMessenger.Output(12, "End Namespace", i );
|
---|
[376] | 105 | }
|
---|
| 106 | else{
|
---|
| 107 | namespaceScopes.pop_back();
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | i += 2;
|
---|
| 111 | continue;
|
---|
| 112 | }
|
---|
| 113 | else if( source[i] == 1 && source[i+1] == ESC_IMPORTS ){
|
---|
| 114 | for(i+=2,i2=0;;i2++,i++){
|
---|
| 115 | if( IsCommandDelimitation( source[i] ) ){
|
---|
| 116 | temporary[i2]=0;
|
---|
| 117 | break;
|
---|
| 118 | }
|
---|
| 119 | temporary[i2]=source[i];
|
---|
| 120 | }
|
---|
| 121 | if( !compiler.GetNamespaceSupporter().ImportsNamespace( temporary ) )
|
---|
| 122 | {
|
---|
[465] | 123 | compiler.errorMessenger.Output(64,temporary,i );
|
---|
[376] | 124 | }
|
---|
| 125 |
|
---|
| 126 | continue;
|
---|
| 127 | }
|
---|
| 128 | else if( source[i] == 1 && source[i+1] == ESC_CLEARNAMESPACEIMPORTED ){
|
---|
| 129 | importedNamespaces.clear();
|
---|
| 130 | continue;
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | if(source[i]==1&&(
|
---|
| 134 | source[i+1]==ESC_CLASS||
|
---|
| 135 | source[i+1]==ESC_TYPE||
|
---|
| 136 | source[i+1]==ESC_INTERFACE
|
---|
| 137 | ))
|
---|
| 138 | {
|
---|
| 139 | int nowLine = i;
|
---|
| 140 | i += 2;
|
---|
| 141 |
|
---|
| 142 | Type blittableType;
|
---|
| 143 | if(memicmp(source.GetBuffer()+i,"Align(",6)==0){
|
---|
| 144 | //アラインメント修飾子
|
---|
| 145 | i+=6;
|
---|
| 146 | i=JumpStringInPare(source.GetBuffer(),i)+1;
|
---|
| 147 | }
|
---|
| 148 | else if( memicmp( source.GetBuffer() + i, "Blittable(", 10 ) == 0 ){
|
---|
| 149 | // Blittable修飾子
|
---|
| 150 | i+=10;
|
---|
| 151 | i+=GetStringInPare_RemovePare(temporary,source.GetBuffer()+i)+1;
|
---|
| 152 | compiler.StringToType( temporary, blittableType );
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 | bool isEnum = false;
|
---|
| 156 | bool isDelegate = false;
|
---|
| 157 | if( source[i] == 1 && source[i+1] == ESC_ENUM ){
|
---|
| 158 | // 列挙型の場合
|
---|
| 159 | isEnum = true;
|
---|
| 160 |
|
---|
| 161 | i += 2;
|
---|
| 162 | }
|
---|
| 163 | else if( source[i] == 1 && source[i+1] == ESC_DELEGATE )
|
---|
| 164 | {
|
---|
| 165 | // デリゲートの場合
|
---|
| 166 | isDelegate = true;
|
---|
| 167 |
|
---|
| 168 | i += 2;
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 | for(i2=0;;i++,i2++){
|
---|
| 172 | if(!IsVariableChar(source[i])){
|
---|
| 173 | temporary[i2]=0;
|
---|
| 174 | break;
|
---|
| 175 | }
|
---|
| 176 | temporary[i2]=source[i];
|
---|
| 177 | }
|
---|
| 178 |
|
---|
| 179 | //クラスを追加
|
---|
| 180 | CClass *pClass = this->Add(namespaceScopes, importedNamespaces, temporary,nowLine);
|
---|
| 181 | if( pClass ){
|
---|
| 182 | if( source[nowLine+1] == ESC_CLASS ){
|
---|
| 183 | if( isEnum )
|
---|
| 184 | {
|
---|
| 185 | pClass->SetClassType( CClass::Enum );
|
---|
| 186 | }
|
---|
| 187 | else if( isDelegate )
|
---|
| 188 | {
|
---|
| 189 | pClass->SetClassType( CClass::Delegate );
|
---|
| 190 | }
|
---|
| 191 | else{
|
---|
| 192 | pClass->SetClassType( CClass::Class );
|
---|
| 193 | }
|
---|
| 194 | }
|
---|
| 195 | else if( source[nowLine+1] == ESC_INTERFACE ){
|
---|
| 196 | pClass->SetClassType( CClass::Interface );
|
---|
| 197 | }
|
---|
| 198 | else{
|
---|
| 199 | pClass->SetClassType( CClass::Structure );
|
---|
| 200 | }
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | // Blittable型の場合
|
---|
| 204 | if( !blittableType.IsNull() ){
|
---|
| 205 | pClass->SetBlittableType( blittableType );
|
---|
| 206 |
|
---|
| 207 | // Blittable型として登録
|
---|
| 208 | compiler.GetObjectModule().meta.GetBlittableTypes().push_back( BlittableType( blittableType, pClass ) );
|
---|
| 209 | }
|
---|
| 210 | }
|
---|
| 211 | }
|
---|
| 212 | }
|
---|
| 213 |
|
---|
| 214 | bool Classes::MemberVar_LoopRefCheck(const CClass &objClass){
|
---|
[409] | 215 | if( objClass.HasSuperClass() )
|
---|
| 216 | {
|
---|
| 217 | // 基底クラスをチェック
|
---|
| 218 | if( MemberVar_LoopRefCheck( objClass.GetSuperClass() ) == false )
|
---|
| 219 | {
|
---|
| 220 | return false;
|
---|
| 221 | }
|
---|
| 222 | }
|
---|
| 223 |
|
---|
[376] | 224 | bool result = true;
|
---|
| 225 | BOOST_FOREACH( CMember *pMember, objClass.GetDynamicMembers() ){
|
---|
| 226 | if(pMember->GetType().IsStruct()){
|
---|
| 227 | //循環参照でないかをチェック
|
---|
| 228 | if(pobj_LoopRefCheck->check(pMember->GetType().GetClass())){
|
---|
| 229 | extern int cp;
|
---|
[465] | 230 | compiler.errorMessenger.Output(124,pMember->GetType().GetClass().GetName(),cp);
|
---|
[376] | 231 | return false;
|
---|
| 232 | }
|
---|
| 233 |
|
---|
| 234 | pobj_LoopRefCheck->add(objClass.GetName().c_str());
|
---|
| 235 |
|
---|
| 236 | bool tempResult = MemberVar_LoopRefCheck(pMember->GetType().GetClass());
|
---|
| 237 | if( result )
|
---|
| 238 | {
|
---|
| 239 | result = tempResult;
|
---|
| 240 | }
|
---|
| 241 |
|
---|
| 242 | pobj_LoopRefCheck->del(objClass.GetName().c_str());
|
---|
| 243 | }
|
---|
| 244 | }
|
---|
| 245 |
|
---|
| 246 | return result;
|
---|
| 247 | }
|
---|
| 248 |
|
---|
| 249 | void Classes::GetClass_recur(const char *lpszInheritsClass){
|
---|
| 250 | extern char *basbuf;
|
---|
| 251 | int i,i2,i3,sub_address,top_pos;
|
---|
| 252 | char temporary[8192];
|
---|
| 253 |
|
---|
| 254 | // 名前空間管理
|
---|
| 255 | NamespaceScopes backupNamespaceScopes = compiler.GetNamespaceSupporter().GetLivingNamespaceScopes();
|
---|
| 256 | NamespaceScopes &namespaceScopes = compiler.GetNamespaceSupporter().GetLivingNamespaceScopes();
|
---|
| 257 | namespaceScopes.clear();
|
---|
| 258 |
|
---|
| 259 | // Importsされた名前空間の管理
|
---|
| 260 | NamespaceScopesCollection backupImportedNamespaces = compiler.GetNamespaceSupporter().GetImportedNamespaces();
|
---|
| 261 | compiler.GetNamespaceSupporter().GetImportedNamespaces().clear();
|
---|
| 262 |
|
---|
| 263 | // 呼び出し元でコンパイル中のクラスポインタをバックアップ
|
---|
| 264 | const CClass *pBackCompilingClass = compiler.pCompilingClass;
|
---|
| 265 |
|
---|
| 266 | for(i=0;;i++){
|
---|
| 267 | if(basbuf[i]=='\0') break;
|
---|
| 268 |
|
---|
| 269 |
|
---|
| 270 | // 名前空間
|
---|
| 271 | if( basbuf[i] == 1 && basbuf[i+1] == ESC_NAMESPACE ){
|
---|
| 272 | for(i+=2,i2=0;;i2++,i++){
|
---|
| 273 | if( IsCommandDelimitation( basbuf[i] ) ){
|
---|
| 274 | temporary[i2]=0;
|
---|
| 275 | break;
|
---|
| 276 | }
|
---|
| 277 | temporary[i2]=basbuf[i];
|
---|
| 278 | }
|
---|
| 279 | namespaceScopes.push_back( temporary );
|
---|
| 280 |
|
---|
| 281 | continue;
|
---|
| 282 | }
|
---|
| 283 | else if( basbuf[i] == 1 && basbuf[i+1] == ESC_ENDNAMESPACE ){
|
---|
| 284 | if( namespaceScopes.size() <= 0 ){
|
---|
[465] | 285 | compiler.errorMessenger.Output(12, "End Namespace", i );
|
---|
[376] | 286 | }
|
---|
| 287 | else{
|
---|
| 288 | namespaceScopes.pop_back();
|
---|
| 289 | }
|
---|
| 290 |
|
---|
| 291 | i += 2;
|
---|
| 292 | continue;
|
---|
| 293 | }
|
---|
| 294 |
|
---|
| 295 | else if( basbuf[i] == 1 && basbuf[i+1] == ESC_IMPORTS ){
|
---|
| 296 | for(i+=2,i2=0;;i2++,i++){
|
---|
| 297 | if( IsCommandDelimitation( basbuf[i] ) ){
|
---|
| 298 | temporary[i2]=0;
|
---|
| 299 | break;
|
---|
| 300 | }
|
---|
| 301 | temporary[i2]=basbuf[i];
|
---|
| 302 | }
|
---|
| 303 | if( !compiler.GetNamespaceSupporter().ImportsNamespace( temporary ) )
|
---|
| 304 | {
|
---|
[465] | 305 | compiler.errorMessenger.Output(64,temporary,i );
|
---|
[376] | 306 | }
|
---|
| 307 |
|
---|
| 308 | continue;
|
---|
| 309 | }
|
---|
| 310 | else if( basbuf[i] == 1 && basbuf[i+1] == ESC_CLEARNAMESPACEIMPORTED ){
|
---|
| 311 | compiler.GetNamespaceSupporter().GetImportedNamespaces().clear();
|
---|
| 312 | continue;
|
---|
| 313 | }
|
---|
| 314 |
|
---|
| 315 |
|
---|
| 316 |
|
---|
| 317 | if(basbuf[i]==1&&basbuf[i+1]==ESC_INTERFACE){
|
---|
| 318 | //////////////////////////
|
---|
| 319 | // インターフェイス
|
---|
| 320 | //////////////////////////
|
---|
| 321 |
|
---|
| 322 | top_pos=i;
|
---|
| 323 |
|
---|
| 324 | i+=2;
|
---|
| 325 |
|
---|
| 326 | //インターフェイス名を取得
|
---|
| 327 | GetCommandToken( temporary, basbuf, i );
|
---|
| 328 |
|
---|
| 329 | char className[VN_SIZE];
|
---|
| 330 | Jenga::Common::Strings typeParameters;
|
---|
[424] | 331 | Jenga::Common::Strings typeParameterBaseClassNames;
|
---|
| 332 | SplitGenericClassInstance( temporary, className, typeParameters, true, &typeParameterBaseClassNames );
|
---|
[376] | 333 |
|
---|
[378] | 334 | CClass *pobj_c = const_cast<CClass *>( this->Find(namespaceScopes, className) );
|
---|
[376] | 335 | if(!pobj_c) continue;
|
---|
| 336 |
|
---|
[379] | 337 | compiler.pCompilingClass = pobj_c;
|
---|
| 338 |
|
---|
[376] | 339 | if(lpszInheritsClass){
|
---|
| 340 | if(lstrcmp(lpszInheritsClass,pobj_c->GetName().c_str())!=0){
|
---|
| 341 | //継承先先読み用
|
---|
| 342 | continue;
|
---|
| 343 | }
|
---|
| 344 | }
|
---|
| 345 |
|
---|
| 346 | if(pobj_c->IsReady()){
|
---|
| 347 | //既に先読みされているとき
|
---|
| 348 | continue;
|
---|
| 349 | }
|
---|
| 350 |
|
---|
| 351 | /////////////////////////////////////////////////////////
|
---|
| 352 | // ☆★☆ ジェネリクスサポート ☆★☆
|
---|
[424] | 353 | for( i2=0; i2<static_cast<int>(typeParameters.size()); i2++ )
|
---|
[376] | 354 | {
|
---|
[424] | 355 | Type baseType( DEF_OBJECT, *GetObjectClassPtr() );
|
---|
| 356 | if( typeParameterBaseClassNames[i2].size() )
|
---|
| 357 | {
|
---|
| 358 | if( !compiler.StringToType( typeParameterBaseClassNames[i2], baseType ) )
|
---|
| 359 | {
|
---|
[465] | 360 | compiler.errorMessenger.Output(106,typeParameterBaseClassNames[i2],i);
|
---|
[424] | 361 | }
|
---|
| 362 | else if( !baseType.IsObject() )
|
---|
| 363 | {
|
---|
[465] | 364 | compiler.errorMessenger.Output(106,typeParameterBaseClassNames[i2],i);
|
---|
[424] | 365 | }
|
---|
| 366 | }
|
---|
| 367 |
|
---|
| 368 | pobj_c->AddFormalGenericType( GenericType( typeParameters[i2], baseType ) );
|
---|
[376] | 369 | }
|
---|
| 370 | /////////////////////////////////////////////////////////
|
---|
| 371 |
|
---|
| 372 | pobj_c->Readed();
|
---|
| 373 |
|
---|
| 374 | pobj_c->SetConstructorMemberSubIndex( -1 );
|
---|
| 375 | pobj_c->SetDestructorMemberSubIndex( -1 );
|
---|
| 376 |
|
---|
| 377 | if( memcmp( basbuf+i+1, "__COM", 5 ) == 0 && IsCommandDelimitation( basbuf[i+1+5] ) )
|
---|
| 378 | {
|
---|
| 379 | // COMインターフェイス
|
---|
| 380 | pobj_c->SetClassType( CClass::ComInterface );
|
---|
| 381 |
|
---|
| 382 | i += 6;
|
---|
| 383 | }
|
---|
| 384 |
|
---|
| 385 | if(basbuf[i+1]==1&&basbuf[i+2]==ESC_INHERITS){
|
---|
| 386 | //継承を行う場合
|
---|
| 387 | for(i+=3,i2=0;;i++,i2++){
|
---|
| 388 | if(IsCommandDelimitation(basbuf[i])){
|
---|
| 389 | temporary[i2]=0;
|
---|
| 390 | break;
|
---|
| 391 | }
|
---|
| 392 | temporary[i2]=basbuf[i];
|
---|
| 393 | }
|
---|
| 394 |
|
---|
| 395 | if(lstrcmpi(temporary,pobj_c->GetName().c_str())==0){
|
---|
[465] | 396 | compiler.errorMessenger.Output(105,temporary,i);
|
---|
[376] | 397 | goto Interface_InheritsError;
|
---|
| 398 | }
|
---|
| 399 |
|
---|
| 400 | //継承元クラスを取得
|
---|
| 401 | const Classes &classes = *this;
|
---|
| 402 | const CClass *pInheritsClass = classes.Find(temporary);
|
---|
| 403 | if( !pInheritsClass ){
|
---|
[465] | 404 | compiler.errorMessenger.Output(106,temporary,i);
|
---|
[376] | 405 | goto Interface_InheritsError;
|
---|
| 406 | }
|
---|
| 407 |
|
---|
| 408 | //継承させる
|
---|
| 409 | if( !pobj_c->InheritsClass( *pInheritsClass, Types(), i ) ){
|
---|
| 410 | goto Interface_InheritsError;
|
---|
| 411 | }
|
---|
| 412 | }
|
---|
| 413 | else{
|
---|
| 414 | //継承無し
|
---|
| 415 | if( &pobj_c->GetSuperClass() || pobj_c->GetVtblNum() )
|
---|
| 416 | {
|
---|
| 417 | // TODO: ここに来ないことが実証できたらこの分岐は消す
|
---|
| 418 | Jenga::Throw( "GetClass_recur内の例外" );
|
---|
| 419 | }
|
---|
| 420 | }
|
---|
| 421 | Interface_InheritsError:
|
---|
| 422 |
|
---|
| 423 | //メンバ変数、関数を取得
|
---|
| 424 | while(1){
|
---|
| 425 | i++;
|
---|
| 426 |
|
---|
| 427 | //エラー
|
---|
| 428 | if(basbuf[i]==1&&(basbuf[i+1]==ESC_CLASS||basbuf[i+1]==ESC_TYPE||basbuf[i+1]==ESC_INTERFACE)){
|
---|
[465] | 429 | compiler.errorMessenger.Output(22,"Interface",i);
|
---|
[376] | 430 | i--;
|
---|
| 431 | break;
|
---|
| 432 | }
|
---|
| 433 |
|
---|
| 434 | if(basbuf[i]==1&&basbuf[i+1]==ESC_INHERITS){
|
---|
[465] | 435 | compiler.errorMessenger.Output(111,NULL,i);
|
---|
[376] | 436 | break;
|
---|
| 437 | }
|
---|
| 438 | else if( basbuf[i] == 1 && basbuf[i+1] == ESC_IMPLEMENTS )
|
---|
| 439 | {
|
---|
[465] | 440 | compiler.errorMessenger.Output(137, NULL, i );
|
---|
[376] | 441 | break;
|
---|
| 442 | }
|
---|
| 443 |
|
---|
| 444 | sub_address=i;
|
---|
| 445 |
|
---|
| 446 | for(i2=0;;i++,i2++){
|
---|
| 447 | if(IsCommandDelimitation(basbuf[i])){
|
---|
| 448 | temporary[i2]=0;
|
---|
| 449 | break;
|
---|
| 450 | }
|
---|
| 451 | temporary[i2]=basbuf[i];
|
---|
| 452 | }
|
---|
| 453 | if(temporary[0]=='\0'){
|
---|
| 454 | if(basbuf[i]=='\0'){
|
---|
| 455 | i--;
|
---|
[465] | 456 | compiler.errorMessenger.Output(22,"Interface",top_pos);
|
---|
[376] | 457 | break;
|
---|
| 458 | }
|
---|
| 459 | continue;
|
---|
| 460 | }
|
---|
| 461 |
|
---|
| 462 | //End Interface記述の場合
|
---|
| 463 | if(temporary[0]==1&&temporary[1]==ESC_ENDINTERFACE) break;
|
---|
| 464 |
|
---|
| 465 | if(!(temporary[0]==1&&(
|
---|
| 466 | temporary[1]==ESC_SUB||temporary[1]==ESC_FUNCTION
|
---|
| 467 | ))){
|
---|
[465] | 468 | compiler.errorMessenger.Output(1,NULL,i);
|
---|
[376] | 469 | break;
|
---|
| 470 | }
|
---|
| 471 |
|
---|
| 472 | //メンバ関数を追加
|
---|
| 473 | pobj_c->AddMethod(pobj_c,
|
---|
| 474 | Prototype::Public, //Publicアクセス権
|
---|
| 475 | 0, // bStatic
|
---|
| 476 | false, // isConst
|
---|
| 477 | true, // isAbstract
|
---|
| 478 | true, // isVirtual
|
---|
| 479 | false, // isOverride
|
---|
| 480 | false, // isAutoGeneration
|
---|
| 481 | temporary,
|
---|
| 482 | sub_address
|
---|
| 483 | );
|
---|
| 484 | }
|
---|
| 485 | }
|
---|
| 486 |
|
---|
| 487 | if(basbuf[i]==1&&(basbuf[i+1]==ESC_CLASS||basbuf[i+1]==ESC_TYPE)){
|
---|
| 488 | //////////////////////////
|
---|
| 489 | // クラス
|
---|
| 490 | //////////////////////////
|
---|
| 491 |
|
---|
| 492 | top_pos=i;
|
---|
| 493 |
|
---|
| 494 | const DWORD dwClassType=basbuf[i+1];
|
---|
| 495 |
|
---|
| 496 | i+=2;
|
---|
| 497 |
|
---|
| 498 | int iAlign=0;
|
---|
| 499 | if(memicmp(basbuf+i,"Align(",6)==0){
|
---|
| 500 | //アラインメント修飾子
|
---|
| 501 | i+=6;
|
---|
| 502 | i+=GetStringInPare_RemovePare(temporary,basbuf+i)+1;
|
---|
| 503 | iAlign=atoi(temporary);
|
---|
| 504 |
|
---|
[409] | 505 | if( dwClassType != ESC_TYPE )
|
---|
| 506 | {
|
---|
[465] | 507 | compiler.errorMessenger.Output(140,NULL,i);
|
---|
[409] | 508 | }
|
---|
| 509 |
|
---|
[376] | 510 | if(!(iAlign==1||iAlign==2||iAlign==4||iAlign==8||iAlign==16))
|
---|
[465] | 511 | compiler.errorMessenger.Output(51,NULL,i);
|
---|
[376] | 512 | }
|
---|
| 513 | else if( memicmp( basbuf + i, "Blittable(", 10 ) == 0 ){
|
---|
| 514 | // Blittable修飾子
|
---|
| 515 | i+=10;
|
---|
| 516 | i=JumpStringInPare(basbuf,i)+1;
|
---|
[409] | 517 |
|
---|
| 518 | if( dwClassType != ESC_CLASS )
|
---|
| 519 | {
|
---|
[465] | 520 | compiler.errorMessenger.Output(141,NULL,i);
|
---|
[409] | 521 | }
|
---|
[376] | 522 | }
|
---|
| 523 |
|
---|
| 524 | if( basbuf[i] == 1 && basbuf[i+1] == ESC_ENUM )
|
---|
| 525 | {
|
---|
| 526 | // 列挙型の場合
|
---|
| 527 | i += 2;
|
---|
| 528 | }
|
---|
| 529 | else if( basbuf[i] == 1 && basbuf[i+1] == ESC_DELEGATE )
|
---|
| 530 | {
|
---|
| 531 | // デリゲートの場合
|
---|
| 532 | i += 2;
|
---|
| 533 | }
|
---|
| 534 |
|
---|
| 535 | //クラス名を取得
|
---|
| 536 | GetCommandToken( temporary, basbuf, i );
|
---|
| 537 |
|
---|
| 538 | char className[VN_SIZE];
|
---|
| 539 | Jenga::Common::Strings typeParameters;
|
---|
[424] | 540 | Jenga::Common::Strings typeParameterBaseClassNames;
|
---|
| 541 | SplitGenericClassInstance( temporary, className, typeParameters, true, &typeParameterBaseClassNames );
|
---|
[376] | 542 |
|
---|
| 543 | CClass *pobj_c = const_cast<CClass *>( this->Find(namespaceScopes, className) );
|
---|
| 544 | if(!pobj_c) continue;
|
---|
| 545 |
|
---|
| 546 | compiler.pCompilingClass = pobj_c;
|
---|
| 547 |
|
---|
| 548 | if(lpszInheritsClass){
|
---|
| 549 | if( pobj_c->GetName() != lpszInheritsClass ){
|
---|
| 550 | //継承先先読み用
|
---|
| 551 | continue;
|
---|
| 552 | }
|
---|
| 553 | }
|
---|
| 554 |
|
---|
| 555 | if(pobj_c->IsReady()){
|
---|
| 556 | //既に先読みされているとき
|
---|
| 557 | continue;
|
---|
| 558 | }
|
---|
| 559 |
|
---|
| 560 |
|
---|
| 561 | /////////////////////////////////////////////////////////
|
---|
| 562 | // ☆★☆ ジェネリクスサポート ☆★☆
|
---|
[424] | 563 | for( i2=0; i2<static_cast<int>(typeParameters.size()); i2++ )
|
---|
[376] | 564 | {
|
---|
[424] | 565 | Type baseType( DEF_OBJECT, *GetObjectClassPtr() );
|
---|
| 566 | if( typeParameterBaseClassNames[i2].size() )
|
---|
| 567 | {
|
---|
| 568 | if( !compiler.StringToType( typeParameterBaseClassNames[i2], baseType ) )
|
---|
| 569 | {
|
---|
[465] | 570 | compiler.errorMessenger.Output(106,typeParameterBaseClassNames[i2],i);
|
---|
[424] | 571 | }
|
---|
| 572 | else if( !baseType.IsObject() )
|
---|
| 573 | {
|
---|
[465] | 574 | compiler.errorMessenger.Output(106,typeParameterBaseClassNames[i2],i);
|
---|
[424] | 575 | }
|
---|
| 576 | }
|
---|
| 577 |
|
---|
| 578 | pobj_c->AddFormalGenericType( GenericType( typeParameters[i2], baseType ) );
|
---|
[376] | 579 | }
|
---|
| 580 | /////////////////////////////////////////////////////////
|
---|
| 581 |
|
---|
| 582 |
|
---|
| 583 | pobj_c->SetFixedAlignment( iAlign );
|
---|
| 584 |
|
---|
| 585 | pobj_c->Readed();
|
---|
| 586 |
|
---|
| 587 | pobj_c->SetConstructorMemberSubIndex( -1 );
|
---|
| 588 | pobj_c->SetDestructorMemberSubIndex( -1 );
|
---|
| 589 |
|
---|
| 590 | //アクセス制限の初期値をセット
|
---|
| 591 | Prototype::Accessibility accessibility;
|
---|
| 592 | if(dwClassType==ESC_CLASS){
|
---|
| 593 | accessibility = Prototype::Private;
|
---|
| 594 | }
|
---|
| 595 | else{
|
---|
| 596 | accessibility = Prototype::Public;
|
---|
| 597 | }
|
---|
| 598 |
|
---|
| 599 | if( pobj_c->GetName() == "Object"
|
---|
| 600 | || dwClassType == ESC_TYPE )
|
---|
| 601 | {
|
---|
| 602 | // 何も継承しない
|
---|
| 603 |
|
---|
| 604 | if( &pobj_c->GetSuperClass() || pobj_c->GetVtblNum() )
|
---|
| 605 | {
|
---|
| 606 | // TODO: ここに来ないことが実証できたらこの分岐は消す
|
---|
| 607 | Jenga::Throw( "GetClass_recur内の例外" );
|
---|
| 608 | }
|
---|
| 609 | }
|
---|
| 610 | else{
|
---|
| 611 | if(basbuf[i+1]==1&&basbuf[i+2]==ESC_INHERITS)
|
---|
| 612 | {
|
---|
| 613 | // クラス継承先が指定されているとき
|
---|
| 614 | i += 3;
|
---|
| 615 | GetCommandToken( temporary, basbuf, i );
|
---|
| 616 |
|
---|
| 617 | if(lstrcmpi(temporary,pobj_c->GetName().c_str())==0){
|
---|
[465] | 618 | compiler.errorMessenger.Output(105,temporary,i);
|
---|
[376] | 619 | goto InheritsError;
|
---|
| 620 | }
|
---|
| 621 | }
|
---|
| 622 | else
|
---|
| 623 | {
|
---|
| 624 | // 何の指定もないときはObjectクラスを継承する
|
---|
| 625 | lstrcpy( temporary, "Object" );
|
---|
| 626 | }
|
---|
| 627 | pobj_c->Inherits( temporary, i );
|
---|
| 628 |
|
---|
| 629 | if( basbuf[i+1] == 1 && basbuf[i+2] == ESC_IMPLEMENTS )
|
---|
| 630 | {
|
---|
| 631 | // インターフェイス実装を行う場合
|
---|
| 632 | i += 3;
|
---|
| 633 | GetCommandToken( temporary, basbuf, i );
|
---|
| 634 |
|
---|
| 635 | pobj_c->Implements( temporary, i );
|
---|
| 636 | }
|
---|
| 637 | }
|
---|
| 638 | InheritsError:
|
---|
| 639 |
|
---|
| 640 | //メンバとメソッドを取得
|
---|
| 641 | while(1){
|
---|
| 642 | i++;
|
---|
| 643 |
|
---|
| 644 | //エラー
|
---|
| 645 | if(basbuf[i]==1&&(basbuf[i+1]==ESC_CLASS||basbuf[i+1]==ESC_TYPE)){
|
---|
[465] | 646 | compiler.errorMessenger.Output(22,"Class",i);
|
---|
[376] | 647 | i--;
|
---|
| 648 | break;
|
---|
| 649 | }
|
---|
| 650 |
|
---|
| 651 | if(basbuf[i]==1&&basbuf[i+1]==ESC_INHERITS){
|
---|
[465] | 652 | compiler.errorMessenger.Output(111,NULL,i);
|
---|
[376] | 653 | break;
|
---|
| 654 | }
|
---|
| 655 | else if( basbuf[i] == 1 && basbuf[i+1] == ESC_IMPLEMENTS )
|
---|
| 656 | {
|
---|
[465] | 657 | compiler.errorMessenger.Output(137, NULL, i );
|
---|
[376] | 658 | break;
|
---|
| 659 | }
|
---|
| 660 |
|
---|
| 661 | //Static修飾子
|
---|
| 662 | BOOL bStatic;
|
---|
| 663 | if(basbuf[i]==1&&basbuf[i+1]==ESC_STATIC){
|
---|
| 664 | bStatic=1;
|
---|
| 665 | i+=2;
|
---|
| 666 | }
|
---|
| 667 | else bStatic=0;
|
---|
| 668 |
|
---|
| 669 | //Const修飾子
|
---|
| 670 | bool isConst = false;
|
---|
| 671 | if( basbuf[i] == 1 && basbuf[i + 1] == ESC_CONST ){
|
---|
| 672 | isConst = true;
|
---|
| 673 | i += 2;
|
---|
| 674 | }
|
---|
| 675 |
|
---|
| 676 | if(basbuf[i]==1&&(
|
---|
| 677 | basbuf[i+1]==ESC_ABSTRACT||basbuf[i+1]==ESC_VIRTUAL||basbuf[i+1]==ESC_OVERRIDE||
|
---|
| 678 | basbuf[i+1]==ESC_SUB||basbuf[i+1]==ESC_FUNCTION
|
---|
| 679 | )){
|
---|
| 680 | i3=basbuf[i+1];
|
---|
| 681 | sub_address=i;
|
---|
| 682 | }
|
---|
| 683 | else i3=0;
|
---|
| 684 |
|
---|
| 685 | bool isVirtual = false, isAbstract = false, isOverride = false;
|
---|
| 686 | if(i3==ESC_ABSTRACT){
|
---|
| 687 | isAbstract=1;
|
---|
| 688 | isVirtual=1;
|
---|
| 689 | i+=2;
|
---|
| 690 |
|
---|
| 691 | i3=basbuf[i+1];
|
---|
| 692 | }
|
---|
| 693 | else if(i3==ESC_VIRTUAL){
|
---|
| 694 | isAbstract=0;
|
---|
| 695 | isVirtual=1;
|
---|
| 696 | i+=2;
|
---|
| 697 |
|
---|
| 698 | i3=basbuf[i+1];
|
---|
| 699 | }
|
---|
| 700 | else if(i3==ESC_OVERRIDE){
|
---|
| 701 | isOverride=1;
|
---|
| 702 | isVirtual=1;
|
---|
| 703 |
|
---|
| 704 | i+=2;
|
---|
| 705 |
|
---|
| 706 | i3=basbuf[i+1];
|
---|
| 707 | }
|
---|
| 708 |
|
---|
| 709 | for(i2=0;;i++,i2++){
|
---|
| 710 | if(IsCommandDelimitation(basbuf[i])){
|
---|
| 711 | temporary[i2]=0;
|
---|
| 712 | break;
|
---|
| 713 | }
|
---|
| 714 | temporary[i2]=basbuf[i];
|
---|
| 715 | }
|
---|
| 716 | if(temporary[0]=='\0'){
|
---|
| 717 | if(basbuf[i]=='\0'){
|
---|
| 718 |
|
---|
| 719 | if(dwClassType==ESC_CLASS)
|
---|
[465] | 720 | compiler.errorMessenger.Output(22,"Class",top_pos);
|
---|
[376] | 721 | else
|
---|
[465] | 722 | compiler.errorMessenger.Output(22,"Type",top_pos);
|
---|
[376] | 723 |
|
---|
| 724 | i--;
|
---|
| 725 | break;
|
---|
| 726 | }
|
---|
| 727 | continue;
|
---|
| 728 | }
|
---|
| 729 |
|
---|
| 730 | //End Class記述の場合
|
---|
| 731 | if(temporary[0]==1&&temporary[1]==ESC_ENDCLASS&&dwClassType==ESC_CLASS) break;
|
---|
| 732 | if(temporary[0]==1&&temporary[1]==ESC_ENDTYPE&&dwClassType==ESC_TYPE) break;
|
---|
| 733 |
|
---|
| 734 | //アクセスを変更
|
---|
| 735 | if(lstrcmpi(temporary,"Private")==0){
|
---|
| 736 | accessibility = Prototype::Private;
|
---|
| 737 | continue;
|
---|
| 738 | }
|
---|
| 739 | if(lstrcmpi(temporary,"Public")==0){
|
---|
| 740 | accessibility = Prototype::Public;
|
---|
| 741 | continue;
|
---|
| 742 | }
|
---|
| 743 | if(lstrcmpi(temporary,"Protected")==0){
|
---|
| 744 | accessibility = Prototype::Protected;
|
---|
| 745 | continue;
|
---|
| 746 | }
|
---|
| 747 |
|
---|
| 748 | extern int cp;
|
---|
| 749 | if(i3==0){
|
---|
| 750 | if(bStatic){
|
---|
| 751 | //静的メンバを追加
|
---|
| 752 | cp=i; //エラー用
|
---|
| 753 | pobj_c->AddStaticMember( accessibility, isConst, false, temporary, i);
|
---|
| 754 | }
|
---|
| 755 | else{
|
---|
| 756 | //メンバを追加
|
---|
| 757 | cp=i; //エラー用
|
---|
| 758 | pobj_c->AddMember( accessibility, isConst, false, temporary, i );
|
---|
| 759 |
|
---|
| 760 |
|
---|
[409] | 761 | if(pobj_c->GetDynamicMembers().back()->GetType().IsStruct()){
|
---|
| 762 | if( !pobj_c->GetDynamicMembers().back()->GetType().GetClass().IsReady() ){
|
---|
[376] | 763 | //参照先が読み取られていないとき
|
---|
[409] | 764 | GetClass_recur(pobj_c->GetDynamicMembers().back()->GetType().GetClass().GetName().c_str());
|
---|
[376] | 765 | }
|
---|
| 766 | }
|
---|
| 767 |
|
---|
| 768 |
|
---|
[409] | 769 | if(pobj_c->GetDynamicMembers().back()->GetType().IsStruct()){
|
---|
[376] | 770 | //循環参照のチェック
|
---|
| 771 | pobj_LoopRefCheck->add(pobj_c->GetName().c_str());
|
---|
[409] | 772 | if(!MemberVar_LoopRefCheck(pobj_c->GetDynamicMembers().back()->GetType().GetClass())){
|
---|
[376] | 773 | //エラー回避
|
---|
| 774 | Type &type = const_cast<Type &>(pobj_c->GetDynamicMembers().back()->GetType());
|
---|
| 775 | type.SetBasicType( DEF_PTR_VOID );
|
---|
| 776 | }
|
---|
| 777 | pobj_LoopRefCheck->del(pobj_c->GetName().c_str());
|
---|
| 778 | }
|
---|
| 779 | }
|
---|
| 780 | }
|
---|
| 781 | else{
|
---|
| 782 | //メソッドを追加
|
---|
| 783 | cp=i; //エラー用
|
---|
| 784 | pobj_c->AddMethod(pobj_c,
|
---|
| 785 | accessibility,
|
---|
| 786 | bStatic,
|
---|
| 787 | isConst,
|
---|
| 788 | isAbstract,
|
---|
| 789 | isVirtual,
|
---|
| 790 | isOverride,
|
---|
| 791 | false,
|
---|
| 792 | temporary,
|
---|
| 793 | sub_address);
|
---|
| 794 |
|
---|
| 795 | if( isAbstract ) continue;
|
---|
| 796 |
|
---|
| 797 | for(;;i++){
|
---|
| 798 | if(basbuf[i]=='\0'){
|
---|
| 799 | i--;
|
---|
| 800 | break;
|
---|
| 801 | }
|
---|
| 802 | if(basbuf[i-1]!='*'&&
|
---|
| 803 | basbuf[i]==1&&(
|
---|
| 804 | basbuf[i+1]==ESC_SUB||
|
---|
| 805 | basbuf[i+1]==ESC_FUNCTION||
|
---|
| 806 | basbuf[i+1]==ESC_MACRO||
|
---|
| 807 | basbuf[i+1]==ESC_TYPE||
|
---|
| 808 | basbuf[i+1]==ESC_CLASS||
|
---|
| 809 | basbuf[i+1]==ESC_INTERFACE||
|
---|
| 810 | basbuf[i+1]==ESC_ENUM)){
|
---|
| 811 | GetDefaultNameFromES(i3,temporary);
|
---|
[465] | 812 | compiler.errorMessenger.Output(22,temporary,i);
|
---|
[376] | 813 | }
|
---|
| 814 | if(basbuf[i]==1&&basbuf[i+1]==GetEndXXXCommand((char)i3)){
|
---|
| 815 | i+=2;
|
---|
| 816 | break;
|
---|
| 817 | }
|
---|
| 818 | }
|
---|
| 819 | }
|
---|
| 820 | }
|
---|
| 821 | }
|
---|
| 822 | }
|
---|
| 823 |
|
---|
| 824 | // 呼び出し元でコンパイル中のクラスポインタを元に戻す
|
---|
| 825 | compiler.pCompilingClass = pBackCompilingClass;
|
---|
| 826 |
|
---|
| 827 | // 名前空間を元に戻す
|
---|
| 828 | compiler.GetNamespaceSupporter().GetLivingNamespaceScopes() = backupNamespaceScopes;
|
---|
| 829 |
|
---|
| 830 | // インポートされた名前空間を元に戻す
|
---|
| 831 | compiler.GetNamespaceSupporter().GetImportedNamespaces() = backupImportedNamespaces;
|
---|
| 832 | }
|
---|
| 833 |
|
---|
| 834 | void Classes::LookaheadClass( const char *className )
|
---|
| 835 | {
|
---|
| 836 | pobj_LoopRefCheck->add( className );
|
---|
| 837 | compiler.GetObjectModule().meta.GetClasses().GetClass_recur( className );
|
---|
| 838 | pobj_LoopRefCheck->del( className );
|
---|
| 839 | }
|
---|
| 840 |
|
---|
| 841 | bool Classes::LoopRefCheck( const CClass &objClass )
|
---|
| 842 | {
|
---|
| 843 | if( pobj_LoopRefCheck->check( objClass ) )
|
---|
| 844 | {
|
---|
| 845 | return false;
|
---|
| 846 | }
|
---|
| 847 |
|
---|
| 848 | return true;
|
---|
| 849 | }
|
---|
| 850 |
|
---|
| 851 | void Classes::GetAllClassInfo(void){
|
---|
| 852 | //ループ継承チェック用のクラス
|
---|
| 853 | pobj_LoopRefCheck=new CLoopRefCheck();
|
---|
| 854 |
|
---|
| 855 | //クラスを取得
|
---|
| 856 | GetClass_recur(0);
|
---|
| 857 |
|
---|
| 858 | delete pobj_LoopRefCheck;
|
---|
| 859 | pobj_LoopRefCheck=0;
|
---|
| 860 |
|
---|
| 861 | // イテレータの準備
|
---|
| 862 | this->Iterator_Init();
|
---|
| 863 | }
|
---|