Changeset 206 in dev for trunk/abdev/BasicCompiler_Common/src/Procedure.cpp
- Timestamp:
- Jul 12, 2007, 2:58:26 AM (17 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/abdev/BasicCompiler_Common/src/Procedure.cpp
r201 r206 1 #include "stdafx.h" 2 3 #include <jenga/include/smoothie/Smoothie.h> 1 4 #include <jenga/include/smoothie/SmoothieException.h> 2 5 #include <jenga/include/smoothie/LexicalAnalysis.h> 3 6 4 7 #include <Compiler.h> 5 #include <Procedure Impl.h>8 #include <Procedure.h> 6 9 #include <NamespaceSupporter.h> 7 10 … … 13 16 #endif 14 17 15 bool UserProcImpl::SetParamsAndReturnType( const char *sourceOfParams, int nowLine, bool isStatic ){ 18 19 std::string UserProc::GetFullName() const 20 { 21 if( HasParentClass() ){ 22 return GetParentClass().GetName() + "." + GetName(); 23 } 24 25 return GetName(); 26 } 27 const NamespaceScopes &UserProc::GetNamespaceScopes() const 28 { 29 if( HasParentClass() ){ 30 return GetParentClassPtr()->GetNamespaceScopes(); 31 } 32 return namespaceScopes; 33 } 34 const NamespaceScopesCollection &UserProc::GetImportedNamespaces() const 35 { 36 return importedNamespaces; 37 } 38 bool UserProc::IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const 39 { 40 if( GetName() != name ){ 41 return false; 42 } 43 44 return compiler.GetNamespaceSupporter().IsSameAreaNamespace( GetNamespaceScopes(), namespaceScopes ); 45 } 46 bool UserProc::IsEqualSymbol( const UserProc &globalProc ) const 47 { 48 return IsEqualSymbol( globalProc.GetNamespaceScopes(), globalProc.GetName() ); 49 } 50 bool UserProc::IsEqualSymbol( const string &fullName ) const 51 { 52 char AreaName[VN_SIZE] = ""; //オブジェクト変数 53 char NestName[VN_SIZE] = ""; //入れ子メンバ 54 bool isNest = SplitMemberName( fullName.c_str(), AreaName, NestName ); 55 56 return IsEqualSymbol( NamespaceScopes( AreaName ), NestName ); 57 } 58 bool UserProc::IsVirtual() const 59 { 60 if( pMethod == NULL ){ 61 return false; 62 } 63 return ( pMethod->IsVirtual() != 0 ); 64 } 65 66 bool UserProc::SetParamsAndReturnType( const char *sourceOfParams, int nowLine, bool isStatic ){ 16 67 int i = 0; 17 68 int i2,i3,sw; … … 51 102 //パラメータ名 52 103 bool isArray = false; 53 int subScripts[MAX_ARRAYDIM];104 Subscripts subscripts; 54 105 char name[VN_SIZE]; 55 106 sw=0; … … 83 134 84 135 if((name[i2-2]=='('&&name[i2-1]==')')|| 85 (name[i2-2]=='['&&name[i2-1]==']')) {86 subScripts[0]=LONG_MAX;87 sub Scripts[1]=-1;136 (name[i2-2]=='['&&name[i2-1]==']')) 137 { 138 subscripts.push_back( LONG_MAX ); 88 139 89 140 name[i2-2]=0; 90 141 } 91 142 else{ 92 GetArrange(name,temp2,sub Scripts);143 GetArrange(name,temp2,subscripts); 93 144 lstrcpy(name,temp2); 94 145 } … … 152 203 Parameter *pParam = new Parameter( name, type, isRef, initValue ); 153 204 if( isArray ){ 154 pParam->SetArray( sub Scripts );205 pParam->SetArray( subscripts ); 155 206 } 156 207 … … 189 240 //パラメータ名 190 241 bool isArray = false; 191 int subScripts[MAX_ARRAYDIM];242 Subscripts subscripts; 192 243 char name[VN_SIZE]; 193 244 sw=0; … … 221 272 222 273 if((name[i2-2]=='('&&name[i2-1]==')')|| 223 (name[i2-2]=='['&&name[i2-1]==']')) {224 subScripts[0]=LONG_MAX;225 sub Scripts[1]=-1;274 (name[i2-2]=='['&&name[i2-1]==']')) 275 { 276 subscripts.push_back( LONG_MAX ); 226 277 227 278 name[i2-2]=0; 228 279 } 229 280 else{ 230 GetArrange(name,temp2,sub Scripts);281 GetArrange(name,temp2,subscripts); 231 282 lstrcpy(name,temp2); 232 283 } … … 273 324 Parameter *pParam = new Parameter( name, type, isRef ); 274 325 if( isArray ){ 275 pParam->SetArray( sub Scripts );326 pParam->SetArray( subscripts ); 276 327 } 277 328 … … 376 427 } 377 428 378 const NamespaceScopes &GlobalProc::GetNamespaceScopes() const 379 { 380 if( HasParentClass() ){ 381 return GetParentClassPtr()->GetNamespaceScopes(); 382 } 383 return namespaceScopes; 384 } 385 bool GlobalProc::IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const 429 const UserProc *UserProc::pCompilingUserProc = NULL; 430 431 432 bool UserProcs::Insert( UserProc *pUserProc, int nowLine ) 433 { 434 ///////////////////////////////// 435 // ハッシュデータに追加 436 ///////////////////////////////// 437 438 if( !Put( pUserProc ) ) 439 { 440 // 重複しているため、失敗 441 SetError(15,pUserProc->GetName().c_str(),nowLine); 442 return false; 443 } 444 445 return true; 446 } 447 UserProc *UserProcs::Add( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, char *buffer,int nowLine,bool isVirtual,CClass *pobj_c, bool isStatic) 448 { 449 int i2,i3; 450 char temporary[8192]; 451 452 int i=1; 453 454 Procedure::Kind kind = Procedure::Sub; 455 bool isMacro = false; 456 if(buffer[i]==ESC_FUNCTION) kind = Procedure::Function; 457 if(buffer[i]==ESC_MACRO){ 458 isMacro = true; 459 } 460 461 i++; 462 463 bool isCdecl = false; 464 bool isExport = false; 465 while(1){ 466 if(buffer[i]==1&&buffer[i+1]==ESC_CDECL&& isCdecl == false ){ 467 isCdecl = true; 468 469 i+=2; 470 } 471 else if(buffer[i]==1&&buffer[i+1]==ESC_EXPORT&& isExport == false ){ 472 isExport = true; 473 474 i+=2; 475 } 476 else break; 477 } 478 479 i2=0; 480 if(buffer[i]==1&&buffer[i+1]==ESC_OPERATOR){ 481 if(!pobj_c){ 482 SetError(126,NULL,nowLine); 483 return 0; 484 } 485 486 //オペレータの場合 487 temporary[i2++]=buffer[i++]; 488 temporary[i2++]=buffer[i++]; 489 490 int iCalcId; 491 if(buffer[i]=='='&&buffer[i+1]=='='){ 492 iCalcId=CALC_EQUAL; 493 i3=2; 494 } 495 else if(buffer[i]=='='){ 496 iCalcId=CALC_SUBSITUATION; 497 i3=1; 498 } 499 else if(buffer[i]=='('){ 500 iCalcId=CALC_AS; 501 i3=0; 502 } 503 else if(buffer[i]=='['&&buffer[i+1]==']'&&buffer[i+2]=='='){ 504 iCalcId=CALC_ARRAY_SET; 505 i3=3; 506 } 507 else if(buffer[i]=='['&&buffer[i+1]==']'){ 508 iCalcId=CALC_ARRAY_GET; 509 i3=2; 510 } 511 else{ 512 iCalcId=GetCalcId(buffer+i,&i3); 513 i3++; 514 } 515 if(!iCalcId){ 516 SetError(1,NULL,nowLine); 517 return 0; 518 } 519 temporary[i2++]=iCalcId; 520 temporary[i2]=0; 521 522 i+=i3; 523 } 524 else{ 525 if(pobj_c){ 526 //クラスメンバの場合、デストラクタには~が付くことを考慮 527 if(buffer[i]=='~'){ 528 temporary[i2]='~'; 529 i++; 530 i2++; 531 } 532 } 533 534 for(;;i++,i2++){ 535 if(!IsVariableChar(buffer[i])){ 536 temporary[i2]=0; 537 break; 538 } 539 temporary[i2]=buffer[i]; 540 } 541 } 542 543 if( isMacro ){ 544 //大文字に変換 545 CharUpper(temporary); 546 547 //マクロ関数の場合は名前リストに追加 548 macroNames.push_back( temporary ); 549 } 550 551 if(!pobj_c){ 552 //クラスメンバ以外の場合のみ 553 //重複チェック 554 555 if(GetDeclareHash(temporary)){ 556 SetError(15,temporary,nowLine); 557 return 0; 558 } 559 } 560 561 // 識別ID 562 static int id_base=0; 563 564 UserProc *pUserProc = new UserProc( namespaceScopes, importedNamespaces, temporary, kind, isMacro, isCdecl, isExport, (id_base++) ); 565 pUserProc->SetParentClass( pobj_c ); 566 if( Smoothie::isFullCompile ){ 567 // すべての関数・メソッドをコンパイルする 568 pUserProc->Using(); 569 } 570 571 if(isExport){ 572 pUserProc->Using(); 573 } 574 575 // パラメータを解析 576 // ※第1パラメータにに指定するデータの例:"( s As String ) As String" 577 pUserProc->SetParamsAndReturnType( buffer + i, nowLine, isStatic ); 578 579 pUserProc->_paramStr = buffer + i; 580 581 // ハッシュに追加 582 if( !Insert( pUserProc, nowLine ) ) 583 { 584 return NULL; 585 } 586 587 return pUserProc; 588 } 589 void UserProcs::EnumGlobalProcs( const char *simpleName, const char *localName, std::vector<const UserProc *> &subs ) 590 { 591 /////////////////////////// 592 // グローバル関数を検索 593 /////////////////////////// 594 595 // ハッシュ値を取得 596 UserProc *pUserProc = GetHashArrayElement( simpleName ); 597 while(pUserProc){ 598 if(!pUserProc->GetParentClassPtr()){ 599 if( pUserProc->IsEqualSymbol( localName ) ){ 600 subs.push_back( pUserProc ); 601 } 602 } 603 604 pUserProc=pUserProc->GetChainNext(); 605 } 606 } 607 608 609 bool DllProc::IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const 386 610 { 387 611 if( GetName() != name ){ 388 612 return false; 389 613 } 390 391 return compiler.GetNamespaceSupporter().IsSameAreaNamespace( GetNamespaceScopes(), namespaceScopes ); 392 } 393 bool GlobalProc::IsEqualSymbol( const GlobalProc &globalProc ) const 394 { 395 return IsEqualSymbol( globalProc.GetNamespaceScopes(), globalProc.GetName() ); 396 } 397 bool GlobalProc::IsEqualSymbol( const string &fullName ) const 614 return compiler.GetNamespaceSupporter().IsSameAreaNamespace( this->GetNamespaceScopes(), namespaceScopes ); 615 } 616 bool DllProc::IsEqualSymbol( const string &fullName ) const 398 617 { 399 618 char AreaName[VN_SIZE] = ""; //オブジェクト変数 400 619 char NestName[VN_SIZE] = ""; //入れ子メンバ 401 bool isNest = CClass::SplitName( fullName.c_str(), AreaName, NestName ); 402 403 return IsEqualSymbol( NamespaceScopes( AreaName ), NestName ); 404 } 405 406 bool DllProcImpl::IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const 407 { 408 if( GetName() != name ){ 409 return false; 410 } 411 return compiler.GetNamespaceSupporter().IsSameAreaNamespace( this->GetNamespaceScopes(), namespaceScopes ); 412 } 413 bool DllProcImpl::SetParamsAndReturnType( const char *sourceOfParams, int nowLine ){ 620 bool isNest = SplitMemberName( fullName.c_str(), AreaName, NestName ); 621 622 if( IsEqualSymbol( NamespaceScopes( AreaName ), NestName ) ){ 623 return true; 624 } 625 626 if( isNest ){ 627 // 静的メンバを考慮 628 629 char AreaName2[VN_SIZE] = ""; //オブジェクト変数 630 char NestName2[VN_SIZE] = ""; //入れ子メンバ 631 bool isNest = SplitMemberName( AreaName, AreaName2, NestName2 ); 632 lstrcat( NestName2, "." ); 633 lstrcat( NestName2, NestName ); 634 635 return IsEqualSymbol( NamespaceScopes( AreaName2 ), NestName2 ); 636 } 637 638 return false; 639 } 640 bool DllProc::SetParamsAndReturnType( const char *sourceOfParams, int nowLine ){ 414 641 int i = 0; 415 642 int i2,i3,sw; … … 443 670 //パラメータ名 444 671 bool isArray = false; 445 int subScripts[MAX_ARRAYDIM];672 Subscripts subscripts; 446 673 char name[VN_SIZE]; 447 674 sw=0; … … 475 702 476 703 if((name[i2-2]=='('&&name[i2-1]==')')|| 477 (name[i2-2]=='['&&name[i2-1]==']')) {478 subScripts[0]=LONG_MAX;479 sub Scripts[1]=-1;704 (name[i2-2]=='['&&name[i2-1]==']')) 705 { 706 subscripts.push_back( LONG_MAX ); 480 707 481 708 name[i2-2]=0; 482 709 } 483 710 else{ 484 GetArrange(name,temp2,sub Scripts);711 GetArrange(name,temp2,subscripts); 485 712 lstrcpy(name,temp2); 486 713 } … … 528 755 Parameter *pParam = new Parameter( name, type, isRef ); 529 756 if( isArray ){ 530 pParam->SetArray( sub Scripts );757 pParam->SetArray( subscripts ); 531 758 } 532 759 … … 584 811 } 585 812 586 bool ProcPointer Impl::SetParamsAndReturnType( const char *sourceOfParams, int nowLine ){813 bool ProcPointer::SetParamsAndReturnType( const char *sourceOfParams, int nowLine ){ 587 814 int i = 0; 588 815 int i2,i3,sw; … … 615 842 //パラメータ名 616 843 bool isArray = false; 617 int subScripts[MAX_ARRAYDIM];844 Subscripts subscripts; 618 845 char name[VN_SIZE]; 619 846 sw=0; … … 647 874 648 875 if((name[i2-2]=='('&&name[i2-1]==')')|| 649 (name[i2-2]=='['&&name[i2-1]==']')) {650 subScripts[0]=LONG_MAX;651 sub Scripts[1]=-1;876 (name[i2-2]=='['&&name[i2-1]==']')) 877 { 878 subscripts.push_back( LONG_MAX ); 652 879 653 880 name[i2-2]=0; 654 881 } 655 882 else{ 656 GetArrange(name,temp2,sub Scripts);883 GetArrange(name,temp2,subscripts); 657 884 lstrcpy(name,temp2); 658 885 } … … 699 926 Parameter *pParam = new Parameter( name, type, isRef ); 700 927 if( isArray ){ 701 pParam->SetArray( sub Scripts );928 pParam->SetArray( subscripts ); 702 929 } 703 930 … … 771 998 } 772 999 773 int ProcPointers Impl::Add( const string &typeExpression )1000 int ProcPointers::Add( const string &typeExpression ) 774 1001 { 775 1002 DWORD dwProcType = (DWORD)typeExpression[2]; … … 781 1008 } 782 1009 783 ProcPointer *pProcPointer = new ProcPointer Impl( kind );1010 ProcPointer *pProcPointer = new ProcPointer( kind ); 784 1011 785 1012 //buffer[0]は'('となっている … … 792 1019 } 793 1020 794 void ProcPointers Impl::Clear()795 { 796 ProcPointers Impl&procPointers = *this;1021 void ProcPointers::Clear() 1022 { 1023 ProcPointers &procPointers = *this; 797 1024 BOOST_FOREACH( ProcPointer *pProcPointer, procPointers ){ 798 1025 delete pProcPointer;
Note:
See TracChangeset
for help on using the changeset viewer.