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

Last change on this file since 728 was 728, checked in by dai, 16 years ago

#200への対応。ジェネリックインターフェイスを実装したジェネリッククラスのテンプレート展開に対応。

File size: 12.7 KB
RevLine 
[184]1#pragma once
2
[206]3class UserProc;
[632]4class UserProcs;
[325]5class Delegate;
[632]6class Classes;
[206]7
[344]8class ClassPrototype : public Prototype, public DynamicMethodsPrototype
[342]9{
[344]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:
[637]20 ClassPrototype( const Symbol &symbol )
21 : Prototype( symbol )
[344]22 , DynamicMethodsPrototype()
23 {
24 }
25 ClassPrototype()
26 : Prototype()
27 , DynamicMethodsPrototype()
28 {
29 }
30};
31
[342]32class CClass: public ClassPrototype, public Jenga::Common::ObjectInHashmap<CClass>
[206]33{
34public:
35 // 型の種類
36 enum ClassType{
37 Class,
38 Interface,
[370]39 ComInterface,
[206]40 Enum,
41 Delegate,
42 Structure,
43 };
[193]44
[206]45private:
46 ClassType classType;
[184]47
[206]48 // importされている名前空間
49 NamespaceScopesCollection importedNamespaces;
[290]50
51 // 型パラメータ
52 GenericTypes formalGenericTypes;
53
[382]54 // 基底クラス
[206]55 const CClass *pSuperClass;
[184]56
[382]57 // 基底クラスの型パラメータ(実パラメータ)
[299]58 Types superClassActualTypeParameters;
59
[206]60 // Blittable型情報
61 Type blittableType;
[184]62
[206]63 // 実装するインターフェイス
64 Interfaces interfaces;
[191]65
[206]66 // 動的メンバ
67 Members dynamicMembers;
[191]68
[206]69 // 静的メンバ
70 Members staticMembers;
71
72 // 動的メソッド
73 int ConstructorMemberSubIndex;
74 int DestructorMemberSubIndex;
75 int vtblNum; // 仮想関数の数
76
77 // 静的メソッド
78 Methods staticMethods;
79
[232]80 //アラインメント値
81 int fixedAlignment;
82
[632]83public:
84 ActiveBasic::Common::Lexical::ExpandedTemplateClasses expandedTemplateClasses;
[672]85 Types expandedClassActualTypeParameters;
[632]86
[191]87 // XMLシリアライズ用
88private:
89 friend class boost::serialization::access;
90 template<class Archive> void serialize(Archive& ar, const unsigned int version)
91 {
[206]92 trace_for_serialize( "serializing - CClass" );
93
[342]94 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( ClassPrototype );
[637]95
96 if( ActiveBasic::Common::Environment::IsRemoveExternal() )
97 {
98 if( this->IsExternal() )
99 {
100 this->NeedResolve();
101 return;
102 }
103 }
104
[206]105 ar & BOOST_SERIALIZATION_NVP( classType );
106 ar & BOOST_SERIALIZATION_NVP( importedNamespaces );
[293]107 ar & BOOST_SERIALIZATION_NVP( formalGenericTypes );
[206]108 ar & boost::serialization::make_nvp( "pSuperClass", const_cast<CClass *&>(pSuperClass) );
[299]109 ar & BOOST_SERIALIZATION_NVP( superClassActualTypeParameters );
[206]110 ar & BOOST_SERIALIZATION_NVP( blittableType );
[353]111 ar & BOOST_SERIALIZATION_NVP( interfaces );
[206]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 );
[232]118 ar & BOOST_SERIALIZATION_NVP( fixedAlignment );
[632]119 ar & BOOST_SERIALIZATION_NVP( expandedTemplateClasses );
[672]120 ar & BOOST_SERIALIZATION_NVP( expandedClassActualTypeParameters );
[191]121 }
[184]122
[206]123 bool isReady;
[184]124public:
[206]125
[637]126 CClass( const Symbol &symbol, const NamespaceScopesCollection &importedNamespaces );
127 CClass( const Symbol &symbol,
[632]128 const NamespaceScopesCollection &importedNamespaces,
[637]129 ClassType classType,
[632]130 const GenericTypes &formalGenericTypes,
131 const Types &superClassActualTypeParameters,
132 int ConstructorMemberSubIndex,
133 int DestructorMemberSubIndex,
134 int vtblNum,
[672]135 int fixedAlignment,
136 const Types &expandedClassActualTypeParameters );
[632]137 CClass();
138 ~CClass();
[191]139
[270]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 }
[640]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 }
[270]169
[540]170 virtual void Using() const;
171
[206]172 void Readed(){
173 isReady = true;
174 }
175 bool IsReady() const{
176 return isReady;
177 }
[184]178
[206]179 const NamespaceScopesCollection &GetImportedNamespaces() const
180 {
181 return importedNamespaces;
182 }
183
[290]184 // 型パラメータ
[424]185 const GenericTypes &GetFormalGenericTypes() const
186 {
187 return formalGenericTypes;
188 }
[290]189 void AddFormalGenericType( GenericType genericType )
190 {
191 this->formalGenericTypes.push_back( genericType );
192 }
[299]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 }
[290]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 }
[379]217 bool IsGeneric() const
218 {
219 return ( this->formalGenericTypes.size() != 0 );
220 }
[290]221
[206]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 }
[299]235 const Types &GetSuperClassActualTypeParameters() const
236 {
237 return superClassActualTypeParameters;
238 }
239 void SetSuperClassActualTypeParameters( const Types &actualTypeParameters )
240 {
241 this->superClassActualTypeParameters = actualTypeParameters;
242 }
[206]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;
[370]259 bool IsComInterface() const;
[206]260 bool IsEnum() const;
261 bool IsDelegate() const;
262 bool IsStructure() const;
263 void SetClassType( ClassType classType )
264 {
265 this->classType = classType;
266 }
[632]267 ClassType GetClassType() const
268 {
269 return classType;
270 }
[206]271
272
273 //コンストラクタをコンパイルしているかどうかのチェックフラグ
[184]274private:
[206]275 mutable bool isCompilingConstructor;
[184]276public:
[206]277 void NotifyStartConstructorCompile() const;
278 void NotifyFinishConstructorCompile() const;
279 bool IsCompilingConstructor() const;
[184]280
[206]281 //デストラクタをコンパイルしているかどうかのチェックフラグ
282private:
283 mutable bool isCompilingDestructor;
284public:
285 void NotifyStartDestructorCompile() const;
286 void NotifyFinishDestructorCompile() const;
287 bool IsCompilingDestructor() const;
[191]288
[193]289
[206]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 }
[560]304 void AddInterface( ::Interface *pInterface )
305 {
306 interfaces.push_back( pInterface );
307 }
[342]308 const Interfaces &GetInterfaces() const
309 {
310 return interfaces;
311 }
[632]312 Interfaces &GetInterfaces()
313 {
314 return interfaces;
315 }
[206]316 bool IsInheritsInterface( const CClass *pInterfaceClass ) const;
317
[340]318 // クラス継承
[299]319 bool InheritsClass( const CClass &inheritsClass, const Types &actualTypeParameters, int nowLine );
[206]320
[728]321 // インターフェイス継承
322 bool InheritsInterface( const CClass &inheritsInterfaceClass, const Types &actualTypeParameters, int nowLine );
323
[206]324 //メンバ、メソッドの追加
[561]325 void AddDynamicMember( Member *pMember );
326 void AddStaticMember( Member *pMember );
[206]327
328 //重複チェック
[409]329 bool DupliCheckAll(const char *name) const;
330 bool DupliCheckMember(const char *name) const;
[206]331
332 const Members &GetDynamicMembers() const
333 {
334 return dynamicMembers;
335 }
336 const Members &GetStaticMembers() const
337 {
338 return staticMembers;
339 }
340 Members &GetDynamicMembers()
341 {
342 return dynamicMembers;
343 }
344 Members &GetStaticMembers()
345 {
346 return staticMembers;
347 }
[355]348
[561]349 const Member *FindDynamicMember( const char *memberName ) const;
[409]350 bool HasDynamicMember( const char *memberName ) const
[355]351 {
[409]352 return ( FindDynamicMember( memberName ) != NULL );
[355]353 }
[206]354
[350]355 void EnumDynamicMethodsOrInterfaceMethods( const char *methodName, std::vector<const UserProc *> &subs ) const;
356 const CMethod *GetDynamicMethodOrInterfaceMethod( const UserProc *pUserProc ) const;
[347]357
[206]358 const Methods &GetStaticMethods() const
359 {
360 return staticMethods;
361 }
362 Methods &GetStaticMethods()
363 {
364 return staticMethods;
365 }
366
367 //デフォルト コンストラクタ
368 const CMethod *GetConstructorMethod() const
369 {
370 if( ConstructorMemberSubIndex == -1 ) return NULL;
[342]371 return GetDynamicMethods()[ConstructorMemberSubIndex];
[206]372 }
373 void SetConstructorMemberSubIndex( int constructorMemberSubIndex )
374 {
375 this->ConstructorMemberSubIndex = constructorMemberSubIndex;
376 }
[632]377 int GetConstructorMemberSubIndex() const
378 {
379 return ConstructorMemberSubIndex;
380 }
[206]381
382 //デストラクタ メソッドを取得
383 const CMethod *GetDestructorMethod() const
384 {
385 if( DestructorMemberSubIndex == -1 ) return NULL;
[342]386 return GetDynamicMethods()[DestructorMemberSubIndex];
[206]387 }
388 void SetDestructorMemberSubIndex( int destructorMemberSubIndex )
389 {
390 this->DestructorMemberSubIndex = destructorMemberSubIndex;
391 }
[632]392 int GetDestructorMemberSubIndex() const
393 {
394 return DestructorMemberSubIndex;
395 }
[206]396
[232]397 // ユーザ指定のアラインメント固定値
398 int GetFixedAlignment() const
399 {
400 return fixedAlignment;
401 }
402 void SetFixedAlignment( int fixedAlignment )
403 {
404 this->fixedAlignment = fixedAlignment;
405 }
406
[672]407 // 展開時の型パラメータ情報
408 bool IsExpanded() const
409 {
410 return !expandedClassActualTypeParameters.empty();
411 }
412 void ResolveExpandedClassActualTypeParameter( Type &type ) const;
413
[206]414 // メンバの総合サイズを取得
[409]415private:
416 int cacheSize;
417public:
[206]418 int GetSize() const;
419
420 // メンバのオフセットを取得
[409]421 int GetMemberOffset( const char *memberName ) const;
[206]422private:
423 // アラインメント値を取得
424 int GetAlignment() const;
425
[342]426
427 /////////////////////////////////////////////////////////////////
428 // vtbl
429 /////////////////////////////////////////////////////////////////
[206]430public:
[342]431 // vtblに存在する仮想関数の数
432 int GetVtblNum() const
433 {
434 return vtblNum;
435 }
436 void SetVtblNum( int vtblNum )
437 {
438 this->vtblNum = vtblNum;
439 }
440 void AddVtblNum( int vtblNum )
441 {
442 this->vtblNum += vtblNum;
443 }
444 bool IsExistVirtualFunctions() const
445 {
[409]446 // 構造体以外は仮想関数を持つ
447 return !IsStructure();
[342]448 }
449
450private:
[593]451 int vtbl_offset;
452 int comVtblOffset;
453 int vtblMasterListOffset;
[559]454public:
[345]455 std::vector<long> vtblMasterList;
[593]456 int GetVtblOffset() const
[559]457 {
458 return vtbl_offset;
459 }
460 void SetVtblOffset( int vtblOffset )
461 {
462 this->vtbl_offset = vtblOffset;
463 }
[593]464 int GetComVtblOffset() const
[559]465 {
466 return comVtblOffset;
467 }
468 void SetComVtblOffset( int comVtblOffset )
469 {
470 this->comVtblOffset = comVtblOffset;
471 }
[348]472 void GetVtblMasterListIndexAndVtblIndex( const UserProc *pUserProc, int &vtblMasterListIndex, int &vtblIndex ) const;
[350]473 int GetVtblMasterListIndex( const CClass *pClass ) const;
[345]474 long GetVtblMasterListOffset() const;
[559]475 void SetVtblMasterListOffset( int vtblMasterListOffset )
476 {
477 this->vtblMasterListOffset = vtblMasterListOffset;
478 }
[206]479 bool IsAbstract() const;
480
481
[355]482 // TypeInfo用
483 mutable int typeInfoDataTableOffset;
484 void SetTypeInfoDataTableOffset( int typeInfoDataTableOffset ) const
485 {
486 this->typeInfoDataTableOffset = typeInfoDataTableOffset;
487 }
488 int GetTypeInfoDataTableOffset() const
489 {
490 return typeInfoDataTableOffset;
491 }
492
[387]493 // 動的型データ用のメンバデータを取得
494 std::string GetStaticDefiningStringAsMemberNames() const;
[412]495 std::string GetStaticDefiningStringAsMemberOffsets() const;
[417]496 void GetReferenceOffsetsInitializeBuffer( std::string &referenceOffsetsBuffer, int &numOfReference, int baseOffset = 0 ) const;
[637]497
[640]498 virtual bool Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors );
[206]499};
500
[270]501class Classes : public Jenga::Common::Hashmap<CClass>
[206]502{
[191]503 // XMLシリアライズ用
[206]504public:
505 Classes()
[538]506 : pStringClass( NULL )
[206]507 , pObjectClass( NULL )
[350]508 , pInterfaceInfo( NULL )
[206]509 {
510 }
511 ~Classes()
512 {
513 }
514
[369]515 bool Insert( CClass *pClass, int nowLine );
[206]516 CClass *Add( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const char *name,int nowLine);
517
[598]518 const CClass *FindEx( const Symbol &symbol ) const;
[206]519
520
521 /////////////////////////////
522 // 特殊クラス
523 /////////////////////////////
[272]524 mutable const CClass *pStringClass;
525 mutable const CClass *pObjectClass;
[349]526 mutable const CClass *pInterfaceInfo;
[272]527 const CClass *GetStringClassPtr() const;
528 const CClass *GetObjectClassPtr() const;
[349]529 const CClass *GetInterfaceInfoClassPtr() const;
[184]530};
Note: See TracBrowser for help on using the repository browser.