source: dev/trunk/ab5.0/abdev/BasicCompiler_Common/include/Class.h@ 513

Last change on this file since 513 was 513, checked in by dai_9181, 16 years ago

Interfaceクラスを独自ファイルにした。

File size: 13.4 KB
RevLine 
[184]1#pragma once
2
[206]3#include <option.h>
4#include <Program.h>
5#include <Member.h>
[266]6#include <Source.h>
[184]7
[206]8class UserProc;
[325]9class Delegate;
[206]10
[344]11class ClassPrototype : public Prototype, public DynamicMethodsPrototype
[342]12{
[344]13 // XMLシリアライズ用
14private:
15 friend class boost::serialization::access;
16 template<class Archive> void serialize(Archive& ar, const unsigned int version)
17 {
18 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Prototype );
19 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( DynamicMethodsPrototype );
20 }
21
22public:
23 ClassPrototype( const NamespaceScopes &namespaceScopes, const string &name )
24 : Prototype( namespaceScopes, name )
25 , DynamicMethodsPrototype()
26 {
27 }
28 ClassPrototype()
29 : Prototype()
30 , DynamicMethodsPrototype()
31 {
32 }
33};
34
[342]35class CClass: public ClassPrototype, public Jenga::Common::ObjectInHashmap<CClass>
[206]36{
37public:
38 // 型の種類
39 enum ClassType{
40 Class,
41 Interface,
[370]42 ComInterface,
[206]43 Enum,
44 Delegate,
45 Structure,
46 };
[193]47
[206]48private:
49 ClassType classType;
[184]50
[206]51 // importされている名前空間
52 NamespaceScopesCollection importedNamespaces;
[290]53
54 // 型パラメータ
55 GenericTypes formalGenericTypes;
56
[382]57 // 基底クラス
[206]58 const CClass *pSuperClass;
[184]59
[382]60 // 基底クラスの型パラメータ(実パラメータ)
[299]61 Types superClassActualTypeParameters;
62
[206]63 // Blittable型情報
64 Type blittableType;
[184]65
[206]66 // 実装するインターフェイス
67 Interfaces interfaces;
[191]68
[206]69 // 動的メンバ
70 Members dynamicMembers;
[191]71
[206]72 // 静的メンバ
73 Members staticMembers;
74
75 // 動的メソッド
76 int ConstructorMemberSubIndex;
77 int DestructorMemberSubIndex;
78 int vtblNum; // 仮想関数の数
79
80 // 静的メソッド
81 Methods staticMethods;
82
[232]83 //アラインメント値
84 int fixedAlignment;
85
[191]86 // XMLシリアライズ用
87private:
88 friend class boost::serialization::access;
89 template<class Archive> void serialize(Archive& ar, const unsigned int version)
90 {
[206]91 trace_for_serialize( "serializing - CClass" );
92
[342]93 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( ClassPrototype );
[206]94 ar & BOOST_SERIALIZATION_NVP( classType );
95 ar & BOOST_SERIALIZATION_NVP( importedNamespaces );
[293]96 ar & BOOST_SERIALIZATION_NVP( formalGenericTypes );
[206]97 ar & boost::serialization::make_nvp( "pSuperClass", const_cast<CClass *&>(pSuperClass) );
[299]98 ar & BOOST_SERIALIZATION_NVP( superClassActualTypeParameters );
[206]99 ar & BOOST_SERIALIZATION_NVP( blittableType );
[353]100 ar & BOOST_SERIALIZATION_NVP( interfaces );
[206]101 ar & BOOST_SERIALIZATION_NVP( dynamicMembers );
102 ar & BOOST_SERIALIZATION_NVP( staticMembers );
103 ar & BOOST_SERIALIZATION_NVP( ConstructorMemberSubIndex );
104 ar & BOOST_SERIALIZATION_NVP( DestructorMemberSubIndex );
105 ar & BOOST_SERIALIZATION_NVP( vtblNum );
106 ar & BOOST_SERIALIZATION_NVP( staticMethods );
[232]107 ar & BOOST_SERIALIZATION_NVP( fixedAlignment );
[191]108 }
[184]109
[206]110 bool isReady;
[184]111public:
[206]112
113 CClass( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const string &name )
[342]114 : ClassPrototype( namespaceScopes, name )
[206]115 , importedNamespaces( importedNamespaces )
116 , classType( Class )
117 , pSuperClass( NULL )
[290]118 , blittableType( Type() )
[206]119 , isReady( false )
[232]120 , fixedAlignment( 0 )
[206]121 , ConstructorMemberSubIndex( -1 )
122 , DestructorMemberSubIndex( -1 )
123 , vtblNum( 0 )
124 , vtbl_offset( -1 )
[370]125 , comVtblOffset( 0 )
[206]126 , isCompilingConstructor( false )
127 , isCompilingDestructor( false )
128 , pobj_NextClass( NULL )
[409]129 , cacheSize( 0 )
[191]130 {
131 }
[206]132 CClass()
[342]133 : ClassPrototype()
[206]134 , importedNamespaces()
135 , classType()
136 , pSuperClass( NULL )
[290]137 , blittableType( Type() )
[206]138 , isReady( false )
[232]139 , fixedAlignment( 0 )
[206]140 , ConstructorMemberSubIndex( -1 )
141 , DestructorMemberSubIndex( -1 )
142 , vtblNum( 0 )
143 , vtbl_offset( -1 )
[370]144 , comVtblOffset( 0 )
[206]145 , isCompilingConstructor( false )
146 , isCompilingDestructor( false )
147 , pobj_NextClass( NULL )
[409]148 , cacheSize( 0 )
[206]149 {
150 }
151 ~CClass()
152 {
153 // 動的メンバ
[346]154 BOOST_FOREACH( CMember *member, dynamicMembers )
155 {
[206]156 delete member;
157 }
[191]158
[206]159 // 静的メンバ
[346]160 BOOST_FOREACH( CMember *member, staticMembers )
161 {
[206]162 delete member;
163 }
[346]164
165 // インターフェイス
166 BOOST_FOREACH( ::Interface *pInterface, interfaces )
167 {
168 delete pInterface;
169 }
[206]170 }
[184]171
[270]172 virtual const std::string &GetKeyName() const
173 {
174 return GetName();
175 }
176 virtual bool IsDuplication( const CClass *pClass ) const
177 {
178 if( pClass->IsEqualSymbol( *this ) )
179 {
180 return true;
181 }
182 return false;
183 }
184
[206]185 void Readed(){
186 isReady = true;
187 }
188 bool IsReady() const{
189 return isReady;
190 }
[184]191
[206]192 const NamespaceScopesCollection &GetImportedNamespaces() const
193 {
194 return importedNamespaces;
195 }
196
[290]197 // 型パラメータ
[424]198 const GenericTypes &GetFormalGenericTypes() const
199 {
200 return formalGenericTypes;
201 }
[290]202 void AddFormalGenericType( GenericType genericType )
203 {
204 this->formalGenericTypes.push_back( genericType );
205 }
[299]206 int GetFormalGenericTypeParameterIndex( const std::string &name ) const
207 {
208 int i = 0;
209 BOOST_FOREACH( const GenericType &genericType, formalGenericTypes )
210 {
211 if( genericType.GetName() == name )
212 {
213 return i;
214 }
215 i++;
216 }
217 return -1;
218 }
[290]219 bool IsExistFormalGenericTypeParameter( const std::string &name ) const
220 {
221 BOOST_FOREACH( const GenericType &genericType, formalGenericTypes )
222 {
223 if( genericType.GetName() == name )
224 {
225 return true;
226 }
227 }
228 return false;
229 }
[379]230 bool IsGeneric() const
231 {
232 return ( this->formalGenericTypes.size() != 0 );
233 }
[290]234
[206]235 // 継承元クラス
236 bool HasSuperClass() const
237 {
238 return ( pSuperClass != NULL );
239 }
240 const CClass &GetSuperClass() const
241 {
242 return *pSuperClass;
243 }
244 void SetSuperClass( const CClass *pSuperClass )
245 {
246 this->pSuperClass = pSuperClass;
247 }
[299]248 const Types &GetSuperClassActualTypeParameters() const
249 {
250 return superClassActualTypeParameters;
251 }
252 void SetSuperClassActualTypeParameters( const Types &actualTypeParameters )
253 {
254 this->superClassActualTypeParameters = actualTypeParameters;
255 }
[206]256
257 // Blittable型
258 bool IsBlittableType() const
259 {
260 return !blittableType.IsNull();
261 }
262 const Type &GetBlittableType() const
263 {
264 return blittableType;
265 }
266 void SetBlittableType( const Type &type ){
267 blittableType = type;
268 }
269
270 bool IsClass() const;
271 bool IsInterface() const;
[370]272 bool IsComInterface() const;
[206]273 bool IsEnum() const;
274 bool IsDelegate() const;
275 bool IsStructure() const;
276 void SetClassType( ClassType classType )
277 {
278 this->classType = classType;
279 }
280
281
282 //コンストラクタをコンパイルしているかどうかのチェックフラグ
[184]283private:
[206]284 mutable bool isCompilingConstructor;
[184]285public:
[206]286 void NotifyStartConstructorCompile() const;
287 void NotifyFinishConstructorCompile() const;
288 bool IsCompilingConstructor() const;
[184]289
[206]290 //デストラクタをコンパイルしているかどうかのチェックフラグ
291private:
292 mutable bool isCompilingDestructor;
293public:
294 void NotifyStartDestructorCompile() const;
295 void NotifyFinishDestructorCompile() const;
296 bool IsCompilingDestructor() const;
[191]297
[193]298
[206]299 //自身の派生クラスかどうかを確認
300 bool IsSubClass( const CClass *pClass ) const;
301
302 //自身と等しいまたは派生クラスかどうかを確認
303 bool IsEqualsOrSubClass( const CClass *pClass ) const;
304
305 // 自身と等しいまたは派生クラス、基底クラスかどうかを確認
306 bool IsEqualsOrSubClassOrSuperClass( const CClass &objClass ) const;
307
308 // インターフェイス
309 bool HasInterfaces() const
310 {
311 return ( interfaces.size() != 0 );
312 }
[342]313 const Interfaces &GetInterfaces() const
314 {
315 return interfaces;
316 }
[206]317 bool IsInheritsInterface( const CClass *pInterfaceClass ) const;
318
[340]319 // クラス継承
[299]320 bool InheritsClass( const CClass &inheritsClass, const Types &actualTypeParameters, int nowLine );
[206]321
[340]322 // インターフェイス実装
[376]323 bool Implements( const CClass &interfaceClass, const Types &actualTypeParameters, int nowLine );
[340]324
[206]325 //メンバ、メソッドの追加
326 CMember *CreateMember( Prototype::Accessibility accessibility, bool isConst, bool isRef, char *buffer, int nowLine );
327 void AddMember( Prototype::Accessibility accessibility, bool idConst, bool isRef, char *buffer, int nowLine );
328 void AddStaticMember( Prototype::Accessibility accessibility, bool isConst, bool isRef, char *buffer, int nowLine );
329
330 //重複チェック
[409]331 bool DupliCheckAll(const char *name) const;
332 bool DupliCheckMember(const char *name) const;
[206]333
334 const Members &GetDynamicMembers() const
335 {
336 return dynamicMembers;
337 }
338 const Members &GetStaticMembers() const
339 {
340 return staticMembers;
341 }
342 Members &GetDynamicMembers()
343 {
344 return dynamicMembers;
345 }
346 Members &GetStaticMembers()
347 {
348 return staticMembers;
349 }
[355]350
[409]351 const CMember *FindDynamicMember( const char *memberName ) const;
352 bool HasDynamicMember( const char *memberName ) const
[355]353 {
[409]354 return ( FindDynamicMember( memberName ) != NULL );
[355]355 }
[206]356
[350]357 void EnumDynamicMethodsOrInterfaceMethods( const char *methodName, std::vector<const UserProc *> &subs ) const;
358 const CMethod *GetDynamicMethodOrInterfaceMethod( const UserProc *pUserProc ) const;
[347]359
[206]360 const Methods &GetStaticMethods() const
361 {
362 return staticMethods;
363 }
364 Methods &GetStaticMethods()
365 {
366 return staticMethods;
367 }
368
369 //デフォルト コンストラクタ
370 const CMethod *GetConstructorMethod() const
371 {
372 if( ConstructorMemberSubIndex == -1 ) return NULL;
[342]373 return GetDynamicMethods()[ConstructorMemberSubIndex];
[206]374 }
375 void SetConstructorMemberSubIndex( int constructorMemberSubIndex )
376 {
377 this->ConstructorMemberSubIndex = constructorMemberSubIndex;
378 }
379
380 //デストラクタ メソッドを取得
381 const CMethod *GetDestructorMethod() const
382 {
383 if( DestructorMemberSubIndex == -1 ) return NULL;
[342]384 return GetDynamicMethods()[DestructorMemberSubIndex];
[206]385 }
386 void SetDestructorMemberSubIndex( int destructorMemberSubIndex )
387 {
388 this->DestructorMemberSubIndex = destructorMemberSubIndex;
389 }
390
[325]391 // デリゲート情報を取得
392 const ::Delegate &GetDelegate() const;
393
[232]394 // ユーザ指定のアラインメント固定値
395 int GetFixedAlignment() const
396 {
397 return fixedAlignment;
398 }
399 void SetFixedAlignment( int fixedAlignment )
400 {
401 this->fixedAlignment = fixedAlignment;
402 }
403
[206]404 // メンバの総合サイズを取得
[409]405private:
406 int cacheSize;
407public:
[206]408 int GetSize() const;
409
410 // メンバのオフセットを取得
[409]411 int GetMemberOffset( const char *memberName ) const;
[206]412private:
413 // アラインメント値を取得
414 int GetAlignment() const;
415
[342]416
417 /////////////////////////////////////////////////////////////////
418 // vtbl
419 /////////////////////////////////////////////////////////////////
[206]420public:
[342]421 // vtblに存在する仮想関数の数
422 int GetVtblNum() const
423 {
424 return vtblNum;
425 }
426 void SetVtblNum( int vtblNum )
427 {
428 this->vtblNum = vtblNum;
429 }
430 void AddVtblNum( int vtblNum )
431 {
432 this->vtblNum += vtblNum;
433 }
434 bool IsExistVirtualFunctions() const
435 {
[409]436 // 構造体以外は仮想関数を持つ
437 return !IsStructure();
[342]438 }
439
440private:
441 long vtbl_offset;
[370]442 long comVtblOffset;
[342]443 long vtblMasterListOffset;
[345]444 std::vector<long> vtblMasterList;
[342]445public:
[348]446 void GetVtblMasterListIndexAndVtblIndex( const UserProc *pUserProc, int &vtblMasterListIndex, int &vtblIndex ) const;
[350]447 int GetVtblMasterListIndex( const CClass *pClass ) const;
[370]448 long GetComVtblOffset() const;
[345]449 long GetVtblMasterListOffset() const;
450 void GenerateVTableMasterList( const std::vector<long> &vtableMasterList, long &offset );
[342]451 void GenerateFullVTables();
452 void ActionVtblSchedule( LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection, LONG_PTR MemPos_DataSection );
[206]453 bool IsAbstract() const;
454
455
[355]456 // TypeInfo用
457 mutable int typeInfoDataTableOffset;
458 void SetTypeInfoDataTableOffset( int typeInfoDataTableOffset ) const
459 {
460 this->typeInfoDataTableOffset = typeInfoDataTableOffset;
461 }
462 int GetTypeInfoDataTableOffset() const
463 {
464 return typeInfoDataTableOffset;
465 }
466
[387]467 // 動的型データ用のメンバデータを取得
468 std::string GetStaticDefiningStringAsMemberNames() const;
469 std::string GetStaticDefiningStringAsMemberTypeInfoNames() const;
[412]470 std::string GetStaticDefiningStringAsMemberOffsets() const;
[417]471 void GetReferenceOffsetsInitializeBuffer( std::string &referenceOffsetsBuffer, int &numOfReference, int baseOffset = 0 ) const;
[355]472
[387]473
[206]474 //線形リスト用
475 CClass *pobj_NextClass;
476};
477
[270]478class Classes : public Jenga::Common::Hashmap<CClass>
[206]479{
[191]480 // XMLシリアライズ用
[206]481public:
482 Classes()
483 : pCompilingMethod( NULL )
484 , pStringClass( NULL )
485 , pObjectClass( NULL )
[350]486 , pInterfaceInfo( NULL )
[206]487 {
488 }
489 ~Classes()
490 {
491 }
492
493 virtual CClass *Create( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const char *name);
[369]494 bool Insert( CClass *pClass, int nowLine );
[206]495 CClass *Add( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const char *name,int nowLine);
496
[342]497 // vtblを一時的に生成
[282]498 void GenerateVTables();
[206]499
[342]500 // vtblのを正規のオフセットで再構築
501 void ActionVtblSchedule(LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection, LONG_PTR MemPos_DataSection );
502
[206]503 virtual void InitStaticMember();
504
505 virtual void Compile_System_InitializeUserTypes();
[355]506 virtual void Compile_System_InitializeUserTypesForBaseType();
[206]507
508 const CClass *Find( const NamespaceScopes &namespaceScopes, const string &name ) const;
509 const CClass *Find( const string &fullName ) const;
510
511
512 /////////////////////////////
513 // 現在コンパイル中の情報
514 /////////////////////////////
515private:
516 const CMethod *pCompilingMethod;
517public:
518 void StartCompile( const UserProc *pUserProc );
519
520 //現在コンパイル中のメソッド情報を取得
521 const CMethod *GetNowCompilingMethodInfo(){
522 return pCompilingMethod;
523 }
524
525
526 /////////////////////////////
527 // 特殊クラス
528 /////////////////////////////
[272]529 mutable const CClass *pStringClass;
530 mutable const CClass *pObjectClass;
[349]531 mutable const CClass *pInterfaceInfo;
[272]532 const CClass *GetStringClassPtr() const;
533 const CClass *GetObjectClassPtr() const;
[349]534 const CClass *GetInterfaceInfoClassPtr() const;
[184]535};
Note: See TracBrowser for help on using the repository browser.