source: dev/BasicCompiler_Common/Class.h@ 141

Last change on this file since 141 was 141, checked in by dai_9181, 17 years ago

CClass::vtblNumをリファクタリングした。
インターフェイスを継承したとき、Objectクラスがインターフェイスの後ろに配置されてしまうバグを修正(どんなときも、Objectクラスが一番最初に継承されるべき)

File size: 6.9 KB
RevLine 
[78]1#pragma once
2
[50]3#include <vector>
[131]4#include <string>
5
6#include <Prototype.h>
[135]7#include <Method.h>
8#include <Member.h>
[100]9#include "Procedure.h"
[4]10
[51]11class CDBClass;
12class CDebugSection;
[131]13class CClass;
14class InheritedInterface
15{
16 CClass *pInterfaceClass;
17 int vtblOffset;
18public:
19 InheritedInterface( CClass *pInterfaceClass, int vtblOffset )
20 : pInterfaceClass( pInterfaceClass )
21 , vtblOffset( vtblOffset )
22 {
23 }
24
25 CClass &GetInterfaceClass() const{
26 return *pInterfaceClass;
27 }
28 int GetVtblOffset() const
29 {
30 return vtblOffset;
31 }
32};
33typedef vector<InheritedInterface> Interfaces;
34class CClass : public Prototype
35{
[53]36 friend CMember;
[51]37 friend CDBClass;
38 friend CDebugSection;
39
[140]40 bool isReady;
41 void Readed(){
42 isReady = true;
43 }
44 bool IsReady() const{
45 return isReady;
46 }
47
[131]48 // importされている名前空間
[108]49 NamespaceScopesCollection importedNamespaces;
[101]50
[131]51 // 継承するインターフェイス
52 Interfaces interfaces;
53
[127]54 // Blittable型情報
55 Type blittableType;
56
[140]57 // 動的メンバ
58 Members dynamicMembers;
[53]59
[140]60 // 静的メンバ
61 Members staticMembers;
62
63 // 動的メソッド
[135]64 Methods methods;
[51]65 int ConstructorMemberSubIndex;
66 int DestructorMemberSubIndex;
[141]67 int vtblNum; // 仮想関数の数
[51]68
[140]69 // 静的メソッド
[135]70 Methods staticMethods;
[50]71
[64]72 enum ClassType{
73 Class,
[90]74 Interface,
75 Enum,
76 Delegate,
[64]77 Structure,
78 };
79
80 ClassType classType;
81
[4]82public:
83
84 //継承クラスへのポインタ
[114]85 const CClass *pobj_InheritsClass;
[4]86
87 //アラインメント値
88 int iAlign;
89
[131]90 CClass( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const string &name );
[4]91 ~CClass();
92
[108]93 const NamespaceScopesCollection &GetImportedNamespaces() const
94 {
95 return importedNamespaces;
96 }
[101]97
[131]98 // インターフェイス
99 bool HasInterfaces() const
[102]100 {
[131]101 return ( interfaces.size() != 0 );
[102]102 }
[131]103 bool IsInheritsInterface( const CClass *pInterfaceClass ) const;
[101]104
[131]105 // Blittable型
[127]106 bool IsBlittableType() const
107 {
[128]108 return !blittableType.IsNull();
[127]109 }
110 const Type &GetBlittableType() const
111 {
112 return blittableType;
113 }
114 void SetBlittableType( const Type &type ){
115 blittableType = type;
116 }
117
[90]118 bool IsClass() const;
119 bool IsInterface() const;
120 bool IsEnum() const;
121 bool IsDelegate() const;
[64]122 bool IsStructure() const;
123
[29]124 //継承させる
[131]125 bool Inherits( const char *inheritNames, int nowLine );
126 bool InheritsClass( const CClass &inheritsClass, int nowLine );
[114]127 bool InheritsInterface( const CClass &inheritsClass, int nowLine );
[29]128
[53]129 //メンバ、メソッドの追加
[137]130 void AddMember( Prototype::Accessibility accessibility, bool idConst, bool isRef, char *buffer );
131 void AddStaticMember( Prototype::Accessibility accessibility, bool isConst, bool isRef, char *buffer, int nowLine );
[4]132
[53]133 //重複チェック
[46]134 BOOL DupliCheckAll(const char *name);
135 BOOL DupliCheckMember(const char *name);
[4]136
[140]137 const Members &GetDynamicMembers() const
138 {
139 return dynamicMembers;
140 }
141
[135]142 const Methods &GetMethods() const
[91]143 {
144 return methods;
145 }
[135]146 const Methods &GetStaticMethods() const
[91]147 {
148 return staticMethods;
149 }
[18]150
[51]151 //デフォルト コンストラクタ メソッドを取得
[135]152 const CMethod *GetConstructorMethod() const;
[50]153
[51]154 //デストラクタ メソッドを取得
[135]155 const CMethod *GetDestructorMethod() const;
[51]156
[141]157 // vtblに存在する仮想関数の数
158 int GetVtblNum() const
159 {
160 return vtblNum;
161 }
162 void SetVtblNum( int vtblNum )
163 {
164 this->vtblNum = vtblNum;
165 }
166 void AddVtblNum( int vtblNum )
167 {
168 this->vtblNum += vtblNum;
169 }
170 bool IsExistVirtualFunctions() const
171 {
172 return ( vtblNum > 0 );
173 }
174
[63]175 // メンバの総合サイズを取得
176 int GetSize() const;
[51]177
[63]178 // メンバのオフセットを取得
[94]179 int GetMemberOffset( const char *memberName, int *pMemberNum = NULL ) const;
[63]180
181private:
182 // アラインメント値を取得
183 int GetAlignment() const;
184
185
[4]186 //vtbl
187private:
[114]188 mutable long vtbl_offset;
[4]189public:
[75]190 int GetFuncNumInVtbl( const UserProc *pUserProc ) const;
[114]191 LONG_PTR GetVtblGlobalOffset(void) const;
[4]192 void ActionVtblSchedule(LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection);
[75]193 bool IsAbstract() const;
[4]194
195
[17]196 //コンストラクタをコンパイルしているかどうかのチェックフラグ
197private:
[114]198 mutable bool isCompilingConstructor;
[17]199public:
[114]200 void NotifyStartConstructorCompile() const;
201 void NotifyFinishConstructorCompile() const;
[75]202 bool IsCompilingConstructor() const;
[17]203
[18]204 //デストラクタをコンパイルしているかどうかのチェックフラグ
205private:
[114]206 mutable bool isCompilingDestructor;
[18]207public:
[114]208 void NotifyStartDestructorCompile() const;
209 void NotifyFinishDestructorCompile() const;
[75]210 bool IsCompilingDestructor() const;
[17]211
[18]212
[28]213 //自身の派生クラスかどうかを確認
[75]214 bool IsSubClass( const CClass *pClass ) const;
[28]215
[59]216 //自身と等しいまたは派生クラスかどうかを確認
[75]217 bool IsEqualsOrSubClass( const CClass *pClass ) const;
[28]218
[94]219 // 自身と等しいまたは派生クラス、基底クラスかどうかを確認
220 bool IsEqualsOrSubClassOrSuperClass( const CClass &objClass ) const;
[59]221
[94]222
[4]223 //線形リスト用
224 CClass *pobj_NextClass;
[64]225
226
227 //メンバの参照方法
228 enum RefType{
[97]229 Non = 0, // no reference member
[64]230 Dot, // obj.member
231 Pointer, // obj->member
232 };
[4]233};
234
235#define MAX_CLASS_HASH 65535
236class CDBClass{
[102]237 int hash(const char *name) const;
[4]238 void DestroyClass(CClass *pobj_c);
239public:
240 CClass *pobj_ClassHash[MAX_CLASS_HASH];
241
242 CDBClass();
243 ~CDBClass();
244
[114]245 const CClass *Find( const string &fullName ) const;
246 const CClass *Find( const NamespaceScopes &namespaceScopes, const string &name ) const;
[4]247
[108]248 CClass *AddClass( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const char *name,int nowLine);
[4]249
250 void ActionVtblSchedule(LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection);
251
252private:
[137]253 void AddMethod(CClass *pobj_c, Prototype::Accessibility accessibility, BOOL bStatic, bool isConst, bool isAbstract,
[135]254 bool isVirtual, bool isOverride, char *buffer, int nowLine);
[75]255 BOOL MemberVar_LoopRefCheck(const CClass &objClass);
[4]256public:
257 void InitNames(void);
[46]258 void GetClass_recur(const char *lpszInheritsClass);
[67]259 void GetAllClassInfo(void);
[89]260 void Compile_System_InitializeUserTypes();
[4]261
262
[18]263 /////////////////////////////
[67]264 // 特殊クラス
265 /////////////////////////////
266 CClass *pStringClass;
267 CClass *pObjectClass;
[117]268 CClass *GetStringClassPtr() const;
269 CClass *GetObjectClassPtr() const;
[67]270
271
272 /////////////////////////////
[18]273 // 現在コンパイル中の情報
274 /////////////////////////////
[4]275private:
[114]276 const CClass *pCompilingClass;
[135]277 const CMethod *pCompilingMethod;
[18]278public:
279 //コンパイル開始の通知を受け取るメソッド
[75]280 void StartCompile( UserProc *pUserProc );
[18]281
282 //現在コンパイル中のメソッド情報を取得
[114]283 const CClass *GetNowCompilingClass() const;
[135]284 const CMethod *GetNowCompilingMethodInfo();
[18]285
286
287 /////////////////////
288 // イテレータ
289 /////////////////////
290private:
[4]291 CClass **ppobj_IteClass;
292 int iIteMaxNum;
293 int iIteNextNum;
294public:
[89]295 void Iterator_Init(void);
[4]296 void Iterator_Reset(void);
297 BOOL Iterator_HasNext(void);
298 CClass *Iterator_GetNext(void);
299 int Iterator_GetMaxCount(void);
300};
301
302
303extern CDBClass *pobj_DBClass;
[114]304extern const CClass *pobj_CompilingClass;
Note: See TracBrowser for help on using the repository browser.