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

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

svn:eol-styleとsvn:mime-type(文字コード指定含む)の設定

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