Changeset 135 in dev for BasicCompiler_Common/Class.cpp
- Timestamp:
- Jun 6, 2007, 12:58:40 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
BasicCompiler_Common/Class.cpp
r134 r135 12 12 13 13 CMember *pCompilingMethod; 14 15 16 17 CMember::CMember( CClass *pobj_c, DWORD access, bool isConst, bool isRef, char *buffer, int nowLine ){18 extern int cp;19 20 if( strstr(buffer,"environVarName")){21 int test=0;22 }23 24 //構文を解析25 char VarName[VN_SIZE];26 char init_buf[VN_SIZE];27 char constract_parameter[VN_SIZE];28 GetDimentionFormat(buffer,VarName,SubScripts,*this,init_buf,constract_parameter);29 30 //重複チェック31 if(pobj_c->DupliCheckAll(VarName)){32 SetError(15,VarName,cp);33 }34 35 //メンバ名36 name=(char *)HeapAlloc(hHeap,0,lstrlen(VarName)+1);37 lstrcpy(name,VarName);38 39 //アクセス権40 dwAccess=access;41 42 //定数扱いかどうか43 this->isConst = isConst;44 45 //初期データ46 InitBuf=(char *)HeapAlloc(hHeap,0,lstrlen(init_buf)+1);47 lstrcpy(InitBuf,init_buf);48 49 //コンストラクタ用のパラメータ50 ConstractParameter=(char *)HeapAlloc(hHeap,0,lstrlen(constract_parameter)+1);51 lstrcpy(ConstractParameter,constract_parameter);52 53 //ソースコードの位置54 source_code_address=nowLine;55 }56 CMember::CMember(CMember &member):57 Type( member )58 {59 60 //name61 name=(char *)HeapAlloc(hHeap,0,lstrlen(member.name)+1);62 lstrcpy(name,member.name);63 64 //定数扱いかどうか65 isConst = member.isConst;66 67 //SubScripts68 memcpy(SubScripts,member.SubScripts,MAX_ARRAYDIM*sizeof(int));69 70 //ソースコードの位置71 source_code_address=member.source_code_address;72 }73 CMember::CMember(){74 memset(this,0,sizeof(CMember));75 }76 CMember::~CMember(){77 HeapDefaultFree(name);78 if(InitBuf) HeapDefaultFree(InitBuf);79 if(ConstractParameter) HeapDefaultFree(ConstractParameter);80 }81 82 bool CMember::IsConst(){83 return isConst;84 }85 86 void CMember::InitStaticMember(void){87 //静的メンバをグローバル領域に作成88 89 //イテレータをリセット90 extern CDBClass *pobj_DBClass;91 pobj_DBClass->Iterator_Reset();92 93 int back_cp=cp;94 95 while(pobj_DBClass->Iterator_HasNext()){96 CClass &objClass = *pobj_DBClass->Iterator_GetNext();97 98 // 名前空間をセット99 Smoothie::Lexical::liveingNamespaceScopes = objClass.GetNamespaceScopes();100 101 int i=0;102 foreach( CMember *member, objClass.staticMembers ){103 char temporary[VN_SIZE];104 sprintf(temporary,"%s.%s",objClass.GetName().c_str(),member->name);105 dim(106 temporary,107 member->SubScripts,108 *member,109 member->InitBuf,110 member->ConstractParameter,111 0);112 113 //ネイティブコードバッファの再確保114 ReallocNativeCodeBuffer();115 116 i++;117 }118 }119 120 Smoothie::Lexical::liveingNamespaceScopes.clear();121 122 cp=back_cp;123 }124 125 126 127 //コピーコンストラクタ128 CMethod::CMethod(CMethod *pMethod)129 : pUserProc( pMethod->pUserProc )130 , dwAccess( pMethod->dwAccess )131 , bAbstract( pMethod->bAbstract )132 , bVirtual( pMethod->bVirtual )133 , isConst( pMethod->isConst )134 , isStatic( pMethod->isStatic )135 {136 }137 138 CMethod::CMethod( UserProc *pUserProc, DWORD dwAccess, BOOL bAbstract, BOOL bVirtual, bool isConst, bool isStatic )139 : pUserProc( pUserProc )140 , dwAccess( dwAccess )141 , bAbstract( bAbstract )142 , bVirtual( bVirtual )143 , isConst( isConst )144 , isStatic( isStatic )145 , pobj_InheritsClass( NULL )146 {147 }148 CMethod::~CMethod(){149 }150 151 14 152 15 … … 184 47 delete member; 185 48 } 186 187 //メソッド188 foreach( CMethod *method, methods ){189 delete method;190 }191 192 //静的メソッド193 foreach( CMethod *method, staticMethods ){194 delete method;195 }196 49 } 197 50 … … 321 174 322 175 //メソッドをコピー 323 foreach( CMethod *baseMethod, inheritsClass.methods ){324 CMethod * method = new CMethod( baseMethod );176 foreach( const CMethod *pBaseMethod, inheritsClass.methods ){ 177 CMethod *pMethod = new DynamicMethod( *pBaseMethod ); 325 178 326 179 //dwAccess 327 if( baseMethod->dwAccess==ACCESS_PRIVATE)328 method->dwAccess=ACCESS_NON;329 else method->dwAccess=baseMethod->dwAccess;180 if(pBaseMethod->dwAccess==ACCESS_PRIVATE) 181 pMethod->dwAccess=ACCESS_NON; 182 else pMethod->dwAccess=pBaseMethod->dwAccess; 330 183 331 184 //pobj_Inherits 332 185 // ※継承元のClassIndexをセット(入れ子継承を考慮する) 333 if(baseMethod->pobj_InheritsClass==0) 334 method->pobj_InheritsClass=&inheritsClass; 335 else 336 method->pobj_InheritsClass= 337 baseMethod->pobj_InheritsClass; 338 339 methods.push_back( method ); 186 if(pBaseMethod->GetInheritsClassPtr()==0){ 187 pMethod->SetInheritsClassPtr( &inheritsClass ); 188 } 189 else{ 190 pMethod->SetInheritsClassPtr( pBaseMethod->GetInheritsClassPtr() ); 191 } 192 193 methods.push_back( pMethod ); 340 194 } 341 195 … … 364 218 365 219 //メソッドをコピー 366 foreach( CMethod *baseMethod, inheritsInterface.methods ){367 CMethod * method = new CMethod( baseMethod );220 foreach( const CMethod *pBaseMethod, inheritsInterface.methods ){ 221 CMethod *pMethod = new DynamicMethod( *pBaseMethod ); 368 222 369 223 //dwAccess 370 if( baseMethod->dwAccess==ACCESS_PRIVATE)371 method->dwAccess=ACCESS_NON;372 else method->dwAccess=baseMethod->dwAccess;224 if(pBaseMethod->dwAccess==ACCESS_PRIVATE) 225 pMethod->dwAccess=ACCESS_NON; 226 else pMethod->dwAccess=pBaseMethod->dwAccess; 373 227 374 228 //pobj_Inherits 375 229 // ※継承元のClassIndexをセット(入れ子継承を考慮する) 376 if(baseMethod->pobj_InheritsClass==0) 377 method->pobj_InheritsClass=&inheritsInterface; 378 else 379 method->pobj_InheritsClass= 380 baseMethod->pobj_InheritsClass; 381 382 methods.push_back( method ); 230 if(pBaseMethod->GetInheritsClassPtr()==0){ 231 pMethod->SetInheritsClassPtr( &inheritsInterface ); 232 } 233 else{ 234 pMethod->SetInheritsClassPtr( pBaseMethod->GetInheritsClassPtr() ); 235 } 236 237 methods.push_back( pMethod ); 383 238 } 384 239 … … 399 254 staticMembers.push_back( member ); 400 255 } 401 void CClass::AddMethod( UserProc *pUserProc,DWORD dwAccess, bool isConst, BOOL bAbstract, BOOL bVirtual ){402 CMethod *method = new CMethod( pUserProc, dwAccess, bAbstract, bVirtual, isConst, false );403 404 methods.push_back( method );405 406 // プロシージャオブジェクトと関連付け407 pUserProc->SetMethod( method );408 }409 void CClass::AddStaticMethod(UserProc *pUserProc,DWORD dwAccess){410 CMethod *method = new CMethod( pUserProc, dwAccess, FALSE, FALSE, false, true );411 412 staticMethods.push_back( method );413 414 // プロシージャオブジェクトと関連付け415 pUserProc->SetMethod( method );416 }417 256 BOOL CClass::DupliCheckAll(const char *name){ 418 257 //重複チェック … … 422 261 423 262 //メソッド 424 foreach( CMethod *method, methods ){425 if( lstrcmp( name, method->pUserProc->GetName().c_str() ) == 0 ){263 foreach( const CMethod *pMethod, methods ){ 264 if( lstrcmp( name, pMethod->pUserProc->GetName().c_str() ) == 0 ){ 426 265 return 1; 427 266 } … … 435 274 //メンバ 436 275 for( int i=0;i<iMemberNum;i++){ 437 if( GetName() == ppobj_Member[i]-> name){276 if( GetName() == ppobj_Member[i]->GetName() ){ 438 277 return 1; 439 278 } … … 442 281 //静的メンバ 443 282 foreach( CMember *member, staticMembers ){ 444 if( GetName() == member-> name){283 if( GetName() == member->GetName() ){ 445 284 return 1; 446 285 } … … 449 288 return 0; 450 289 } 451 CMethod *CClass::GetMethodInfo( UserProc *pUserProc ) const452 {453 for( int i=(int)methods.size()-1; i>=0; i-- ){454 if( pUserProc == methods[i]->pUserProc ){455 return methods[i];456 }457 }458 return NULL;459 }460 CMethod *CClass::GetStaticMethodInfo( UserProc *pUserProc ) const461 {462 for( int i=(int)staticMethods.size()-1; i>=0; i-- ){463 if( pUserProc == staticMethods[i]->pUserProc ) return staticMethods[i];464 }465 return NULL;466 }467 bool CClass::IsExistMethod( const char *name ) const468 {469 foreach( CMethod *method, methods ){470 if( method->pUserProc->GetName() == name ) return true;471 }472 return false;473 }474 bool CClass::IsExistStaticMethod( const char *name ) const475 {476 foreach( CMethod *method, staticMethods ){477 if( method->pUserProc->GetName() == name ) return true;478 }479 return false;480 }481 482 void CClass::EnumStaticMethod( const char *methodName, vector<UserProc *> &subs ) const483 {484 foreach( CMethod *method, staticMethods ){485 if( method->pUserProc->GetName() == methodName ){486 subs.push_back( method->pUserProc );487 }488 }489 }490 491 void CClass::EnumMethod( const char *methodName, vector<UserProc *> &subs ) const492 {493 //オブジェクトのメンバ関数の場合494 //※オーバーライドされた関数を先にサーチする必要があるため、バックサーチを行う495 for( int i=(int)methods.size()-1; i>=0; i-- ){496 if( methods[i]->pUserProc->GetName() == methodName ){497 subs.push_back( methods[i]->pUserProc );498 }499 }500 }501 502 void CClass::EnumMethod( const BYTE idOperatorCalc, vector<UserProc *> &subs ) const503 {504 //オブジェクトのメンバ関数の場合505 //※オーバーライドされた関数を先にサーチする必要があるため、バックサーチを行う506 for( int i=(int)methods.size()-1; i>=0; i-- ){507 UserProc *pUserProc = methods[i]->pUserProc;508 const char *temp = pUserProc->GetName().c_str();509 if(temp[0]==1&&temp[1]==ESC_OPERATOR){510 if((BYTE)temp[2]==idOperatorCalc){511 subs.push_back( pUserProc );512 }513 }514 }515 }516 290 517 291 //デフォルト コンストラクタ メソッドを取得 518 CMethod *CClass::GetConstructorMethod() const292 const CMethod *CClass::GetConstructorMethod() const 519 293 { 520 294 if( ConstructorMemberSubIndex == -1 ) return NULL; … … 523 297 524 298 //デストラクタ メソッドを取得 525 CMethod *CClass::GetDestructorMethod() const299 const CMethod *CClass::GetDestructorMethod() const 526 300 { 527 301 if( DestructorMemberSubIndex == -1 ) return NULL; … … 584 358 if(memberName){ 585 359 //メンバ指定がある場合は、オフセットを返す 586 if( lstrcmp(pMember->name,memberName)==0){360 if( pMember->GetName() == memberName ){ 587 361 if(pMemberNum) *pMemberNum=i; 588 362 return offset; … … 644 418 { 645 419 int n = 0; 646 foreach( CMethod *method, methods ){647 if( method->pUserProc == pUserProc ) break;648 if( method->bVirtual) n++;420 foreach( const CMethod *pMethod, methods ){ 421 if( pMethod->pUserProc == pUserProc ) break; 422 if( pMethod->IsVirtual() ) n++; 649 423 } 650 424 return n; … … 667 441 //関数テーブルに値をセット 668 442 int i2 = 0; 669 foreach( CMethod *method, methods ){670 if( method->bVirtual){671 method->pUserProc->Using();672 673 if( method->bAbstract){443 foreach( const CMethod *pMethod, methods ){ 444 if(pMethod->IsVirtual()){ 445 pMethod->pUserProc->Using(); 446 447 if(pMethod->IsAbstract()){ 674 448 extern int cp; 675 449 SetError(300,NULL,cp); … … 678 452 } 679 453 else{ 680 ppsi[i2]= method->pUserProc;454 ppsi[i2]=pMethod->pUserProc; 681 455 } 682 456 i2++; … … 712 486 // 未実装(abstract)の仮想関数を持つ場合はtrueを返す 713 487 714 foreach( CMethod *method, methods ){715 if( method->bVirtual){716 if( method->bAbstract){488 foreach( const CMethod *pMethod, methods ){ 489 if(pMethod->IsVirtual()){ 490 if(pMethod->IsAbstract()){ 717 491 return true; 718 492 } … … 1063 837 1064 838 1065 void CDBClass::AddMethod(CClass *pobj_c, DWORD dwAccess, BOOL bStatic, bool isConst, BOOL bAbstract,1066 BOOL bVirtual, BOOL bOverride, char *buffer, int nowLine){839 void CDBClass::AddMethod(CClass *pobj_c, DWORD dwAccess, BOOL bStatic, bool isConst, bool isAbstract, 840 bool isVirtual, bool isOverride, char *buffer, int nowLine){ 1067 841 int i,i2; 1068 842 char temporary[VN_SIZE]; … … 1080 854 //関数ハッシュへ登録 1081 855 GlobalProc *pUserProc; 1082 pUserProc=AddSubData( NamespaceScopes(), NamespaceScopesCollection(), buffer,nowLine, bVirtual,pobj_c, (bStatic!=0) );856 pUserProc=AddSubData( NamespaceScopes(), NamespaceScopesCollection(), buffer,nowLine,isVirtual,pobj_c, (bStatic!=0) ); 1083 857 if(!pUserProc) return; 1084 858 … … 1129 903 1130 904 //メソッド 1131 foreach( CMethod *method, pobj_c->methods ){905 foreach( const CMethod *pMethod, pobj_c->methods ){ 1132 906 //基底クラスと重複する場合はオーバーライドを行う 1133 if( method->pobj_InheritsClass) continue;1134 1135 if( method->pUserProc->GetName() == temporary ){1136 if( method->pUserProc->Params().Equals( pUserProc->Params() ) ){907 if( pMethod->GetInheritsClassPtr() ) continue; 908 909 if( pMethod->pUserProc->GetName() == temporary ){ 910 if( pMethod->pUserProc->Params().Equals( pUserProc->Params() ) ){ 1137 911 //関数名、パラメータ属性が合致したとき 1138 912 SetError(15,pUserProc->GetName().c_str(),nowLine); … … 1143 917 1144 918 //仮想関数の場合 1145 if( bAbstract) pUserProc->CompleteCompile();919 if( isAbstract ) pUserProc->CompleteCompile(); 1146 920 1147 921 //メソッドのオーバーライド 1148 foreach( CMethod * method, pobj_c->methods ){1149 if( method->pUserProc->GetName() == temporary ){1150 if( method->pUserProc->Params().Equals( pUserProc->Params() ) ){1151 1152 if( method->bVirtual){922 foreach( CMethod *pMethod, pobj_c->methods ){ 923 if( pMethod->pUserProc->GetName() == temporary ){ 924 if( pMethod->pUserProc->Params().Equals( pUserProc->Params() ) ){ 925 926 if(pMethod->IsVirtual()){ 1153 927 //メンバ関数を上書き 1154 method->pUserProc=pUserProc;1155 method->bAbstract=0;1156 1157 if( !bOverride){928 pMethod->pUserProc=pUserProc; 929 pMethod->Override(); 930 931 if( !isOverride ){ 1158 932 SetError(127,NULL,nowLine); 1159 933 } 1160 if( method->dwAccess!=dwAccess){934 if(pMethod->dwAccess!=dwAccess){ 1161 935 SetError(128,NULL,nowLine); 1162 936 } 1163 937 1164 pUserProc->SetMethod( method );938 pUserProc->SetMethod( pMethod ); 1165 939 return; 1166 940 } … … 1169 943 } 1170 944 1171 if( bVirtual){945 if( isVirtual ){ 1172 946 pobj_c->vtbl_num++; 1173 947 } 1174 948 1175 if( bOverride){949 if( isOverride ){ 1176 950 SetError(12,"Override",nowLine); 1177 951 } 1178 952 1179 953 if(bStatic){ 1180 pobj_c-> AddStaticMethod(pUserProc,dwAccess);954 pobj_c->staticMethods.AddStatic(pUserProc,dwAccess); 1181 955 } 1182 956 else{ 1183 pobj_c-> AddMethod(pUserProc, dwAccess, isConst, bAbstract, bVirtual);957 pobj_c->methods.Add(pUserProc, dwAccess, isConst, isAbstract, isVirtual); 1184 958 } 1185 959 } … … 1517 1291 else i3=0; 1518 1292 1519 BOOL bVirtual=0,bAbstract=0,bOverride=0;1293 bool isVirtual = false, isAbstract = false, isOverride = false; 1520 1294 if(i3==ESC_ABSTRACT){ 1521 bAbstract=1;1522 bVirtual=1;1295 isAbstract=1; 1296 isVirtual=1; 1523 1297 i+=2; 1524 1298 … … 1526 1300 } 1527 1301 else if(i3==ESC_VIRTUAL){ 1528 bAbstract=0;1529 bVirtual=1;1302 isAbstract=0; 1303 isVirtual=1; 1530 1304 i+=2; 1531 1305 … … 1533 1307 } 1534 1308 else if(i3==ESC_OVERRIDE){ 1535 bOverride=1;1536 bVirtual=1;1309 isOverride=1; 1310 isVirtual=1; 1537 1311 1538 1312 i+=2; … … 1619 1393 bStatic, 1620 1394 isConst, 1621 bAbstract,1622 bVirtual,1623 bOverride,1395 isAbstract, 1396 isVirtual, 1397 isOverride, 1624 1398 temporary, 1625 1399 sub_address); 1626 1400 1627 if( bAbstract) continue;1401 if( isAbstract ) continue; 1628 1402 1629 1403 for(;;i++){ … … 1699 1473 sprintf( referenceOffsetsBuffer + lstrlen( referenceOffsetsBuffer ), 1700 1474 "%d", 1701 objClass.GetMemberOffset( member. name) );1475 objClass.GetMemberOffset( member.GetName().c_str() ) ); 1702 1476 1703 1477 numOfReference++; … … 1822 1596 pCompilingClass->Using(); 1823 1597 1824 pCompilingMethod = pCompilingClass-> GetMethodInfo( pUserProc );1598 pCompilingMethod = pCompilingClass->methods.GetMethodPtr( pUserProc ); 1825 1599 if( !pCompilingMethod ){ 1826 pCompilingMethod = pCompilingClass-> GetStaticMethodInfo( pUserProc );1600 pCompilingMethod = pCompilingClass->staticMethods.GetMethodPtr( pUserProc ); 1827 1601 if( !pCompilingMethod ){ 1828 1602 SetError(300,NULL,cp); … … 1838 1612 return pCompilingClass; 1839 1613 } 1840 CMethod *CDBClass::GetNowCompilingMethodInfo(){1614 const CMethod *CDBClass::GetNowCompilingMethodInfo(){ 1841 1615 return pCompilingMethod; 1842 1616 }
Note:
See TracChangeset
for help on using the changeset viewer.