#pragma once #include #include #include #include #include class UserProc; 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 ClassType{ Class, Interface, Enum, Delegate, Structure, }; private: ClassType classType; // importされている名前空間 NamespaceScopesCollection importedNamespaces; // 継承クラス const CClass *pSuperClass; // Blittable型情報 Type blittableType; // 実装するインターフェイス Interfaces interfaces; // 動的メンバ 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) { trace_for_serialize( "serializing - CClass" ); ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Prototype ); ar & BOOST_SERIALIZATION_NVP( classType ); ar & BOOST_SERIALIZATION_NVP( importedNamespaces ); ar & boost::serialization::make_nvp( "pSuperClass", const_cast(pSuperClass) ); ar & BOOST_SERIALIZATION_NVP( blittableType ); //ar & BOOST_SERIALIZATION_NVP( interfaces ); 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 ) : Prototype( namespaceScopes, name ) , importedNamespaces( importedNamespaces ) , classType( Class ) , pSuperClass( NULL ) , isReady( false ) , iAlign( 0 ) , ConstructorMemberSubIndex( -1 ) , DestructorMemberSubIndex( -1 ) , vtblNum( 0 ) , vtbl_offset( -1 ) , isCompilingConstructor( false ) , isCompilingDestructor( false ) , pobj_NextClass( NULL ) { } CClass() : Prototype() , importedNamespaces() , classType() , pSuperClass( NULL ) , isReady( false ) , iAlign( 0 ) , ConstructorMemberSubIndex( -1 ) , DestructorMemberSubIndex( -1 ) , vtblNum( 0 ) , vtbl_offset( -1 ) , isCompilingConstructor( false ) , isCompilingDestructor( false ) , pobj_NextClass( NULL ) { } ~CClass() { // 動的メンバ BOOST_FOREACH( CMember *member, dynamicMembers ){ delete member; } // 静的メンバ BOOST_FOREACH( CMember *member, staticMembers ){ delete member; } } void Readed(){ isReady = true; } bool IsReady() const{ return isReady; } const NamespaceScopesCollection &GetImportedNamespaces() const { return importedNamespaces; } // 継承元クラス 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; } //コンストラクタをコンパイルしているかどうかのチェックフラグ 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; // インターフェイス bool HasInterfaces() const { return ( interfaces.size() != 0 ); } bool IsInheritsInterface( const CClass *pInterfaceClass ) const; //継承させる bool Inherits( const char *inheritNames, int nowLine ); bool InheritsClass( const CClass &inheritsClass, int nowLine ); bool InheritsInterface( const CClass &inheritsClass, int nowLine ); //メンバ、メソッドの追加 CMember *CreateMember( Prototype::Accessibility accessibility, bool isConst, bool isRef, char *buffer, int nowLine ); void AddMember( Prototype::Accessibility accessibility, bool idConst, bool isRef, char *buffer, int nowLine ); void AddStaticMember( Prototype::Accessibility accessibility, bool isConst, bool isRef, char *buffer, int nowLine ); void AddMethod(CClass *pobj_c, Prototype::Accessibility accessibility, BOOL bStatic, bool isConst, bool isAbstract, bool isVirtual, bool isOverride, char *buffer, int nowLine); //重複チェック 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 { if( ConstructorMemberSubIndex == -1 ) return NULL; return methods[ConstructorMemberSubIndex]; } void SetConstructorMemberSubIndex( int constructorMemberSubIndex ) { this->ConstructorMemberSubIndex = constructorMemberSubIndex; } //デストラクタ メソッドを取得 const CMethod *GetDestructorMethod() const { if( DestructorMemberSubIndex == -1 ) return NULL; return methods[DestructorMemberSubIndex]; } 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; LONG_PTR GetVtblGlobalOffset(void) const; void ActionVtblSchedule(LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection); bool IsAbstract() const; //線形リスト用 CClass *pobj_NextClass; }; #define MAX_CLASS_HASH 65535 class Classes { CClass *pobj_ClassHash[MAX_CLASS_HASH]; int GetHashCode(const char *name) const; // XMLシリアライズ用 private: friend class boost::serialization::access; BOOST_SERIALIZATION_SPLIT_MEMBER(); template void load(Archive& ar, const unsigned int version) { trace_for_serialize( "serializing(load) - Classes" ); std::vector vectorClasses; ar & BOOST_SERIALIZATION_NVP( vectorClasses ); // 読み込み後の処理 Clear(); BOOST_FOREACH( CClass *pClass, vectorClasses ) { Insert( pClass ); } Iterator_Init(); } template void save(Archive& ar, const unsigned int version) const { trace_for_serialize( "serializing(save) - Classes" ); // 保存準備 std::vector vectorClasses; vectorClasses.clear(); Iterator_Reset(); while( Iterator_HasNext() ) { vectorClasses.push_back( dynamic_cast(Iterator_GetNext()) ); } ar & BOOST_SERIALIZATION_NVP( vectorClasses ); } public: Classes() : pCompilingMethod( NULL ) , pStringClass( NULL ) , pObjectClass( NULL ) , ppobj_IteClass( NULL ) , iIteMaxNum( 0 ) , iIteNextNum( 0 ) { memset( pobj_ClassHash, 0, MAX_CLASS_HASH * sizeof(CClass *) ); } ~Classes() { for(int i=0;ipobj_NextClass){ DestroyClass(pobj_c->pobj_NextClass); } delete pobj_c; } void Clear() { if(ppobj_IteClass) { free(ppobj_IteClass); ppobj_IteClass = NULL; } // TODO: ここはこれでいいのか… memset( pobj_ClassHash, 0, MAX_CLASS_HASH * sizeof(CClass *) ); } virtual CClass *Create( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const char *name); bool Insert( CClass *pClass ); CClass *Add( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const char *name,int nowLine); virtual void CollectClassesForNameOnly( const BasicSource &source ); void ActionVtblSchedule(LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection); virtual void InitStaticMember(); private: bool MemberVar_LoopRefCheck(const CClass &objClass); public: virtual void GetClass_recur(const char *lpszInheritsClass); virtual void GetAllClassInfo(); virtual void Compile_System_InitializeUserTypes(); const CClass *Find( const NamespaceScopes &namespaceScopes, const string &name ) const; const CClass *Find( const string &fullName ) const; ///////////////////////////// // 現在コンパイル中の情報 ///////////////////////////// private: const CMethod *pCompilingMethod; public: void StartCompile( const UserProc *pUserProc ); //現在コンパイル中のメソッド情報を取得 const CMethod *GetNowCompilingMethodInfo(){ return pCompilingMethod; } ///////////////////////////// // 特殊クラス ///////////////////////////// CClass *pStringClass; CClass *pObjectClass; CClass *GetStringClassPtr() const; CClass *GetObjectClassPtr() const; ///////////////////// // イテレータ ///////////////////// 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; };