source: dev/branches/egtra/ab5.0/abdev/ab_common/include/Lexical/Class.h@ 816

Last change on this file since 816 was 816, checked in by イグトランス (egtra), 13 years ago

ab_commonにおいて、各クラスのコピー禁止を明確化、ならびにコピー可能なものにムーブコンストラクタ・ムーブ代入演算子を追加

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