source: dev/BasicCompiler_Common/Class.h@ 100

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

名前空間機能をグローバル関数に適用。

File size: 6.5 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 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 std::vector<CMember *> staticMembers;
66
67 //メソッド情報
68 std::vector<CMethod *> methods;
69 int ConstructorMemberSubIndex;
70 int DestructorMemberSubIndex;
71
72 //静的メソッド情報
73 std::vector<CMethod *> staticMethods;
74
75 enum ClassType{
76 Class,
77 Interface,
78 Enum,
79 Delegate,
80 Structure,
81 };
82
83 ClassType classType;
84
85 bool isUsing;
86
87public:
88 //クラス名
89 char *name;
90
91 //継承クラスへのポインタ
92 CClass *pobj_InheritsClass;
93
94 //メンバ情報
95 CMember **ppobj_Member;
96 int iMemberNum;
97
98 //仮想関数の数
99 int vtbl_num;
100
101 //アラインメント値
102 int iAlign;
103
104
105public:
106 CClass(const char *name);
107 ~CClass();
108
109 bool IsUsing() const;
110 void Using();
111
112 bool IsClass() const;
113 bool IsInterface() const;
114 bool IsEnum() const;
115 bool IsDelegate() const;
116 bool IsStructure() const;
117
118 //継承させる
119 bool Inherits( CClass &inheritsClass, int nowLine );
120 bool InheritsInterface( CClass &inheritsClass, int nowLine );
121
122 //メンバ、メソッドの追加
123 void AddMember( DWORD dwAccess, bool idConst, bool isRef, char *buffer );
124 void AddStaticMember( DWORD dwAccess, bool isConst, bool isRef, char *buffer, int nowLine );
125 void AddMethod( UserProc *pUserProc,DWORD dwAccess, bool isConst, BOOL bAbstract, BOOL bVirtual );
126 void AddStaticMethod(UserProc *pUserProc,DWORD dwAccess);
127
128 //重複チェック
129 BOOL DupliCheckAll(const char *name);
130 BOOL DupliCheckMember(const char *name);
131
132 //メソッド取得
133 CMethod *GetMethodInfo( UserProc *pUserProc ) const;
134 CMethod *GetStaticMethodInfo( UserProc *pUserProc ) const;
135
136 //メソッドの存在を確認
137 bool IsExistMethod( const char *name ) const;
138 bool IsExistStaticMethod( const char *name ) const;
139
140 //メソッドを列挙
141 void EnumStaticMethod( const char *methodName, vector<UserProc *> &subs ) const;
142 void EnumMethod( const char *methodName, vector<UserProc *> &subs ) const;
143 void EnumMethod( const BYTE idOperatorCalc, vector<UserProc *> &subs ) const;
144 const std::vector<CMethod *> &GetMethods() const
145 {
146 return methods;
147 }
148 const std::vector<CMethod *> &GetStaticMethods() const
149 {
150 return staticMethods;
151 }
152
153 //デフォルト コンストラクタ メソッドを取得
154 CMethod *GetConstructorMethod() const;
155
156 //デストラクタ メソッドを取得
157 CMethod *GetDestructorMethod() const;
158
159 // メンバの総合サイズを取得
160 int GetSize() const;
161
162 // メンバのオフセットを取得
163 int GetMemberOffset( const char *memberName, int *pMemberNum = NULL ) const;
164
165private:
166 // アラインメント値を取得
167 int GetAlignment() const;
168
169
170 //vtbl
171private:
172 long vtbl_offset;
173public:
174 int GetFuncNumInVtbl( const UserProc *pUserProc ) const;
175 LONG_PTR GetVtblGlobalOffset(void);
176 void ActionVtblSchedule(LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection);
177 bool IsAbstract() const;
178
179
180 //コンストラクタをコンパイルしているかどうかのチェックフラグ
181private:
182 bool isCompilingConstructor;
183public:
184 void NotifyStartConstructorCompile();
185 void NotifyFinishConstructorCompile();
186 bool IsCompilingConstructor() const;
187
188 //デストラクタをコンパイルしているかどうかのチェックフラグ
189private:
190 bool isCompilingDestructor;
191public:
192 void NotifyStartDestructorCompile();
193 void NotifyFinishDestructorCompile();
194 bool IsCompilingDestructor() const;
195
196
197 //自身と等しいクラスかどうかを確認
198 bool IsEquals( const CClass *pClass ) const;
199
200 //自身の派生クラスかどうかを確認
201 bool IsSubClass( const CClass *pClass ) const;
202
203 //自身と等しいまたは派生クラスかどうかを確認
204 bool IsEqualsOrSubClass( const CClass *pClass ) const;
205
206 // 自身と等しいまたは派生クラス、基底クラスかどうかを確認
207 bool IsEqualsOrSubClassOrSuperClass( const CClass &objClass ) const;
208
209
210 //線形リスト用
211 CClass *pobj_NextClass;
212
213
214 //メンバの参照方法
215 enum RefType{
216 Non = 0, // no reference member
217 Dot, // obj.member
218 Pointer, // obj->member
219 };
220};
221
222#define MAX_CLASS_HASH 65535
223class CDBClass{
224 int hash(const char *name);
225 void DestroyClass(CClass *pobj_c);
226public:
227 CClass *pobj_ClassHash[MAX_CLASS_HASH];
228
229 CDBClass();
230 ~CDBClass();
231
232 CClass *check(const char *name);
233
234 CClass *AddClass(const char *name,int nowLine);
235
236 void ActionVtblSchedule(LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection);
237
238private:
239 void AddMethod(CClass *pobj_c, DWORD dwAccess, BOOL bStatic, bool isConst, BOOL bAbstract,
240 BOOL bVirtual, BOOL bOverride, char *buffer, int nowLine);
241 BOOL MemberVar_LoopRefCheck(const CClass &objClass);
242public:
243 void InitNames(void);
244 void GetClass_recur(const char *lpszInheritsClass);
245 void GetAllClassInfo(void);
246 void Compile_System_InitializeUserTypes();
247
248
249 /////////////////////////////
250 // 特殊クラス
251 /////////////////////////////
252 CClass *pStringClass;
253 CClass *pObjectClass;
254 CClass *GetStringClass() const;
255 CClass *GetObjectClass() const;
256
257
258 /////////////////////////////
259 // 現在コンパイル中の情報
260 /////////////////////////////
261private:
262 CClass *pCompilingClass;
263 CMethod *pCompilingMethod;
264public:
265 //コンパイル開始の通知を受け取るメソッド
266 void StartCompile( UserProc *pUserProc );
267
268 //現在コンパイル中のメソッド情報を取得
269 CClass *GetNowCompilingClass();
270 CMethod *GetNowCompilingMethodInfo();
271
272
273 /////////////////////
274 // イテレータ
275 /////////////////////
276private:
277 CClass **ppobj_IteClass;
278 int iIteMaxNum;
279 int iIteNextNum;
280public:
281 void Iterator_Init(void);
282 void Iterator_Reset(void);
283 BOOL Iterator_HasNext(void);
284 CClass *Iterator_GetNext(void);
285 int Iterator_GetMaxCount(void);
286};
287
288
289extern CDBClass *pobj_DBClass;
290extern CClass *pobj_CompilingClass;
Note: See TracBrowser for help on using the repository browser.