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

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

Classes::Insertメソッド内のエラー発生部分でコード位置情報を不正な値になっていたバグを修正。

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