source: dev/trunk/abdev/BasicCompiler_Common/include/Class.h@ 387

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

メンバ情報を保持するようにした

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