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