source: dev/BasicCompiler_Common/Class.h@ 133

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

Prototypeクラスをちょっとだけ装飾

File size: 8.1 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 // シンボル比較
165 bool IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const;
166 bool IsEqualSymbol( const CClass &objClass ) const;
167 bool IsEqualSymbol( const string &name ) const;
168
169 bool IsClass() const;
170 bool IsInterface() const;
171 bool IsEnum() const;
172 bool IsDelegate() const;
173 bool IsStructure() const;
174
175 //継承させる
176 bool Inherits( const char *inheritNames, int nowLine );
177 bool InheritsClass( const CClass &inheritsClass, int nowLine );
178 bool InheritsInterface( const CClass &inheritsClass, int nowLine );
179
180 //メンバ、メソッドの追加
181 void AddMember( DWORD dwAccess, bool idConst, bool isRef, char *buffer );
182 void AddStaticMember( DWORD dwAccess, bool isConst, bool isRef, char *buffer, int nowLine );
183 void AddMethod( UserProc *pUserProc,DWORD dwAccess, bool isConst, BOOL bAbstract, BOOL bVirtual );
184 void AddStaticMethod(UserProc *pUserProc,DWORD dwAccess);
185
186 //重複チェック
187 BOOL DupliCheckAll(const char *name);
188 BOOL DupliCheckMember(const char *name);
189
190 //メソッド取得
191 CMethod *GetMethodInfo( UserProc *pUserProc ) const;
192 CMethod *GetStaticMethodInfo( UserProc *pUserProc ) const;
193
194 //メソッドの存在を確認
195 bool IsExistMethod( const char *name ) const;
196 bool IsExistStaticMethod( const char *name ) const;
197
198 //メソッドを列挙
199 void EnumStaticMethod( const char *methodName, vector<UserProc *> &subs ) const;
200 void EnumMethod( const char *methodName, vector<UserProc *> &subs ) const;
201 void EnumMethod( const BYTE idOperatorCalc, vector<UserProc *> &subs ) const;
202 const std::vector<CMethod *> &GetMethods() const
203 {
204 return methods;
205 }
206 const std::vector<CMethod *> &GetStaticMethods() const
207 {
208 return staticMethods;
209 }
210
211 //デフォルト コンストラクタ メソッドを取得
212 CMethod *GetConstructorMethod() const;
213
214 //デストラクタ メソッドを取得
215 CMethod *GetDestructorMethod() const;
216
217 // メンバの総合サイズを取得
218 int GetSize() const;
219
220 // メンバのオフセットを取得
221 int GetMemberOffset( const char *memberName, int *pMemberNum = NULL ) const;
222
223private:
224 // アラインメント値を取得
225 int GetAlignment() const;
226
227
228 //vtbl
229private:
230 mutable long vtbl_offset;
231public:
232 int GetFuncNumInVtbl( const UserProc *pUserProc ) const;
233 LONG_PTR GetVtblGlobalOffset(void) const;
234 void ActionVtblSchedule(LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection);
235 bool IsAbstract() const;
236
237
238 //コンストラクタをコンパイルしているかどうかのチェックフラグ
239private:
240 mutable bool isCompilingConstructor;
241public:
242 void NotifyStartConstructorCompile() const;
243 void NotifyFinishConstructorCompile() const;
244 bool IsCompilingConstructor() const;
245
246 //デストラクタをコンパイルしているかどうかのチェックフラグ
247private:
248 mutable bool isCompilingDestructor;
249public:
250 void NotifyStartDestructorCompile() const;
251 void NotifyFinishDestructorCompile() const;
252 bool IsCompilingDestructor() const;
253
254
255 //自身の派生クラスかどうかを確認
256 bool IsSubClass( const CClass *pClass ) const;
257
258 //自身と等しいまたは派生クラスかどうかを確認
259 bool IsEqualsOrSubClass( const CClass *pClass ) const;
260
261 // 自身と等しいまたは派生クラス、基底クラスかどうかを確認
262 bool IsEqualsOrSubClassOrSuperClass( const CClass &objClass ) const;
263
264
265 //線形リスト用
266 CClass *pobj_NextClass;
267
268
269 //メンバの参照方法
270 enum RefType{
271 Non = 0, // no reference member
272 Dot, // obj.member
273 Pointer, // obj->member
274 };
275};
276
277#define MAX_CLASS_HASH 65535
278class CDBClass{
279 int hash(const char *name) const;
280 void DestroyClass(CClass *pobj_c);
281public:
282 CClass *pobj_ClassHash[MAX_CLASS_HASH];
283
284 CDBClass();
285 ~CDBClass();
286
287 const CClass *Find( const string &fullName ) const;
288 const CClass *Find( const NamespaceScopes &namespaceScopes, const string &name ) const;
289
290 CClass *AddClass( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const char *name,int nowLine);
291
292 void ActionVtblSchedule(LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection);
293
294private:
295 void AddMethod(CClass *pobj_c, DWORD dwAccess, BOOL bStatic, bool isConst, BOOL bAbstract,
296 BOOL bVirtual, BOOL bOverride, char *buffer, int nowLine);
297 BOOL MemberVar_LoopRefCheck(const CClass &objClass);
298public:
299 void InitNames(void);
300 void GetClass_recur(const char *lpszInheritsClass);
301 void GetAllClassInfo(void);
302 void Compile_System_InitializeUserTypes();
303
304
305 /////////////////////////////
306 // 特殊クラス
307 /////////////////////////////
308 CClass *pStringClass;
309 CClass *pObjectClass;
310 CClass *GetStringClassPtr() const;
311 CClass *GetObjectClassPtr() const;
312
313
314 /////////////////////////////
315 // 現在コンパイル中の情報
316 /////////////////////////////
317private:
318 const CClass *pCompilingClass;
319 CMethod *pCompilingMethod;
320public:
321 //コンパイル開始の通知を受け取るメソッド
322 void StartCompile( UserProc *pUserProc );
323
324 //現在コンパイル中のメソッド情報を取得
325 const CClass *GetNowCompilingClass() const;
326 CMethod *GetNowCompilingMethodInfo();
327
328
329 /////////////////////
330 // イテレータ
331 /////////////////////
332private:
333 CClass **ppobj_IteClass;
334 int iIteMaxNum;
335 int iIteNextNum;
336public:
337 void Iterator_Init(void);
338 void Iterator_Reset(void);
339 BOOL Iterator_HasNext(void);
340 CClass *Iterator_GetNext(void);
341 int Iterator_GetMaxCount(void);
342};
343
344
345extern CDBClass *pobj_DBClass;
346extern const CClass *pobj_CompilingClass;
Note: See TracBrowser for help on using the repository browser.