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