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