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

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

COM修飾子に対応。COMインターフェイスを呼び出せるようにした

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