Changeset 182 in dev for trunk/abdev/BasicCompiler_Common/VariableOpe.cpp
- Timestamp:
- Jun 24, 2007, 6:49:13 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abdev/BasicCompiler_Common/VariableOpe.cpp
r159 r182 1 #include <jenga/include/smoothie/Smoothie.h> 2 #include <jenga/include/smoothie/LexicalAnalysis.h> 3 4 #include <LexicalScopingImpl.h> 5 1 6 #include "../BasicCompiler_Common/common.h" 2 7 … … 7 12 #endif 8 13 9 BOOL IsVariableTopChar(char c){10 if((c>='A'&&c<='Z')||(c>='a'&&c<='z')||c=='_') return 1;11 return 0;12 }13 BOOL IsVariableChar(char c){14 if((c>='A'&&c<='Z')||(c>='a'&&c<='z')||(c>='0'&&c<='9')||15 c=='%'||c=='!'||c=='#'||c=='$'||16 c=='_'||c=='.') return 1;17 return 0;18 }19 14 BOOL IsPtrType(int type){ 20 15 if(type==-1) return 0; … … 119 114 return DEF_QWORD; 120 115 case DEF_CHAR: 121 if( isUnicode) return DEF_WORD;116 if( Smoothie::IsUnicode() ) return DEF_WORD; 122 117 return DEF_BYTE; 123 118 } … … 150 145 //文字型 151 146 else if( type == DEF_CHAR ){ 152 if( isUnicode) return sizeof( WORD );147 if( Smoothie::IsUnicode() ) return sizeof( WORD ); 153 148 return sizeof( BYTE ); 154 149 } … … 220 215 if(lpIndex==-1) lstrcpy(name,"VoidPtr"); 221 216 else{ 222 if( Smoothie:: meta.procPointers[lpIndex]->ReturnType().IsNull() )217 if( Smoothie::GetMeta().GetProcPointers()[lpIndex]->ReturnType().IsNull() ) 223 218 lstrcpy(name,"*Sub"); 224 219 else lstrcpy(name,"*Function"); … … 235 230 236 231 Type GetStringTypeInfo(){ 237 Type type( DEF_OBJECT, * pobj_DBClass->GetStringClassPtr() );232 Type type( DEF_OBJECT, *Smoothie::GetMeta().GetClasses().GetStringClassPtr() ); 238 233 return type; 239 234 } … … 248 243 } 249 244 250 /*TODO: 消す 251 bool FormatUseProcReturnObject( const char *term, char *procName, char *parameter, CClass::RefType &refType, char *member ){ 252 int p1 = 0, p2 = 0; 253 254 for( int i=0; term[i]!='\0' ; i++ ){ 255 256 if( term[i] == '[' ){ 257 i = JumpStringInBracket( term, i + 1 ); 258 if( term[i] == '\0' ) break; 259 continue; 260 } 261 if( term[i] == '(' ){ 262 int temp_p = i; 263 i = JumpStringInPare( term, i + 1 ) + 1; 264 if( term[i] == '\0' ) break; 265 if( term[i] == '.' 266 || term[i] == 1 && term[i] == ESC_PSMEM ){ 267 p1 = temp_p; 268 p2 = i; 269 } 270 continue; 271 } 272 } 273 if( !p1 ) return false; 274 275 //メソッド名 276 memcpy( procName, term, p1 ); 277 procName[p1] = 0; 278 279 //パラメータ 280 memcpy( parameter, term + p1 + 1, p2 - p1 - 2 ); 281 parameter[ p2 - p1 - 2 ] = 0; 282 283 //参照タイプ 284 if( term[p2] == '.' ){ 285 refType = CClass::Dot; 286 } 287 else{ 288 refType = CClass::Pointer; 289 p2++; 290 } 291 292 //メンバ 293 lstrcpy( member, term + p2 + 1 ); 294 295 return true; 296 }*/ 245 246 void GetArrange(char *variable,char *variAnswer,int *SubScripts){ 247 extern int cp; 248 int i,i2,i3,i4; 249 double dbl; 250 _int64 i64data; 251 BOOL bBracket; 252 char temporary[VN_SIZE]; 253 254 for(i=0;;i++){ 255 if(variable[i]=='('||variable[i]=='['){ 256 if(variable[i]=='[') bBracket=1; 257 else bBracket=0; 258 259 variAnswer[i]=0; 260 for(i++,i2=0,i3=0;;i++,i2++){ 261 if(variable[i]==','){ 262 temporary[i2]=0; 263 264 Type resultType; 265 if( !StaticCalculation(true, temporary,0,&i64data,resultType) ){ 266 return; 267 } 268 if(resultType.IsReal()){ 269 memcpy(&dbl,&i64data,sizeof(double)); 270 i64data=(_int64)dbl; 271 } 272 273 if(i64data<0){ 274 //error 275 SubScripts[i3]=0; 276 } 277 else SubScripts[i3]=(int)i64data; 278 i3++; 279 i2=-1; 280 continue; 281 } 282 if(variable[i]=='('){ 283 i4=GetStringInPare(temporary+i2,variable+i); 284 i2+=i4-1; 285 i+=i4-1; 286 continue; 287 } 288 if(variable[i]=='['){ 289 i4=GetStringInBracket(temporary+i2,variable+i); 290 i2+=i4-1; 291 i+=i4-1; 292 continue; 293 } 294 if(variable[i]==')'&&bBracket==0|| 295 variable[i]==']'&&bBracket){ 296 temporary[i2]=0; 297 if(i2==0){ 298 SubScripts[i3]=-2; 299 break; 300 } 301 302 Type resultType; 303 if( !StaticCalculation(true, temporary,0,&i64data,resultType) ){ 304 return; 305 } 306 if(resultType.IsReal()){ 307 memcpy(&dbl,&i64data,sizeof(double)); 308 i64data=(_int64)dbl; 309 } 310 311 if(i64data<0){ 312 //error 313 SubScripts[i3]=0; 314 } 315 else SubScripts[i3]=(int)i64data; 316 SubScripts[i3+1]=-1; 317 break; 318 } 319 if(variable[i]=='\"'){ 320 SetError(1,NULL,cp); 321 return; 322 } 323 temporary[i2]=variable[i]; 324 } 325 break; 326 } 327 variAnswer[i]=variable[i]; 328 if(variable[i]=='\0'){ 329 SubScripts[0]=-1; 330 break; 331 } 332 } 333 } 334 297 335 298 336 BOOL GetVarFormatString(char *buffer,char *array,char *array2,char *NestMember,CClass::RefType &refType){ … … 427 465 return i2; 428 466 } 429 void GetArrange(char *variable,char *variAnswer,int *SubScripts){430 extern int cp;431 int i,i2,i3,i4;432 double dbl;433 _int64 i64data;434 BOOL bBracket;435 char temporary[VN_SIZE];436 437 for(i=0;;i++){438 if(variable[i]=='('||variable[i]=='['){439 if(variable[i]=='[') bBracket=1;440 else bBracket=0;441 442 variAnswer[i]=0;443 for(i++,i2=0,i3=0;;i++,i2++){444 if(variable[i]==','){445 temporary[i2]=0;446 447 Type resultType;448 if( !StaticCalculation(true, temporary,0,&i64data,resultType) ){449 return;450 }451 if(resultType.IsReal()){452 memcpy(&dbl,&i64data,sizeof(double));453 i64data=(_int64)dbl;454 }455 456 if(i64data<0){457 //error458 SubScripts[i3]=0;459 }460 else SubScripts[i3]=(int)i64data;461 i3++;462 i2=-1;463 continue;464 }465 if(variable[i]=='('){466 i4=GetStringInPare(temporary+i2,variable+i);467 i2+=i4-1;468 i+=i4-1;469 continue;470 }471 if(variable[i]=='['){472 i4=GetStringInBracket(temporary+i2,variable+i);473 i2+=i4-1;474 i+=i4-1;475 continue;476 }477 if(variable[i]==')'&&bBracket==0||478 variable[i]==']'&&bBracket){479 temporary[i2]=0;480 if(i2==0){481 SubScripts[i3]=-2;482 break;483 }484 485 Type resultType;486 if( !StaticCalculation(true, temporary,0,&i64data,resultType) ){487 return;488 }489 if(resultType.IsReal()){490 memcpy(&dbl,&i64data,sizeof(double));491 i64data=(_int64)dbl;492 }493 494 if(i64data<0){495 //error496 SubScripts[i3]=0;497 }498 else SubScripts[i3]=(int)i64data;499 SubScripts[i3+1]=-1;500 break;501 }502 if(variable[i]=='\"'){503 SetError(1,NULL,cp);504 return;505 }506 temporary[i2]=variable[i];507 }508 break;509 }510 variAnswer[i]=variable[i];511 if(variable[i]=='\0'){512 SubScripts[0]=-1;513 break;514 }515 }516 }517 518 int GetTypeFromSimpleName(char *variable){519 extern char DefIntVari[26],DefSngVari[26],DefStrVari[26],divNum,dsvNum,dStrvNum;520 int i;521 char name[VN_SIZE];522 523 //構造体メンバの場合を考慮524 for(i=lstrlen(variable);i>0;i--){525 if(variable[i]=='.'){526 i++;527 break;528 }529 }530 531 for(;;i++){532 if(variable[i]=='('||variable[i]=='\0'){533 name[i]=0;534 break;535 }536 name[i]=variable[i];537 }538 //変数名から選択539 i--;540 if(name[i]=='#') return DEF_DOUBLE;541 if(name[i]=='!') return DEF_SINGLE;542 if(name[i]=='%') return DEF_INTEGER;543 return DEF_DOUBLE;544 }545 467 546 468 … … 571 493 572 494 //アクセシビリティをチェック 573 if( &objClass == pobj_CompilingClass ){495 if( &objClass == Smoothie::Temp::pCompilingClass ){ 574 496 //同一クラスオブジェクトの場合はプライベートアクセスを容認する 575 497 if( pMember->IsNoneAccess() ){ … … 645 567 // 名前空間を分離 646 568 char namespaceStr[VN_SIZE]="", simpleName[VN_SIZE]; 647 Smoothie:: meta.namespaceScopesCollection.SplitNamespace( variable, namespaceStr, simpleName );569 Smoothie::GetMeta().namespaceScopesCollection.SplitNamespace( variable, namespaceStr, simpleName ); 648 570 649 571 // 先頭オブジェクトまたはクラス名と入れ子メンバに分割 … … 675 597 } 676 598 677 if( pobj_CompilingClass){599 if(Smoothie::Temp::pCompilingClass){ 678 600 /////////////////////// 679 601 // クラスメンバの参照 … … 682 604 if(lstrcmpi(variable,"This")==0){ 683 605 //Thisオブジェクト 684 resultType.SetType( DEF_OBJECT, pobj_CompilingClass );606 resultType.SetType( DEF_OBJECT, Smoothie::Temp::pCompilingClass ); 685 607 return true; 686 608 } … … 695 617 696 618 bool isFound = false; 697 BOOST_FOREACH( CMember *pMember, pobj_CompilingClass->GetDynamicMembers() ){619 BOOST_FOREACH( CMember *pMember, Smoothie::Temp::pCompilingClass->GetDynamicMembers() ){ 698 620 if( pMember->GetName() == VarName ){ 699 621 isFound = true; … … 704 626 } 705 627 706 return GetMemberType(* pobj_CompilingClass,variable,resultType,1,isErrorEnabled);628 return GetMemberType(*Smoothie::Temp::pCompilingClass,variable,resultType,1,isErrorEnabled); 707 629 } 708 630 … … 738 660 } 739 661 740 int typeDefIndex = Smoothie:: meta.typeDefs.GetIndex( VarName );662 int typeDefIndex = Smoothie::GetMeta().typeDefs.GetIndex( VarName ); 741 663 if( typeDefIndex != -1 ){ 742 664 // TypeDef後の型名だったとき 743 lstrcpy( VarName, Smoothie:: meta.typeDefs[typeDefIndex].GetBaseName().c_str() );665 lstrcpy( VarName, Smoothie::GetMeta().typeDefs[typeDefIndex].GetBaseName().c_str() ); 744 666 } 745 667 … … 755 677 } 756 678 757 if( pobj_CompilingClass){679 if(Smoothie::Temp::pCompilingClass){ 758 680 //自身のクラスから静的メンバを参照する場合 759 681 char temp2[VN_SIZE]; 760 sprintf(temp2,"%s.%s", pobj_CompilingClass->GetName().c_str(),VarName);682 sprintf(temp2,"%s.%s",Smoothie::Temp::pCompilingClass->GetName().c_str(),VarName); 761 683 762 684 pVar = globalVars.Find( Symbol( temp2 ) ); … … 972 894 if( InitBuf[0] == '\0' ){ 973 895 //As指定も、初期値指定もない場合 974 type.SetBasicType( GetTypeFromSimpleName(variable) );896 type.SetBasicType( Type::GetBasicTypeFromSimpleName(variable) ); 975 897 976 898 i2=lstrlen(variable)-1; … … 1015 937 1016 938 //クラス名 1017 if( pobj_CompilingClass){1018 lstrcat(FullName, pobj_CompilingClass->GetName().c_str());939 if(Smoothie::Temp::pCompilingClass){ 940 lstrcat(FullName,Smoothie::Temp::pCompilingClass->GetName().c_str()); 1019 941 lstrcat(FullName,"%"); 1020 942 } … … 1052 974 bool isConst = ( dwFlag & DIMFLAG_CONST ) ? true:false; 1053 975 1054 Variable *pVar = new Variable( Smoothie:: Lexical::liveingNamespaceScopes, name, type, isConst );976 Variable *pVar = new Variable( Smoothie::Temp::liveingNamespaceScopes, name, type, isConst ); 1055 977 1056 978 if( SubScripts[0] != -1 ){ … … 1063 985 1064 986 //レキシカルスコープ 1065 pVar->ScopeLevel= obj_LexScopes.GetNowLevel();1066 pVar->ScopeStartAddress= obj_LexScopes.GetStartAddress();987 pVar->ScopeLevel=GetLexicalScopes().GetNowLevel(); 988 pVar->ScopeStartAddress=GetLexicalScopes().GetStartAddress(); 1067 989 pVar->bLiving=TRUE; 1068 990
Note:
See TracChangeset
for help on using the changeset viewer.