source: dev/trunk/abdev/BasicCompiler_Common/include/Class.h@ 290

Last change on this file since 290 was 290, checked in by dai_9181, 17 years ago

ジェネリクスのベースを実装

File size: 10.7 KB
Line 
1#pragma once
2
3#include <option.h>
4#include <Program.h>
5#include <Prototype.h>
6#include <Method.h>
7#include <Member.h>
8#include <Source.h>
9
10class UserProc;
11class CClass;
12
13class InheritedInterface
14{
15 CClass *pInterfaceClass;
16 int vtblOffset;
17public:
18 InheritedInterface( CClass *pInterfaceClass, int vtblOffset )
19 : pInterfaceClass( pInterfaceClass )
20 , vtblOffset( vtblOffset )
21 {
22 }
23
24 CClass &GetInterfaceClass() const{
25 return *pInterfaceClass;
26 }
27 int GetVtblOffset() const
28 {
29 return vtblOffset;
30 }
31};
32typedef vector<InheritedInterface> Interfaces;
33
34class CClass: public Prototype, public Jenga::Common::ObjectInHashmap<CClass>
35{
36public:
37 // 型の種類
38 enum ClassType{
39 Class,
40 Interface,
41 Enum,
42 Delegate,
43 Structure,
44 };
45
46private:
47 ClassType classType;
48
49 // importされている名前空間
50 NamespaceScopesCollection importedNamespaces;
51
52 // 型パラメータ
53 GenericTypes formalGenericTypes;
54
55 // 継承クラス
56 const CClass *pSuperClass;
57
58 // Blittable型情報
59 Type blittableType;
60
61 // 実装するインターフェイス
62 Interfaces interfaces;
63
64 // 動的メンバ
65 Members dynamicMembers;
66
67 // 静的メンバ
68 Members staticMembers;
69
70 // 動的メソッド
71 Methods methods;
72 int ConstructorMemberSubIndex;
73 int DestructorMemberSubIndex;
74 int vtblNum; // 仮想関数の数
75
76 // 静的メソッド
77 Methods staticMethods;
78
79 //アラインメント値
80 int fixedAlignment;
81
82 // XMLシリアライズ用
83 // TODO: xml未完成
84private:
85 friend class boost::serialization::access;
86 template<class Archive> void serialize(Archive& ar, const unsigned int version)
87 {
88 trace_for_serialize( "serializing - CClass" );
89
90 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Prototype );
91 ar & BOOST_SERIALIZATION_NVP( classType );
92 ar & BOOST_SERIALIZATION_NVP( importedNamespaces );
93 ar & boost::serialization::make_nvp( "pSuperClass", const_cast<CClass *&>(pSuperClass) );
94 ar & BOOST_SERIALIZATION_NVP( blittableType );
95 //ar & BOOST_SERIALIZATION_NVP( interfaces );
96 ar & BOOST_SERIALIZATION_NVP( dynamicMembers );
97 ar & BOOST_SERIALIZATION_NVP( staticMembers );
98 ar & BOOST_SERIALIZATION_NVP( methods );
99 ar & BOOST_SERIALIZATION_NVP( ConstructorMemberSubIndex );
100 ar & BOOST_SERIALIZATION_NVP( DestructorMemberSubIndex );
101 ar & BOOST_SERIALIZATION_NVP( vtblNum );
102 ar & BOOST_SERIALIZATION_NVP( staticMethods );
103 ar & BOOST_SERIALIZATION_NVP( fixedAlignment );
104 }
105
106 bool isReady;
107public:
108
109 CClass( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const string &name )
110 : Prototype( namespaceScopes, name )
111 , importedNamespaces( importedNamespaces )
112 , classType( Class )
113 , pSuperClass( NULL )
114 , blittableType( Type() )
115 , isReady( false )
116 , fixedAlignment( 0 )
117 , ConstructorMemberSubIndex( -1 )
118 , DestructorMemberSubIndex( -1 )
119 , vtblNum( 0 )
120 , vtbl_offset( -1 )
121 , isCompilingConstructor( false )
122 , isCompilingDestructor( false )
123 , pobj_NextClass( NULL )
124 {
125 }
126 CClass()
127 : Prototype()
128 , importedNamespaces()
129 , classType()
130 , pSuperClass( NULL )
131 , blittableType( Type() )
132 , isReady( false )
133 , fixedAlignment( 0 )
134 , ConstructorMemberSubIndex( -1 )
135 , DestructorMemberSubIndex( -1 )
136 , vtblNum( 0 )
137 , vtbl_offset( -1 )
138 , isCompilingConstructor( false )
139 , isCompilingDestructor( false )
140 , pobj_NextClass( NULL )
141 {
142 }
143 ~CClass()
144 {
145 // 動的メンバ
146 BOOST_FOREACH( CMember *member, dynamicMembers ){
147 delete member;
148 }
149
150 // 静的メンバ
151 BOOST_FOREACH( CMember *member, staticMembers ){
152 delete member;
153 }
154 }
155
156 virtual const std::string &GetKeyName() const
157 {
158 return GetName();
159 }
160 virtual bool IsDuplication( const CClass *pClass ) const
161 {
162 if( pClass->IsEqualSymbol( *this ) )
163 {
164 return true;
165 }
166 return false;
167 }
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 void AddFormalGenericType( GenericType genericType )
183 {
184 this->formalGenericTypes.push_back( genericType );
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
198 // 継承元クラス
199 bool HasSuperClass() const
200 {
201 return ( pSuperClass != NULL );
202 }
203 const CClass &GetSuperClass() const
204 {
205 return *pSuperClass;
206 }
207 void SetSuperClass( const CClass *pSuperClass )
208 {
209 this->pSuperClass = pSuperClass;
210 }
211
212 // Blittable型
213 bool IsBlittableType() const
214 {
215 return !blittableType.IsNull();
216 }
217 const Type &GetBlittableType() const
218 {
219 return blittableType;
220 }
221 void SetBlittableType( const Type &type ){
222 blittableType = type;
223 }
224
225 bool IsClass() const;
226 bool IsInterface() const;
227 bool IsEnum() const;
228 bool IsDelegate() const;
229 bool IsStructure() const;
230 void SetClassType( ClassType classType )
231 {
232 this->classType = classType;
233 }
234
235
236 //コンストラクタをコンパイルしているかどうかのチェックフラグ
237private:
238 mutable bool isCompilingConstructor;
239public:
240 void NotifyStartConstructorCompile() const;
241 void NotifyFinishConstructorCompile() const;
242 bool IsCompilingConstructor() const;
243
244 //デストラクタをコンパイルしているかどうかのチェックフラグ
245private:
246 mutable bool isCompilingDestructor;
247public:
248 void NotifyStartDestructorCompile() const;
249 void NotifyFinishDestructorCompile() const;
250 bool IsCompilingDestructor() const;
251
252
253 //自身の派生クラスかどうかを確認
254 bool IsSubClass( const CClass *pClass ) const;
255
256 //自身と等しいまたは派生クラスかどうかを確認
257 bool IsEqualsOrSubClass( const CClass *pClass ) const;
258
259 // 自身と等しいまたは派生クラス、基底クラスかどうかを確認
260 bool IsEqualsOrSubClassOrSuperClass( const CClass &objClass ) const;
261
262 // インターフェイス
263 bool HasInterfaces() const
264 {
265 return ( interfaces.size() != 0 );
266 }
267 bool IsInheritsInterface( const CClass *pInterfaceClass ) const;
268
269 //継承させる
270 bool Inherits( const char *inheritNames, int nowLine );
271 bool InheritsClass( const CClass &inheritsClass, int nowLine );
272 bool InheritsInterface( const CClass &inheritsClass, int nowLine );
273
274 //メンバ、メソッドの追加
275 CMember *CreateMember( Prototype::Accessibility accessibility, bool isConst, bool isRef, char *buffer, int nowLine );
276 void AddMember( Prototype::Accessibility accessibility, bool idConst, bool isRef, char *buffer, int nowLine );
277 void AddStaticMember( Prototype::Accessibility accessibility, bool isConst, bool isRef, char *buffer, int nowLine );
278
279 void AddMethod(CClass *pobj_c, Prototype::Accessibility accessibility, BOOL bStatic, bool isConst, bool isAbstract,
280 bool isVirtual, bool isOverride, char *buffer, int nowLine);
281
282 //重複チェック
283 bool DupliCheckAll(const char *name);
284 bool DupliCheckMember(const char *name);
285
286 const Members &GetDynamicMembers() const
287 {
288 return dynamicMembers;
289 }
290 const Members &GetStaticMembers() const
291 {
292 return staticMembers;
293 }
294 Members &GetDynamicMembers()
295 {
296 return dynamicMembers;
297 }
298 Members &GetStaticMembers()
299 {
300 return staticMembers;
301 }
302
303 const Methods &GetMethods() const
304 {
305 return methods;
306 }
307 const Methods &GetStaticMethods() const
308 {
309 return staticMethods;
310 }
311 Methods &GetMethods()
312 {
313 return methods;
314 }
315 Methods &GetStaticMethods()
316 {
317 return staticMethods;
318 }
319
320 //デフォルト コンストラクタ
321 const CMethod *GetConstructorMethod() const
322 {
323 if( ConstructorMemberSubIndex == -1 ) return NULL;
324 return methods[ConstructorMemberSubIndex];
325 }
326 void SetConstructorMemberSubIndex( int constructorMemberSubIndex )
327 {
328 this->ConstructorMemberSubIndex = constructorMemberSubIndex;
329 }
330
331 //デストラクタ メソッドを取得
332 const CMethod *GetDestructorMethod() const
333 {
334 if( DestructorMemberSubIndex == -1 ) return NULL;
335 return methods[DestructorMemberSubIndex];
336 }
337 void SetDestructorMemberSubIndex( int destructorMemberSubIndex )
338 {
339 this->DestructorMemberSubIndex = destructorMemberSubIndex;
340 }
341
342 // vtblに存在する仮想関数の数
343 int GetVtblNum() const
344 {
345 return vtblNum;
346 }
347 void SetVtblNum( int vtblNum )
348 {
349 this->vtblNum = vtblNum;
350 }
351 void AddVtblNum( int vtblNum )
352 {
353 this->vtblNum += vtblNum;
354 }
355 bool IsExistVirtualFunctions() const
356 {
357 return ( vtblNum > 0 );
358 }
359
360 // ユーザ指定のアラインメント固定値
361 int GetFixedAlignment() const
362 {
363 return fixedAlignment;
364 }
365 void SetFixedAlignment( int fixedAlignment )
366 {
367 this->fixedAlignment = fixedAlignment;
368 }
369
370 // メンバの総合サイズを取得
371 int GetSize() const;
372
373 // メンバのオフセットを取得
374 int GetMemberOffset( const char *memberName, int *pMemberNum = NULL ) const;
375private:
376 // アラインメント値を取得
377 int GetAlignment() const;
378
379 //vtbl
380protected:
381 mutable long vtbl_offset;
382public:
383 int GetFuncNumInVtbl( const UserProc *pUserProc ) const;
384 LONG_PTR GetVtblGlobalOffset(void) const;
385 void GenerateVTables();
386 void ActionVtblSchedule(LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection);
387 bool IsAbstract() const;
388
389
390 //線形リスト用
391 CClass *pobj_NextClass;
392};
393
394class Classes : public Jenga::Common::Hashmap<CClass>
395{
396 // XMLシリアライズ用
397public:
398 Classes()
399 : pCompilingMethod( NULL )
400 , pStringClass( NULL )
401 , pObjectClass( NULL )
402 {
403 }
404 ~Classes()
405 {
406 }
407
408 virtual CClass *Create( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const char *name);
409 bool Insert( CClass *pClass );
410 CClass *Add( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const char *name,int nowLine);
411 virtual void CollectClassesForNameOnly( const BasicSource &source );
412
413 void GenerateVTables();
414 void ActionVtblSchedule(LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection);
415
416 virtual void InitStaticMember();
417
418private:
419 bool MemberVar_LoopRefCheck(const CClass &objClass);
420public:
421 virtual void GetClass_recur(const char *lpszInheritsClass);
422 virtual void GetAllClassInfo();
423 virtual void Compile_System_InitializeUserTypes();
424
425 const CClass *Find( const NamespaceScopes &namespaceScopes, const string &name ) const;
426 const CClass *Find( const string &fullName ) const;
427
428
429 /////////////////////////////
430 // 現在コンパイル中の情報
431 /////////////////////////////
432private:
433 const CMethod *pCompilingMethod;
434public:
435 void StartCompile( const UserProc *pUserProc );
436
437 //現在コンパイル中のメソッド情報を取得
438 const CMethod *GetNowCompilingMethodInfo(){
439 return pCompilingMethod;
440 }
441
442
443 /////////////////////////////
444 // 特殊クラス
445 /////////////////////////////
446 mutable const CClass *pStringClass;
447 mutable const CClass *pObjectClass;
448 const CClass *GetStringClassPtr() const;
449 const CClass *GetObjectClassPtr() const;
450};
Note: See TracBrowser for help on using the repository browser.