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

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