Changeset 206 in dev for trunk/abdev/BasicCompiler_Common/Subroutine.cpp
- Timestamp:
- Jul 12, 2007, 2:58:26 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abdev/BasicCompiler_Common/Subroutine.cpp
r199 r206 1 #include "stdafx.h" 2 1 3 #include <jenga/include/smoothie/Smoothie.h> 2 4 #include <jenga/include/smoothie/LexicalAnalysis.h> 3 5 4 6 #include <Compiler.h> 5 #include <Procedure Impl.h>7 #include <Procedure.h> 6 8 #include <NamespaceSupporter.h> 7 9 … … 103 105 ///////////////////// 104 106 105 UserProc *pUserProc = (UserProc *)pProc;107 const UserProc *pUserProc = (const UserProc *)pProc; 106 108 107 109 //オブジェクト名を取得 … … 115 117 //////////////////////// 116 118 117 std::vector< UserProc *> subs;119 std::vector<const UserProc *> subs; 118 120 GetOverloadSubHash(fullCallName,subs); 119 121 if(subs.size()){ … … 194 196 195 197 //オーバーロード用の関数リストを作成 196 std::vector< UserProc *> subs;198 std::vector<const UserProc *> subs; 197 199 GetOverloadSubHash(VarName,subs); 198 200 if(subs.size()==0){ … … 210 212 211 213 //オーバーロードを解決 212 UserProc *pUserProc; 213 pUserProc=OverloadSolutionWithStrParam(VarName,subs,Parameter,ObjectName); 214 const UserProc *pUserProc = OverloadSolutionWithStrParam(VarName,subs,Parameter,ObjectName); 214 215 215 216 if(pUserProc){ … … 238 239 239 240 //オーバーロード用の関数リストを作成 240 std::vector< UserProc *> subs;241 std::vector<const UserProc *> subs; 241 242 GetOverloadSubHash(VarName,subs); 242 243 if(subs.size()==0){ … … 254 255 255 256 //オーバーロードを解決 256 UserProc *pUserProc; 257 pUserProc=OverloadSolutionWithStrParam(VarName,subs,Parameter,ObjectName); 257 const UserProc *pUserProc = OverloadSolutionWithStrParam(VarName,subs,Parameter,ObjectName); 258 258 259 259 if(pUserProc){ … … 266 266 //インデクサ(getter)の戻り値を取得 267 267 bool GetReturnTypeOfIndexerGetterProc( const CClass &objClass, Type &resultType ){ 268 vector< UserProc *> subs;268 vector<const UserProc *> subs; 269 269 objClass.GetMethods().Enum( CALC_ARRAY_GET, subs ); 270 270 if( subs.size() == 0 ){ … … 369 369 370 370 // オブジェクトを生成 371 DllProc *pDllProc = new DllProc Impl( namespaceScopes, procName, kind, isCdecl, dllFileName, alias );371 DllProc *pDllProc = new DllProc( namespaceScopes, procName, kind, isCdecl, dllFileName, alias ); 372 372 373 373 // パラメータを解析 … … 429 429 } 430 430 431 GlobalProc *AddSubData( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, char *buffer,int nowLine,bool isVirtual,CClass *pobj_c, bool isStatic){ 432 int i2,i3; 433 char temporary[8192]; 434 435 int i=1; 436 437 Procedure::Kind kind = Procedure::Sub; 438 bool isMacro = false; 439 if(buffer[i]==ESC_FUNCTION) kind = Procedure::Function; 440 if(buffer[i]==ESC_MACRO){ 441 isMacro = true; 442 } 443 444 i++; 445 446 bool isCdecl = false; 447 bool isExport = false; 448 while(1){ 449 if(buffer[i]==1&&buffer[i+1]==ESC_CDECL&& isCdecl == false ){ 450 isCdecl = true; 451 452 i+=2; 453 } 454 else if(buffer[i]==1&&buffer[i+1]==ESC_EXPORT&& isExport == false ){ 455 isExport = true; 456 457 i+=2; 458 } 459 else break; 460 } 461 462 i2=0; 463 if(buffer[i]==1&&buffer[i+1]==ESC_OPERATOR){ 464 if(!pobj_c){ 465 SetError(126,NULL,nowLine); 466 return 0; 467 } 468 469 //オペレータの場合 470 temporary[i2++]=buffer[i++]; 471 temporary[i2++]=buffer[i++]; 472 473 int iCalcId; 474 if(buffer[i]=='='&&buffer[i+1]=='='){ 475 iCalcId=CALC_EQUAL; 476 i3=2; 477 } 478 else if(buffer[i]=='='){ 479 iCalcId=CALC_SUBSITUATION; 480 i3=1; 481 } 482 else if(buffer[i]=='('){ 483 iCalcId=CALC_AS; 484 i3=0; 485 } 486 else if(buffer[i]=='['&&buffer[i+1]==']'&&buffer[i+2]=='='){ 487 iCalcId=CALC_ARRAY_SET; 488 i3=3; 489 } 490 else if(buffer[i]=='['&&buffer[i+1]==']'){ 491 iCalcId=CALC_ARRAY_GET; 492 i3=2; 493 } 494 else{ 495 iCalcId=GetCalcId(buffer+i,&i3); 496 i3++; 497 } 498 if(!iCalcId){ 499 SetError(1,NULL,nowLine); 500 return 0; 501 } 502 temporary[i2++]=iCalcId; 503 temporary[i2]=0; 504 505 i+=i3; 506 } 507 else{ 508 if(pobj_c){ 509 //クラスメンバの場合、デストラクタには~が付くことを考慮 510 if(buffer[i]=='~'){ 511 temporary[i2]='~'; 512 i++; 513 i2++; 514 } 515 } 516 517 for(;;i++,i2++){ 518 if(!IsVariableChar(buffer[i])){ 519 temporary[i2]=0; 520 break; 521 } 522 temporary[i2]=buffer[i]; 523 } 524 } 525 526 if( isMacro ){ 527 //大文字に変換 528 CharUpper(temporary); 529 530 //マクロ関数の場合は名前リストに追加 531 extern char **ppMacroNames; 532 extern int MacroNum; 533 ppMacroNames=(char **)HeapReAlloc(hHeap,0,ppMacroNames,(MacroNum+1)*sizeof(char *)); 534 ppMacroNames[MacroNum]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1); 535 lstrcpy(ppMacroNames[MacroNum],temporary); 536 MacroNum++; 537 } 538 539 if(!pobj_c){ 540 //クラスメンバ以外の場合のみ 541 //重複チェック 542 543 if(GetDeclareHash(temporary)){ 544 SetError(15,temporary,nowLine); 545 return 0; 546 } 547 } 548 549 extern int SubNum; 550 SubNum++; 551 552 GlobalProc *pUserProc = new GlobalProc( namespaceScopes, importedNamespaces, temporary, kind, isMacro, isCdecl, isExport ); 553 pUserProc->SetParentClass( pobj_c ); 554 if( Smoothie::isFullCompile ){ 555 // すべての関数・メソッドをコンパイルする 556 pUserProc->Using(); 557 } 558 559 //ID 560 static int id_base=0; 561 pUserProc->id = (id_base++); 562 563 if(isExport){ 564 pUserProc->Using(); 565 } 566 567 // パラメータを解析 568 // ※第1パラメータにに指定するデータの例:"( s As String ) As String" 569 pUserProc->SetParamsAndReturnType( buffer + i, nowLine, isStatic ); 570 571 pUserProc->_paramStr = buffer + i; 572 573 574 ///////////////////////////////// 575 // ハッシュデータに追加 576 ///////////////////////////////// 577 578 int key; 579 key=hash_default(pUserProc->GetName().c_str()); 580 581 extern GlobalProc **ppSubHash; 582 if(ppSubHash[key]){ 583 GlobalProc *psi2; 584 psi2=ppSubHash[key]; 585 while(1){ 586 if(pobj_c==psi2->GetParentClassPtr()){ 587 //重複エラーチェックを行う 588 if( pUserProc->IsEqualSymbol( *psi2 ) ){ 589 if( psi2->Params().Equals( pUserProc->Params() ) ){ 590 SetError(15,pUserProc->GetName().c_str(),nowLine); 591 return 0; 592 } 593 } 594 } 595 596 if(psi2->pNextData==0) break; 597 psi2=psi2->pNextData; 598 } 599 psi2->pNextData=pUserProc; 600 } 601 else{ 602 ppSubHash[key]=pUserProc; 603 } 604 605 return pUserProc; 606 } 607 608 void GetSubInfo(void){ //サブルーチン情報を取得 431 void UserProcs::CollectUserProcs( const BasicSource &source, UserProcs &userProcs ) 432 { 609 433 extern HANDLE hHeap; 610 extern char *basbuf;611 434 int i,i2,i3; 612 435 char temporary[8192]; … … 617 440 618 441 //サブルーチン(ユーザー定義)情報を初期化 619 extern GlobalProc **ppSubHash; 620 extern int SubNum; 621 ppSubHash=(GlobalProc **)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,MAX_HASH*sizeof(GlobalProc *)); 622 SubNum=0; 623 624 //マクロ関数の名前リストを初期化 625 extern char **ppMacroNames; 626 extern int MacroNum; 627 ppMacroNames=(char **)HeapAlloc(hHeap,0,1); 628 MacroNum=0; 442 userProcs.Clear(); 629 443 630 444 // 名前空間管理 … … 640 454 i++; 641 455 642 if( basbuf[i]==1&&(basbuf[i+1]==ESC_CLASS||basbuf[i+1]==ESC_INTERFACE)){456 if(source[i]==1&&(source[i+1]==ESC_CLASS||source[i+1]==ESC_INTERFACE)){ 643 457 /* Class ~ End Class 644 458 Interface ~ End Interface 645 459 を飛び越す */ 646 i3=GetEndXXXCommand( basbuf[i+1]);460 i3=GetEndXXXCommand(source[i+1]); 647 461 for(i+=2,i2=0;;i++,i2++){ 648 if( basbuf[i]=='\0') break;649 if( basbuf[i]==1&&basbuf[i+1]==(char)i3){462 if(source[i]=='\0') break; 463 if(source[i]==1&&source[i+1]==(char)i3){ 650 464 i++; 651 465 break; 652 466 } 653 467 } 654 if( basbuf[i]=='\0') break;655 continue; 656 } 657 658 if( basbuf[i] == 1 && basbuf[i+1] == ESC_NAMESPACE ){468 if(source[i]=='\0') break; 469 continue; 470 } 471 472 if( source[i] == 1 && source[i+1] == ESC_NAMESPACE ){ 659 473 for(i+=2,i2=0;;i2++,i++){ 660 if( IsCommandDelimitation( basbuf[i] ) ){474 if( IsCommandDelimitation( source[i] ) ){ 661 475 temporary[i2]=0; 662 476 break; 663 477 } 664 temporary[i2]= basbuf[i];478 temporary[i2]=source[i]; 665 479 } 666 480 namespaceScopes.push_back( temporary ); … … 668 482 continue; 669 483 } 670 else if( basbuf[i] == 1 && basbuf[i+1] == ESC_ENDNAMESPACE ){484 else if( source[i] == 1 && source[i+1] == ESC_ENDNAMESPACE ){ 671 485 if( namespaceScopes.size() <= 0 ){ 672 486 SetError(12, "End Namespace", i ); … … 679 493 continue; 680 494 } 681 else if( basbuf[i] == 1 && basbuf[i+1] == ESC_IMPORTS ){495 else if( source[i] == 1 && source[i+1] == ESC_IMPORTS ){ 682 496 for(i+=2,i2=0;;i2++,i++){ 683 if( IsCommandDelimitation( basbuf[i] ) ){497 if( IsCommandDelimitation( source[i] ) ){ 684 498 temporary[i2]=0; 685 499 break; 686 500 } 687 temporary[i2]= basbuf[i];501 temporary[i2]=source[i]; 688 502 } 689 503 if( !compiler.GetNamespaceSupporter().ImportsNamespace( temporary ) ) … … 694 508 continue; 695 509 } 696 else if( basbuf[i] == 1 && basbuf[i+1] == ESC_CLEARNAMESPACEIMPORTED ){510 else if( source[i] == 1 && source[i+1] == ESC_CLEARNAMESPACEIMPORTED ){ 697 511 importedNamespaces.clear(); 698 512 continue; 699 513 } 700 514 701 if( basbuf[i]==1&&basbuf[i+1]==ESC_DECLARE){515 if(source[i]==1&&source[i+1]==ESC_DECLARE){ 702 516 for(i+=2,i2=0;;i2++,i++){ 703 if( basbuf[i]=='\n'){517 if(source[i]=='\n'){ 704 518 temporary[i2]=0; 705 519 break; 706 520 } 707 temporary[i2]= basbuf[i];708 if( basbuf[i]=='\0') break;521 temporary[i2]=source[i]; 522 if(source[i]=='\0') break; 709 523 } 710 524 AddDeclareData(namespaceScopes,temporary,i); … … 712 526 continue; 713 527 } 714 if( basbuf[i]==1&&(basbuf[i+1]==ESC_SUB||basbuf[i+1]==ESC_FUNCTION||basbuf[i+1]==ESC_MACRO)){715 char statementChar = basbuf[i+1];528 if(source[i]==1&&(source[i+1]==ESC_SUB||source[i+1]==ESC_FUNCTION||source[i+1]==ESC_MACRO)){ 529 char statementChar = source[i+1]; 716 530 717 531 for(i2=0;;i2++,i++){ 718 if(IsCommandDelimitation( basbuf[i])){532 if(IsCommandDelimitation(source[i])){ 719 533 temporary[i2]=0; 720 534 break; 721 535 } 722 temporary[i2]= basbuf[i];723 if( basbuf[i]=='\0') break;724 } 725 AddSubData(namespaceScopes, importedNamespaces, temporary,i,0,0);536 temporary[i2]=source[i]; 537 if(source[i]=='\0') break; 538 } 539 userProcs.Add(namespaceScopes, importedNamespaces, temporary,i,false,NULL,false); 726 540 727 541 /* Sub ~ End Sub … … 731 545 char endStatementChar = GetEndXXXCommand( statementChar ); 732 546 for(i2=0;;i++,i2++){ 733 if( basbuf[i] == '\0' ) break;734 if( basbuf[i] == 1 && basbuf[i+1] == endStatementChar ){547 if( source[i] == '\0' ) break; 548 if( source[i] == 1 && source[i+1] == endStatementChar ){ 735 549 i++; 736 550 break; 737 551 } 738 552 } 739 if( basbuf[i]=='\0') break;553 if(source[i]=='\0') break; 740 554 continue; 741 555 } … … 743 557 //次の行 744 558 for(;;i++){ 745 if(IsCommandDelimitation( basbuf[i])) break;746 } 747 if( basbuf[i]=='\0') break;559 if(IsCommandDelimitation(source[i])) break; 560 } 561 if(source[i]=='\0') break; 748 562 } 749 563 … … 755 569 756 570 sprintf(temporary,"%c%c_allrem()",1,ESC_SUB); 757 AddSubData( namespaceScopes, importedNamespaces, temporary,0,0,0);571 userProcs.Add( namespaceScopes, importedNamespaces, temporary,0,false,NULL,false); 758 572 759 573 sprintf(temporary,"%c%c_aullrem()",1,ESC_SUB); 760 AddSubData( namespaceScopes, importedNamespaces, temporary,0,0,0);574 userProcs.Add( namespaceScopes, importedNamespaces, temporary,0,false,NULL,false); 761 575 762 576 sprintf(temporary,"%c%c_allmul()",1,ESC_SUB); 763 AddSubData( namespaceScopes, importedNamespaces, temporary,0,0,0);577 userProcs.Add( namespaceScopes, importedNamespaces, temporary,0,false,NULL,false); 764 578 765 579 sprintf(temporary,"%c%c_alldiv()",1,ESC_SUB); 766 AddSubData( namespaceScopes, importedNamespaces, temporary,0,0,0);580 userProcs.Add( namespaceScopes, importedNamespaces, temporary,0,false,NULL,false); 767 581 768 582 sprintf(temporary,"%c%c_aulldiv()",1,ESC_SUB); 769 AddSubData( namespaceScopes, importedNamespaces, temporary,0,0,0);583 userProcs.Add( namespaceScopes, importedNamespaces, temporary,0,false,NULL,false); 770 584 771 585 sprintf(temporary,"%c%c_allshl()",1,ESC_SUB); 772 AddSubData( namespaceScopes, importedNamespaces, temporary,0,0,0);586 userProcs.Add( namespaceScopes, importedNamespaces, temporary,0,false,NULL,false); 773 587 774 588 sprintf(temporary,"%c%c_allshr()",1,ESC_SUB); 775 AddSubData( namespaceScopes, importedNamespaces, temporary,0,0,0);589 userProcs.Add( namespaceScopes, importedNamespaces, temporary,0,false,NULL,false); 776 590 777 591 sprintf(temporary,"%c%c_aullshr()",1,ESC_SUB); 778 AddSubData( namespaceScopes, importedNamespaces, temporary,0,0,0);592 userProcs.Add( namespaceScopes, importedNamespaces, temporary,0,false,NULL,false); 779 593 780 594 sprintf(temporary,"%c%c_System_InitStaticLocalVariables()",1,ESC_SUB); 781 AddSubData( namespaceScopes, importedNamespaces, temporary,0,0,0); 782 } 783 void Delete_si(GlobalProc *pUserProc){ 784 if(pUserProc->pNextData) Delete_si(pUserProc->pNextData); 785 delete pUserProc; 786 } 787 void DeleteSubInfo(GlobalProc **ppSubHash,char **ppMacroNames,int MacroNum){ //サブルーチン情報のメモリ解放 788 int i; 789 for(i=0;i<MAX_HASH;i++){ 790 if(!ppSubHash[i]) continue; 791 792 Delete_si(ppSubHash[i]); 793 } 794 HeapDefaultFree(ppSubHash); 795 796 //マクロの名前リスト 797 if(ppMacroNames){ 798 for(i=0;i<MacroNum;i++){ 799 HeapDefaultFree(ppMacroNames[i]); 800 } 801 HeapDefaultFree(ppMacroNames); 802 } 595 userProcs.Add( namespaceScopes, importedNamespaces, temporary,0,false,NULL,false); 803 596 } 804 597 void Delete_di(DllProc *pDllProc){ … … 820 613 821 614 bool IsNeedProcCompile(){ 822 for(int i2=0;i2<MAX_HASH;i2++){ 823 extern GlobalProc **ppSubHash; 824 GlobalProc *pUserProc=ppSubHash[i2]; 825 while(pUserProc){ 826 if( pUserProc->IsUsing() && pUserProc->IsCompiled() == false ){ 827 return true; 828 } 829 830 pUserProc=pUserProc->pNextData; 615 compiler.GetMeta().GetUserProcs().Iterator_Reset(); 616 while( compiler.GetMeta().GetUserProcs().Iterator_HasNext() ) 617 { 618 UserProc *pUserProc = compiler.GetMeta().GetUserProcs().Iterator_GetNext(); 619 if( pUserProc->IsUsing() && pUserProc->IsCompiled() == false ){ 620 return true; 831 621 } 832 622 }
Note:
See TracChangeset
for help on using the changeset viewer.