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

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

BOOST_FOREACHを可能なものはVC++ 2005 for eachへ置換(やや速くなる)。

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