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