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

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