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

Last change on this file since 632 was 632, checked in by dai_9181, 16 years ago

ジェネリッククラスの型パラメータに値型が指定されたときに限り、テンプレート展開を行うようにした。

TODO: libファイルを跨ってテンプレート展開ができていないため、ソースコード管理部分に手を加える必要あり。

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