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

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

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

File size: 11.9 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
86 // XMLシリアライズ用
87private:
88 friend class boost::serialization::access;
89 template<class Archive> void serialize(Archive& ar, const unsigned int version)
90 {
91 trace_for_serialize( "serializing - CClass" );
92
93 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( ClassPrototype );
94
95 if( ActiveBasic::Common::Environment::IsRemoveExternal() )
96 {
97 if( this->IsExternal() )
98 {
99 this->NeedResolve();
100 return;
101 }
102 }
103
104 ar & BOOST_SERIALIZATION_NVP( classType );
105 ar & BOOST_SERIALIZATION_NVP( importedNamespaces );
106 ar & BOOST_SERIALIZATION_NVP( formalGenericTypes );
107 ar & boost::serialization::make_nvp( "pSuperClass", const_cast<CClass *&>(pSuperClass) );
108 ar & BOOST_SERIALIZATION_NVP( superClassActualTypeParameters );
109 ar & BOOST_SERIALIZATION_NVP( blittableType );
110 ar & BOOST_SERIALIZATION_NVP( interfaces );
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 );
117 ar & BOOST_SERIALIZATION_NVP( fixedAlignment );
118 ar & BOOST_SERIALIZATION_NVP( expandedTemplateClasses );
119 }
120
121 bool isReady;
122public:
123
124 CClass( const Symbol &symbol, const NamespaceScopesCollection &importedNamespaces );
125 CClass( const Symbol &symbol,
126 const NamespaceScopesCollection &importedNamespaces,
127 ClassType classType,
128 const GenericTypes &formalGenericTypes,
129 const Types &superClassActualTypeParameters,
130 int ConstructorMemberSubIndex,
131 int DestructorMemberSubIndex,
132 int vtblNum,
133 int fixedAlignment );
134 CClass();
135 ~CClass();
136
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
150 virtual void Using() const;
151
152 void Readed(){
153 isReady = true;
154 }
155 bool IsReady() const{
156 return isReady;
157 }
158
159 const NamespaceScopesCollection &GetImportedNamespaces() const
160 {
161 return importedNamespaces;
162 }
163
164 // 型パラメータ
165 const GenericTypes &GetFormalGenericTypes() const
166 {
167 return formalGenericTypes;
168 }
169 void AddFormalGenericType( GenericType genericType )
170 {
171 this->formalGenericTypes.push_back( genericType );
172 }
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 }
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 }
197 bool IsGeneric() const
198 {
199 return ( this->formalGenericTypes.size() != 0 );
200 }
201
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 }
215 const Types &GetSuperClassActualTypeParameters() const
216 {
217 return superClassActualTypeParameters;
218 }
219 void SetSuperClassActualTypeParameters( const Types &actualTypeParameters )
220 {
221 this->superClassActualTypeParameters = actualTypeParameters;
222 }
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;
239 bool IsComInterface() const;
240 bool IsEnum() const;
241 bool IsDelegate() const;
242 bool IsStructure() const;
243 void SetClassType( ClassType classType )
244 {
245 this->classType = classType;
246 }
247 ClassType GetClassType() const
248 {
249 return classType;
250 }
251
252
253 //コンストラクタをコンパイルしているかどうかのチェックフラグ
254private:
255 mutable bool isCompilingConstructor;
256public:
257 void NotifyStartConstructorCompile() const;
258 void NotifyFinishConstructorCompile() const;
259 bool IsCompilingConstructor() const;
260
261 //デストラクタをコンパイルしているかどうかのチェックフラグ
262private:
263 mutable bool isCompilingDestructor;
264public:
265 void NotifyStartDestructorCompile() const;
266 void NotifyFinishDestructorCompile() const;
267 bool IsCompilingDestructor() const;
268
269
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 }
284 void AddInterface( ::Interface *pInterface )
285 {
286 interfaces.push_back( pInterface );
287 }
288 const Interfaces &GetInterfaces() const
289 {
290 return interfaces;
291 }
292 Interfaces &GetInterfaces()
293 {
294 return interfaces;
295 }
296 bool IsInheritsInterface( const CClass *pInterfaceClass ) const;
297
298 // クラス継承
299 bool InheritsClass( const CClass &inheritsClass, const Types &actualTypeParameters, int nowLine );
300
301 //メンバ、メソッドの追加
302 void AddDynamicMember( Member *pMember );
303 void AddStaticMember( Member *pMember );
304
305 //重複チェック
306 bool DupliCheckAll(const char *name) const;
307 bool DupliCheckMember(const char *name) const;
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 }
325
326 const Member *FindDynamicMember( const char *memberName ) const;
327 bool HasDynamicMember( const char *memberName ) const
328 {
329 return ( FindDynamicMember( memberName ) != NULL );
330 }
331
332 void EnumDynamicMethodsOrInterfaceMethods( const char *methodName, std::vector<const UserProc *> &subs ) const;
333 const CMethod *GetDynamicMethodOrInterfaceMethod( const UserProc *pUserProc ) const;
334
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;
348 return GetDynamicMethods()[ConstructorMemberSubIndex];
349 }
350 void SetConstructorMemberSubIndex( int constructorMemberSubIndex )
351 {
352 this->ConstructorMemberSubIndex = constructorMemberSubIndex;
353 }
354 int GetConstructorMemberSubIndex() const
355 {
356 return ConstructorMemberSubIndex;
357 }
358
359 //デストラクタ メソッドを取得
360 const CMethod *GetDestructorMethod() const
361 {
362 if( DestructorMemberSubIndex == -1 ) return NULL;
363 return GetDynamicMethods()[DestructorMemberSubIndex];
364 }
365 void SetDestructorMemberSubIndex( int destructorMemberSubIndex )
366 {
367 this->DestructorMemberSubIndex = destructorMemberSubIndex;
368 }
369 int GetDestructorMemberSubIndex() const
370 {
371 return DestructorMemberSubIndex;
372 }
373
374 // ユーザ指定のアラインメント固定値
375 int GetFixedAlignment() const
376 {
377 return fixedAlignment;
378 }
379 void SetFixedAlignment( int fixedAlignment )
380 {
381 this->fixedAlignment = fixedAlignment;
382 }
383
384 // メンバの総合サイズを取得
385private:
386 int cacheSize;
387public:
388 int GetSize() const;
389
390 // メンバのオフセットを取得
391 int GetMemberOffset( const char *memberName ) const;
392private:
393 // アラインメント値を取得
394 int GetAlignment() const;
395
396
397 /////////////////////////////////////////////////////////////////
398 // vtbl
399 /////////////////////////////////////////////////////////////////
400public:
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 {
416 // 構造体以外は仮想関数を持つ
417 return !IsStructure();
418 }
419
420private:
421 int vtbl_offset;
422 int comVtblOffset;
423 int vtblMasterListOffset;
424public:
425 std::vector<long> vtblMasterList;
426 int GetVtblOffset() const
427 {
428 return vtbl_offset;
429 }
430 void SetVtblOffset( int vtblOffset )
431 {
432 this->vtbl_offset = vtblOffset;
433 }
434 int GetComVtblOffset() const
435 {
436 return comVtblOffset;
437 }
438 void SetComVtblOffset( int comVtblOffset )
439 {
440 this->comVtblOffset = comVtblOffset;
441 }
442 void GetVtblMasterListIndexAndVtblIndex( const UserProc *pUserProc, int &vtblMasterListIndex, int &vtblIndex ) const;
443 int GetVtblMasterListIndex( const CClass *pClass ) const;
444 long GetVtblMasterListOffset() const;
445 void SetVtblMasterListOffset( int vtblMasterListOffset )
446 {
447 this->vtblMasterListOffset = vtblMasterListOffset;
448 }
449 bool IsAbstract() const;
450
451
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
463 // 動的型データ用のメンバデータを取得
464 std::string GetStaticDefiningStringAsMemberNames() const;
465 std::string GetStaticDefiningStringAsMemberOffsets() const;
466 void GetReferenceOffsetsInitializeBuffer( std::string &referenceOffsetsBuffer, int &numOfReference, int baseOffset = 0 ) const;
467
468 virtual bool Resolve( const ObjectModule &resolver );
469};
470
471class Classes : public Jenga::Common::Hashmap<CClass>
472{
473 // XMLシリアライズ用
474public:
475 Classes()
476 : pStringClass( NULL )
477 , pObjectClass( NULL )
478 , pInterfaceInfo( NULL )
479 {
480 }
481 ~Classes()
482 {
483 }
484
485 bool Insert( CClass *pClass, int nowLine );
486 CClass *Add( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const char *name,int nowLine);
487
488 const CClass *FindEx( const Symbol &symbol ) const;
489
490
491 /////////////////////////////
492 // 特殊クラス
493 /////////////////////////////
494 mutable const CClass *pStringClass;
495 mutable const CClass *pObjectClass;
496 mutable const CClass *pInterfaceInfo;
497 const CClass *GetStringClassPtr() const;
498 const CClass *GetObjectClassPtr() const;
499 const CClass *GetInterfaceInfoClassPtr() const;
500};
Note: See TracBrowser for help on using the repository browser.