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