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

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

jengaライブラリに一通りserializeメソッドを仕込んだ

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