Changeset 206 in dev for trunk/abdev/BasicCompiler64/Compile_Var.cpp
- Timestamp:
- Jul 12, 2007, 2:58:26 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abdev/BasicCompiler64/Compile_Var.cpp
r198 r206 1 #include "stdafx.h" 2 1 3 #include <jenga/include/smoothie/Smoothie.h> 2 4 #include <jenga/include/smoothie/LexicalAnalysis.h> … … 5 7 #include <CodeGenerator.h> 6 8 #include <Compiler.h> 7 #include <Variable Impl.h>9 #include <Variable.h> 8 10 9 11 #include "../BasicCompiler_Common/common.h" … … 11 13 12 14 //変数 13 Variables globalVars; 15 // TODO: xml未完成 14 16 int AllGlobalVarSize; 15 17 int AllInitGlobalVarSize; … … 86 88 } 87 89 } 88 bool GetArrayOffset(const int *SubScripts,char *array, const Type &type){90 bool GetArrayOffset(const Subscripts &subscripts,char *array, const Type &type){ 89 91 extern HANDLE hHeap; 90 92 int i,i2,i3,i4; … … 105 107 } 106 108 if(array[i]==','||array[i]=='\0'){ 107 if(SubScripts[i3]==-1){ 109 if( i3 >= (int)subscripts.size() ) 110 { 108 111 for(i3--;i3>=0;i3--) HeapDefaultFree(pParm[i3]); 109 112 return false; … … 118 121 119 122 if(array[i]=='\0'){ 120 if(SubScripts[i3]!=-1){ 123 if( i3 < (int)subscripts.size() ) 124 { 121 125 for(i3--;i3>=0;i3--) HeapDefaultFree(pParm[i3]); 122 126 return false; … … 166 170 pobj_sf->pop(REG_R12); 167 171 168 for(i2=i+1,i4=1;i2<i3;i2++) i4*= SubScripts[i2]+1;172 for(i2=i+1,i4=1;i2<i3;i2++) i4*=subscripts[i2]+1; 169 173 170 174 //imul reg,i4 … … 204 208 char lpPtrOffset[VN_SIZE]; //第2次配列 205 209 char NestMember[VN_SIZE]; //入れ子メンバ 206 CClass::RefTyperefType;210 ReferenceKind refType; 207 211 lstrcpy(VarName,member); 208 212 if(!GetVarFormatString(VarName,array,lpPtrOffset,NestMember,refType)) return false; … … 224 228 225 229 //アクセシビリティをチェック 226 if(&objClass== Smoothie::Temp::pCompilingClass){230 if(&objClass==compiler.pCompilingClass){ 227 231 //同一クラスオブジェクトの場合はプライベートアクセスを容認する 228 232 if(pMember->IsNoneAccess()){ … … 257 261 //ポインタ変数の場合 258 262 if( resultType.IsPointer() ){ 259 if( pMember->SubScripts[0]==-1){263 if( pMember->GetSubscripts().size() == 0 ){ 260 264 lstrcpy(lpPtrOffset,array); 261 265 array[0]=0; … … 280 284 if(array[0]){ 281 285 //配列オフセット 282 if(!GetArrayOffset(pMember-> SubScripts,array,pMember->GetType())){286 if(!GetArrayOffset(pMember->GetSubscripts(),array,pMember->GetType())){ 283 287 if(isErrorEnabled) SetError(14,member,cp); 284 288 } 285 289 } 286 else if( pMember->SubScripts[0]!=-1){290 else if( pMember->GetSubscripts().size() > 0 ){ 287 291 resultType.SetBasicType( resultType.GetBasicType() | FLAG_PTR ); 288 292 } … … 292 296 293 297 if( resultType.IsObject() || resultType.IsStruct() ){ 294 if( refType != CClass::Dot ){298 if( refType != RefDot ){ 295 299 if(isErrorEnabled) SetError(104,member,cp); 296 300 return false; … … 308 312 //pObj[n].member 309 313 if( ( resultType.IsObjectPtr() || resultType.IsStructPtr() ) 310 && refType != CClass::Dot ){314 && refType != RefDot ){ 311 315 if(isErrorEnabled) SetError(104,member,cp); 312 316 return false; … … 322 326 //pObj->member 323 327 if( (resultType.IsObjectPtr() || resultType.IsStructPtr() ) 324 && refType != CClass::Pointer ){328 && refType != RefPointer ){ 325 329 if(isErrorEnabled) SetError(104,member,cp); 326 330 return false; … … 336 340 if(lpPtrOffset[0]){ 337 341 //ppObj[n]->member 338 if( refType != CClass::Pointer ){342 if( refType != RefPointer ){ 339 343 if(isErrorEnabled) SetError(104,member,cp); 340 344 return false; … … 385 389 SetReg_WholeVariable(DEF_PTR_VOID,&RelativeVar,reg); 386 390 } 387 bool GetVarOffset(bool isErrorEnabled,bool isWriteAccess,const char *NameBuffer,RELATIVE_VAR *pRelativeVar,Type &resultType, int *pss){391 bool GetVarOffset(bool isErrorEnabled,bool isWriteAccess,const char *NameBuffer,RELATIVE_VAR *pRelativeVar,Type &resultType, Subscripts *pResultSubscripts ){ 388 392 char variable[VN_SIZE]; 389 393 … … 399 403 400 404 // 先頭オブジェクトまたはクラス名と入れ子メンバに分割 401 CClass::RefTyperefType;405 ReferenceKind refType; 402 406 char member[VN_SIZE],array[VN_SIZE],lpPtrOffset[VN_SIZE]; 403 407 GetVarFormatString(simpleName,array,lpPtrOffset,member,refType); … … 412 416 } 413 417 414 const int *pSubScripts;418 const Subscripts *pSubscripts; 415 419 bool bConst = false; 416 420 … … 421 425 ////////////////// 422 426 423 const Variable *pVar = UserProc::CompilingUserProc(). localVars.BackSearch( VarName);427 const Variable *pVar = UserProc::CompilingUserProc().GetLocalVars().BackSearch( Symbol( VarName ) ); 424 428 if( pVar ){ 425 429 //ポインタ変数の場合 426 if( pVar-> IsPointer() ){430 if( pVar->GetType().IsPointer() ){ 427 431 if( !pVar->IsArray() ){ 428 432 lstrcpy(lpPtrOffset,array); … … 438 442 } 439 443 440 pRelativeVar->offset=-pVar-> offset;444 pRelativeVar->offset=-pVar->GetOffsetAddress(); 441 445 pRelativeVar->bOffsetOffset=0; 442 446 if( pVar->IsRef() ){ … … 445 449 } 446 450 else pRelativeVar->dwKind=VAR_LOCAL; 447 resultType = *pVar;448 pSub Scripts=pVar->GetSubScriptsPtr();451 resultType = pVar->GetType(); 452 pSubscripts = &pVar->GetSubscripts(); 449 453 bConst = pVar->IsConst(); 450 454 … … 454 458 455 459 456 if( Smoothie::Temp::pCompilingClass){460 if(compiler.pCompilingClass){ 457 461 ////////////////////// 458 462 // クラスメンバの参照 … … 465 469 pRelativeVar->dwKind=VAR_DIRECTMEM; 466 470 467 resultType.SetType( DEF_OBJECT, Smoothie::Temp::pCompilingClass );471 resultType.SetType( DEF_OBJECT, compiler.pCompilingClass ); 468 472 return true; 469 473 } … … 478 482 479 483 bool isFound = false; 480 BOOST_FOREACH( CMember *pMember, Smoothie::Temp::pCompilingClass->GetDynamicMembers() ){484 BOOST_FOREACH( CMember *pMember, compiler.pCompilingClass->GetDynamicMembers() ){ 481 485 if( pMember->GetName() == VarName ){ 482 486 isFound = true; … … 492 496 if( isWriteAccess && 493 497 pMethod->IsConst() && 494 Smoothie::Temp::pCompilingClass->IsCompilingConstructor() == false &&495 Smoothie::Temp::pCompilingClass->IsCompilingDestructor() == false498 compiler.pCompilingClass->IsCompilingConstructor() == false && 499 compiler.pCompilingClass->IsCompilingDestructor() == false 496 500 ){ 497 501 SetError(131, NULL, cp ); … … 505 509 isErrorEnabled, 506 510 isWriteAccess, 507 * Smoothie::Temp::pCompilingClass,511 *compiler.pCompilingClass, 508 512 variable, 509 513 pRelativeVar, … … 526 530 GetNowStaticVarFullName(VarName,temporary); 527 531 528 pVar = globalVars.Find( temporary);532 pVar = compiler.GetMeta().GetGlobalVars().Find( Symbol( temporary ) ); 529 533 if( pVar ){ 530 534 goto GlobalOk; … … 545 549 char tempArray[VN_SIZE]; 546 550 { 547 CClass::RefTyperefType;551 ReferenceKind refType; 548 552 GetVarFormatString(temporary,tempArray,lpPtrOffset,tempMember, refType ); 549 553 } … … 557 561 char temp2[VN_SIZE]; 558 562 sprintf(temp2,"%s.%s",VarName,temporary); 559 pVar = globalVars.Find( temp2);563 pVar = compiler.GetMeta().GetGlobalVars().Find( Symbol( temp2 ) ); 560 564 if( pVar ){ 561 565 lstrcpy(member,tempMember); … … 565 569 } 566 570 567 if( Smoothie::Temp::pCompilingClass){571 if(compiler.pCompilingClass){ 568 572 //自身のクラスから静的メンバを参照する場合 569 573 char temp2[VN_SIZE]; 570 sprintf(temp2,"%s.%s", Smoothie::Temp::pCompilingClass->GetName().c_str(),VarName);571 pVar = globalVars.Find( temp2);574 sprintf(temp2,"%s.%s",compiler.pCompilingClass->GetName().c_str(),VarName); 575 pVar = compiler.GetMeta().GetGlobalVars().Find( Symbol( temp2 ) ); 572 576 if( pVar ){ 573 577 goto GlobalOk; … … 579 583 ///////////////////// 580 584 581 pVar = globalVars.BackSearch( VarName);585 pVar = compiler.GetMeta().GetGlobalVars().BackSearch( Symbol( VarName ) ); 582 586 if( pVar ){ 583 587 goto GlobalOk; … … 592 596 GlobalOk: 593 597 //ポインタ変数の場合 594 if( pVar-> IsPointer() ){598 if( pVar->GetType().IsPointer() ){ 595 599 if( !pVar->IsArray() ){ 596 600 lstrcpy(lpPtrOffset,array); … … 606 610 } 607 611 608 pRelativeVar->offset=pVar-> offset;612 pRelativeVar->offset=pVar->GetOffsetAddress(); 609 613 pRelativeVar->bOffsetOffset=0; 610 614 if( pVar->IsRef() ){ … … 613 617 } 614 618 else pRelativeVar->dwKind=VAR_GLOBAL; 615 resultType = *pVar;616 pSub Scripts=pVar->GetSubScriptsPtr();619 resultType = pVar->GetType(); 620 pSubscripts=&pVar->GetSubscripts(); 617 621 bConst = pVar->IsConst(); 618 622 } … … 634 638 } 635 639 636 if( array[0]==0&&pSubScripts[0]!=-1){640 if( array[0] == 0 && pSubscripts->size() > 0 ){ 637 641 //配列の先頭ポインタを示す場合 638 642 resultType.SetBasicType( resultType.GetBasicType() | FLAG_PTR ); 639 if(pss) memcpy(pss,pSubScripts,MAX_ARRAYDIM); 643 644 if( pResultSubscripts ) 645 { 646 (*pResultSubscripts) = *pSubscripts; 647 } 640 648 return true; 641 649 } … … 649 657 } 650 658 if(array[0]){ 651 if(!GetArrayOffset( pSubScripts,array,resultType)){659 if(!GetArrayOffset(*pSubscripts,array,resultType)){ 652 660 SetError(14,variable,cp); 653 661 pRelativeVar->dwKind=NON_VAR; … … 658 666 if( resultType.IsObject() || resultType.IsStruct() ){ 659 667 //実態オブジェクトのメンバを参照(obj.member) 660 if( refType != CClass::Dot ){668 if( refType != RefDot ){ 661 669 SetError(104,VarName,cp); 662 670 pRelativeVar->dwKind=NON_VAR; … … 673 681 if(lpPtrOffset[0]){ 674 682 //pObj[n].member 675 if( refType != CClass::Dot ){683 if( refType != RefDot ){ 676 684 SetError(104,VarName,cp); 677 685 pRelativeVar->dwKind=NON_VAR; … … 683 691 else{ 684 692 //pObj->member 685 if( refType != CClass::Pointer ){693 if( refType != RefPointer ){ 686 694 SetError(104,VarName,cp); 687 695 pRelativeVar->dwKind=NON_VAR; … … 700 708 if(lpPtrOffset[0]){ 701 709 //ppObj[n]->member 702 if( refType != CClass::Pointer ){710 if( refType != RefPointer ){ 703 711 SetError(104,VarName,cp); 704 712 pRelativeVar->dwKind=NON_VAR; … … 744 752 } 745 753 746 bool SetInitGlobalData(int offset,const Type &type,const int *SubScripts,const char *lpszInitBuf){754 bool SetInitGlobalData(int offset,const Type &type,const Subscripts &subscripts,const char *lpszInitBuf){ 747 755 extern BYTE *initGlobalBuf; 748 int i ,i2,i3;756 int i2,i3; 749 757 char temporary[VN_SIZE]; 750 758 char InitBuf[VN_SIZE]; … … 757 765 int typeSize = type.GetSize(); 758 766 759 if(SubScripts[0]!=-1){ 760 typeSize*=JumpSubScripts(SubScripts+1); 761 i=0; 762 i2=0; 763 while(1){ 764 if(SubScripts[0]<i2){ 765 SetError(41,0,cp); 766 return 0; 767 } 768 i=GetOneParameter(InitBuf,i,temporary); 769 if(!SetInitGlobalData( 770 offset+i2*typeSize, 771 type, 772 SubScripts+1, 773 temporary)) return false; 774 i2++; 775 if(InitBuf[i]=='\0') break; 767 if( subscripts.size() > 0 ){ 768 Subscripts nestSubscripts; 769 for( int i=1; i<(int)subscripts.size(); i++ ) 770 { 771 nestSubscripts.push_back( subscripts[i] ); 772 } 773 774 typeSize*=JumpSubScripts( nestSubscripts ); 775 { 776 int i=0; 777 i2=0; 778 while(1){ 779 if( subscripts[0] < i2 ){ 780 SetError(41,0,cp); 781 return 0; 782 } 783 i=GetOneParameter(InitBuf,i,temporary); 784 if(!SetInitGlobalData( 785 offset+i2*typeSize, 786 type, 787 nestSubscripts, 788 temporary)) return false; 789 i2++; 790 if(InitBuf[i]=='\0') break; 791 } 776 792 } 777 793 return true; … … 794 810 if(!SetInitGlobalData(offset+i3, 795 811 pMember->GetType(), 796 pMember-> SubScripts,812 pMember->GetSubscripts(), 797 813 temporary)) return false; 798 814 } … … 815 831 } 816 832 817 if( SubScripts[0]!=-1){833 if( subscripts.size() > 0 ){ 818 834 SetError(41,0,cp); 819 835 return false; … … 883 899 return true; 884 900 } 885 bool InitLocalVar(int offset,const Type &type,const int *SubScripts,const char *lpszInitBuf){886 int i ,i2,i3;901 bool InitLocalVar(int offset,const Type &type,const Subscripts &subscripts,const char *lpszInitBuf){ 902 int i2,i3; 887 903 char temporary[VN_SIZE]; 888 904 char InitBuf[VN_SIZE]; … … 895 911 int typeSize = type.GetSize(); 896 912 897 if(SubScripts[0]!=-1){ 898 typeSize*=JumpSubScripts(SubScripts+1); 899 i=0; 900 i2=0; 901 while(1){ 902 if(SubScripts[0]<i2){ 903 SetError(41,0,cp); 904 return false; 905 } 906 i=GetOneParameter(InitBuf,i,temporary); 907 if(!InitLocalVar( 908 offset+i2*typeSize, 909 type, 910 SubScripts+1, 911 temporary)) return false; 912 i2++; 913 if(InitBuf[i]=='\0') break; 913 if( subscripts.size() > 0 ){ 914 Subscripts nestSubscripts; 915 for( int i=1; i<(int)subscripts.size(); i++ ) 916 { 917 nestSubscripts.push_back( subscripts[i] ); 918 } 919 920 typeSize*=JumpSubScripts( nestSubscripts ); 921 { 922 int i=0; 923 i2=0; 924 while(1){ 925 if( subscripts[0] < i2 ){ 926 SetError(41,0,cp); 927 return 0; 928 } 929 i=GetOneParameter(InitBuf,i,temporary); 930 if(!InitLocalVar( 931 offset+i2*typeSize, 932 type, 933 nestSubscripts, 934 temporary)) return false; 935 i2++; 936 if(InitBuf[i]=='\0') break; 937 } 914 938 } 915 939 return true; … … 932 956 if(!InitLocalVar(offset+i3, 933 957 pMember->GetType(), 934 pMember-> SubScripts,958 pMember->GetSubscripts(), 935 959 temporary)) return false; 936 960 … … 949 973 /////////////////////////////////////// 950 974 951 if( SubScripts[0]!=-1){975 if( subscripts.size() > 0 ){ 952 976 SetError(41,0,cp); 953 977 return false; … … 1061 1085 } 1062 1086 1063 void dim( char *VarName, int *SubScripts,Type &type,const char *InitBuf,const char *ConstractParameter,DWORD dwFlags){1087 void dim( char *VarName, const Subscripts &subscripts, Type &type,const char *InitBuf,const char *ConstractParameter,DWORD dwFlags){ 1064 1088 if( UserProc::IsGlobalAreaCompiling() ){ 1065 1089 ///////////////////////// … … 1067 1091 ///////////////////////// 1068 1092 1069 //OpcodeOthers( ( (string)"OutputDebugString(Ex\"" + VarName + "\r\n\")" ).c_str() ); 1070 AddGlobalVariable(VarName,SubScripts,type,InitBuf,ConstractParameter,dwFlags); 1093 AddGlobalVariable(VarName,subscripts,type,InitBuf,ConstractParameter,dwFlags); 1071 1094 } 1072 1095 else{ … … 1075 1098 ///////////////// 1076 1099 1077 if( UserProc::CompilingUserProc(). localVars.DuplicateCheck( VarName ) ){1100 if( UserProc::CompilingUserProc().GetLocalVars().DuplicateCheck( VarName ) ){ 1078 1101 //2重定義のエラー 1079 1102 SetError(15,VarName,cp); … … 1083 1106 bool isConst = ( dwFlags & DIMFLAG_CONST ) ? true:false; 1084 1107 1085 Variable *pVar = new Variable Impl( VarName, type, isConst);1086 1087 if( SubScripts[0] != -1){1108 Variable *pVar = new Variable( VarName, type, isConst, false, ConstractParameter ); 1109 1110 if( subscripts.size() > 0 ){ 1088 1111 //配列あり 1089 pVar->SetArray( SubScripts ); 1090 } 1091 1092 //コンストラクタ用パラメータ 1093 pVar->paramStrForConstructor = ConstractParameter; 1112 pVar->SetArray( subscripts ); 1113 } 1094 1114 1095 1115 //レキシカルスコープ 1096 pVar->S copeLevel=GetLexicalScopes().GetNowLevel();1097 pVar->S copeStartAddress=GetLexicalScopes().GetStartAddress();1116 pVar->SetScopeLevel( GetLexicalScopes().GetNowLevel() ); 1117 pVar->SetScopeStartAddress( GetLexicalScopes().GetStartAddress() ); 1098 1118 pVar->bLiving=TRUE; 1099 1119 … … 1102 1122 1103 1123 // 変数を追加 1104 UserProc::CompilingUserProc(). localVars.push_back( pVar );1124 UserProc::CompilingUserProc().GetLocalVars().push_back( pVar ); 1105 1125 1106 1126 //アラインメントを考慮 1107 if( pVar-> IsStruct() ){1108 int alignment = pVar->Get Class().iAlign;1127 if( pVar->GetType().IsStruct() ){ 1128 int alignment = pVar->GetType().GetClass().iAlign; 1109 1129 1110 1130 if( alignment ){ … … 1126 1146 1127 1147 AllLocalVarSize += pVar->GetMemorySize(); 1128 pVar-> offset = AllLocalVarSize;1148 pVar->SetOffsetAddress( AllLocalVarSize ); 1129 1149 1130 1150 //レキシカルスコープ 1131 pVar->S copeLevel=GetLexicalScopes().GetNowLevel();1132 pVar->S copeStartAddress=GetLexicalScopes().GetStartAddress();1151 pVar->SetScopeLevel( GetLexicalScopes().GetNowLevel() ); 1152 pVar->SetScopeStartAddress( GetLexicalScopes().GetStartAddress() ); 1133 1153 pVar->bLiving=TRUE; 1134 1154 … … 1140 1160 1141 1161 int result = 0; 1142 if( !pVar-> IsObject() ){1143 result = InitLocalVar(-pVar-> offset,1144 *pVar,1145 pVar->GetSub ScriptsPtr(),1162 if( !pVar->GetType().IsObject() ){ 1163 result = InitLocalVar(-pVar->GetOffsetAddress(), 1164 pVar->GetType(), 1165 pVar->GetSubscripts(), 1146 1166 InitBuf); 1147 1167 } … … 1171 1191 1172 1192 //add rcx, offset 1173 op_add_RV( REG_RCX, -pVar-> offset);1193 op_add_RV( REG_RCX, -pVar->GetOffsetAddress() ); 1174 1194 obp-=sizeof(long); 1175 1195 AddLocalVarAddrSchedule(); … … 1186 1206 if( type.IsObject() &&(dwFlags&DIMFLAG_NONCALL_CONSTRACTOR)==0&&InitBuf[0]=='\0'){ 1187 1207 char objectSize[255]; 1188 if( SubScripts[0] == -1){1208 if( subscripts.size() == 0 ){ 1189 1209 objectSize[0] = 0; 1190 1210 } 1191 1211 else{ 1192 if( SubScripts[1] != -1 ){1212 if( subscripts.size() > 1 ){ 1193 1213 SetError(300,NULL,cp); 1194 1214 } 1195 sprintf( objectSize, "%d", SubScripts[0] );1215 sprintf( objectSize, "%d", subscripts[0] ); 1196 1216 } 1197 1217 Operator_New( type.GetClass(), objectSize, ConstractParameter, type ); … … 1304 1324 1305 1325 bool Compile_AddGlobalRootsForGc(){ 1306 UserProc *pUserProc_AddGlobalRootPtr = GetClassMethod( "_System_CGarbageCollection", "AddGlobalRootPtr" );1326 const UserProc *pUserProc_AddGlobalRootPtr = GetClassMethod( "_System_CGarbageCollection", "AddGlobalRootPtr" ); 1307 1327 if( !pUserProc_AddGlobalRootPtr ){ 1308 1328 SetError(3, "_System_CGarbageCollection.AddGlobalRootPtr", -1 ); … … 1310 1330 } 1311 1331 1312 BOOST_FOREACH( const Variable *pVar, globalVars){1313 if( pVar-> IsObject() || pVar->IsPointer() || pVar->IsStruct() ){1332 BOOST_FOREACH( const Variable *pVar, compiler.GetMeta().GetGlobalVars() ){ 1333 if( pVar->GetType().IsObject() || pVar->GetType().IsPointer() || pVar->GetType().IsStruct() ){ 1314 1334 // オブジェクトまたはポインタだったとき 1315 1335 // ※構造体も含む(暫定対応) … … 1321 1341 // ルートポインタを引き渡す 1322 1342 //mov rdx,offset 1323 op_mov_RV(sizeof(_int64), REG_RDX,(int)pVar-> offset);1343 op_mov_RV(sizeof(_int64), REG_RDX,(int)pVar->GetOffsetAddress()); 1324 1344 obp-=sizeof(long); 1325 1345 pobj_GlobalVarSchedule->add();
Note:
See TracChangeset
for help on using the changeset viewer.