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

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

Prototypeクラスをab_commonプロジェクトに移動した。

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