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

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