#pragma once #include #include #include #include #include #include #include class UserProc; class CClass; class Delegate; class DynamicMethodsPrototype { // 動的メソッド Methods dynamicMethods; // XMLシリアライズ用 private: friend class boost::serialization::access; template void serialize(Archive& ar, const unsigned int version) { ar & BOOST_SERIALIZATION_NVP( dynamicMethods ); } public: DynamicMethodsPrototype(){} DynamicMethodsPrototype( const DynamicMethodsPrototype &dynamicMethodsPrototype ) : dynamicMethods( dynamicMethodsPrototype.dynamicMethods ) { } ~DynamicMethodsPrototype(){} const Methods &GetDynamicMethods() const { return dynamicMethods; } Methods &GetDynamicMethods() { return dynamicMethods; } void AddDynamicMethods( CMethod *pMethod ) { dynamicMethods.push_back( pMethod ); } }; class ClassPrototype : public Prototype, public DynamicMethodsPrototype { // 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_BASE_OBJECT_NVP( DynamicMethodsPrototype ); } public: ClassPrototype( const NamespaceScopes &namespaceScopes, const string &name ) : Prototype( namespaceScopes, name ) , DynamicMethodsPrototype() { } ClassPrototype() : Prototype() , DynamicMethodsPrototype() { } }; class Interface : public DynamicMethodsPrototype { const CClass *pInterfaceClass; mutable LONG_PTR vtblOffset; // 型パラメータ(実パラメータ) Types actualTypeParameters; // XMLシリアライズ用 private: friend class boost::serialization::access; template void serialize(Archive& ar, const unsigned int version) { trace_for_serialize( "serializing - Interface" ); ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( DynamicMethodsPrototype ); ar & boost::serialization::make_nvp("pInterfaceClass", const_cast(pInterfaceClass) ); ar & BOOST_SERIALIZATION_NVP( vtblOffset ); ar & BOOST_SERIALIZATION_NVP( actualTypeParameters ); } public: Interface( const CClass *pInterfaceClass, const Types &actualTypeParameters ); Interface( const Interface &objInterface ) : DynamicMethodsPrototype( objInterface ) , pInterfaceClass( objInterface.pInterfaceClass ) , vtblOffset( objInterface.vtblOffset ) { } Interface() { } const CClass &GetClass() const{ return *pInterfaceClass; } LONG_PTR GetVtblOffset() const { return vtblOffset; } void SetVtblOffset( LONG_PTR vtblOffset ) const { this->vtblOffset = vtblOffset; } const Types &GetActualTypeParameters() const { return actualTypeParameters; } std::string GetFullNameWithActualGenericTypeParameters() const; }; typedef std::vector Interfaces; class CClass: public ClassPrototype, public Jenga::Common::ObjectInHashmap { public: // 型の種類 enum ClassType{ Class, Interface, ComInterface, 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; // 動的メソッド int ConstructorMemberSubIndex; int DestructorMemberSubIndex; int vtblNum; // 仮想関数の数 // 静的メソッド Methods staticMethods; //アラインメント値 int fixedAlignment; // 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( ClassPrototype ); 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( 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 ) : ClassPrototype( namespaceScopes, name ) , importedNamespaces( importedNamespaces ) , classType( Class ) , pSuperClass( NULL ) , blittableType( Type() ) , isReady( false ) , fixedAlignment( 0 ) , ConstructorMemberSubIndex( -1 ) , DestructorMemberSubIndex( -1 ) , vtblNum( 0 ) , vtbl_offset( -1 ) , comVtblOffset( 0 ) , isCompilingConstructor( false ) , isCompilingDestructor( false ) , pobj_NextClass( NULL ) { } CClass() : ClassPrototype() , importedNamespaces() , classType() , pSuperClass( NULL ) , blittableType( Type() ) , isReady( false ) , fixedAlignment( 0 ) , ConstructorMemberSubIndex( -1 ) , DestructorMemberSubIndex( -1 ) , vtblNum( 0 ) , vtbl_offset( -1 ) , comVtblOffset( 0 ) , isCompilingConstructor( false ) , isCompilingDestructor( false ) , pobj_NextClass( NULL ) { } ~CClass() { // 動的メンバ BOOST_FOREACH( CMember *member, dynamicMembers ) { delete member; } // 静的メンバ BOOST_FOREACH( CMember *member, staticMembers ) { delete member; } // インターフェイス BOOST_FOREACH( ::Interface *pInterface, interfaces ) { delete pInterface; } } 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 IsGeneric() const { return ( this->formalGenericTypes.size() != 0 ); } // 継承元クラス 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 IsComInterface() 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 ); } const Interfaces &GetInterfaces() const { return interfaces; } 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 ); // インターフェイス実装 bool Implements( const CClass &interfaceClass, const Types &actualTypeParameters, int nowLine ); bool Implements( const char *interfaceNames, 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, bool isAutoGeneration, 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 CMember *FindDynamicMember( const char *memberName ) const { BOOST_FOREACH( CMember *pMember, GetDynamicMembers() ) { if( pMember->GetName() == memberName ) { return pMember; } } return NULL; } void EnumDynamicMethodsOrInterfaceMethods( const char *methodName, std::vector &subs ) const; const CMethod *GetDynamicMethodOrInterfaceMethod( const UserProc *pUserProc ) const; const Methods &GetStaticMethods() const { return staticMethods; } Methods &GetStaticMethods() { return staticMethods; } //デフォルト コンストラクタ const CMethod *GetConstructorMethod() const { if( ConstructorMemberSubIndex == -1 ) return NULL; return GetDynamicMethods()[ConstructorMemberSubIndex]; } void SetConstructorMemberSubIndex( int constructorMemberSubIndex ) { this->ConstructorMemberSubIndex = constructorMemberSubIndex; } //デストラクタ メソッドを取得 const CMethod *GetDestructorMethod() const { if( DestructorMemberSubIndex == -1 ) return NULL; return GetDynamicMethods()[DestructorMemberSubIndex]; } void SetDestructorMemberSubIndex( int destructorMemberSubIndex ) { this->DestructorMemberSubIndex = destructorMemberSubIndex; } // デリゲート情報を取得 const ::Delegate &GetDelegate() const; // ユーザ指定のアラインメント固定値 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 ///////////////////////////////////////////////////////////////// public: // 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 ); } private: long vtbl_offset; long comVtblOffset; long vtblMasterListOffset; std::vector vtblMasterList; public: void GetVtblMasterListIndexAndVtblIndex( const UserProc *pUserProc, int &vtblMasterListIndex, int &vtblIndex ) const; int GetVtblMasterListIndex( const CClass *pClass ) const; long GetComVtblOffset() const; long GetVtblMasterListOffset() const; void GenerateVTableMasterList( const std::vector &vtableMasterList, long &offset ); void GenerateFullVTables(); void ActionVtblSchedule( LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection, LONG_PTR MemPos_DataSection ); bool IsAbstract() const; // TypeInfo用 mutable int typeInfoDataTableOffset; void SetTypeInfoDataTableOffset( int typeInfoDataTableOffset ) const { this->typeInfoDataTableOffset = typeInfoDataTableOffset; } int GetTypeInfoDataTableOffset() const { return typeInfoDataTableOffset; } // 動的型データ用のメンバデータを取得 std::string GetStaticDefiningStringAsMemberNames() const; std::string GetStaticDefiningStringAsMemberTypeInfoNames() const; //線形リスト用 CClass *pobj_NextClass; }; class Classes : public Jenga::Common::Hashmap { // XMLシリアライズ用 public: Classes() : pCompilingMethod( NULL ) , pStringClass( NULL ) , pObjectClass( NULL ) , pInterfaceInfo( NULL ) { } ~Classes() { } virtual CClass *Create( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const char *name); bool Insert( CClass *pClass, int nowLine ); CClass *Add( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const char *name,int nowLine); virtual void CollectClassesForNameOnly( const BasicSource &source ); // vtblを一時的に生成 void GenerateVTables(); // vtblのを正規のオフセットで再構築 void ActionVtblSchedule(LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection, LONG_PTR MemPos_DataSection ); virtual void InitStaticMember(); private: bool MemberVar_LoopRefCheck(const CClass &objClass); public: virtual void GetClass_recur(const char *lpszInheritsClass); void LookaheadClass( const char *className ); bool LoopRefCheck( const CClass &objClass ); virtual void GetAllClassInfo(); virtual void Compile_System_InitializeUserTypes(); virtual void Compile_System_InitializeUserTypesForBaseType(); 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; mutable const CClass *pInterfaceInfo; const CClass *GetStringClassPtr() const; const CClass *GetObjectClassPtr() const; const CClass *GetInterfaceInfoClassPtr() const; };