#pragma once #include #include #include #include #include #include class UserProc; class CClass; class Delegate; 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 Jenga::Common::ObjectInHashmap { public: // 型の種類 enum ClassType{ Class, Interface, Enum, Delegate, Structure, }; private: ClassType classType; // importされている名前空間 NamespaceScopesCollection importedNamespaces; // 型パラメータ GenericTypes formalGenericTypes; // 継承クラス const CClass *pSuperClass; // 継承クラスの型パラメータ(実パラメータ) Types superClassActualTypeParameters; // Blittable型情報 Type blittableType; // 実装するインターフェイス Interfaces interfaces; // 動的メンバ Members dynamicMembers; // 静的メンバ Members staticMembers; // 動的メソッド Methods methods; int ConstructorMemberSubIndex; int DestructorMemberSubIndex; int vtblNum; // 仮想関数の数 // 静的メソッド Methods staticMethods; //アラインメント値 int fixedAlignment; // 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_NVP( formalGenericTypes ); ar & boost::serialization::make_nvp( "pSuperClass", const_cast(pSuperClass) ); ar & BOOST_SERIALIZATION_NVP( superClassActualTypeParameters ); 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 ); ar & BOOST_SERIALIZATION_NVP( fixedAlignment ); } bool isReady; public: CClass( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const string &name ) : Prototype( namespaceScopes, name ) , importedNamespaces( importedNamespaces ) , classType( Class ) , pSuperClass( NULL ) , blittableType( Type() ) , isReady( false ) , fixedAlignment( 0 ) , ConstructorMemberSubIndex( -1 ) , DestructorMemberSubIndex( -1 ) , vtblNum( 0 ) , vtbl_offset( -1 ) , isCompilingConstructor( false ) , isCompilingDestructor( false ) , pobj_NextClass( NULL ) { } CClass() : Prototype() , importedNamespaces() , classType() , pSuperClass( NULL ) , blittableType( Type() ) , isReady( false ) , fixedAlignment( 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; } } virtual const std::string &GetKeyName() const { return GetName(); } virtual bool IsDuplication( const CClass *pClass ) const { if( pClass->IsEqualSymbol( *this ) ) { return true; } return false; } void Readed(){ isReady = true; } bool IsReady() const{ return isReady; } const NamespaceScopesCollection &GetImportedNamespaces() const { return importedNamespaces; } // 型パラメータ void AddFormalGenericType( GenericType genericType ) { this->formalGenericTypes.push_back( genericType ); } int GetFormalGenericTypeParameterIndex( const std::string &name ) const { int i = 0; BOOST_FOREACH( const GenericType &genericType, formalGenericTypes ) { if( genericType.GetName() == name ) { return i; } i++; } return -1; } bool IsExistFormalGenericTypeParameter( const std::string &name ) const { BOOST_FOREACH( const GenericType &genericType, formalGenericTypes ) { if( genericType.GetName() == name ) { return true; } } return false; } // 継承元クラス bool HasSuperClass() const { return ( pSuperClass != NULL ); } const CClass &GetSuperClass() const { return *pSuperClass; } void SetSuperClass( const CClass *pSuperClass ) { this->pSuperClass = pSuperClass; } const Types &GetSuperClassActualTypeParameters() const { return superClassActualTypeParameters; } void SetSuperClassActualTypeParameters( const Types &actualTypeParameters ) { this->superClassActualTypeParameters = actualTypeParameters; } // 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, const Types &actualTypeParameters, 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; } // デリゲート情報を取得 const ::Delegate &GetDelegate() const; // 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 GetFixedAlignment() const { return fixedAlignment; } void SetFixedAlignment( int fixedAlignment ) { this->fixedAlignment = fixedAlignment; } // メンバの総合サイズを取得 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 GenerateVTables(); void ActionVtblSchedule(LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection); bool IsAbstract() const; //線形リスト用 CClass *pobj_NextClass; }; class Classes : public Jenga::Common::Hashmap { // XMLシリアライズ用 public: Classes() : pCompilingMethod( NULL ) , pStringClass( NULL ) , pObjectClass( NULL ) { } ~Classes() { } 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 GenerateVTables(); 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; } ///////////////////////////// // 特殊クラス ///////////////////////////// mutable const CClass *pStringClass; mutable const CClass *pObjectClass; const CClass *GetStringClassPtr() const; const CClass *GetObjectClassPtr() const; };