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

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

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

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