Changeset 206 in dev for trunk/abdev/BasicCompiler_Common/VariableOpe.cpp
- Timestamp:
- Jul 12, 2007, 2:58:26 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abdev/BasicCompiler_Common/VariableOpe.cpp
r199 r206 1 #include "stdafx.h" 2 1 3 #include <jenga/include/smoothie/Smoothie.h> 2 4 #include <jenga/include/smoothie/LexicalAnalysis.h> … … 4 6 #include <Compiler.h> 5 7 #include <LexicalScopingImpl.h> 6 #include <Variable Impl.h>8 #include <Variable.h> 7 9 #include <NamespaceSupporter.h> 8 10 … … 247 249 248 250 249 void GetArrange(char *variable,char *variAnswer, int *SubScripts){251 void GetArrange(char *variable,char *variAnswer, Subscripts &subscripts ){ 250 252 extern int cp; 251 int i,i2,i 3,i4;253 int i,i2,i4; 252 254 double dbl; 253 255 _int64 i64data; … … 261 263 262 264 variAnswer[i]=0; 263 for(i++,i2=0 ,i3=0;;i++,i2++){265 for(i++,i2=0;;i++,i2++){ 264 266 if(variable[i]==','){ 265 267 temporary[i2]=0; … … 274 276 } 275 277 276 if(i64data<0){ 278 if(i64data<0) 279 { 277 280 //error 278 SubScripts[i3]=0;281 subscripts.push_back( 0 ); 279 282 } 280 else SubScripts[i3]=(int)i64data; 281 i3++; 283 else 284 { 285 subscripts.push_back( (int)i64data ); 286 } 282 287 i2=-1; 283 288 continue; … … 299 304 temporary[i2]=0; 300 305 if(i2==0){ 301 SubScripts[i3]=-2;306 subscripts.push_back( -2 ); 302 307 break; 303 308 } … … 314 319 if(i64data<0){ 315 320 //error 316 SubScripts[i3]=0;321 subscripts.push_back( 0 ); 317 322 } 318 else SubScripts[i3]=(int)i64data; 319 SubScripts[i3+1]=-1; 323 else 324 { 325 subscripts.push_back( (int)i64data ); 326 } 320 327 break; 321 328 } … … 330 337 variAnswer[i]=variable[i]; 331 338 if(variable[i]=='\0'){ 332 SubScripts[0]=-1;333 339 break; 334 340 } … … 337 343 338 344 339 BOOL GetVarFormatString(char *buffer,char *array,char *array2,char *NestMember, CClass::RefType&refType){345 BOOL GetVarFormatString(char *buffer,char *array,char *array2,char *NestMember,ReferenceKind &refType){ 340 346 extern int cp; 341 347 int i,i2,i3; … … 403 409 if(buffer[i]=='.'){ 404 410 lstrcpy(NestMember,buffer+i+1); 405 refType = CClass::Dot;411 refType = RefDot; 406 412 buffer[i]=0; 407 413 break; … … 409 415 if(buffer[i]==1&&buffer[i+1]==ESC_PSMEM){ 410 416 lstrcpy(NestMember,buffer+i+2); 411 refType = CClass::Pointer;417 refType = RefPointer; 412 418 buffer[i]=0; 413 419 break; … … 459 465 } 460 466 461 int JumpSubScripts( const int *ss){467 int JumpSubScripts( const Subscripts &subscripts ){ 462 468 //DIMで定義された並んだ配列の数だけアドレスを進める 463 int i,i2; 464 for(i=0,i2=1;i<255;i++){ 465 if(ss[i]==-1) break; 466 i2*=ss[i]+1; 469 int i, i2; 470 for( i=0,i2=1; i<(int)subscripts.size(); i++ ){ 471 i2 *= subscripts[i] + 1; 467 472 } 468 473 return i2; … … 478 483 char lpPtrOffset[VN_SIZE]; //第2次配列 479 484 char NestMember[VN_SIZE]; //入れ子メンバ 480 CClass::RefType refType = CClass::Non;485 ReferenceKind refType = RefNon; 481 486 lstrcpy(VarName,lpszMember); 482 487 if(!GetVarFormatString(VarName,array,lpPtrOffset,NestMember,refType)) return false; … … 496 501 497 502 //アクセシビリティをチェック 498 if( &objClass == Smoothie::Temp::pCompilingClass ){503 if( &objClass == compiler.pCompilingClass ){ 499 504 //同一クラスオブジェクトの場合はプライベートアクセスを容認する 500 505 if( pMember->IsNoneAccess() ){ … … 519 524 //ポインタ変数の場合 520 525 if( resultType.IsPointer() ){ 521 if( pMember->SubScripts[0]==-1){526 if( pMember->GetSubscripts().size() == 0 ){ 522 527 lstrcpy(lpPtrOffset,array); 523 528 array[0]=0; … … 531 536 } 532 537 533 if( refType != CClass::Non ){538 if( refType != RefNon ){ 534 539 //入れ子構造の場合 535 540 … … 541 546 } 542 547 543 if( array[0]==0&&pMember->SubScripts[0]!=-1){548 if( array[0] == 0 && pMember->GetSubscripts().size() > 0 ){ 544 549 resultType.SetBasicType( resultType.GetBasicType() | FLAG_PTR ); 545 550 return true; … … 573 578 574 579 // 先頭オブジェクトまたはクラス名と入れ子メンバに分割 575 CClass::RefTyperefType;580 ReferenceKind refType; 576 581 char member[VN_SIZE],array[VN_SIZE],lpPtrOffset[VN_SIZE]; 577 582 GetVarFormatString(simpleName,array,lpPtrOffset,member,refType); … … 587 592 588 593 const Variable *pVar = NULL; 589 const int *pSubScripts;590 594 591 595 if( UserProc::IsLocalAreaCompiling() ){ … … 594 598 ///////////////// 595 599 596 pVar = UserProc::CompilingUserProc(). localVars.BackSearch( Symbol( VarName ) );600 pVar = UserProc::CompilingUserProc().GetLocalVars().BackSearch( Symbol( VarName ) ); 597 601 if( pVar ){ 598 602 goto ok; … … 600 604 } 601 605 602 if( Smoothie::Temp::pCompilingClass){606 if(compiler.pCompilingClass){ 603 607 /////////////////////// 604 608 // クラスメンバの参照 … … 607 611 if(lstrcmpi(variable,"This")==0){ 608 612 //Thisオブジェクト 609 resultType.SetType( DEF_OBJECT, Smoothie::Temp::pCompilingClass );613 resultType.SetType( DEF_OBJECT, compiler.pCompilingClass ); 610 614 return true; 611 615 } … … 620 624 621 625 bool isFound = false; 622 BOOST_FOREACH( CMember *pMember, Smoothie::Temp::pCompilingClass->GetDynamicMembers() ){626 BOOST_FOREACH( CMember *pMember, compiler.pCompilingClass->GetDynamicMembers() ){ 623 627 if( pMember->GetName() == VarName ){ 624 628 isFound = true; … … 629 633 } 630 634 631 return GetMemberType(* Smoothie::Temp::pCompilingClass,variable,resultType,1,isErrorEnabled);635 return GetMemberType(*compiler.pCompilingClass,variable,resultType,1,isErrorEnabled); 632 636 } 633 637 … … 643 647 GetNowStaticVarFullName(VarName,temporary); 644 648 645 pVar = globalVars.Find( Symbol( temporary ) );649 pVar = compiler.GetMeta().GetGlobalVars().Find( Symbol( temporary ) ); 646 650 if( pVar ){ 647 651 goto ok; … … 659 663 char tempArray[VN_SIZE]; 660 664 { 661 CClass::RefTyperefType;665 ReferenceKind refType; 662 666 GetVarFormatString(temporary,tempArray,lpPtrOffset,tempMember,refType); 663 667 } … … 672 676 sprintf(temp2,"%s.%s",VarName,temporary); 673 677 674 pVar = globalVars.Find( Symbol( temp2 ) );678 pVar = compiler.GetMeta().GetGlobalVars().Find( Symbol( temp2 ) ); 675 679 if( pVar ){ 676 680 lstrcpy(member,tempMember); … … 680 684 } 681 685 682 if( Smoothie::Temp::pCompilingClass){686 if(compiler.pCompilingClass){ 683 687 //自身のクラスから静的メンバを参照する場合 684 688 char temp2[VN_SIZE]; 685 sprintf(temp2,"%s.%s", Smoothie::Temp::pCompilingClass->GetName().c_str(),VarName);686 687 pVar = globalVars.Find( Symbol( temp2 ) );689 sprintf(temp2,"%s.%s",compiler.pCompilingClass->GetName().c_str(),VarName); 690 691 pVar = compiler.GetMeta().GetGlobalVars().Find( Symbol( temp2 ) ); 688 692 if( pVar ){ 689 693 goto ok; … … 696 700 //////////////////// 697 701 698 pVar = globalVars.BackSearch( Symbol( VarName ) );702 pVar = compiler.GetMeta().GetGlobalVars().BackSearch( Symbol( VarName ) ); 699 703 if( pVar ){ 700 704 goto ok; … … 708 712 709 713 //ポインタ変数の場合 710 if( pVar-> IsPointer() ){714 if( pVar->GetType().IsPointer() ){ 711 715 if( !pVar->IsArray() ){ 712 716 lstrcpy(lpPtrOffset,array); … … 721 725 } 722 726 723 resultType = (*pVar); 724 pSubScripts=pVar->GetSubScriptsPtr(); 725 727 resultType = pVar->GetType(); 726 728 727 729 if(member[0]){ … … 732 734 } 733 735 734 if( array[0]==0&&pSubScripts[0]!=-1){736 if( array[0] == 0 && pVar->GetSubscripts().size() > 0 ){ 735 737 //配列の先頭ポインタを示す場合 736 738 resultType.SetBasicType( resultType.GetBasicType() | FLAG_PTR ); … … 751 753 } 752 754 753 bool GetVarOffsetReadOnly(const char *NameBuffer,RELATIVE_VAR *pRelativeVar,Type &resultType, int *pss ){755 bool GetVarOffsetReadOnly(const char *NameBuffer,RELATIVE_VAR *pRelativeVar,Type &resultType, Subscripts *pResultSubscripts ){ 754 756 //読み取り専用で変数へアクセス 755 757 return GetVarOffset( … … 759 761 pRelativeVar, 760 762 resultType, 761 pss); 762 } 763 bool GetVarOffsetReadWrite(const char *NameBuffer,RELATIVE_VAR *pRelativeVar,Type &resultType,int *pss ){ 763 pResultSubscripts 764 ); 765 } 766 bool GetVarOffsetReadWrite(const char *NameBuffer,RELATIVE_VAR *pRelativeVar,Type &resultType, Subscripts *pResultSubscripts ){ 764 767 //読み書き両用で変数へアクセス 765 768 return GetVarOffset( … … 769 772 pRelativeVar, 770 773 resultType, 771 pss); 774 pResultSubscripts 775 ); 772 776 } 773 777 … … 776 780 bool GetDimentionFormat( const char *buffer, 777 781 char *VarName, 778 int *SubScripts,782 Subscripts &subscripts, 779 783 Type &type, 780 784 char *InitBuf, … … 924 928 } 925 929 926 GetArrange(variable,VarName, SubScripts);930 GetArrange(variable,VarName,subscripts); 927 931 return true; 928 932 } … … 934 938 } 935 939 936 UserProc &proc = UserProc::CompilingUserProc();940 const UserProc &proc = UserProc::CompilingUserProc(); 937 941 938 942 //Static識別 … … 940 944 941 945 //クラス名 942 if( Smoothie::Temp::pCompilingClass){943 lstrcat(FullName, Smoothie::Temp::pCompilingClass->GetName().c_str());946 if(compiler.pCompilingClass){ 947 lstrcat(FullName,compiler.pCompilingClass->GetName().c_str()); 944 948 lstrcat(FullName,"%"); 945 949 } … … 951 955 //ID 952 956 char temp[255]; 953 sprintf(temp,"%x",proc. id);957 sprintf(temp,"%x",proc.GetId()); 954 958 lstrcat(FullName,temp); 955 959 lstrcat(FullName,"%"); … … 962 966 963 967 964 void AddGlobalVariable( const char *name, int *SubScripts, const Type &type,const char *InitBuf,const char *ConstractParameter,DWORD dwFlag){968 void AddGlobalVariable( const char *name, const Subscripts &subscripts, const Type &type,const char *InitBuf,const char *ConstractParameter,DWORD dwFlag){ 965 969 ///////////////////////// 966 970 // グローバル変数を追加 … … 969 973 extern int AllGlobalVarSize; 970 974 971 if( globalVars.DuplicateCheck( Symbol( name ) ) ){975 if( compiler.GetMeta().GetGlobalVars().DuplicateCheck( Symbol( name ) ) ){ 972 976 //2重定義のエラー 973 977 SetError(15,name,cp); … … 977 981 bool isConst = ( dwFlag & DIMFLAG_CONST ) ? true:false; 978 982 979 Variable *pVar = new Variable Impl( compiler.GetNamespaceSupporter().GetLivingNamespaceScopes(), name, type, isConst);980 981 if( SubScripts[0] != -1){983 Variable *pVar = new Variable( compiler.GetNamespaceSupporter().GetLivingNamespaceScopes(), name, type, isConst, false, ConstractParameter ); 984 985 if( subscripts.size() > 0 ){ 982 986 //配列あり 983 pVar->SetArray( SubScripts ); 984 } 985 986 //コンストラクタ用パラメータ 987 pVar->paramStrForConstructor = ConstractParameter; 987 pVar->SetArray( subscripts ); 988 } 988 989 989 990 //レキシカルスコープ 990 pVar->S copeLevel=GetLexicalScopes().GetNowLevel();991 pVar->S copeStartAddress=GetLexicalScopes().GetStartAddress();991 pVar->SetScopeLevel( GetLexicalScopes().GetNowLevel() ); 992 pVar->SetScopeStartAddress( GetLexicalScopes().GetStartAddress() ); 992 993 pVar->bLiving=TRUE; 993 994 … … 996 997 997 998 // 変数を追加 998 globalVars.push_back( pVar );999 compiler.GetMeta().GetGlobalVars().push_back( pVar ); 999 1000 1000 1001 //アラインメントを考慮 1001 1002 int alignment = 0; 1002 if( pVar-> IsStruct() ){1003 alignment = pVar->Get Class().iAlign;1003 if( pVar->GetType().IsStruct() ){ 1004 alignment = pVar->GetType().GetClass().iAlign; 1004 1005 } 1005 1006 … … 1013 1014 } 1014 1015 1015 pVar-> offset=AllInitGlobalVarSize;1016 pVar->SetOffsetAddress( AllInitGlobalVarSize ); 1016 1017 AllInitGlobalVarSize += pVar->GetMemorySize(); 1017 1018 } … … 1025 1026 } 1026 1027 1027 pVar-> offset=AllGlobalVarSize | 0x80000000;1028 pVar->SetOffsetAddress( AllGlobalVarSize | 0x80000000 ); 1028 1029 AllGlobalVarSize += pVar->GetMemorySize(); 1029 1030 } … … 1031 1032 if(InitBuf[0]){ 1032 1033 int result = 0; 1033 if( !pVar-> IsObject() ){1034 if( !pVar->GetType().IsObject() ){ 1034 1035 //初期バッファにデータをセット 1035 1036 extern BYTE *initGlobalBuf; … … 1039 1040 AllInitGlobalVarSize); 1040 1041 1041 result = SetInitGlobalData(pVar-> offset,1042 *pVar,1043 pVar->GetSub ScriptsPtr(),1042 result = SetInitGlobalData(pVar->GetOffsetAddress(), 1043 pVar->GetType(), 1044 pVar->GetSubscripts(), 1044 1045 InitBuf); 1045 1046 } … … 1070 1071 const CMethod *method = type.GetClass().GetDestructorMethod(); 1071 1072 if( method ){ 1072 method-> pUserProc->Using();1073 method->GetUserProc().Using(); 1073 1074 } 1074 1075 } … … 1104 1105 1105 1106 //定数と2重定義されていないる場合は抜け出す 1106 if( CDBConst::obj.GetBasicType(VarName)){1107 if(compiler.GetMeta().GetGlobalConsts().GetBasicType(VarName)){ 1107 1108 return; 1108 1109 } 1109 1110 1110 1111 //定数マクロとして定義されている場合は抜け出す 1111 if(GetConstHash(VarName)){ 1112 if( compiler.GetMeta().GetGlobalConstMacros().IsExist( VarName ) ) 1113 { 1112 1114 return; 1113 1115 } … … 1115 1117 1116 1118 //構文を解析 1117 int SubScripts[MAX_ARRAYDIM];1118 1119 Type type; 1119 1120 char InitBuf[8192]; 1120 1121 char ConstractParameter[VN_SIZE]; 1121 if(!GetDimentionFormat(Parameter, VarName,SubScripts,type,InitBuf,ConstractParameter)) 1122 Subscripts subscripts; 1123 if(!GetDimentionFormat(Parameter, VarName,subscripts,type,InitBuf,ConstractParameter)) 1122 1124 return; 1123 1125 1124 1126 1125 1127 //定数と2重定義されていないかを調べる 1126 if( CDBConst::obj.GetBasicType(VarName)){1128 if(compiler.GetMeta().GetGlobalConsts().GetBasicType(VarName)){ 1127 1129 SetError(15,VarName,cp); 1128 1130 return; … … 1130 1132 1131 1133 //定数マクロとして定義されている場合 1132 if( GetConstHash(VarName)){1134 if( compiler.GetMeta().GetGlobalConstMacros().IsExist( VarName ) ){ 1133 1135 SetError(15,VarName,cp); 1134 1136 return; … … 1165 1167 GetNowStaticVarFullName(VarName,temporary); 1166 1168 1167 dim( temporary, SubScripts,type,InitBuf,ConstractParameter,dwFlags );1169 dim( temporary,subscripts,type,InitBuf,ConstractParameter,dwFlags ); 1168 1170 1169 1171 /* … … 1173 1175 } 1174 1176 else{ 1175 dim( VarName, SubScripts,type,InitBuf,ConstractParameter,dwFlags );1177 dim( VarName,subscripts,type,InitBuf,ConstractParameter,dwFlags ); 1176 1178 } 1177 1179 }
Note:
See TracChangeset
for help on using the changeset viewer.