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

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

#171への対応。テンプレート展開後のクラスメソッドの実装で、SizeOf(T)が正常値を返さない不具合を修正(特にTが4バイト未満の型場合)。

File size: 12.6 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 Symbol &symbol )
21 : Prototype( symbol )
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 Types expandedClassActualTypeParameters;
86
87 // XMLシリアライズ用
88private:
89 friend class boost::serialization::access;
90 template<class Archive> void serialize(Archive& ar, const unsigned int version)
91 {
92 trace_for_serialize( "serializing - CClass" );
93
94 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( ClassPrototype );
95
96 if( ActiveBasic::Common::Environment::IsRemoveExternal() )
97 {
98 if( this->IsExternal() )
99 {
100 this->NeedResolve();
101 return;
102 }
103 }
104
105 ar & BOOST_SERIALIZATION_NVP( classType );
106 ar & BOOST_SERIALIZATION_NVP( importedNamespaces );
107 ar & BOOST_SERIALIZATION_NVP( formalGenericTypes );
108 ar & boost::serialization::make_nvp( "pSuperClass", const_cast<CClass *&>(pSuperClass) );
109 ar & BOOST_SERIALIZATION_NVP( superClassActualTypeParameters );
110 ar & BOOST_SERIALIZATION_NVP( blittableType );
111 ar & BOOST_SERIALIZATION_NVP( interfaces );
112 ar & BOOST_SERIALIZATION_NVP( dynamicMembers );
113 ar & BOOST_SERIALIZATION_NVP( staticMembers );
114 ar & BOOST_SERIALIZATION_NVP( ConstructorMemberSubIndex );
115 ar & BOOST_SERIALIZATION_NVP( DestructorMemberSubIndex );
116 ar & BOOST_SERIALIZATION_NVP( vtblNum );
117 ar & BOOST_SERIALIZATION_NVP( staticMethods );
118 ar & BOOST_SERIALIZATION_NVP( fixedAlignment );
119 ar & BOOST_SERIALIZATION_NVP( expandedTemplateClasses );
120 ar & BOOST_SERIALIZATION_NVP( expandedClassActualTypeParameters );
121 }
122
123 bool isReady;
124public:
125
126 CClass( const Symbol &symbol, const NamespaceScopesCollection &importedNamespaces );
127 CClass( const Symbol &symbol,
128 const NamespaceScopesCollection &importedNamespaces,
129 ClassType classType,
130 const GenericTypes &formalGenericTypes,
131 const Types &superClassActualTypeParameters,
132 int ConstructorMemberSubIndex,
133 int DestructorMemberSubIndex,
134 int vtblNum,
135 int fixedAlignment,
136 const Types &expandedClassActualTypeParameters );
137 CClass();
138 ~CClass();
139
140 virtual const std::string &GetKeyName() const
141 {
142 return GetName();
143 }
144 virtual bool IsDuplication( const CClass *pClass ) const
145 {
146 if( pClass->IsEqualSymbol( *this ) )
147 {
148 return true;
149 }
150 return false;
151 }
152 bool Equals( const CClass *pClass ) const
153 {
154 // ポインタが等しいかどうかを見てみる
155 if( this == pClass )
156 {
157 return true;
158 }
159 else if( this->IsNeedResolve() || pClass->IsNeedResolve() )
160 {
161 // 依存関係解決前の状態であれば、パスが等しいかどうかを見てみる
162 if( this->IsDuplication( pClass ) )
163 {
164 return true;
165 }
166 }
167 return false;
168 }
169
170 virtual void Using() const;
171
172 void Readed(){
173 isReady = true;
174 }
175 bool IsReady() const{
176 return isReady;
177 }
178
179 const NamespaceScopesCollection &GetImportedNamespaces() const
180 {
181 return importedNamespaces;
182 }
183
184 // 型パラメータ
185 const GenericTypes &GetFormalGenericTypes() const
186 {
187 return formalGenericTypes;
188 }
189 void AddFormalGenericType( GenericType genericType )
190 {
191 this->formalGenericTypes.push_back( genericType );
192 }
193 int GetFormalGenericTypeParameterIndex( const std::string &name ) const
194 {
195 int i = 0;
196 BOOST_FOREACH( const GenericType &genericType, formalGenericTypes )
197 {
198 if( genericType.GetName() == name )
199 {
200 return i;
201 }
202 i++;
203 }
204 return -1;
205 }
206 bool IsExistFormalGenericTypeParameter( const std::string &name ) const
207 {
208 BOOST_FOREACH( const GenericType &genericType, formalGenericTypes )
209 {
210 if( genericType.GetName() == name )
211 {
212 return true;
213 }
214 }
215 return false;
216 }
217 bool IsGeneric() const
218 {
219 return ( this->formalGenericTypes.size() != 0 );
220 }
221
222 // 継承元クラス
223 bool HasSuperClass() const
224 {
225 return ( pSuperClass != NULL );
226 }
227 const CClass &GetSuperClass() const
228 {
229 return *pSuperClass;
230 }
231 void SetSuperClass( const CClass *pSuperClass )
232 {
233 this->pSuperClass = pSuperClass;
234 }
235 const Types &GetSuperClassActualTypeParameters() const
236 {
237 return superClassActualTypeParameters;
238 }
239 void SetSuperClassActualTypeParameters( const Types &actualTypeParameters )
240 {
241 this->superClassActualTypeParameters = actualTypeParameters;
242 }
243
244 // Blittable型
245 bool IsBlittableType() const
246 {
247 return !blittableType.IsNull();
248 }
249 const Type &GetBlittableType() const
250 {
251 return blittableType;
252 }
253 void SetBlittableType( const Type &type ){
254 blittableType = type;
255 }
256
257 bool IsClass() const;
258 bool IsInterface() const;
259 bool IsComInterface() const;
260 bool IsEnum() const;
261 bool IsDelegate() const;
262 bool IsStructure() const;
263 void SetClassType( ClassType classType )
264 {
265 this->classType = classType;
266 }
267 ClassType GetClassType() const
268 {
269 return classType;
270 }
271
272
273 //コンストラクタをコンパイルしているかどうかのチェックフラグ
274private:
275 mutable bool isCompilingConstructor;
276public:
277 void NotifyStartConstructorCompile() const;
278 void NotifyFinishConstructorCompile() const;
279 bool IsCompilingConstructor() const;
280
281 //デストラクタをコンパイルしているかどうかのチェックフラグ
282private:
283 mutable bool isCompilingDestructor;
284public:
285 void NotifyStartDestructorCompile() const;
286 void NotifyFinishDestructorCompile() const;
287 bool IsCompilingDestructor() const;
288
289
290 //自身の派生クラスかどうかを確認
291 bool IsSubClass( const CClass *pClass ) const;
292
293 //自身と等しいまたは派生クラスかどうかを確認
294 bool IsEqualsOrSubClass( const CClass *pClass ) const;
295
296 // 自身と等しいまたは派生クラス、基底クラスかどうかを確認
297 bool IsEqualsOrSubClassOrSuperClass( const CClass &objClass ) const;
298
299 // インターフェイス
300 bool HasInterfaces() const
301 {
302 return ( interfaces.size() != 0 );
303 }
304 void AddInterface( ::Interface *pInterface )
305 {
306 interfaces.push_back( pInterface );
307 }
308 const Interfaces &GetInterfaces() const
309 {
310 return interfaces;
311 }
312 Interfaces &GetInterfaces()
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 int GetConstructorMemberSubIndex() const
375 {
376 return ConstructorMemberSubIndex;
377 }
378
379 //デストラクタ メソッドを取得
380 const CMethod *GetDestructorMethod() const
381 {
382 if( DestructorMemberSubIndex == -1 ) return NULL;
383 return GetDynamicMethods()[DestructorMemberSubIndex];
384 }
385 void SetDestructorMemberSubIndex( int destructorMemberSubIndex )
386 {
387 this->DestructorMemberSubIndex = destructorMemberSubIndex;
388 }
389 int GetDestructorMemberSubIndex() const
390 {
391 return DestructorMemberSubIndex;
392 }
393
394 // ユーザ指定のアラインメント固定値
395 int GetFixedAlignment() const
396 {
397 return fixedAlignment;
398 }
399 void SetFixedAlignment( int fixedAlignment )
400 {
401 this->fixedAlignment = fixedAlignment;
402 }
403
404 // 展開時の型パラメータ情報
405 bool IsExpanded() const
406 {
407 return !expandedClassActualTypeParameters.empty();
408 }
409 void ResolveExpandedClassActualTypeParameter( Type &type ) const;
410
411 // メンバの総合サイズを取得
412private:
413 int cacheSize;
414public:
415 int GetSize() const;
416
417 // メンバのオフセットを取得
418 int GetMemberOffset( const char *memberName ) const;
419private:
420 // アラインメント値を取得
421 int GetAlignment() const;
422
423
424 /////////////////////////////////////////////////////////////////
425 // vtbl
426 /////////////////////////////////////////////////////////////////
427public:
428 // vtblに存在する仮想関数の数
429 int GetVtblNum() const
430 {
431 return vtblNum;
432 }
433 void SetVtblNum( int vtblNum )
434 {
435 this->vtblNum = vtblNum;
436 }
437 void AddVtblNum( int vtblNum )
438 {
439 this->vtblNum += vtblNum;
440 }
441 bool IsExistVirtualFunctions() const
442 {
443 // 構造体以外は仮想関数を持つ
444 return !IsStructure();
445 }
446
447private:
448 int vtbl_offset;
449 int comVtblOffset;
450 int vtblMasterListOffset;
451public:
452 std::vector<long> vtblMasterList;
453 int GetVtblOffset() const
454 {
455 return vtbl_offset;
456 }
457 void SetVtblOffset( int vtblOffset )
458 {
459 this->vtbl_offset = vtblOffset;
460 }
461 int GetComVtblOffset() const
462 {
463 return comVtblOffset;
464 }
465 void SetComVtblOffset( int comVtblOffset )
466 {
467 this->comVtblOffset = comVtblOffset;
468 }
469 void GetVtblMasterListIndexAndVtblIndex( const UserProc *pUserProc, int &vtblMasterListIndex, int &vtblIndex ) const;
470 int GetVtblMasterListIndex( const CClass *pClass ) const;
471 long GetVtblMasterListOffset() const;
472 void SetVtblMasterListOffset( int vtblMasterListOffset )
473 {
474 this->vtblMasterListOffset = vtblMasterListOffset;
475 }
476 bool IsAbstract() const;
477
478
479 // TypeInfo用
480 mutable int typeInfoDataTableOffset;
481 void SetTypeInfoDataTableOffset( int typeInfoDataTableOffset ) const
482 {
483 this->typeInfoDataTableOffset = typeInfoDataTableOffset;
484 }
485 int GetTypeInfoDataTableOffset() const
486 {
487 return typeInfoDataTableOffset;
488 }
489
490 // 動的型データ用のメンバデータを取得
491 std::string GetStaticDefiningStringAsMemberNames() const;
492 std::string GetStaticDefiningStringAsMemberOffsets() const;
493 void GetReferenceOffsetsInitializeBuffer( std::string &referenceOffsetsBuffer, int &numOfReference, int baseOffset = 0 ) const;
494
495 virtual bool Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors );
496};
497
498class Classes : public Jenga::Common::Hashmap<CClass>
499{
500 // XMLシリアライズ用
501public:
502 Classes()
503 : pStringClass( NULL )
504 , pObjectClass( NULL )
505 , pInterfaceInfo( NULL )
506 {
507 }
508 ~Classes()
509 {
510 }
511
512 bool Insert( CClass *pClass, int nowLine );
513 CClass *Add( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const char *name,int nowLine);
514
515 const CClass *FindEx( const Symbol &symbol ) const;
516
517
518 /////////////////////////////
519 // 特殊クラス
520 /////////////////////////////
521 mutable const CClass *pStringClass;
522 mutable const CClass *pObjectClass;
523 mutable const CClass *pInterfaceInfo;
524 const CClass *GetStringClassPtr() const;
525 const CClass *GetObjectClassPtr() const;
526 const CClass *GetInterfaceInfoClassPtr() const;
527};
Note: See TracBrowser for help on using the repository browser.