source: dev/BasicCompiler_Common/Class.h@ 90

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

実行時型情報の生成にほぼ対応した。

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