source: dev/trunk/ab5.0/abdev/ab_common/include/Lexical/Class.h@ 629

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

ObjectModuleに関連するクラス一式をab_commonプロジェクトに移動した。

File size: 12.1 KB
Line 
1#pragma once
2
3class UserProc;
4class Delegate;
5
6class ClassPrototype : public Prototype, public DynamicMethodsPrototype
7{
8 // XMLシリアライズ用
9private:
10 friend class boost::serialization::access;
11 template<class Archive> void serialize(Archive& ar, const unsigned int version)
12 {
13 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Prototype );
14 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( DynamicMethodsPrototype );
15 }
16
17public:
18 ClassPrototype( const NamespaceScopes &namespaceScopes, const std::string &name )
19 : Prototype( namespaceScopes, name )
20 , DynamicMethodsPrototype()
21 {
22 }
23 ClassPrototype()
24 : Prototype()
25 , DynamicMethodsPrototype()
26 {
27 }
28};
29
30class CClass: public ClassPrototype, public Jenga::Common::ObjectInHashmap<CClass>
31{
32public:
33 // 型の種類
34 enum ClassType{
35 Class,
36 Interface,
37 ComInterface,
38 Enum,
39 Delegate,
40 Structure,
41 };
42
43private:
44 ClassType classType;
45
46 // importされている名前空間
47 NamespaceScopesCollection importedNamespaces;
48
49 // 型パラメータ
50 GenericTypes formalGenericTypes;
51
52 // 基底クラス
53 const CClass *pSuperClass;
54
55 // 基底クラスの型パラメータ(実パラメータ)
56 Types superClassActualTypeParameters;
57
58 // Blittable型情報
59 Type blittableType;
60
61 // 実装するインターフェイス
62 Interfaces interfaces;
63
64 // 動的メンバ
65 Members dynamicMembers;
66
67 // 静的メンバ
68 Members staticMembers;
69
70 // 動的メソッド
71 int ConstructorMemberSubIndex;
72 int DestructorMemberSubIndex;
73 int vtblNum; // 仮想関数の数
74
75 // 静的メソッド
76 Methods staticMethods;
77
78 //アラインメント値
79 int fixedAlignment;
80
81 // XMLシリアライズ用
82private:
83 friend class boost::serialization::access;
84 template<class Archive> void serialize(Archive& ar, const unsigned int version)
85 {
86 trace_for_serialize( "serializing - CClass" );
87
88 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( ClassPrototype );
89 ar & BOOST_SERIALIZATION_NVP( classType );
90 ar & BOOST_SERIALIZATION_NVP( importedNamespaces );
91 ar & BOOST_SERIALIZATION_NVP( formalGenericTypes );
92 ar & boost::serialization::make_nvp( "pSuperClass", const_cast<CClass *&>(pSuperClass) );
93 ar & BOOST_SERIALIZATION_NVP( superClassActualTypeParameters );
94 ar & BOOST_SERIALIZATION_NVP( blittableType );
95 ar & BOOST_SERIALIZATION_NVP( interfaces );
96 ar & BOOST_SERIALIZATION_NVP( dynamicMembers );
97 ar & BOOST_SERIALIZATION_NVP( staticMembers );
98 ar & BOOST_SERIALIZATION_NVP( ConstructorMemberSubIndex );
99 ar & BOOST_SERIALIZATION_NVP( DestructorMemberSubIndex );
100 ar & BOOST_SERIALIZATION_NVP( vtblNum );
101 ar & BOOST_SERIALIZATION_NVP( staticMethods );
102 ar & BOOST_SERIALIZATION_NVP( fixedAlignment );
103 }
104
105 bool isReady;
106public:
107
108 CClass( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const std::string &name )
109 : ClassPrototype( namespaceScopes, name )
110 , importedNamespaces( importedNamespaces )
111 , classType( Class )
112 , pSuperClass( NULL )
113 , blittableType( Type() )
114 , isReady( false )
115 , fixedAlignment( 0 )
116 , ConstructorMemberSubIndex( -1 )
117 , DestructorMemberSubIndex( -1 )
118 , vtblNum( 0 )
119 , vtbl_offset( -1 )
120 , comVtblOffset( 0 )
121 , isCompilingConstructor( false )
122 , isCompilingDestructor( false )
123 , cacheSize( 0 )
124 {
125 }
126 CClass()
127 : ClassPrototype()
128 , importedNamespaces()
129 , classType()
130 , pSuperClass( NULL )
131 , blittableType( Type() )
132 , isReady( false )
133 , fixedAlignment( 0 )
134 , ConstructorMemberSubIndex( -1 )
135 , DestructorMemberSubIndex( -1 )
136 , vtblNum( 0 )
137 , vtbl_offset( -1 )
138 , comVtblOffset( 0 )
139 , isCompilingConstructor( false )
140 , isCompilingDestructor( false )
141 , cacheSize( 0 )
142 {
143 }
144 ~CClass()
145 {
146 // 動的メンバ
147 BOOST_FOREACH( Member *member, dynamicMembers )
148 {
149 delete member;
150 }
151
152 // 静的メンバ
153 BOOST_FOREACH( Member *member, staticMembers )
154 {
155 delete member;
156 }
157
158 // インターフェイス
159 BOOST_FOREACH( ::Interface *pInterface, interfaces )
160 {
161 delete pInterface;
162 }
163 }
164
165 virtual const std::string &GetKeyName() const
166 {
167 return GetName();
168 }
169 virtual bool IsDuplication( const CClass *pClass ) const
170 {
171 if( pClass->IsEqualSymbol( *this ) )
172 {
173 return true;
174 }
175 return false;
176 }
177
178 virtual void Using() const;
179
180 void Readed(){
181 isReady = true;
182 }
183 bool IsReady() const{
184 return isReady;
185 }
186
187 const NamespaceScopesCollection &GetImportedNamespaces() const
188 {
189 return importedNamespaces;
190 }
191
192 // 型パラメータ
193 const GenericTypes &GetFormalGenericTypes() const
194 {
195 return formalGenericTypes;
196 }
197 void AddFormalGenericType( GenericType genericType )
198 {
199 this->formalGenericTypes.push_back( genericType );
200 }
201 int GetFormalGenericTypeParameterIndex( const std::string &name ) const
202 {
203 int i = 0;
204 BOOST_FOREACH( const GenericType &genericType, formalGenericTypes )
205 {
206 if( genericType.GetName() == name )
207 {
208 return i;
209 }
210 i++;
211 }
212 return -1;
213 }
214 bool IsExistFormalGenericTypeParameter( const std::string &name ) const
215 {
216 BOOST_FOREACH( const GenericType &genericType, formalGenericTypes )
217 {
218 if( genericType.GetName() == name )
219 {
220 return true;
221 }
222 }
223 return false;
224 }
225 bool IsGeneric() const
226 {
227 return ( this->formalGenericTypes.size() != 0 );
228 }
229
230 // 継承元クラス
231 bool HasSuperClass() const
232 {
233 return ( pSuperClass != NULL );
234 }
235 const CClass &GetSuperClass() const
236 {
237 return *pSuperClass;
238 }
239 void SetSuperClass( const CClass *pSuperClass )
240 {
241 this->pSuperClass = pSuperClass;
242 }
243 const Types &GetSuperClassActualTypeParameters() const
244 {
245 return superClassActualTypeParameters;
246 }
247 void SetSuperClassActualTypeParameters( const Types &actualTypeParameters )
248 {
249 this->superClassActualTypeParameters = actualTypeParameters;
250 }
251
252 // Blittable型
253 bool IsBlittableType() const
254 {
255 return !blittableType.IsNull();
256 }
257 const Type &GetBlittableType() const
258 {
259 return blittableType;
260 }
261 void SetBlittableType( const Type &type ){
262 blittableType = type;
263 }
264
265 bool IsClass() const;
266 bool IsInterface() const;
267 bool IsComInterface() const;
268 bool IsEnum() const;
269 bool IsDelegate() const;
270 bool IsStructure() const;
271 void SetClassType( ClassType classType )
272 {
273 this->classType = classType;
274 }
275
276
277 //コンストラクタをコンパイルしているかどうかのチェックフラグ
278private:
279 mutable bool isCompilingConstructor;
280public:
281 void NotifyStartConstructorCompile() const;
282 void NotifyFinishConstructorCompile() const;
283 bool IsCompilingConstructor() const;
284
285 //デストラクタをコンパイルしているかどうかのチェックフラグ
286private:
287 mutable bool isCompilingDestructor;
288public:
289 void NotifyStartDestructorCompile() const;
290 void NotifyFinishDestructorCompile() const;
291 bool IsCompilingDestructor() const;
292
293
294 //自身の派生クラスかどうかを確認
295 bool IsSubClass( const CClass *pClass ) const;
296
297 //自身と等しいまたは派生クラスかどうかを確認
298 bool IsEqualsOrSubClass( const CClass *pClass ) const;
299
300 // 自身と等しいまたは派生クラス、基底クラスかどうかを確認
301 bool IsEqualsOrSubClassOrSuperClass( const CClass &objClass ) const;
302
303 // インターフェイス
304 bool HasInterfaces() const
305 {
306 return ( interfaces.size() != 0 );
307 }
308 void AddInterface( ::Interface *pInterface )
309 {
310 interfaces.push_back( pInterface );
311 }
312 const Interfaces &GetInterfaces() const
313 {
314 return interfaces;
315 }
316 bool IsInheritsInterface( const CClass *pInterfaceClass ) const;
317
318 // クラス継承
319 bool InheritsClass( const CClass &inheritsClass, const Types &actualTypeParameters, int nowLine );
320
321 //メンバ、メソッドの追加
322 void AddDynamicMember( Member *pMember );
323 void AddStaticMember( Member *pMember );
324
325 //重複チェック
326 bool DupliCheckAll(const char *name) const;
327 bool DupliCheckMember(const char *name) const;
328
329 const Members &GetDynamicMembers() const
330 {
331 return dynamicMembers;
332 }
333 const Members &GetStaticMembers() const
334 {
335 return staticMembers;
336 }
337 Members &GetDynamicMembers()
338 {
339 return dynamicMembers;
340 }
341 Members &GetStaticMembers()
342 {
343 return staticMembers;
344 }
345
346 const Member *FindDynamicMember( const char *memberName ) const;
347 bool HasDynamicMember( const char *memberName ) const
348 {
349 return ( FindDynamicMember( memberName ) != NULL );
350 }
351
352 void EnumDynamicMethodsOrInterfaceMethods( const char *methodName, std::vector<const UserProc *> &subs ) const;
353 const CMethod *GetDynamicMethodOrInterfaceMethod( const UserProc *pUserProc ) const;
354
355 const Methods &GetStaticMethods() const
356 {
357 return staticMethods;
358 }
359 Methods &GetStaticMethods()
360 {
361 return staticMethods;
362 }
363
364 //デフォルト コンストラクタ
365 const CMethod *GetConstructorMethod() const
366 {
367 if( ConstructorMemberSubIndex == -1 ) return NULL;
368 return GetDynamicMethods()[ConstructorMemberSubIndex];
369 }
370 void SetConstructorMemberSubIndex( int constructorMemberSubIndex )
371 {
372 this->ConstructorMemberSubIndex = constructorMemberSubIndex;
373 }
374
375 //デストラクタ メソッドを取得
376 const CMethod *GetDestructorMethod() const
377 {
378 if( DestructorMemberSubIndex == -1 ) return NULL;
379 return GetDynamicMethods()[DestructorMemberSubIndex];
380 }
381 void SetDestructorMemberSubIndex( int destructorMemberSubIndex )
382 {
383 this->DestructorMemberSubIndex = destructorMemberSubIndex;
384 }
385
386 // ユーザ指定のアラインメント固定値
387 int GetFixedAlignment() const
388 {
389 return fixedAlignment;
390 }
391 void SetFixedAlignment( int fixedAlignment )
392 {
393 this->fixedAlignment = fixedAlignment;
394 }
395
396 // メンバの総合サイズを取得
397private:
398 int cacheSize;
399public:
400 int GetSize() const;
401
402 // メンバのオフセットを取得
403 int GetMemberOffset( const char *memberName ) const;
404private:
405 // アラインメント値を取得
406 int GetAlignment() const;
407
408
409 /////////////////////////////////////////////////////////////////
410 // vtbl
411 /////////////////////////////////////////////////////////////////
412public:
413 // vtblに存在する仮想関数の数
414 int GetVtblNum() const
415 {
416 return vtblNum;
417 }
418 void SetVtblNum( int vtblNum )
419 {
420 this->vtblNum = vtblNum;
421 }
422 void AddVtblNum( int vtblNum )
423 {
424 this->vtblNum += vtblNum;
425 }
426 bool IsExistVirtualFunctions() const
427 {
428 // 構造体以外は仮想関数を持つ
429 return !IsStructure();
430 }
431
432private:
433 int vtbl_offset;
434 int comVtblOffset;
435 int vtblMasterListOffset;
436public:
437 std::vector<long> vtblMasterList;
438 int GetVtblOffset() const
439 {
440 return vtbl_offset;
441 }
442 void SetVtblOffset( int vtblOffset )
443 {
444 this->vtbl_offset = vtblOffset;
445 }
446 int GetComVtblOffset() const
447 {
448 return comVtblOffset;
449 }
450 void SetComVtblOffset( int comVtblOffset )
451 {
452 this->comVtblOffset = comVtblOffset;
453 }
454 void GetVtblMasterListIndexAndVtblIndex( const UserProc *pUserProc, int &vtblMasterListIndex, int &vtblIndex ) const;
455 int GetVtblMasterListIndex( const CClass *pClass ) const;
456 long GetVtblMasterListOffset() const;
457 void SetVtblMasterListOffset( int vtblMasterListOffset )
458 {
459 this->vtblMasterListOffset = vtblMasterListOffset;
460 }
461 bool IsAbstract() const;
462
463
464 // TypeInfo用
465 mutable int typeInfoDataTableOffset;
466 void SetTypeInfoDataTableOffset( int typeInfoDataTableOffset ) const
467 {
468 this->typeInfoDataTableOffset = typeInfoDataTableOffset;
469 }
470 int GetTypeInfoDataTableOffset() const
471 {
472 return typeInfoDataTableOffset;
473 }
474
475 // 動的型データ用のメンバデータを取得
476 std::string GetStaticDefiningStringAsMemberNames() const;
477 std::string GetStaticDefiningStringAsMemberOffsets() const;
478 void GetReferenceOffsetsInitializeBuffer( std::string &referenceOffsetsBuffer, int &numOfReference, int baseOffset = 0 ) const;
479};
480
481class Classes : public Jenga::Common::Hashmap<CClass>
482{
483 // XMLシリアライズ用
484public:
485 Classes()
486 : pStringClass( NULL )
487 , pObjectClass( NULL )
488 , pInterfaceInfo( NULL )
489 {
490 }
491 ~Classes()
492 {
493 }
494
495 bool Insert( CClass *pClass, int nowLine );
496 CClass *Add( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const char *name,int nowLine);
497
498 const CClass *FindEx( const Symbol &symbol ) const;
499
500
501 /////////////////////////////
502 // 特殊クラス
503 /////////////////////////////
504 mutable const CClass *pStringClass;
505 mutable const CClass *pObjectClass;
506 mutable const CClass *pInterfaceInfo;
507 const CClass *GetStringClassPtr() const;
508 const CClass *GetObjectClassPtr() const;
509 const CClass *GetInterfaceInfoClassPtr() const;
510};
Note: See TracBrowser for help on using the repository browser.