source: dev/BasicCompiler_Common/Class.h@ 134

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

Prototype::IsEqualSymbolメソッドを実装。

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