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