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

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