source: dev/BasicCompiler_Common/Class.h@ 102

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

名前空間機能をクラスに適用。

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