| 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 Classes;
 | 
|---|
| 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 Classes;
 | 
|---|
| 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 |     int vtblNum;                    // 仮想関数の数
 | 
|---|
| 68 | 
 | 
|---|
| 69 |     // 静的メソッド
 | 
|---|
| 70 |     Methods staticMethods;
 | 
|---|
| 71 | 
 | 
|---|
| 72 |     enum ClassType{
 | 
|---|
| 73 |         Class,
 | 
|---|
| 74 |         Interface,
 | 
|---|
| 75 |         Enum,
 | 
|---|
| 76 |         Delegate,
 | 
|---|
| 77 |         Structure,
 | 
|---|
| 78 |     };
 | 
|---|
| 79 | 
 | 
|---|
| 80 |     ClassType classType;
 | 
|---|
| 81 | 
 | 
|---|
| 82 | public:
 | 
|---|
| 83 | 
 | 
|---|
| 84 |     //継承クラスへのポインタ
 | 
|---|
| 85 |     const CClass *pobj_InheritsClass;
 | 
|---|
| 86 | 
 | 
|---|
| 87 |     //アラインメント値
 | 
|---|
| 88 |     int iAlign;
 | 
|---|
| 89 | 
 | 
|---|
| 90 |     CClass( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const string &name );
 | 
|---|
| 91 |     ~CClass();
 | 
|---|
| 92 | 
 | 
|---|
| 93 |     const NamespaceScopesCollection &GetImportedNamespaces() const
 | 
|---|
| 94 |     {
 | 
|---|
| 95 |         return importedNamespaces;
 | 
|---|
| 96 |     }
 | 
|---|
| 97 | 
 | 
|---|
| 98 |     // インターフェイス
 | 
|---|
| 99 |     bool HasInterfaces() const
 | 
|---|
| 100 |     {
 | 
|---|
| 101 |         return ( interfaces.size() != 0 );
 | 
|---|
| 102 |     }
 | 
|---|
| 103 |     bool IsInheritsInterface( const CClass *pInterfaceClass ) const;
 | 
|---|
| 104 | 
 | 
|---|
| 105 |     // Blittable型
 | 
|---|
| 106 |     bool IsBlittableType() const
 | 
|---|
| 107 |     {
 | 
|---|
| 108 |         return !blittableType.IsNull();
 | 
|---|
| 109 |     }
 | 
|---|
| 110 |     const Type &GetBlittableType() const
 | 
|---|
| 111 |     {
 | 
|---|
| 112 |         return blittableType;
 | 
|---|
| 113 |     }
 | 
|---|
| 114 |     void SetBlittableType( const Type &type ){
 | 
|---|
| 115 |         blittableType = type;
 | 
|---|
| 116 |     }
 | 
|---|
| 117 | 
 | 
|---|
| 118 |     bool IsClass() const;
 | 
|---|
| 119 |     bool IsInterface() const;
 | 
|---|
| 120 |     bool IsEnum() const;
 | 
|---|
| 121 |     bool IsDelegate() const;
 | 
|---|
| 122 |     bool IsStructure() const;
 | 
|---|
| 123 | 
 | 
|---|
| 124 |     //継承させる
 | 
|---|
| 125 |     bool Inherits( const char *inheritNames, int nowLine );
 | 
|---|
| 126 |     bool InheritsClass( const CClass &inheritsClass, int nowLine );
 | 
|---|
| 127 |     bool InheritsInterface( const CClass &inheritsClass, int nowLine );
 | 
|---|
| 128 | 
 | 
|---|
| 129 |     //メンバ、メソッドの追加
 | 
|---|
| 130 |     void AddMember( Prototype::Accessibility accessibility, bool idConst, bool isRef, char *buffer );
 | 
|---|
| 131 |     void AddStaticMember( Prototype::Accessibility accessibility, bool isConst, bool isRef, char *buffer, int nowLine );
 | 
|---|
| 132 | 
 | 
|---|
| 133 |     //重複チェック
 | 
|---|
| 134 |     BOOL DupliCheckAll(const char *name);
 | 
|---|
| 135 |     BOOL DupliCheckMember(const char *name);
 | 
|---|
| 136 | 
 | 
|---|
| 137 |     const Members &GetDynamicMembers() const
 | 
|---|
| 138 |     {
 | 
|---|
| 139 |         return dynamicMembers;
 | 
|---|
| 140 |     }
 | 
|---|
| 141 | 
 | 
|---|
| 142 |     const Methods &GetMethods() const
 | 
|---|
| 143 |     {
 | 
|---|
| 144 |         return methods;
 | 
|---|
| 145 |     }
 | 
|---|
| 146 |     const Methods &GetStaticMethods() const
 | 
|---|
| 147 |     {
 | 
|---|
| 148 |         return staticMethods;
 | 
|---|
| 149 |     }
 | 
|---|
| 150 | 
 | 
|---|
| 151 |     //デフォルト コンストラクタ メソッドを取得
 | 
|---|
| 152 |     const CMethod *GetConstructorMethod() const;
 | 
|---|
| 153 | 
 | 
|---|
| 154 |     //デストラクタ メソッドを取得
 | 
|---|
| 155 |     const CMethod *GetDestructorMethod() const;
 | 
|---|
| 156 | 
 | 
|---|
| 157 |     // vtblに存在する仮想関数の数
 | 
|---|
| 158 |     int GetVtblNum() const
 | 
|---|
| 159 |     {
 | 
|---|
| 160 |         return vtblNum;
 | 
|---|
| 161 |     }
 | 
|---|
| 162 |     void SetVtblNum( int vtblNum )
 | 
|---|
| 163 |     {
 | 
|---|
| 164 |         this->vtblNum = vtblNum;
 | 
|---|
| 165 |     }
 | 
|---|
| 166 |     void AddVtblNum( int vtblNum )
 | 
|---|
| 167 |     {
 | 
|---|
| 168 |         this->vtblNum += vtblNum;
 | 
|---|
| 169 |     }
 | 
|---|
| 170 |     bool IsExistVirtualFunctions() const
 | 
|---|
| 171 |     {
 | 
|---|
| 172 |         return ( vtblNum > 0 );
 | 
|---|
| 173 |     }
 | 
|---|
| 174 | 
 | 
|---|
| 175 |     // メンバの総合サイズを取得
 | 
|---|
| 176 |     int GetSize() const;
 | 
|---|
| 177 | 
 | 
|---|
| 178 |     // メンバのオフセットを取得
 | 
|---|
| 179 |     int GetMemberOffset( const char *memberName, int *pMemberNum = NULL ) const;
 | 
|---|
| 180 | 
 | 
|---|
| 181 | private:
 | 
|---|
| 182 |     // アラインメント値を取得
 | 
|---|
| 183 |     int GetAlignment() const;
 | 
|---|
| 184 | 
 | 
|---|
| 185 | 
 | 
|---|
| 186 |     //vtbl
 | 
|---|
| 187 | private:
 | 
|---|
| 188 |     mutable long vtbl_offset;
 | 
|---|
| 189 | public:
 | 
|---|
| 190 |     int GetFuncNumInVtbl( const UserProc *pUserProc ) const;
 | 
|---|
| 191 |     LONG_PTR GetVtblGlobalOffset(void) const;
 | 
|---|
| 192 |     void ActionVtblSchedule(LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection);
 | 
|---|
| 193 |     bool IsAbstract() const;
 | 
|---|
| 194 | 
 | 
|---|
| 195 | 
 | 
|---|
| 196 |     //コンストラクタをコンパイルしているかどうかのチェックフラグ
 | 
|---|
| 197 | private:
 | 
|---|
| 198 |     mutable bool isCompilingConstructor;
 | 
|---|
| 199 | public:
 | 
|---|
| 200 |     void NotifyStartConstructorCompile() const;
 | 
|---|
| 201 |     void NotifyFinishConstructorCompile() const;
 | 
|---|
| 202 |     bool IsCompilingConstructor() const;
 | 
|---|
| 203 | 
 | 
|---|
| 204 |     //デストラクタをコンパイルしているかどうかのチェックフラグ
 | 
|---|
| 205 | private:
 | 
|---|
| 206 |     mutable bool isCompilingDestructor;
 | 
|---|
| 207 | public:
 | 
|---|
| 208 |     void NotifyStartDestructorCompile() const;
 | 
|---|
| 209 |     void NotifyFinishDestructorCompile() const;
 | 
|---|
| 210 |     bool IsCompilingDestructor() const;
 | 
|---|
| 211 | 
 | 
|---|
| 212 | 
 | 
|---|
| 213 |     //自身の派生クラスかどうかを確認
 | 
|---|
| 214 |     bool IsSubClass( const CClass *pClass ) const;
 | 
|---|
| 215 | 
 | 
|---|
| 216 |     //自身と等しいまたは派生クラスかどうかを確認
 | 
|---|
| 217 |     bool IsEqualsOrSubClass( const CClass *pClass ) const;
 | 
|---|
| 218 | 
 | 
|---|
| 219 |     // 自身と等しいまたは派生クラス、基底クラスかどうかを確認
 | 
|---|
| 220 |     bool IsEqualsOrSubClassOrSuperClass( const CClass &objClass ) const;
 | 
|---|
| 221 | 
 | 
|---|
| 222 | 
 | 
|---|
| 223 |     //線形リスト用
 | 
|---|
| 224 |     CClass *pobj_NextClass;
 | 
|---|
| 225 | 
 | 
|---|
| 226 | 
 | 
|---|
| 227 |     //メンバの参照方法
 | 
|---|
| 228 |     enum RefType{
 | 
|---|
| 229 |         Non = 0,        // no reference member
 | 
|---|
| 230 |         Dot,            // obj.member
 | 
|---|
| 231 |         Pointer,        // obj->member
 | 
|---|
| 232 |     };
 | 
|---|
| 233 | };
 | 
|---|
| 234 | 
 | 
|---|
| 235 | #define MAX_CLASS_HASH 65535
 | 
|---|
| 236 | class Classes{
 | 
|---|
| 237 |     int hash(const char *name) const;
 | 
|---|
| 238 |     void DestroyClass(CClass *pobj_c);
 | 
|---|
| 239 | public:
 | 
|---|
| 240 |     CClass *pobj_ClassHash[MAX_CLASS_HASH];
 | 
|---|
| 241 | 
 | 
|---|
| 242 |     Classes();
 | 
|---|
| 243 |     ~Classes();
 | 
|---|
| 244 | 
 | 
|---|
| 245 |     const CClass *Find( const string &fullName ) const;
 | 
|---|
| 246 |     const CClass *Find( const NamespaceScopes &namespaceScopes, const string &name ) const;
 | 
|---|
| 247 | 
 | 
|---|
| 248 |     CClass *AddClass( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const char *name,int nowLine);
 | 
|---|
| 249 | 
 | 
|---|
| 250 |     void ActionVtblSchedule(LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection);
 | 
|---|
| 251 | 
 | 
|---|
| 252 | private:
 | 
|---|
| 253 |     void AddMethod(CClass *pobj_c, Prototype::Accessibility accessibility, BOOL bStatic, bool isConst, bool isAbstract,
 | 
|---|
| 254 |         bool isVirtual, bool isOverride, char *buffer, int nowLine);
 | 
|---|
| 255 |     BOOL MemberVar_LoopRefCheck(const CClass &objClass);
 | 
|---|
| 256 | public:
 | 
|---|
| 257 |     void InitNames(void);
 | 
|---|
| 258 |     void GetClass_recur(const char *lpszInheritsClass);
 | 
|---|
| 259 |     void GetAllClassInfo(void);
 | 
|---|
| 260 |     void Compile_System_InitializeUserTypes();
 | 
|---|
| 261 | 
 | 
|---|
| 262 | 
 | 
|---|
| 263 |     /////////////////////////////
 | 
|---|
| 264 |     // 特殊クラス
 | 
|---|
| 265 |     /////////////////////////////
 | 
|---|
| 266 |     CClass *pStringClass;
 | 
|---|
| 267 |     CClass *pObjectClass;
 | 
|---|
| 268 |     CClass *GetStringClassPtr() const;
 | 
|---|
| 269 |     CClass *GetObjectClassPtr() const;
 | 
|---|
| 270 | 
 | 
|---|
| 271 | 
 | 
|---|
| 272 |     /////////////////////////////
 | 
|---|
| 273 |     // 現在コンパイル中の情報
 | 
|---|
| 274 |     /////////////////////////////
 | 
|---|
| 275 | private:
 | 
|---|
| 276 |     const CClass *pCompilingClass;
 | 
|---|
| 277 |     const CMethod *pCompilingMethod;
 | 
|---|
| 278 | public:
 | 
|---|
| 279 |     //コンパイル開始の通知を受け取るメソッド
 | 
|---|
| 280 |     void StartCompile( UserProc *pUserProc );
 | 
|---|
| 281 | 
 | 
|---|
| 282 |     //現在コンパイル中のメソッド情報を取得
 | 
|---|
| 283 |     const CClass *GetNowCompilingClass() const;
 | 
|---|
| 284 |     const CMethod *GetNowCompilingMethodInfo();
 | 
|---|
| 285 | 
 | 
|---|
| 286 | 
 | 
|---|
| 287 |     /////////////////////
 | 
|---|
| 288 |     // イテレータ
 | 
|---|
| 289 |     /////////////////////
 | 
|---|
| 290 | private:
 | 
|---|
| 291 |     CClass **ppobj_IteClass;
 | 
|---|
| 292 |     int iIteMaxNum;
 | 
|---|
| 293 |     int iIteNextNum;
 | 
|---|
| 294 | public:
 | 
|---|
| 295 |     void Iterator_Init(void);
 | 
|---|
| 296 |     void Iterator_Reset(void);
 | 
|---|
| 297 |     BOOL Iterator_HasNext(void);
 | 
|---|
| 298 |     CClass *Iterator_GetNext(void);
 | 
|---|
| 299 |     int Iterator_GetMaxCount(void);
 | 
|---|
| 300 | };
 | 
|---|
| 301 | 
 | 
|---|
| 302 | 
 | 
|---|
| 303 | extern Classes *pobj_DBClass;
 | 
|---|
| 304 | extern const CClass *pobj_CompilingClass;
 | 
|---|