source: dev/BasicCompiler_Common/Class.h@ 101

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

名前空間機能をグローバル関数に適用(作業完了)。

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