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

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

pobj_NextClasstが不要だったので消去。

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