Changeset 206 in dev for trunk/abdev/BasicCompiler_Common/src
- Timestamp:
- Jul 12, 2007, 2:58:26 AM (17 years ago)
- Location:
- trunk/abdev/BasicCompiler_Common/src
- Files:
-
- 4 added
- 1 deleted
- 9 edited
- 3 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/abdev/BasicCompiler_Common/src/Class.cpp
r204 r206 1 #include "stdafx.h" 2 1 3 #include <jenga/include/smoothie/Smoothie.h> 2 #include <jenga/include/smoothie/Class.h>3 4 #include <jenga/include/smoothie/Source.h> 4 5 #include <jenga/include/smoothie/SmoothieException.h> 5 6 #include <jenga/include/smoothie/LexicalAnalysis.h> 6 7 7 #include <Class Impl.h>8 #include <Class.h> 8 9 #include <Compiler.h> 9 10 #include <NamespaceSupporter.h> … … 15 16 #include "../../BasicCompiler32/opcode.h" 16 17 #endif 17 18 19 18 20 19 … … 77 76 78 77 79 bool ClassImpl::IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const 80 { 81 if( GetName() != name ){ 78 bool CClass::IsClass() const 79 { 80 return classType == CClass::Class; 81 } 82 bool CClass::IsInterface() const 83 { 84 return classType == CClass::Interface; 85 } 86 bool CClass::IsEnum() const 87 { 88 return classType == CClass::Enum; 89 } 90 bool CClass::IsDelegate() const 91 { 92 return classType == CClass::Delegate; 93 } 94 bool CClass::IsStructure() const 95 { 96 return classType == CClass::Structure; 97 } 98 99 100 // コンストラクタのコンパイルを開始 101 void CClass::NotifyStartConstructorCompile() const 102 { 103 isCompilingConstructor = true; 104 } 105 106 //コンストラクタのコンパイルを終了 107 void CClass::NotifyFinishConstructorCompile() const 108 { 109 isCompilingConstructor = false; 110 } 111 112 //コンストラクタをコンパイル中かどうかを判別 113 bool CClass::IsCompilingConstructor() const 114 { 115 return isCompilingConstructor; 116 } 117 118 //デストラクタのコンパイルを開始 119 void CClass::NotifyStartDestructorCompile() const{ 120 isCompilingDestructor = true; 121 } 122 123 //デストラクタのコンパイルを終了 124 void CClass::NotifyFinishDestructorCompile() const{ 125 isCompilingDestructor = false; 126 } 127 128 //デストラクタをコンパイル中かどうかを判別 129 bool CClass::IsCompilingDestructor() const 130 { 131 return isCompilingDestructor; 132 } 133 134 //自身の派生クラスかどうかを確認 135 bool CClass::IsSubClass( const CClass *pClass ) const 136 { 137 if( !pClass->HasSuperClass() ) 138 { 82 139 return false; 83 140 } 84 141 85 return compiler.GetNamespaceSupporter().IsSameAreaNamespace( GetNamespaceScopes(), namespaceScopes ); 86 } 87 88 bool ClassImpl::Inherits( const char *inheritNames, int nowLine ){ 142 const CClass *pTempClass = &pClass->GetSuperClass(); 143 while( pTempClass ){ 144 if( this == pTempClass ) return true; 145 pTempClass = &pTempClass->GetSuperClass(); 146 } 147 return false; 148 } 149 150 //自身と等しいまたは派生クラスかどうかを確認 151 bool CClass::IsEqualsOrSubClass( const CClass *pClass ) const 152 { 153 if( IsEquals( pClass ) ) return true; 154 return IsSubClass( pClass ); 155 } 156 157 // 自身と等しいまたは派生クラス、基底クラスかどうかを確認 158 bool CClass::IsEqualsOrSubClassOrSuperClass( const CClass &objClass ) const 159 { 160 if( IsEquals( &objClass ) ) return true; 161 if( IsSubClass( &objClass ) ) return true; 162 if( objClass.IsSubClass( this ) ) return true; 163 return false; 164 } 165 166 bool CClass::IsInheritsInterface( const CClass *pInterfaceClass ) const 167 { 168 BOOST_FOREACH( const InheritedInterface &objInterface, interfaces ){ 169 if( pInterfaceClass == &objInterface.GetInterfaceClass() ){ 170 return true; 171 } 172 } 173 return false; 174 } 175 176 bool CClass::Inherits( const char *inheritNames, int nowLine ){ 89 177 int i = 0; 90 178 bool isInheritsClass = false; … … 183 271 return true; 184 272 } 185 bool C lassImpl::InheritsClass( const CClass &inheritsClass, int nowLine ){273 bool CClass::InheritsClass( const CClass &inheritsClass, int nowLine ){ 186 274 187 275 //ループ継承でないかをチェック … … 245 333 return true; 246 334 } 247 bool C lassImpl::InheritsInterface( const CClass &inheritsInterface, int nowLine ){335 bool CClass::InheritsInterface( const CClass &inheritsInterface, int nowLine ){ 248 336 249 337 //ループ継承でないかをチェック … … 291 379 return true; 292 380 } 293 CMember *C lassImpl::CreateMember( Prototype::Accessibility accessibility, bool isConst, bool isRef, char *buffer, int nowLine )381 CMember *CClass::CreateMember( Prototype::Accessibility accessibility, bool isConst, bool isRef, char *buffer, int nowLine ) 294 382 { 295 383 extern int cp; … … 299 387 char initBuffer[VN_SIZE]; 300 388 char lpszConstructParameter[VN_SIZE]; 301 int SubScripts[MAX_ARRAYDIM];389 Subscripts subscripts; 302 390 Type type; 303 GetDimentionFormat(buffer,VarName, SubScripts,type,initBuffer,lpszConstructParameter);391 GetDimentionFormat(buffer,VarName,subscripts,type,initBuffer,lpszConstructParameter); 304 392 305 393 //重複チェック … … 308 396 } 309 397 310 CMember *pMember = new CMember( accessibility, VarName, type, isConst, initBuffer, lpszConstructParameter );398 CMember *pMember = new CMember( accessibility, VarName, type, isConst, subscripts, initBuffer, lpszConstructParameter ); 311 399 pMember->source_code_address = nowLine; 312 memcpy( pMember->SubScripts, SubScripts, MAX_ARRAYDIM * sizeof(int) );313 400 return pMember; 314 401 } 315 void C lassImpl::AddMember( Prototype::Accessibility accessibility, bool isConst, bool isRef, char *buffer, int nowLine ){402 void CClass::AddMember( Prototype::Accessibility accessibility, bool isConst, bool isRef, char *buffer, int nowLine ){ 316 403 dynamicMembers.push_back( 317 404 CreateMember( accessibility, isConst, isRef, buffer, nowLine ) 318 405 ); 319 406 } 320 void C lassImpl::AddStaticMember( Prototype::Accessibility accessibility, bool isConst, bool isRef, char *buffer, int nowLine ){407 void CClass::AddStaticMember( Prototype::Accessibility accessibility, bool isConst, bool isRef, char *buffer, int nowLine ){ 321 408 staticMembers.push_back( 322 409 CreateMember( accessibility, isConst, isRef, buffer, nowLine ) … … 324 411 } 325 412 326 void C lassImpl::AddMethod(CClass *pobj_c, Prototype::Accessibility accessibility, BOOL bStatic, bool isConst, bool isAbstract,413 void CClass::AddMethod(CClass *pobj_c, Prototype::Accessibility accessibility, BOOL bStatic, bool isConst, bool isAbstract, 327 414 bool isVirtual, bool isOverride, char *buffer, int nowLine){ 328 415 int i,i2; … … 340 427 341 428 //関数ハッシュへ登録 342 GlobalProc *pUserProc; 343 pUserProc=AddSubData( NamespaceScopes(), NamespaceScopesCollection(), buffer,nowLine,isVirtual,pobj_c, (bStatic!=0) ); 429 UserProc *pUserProc = compiler.GetMeta().GetUserProcs().Add( NamespaceScopes(), NamespaceScopesCollection(), buffer,nowLine,isVirtual,pobj_c, (bStatic!=0) ); 344 430 if(!pUserProc) return; 345 431 … … 394 480 if( pMethod->GetInheritsClassPtr() ) continue; 395 481 396 if( pMethod-> pUserProc->GetName() == temporary ){397 if( pMethod-> pUserProc->Params().Equals( pUserProc->Params() ) ){482 if( pMethod->GetUserProc().GetName() == temporary ){ 483 if( pMethod->GetUserProc().Params().Equals( pUserProc->Params() ) ){ 398 484 //関数名、パラメータ属性が合致したとき 399 485 SetError(15,pUserProc->GetName().c_str(),nowLine); … … 408 494 //メソッドのオーバーライド 409 495 BOOST_FOREACH( CMethod *pMethod, pobj_c->GetMethods() ){ 410 if( pMethod-> pUserProc->GetName() == temporary ){411 if( pMethod-> pUserProc->Params().Equals( pUserProc->Params() ) ){496 if( pMethod->GetUserProc().GetName() == temporary ){ 497 if( pMethod->GetUserProc().Params().Equals( pUserProc->Params() ) ){ 412 498 413 499 if(pMethod->IsVirtual()){ 414 500 //メンバ関数を上書き 415 pMethod-> pUserProc=pUserProc;501 pMethod->SetUserProcPtr( pUserProc ); 416 502 pMethod->Override(); 417 503 … … 446 532 } 447 533 448 LONG_PTR ClassImpl::GetVtblGlobalOffset(void) const 534 bool CClass::DupliCheckAll(const char *name){ 535 //重複チェック 536 537 //メンバ 538 if(DupliCheckMember(name)) return 1; 539 540 //メソッド 541 BOOST_FOREACH( const CMethod *pMethod, methods ){ 542 if( lstrcmp( name, pMethod->GetUserProc().GetName().c_str() ) == 0 ){ 543 return 1; 544 } 545 } 546 547 return 0; 548 } 549 bool CClass::DupliCheckMember(const char *name){ 550 //重複チェック 551 552 // 動的メンバ 553 BOOST_FOREACH( CMember *pMember, dynamicMembers ){ 554 if( GetName() == pMember->GetName() ){ 555 return 1; 556 } 557 } 558 559 // 静的メンバ 560 BOOST_FOREACH( CMember *pMember, staticMembers ){ 561 if( GetName() == pMember->GetName() ){ 562 return 1; 563 } 564 } 565 566 return 0; 567 } 568 569 //サイズを取得 570 int CClass::GetSize() const 571 { 572 return GetMemberOffset( NULL, NULL ); 573 } 574 575 //メンバのオフセットを取得 576 int CClass::GetMemberOffset( const char *memberName, int *pMemberNum ) const 577 { 578 int i2; 579 580 //仮想関数が存在する場合は関数リストへのポインタのサイズを追加 581 int offset = IsExistVirtualFunctions() ? PTR_SIZE : 0; 582 583 int alignment; 584 if(iAlign) alignment=iAlign; 585 else alignment=1; 586 587 int iMaxAlign=0; 588 int i = -1; 589 BOOST_FOREACH( CMember *pMember, dynamicMembers ){ 590 i++; 591 592 i2 = pMember->GetType().GetSize(); 593 594 //アラインメントを算出 595 int member_size; 596 if( pMember->GetType().IsStruct() ){ 597 //メンバクラスのアラインメントを取得 598 member_size=pMember->GetType().GetClass().GetAlignment(); 599 } 600 else{ 601 //メンバサイズを取得 602 member_size=i2; 603 } 604 if(iMaxAlign<member_size) iMaxAlign=member_size; 605 606 //アラインメントを考慮 607 if(iAlign&&iAlign<member_size){ 608 if(offset%alignment) offset+=alignment-(offset%alignment); 609 } 610 else{ 611 if(alignment<member_size) alignment=member_size; 612 613 if(member_size==0){ 614 //メンバを持たないクラス 615 //※何もしない(オフセットの計算をしない) 616 } 617 else{ 618 if(offset%member_size) offset+=member_size-(offset%member_size); 619 } 620 } 621 622 if(memberName){ 623 //メンバ指定がある場合は、オフセットを返す 624 if( pMember->GetName() == memberName ){ 625 if(pMemberNum) *pMemberNum=i; 626 return offset; 627 } 628 } 629 630 //配列を考慮したメンバサイズを取得 631 member_size = i2 * Variable::GetSubScriptCounts( pMember->GetSubscripts() ); 632 633 //メンバサイズを加算 634 offset+= member_size; 635 } 636 637 if(iMaxAlign<alignment) alignment=iMaxAlign; 638 639 //アラインメントを考慮 640 if(alignment){ 641 if(offset%alignment) offset+=alignment-(offset%alignment); 642 } 643 644 if(pMemberNum) *pMemberNum=i; 645 return offset; 646 } 647 int CClass::GetAlignment() const 648 { 649 //仮想関数が存在する場合は関数リストへのポインタのサイズを追加 650 int alignment = IsExistVirtualFunctions() ? PTR_SIZE : 0; 651 652 BOOST_FOREACH( CMember *pMember, dynamicMembers ){ 653 int member_size; 654 if(pMember->GetType().IsStruct()){ 655 //メンバクラスのアラインメントを取得 656 member_size=pMember->GetType().GetClass().GetAlignment(); 657 } 658 else{ 659 //メンバサイズを取得 660 member_size = pMember->GetType().GetSize(); 661 } 662 663 //アラインメントをセット 664 if(alignment<member_size) alignment=member_size; 665 } 666 667 if(alignment==0) return 0; 668 669 if(iAlign) alignment=iAlign; 670 671 return alignment; 672 } 673 int CClass::GetFuncNumInVtbl( const UserProc *pUserProc ) const 674 { 675 int n = 0; 676 BOOST_FOREACH( const CMethod *pMethod, methods ){ 677 if( &pMethod->GetUserProc() == pUserProc ) break; 678 if( pMethod->IsVirtual() ) n++; 679 } 680 return n; 681 } 682 LONG_PTR CClass::GetVtblGlobalOffset(void) const 449 683 { 450 684 … … 458 692 ////////////////////////////////////// 459 693 460 UserProc **ppsi;461 ppsi=( UserProc **)malloc(GetVtblNum()*sizeof(UserProc *));694 const UserProc **ppsi; 695 ppsi=(const UserProc **)malloc(GetVtblNum()*sizeof(UserProc *)); 462 696 463 697 //関数テーブルに値をセット … … 465 699 BOOST_FOREACH( const CMethod *pMethod, methods ){ 466 700 if(pMethod->IsVirtual()){ 467 pMethod-> pUserProc->Using();701 pMethod->GetUserProc().Using(); 468 702 469 703 if(pMethod->IsAbstract()){ … … 474 708 } 475 709 else{ 476 ppsi[i2]= pMethod->pUserProc;710 ppsi[i2]=&pMethod->GetUserProc(); 477 711 } 478 712 i2++; … … 490 724 return vtbl_offset; 491 725 } 492 void C lassImpl::ActionVtblSchedule(LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection){726 void CClass::ActionVtblSchedule(LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection){ 493 727 if(vtbl_offset==-1) return; 494 728 … … 501 735 pUserProc=(UserProc *)pVtbl[i]; 502 736 if(!pUserProc) continue; 503 pVtbl[i]=pUserProc->beginOpAddress+ImageBase+MemPos_CodeSection; 504 } 505 } 506 507 CClass *ClassesImpl::Create( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const char *name){ 508 return new ClassImpl(namespaceScopes, importedNamespaces, name); 509 } 510 511 void ClassesImpl::CollectClassesForNameOnly( const BasicSource &source ) 737 pVtbl[i]=pUserProc->GetBeginOpAddress()+ImageBase+MemPos_CodeSection; 738 } 739 } 740 bool CClass::IsAbstract() const 741 { 742 // 未実装(abstract)の仮想関数を持つ場合はtrueを返す 743 744 BOOST_FOREACH( const CMethod *pMethod, methods ){ 745 if(pMethod->IsVirtual()){ 746 if(pMethod->IsAbstract()){ 747 return true; 748 } 749 } 750 } 751 752 return false; 753 } 754 755 756 int Classes::GetHashCode(const char *name) const 757 { 758 int key; 759 760 for(key=0;*name!='\0';name++){ 761 key=((key<<8)+ *name )%MAX_CLASS_HASH; 762 } 763 764 return key; 765 } 766 767 CClass *Classes::Create( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const char *name){ 768 return new CClass(namespaceScopes, importedNamespaces, name); 769 } 770 bool Classes::Insert( CClass *pClass ) 771 { 772 // キャッシュしておくクラス 773 if( pClass->GetName() == "String" ) 774 { 775 pStringClass=pClass; 776 } 777 else if( pClass->GetName() == "Object" ) 778 { 779 pObjectClass = pClass; 780 } 781 782 ///////////////////////////////// 783 // ハッシュデータに追加 784 ///////////////////////////////// 785 786 int key; 787 key=GetHashCode( pClass->GetName().c_str() ); 788 789 if(pobj_ClassHash[key]){ 790 CClass *pobj_c2; 791 pobj_c2=pobj_ClassHash[key]; 792 while(1){ 793 if( ((const Prototype *)pobj_c2)->IsEqualSymbol( *(const Prototype *)pClass ) ){ 794 //名前空間及びクラス名が重複した場合 795 SmoothieException::Throw(15,pClass->GetName()); 796 return false; 797 } 798 799 if(pobj_c2->pobj_NextClass==0) break; 800 pobj_c2=pobj_c2->pobj_NextClass; 801 } 802 pobj_c2->pobj_NextClass=pClass; 803 } 804 else{ 805 pobj_ClassHash[key]=pClass; 806 } 807 return true; 808 } 809 CClass *Classes::Add( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const char *name,int nowLine){ 810 ////////////////////////////////////////////////////////////////////////// 811 // クラスを追加 812 // ※名前のみを登録。その他の情報はSetClassメソッドで! 813 ////////////////////////////////////////////////////////////////////////// 814 815 CClass *pClass = Create(namespaceScopes, importedNamespaces, name); 816 817 if( !Insert( pClass ) ) 818 { 819 return NULL; 820 } 821 822 return pClass; 823 } 824 825 void Classes::CollectClassesForNameOnly( const BasicSource &source ) 512 826 { 513 827 int i, i2; … … 641 955 } 642 956 643 void ClassesImpl::InitStaticMember(){ 957 void Classes::ActionVtblSchedule(LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection){ 958 int i; 959 for(i=0;i<MAX_CLASS_HASH;i++){ 960 if(pobj_ClassHash[i]){ 961 CClass *pobj_c; 962 pobj_c=pobj_ClassHash[i]; 963 while(1){ 964 pobj_c->ActionVtblSchedule(ImageBase,MemPos_CodeSection); 965 966 if(pobj_c->pobj_NextClass==0) break; 967 pobj_c=pobj_c->pobj_NextClass; 968 } 969 } 970 } 971 } 972 973 974 void Classes::InitStaticMember(){ 644 975 //静的メンバをグローバル領域に作成 645 976 … … 662 993 dim( 663 994 temporary, 664 member-> SubScripts,995 member->GetSubscripts(), 665 996 member->GetType(), 666 997 member->GetInitializeExpression().c_str(), … … 679 1010 cp=back_cp; 680 1011 } 681 bool Classes Impl::MemberVar_LoopRefCheck(const CClass &objClass){1012 bool Classes::MemberVar_LoopRefCheck(const CClass &objClass){ 682 1013 bool result = true; 683 1014 BOOST_FOREACH( CMember *pMember, objClass.GetDynamicMembers() ){ … … 704 1035 return result; 705 1036 } 706 void Classes Impl::GetClass_recur(const char *lpszInheritsClass){1037 void Classes::GetClass_recur(const char *lpszInheritsClass){ 707 1038 extern char *basbuf; 708 1039 int i,i2,i3,sub_address,top_pos; … … 1156 1487 compiler.GetNamespaceSupporter().GetLivingNamespaceScopes() = backupNamespaceScopes; 1157 1488 } 1158 void Classes Impl::GetAllClassInfo(void){1489 void Classes::GetAllClassInfo(void){ 1159 1490 //ループ継承チェック用のクラス 1160 1491 pobj_LoopRefCheck=new CLoopRefCheck(); … … 1169 1500 this->Iterator_Init(); 1170 1501 } 1171 void Classes Impl::Compile_System_InitializeUserTypes(){1502 void Classes::Compile_System_InitializeUserTypes(){ 1172 1503 char temporary[VN_SIZE]; 1173 1504 … … 1296 1627 } 1297 1628 1298 const CClass *Classes Impl::Find( const NamespaceScopes &namespaceScopes, const string &name ) const1629 const CClass *Classes::Find( const NamespaceScopes &namespaceScopes, const string &name ) const 1299 1630 { 1300 1631 int key; … … 1333 1664 return NULL; 1334 1665 } 1666 const CClass *Classes::Find( const string &fullName ) const 1667 { 1668 char AreaName[VN_SIZE] = ""; //オブジェクト変数 1669 char NestName[VN_SIZE] = ""; //入れ子メンバ 1670 bool isNest = SplitMemberName( fullName.c_str(), AreaName, NestName ); 1671 1672 return Find( NamespaceScopes( AreaName ), NestName ); 1673 } 1674 void Classes::StartCompile( const UserProc *pUserProc ){ 1675 const CClass *pParentClass = pUserProc->GetParentClassPtr(); 1676 if( pParentClass ){ 1677 pParentClass->Using(); 1678 1679 pCompilingMethod = pParentClass->GetMethods().GetMethodPtr( pUserProc ); 1680 if( !pCompilingMethod ){ 1681 pCompilingMethod = pParentClass->GetStaticMethods().GetMethodPtr( pUserProc ); 1682 if( !pCompilingMethod ){ 1683 SmoothieException::Throw(300); 1684 } 1685 } 1686 } 1687 else{ 1688 pCompilingMethod = NULL; 1689 } 1690 } 1691 1692 CClass *Classes::GetStringClassPtr() const 1693 { 1694 if( !pStringClass ){ 1695 SmoothieException::Throw(); 1696 return NULL; 1697 } 1698 return pStringClass; 1699 } 1700 CClass *Classes::GetObjectClassPtr() const 1701 { 1702 if( !pObjectClass ){ 1703 SmoothieException::Throw(); 1704 return NULL; 1705 } 1706 return pObjectClass; 1707 } 1708 1709 1710 ////////////////////// 1711 // イテレータ 1712 ////////////////////// 1713 1714 void Classes::Iterator_Init() const 1715 { 1716 if(ppobj_IteClass) free(ppobj_IteClass); 1717 1718 iIteMaxNum=0; 1719 iIteNextNum=0; 1720 ppobj_IteClass=(CClass **)malloc(1); 1721 1722 int i; 1723 for(i=0;i<MAX_CLASS_HASH;i++){ 1724 if(pobj_ClassHash[i]){ 1725 CClass *pobj_c; 1726 pobj_c=pobj_ClassHash[i]; 1727 while(1){ 1728 ppobj_IteClass=(CClass **)realloc(ppobj_IteClass,(iIteMaxNum+1)*sizeof(CClass *)); 1729 ppobj_IteClass[iIteMaxNum]=pobj_c; 1730 iIteMaxNum++; 1731 1732 if(pobj_c->pobj_NextClass==0) break; 1733 pobj_c=pobj_c->pobj_NextClass; 1734 } 1735 } 1736 } 1737 } 1738 void Classes::Iterator_Reset() const 1739 { 1740 iIteNextNum = 0; 1741 } 1742 BOOL Classes::Iterator_HasNext() const 1743 { 1744 if(iIteNextNum<iIteMaxNum) return 1; 1745 return 0; 1746 } 1747 CClass *Classes::Iterator_GetNext() const 1748 { 1749 CClass *pobj_c = ppobj_IteClass[iIteNextNum]; 1750 iIteNextNum++; 1751 return pobj_c; 1752 } 1753 int Classes::Iterator_GetMaxCount() const 1754 { 1755 return iIteMaxNum; 1756 } -
trunk/abdev/BasicCompiler_Common/src/CodeGenerator.cpp
r184 r206 1 #include "stdafx.h" 2 1 3 #include <windows.h> 2 4 #include <stdlib.h> -
trunk/abdev/BasicCompiler_Common/src/Compiler.cpp
r196 r206 1 #include <jenga/include/smoothie/Type.h> 1 #include "stdafx.h" 2 2 3 #include <jenga/include/smoothie/SmoothieException.h> 3 4 4 5 #include <Compiler.h> 6 #include <Type.h> 5 7 6 8 Compiler compiler; -
trunk/abdev/BasicCompiler_Common/src/Const.cpp
r201 r206 1 #include "stdafx.h" 2 1 3 #include <Compiler.h> 2 #include <NamespaceSupporter.h> 3 4 #include "common.h" 5 #include OPCODE_H_PATH //opcode.h 6 7 8 //シングルトンオブジェクト 9 CDBConst CDBConst::obj; 10 11 12 bool ConstBase::IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const 13 { 14 if( GetName() != name ){ 15 return false; 16 } 17 return compiler.GetNamespaceSupporter().IsSameAreaNamespace( this->namespaceScopes, namespaceScopes ); 18 } 19 bool ConstBase::IsEqualSymbol( const string &fullName ) const 20 { 21 char AreaName[VN_SIZE] = ""; //オブジェクト変数 22 char NestName[VN_SIZE] = ""; //入れ子メンバ 23 bool isNest = CClass::SplitName( fullName.c_str(), AreaName, NestName ); 24 25 return IsEqualSymbol( NamespaceScopes( AreaName ), NestName ); 26 } 27 28 29 30 31 CConst::CConst( const NamespaceScopes &namespaceScopes, const string &name, const Type &newType, _int64 i64data) 32 : ConstBase( namespaceScopes, name ) 33 , type( newType ) 34 , i64data( i64data ) 35 , pNext( NULL ) 36 { 37 } 38 CConst::CConst( const NamespaceScopes &namespaceScopes, const string &name, int value) 39 : ConstBase( namespaceScopes, name ) 40 , type( Type(DEF_LONG) ) 41 , i64data( value ) 42 , pNext( NULL ) 43 { 44 } 45 CConst::~CConst(){ 46 //連結先のオブジェクトを破棄 47 if(pNext){ 48 delete pNext; 49 pNext = 0; 50 } 51 } 52 53 Type CConst::GetType(){ 54 return type; 55 } 56 _int64 CConst::GetWholeData(){ 57 return i64data; 58 } 4 5 59 6 double CConst::GetDoubleData(){ 60 7 double dbl; … … 63 10 } 64 11 65 66 67 CConstMacro::CConstMacro( const NamespaceScopes &namespaceScopes, const string &name, char *Expression) 68 : ConstBase( namespaceScopes, name ) 69 { 70 } 71 CConstMacro::~CConstMacro(){ 72 } 73 74 75 76 77 78 CDBConst::CDBConst(){ 79 memset(this,0,sizeof(CDBConst)); 80 81 ppHash = (CConst **)calloc(MAX_HASH*sizeof(CConst *),1); 82 Init(); 83 } 84 CDBConst::~CDBConst(){ 85 Free(); 86 87 free(ppHash); 88 } 89 90 //解放 91 void CDBConst::Free(){ 12 void AddConst( const NamespaceScopes &namespaceScopes, char *buffer ){ 92 13 int i; 93 for(i=0; i<MAX_HASH; i++){94 if(ppHash[i]){95 delete ppHash[i];96 ppHash[i] = 0;97 }98 }99 }100 101 //初期化102 void CDBConst::Init(){103 Free();104 }105 106 void AddConstData(char *Command);107 void CDBConst::Add( const NamespaceScopes &namespaceScopes, char *buffer ){108 int i;109 14 110 15 //名前を取得 111 char Name[VN_SIZE];16 char name[VN_SIZE]; 112 17 for(i=0;;i++){ 113 18 if(buffer[i]=='\0'){ … … 116 21 } 117 22 if(buffer[i]=='='||buffer[i]=='('){ 118 Name[i]=0;23 name[i]=0; 119 24 break; 120 25 } 121 Name[i]=buffer[i];26 name[i]=buffer[i]; 122 27 } 123 28 124 29 //重複チェック 125 if(GetBasicType(Name)){ 126 SetError(15,Name,cp); 30 if( compiler.GetMeta().GetGlobalConstMacros().IsExist( name ) 31 || compiler.GetMeta().GetGlobalConsts().IsExist( name ) ) 32 { 33 SetError(15,name,cp); 127 34 return; 128 35 } … … 131 38 //定数マクロ 132 39 133 //未完成 134 AddConstData(buffer); 40 compiler.GetMeta().GetGlobalConstMacros().Add( namespaceScopes, name, buffer + i ); 135 41 } 136 42 else{ 137 43 //一般の定数 138 char *Expression = buffer + i + 1; 139 140 AddConst( namespaceScopes, Name,Expression); 141 } 142 } 143 144 void CDBConst::AddConst( const string &name, CConst *newconst){ 145 int key = hash_default(name.c_str()); 146 147 //ハッシュリストに追加 148 if(ppHash[key]){ 149 CConst *pConst = ppHash[key]; 150 while(pConst->pNext){ 151 pConst = pConst->pNext; 152 } 153 154 pConst->pNext = newconst; 155 } 156 else{ 157 ppHash[key] = newconst; 158 } 159 } 160 void CDBConst::AddConst( const NamespaceScopes &namespaceScopes, const string &name , char *Expression){ 44 char *expression = buffer + i + 1; 45 46 compiler.GetMeta().GetGlobalConsts().Add( namespaceScopes, name, expression ); 47 } 48 } 49 50 void Consts::Add( const NamespaceScopes &namespaceScopes, const string &name , char *Expression) 51 { 161 52 _int64 i64data; 162 53 Type resultType; … … 172 63 CConst *newconst = new CConst(namespaceScopes, name, resultType, i64data); 173 64 174 AddConst( name, newconst); 175 } 176 void CDBConst::AddConst(const NamespaceScopes &namespaceScopes, const string &name, int value){ 65 //ハッシュリストに追加 66 Put( newconst ); 67 } 68 void Consts::Add(const NamespaceScopes &namespaceScopes, const string &name, int value){ 177 69 CConst *newconst = new CConst( namespaceScopes, name, value); 178 70 179 AddConst(name, newconst); 180 } 181 182 CConst *CDBConst::GetObjectPtr( const string &name ){ 71 //ハッシュリストに追加 72 Put( newconst ); 73 } 74 75 CConst *Consts::GetObjectPtr( const string &name ){ 183 76 char ObjName[VN_SIZE]; //オブジェクト変数 184 77 char NestMember[VN_SIZE]; //入れ子メンバ 185 bool isObjectMember = CClass::SplitName( name.c_str(), ObjName, NestMember ); 186 187 //ハッシュ値を取得 188 int key; 189 key=hash_default( NestMember ); 190 191 //格納位置を取得 192 CConst *pConst; 193 pConst=ppHash[key]; 194 while(pConst){ 195 if( pConst->IsEqualSymbol( name ) ) break; 196 197 pConst=pConst->pNext; 78 bool isObjectMember = SplitMemberName( name.c_str(), ObjName, NestMember ); 79 80 CConst *pConst = GetHashArrayElement( NestMember ); 81 while( pConst ) 82 { 83 if( pConst->IsEqualSymbol( name ) ) 84 { 85 break; 86 } 87 pConst = pConst->GetChainNext(); 198 88 } 199 89 … … 202 92 203 93 204 int C DBConst::GetBasicType(char *Name){94 int Consts::GetBasicType(char *Name){ 205 95 CConst *pConst = GetObjectPtr(Name); 206 96 … … 209 99 return pConst->GetType().GetBasicType(); 210 100 } 211 _int64 C DBConst::GetWholeData(char *Name){101 _int64 Consts::GetWholeData(char *Name){ 212 102 CConst *pConst = GetObjectPtr(Name); 213 103 … … 216 106 return pConst->GetWholeData(); 217 107 } 218 double C DBConst::GetDoubleData(char *Name){108 double Consts::GetDoubleData(char *Name){ 219 109 CConst *pConst = GetObjectPtr(Name); 220 110 … … 223 113 return pConst->GetDoubleData(); 224 114 } 225 bool C DBConst::IsStringPtr( char *Name ){115 bool Consts::IsStringPtr( char *Name ){ 226 116 CConst *pConst = GetObjectPtr(Name); 227 117 … … 232 122 return ( type.GetBasicType() == typeOfPtrChar && type.GetIndex() == LITERAL_STRING ); 233 123 } 124 125 126 bool ConstMacro::GetCalcBuffer( const char *parameterStr, char *dest ) const 127 { 128 extern HANDLE hHeap; 129 int i2,i3,i4,num; 130 char temporary[VN_SIZE]; 131 char *pParms[MAX_PARMS]; 132 num=0; 133 i2=0; 134 while(1){ 135 i2=GetOneParameter(parameterStr,i2,temporary); 136 137 pParms[num]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1); 138 lstrcpy(pParms[num],temporary); 139 140 num++; 141 if(parameterStr[i2]=='\0') break; 142 } 143 if( num != this->GetParameters().size() ){ 144 extern int cp; 145 for(i2=0;i2<num;i2++) HeapDefaultFree(pParms[i2]); 146 SetError(10,GetName().c_str(),cp); 147 lstrcpy(dest,"0"); 148 return 1; 149 } 150 151 i2=0; 152 i4=0; 153 while(1){ 154 155 //数式内の項を取得 156 for(i3=0;;i2++,i3++){ 157 if(!IsVariableChar( this->GetExpression()[i2] )){ 158 temporary[i3]=0; 159 break; 160 } 161 temporary[i3] = this->GetExpression()[i2]; 162 } 163 164 //パラメータと照合する 165 for( i3=0; i3<(int)this->GetParameters().size(); i3++ ){ 166 if( this->GetParameters()[i3] == temporary ) break; 167 } 168 169 if( i3 == (int)this->GetParameters().size() ){ 170 //パラメータでないとき 171 lstrcpy(dest+i4,temporary); 172 i4+=lstrlen(temporary); 173 } 174 else{ 175 //パラメータのとき 176 lstrcpy(dest+i4,pParms[i3]); 177 i4+=lstrlen(pParms[i3]); 178 } 179 180 //演算子をコピー 181 for(;;i2++,i4++){ 182 if( this->GetExpression()[i2] == 1 ){ 183 dest[i4++] = this->GetExpression()[i2++]; 184 dest[i4] = this->GetExpression()[i2]; 185 continue; 186 } 187 if(IsVariableTopChar( this->GetExpression()[i2] )) break; 188 dest[i4] = this->GetExpression()[i2]; 189 if( this->GetExpression()[i2] == '\0' ) break; 190 } 191 192 if( this->GetExpression()[i2] == '\0' ) break; 193 } 194 195 for(i2=0;i2<num;i2++) HeapDefaultFree(pParms[i2]); 196 197 return 1; 198 } 199 200 // マクロ定数を追加するための関数 201 void ConstMacros::Add( const NamespaceScopes &namespaceScopes, const std::string &name, const char *parameterStr ) 202 { 203 std::vector<std::string> parameters; 204 205 int i = 0; 206 if(parameterStr[i]!='(') 207 { 208 SetError(); 209 return; 210 } 211 212 char temporary[VN_SIZE]; 213 int i2; 214 for(i++,i2=0;;i++,i2++){ 215 if(parameterStr[i]=='\0'){ 216 SetError(1,NULL,cp); 217 return; 218 } 219 if(parameterStr[i]==','||parameterStr[i]==')'){ 220 temporary[i2]=0; 221 222 parameters.push_back( temporary ); 223 224 if(parameterStr[i]==')'){ 225 i++; 226 if(parameterStr[i]!='='){ 227 extern int cp; 228 SetError(1,NULL,cp); 229 return; 230 } 231 break; 232 } 233 234 i2=-1; 235 continue; 236 } 237 temporary[i2]=parameterStr[i]; 238 } 239 240 //データ 241 lstrcpy(temporary,parameterStr+i+1); 242 243 Put( new ConstMacro( namespaceScopes, name, parameters, temporary ) ); 244 } 245 ConstMacro *ConstMacros::Find( const std::string &name ){ 246 char ObjName[VN_SIZE]; //オブジェクト変数 247 char NestMember[VN_SIZE]; //入れ子メンバ 248 bool isObjectMember = SplitMemberName( name.c_str(), ObjName, NestMember ); 249 250 ConstMacro *pConstMacro = GetHashArrayElement( NestMember ); 251 while( pConstMacro ) 252 { 253 if( pConstMacro->IsEqualSymbol( name ) ) 254 { 255 break; 256 } 257 pConstMacro = pConstMacro->GetChainNext(); 258 } 259 260 return pConstMacro; 261 } -
trunk/abdev/BasicCompiler_Common/src/DataTable.cpp
r184 r206 1 #include "stdafx.h" 2 1 3 #include <jenga/include/smoothie/Smoothie.h> 2 4 -
trunk/abdev/BasicCompiler_Common/src/Exception.cpp
r125 r206 1 #include "stdafx.h" 2 1 3 #include <Exception.h> 2 4 -
trunk/abdev/BasicCompiler_Common/src/LexicalScopingImpl.cpp
r184 r206 1 #include "stdafx.h" 2 1 3 #include <LexicalScopingImpl.h> 4 #include <Compiler.h> 2 5 3 6 #include "../common.h" … … 29 32 } 30 33 34 void LexicalScopesImpl::End(){ 35 if( level <= 0 ){ 36 SetError(); 37 return; 38 } 39 40 //デストラクタを呼ぶ 41 CallDestructorsOfScopeEnd(); 42 43 Variables &vars = UserProc::IsGlobalAreaCompiling() ? 44 compiler.GetMeta().GetGlobalVars() : 45 UserProc::CompilingUserProc().GetLocalVars(); 46 47 //使用済みローカル変数の生存チェックを外す 48 BOOST_FOREACH( Variable *pVar, vars ){ 49 if(pVar->bLiving&&pVar->GetScopeLevel()==level){ 50 pVar->bLiving=0; 51 extern int obp; 52 pVar->SetScopeEndAddress( obp ); 53 } 54 } 55 56 57 //スコープ抜け出しスケジュール 58 ppScopes[level]->RunScheduleOfBreak(); 59 60 61 //スコープレベルを下げる 62 delete ppScopes[level]; 63 level--; 64 } 65 31 66 // スコープ終了時のデストラクタ呼び出し 32 67 void LexicalScopesImpl::CallDestructorsOfScopeEnd(){ 33 68 34 Variables &vars = UserProc::IsGlobalAreaCompiling() ?35 globalVars:36 UserProc::CompilingUserProc(). localVars;69 Variables &vars = UserProc::IsGlobalAreaCompiling() ? 70 compiler.GetMeta().GetGlobalVars() : 71 UserProc::CompilingUserProc().GetLocalVars(); 37 72 38 73 … … 52 87 //同一レベルのレキシカルスコープのみを検知 53 88 if(!pVar->bLiving) continue; 54 if( pVar-> ScopeLevel!= GetNowLevel() ) continue;89 if( pVar->GetScopeLevel() != GetNowLevel() ) continue; 55 90 56 if( pVar-> IsStruct() && pVar->IsParameter() ){91 if( pVar->GetType().IsStruct() && pVar->IsParameter() ){ 57 92 //構造体パラメータを持つとき 58 93 … … 64 99 //mov rcx,qword ptr[rsp+offset] 65 100 op_mov_RM(sizeof(_int64),REG_RCX,REG_RSP, 66 -pVar-> offset,101 -pVar->GetOffsetAddress(), 67 102 MOD_BASE_DISP32); 68 103 obp-=sizeof(long); … … 73 108 74 109 //mov ecx,dword ptr[ebp+offset] 75 op_mov_RM(sizeof(long),REG_ECX,REG_EBP,-pVar-> offset,MOD_BASE_DISP32);110 op_mov_RM(sizeof(long),REG_ECX,REG_EBP,-pVar->GetOffsetAddress(),MOD_BASE_DISP32); 76 111 obp-=sizeof(long); 77 112 AddLocalVarAddrSchedule(); … … 83 118 84 119 //call free 85 extern UserProc *pSub_free;120 extern const UserProc *pSub_free; 86 121 op_call(pSub_free); 87 122 … … 96 131 if(indexSystemGC!=-1){ 97 132 //_System_GCオブジェクトのデストラクタの呼び出し処理 98 const CMethod *method = vars[indexSystemGC]->Get Class().GetDestructorMethod();133 const CMethod *method = vars[indexSystemGC]->GetType().GetClass().GetDestructorMethod(); 99 134 if( method ){ 100 Opcode_CallProc("", method->pUserProc,0,vars[indexSystemGC]->GetName().c_str(),DEF_OBJECT);135 Opcode_CallProc("",&method->GetUserProc(),0,vars[indexSystemGC]->GetName().c_str(),DEF_OBJECT); 101 136 } 102 137 } -
trunk/abdev/BasicCompiler_Common/src/NamespaceSupporter.cpp
r199 r206 1 #include "stdafx.h" 2 1 3 #include <jenga/include/smoothie/SmoothieException.h> 4 #include <jenga/include/smoothie/LexicalAnalysis.h> 2 5 3 6 #include <Compiler.h> -
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; -
trunk/abdev/BasicCompiler_Common/src/Program.cpp
r168 r206 1 #include "stdafx.h" 2 1 3 #include <jenga/include/common/Environment.h> 2 4 3 5 #include <Program.h> 4 6 5 Jenga::Common::Logger Program::logger( Jenga::Common::Environment::GetAppDir() + "\\logger.log" );7 Jenga::Common::Logger Program::logger( Jenga::Common::Environment::GetAppDir() + "\\logger.log", true ); -
trunk/abdev/BasicCompiler_Common/src/SmoothieImpl.cpp
r193 r206 1 #include "stdafx.h" 2 1 3 #include <jenga/include/smoothie/Smoothie.h> 2 4 3 5 #include <SmoothieImpl.h> 4 #include <Class Impl.h>5 #include <Procedure Impl.h>6 #include <Class.h> 7 #include <Procedure.h> 6 8 #include <LexicalScopingImpl.h> 7 9 -
trunk/abdev/BasicCompiler_Common/src/TypeDef.cpp
r199 r206 1 #include "stdafx.h" 2 1 3 #include <jenga/include/smoothie/Smoothie.h> 2 #include <jenga/include/smoothie/Class.h>3 4 #include <jenga/include/smoothie/SmoothieException.h> 5 #include <jenga/include/smoothie/LexicalAnalysis.h> 4 6 5 7 #include <TypeDef.h> … … 8 10 9 11 TypeDef::TypeDef( const NamespaceScopes &namespaceScopes, const string &name, const string &baseName, int nowLine ) 10 : namespaceScopes( namespaceScopes ) 11 , name( name ) 12 : Symbol( namespaceScopes, name ) 12 13 , baseName( baseName ) 13 14 { … … 17 18 } 18 19 } 19 TypeDef::~TypeDef(){ 20 } 21 20 /* 22 21 bool TypeDef::IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const 23 22 { … … 31 30 char AreaName[VN_SIZE] = ""; //オブジェクト変数 32 31 char NestName[VN_SIZE] = ""; //入れ子メンバ 33 bool isNest = CClass::SplitName( fullName.c_str(), AreaName, NestName );32 bool isNest = SplitMemberName( fullName.c_str(), AreaName, NestName ); 34 33 35 34 if( IsEqualSymbol( NamespaceScopes( AreaName ), NestName ) ){ … … 42 41 char AreaName2[VN_SIZE] = ""; //オブジェクト変数 43 42 char NestName2[VN_SIZE] = ""; //入れ子メンバ 44 bool isNest = CClass::SplitName( AreaName, AreaName2, NestName2 );43 bool isNest = SplitMemberName( AreaName, AreaName2, NestName2 ); 45 44 lstrcat( NestName2, "." ); 46 45 lstrcat( NestName2, NestName ); … … 50 49 51 50 return false; 52 } 51 }*/ 53 52 54 53 … … 74 73 char AreaName[VN_SIZE] = ""; //オブジェクト変数 75 74 char NestName[VN_SIZE] = ""; //入れ子メンバ 76 bool isNest = CClass::SplitName( fullName.c_str(), AreaName, NestName );75 bool isNest = SplitMemberName( fullName.c_str(), AreaName, NestName ); 77 76 78 77 return GetIndex( NamespaceScopes( AreaName ), NestName );
Note:
See TracChangeset
for help on using the changeset viewer.