source: dev/BasicCompiler_Common/Class.h@ 134

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

Prototype::IsEqualSymbolメソッドを実装。

File size: 7.9 KB
RevLine 
[78]1#pragma once
2
[50]3#include <vector>
[131]4#include <string>
5
6#include <Prototype.h>
[75]7#include "Type.h"
[100]8#include "Procedure.h"
[4]9
10class CClass;
11
12#define ACCESS_NON 0
13#define ACCESS_PRIVATE 1
14#define ACCESS_PUBLIC 2
15#define ACCESS_PROTECTED 3
16
[75]17class CMember : public Type
18{
[17]19 bool isConst;
[4]20public:
21 char *name;
22 int SubScripts[MAX_ARRAYDIM];
23
24 DWORD dwAccess;
25
26 char *InitBuf;
27 char *ConstractParameter;
28
29 int source_code_address;
30
31
[75]32 CMember( CClass *pobj_c, DWORD access, bool idConst, bool isRef, char *buffer, int nowLine=-1 );
33 CMember( CMember &member );
[4]34 CMember();
35 ~CMember();
36
[17]37 bool IsConst();
[4]38
[17]39
[4]40 static void InitStaticMember(void);
41};
[100]42class CMethod
43{
[4]44public:
[75]45 UserProc *pUserProc;
[100]46
[4]47 DWORD dwAccess;
48 BOOL bAbstract;
49 BOOL bVirtual;
[18]50 bool isConst;
[100]51 bool isStatic;
[4]52
[114]53 const CClass *pobj_InheritsClass;
[4]54
55 CMethod(CMethod *pobj);
[100]56 CMethod( UserProc *pUserProc, DWORD dwAccess, BOOL bAbstract, BOOL bVirtual, bool isConst, bool isStatic );
[4]57 ~CMethod();
58};
[100]59
[51]60class CDBClass;
61class CDebugSection;
[131]62class CClass;
63class InheritedInterface
64{
65 CClass *pInterfaceClass;
66 int vtblOffset;
67public:
68 InheritedInterface( CClass *pInterfaceClass, int vtblOffset )
69 : pInterfaceClass( pInterfaceClass )
70 , vtblOffset( vtblOffset )
71 {
72 }
73
74 CClass &GetInterfaceClass() const{
75 return *pInterfaceClass;
76 }
77 int GetVtblOffset() const
78 {
79 return vtblOffset;
80 }
81};
82typedef vector<InheritedInterface> Interfaces;
83class CClass : public Prototype
84{
[53]85 friend CMember;
[51]86 friend CDBClass;
87 friend CDebugSection;
88
[131]89 // importされている名前空間
[108]90 NamespaceScopesCollection importedNamespaces;
[101]91
[131]92 // 継承するインターフェイス
93 Interfaces interfaces;
94
[127]95 // Blittable型情報
96 Type blittableType;
97
[53]98 //静的メンバ情報
[91]99 std::vector<CMember *> staticMembers;
[53]100
[51]101 //メソッド情報
102 std::vector<CMethod *> methods;
103 int ConstructorMemberSubIndex;
104 int DestructorMemberSubIndex;
105
[50]106 //静的メソッド情報
[51]107 std::vector<CMethod *> staticMethods;
[50]108
[64]109 enum ClassType{
110 Class,
[90]111 Interface,
112 Enum,
113 Delegate,
[64]114 Structure,
115 };
116
117 ClassType classType;
118
[4]119public:
120
121 //継承クラスへのポインタ
[114]122 const CClass *pobj_InheritsClass;
[4]123
124 //メンバ情報
125 CMember **ppobj_Member;
126 int iMemberNum;
127
128 //仮想関数の数
129 int vtbl_num;
130
131 //アラインメント値
132 int iAlign;
133
134
135public:
[131]136 CClass( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const string &name );
[4]137 ~CClass();
138
[108]139 const NamespaceScopesCollection &GetImportedNamespaces() const
140 {
141 return importedNamespaces;
142 }
[101]143
[131]144 // インターフェイス
145 bool HasInterfaces() const
[102]146 {
[131]147 return ( interfaces.size() != 0 );
[102]148 }
[131]149 bool IsInheritsInterface( const CClass *pInterfaceClass ) const;
[101]150
[131]151 // Blittable型
[127]152 bool IsBlittableType() const
153 {
[128]154 return !blittableType.IsNull();
[127]155 }
156 const Type &GetBlittableType() const
157 {
158 return blittableType;
159 }
160 void SetBlittableType( const Type &type ){
161 blittableType = type;
162 }
163
[90]164 bool IsClass() const;
165 bool IsInterface() const;
166 bool IsEnum() const;
167 bool IsDelegate() const;
[64]168 bool IsStructure() const;
169
[29]170 //継承させる
[131]171 bool Inherits( const char *inheritNames, int nowLine );
172 bool InheritsClass( const CClass &inheritsClass, int nowLine );
[114]173 bool InheritsInterface( const CClass &inheritsClass, int nowLine );
[29]174
[53]175 //メンバ、メソッドの追加
[40]176 void AddMember( DWORD dwAccess, bool idConst, bool isRef, char *buffer );
[75]177 void AddStaticMember( DWORD dwAccess, bool isConst, bool isRef, char *buffer, int nowLine );
178 void AddMethod( UserProc *pUserProc,DWORD dwAccess, bool isConst, BOOL bAbstract, BOOL bVirtual );
179 void AddStaticMethod(UserProc *pUserProc,DWORD dwAccess);
[4]180
[53]181 //重複チェック
[46]182 BOOL DupliCheckAll(const char *name);
183 BOOL DupliCheckMember(const char *name);
[4]184
[28]185 //メソッド取得
[75]186 CMethod *GetMethodInfo( UserProc *pUserProc ) const;
187 CMethod *GetStaticMethodInfo( UserProc *pUserProc ) const;
[28]188
189 //メソッドの存在を確認
[75]190 bool IsExistMethod( const char *name ) const;
191 bool IsExistStaticMethod( const char *name ) const;
[4]192
[50]193 //メソッドを列挙
[100]194 void EnumStaticMethod( const char *methodName, vector<UserProc *> &subs ) const;
195 void EnumMethod( const char *methodName, vector<UserProc *> &subs ) const;
196 void EnumMethod( const BYTE idOperatorCalc, vector<UserProc *> &subs ) const;
[91]197 const std::vector<CMethod *> &GetMethods() const
198 {
199 return methods;
200 }
201 const std::vector<CMethod *> &GetStaticMethods() const
202 {
203 return staticMethods;
204 }
[18]205
[51]206 //デフォルト コンストラクタ メソッドを取得
207 CMethod *GetConstructorMethod() const;
[50]208
[51]209 //デストラクタ メソッドを取得
210 CMethod *GetDestructorMethod() const;
211
[63]212 // メンバの総合サイズを取得
213 int GetSize() const;
[51]214
[63]215 // メンバのオフセットを取得
[94]216 int GetMemberOffset( const char *memberName, int *pMemberNum = NULL ) const;
[63]217
218private:
219 // アラインメント値を取得
220 int GetAlignment() const;
221
222
[4]223 //vtbl
224private:
[114]225 mutable long vtbl_offset;
[4]226public:
[75]227 int GetFuncNumInVtbl( const UserProc *pUserProc ) const;
[114]228 LONG_PTR GetVtblGlobalOffset(void) const;
[4]229 void ActionVtblSchedule(LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection);
[75]230 bool IsAbstract() const;
[4]231
232
[17]233 //コンストラクタをコンパイルしているかどうかのチェックフラグ
234private:
[114]235 mutable bool isCompilingConstructor;
[17]236public:
[114]237 void NotifyStartConstructorCompile() const;
238 void NotifyFinishConstructorCompile() const;
[75]239 bool IsCompilingConstructor() const;
[17]240
[18]241 //デストラクタをコンパイルしているかどうかのチェックフラグ
242private:
[114]243 mutable bool isCompilingDestructor;
[18]244public:
[114]245 void NotifyStartDestructorCompile() const;
246 void NotifyFinishDestructorCompile() const;
[75]247 bool IsCompilingDestructor() const;
[17]248
[18]249
[28]250 //自身の派生クラスかどうかを確認
[75]251 bool IsSubClass( const CClass *pClass ) const;
[28]252
[59]253 //自身と等しいまたは派生クラスかどうかを確認
[75]254 bool IsEqualsOrSubClass( const CClass *pClass ) const;
[28]255
[94]256 // 自身と等しいまたは派生クラス、基底クラスかどうかを確認
257 bool IsEqualsOrSubClassOrSuperClass( const CClass &objClass ) const;
[59]258
[94]259
[4]260 //線形リスト用
261 CClass *pobj_NextClass;
[64]262
263
264 //メンバの参照方法
265 enum RefType{
[97]266 Non = 0, // no reference member
[64]267 Dot, // obj.member
268 Pointer, // obj->member
269 };
[4]270};
271
272#define MAX_CLASS_HASH 65535
273class CDBClass{
[102]274 int hash(const char *name) const;
[4]275 void DestroyClass(CClass *pobj_c);
276public:
277 CClass *pobj_ClassHash[MAX_CLASS_HASH];
278
279 CDBClass();
280 ~CDBClass();
281
[114]282 const CClass *Find( const string &fullName ) const;
283 const CClass *Find( const NamespaceScopes &namespaceScopes, const string &name ) const;
[4]284
[108]285 CClass *AddClass( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const char *name,int nowLine);
[4]286
287 void ActionVtblSchedule(LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection);
288
289private:
[18]290 void AddMethod(CClass *pobj_c, DWORD dwAccess, BOOL bStatic, bool isConst, BOOL bAbstract,
[75]291 BOOL bVirtual, BOOL bOverride, char *buffer, int nowLine);
292 BOOL MemberVar_LoopRefCheck(const CClass &objClass);
[4]293public:
294 void InitNames(void);
[46]295 void GetClass_recur(const char *lpszInheritsClass);
[67]296 void GetAllClassInfo(void);
[89]297 void Compile_System_InitializeUserTypes();
[4]298
299
[18]300 /////////////////////////////
[67]301 // 特殊クラス
302 /////////////////////////////
303 CClass *pStringClass;
304 CClass *pObjectClass;
[117]305 CClass *GetStringClassPtr() const;
306 CClass *GetObjectClassPtr() const;
[67]307
308
309 /////////////////////////////
[18]310 // 現在コンパイル中の情報
311 /////////////////////////////
[4]312private:
[114]313 const CClass *pCompilingClass;
[18]314 CMethod *pCompilingMethod;
315public:
316 //コンパイル開始の通知を受け取るメソッド
[75]317 void StartCompile( UserProc *pUserProc );
[18]318
319 //現在コンパイル中のメソッド情報を取得
[114]320 const CClass *GetNowCompilingClass() const;
[18]321 CMethod *GetNowCompilingMethodInfo();
322
323
324 /////////////////////
325 // イテレータ
326 /////////////////////
327private:
[4]328 CClass **ppobj_IteClass;
329 int iIteMaxNum;
330 int iIteNextNum;
331public:
[89]332 void Iterator_Init(void);
[4]333 void Iterator_Reset(void);
334 BOOL Iterator_HasNext(void);
335 CClass *Iterator_GetNext(void);
336 int Iterator_GetMaxCount(void);
337};
338
339
340extern CDBClass *pobj_DBClass;
[114]341extern const CClass *pobj_CompilingClass;
Note: See TracBrowser for help on using the repository browser.