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

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

ImplementsメソッドをLexicalAnalyzerクラスに移動した。

File size: 12.9 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
[540]178 virtual void Using() const;
179
[206]180 void Readed(){
181 isReady = true;
182 }
183 bool IsReady() const{
184 return isReady;
185 }
[184]186
[206]187 const NamespaceScopesCollection &GetImportedNamespaces() const
188 {
189 return importedNamespaces;
190 }
191
[290]192 // 型パラメータ
[424]193 const GenericTypes &GetFormalGenericTypes() const
194 {
195 return formalGenericTypes;
196 }
[290]197 void AddFormalGenericType( GenericType genericType )
198 {
199 this->formalGenericTypes.push_back( genericType );
200 }
[299]201 int GetFormalGenericTypeParameterIndex( const std::string &name ) const
202 {
203 int i = 0;
204 BOOST_FOREACH( const GenericType &genericType, formalGenericTypes )
205 {
206 if( genericType.GetName() == name )
207 {
208 return i;
209 }
210 i++;
211 }
212 return -1;
213 }
[290]214 bool IsExistFormalGenericTypeParameter( const std::string &name ) const
215 {
216 BOOST_FOREACH( const GenericType &genericType, formalGenericTypes )
217 {
218 if( genericType.GetName() == name )
219 {
220 return true;
221 }
222 }
223 return false;
224 }
[379]225 bool IsGeneric() const
226 {
227 return ( this->formalGenericTypes.size() != 0 );
228 }
[290]229
[206]230 // 継承元クラス
231 bool HasSuperClass() const
232 {
233 return ( pSuperClass != NULL );
234 }
235 const CClass &GetSuperClass() const
236 {
237 return *pSuperClass;
238 }
239 void SetSuperClass( const CClass *pSuperClass )
240 {
241 this->pSuperClass = pSuperClass;
242 }
[299]243 const Types &GetSuperClassActualTypeParameters() const
244 {
245 return superClassActualTypeParameters;
246 }
247 void SetSuperClassActualTypeParameters( const Types &actualTypeParameters )
248 {
249 this->superClassActualTypeParameters = actualTypeParameters;
250 }
[206]251
252 // Blittable型
253 bool IsBlittableType() const
254 {
255 return !blittableType.IsNull();
256 }
257 const Type &GetBlittableType() const
258 {
259 return blittableType;
260 }
261 void SetBlittableType( const Type &type ){
262 blittableType = type;
263 }
264
265 bool IsClass() const;
266 bool IsInterface() const;
[370]267 bool IsComInterface() const;
[206]268 bool IsEnum() const;
269 bool IsDelegate() const;
270 bool IsStructure() const;
271 void SetClassType( ClassType classType )
272 {
273 this->classType = classType;
274 }
275
276
277 //コンストラクタをコンパイルしているかどうかのチェックフラグ
[184]278private:
[206]279 mutable bool isCompilingConstructor;
[184]280public:
[206]281 void NotifyStartConstructorCompile() const;
282 void NotifyFinishConstructorCompile() const;
283 bool IsCompilingConstructor() const;
[184]284
[206]285 //デストラクタをコンパイルしているかどうかのチェックフラグ
286private:
287 mutable bool isCompilingDestructor;
288public:
289 void NotifyStartDestructorCompile() const;
290 void NotifyFinishDestructorCompile() const;
291 bool IsCompilingDestructor() const;
[191]292
[193]293
[206]294 //自身の派生クラスかどうかを確認
295 bool IsSubClass( const CClass *pClass ) const;
296
297 //自身と等しいまたは派生クラスかどうかを確認
298 bool IsEqualsOrSubClass( const CClass *pClass ) const;
299
300 // 自身と等しいまたは派生クラス、基底クラスかどうかを確認
301 bool IsEqualsOrSubClassOrSuperClass( const CClass &objClass ) const;
302
303 // インターフェイス
304 bool HasInterfaces() const
305 {
306 return ( interfaces.size() != 0 );
307 }
[560]308 void AddInterface( ::Interface *pInterface )
309 {
310 interfaces.push_back( pInterface );
311 }
[342]312 const Interfaces &GetInterfaces() const
313 {
314 return interfaces;
315 }
[206]316 bool IsInheritsInterface( const CClass *pInterfaceClass ) const;
317
[340]318 // クラス継承
[299]319 bool InheritsClass( const CClass &inheritsClass, const Types &actualTypeParameters, int nowLine );
[206]320
321 //メンバ、メソッドの追加
322 CMember *CreateMember( Prototype::Accessibility accessibility, bool isConst, bool isRef, char *buffer, int nowLine );
323 void AddMember( Prototype::Accessibility accessibility, bool idConst, bool isRef, char *buffer, int nowLine );
324 void AddStaticMember( Prototype::Accessibility accessibility, bool isConst, bool isRef, char *buffer, int nowLine );
325
326 //重複チェック
[409]327 bool DupliCheckAll(const char *name) const;
328 bool DupliCheckMember(const char *name) const;
[206]329
330 const Members &GetDynamicMembers() const
331 {
332 return dynamicMembers;
333 }
334 const Members &GetStaticMembers() const
335 {
336 return staticMembers;
337 }
338 Members &GetDynamicMembers()
339 {
340 return dynamicMembers;
341 }
342 Members &GetStaticMembers()
343 {
344 return staticMembers;
345 }
[355]346
[409]347 const CMember *FindDynamicMember( const char *memberName ) const;
348 bool HasDynamicMember( const char *memberName ) const
[355]349 {
[409]350 return ( FindDynamicMember( memberName ) != NULL );
[355]351 }
[206]352
[350]353 void EnumDynamicMethodsOrInterfaceMethods( const char *methodName, std::vector<const UserProc *> &subs ) const;
354 const CMethod *GetDynamicMethodOrInterfaceMethod( const UserProc *pUserProc ) const;
[347]355
[206]356 const Methods &GetStaticMethods() const
357 {
358 return staticMethods;
359 }
360 Methods &GetStaticMethods()
361 {
362 return staticMethods;
363 }
364
365 //デフォルト コンストラクタ
366 const CMethod *GetConstructorMethod() const
367 {
368 if( ConstructorMemberSubIndex == -1 ) return NULL;
[342]369 return GetDynamicMethods()[ConstructorMemberSubIndex];
[206]370 }
371 void SetConstructorMemberSubIndex( int constructorMemberSubIndex )
372 {
373 this->ConstructorMemberSubIndex = constructorMemberSubIndex;
374 }
375
376 //デストラクタ メソッドを取得
377 const CMethod *GetDestructorMethod() const
378 {
379 if( DestructorMemberSubIndex == -1 ) return NULL;
[342]380 return GetDynamicMethods()[DestructorMemberSubIndex];
[206]381 }
382 void SetDestructorMemberSubIndex( int destructorMemberSubIndex )
383 {
384 this->DestructorMemberSubIndex = destructorMemberSubIndex;
385 }
386
[325]387 // デリゲート情報を取得
388 const ::Delegate &GetDelegate() const;
389
[232]390 // ユーザ指定のアラインメント固定値
391 int GetFixedAlignment() const
392 {
393 return fixedAlignment;
394 }
395 void SetFixedAlignment( int fixedAlignment )
396 {
397 this->fixedAlignment = fixedAlignment;
398 }
399
[206]400 // メンバの総合サイズを取得
[409]401private:
402 int cacheSize;
403public:
[206]404 int GetSize() const;
405
406 // メンバのオフセットを取得
[409]407 int GetMemberOffset( const char *memberName ) const;
[206]408private:
409 // アラインメント値を取得
410 int GetAlignment() const;
411
[342]412
413 /////////////////////////////////////////////////////////////////
414 // vtbl
415 /////////////////////////////////////////////////////////////////
[206]416public:
[342]417 // vtblに存在する仮想関数の数
418 int GetVtblNum() const
419 {
420 return vtblNum;
421 }
422 void SetVtblNum( int vtblNum )
423 {
424 this->vtblNum = vtblNum;
425 }
426 void AddVtblNum( int vtblNum )
427 {
428 this->vtblNum += vtblNum;
429 }
430 bool IsExistVirtualFunctions() const
431 {
[409]432 // 構造体以外は仮想関数を持つ
433 return !IsStructure();
[342]434 }
435
436private:
437 long vtbl_offset;
[370]438 long comVtblOffset;
[342]439 long vtblMasterListOffset;
[559]440public:
[345]441 std::vector<long> vtblMasterList;
[559]442 LONG_PTR GetVtblOffset() const
443 {
444 return vtbl_offset;
445 }
446 void SetVtblOffset( int vtblOffset )
447 {
448 this->vtbl_offset = vtblOffset;
449 }
450 long GetComVtblOffset() const
451 {
452 return comVtblOffset;
453 }
454 void SetComVtblOffset( int comVtblOffset )
455 {
456 this->comVtblOffset = comVtblOffset;
457 }
[348]458 void GetVtblMasterListIndexAndVtblIndex( const UserProc *pUserProc, int &vtblMasterListIndex, int &vtblIndex ) const;
[350]459 int GetVtblMasterListIndex( const CClass *pClass ) const;
[345]460 long GetVtblMasterListOffset() const;
[559]461 void SetVtblMasterListOffset( int vtblMasterListOffset )
462 {
463 this->vtblMasterListOffset = vtblMasterListOffset;
464 }
[206]465 bool IsAbstract() const;
466
467
[355]468 // TypeInfo用
469 mutable int typeInfoDataTableOffset;
470 void SetTypeInfoDataTableOffset( int typeInfoDataTableOffset ) const
471 {
472 this->typeInfoDataTableOffset = typeInfoDataTableOffset;
473 }
474 int GetTypeInfoDataTableOffset() const
475 {
476 return typeInfoDataTableOffset;
477 }
478
[387]479 // 動的型データ用のメンバデータを取得
480 std::string GetStaticDefiningStringAsMemberNames() const;
481 std::string GetStaticDefiningStringAsMemberTypeInfoNames() const;
[412]482 std::string GetStaticDefiningStringAsMemberOffsets() const;
[417]483 void GetReferenceOffsetsInitializeBuffer( std::string &referenceOffsetsBuffer, int &numOfReference, int baseOffset = 0 ) const;
[206]484};
485
[270]486class Classes : public Jenga::Common::Hashmap<CClass>
[206]487{
[191]488 // XMLシリアライズ用
[206]489public:
490 Classes()
[538]491 : pStringClass( NULL )
[206]492 , pObjectClass( NULL )
[350]493 , pInterfaceInfo( NULL )
[206]494 {
495 }
496 ~Classes()
497 {
498 }
499
500 virtual CClass *Create( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const char *name);
[369]501 bool Insert( CClass *pClass, int nowLine );
[206]502 CClass *Add( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const char *name,int nowLine);
503
504 virtual void InitStaticMember();
505
506 virtual void Compile_System_InitializeUserTypes();
[355]507 virtual void Compile_System_InitializeUserTypesForBaseType();
[206]508
[523]509 const CClass *Find( const NamespaceScopes &namespaceScopes, const std::string &name ) const;
510 const CClass *Find( const std::string &fullName ) const;
[206]511
512
513 /////////////////////////////
514 // 特殊クラス
515 /////////////////////////////
[272]516 mutable const CClass *pStringClass;
517 mutable const CClass *pObjectClass;
[349]518 mutable const CClass *pInterfaceInfo;
[272]519 const CClass *GetStringClassPtr() const;
520 const CClass *GetObjectClassPtr() const;
[349]521 const CClass *GetInterfaceInfoClassPtr() const;
[184]522};
Note: See TracBrowser for help on using the repository browser.