source: dev/trunk/jenga/include/smoothie/Class.h@ 180

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

Meta::GetClassesメソッドを追加

File size: 8.1 KB
Line 
1#pragma once
2
3#include "Prototype.h"
4#include "Member.h"
5#include "Method.h"
6#include "LexicalAnalysis.h"
7
8class InheritedInterface
9{
10 CClass *pInterfaceClass;
11 int vtblOffset;
12public:
13 InheritedInterface( CClass *pInterfaceClass, int vtblOffset )
14 : pInterfaceClass( pInterfaceClass )
15 , vtblOffset( vtblOffset )
16 {
17 }
18
19 CClass &GetInterfaceClass() const{
20 return *pInterfaceClass;
21 }
22 int GetVtblOffset() const
23 {
24 return vtblOffset;
25 }
26};
27typedef vector<InheritedInterface> Interfaces;
28
29class CClass : public Prototype
30{
31public:
32 // メンバの参照方法
33 enum RefType{
34 Non = 0, // no reference member
35 Dot, // obj.member
36 Pointer, // obj->member
37 };
38
39 // 型の種類
40 enum ClassType{
41 Class,
42 Interface,
43 Enum,
44 Delegate,
45 Structure,
46 };
47
48private:
49 ClassType classType;
50
51 bool isReady;
52 void Readed(){
53 isReady = true;
54 }
55 bool IsReady() const{
56 return isReady;
57 }
58
59 // importされている名前空間
60 NamespaceScopesCollection importedNamespaces;
61
62 // 継承するインターフェイス
63 Interfaces interfaces;
64
65 // Blittable型情報
66 Type blittableType;
67
68 // 動的メンバ
69 Members dynamicMembers;
70
71 // 静的メンバ
72 Members staticMembers;
73
74 // 動的メソッド
75 Methods methods;
76 int ConstructorMemberSubIndex;
77 int DestructorMemberSubIndex;
78 int vtblNum; // 仮想関数の数
79
80 // 静的メソッド
81 Methods staticMethods;
82
83public:
84 //継承クラスへのポインタ
85 const CClass *pobj_InheritsClass;
86
87 //アラインメント値
88 int iAlign;
89
90 CClass( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const string &name );
91 ~CClass();
92
93 const NamespaceScopesCollection &GetImportedNamespaces() const
94 {
95 return importedNamespaces;
96 }
97
98 // インターフェイス
99 bool HasInterfaces() const
100 {
101 return ( interfaces.size() != 0 );
102 }
103 bool IsInheritsInterface( const CClass *pInterfaceClass ) const;
104
105 // Blittable型
106 bool IsBlittableType() const
107 {
108 return !blittableType.IsNull();
109 }
110 const Type &GetBlittableType() const
111 {
112 return blittableType;
113 }
114 void SetBlittableType( const Type &type ){
115 blittableType = type;
116 }
117
118 bool IsClass() const;
119 bool IsInterface() const;
120 bool IsEnum() const;
121 bool IsDelegate() const;
122 bool IsStructure() const;
123 void SetClassType( ClassType classType )
124 {
125 this->classType = classType;
126 }
127
128 //継承させる
129 bool Inherits( const char *inheritNames, int nowLine );
130 bool InheritsClass( const CClass &inheritsClass, int nowLine );
131 bool InheritsInterface( const CClass &inheritsClass, int nowLine );
132
133 //メンバ、メソッドの追加
134 void AddMember( Prototype::Accessibility accessibility, bool idConst, bool isRef, char *buffer );
135 void AddStaticMember( Prototype::Accessibility accessibility, bool isConst, bool isRef, char *buffer, int nowLine );
136
137 //重複チェック
138 BOOL DupliCheckAll(const char *name);
139 BOOL DupliCheckMember(const char *name);
140
141 const Members &GetDynamicMembers() const
142 {
143 return dynamicMembers;
144 }
145 const Members &GetStaticMembers() const
146 {
147 return staticMembers;
148 }
149 Members &GetDynamicMembers()
150 {
151 return dynamicMembers;
152 }
153 Members &GetStaticMembers()
154 {
155 return staticMembers;
156 }
157
158 const Methods &GetMethods() const
159 {
160 return methods;
161 }
162 const Methods &GetStaticMethods() const
163 {
164 return staticMethods;
165 }
166 Methods &GetMethods()
167 {
168 return methods;
169 }
170 Methods &GetStaticMethods()
171 {
172 return staticMethods;
173 }
174
175 //デフォルト コンストラクタ メソッドを取得
176 const CMethod *GetConstructorMethod() const;
177
178 //デストラクタ メソッドを取得
179 const CMethod *GetDestructorMethod() const;
180
181 // vtblに存在する仮想関数の数
182 int GetVtblNum() const
183 {
184 return vtblNum;
185 }
186 void SetVtblNum( int vtblNum )
187 {
188 this->vtblNum = vtblNum;
189 }
190 void AddVtblNum( int vtblNum )
191 {
192 this->vtblNum += vtblNum;
193 }
194 bool IsExistVirtualFunctions() const
195 {
196 return ( vtblNum > 0 );
197 }
198
199 // メンバの総合サイズを取得
200 int GetSize() const;
201
202 // メンバのオフセットを取得
203 int GetMemberOffset( const char *memberName, int *pMemberNum = NULL ) const;
204
205private:
206 // アラインメント値を取得
207 int GetAlignment() const;
208
209
210 //vtbl
211private:
212 mutable long vtbl_offset;
213public:
214 int GetFuncNumInVtbl( const UserProc *pUserProc ) const;
215 LONG_PTR GetVtblGlobalOffset(void) const;
216 void ActionVtblSchedule(LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection);
217 bool IsAbstract() const;
218
219
220 //コンストラクタをコンパイルしているかどうかのチェックフラグ
221private:
222 mutable bool isCompilingConstructor;
223public:
224 void NotifyStartConstructorCompile() const;
225 void NotifyFinishConstructorCompile() const;
226 bool IsCompilingConstructor() const;
227
228 //デストラクタをコンパイルしているかどうかのチェックフラグ
229private:
230 mutable bool isCompilingDestructor;
231public:
232 void NotifyStartDestructorCompile() const;
233 void NotifyFinishDestructorCompile() const;
234 bool IsCompilingDestructor() const;
235
236
237 //自身の派生クラスかどうかを確認
238 bool IsSubClass( const CClass *pClass ) const;
239
240 //自身と等しいまたは派生クラスかどうかを確認
241 bool IsEqualsOrSubClass( const CClass *pClass ) const;
242
243 // 自身と等しいまたは派生クラス、基底クラスかどうかを確認
244 bool IsEqualsOrSubClassOrSuperClass( const CClass &objClass ) const;
245
246
247 //線形リスト用
248 CClass *pobj_NextClass;
249
250
251 static bool SplitName( const char *desc, char *object, char *member, CClass::RefType &refType ){
252 int lastIndex = -1;
253 for( int i=0; desc[i]; i++ ){
254 if( desc[i] == '(' ){
255 i=JumpStringInPare(desc,i+1);
256 continue;
257 }
258 else if( desc[i] == '[' ){
259 i=JumpStringInBracket(desc,i+1);
260 continue;
261 }
262 else if(desc[i]=='.'||(desc[i]==1&&desc[i+1]==ESC_PSMEM)){
263 lastIndex = i;
264 }
265 }
266 if( lastIndex == -1 ){
267 lstrcpy( member, desc );
268 return false;
269 }
270
271 if(desc[lastIndex]=='.'){
272 lstrcpy(member,desc+lastIndex+1);
273 refType = CClass::Dot;
274 }
275 else{
276 lstrcpy(member,desc+lastIndex+2);
277 refType = CClass::Pointer;
278 }
279
280 if( object ){
281 lstrcpy( object, desc );
282 object[lastIndex]=0;
283 }
284
285 return true;
286 }
287 static bool SplitName( const char *desc, char *object, char *member ){
288 CClass::RefType dummyRefType;
289 return SplitName( desc, object, member, dummyRefType );
290 }
291};
292
293#define MAX_CLASS_HASH 65535
294class Classes
295{
296 int hash(const char *name) const;
297 void DestroyClass(CClass *pobj_c);
298public:
299 CClass *pobj_ClassHash[MAX_CLASS_HASH];
300
301 Classes();
302 ~Classes();
303 void Clear();
304
305 const CClass *Find( const string &fullName ) const;
306 const CClass *Find( const NamespaceScopes &namespaceScopes, const string &name ) const;
307
308 CClass *AddClass( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const char *name,int nowLine);
309
310 void ActionVtblSchedule(LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection);
311
312private:
313 void AddMethod(CClass *pobj_c, Prototype::Accessibility accessibility, BOOL bStatic, bool isConst, bool isAbstract,
314 bool isVirtual, bool isOverride, char *buffer, int nowLine);
315 BOOL MemberVar_LoopRefCheck(const CClass &objClass);
316public:
317
318 // 実体収集
319 virtual void CollectClassesForNameOnly( const BasicSource &source ) = 0;
320 virtual void GetAllClassInfo() = 0;
321 virtual void Compile_System_InitializeUserTypes() = 0;
322 virtual void InitStaticMember() = 0;
323
324
325 /////////////////////////////
326 // 特殊クラス
327 /////////////////////////////
328 CClass *pStringClass;
329 CClass *pObjectClass;
330 CClass *GetStringClassPtr() const;
331 CClass *GetObjectClassPtr() const;
332
333
334 /////////////////////////////
335 // 現在コンパイル中の情報
336 /////////////////////////////
337private:
338 const CClass *pCompilingClass;
339 const CMethod *pCompilingMethod;
340public:
341 //コンパイル開始の通知を受け取るメソッド
342 void StartCompile( UserProc *pUserProc );
343
344 //現在コンパイル中のメソッド情報を取得
345 const CClass *GetNowCompilingClass() const;
346 const CMethod *GetNowCompilingMethodInfo();
347
348
349 /////////////////////
350 // イテレータ
351 /////////////////////
352private:
353 CClass **ppobj_IteClass;
354 int iIteMaxNum;
355 int iIteNextNum;
356public:
357 void Iterator_Init(void);
358 void Iterator_Reset(void);
359 BOOL Iterator_HasNext(void);
360 CClass *Iterator_GetNext(void);
361 int Iterator_GetMaxCount(void);
362};
Note: See TracBrowser for help on using the repository browser.