Changeset 270 in dev
- Timestamp:
- Aug 9, 2007, 3:18:40 AM (17 years ago)
- Location:
- trunk/abdev
- Files:
-
- 2 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abdev/BasicCompiler32/BasicCompiler.vcproj
r266 r270 1297 1297 </File> 1298 1298 <File 1299 RelativePath="..\BasicCompiler_Common\src\Meta.cpp" 1300 > 1301 </File> 1302 <File 1299 1303 RelativePath="..\BasicCompiler_Common\src\Method.cpp" 1300 1304 > … … 1478 1482 </File> 1479 1483 <File 1484 RelativePath="..\BasicCompiler_Common\include\ObjectModule.h" 1485 > 1486 </File> 1487 <File 1480 1488 RelativePath="..\BasicCompiler_Common\include\Parameter.h" 1481 1489 > -
trunk/abdev/BasicCompiler64/BasicCompiler.vcproj
r266 r270 368 368 </File> 369 369 <File 370 RelativePath="..\BasicCompiler_Common\include\ObjectModule.h" 371 > 372 </File> 373 <File 370 374 RelativePath="..\BasicCompiler_Common\include\Parameter.h" 371 375 > … … 1156 1160 </File> 1157 1161 <File 1162 RelativePath="..\BasicCompiler_Common\src\Meta.cpp" 1163 > 1164 </File> 1165 <File 1158 1166 RelativePath="..\BasicCompiler_Common\src\Method.cpp" 1159 1167 > -
trunk/abdev/BasicCompiler_Common/Intermediate_Step1.cpp
r269 r270 253 253 254 254 compiler.staticLibraryFilePaths.push_back( temporary ); 255 256 ObjectModule *pStaticLibrary = new ObjectModule(); 257 pStaticLibrary->ReadText( temporary ); 258 compiler.staticLibraries.push_back( pStaticLibrary ); 255 259 256 260 for(;;i2++){ … … 361 365 362 366 bool isBeforeCharDelimitation = false; 363 temporary=(char *)HeapAlloc(hHeap,HEAP_ZERO_MEMORY, lstrlen(buffer)*2);367 temporary=(char *)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,(lstrlen(buffer)+255)*2); 364 368 for(i=0,i2=0,IsStr=0;;i++,i2++){ 365 369 if(buffer[i]=='\"') IsStr^=1; -
trunk/abdev/BasicCompiler_Common/include/Class.h
r266 r270 31 31 typedef vector<InheritedInterface> Interfaces; 32 32 33 class CClass: public Prototype 33 class CClass: public Prototype, public Jenga::Common::ObjectInHashmap<CClass> 34 34 { 35 35 public: … … 148 148 } 149 149 150 virtual const std::string &GetKeyName() const 151 { 152 return GetName(); 153 } 154 virtual bool IsDuplication( const CClass *pClass ) const 155 { 156 if( pClass->IsEqualSymbol( *this ) ) 157 { 158 return true; 159 } 160 return false; 161 } 162 150 163 void Readed(){ 151 164 isReady = true; … … 355 368 }; 356 369 357 #define MAX_CLASS_HASH 65535 358 class Classes 370 class Classes : public Jenga::Common::Hashmap<CClass> 359 371 { 360 CClass *pobj_ClassHash[MAX_CLASS_HASH];361 int GetHashCode(const char *name) const;362 363 372 // XMLシリアライズ用 364 private:365 friend class boost::serialization::access;366 BOOST_SERIALIZATION_SPLIT_MEMBER();367 template<class Archive> void load(Archive& ar, const unsigned int version)368 {369 trace_for_serialize( "serializing(load) - Classes" );370 371 std::vector<CClass *> vectorClasses;372 ar & BOOST_SERIALIZATION_NVP( vectorClasses );373 374 // 読み込み後の処理375 Clear();376 BOOST_FOREACH( CClass *pClass, vectorClasses )377 {378 Insert( pClass );379 }380 Iterator_Init();381 }382 template<class Archive> void save(Archive& ar, const unsigned int version) const383 {384 trace_for_serialize( "serializing(save) - Classes" );385 386 // 保存準備387 std::vector<CClass *> vectorClasses;388 vectorClasses.clear();389 Iterator_Reset();390 while( Iterator_HasNext() )391 {392 vectorClasses.push_back( dynamic_cast<CClass *>(Iterator_GetNext()) );393 }394 395 ar & BOOST_SERIALIZATION_NVP( vectorClasses );396 }397 398 373 public: 399 374 Classes() … … 401 376 , pStringClass( NULL ) 402 377 , pObjectClass( NULL ) 403 , ppobj_IteClass( NULL ) 404 , iIteMaxNum( 0 ) 405 , iIteNextNum( 0 ) 406 { 407 memset( pobj_ClassHash, 0, MAX_CLASS_HASH * sizeof(CClass *) ); 378 { 408 379 } 409 380 ~Classes() 410 381 { 411 for(int i=0;i<MAX_CLASS_HASH;i++){412 if(pobj_ClassHash[i]) DestroyClass(pobj_ClassHash[i]);413 }414 }415 void DestroyClass(CClass *pobj_c)416 {417 if(pobj_c->pobj_NextClass){418 DestroyClass(pobj_c->pobj_NextClass);419 }420 421 delete pobj_c;422 }423 void Clear()424 {425 if(ppobj_IteClass)426 {427 free(ppobj_IteClass);428 ppobj_IteClass = NULL;429 }430 // TODO: ここはこれでいいのか…431 memset( pobj_ClassHash, 0, MAX_CLASS_HASH * sizeof(CClass *) );432 382 } 433 383 … … 473 423 CClass *GetStringClassPtr() const; 474 424 CClass *GetObjectClassPtr() const; 475 476 477 /////////////////////478 // イテレータ479 /////////////////////480 private:481 mutable CClass **ppobj_IteClass;482 mutable int iIteMaxNum;483 mutable int iIteNextNum;484 public:485 void Iterator_Init() const;486 void Iterator_Reset() const;487 BOOL Iterator_HasNext() const;488 CClass *Iterator_GetNext() const;489 int Iterator_GetMaxCount() const;490 425 }; -
trunk/abdev/BasicCompiler_Common/include/Compiler.h
r269 r270 6 6 #include <DataTable.h> 7 7 #include <CodeGenerator.h> 8 #include <ObjectModule.h> 8 9 #include <Linker.h> 9 10 … … 28 29 { 29 30 delete pObjectModule; 31 Clear(); 30 32 } 33 void Clear() 34 { 35 BOOST_FOREACH( ObjectModule *pStaticLibrary, staticLibraries ) 36 { 37 delete pStaticLibrary; 38 } 39 staticLibraries.clear(); 40 } 41 42 void StaticLink( ObjectModules &staticLibraries ); 31 43 32 44 NamespaceSupporter &GetNamespaceSupporter() … … 46 58 // 静的リンクするオブジェクトファイル 47 59 std::vector<std::string> staticLibraryFilePaths; 60 61 // 静的リンクするオブジェクトモジュール 62 ObjectModules staticLibraries; 48 63 49 64 // オブジェクトモジュール … … 98 113 99 114 100 101 115 static bool StringToType( const std::string &typeName, Type &type ); 102 116 static const std::string TypeToString( const Type &type ); -
trunk/abdev/BasicCompiler_Common/include/Hashmap.h
r215 r270 52 52 } 53 53 54 // 内容を破棄せずにすべて抜き取る 55 void PullOutAll() 56 { 57 memset( hashArray, 0, MAX_HASHMAP*sizeof(T*) ); 58 } 59 54 60 bool Put( T* value ) 55 61 { … … 81 87 82 88 T* GetHashArrayElement( const char *keyName ) 89 { 90 return hashArray[GetHash(keyName)]; 91 } 92 const T* GetHashArrayElement( const char *keyName ) const 83 93 { 84 94 return hashArray[GetHash(keyName)]; … … 222 232 return pNextObject; 223 233 } 234 const T *GetChainNext() const 235 { 236 return pNextObject; 237 } 224 238 void SetChainNext( T *pNextObject ) 225 239 { -
trunk/abdev/BasicCompiler_Common/include/Linker.h
r268 r270 1 1 #pragma once 2 3 class ObjectModule : public Jenga::Common::BoostSerializationSupport<ObjectModule>4 {5 public:6 // メタ情報7 Meta meta;8 9 // グローバル領域のネイティブコード10 NativeCode globalNativeCode;11 12 // データテーブル13 DataTable dataTable;14 15 // XMLシリアライズ用16 private:17 virtual const char *RootTagName() const18 {19 return "objectModule";20 }21 friend class boost::serialization::access;22 template<class Archive> void serialize(Archive& ar, const unsigned int version)23 {24 trace_for_serialize( "serializing - objectModule" );25 26 ar & BOOST_SERIALIZATION_NVP( meta );27 ar & BOOST_SERIALIZATION_NVP( globalNativeCode );28 ar & BOOST_SERIALIZATION_NVP( dataTable );29 }30 };31 2 32 3 class Linker -
trunk/abdev/BasicCompiler_Common/include/Meta.h
r256 r270 70 70 { 71 71 } 72 73 // 静的リンク 74 void StaticLink( Meta &meta ); 72 75 73 76 const NamespaceScopesCollection &GetNamespaces() const -
trunk/abdev/BasicCompiler_Common/include/Procedure.h
r266 r270 58 58 59 59 public: 60 bool isTargetObjectModule; 60 61 Procedure( const NamespaceScopes &namespaceScopes, const string &name, Kind kind, bool isCdecl ) 61 62 : Symbol( namespaceScopes, name ) … … 64 65 , isUsing( false ) 65 66 , codePos( -1 ) 67 , isTargetObjectModule( true ) 66 68 { 67 69 } 68 70 Procedure() 71 : isTargetObjectModule( true ) 69 72 { 70 73 } -
trunk/abdev/BasicCompiler_Common/include/option.h
r215 r270 37 37 38 38 // XMLシリアライズに関するログを生成する 39 #define USE_TRACE_FOR_SERIALIZE39 //#define USE_TRACE_FOR_SERIALIZE 40 40 41 41 // ソースコードステップに関するログを生成する -
trunk/abdev/BasicCompiler_Common/src/Class.cpp
r266 r270 758 758 } 759 759 760 761 int Classes::GetHashCode(const char *name) const762 {763 int key;764 765 for(key=0;*name!='\0';name++){766 key=((key<<8)+ *name )%MAX_CLASS_HASH;767 }768 769 return key;770 }771 772 760 CClass *Classes::Create( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const char *name){ 773 761 return new CClass(namespaceScopes, importedNamespaces, name); … … 789 777 ///////////////////////////////// 790 778 791 int key; 792 key=GetHashCode( pClass->GetName().c_str() ); 793 794 if(pobj_ClassHash[key]){ 795 CClass *pobj_c2; 796 pobj_c2=pobj_ClassHash[key]; 797 while(1){ 798 if( ((const Prototype *)pobj_c2)->IsEqualSymbol( *(const Prototype *)pClass ) ){ 799 //名前空間及びクラス名が重複した場合 800 SmoothieException::Throw(15,pClass->GetName()); 801 return false; 802 } 803 804 if(pobj_c2->pobj_NextClass==0) break; 805 pobj_c2=pobj_c2->pobj_NextClass; 806 } 807 pobj_c2->pobj_NextClass=pClass; 808 } 809 else{ 810 pobj_ClassHash[key]=pClass; 779 if( !Put( pClass ) ) 780 { 781 SetError(15,pClass->GetName(), cp); 782 return false; 811 783 } 812 784 return true; … … 961 933 962 934 void Classes::ActionVtblSchedule(LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection){ 963 int i; 964 for(i=0;i<MAX_CLASS_HASH;i++){ 965 if(pobj_ClassHash[i]){ 966 CClass *pobj_c; 967 pobj_c=pobj_ClassHash[i]; 968 while(1){ 969 pobj_c->ActionVtblSchedule(ImageBase,MemPos_CodeSection); 970 971 if(pobj_c->pobj_NextClass==0) break; 972 pobj_c=pobj_c->pobj_NextClass; 973 } 974 } 935 Iterator_Reset(); 936 while( Iterator_HasNext() ) 937 { 938 CClass *pClass = Iterator_GetNext(); 939 pClass->ActionVtblSchedule(ImageBase,MemPos_CodeSection); 975 940 } 976 941 } … … 981 946 982 947 //イテレータをリセット 983 this->Iterator_Reset();984 948 985 949 extern int cp; 986 950 int back_cp=cp; 987 951 952 this->Iterator_Reset(); 988 953 while(this->Iterator_HasNext()){ 989 954 CClass &objClass = *this->Iterator_GetNext(); … … 1634 1599 const CClass *Classes::Find( const NamespaceScopes &namespaceScopes, const string &name ) const 1635 1600 { 1636 int key;1637 key=GetHashCode(name.c_str());1638 1639 1601 if( namespaceScopes.size() == 0 && name == "Object" ){ 1640 1602 return GetObjectClassPtr(); … … 1644 1606 } 1645 1607 1646 if(pobj_ClassHash[key]){ 1647 CClass *pobj_c; 1648 pobj_c=pobj_ClassHash[key]; 1649 while(1){ 1650 if( pobj_c->IsEqualSymbol( namespaceScopes, name ) ){ 1651 //名前空間とクラス名が一致した 1652 return pobj_c; 1653 } 1654 1655 if(pobj_c->pobj_NextClass==0) break; 1656 pobj_c=pobj_c->pobj_NextClass; 1657 } 1608 const CClass *pClass = GetHashArrayElement( name.c_str() ); 1609 while( pClass ) 1610 { 1611 if( pClass->IsEqualSymbol( namespaceScopes, name ) ){ 1612 //名前空間とクラス名が一致した 1613 return pClass; 1614 } 1615 pClass = pClass->GetChainNext(); 1658 1616 } 1659 1617 … … 1711 1669 return pObjectClass; 1712 1670 } 1713 1714 1715 //////////////////////1716 // イテレータ1717 //////////////////////1718 1719 void Classes::Iterator_Init() const1720 {1721 if(ppobj_IteClass) free(ppobj_IteClass);1722 1723 iIteMaxNum=0;1724 iIteNextNum=0;1725 ppobj_IteClass=(CClass **)malloc(1);1726 1727 int i;1728 for(i=0;i<MAX_CLASS_HASH;i++){1729 if(pobj_ClassHash[i]){1730 CClass *pobj_c;1731 pobj_c=pobj_ClassHash[i];1732 while(1){1733 ppobj_IteClass=(CClass **)realloc(ppobj_IteClass,(iIteMaxNum+1)*sizeof(CClass *));1734 ppobj_IteClass[iIteMaxNum]=pobj_c;1735 iIteMaxNum++;1736 1737 if(pobj_c->pobj_NextClass==0) break;1738 pobj_c=pobj_c->pobj_NextClass;1739 }1740 }1741 }1742 }1743 void Classes::Iterator_Reset() const1744 {1745 iIteNextNum = 0;1746 }1747 BOOL Classes::Iterator_HasNext() const1748 {1749 if(iIteNextNum<iIteMaxNum) return 1;1750 return 0;1751 }1752 CClass *Classes::Iterator_GetNext() const1753 {1754 CClass *pobj_c = ppobj_IteClass[iIteNextNum];1755 iIteNextNum++;1756 return pobj_c;1757 }1758 int Classes::Iterator_GetMaxCount() const1759 {1760 return iIteMaxNum;1761 } -
trunk/abdev/BasicCompiler_Common/src/Compiler.cpp
r265 r270 7 7 8 8 Compiler compiler; 9 10 void Compiler::StaticLink( ObjectModules &staticLibraries ) 11 { 12 BOOST_FOREACH( ObjectModule *pStaticLibrary, staticLibraries ) 13 { 14 // メタ情報 15 pNowObjectModule->meta.StaticLink( pStaticLibrary->meta ); 16 } 17 } 9 18 10 19 bool Compiler::StringToType( const string &typeName, Type &type ){ -
trunk/abdev/BasicCompiler_Common/src/Source.cpp
r269 r270 821 821 822 822 // basic.sbpをインクルード 823 const char *headCode = "\n"; 823 const char *headCode = "#include <basic.sbp>\n"; 824 //const char *headCode = "\n"; 824 825 Realloc( length + lstrlen(headCode) ); 825 826 Text::SlideString( buffer, lstrlen(headCode) );
Note:
See TracChangeset
for help on using the changeset viewer.