source: dev/BasicCompiler_Common/Class.h@ 127

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

Bittableをちょっとだけ実装。
64bitコンパイラプロジェクトにSmallDebugビルド構成を作成(Releaseビルドが不調な間の暫定モード)。

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