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

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

静的リンクリンカの依存関係解決モジュールを製作中

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