source: dev/BasicCompiler_Common/Class.h@ 132

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

Prototypeクラスを用意した。

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