#pragma once #include #include "Prototype.h" #include "Member.h" #include "Method.h" #include "LexicalAnalysis.h" class InheritedInterface { CClass *pInterfaceClass; int vtblOffset; public: InheritedInterface( CClass *pInterfaceClass, int vtblOffset ) : pInterfaceClass( pInterfaceClass ) , vtblOffset( vtblOffset ) { } CClass &GetInterfaceClass() const{ return *pInterfaceClass; } int GetVtblOffset() const { return vtblOffset; } }; typedef vector Interfaces; class CClass : public Prototype { public: // メンバの参照方法 enum RefType{ Non = 0, // no reference member Dot, // obj.member Pointer, // obj->member }; // 型の種類 enum ClassType{ Class, Interface, Enum, Delegate, Structure, }; protected: ClassType classType; // importされている名前空間 NamespaceScopesCollection importedNamespaces; // 実装するインターフェイス Interfaces interfaces; // 継承クラス const CClass *pSuperClass; // Blittable型情報 Type blittableType; // 動的メンバ Members dynamicMembers; // 静的メンバ Members staticMembers; // 動的メソッド Methods methods; int ConstructorMemberSubIndex; int DestructorMemberSubIndex; int vtblNum; // 仮想関数の数 // 静的メソッド Methods staticMethods; // XMLシリアライズ用 // TODO: xml実装 private: friend class boost::serialization::access; template void serialize(Archive& ar, const unsigned int version) { ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Prototype ); ar & BOOST_SERIALIZATION_NVP( classType ); ar & BOOST_SERIALIZATION_NVP( importedNamespaces ); //ar & BOOST_SERIALIZATION_NVP( interfaces ); ar & boost::serialization::make_nvp( "pSuperClass", const_cast(pSuperClass) ); ar & BOOST_SERIALIZATION_NVP( blittableType ); //ar & BOOST_SERIALIZATION_NVP( dynamicMembers ); //ar & BOOST_SERIALIZATION_NVP( staticMembers ); //ar & BOOST_SERIALIZATION_NVP( methods ); ar & BOOST_SERIALIZATION_NVP( ConstructorMemberSubIndex ); ar & BOOST_SERIALIZATION_NVP( DestructorMemberSubIndex ); ar & BOOST_SERIALIZATION_NVP( vtblNum ); //ar & BOOST_SERIALIZATION_NVP( staticMethods ); } bool isReady; public: //アラインメント値 int iAlign; CClass( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const string &name ) : isReady( false ) , Prototype( namespaceScopes, name ) , importedNamespaces( importedNamespaces ) , ConstructorMemberSubIndex( -1 ) , DestructorMemberSubIndex( -1 ) , classType( Class ) , pSuperClass( NULL ) , vtblNum( 0 ) , iAlign( 0 ) , vtbl_offset( -1 ) , isCompilingConstructor( false ) , isCompilingDestructor( false ) , pobj_NextClass( NULL ) { } CClass() : isReady( false ) , Prototype() , importedNamespaces() , ConstructorMemberSubIndex( -1 ) , DestructorMemberSubIndex( -1 ) , classType() , pSuperClass( NULL ) , vtblNum( 0 ) , iAlign( 0 ) , vtbl_offset( -1 ) , isCompilingConstructor( false ) , isCompilingDestructor( false ) , pobj_NextClass( NULL ) { } ~CClass(); void Readed(){ isReady = true; } bool IsReady() const{ return isReady; } const NamespaceScopesCollection &GetImportedNamespaces() const { return importedNamespaces; } // インターフェイス bool HasInterfaces() const { return ( interfaces.size() != 0 ); } bool IsInheritsInterface( const CClass *pInterfaceClass ) const; // 継承元クラス bool HasSuperClass() const { return ( pSuperClass != NULL ); } const CClass &GetSuperClass() const { return *pSuperClass; } void SetSuperClass( const CClass *pSuperClass ) { this->pSuperClass = pSuperClass; } // Blittable型 bool IsBlittableType() const { return !blittableType.IsNull(); } const Type &GetBlittableType() const { return blittableType; } void SetBlittableType( const Type &type ){ blittableType = type; } bool IsClass() const; bool IsInterface() const; bool IsEnum() const; bool IsDelegate() const; bool IsStructure() const; void SetClassType( ClassType classType ) { this->classType = classType; } // 継承させる virtual bool Inherits( const char *inheritNames, int nowLine ) = 0; virtual bool InheritsClass( const CClass &inheritsClass, int nowLine ) = 0; virtual bool InheritsInterface( const CClass &inheritsClass, int nowLine ) = 0; virtual void AddMember( Prototype::Accessibility accessibility, bool idConst, bool isRef, char *buffer, int nowLine ) = 0; virtual void AddStaticMember( Prototype::Accessibility accessibility, bool isConst, bool isRef, char *buffer, int nowLine ) = 0; virtual void AddMethod(CClass *pobj_c, Prototype::Accessibility accessibility, BOOL bStatic, bool isConst, bool isAbstract, bool isVirtual, bool isOverride, char *buffer, int nowLine) = 0; //重複チェック BOOL DupliCheckAll(const char *name); BOOL DupliCheckMember(const char *name); const Members &GetDynamicMembers() const { return dynamicMembers; } const Members &GetStaticMembers() const { return staticMembers; } Members &GetDynamicMembers() { return dynamicMembers; } Members &GetStaticMembers() { return staticMembers; } const Methods &GetMethods() const { return methods; } const Methods &GetStaticMethods() const { return staticMethods; } Methods &GetMethods() { return methods; } Methods &GetStaticMethods() { return staticMethods; } //デフォルト コンストラクタ const CMethod *GetConstructorMethod() const; void SetConstructorMemberSubIndex( int constructorMemberSubIndex ) { this->ConstructorMemberSubIndex = constructorMemberSubIndex; } //デストラクタ メソッドを取得 const CMethod *GetDestructorMethod() const; void SetDestructorMemberSubIndex( int destructorMemberSubIndex ) { this->DestructorMemberSubIndex = destructorMemberSubIndex; } // vtblに存在する仮想関数の数 int GetVtblNum() const { return vtblNum; } void SetVtblNum( int vtblNum ) { this->vtblNum = vtblNum; } void AddVtblNum( int vtblNum ) { this->vtblNum += vtblNum; } bool IsExistVirtualFunctions() const { return ( vtblNum > 0 ); } // メンバの総合サイズを取得 int GetSize() const; // メンバのオフセットを取得 int GetMemberOffset( const char *memberName, int *pMemberNum = NULL ) const; private: // アラインメント値を取得 int GetAlignment() const; //vtbl protected: mutable long vtbl_offset; public: int GetFuncNumInVtbl( const UserProc *pUserProc ) const; virtual LONG_PTR GetVtblGlobalOffset(void) const = 0; virtual void ActionVtblSchedule(LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection) = 0; bool IsAbstract() const; //コンストラクタをコンパイルしているかどうかのチェックフラグ private: mutable bool isCompilingConstructor; public: void NotifyStartConstructorCompile() const; void NotifyFinishConstructorCompile() const; bool IsCompilingConstructor() const; //デストラクタをコンパイルしているかどうかのチェックフラグ private: mutable bool isCompilingDestructor; public: void NotifyStartDestructorCompile() const; void NotifyFinishDestructorCompile() const; bool IsCompilingDestructor() const; //自身の派生クラスかどうかを確認 bool IsSubClass( const CClass *pClass ) const; //自身と等しいまたは派生クラスかどうかを確認 bool IsEqualsOrSubClass( const CClass *pClass ) const; // 自身と等しいまたは派生クラス、基底クラスかどうかを確認 bool IsEqualsOrSubClassOrSuperClass( const CClass &objClass ) const; //線形リスト用 CClass *pobj_NextClass; public: static bool SplitName( const char *desc, char *object, char *member, CClass::RefType &refType ){ int lastIndex = -1; for( int i=0; desc[i]; i++ ){ if( desc[i] == '(' ){ i=JumpStringInPare(desc,i+1); continue; } else if( desc[i] == '[' ){ i=JumpStringInBracket(desc,i+1); continue; } else if(desc[i]=='.'||(desc[i]==1&&desc[i+1]==ESC_PSMEM)){ lastIndex = i; } } if( lastIndex == -1 ){ lstrcpy( member, desc ); return false; } if(desc[lastIndex]=='.'){ lstrcpy(member,desc+lastIndex+1); refType = CClass::Dot; } else{ lstrcpy(member,desc+lastIndex+2); refType = CClass::Pointer; } if( object ){ lstrcpy( object, desc ); object[lastIndex]=0; } return true; } static bool SplitName( const char *desc, char *object, char *member ){ CClass::RefType dummyRefType; return SplitName( desc, object, member, dummyRefType ); } }; #define MAX_CLASS_HASH 65535 class Classes { protected: int GetHashCode(const char *name) const; void DestroyClass(CClass *pobj_c); public: CClass *pobj_ClassHash[MAX_CLASS_HASH]; Classes(); ~Classes(); void Clear(); const CClass *Find( const string &fullName ) const; virtual const CClass *Find( const NamespaceScopes &namespaceScopes, const string &name ) const = 0; virtual CClass *Create( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const char *name) = 0; bool Insert( CClass *pClass ); CClass *Add( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const char *name,int nowLine); void ActionVtblSchedule(LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection); public: // 実体収集 virtual void CollectClassesForNameOnly( const BasicSource &source ) = 0; virtual void GetClass_recur(const char *lpszInheritsClass) = 0; virtual void GetAllClassInfo() = 0; virtual void Compile_System_InitializeUserTypes() = 0; virtual void InitStaticMember() = 0; ///////////////////////////// // 特殊クラス ///////////////////////////// CClass *pStringClass; CClass *pObjectClass; CClass *GetStringClassPtr() const; CClass *GetObjectClassPtr() const; ///////////////////////////// // 現在コンパイル中の情報 ///////////////////////////// private: const CClass *pCompilingClass; const CMethod *pCompilingMethod; public: //コンパイル開始の通知を受け取るメソッド void StartCompile( UserProc *pUserProc ); //現在コンパイル中のメソッド情報を取得 const CClass *GetNowCompilingClass() const; const CMethod *GetNowCompilingMethodInfo(); ///////////////////// // イテレータ ///////////////////// private: mutable CClass **ppobj_IteClass; mutable int iIteMaxNum; mutable int iIteNextNum; public: void Iterator_Init() const; void Iterator_Reset() const; BOOL Iterator_HasNext() const; CClass *Iterator_GetNext() const; int Iterator_GetMaxCount() const; };