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

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

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

File size: 12.2 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 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 }
166
167 virtual void Using() const;
168
169 void Readed(){
170 isReady = true;
171 }
172 bool IsReady() const{
173 return isReady;
174 }
175
176 const NamespaceScopesCollection &GetImportedNamespaces() const
177 {
178 return importedNamespaces;
179 }
180
181 // 型パラメータ
182 const GenericTypes &GetFormalGenericTypes() const
183 {
184 return formalGenericTypes;
185 }
186 void AddFormalGenericType( GenericType genericType )
187 {
188 this->formalGenericTypes.push_back( genericType );
189 }
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 }
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 }
214 bool IsGeneric() const
215 {
216 return ( this->formalGenericTypes.size() != 0 );
217 }
218
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 }
232 const Types &GetSuperClassActualTypeParameters() const
233 {
234 return superClassActualTypeParameters;
235 }
236 void SetSuperClassActualTypeParameters( const Types &actualTypeParameters )
237 {
238 this->superClassActualTypeParameters = actualTypeParameters;
239 }
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;
256 bool IsComInterface() const;
257 bool IsEnum() const;
258 bool IsDelegate() const;
259 bool IsStructure() const;
260 void SetClassType( ClassType classType )
261 {
262 this->classType = classType;
263 }
264 ClassType GetClassType() const
265 {
266 return classType;
267 }
268
269
270 //コンストラクタをコンパイルしているかどうかのチェックフラグ
271private:
272 mutable bool isCompilingConstructor;
273public:
274 void NotifyStartConstructorCompile() const;
275 void NotifyFinishConstructorCompile() const;
276 bool IsCompilingConstructor() const;
277
278 //デストラクタをコンパイルしているかどうかのチェックフラグ
279private:
280 mutable bool isCompilingDestructor;
281public:
282 void NotifyStartDestructorCompile() const;
283 void NotifyFinishDestructorCompile() const;
284 bool IsCompilingDestructor() const;
285
286
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 }
301 void AddInterface( ::Interface *pInterface )
302 {
303 interfaces.push_back( pInterface );
304 }
305 const Interfaces &GetInterfaces() const
306 {
307 return interfaces;
308 }
309 Interfaces &GetInterfaces()
310 {
311 return interfaces;
312 }
313 bool IsInheritsInterface( const CClass *pInterfaceClass ) const;
314
315 // クラス継承
316 bool InheritsClass( const CClass &inheritsClass, const Types &actualTypeParameters, int nowLine );
317
318 //メンバ、メソッドの追加
319 void AddDynamicMember( Member *pMember );
320 void AddStaticMember( Member *pMember );
321
322 //重複チェック
323 bool DupliCheckAll(const char *name) const;
324 bool DupliCheckMember(const char *name) const;
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 }
342
343 const Member *FindDynamicMember( const char *memberName ) const;
344 bool HasDynamicMember( const char *memberName ) const
345 {
346 return ( FindDynamicMember( memberName ) != NULL );
347 }
348
349 void EnumDynamicMethodsOrInterfaceMethods( const char *methodName, std::vector<const UserProc *> &subs ) const;
350 const CMethod *GetDynamicMethodOrInterfaceMethod( const UserProc *pUserProc ) const;
351
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;
365 return GetDynamicMethods()[ConstructorMemberSubIndex];
366 }
367 void SetConstructorMemberSubIndex( int constructorMemberSubIndex )
368 {
369 this->ConstructorMemberSubIndex = constructorMemberSubIndex;
370 }
371 int GetConstructorMemberSubIndex() const
372 {
373 return ConstructorMemberSubIndex;
374 }
375
376 //デストラクタ メソッドを取得
377 const CMethod *GetDestructorMethod() const
378 {
379 if( DestructorMemberSubIndex == -1 ) return NULL;
380 return GetDynamicMethods()[DestructorMemberSubIndex];
381 }
382 void SetDestructorMemberSubIndex( int destructorMemberSubIndex )
383 {
384 this->DestructorMemberSubIndex = destructorMemberSubIndex;
385 }
386 int GetDestructorMemberSubIndex() const
387 {
388 return DestructorMemberSubIndex;
389 }
390
391 // ユーザ指定のアラインメント固定値
392 int GetFixedAlignment() const
393 {
394 return fixedAlignment;
395 }
396 void SetFixedAlignment( int fixedAlignment )
397 {
398 this->fixedAlignment = fixedAlignment;
399 }
400
401 // メンバの総合サイズを取得
402private:
403 int cacheSize;
404public:
405 int GetSize() const;
406
407 // メンバのオフセットを取得
408 int GetMemberOffset( const char *memberName ) const;
409private:
410 // アラインメント値を取得
411 int GetAlignment() const;
412
413
414 /////////////////////////////////////////////////////////////////
415 // vtbl
416 /////////////////////////////////////////////////////////////////
417public:
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 {
433 // 構造体以外は仮想関数を持つ
434 return !IsStructure();
435 }
436
437private:
438 int vtbl_offset;
439 int comVtblOffset;
440 int vtblMasterListOffset;
441public:
442 std::vector<long> vtblMasterList;
443 int GetVtblOffset() const
444 {
445 return vtbl_offset;
446 }
447 void SetVtblOffset( int vtblOffset )
448 {
449 this->vtbl_offset = vtblOffset;
450 }
451 int GetComVtblOffset() const
452 {
453 return comVtblOffset;
454 }
455 void SetComVtblOffset( int comVtblOffset )
456 {
457 this->comVtblOffset = comVtblOffset;
458 }
459 void GetVtblMasterListIndexAndVtblIndex( const UserProc *pUserProc, int &vtblMasterListIndex, int &vtblIndex ) const;
460 int GetVtblMasterListIndex( const CClass *pClass ) const;
461 long GetVtblMasterListOffset() const;
462 void SetVtblMasterListOffset( int vtblMasterListOffset )
463 {
464 this->vtblMasterListOffset = vtblMasterListOffset;
465 }
466 bool IsAbstract() const;
467
468
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
480 // 動的型データ用のメンバデータを取得
481 std::string GetStaticDefiningStringAsMemberNames() const;
482 std::string GetStaticDefiningStringAsMemberOffsets() const;
483 void GetReferenceOffsetsInitializeBuffer( std::string &referenceOffsetsBuffer, int &numOfReference, int baseOffset = 0 ) const;
484
485 virtual bool Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors );
486};
487
488class Classes : public Jenga::Common::Hashmap<CClass>
489{
490 // XMLシリアライズ用
491public:
492 Classes()
493 : pStringClass( NULL )
494 , pObjectClass( NULL )
495 , pInterfaceInfo( NULL )
496 {
497 }
498 ~Classes()
499 {
500 }
501
502 bool Insert( CClass *pClass, int nowLine );
503 CClass *Add( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const char *name,int nowLine);
504
505 const CClass *FindEx( const Symbol &symbol ) const;
506
507
508 /////////////////////////////
509 // 特殊クラス
510 /////////////////////////////
511 mutable const CClass *pStringClass;
512 mutable const CClass *pObjectClass;
513 mutable const CClass *pInterfaceInfo;
514 const CClass *GetStringClassPtr() const;
515 const CClass *GetObjectClassPtr() const;
516 const CClass *GetInterfaceInfoClassPtr() const;
517};
Note: See TracBrowser for help on using the repository browser.