Ignore:
Timestamp:
Jul 12, 2007, 2:58:26 AM (17 years ago)
Author:
dai_9181
Message:

コード全体のリファクタリングを実施

File:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/abdev/BasicCompiler_Common/include/Procedure.h

    r201 r206  
    11#pragma once
    22
    3 #include <jenga/include/smoothie/Procedure.h>
    4 
    5 
    6 class UserProcImpl : public UserProc
     3#include <jenga/include/common/Hashmap.h>
     4#include <jenga/include/smoothie/Source.h>
     5#include <jenga/include/smoothie/LexicalAnalysis.h>
     6
     7#include <option.h>
     8#include <Program.h>
     9#include <Class.h>
     10#include <Method.h>
     11#include <Procedure.h>
     12#include <Parameter.h>
     13#include <Variable.h>
     14
     15class CClass;
     16class CMethod;
     17
     18class Procedure
    719{
    820public:
    9     UserProcImpl( const string &name, Kind kind, bool isMacro, bool isCdecl, bool isExport )
    10         : UserProc( name, kind, isMacro, isCdecl, isExport )
    11     {
    12     }
    13     virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine, bool isStatic );
     21    // 種類
     22    enum Kind{
     23        Sub,
     24        Function,
     25    };
     26
     27private:
     28    string name;                        // プロシージャ名
     29
     30    Kind kind;
     31
     32    bool isCdecl;
     33    mutable bool isUsing;
     34
     35protected:
     36
     37    // パラメータ
     38    Parameters params;
     39
     40    // 戻り値の型
     41    Type returnType;
     42
     43    // ソースコードの位置
     44    int codePos;
     45
     46    // XMLシリアライズ用
     47private:
     48private:
     49    friend class boost::serialization::access;
     50    BOOST_SERIALIZATION_SPLIT_MEMBER();
     51    template<class Archive> void load(Archive& ar, const unsigned int version)
     52    {
     53        trace_for_serialize( "serializing - Procedure" );
     54
     55        std::string _name;
     56        ar & BOOST_SERIALIZATION_NVP( _name );
     57        this->name = Operator_NaturalStringToCalcMarkString( _name );
     58
     59        ar & BOOST_SERIALIZATION_NVP( kind );
     60        ar & BOOST_SERIALIZATION_NVP( isCdecl );
     61        ar & BOOST_SERIALIZATION_NVP( isUsing );
     62        ar & BOOST_SERIALIZATION_NVP( params );
     63        ar & BOOST_SERIALIZATION_NVP( returnType );
     64        ar & BOOST_SERIALIZATION_NVP( codePos );
     65    }
     66    template<class Archive> void save(Archive& ar, const unsigned int version) const
     67    {
     68        trace_for_serialize( "serializing - Procedure" );
     69
     70        std::string _name = Operator_CalcMarkStringToNaturalString( name );
     71        ar & BOOST_SERIALIZATION_NVP( _name );
     72
     73        ar & BOOST_SERIALIZATION_NVP( kind );
     74        ar & BOOST_SERIALIZATION_NVP( isCdecl );
     75        ar & BOOST_SERIALIZATION_NVP( isUsing );
     76        ar & BOOST_SERIALIZATION_NVP( params );
     77        ar & BOOST_SERIALIZATION_NVP( returnType );
     78        ar & BOOST_SERIALIZATION_NVP( codePos );
     79    }
     80
     81public:
     82    Procedure( const string &name, Kind kind, bool isCdecl )
     83        : name( name )
     84        , kind( kind )
     85        , isCdecl( isCdecl )
     86        , isUsing( false )
     87        , codePos( -1 )
     88    {
     89    }
     90    Procedure()
     91    {
     92    }
     93    ~Procedure(){
     94        BOOST_FOREACH( Parameter *pParam, params ){
     95            delete pParam;
     96        }
     97    }
     98
     99    const string &GetName() const
     100    {
     101        return name;
     102    }
     103
     104    bool IsSub() const
     105    {
     106        return ( kind == Sub );
     107    }
     108    bool IsFunction() const
     109    {
     110        return ( kind == Function );
     111    }
     112
     113    bool IsCdecl() const
     114    {
     115        return isCdecl;
     116    }
     117    void Using() const
     118    {
     119        isUsing = true;
     120    }
     121    bool IsUsing() const
     122    {
     123        return isUsing;
     124    }
     125
     126    int GetCodePos() const
     127    {
     128        return codePos;
     129    }
     130
     131    const Parameters &Params() const
     132    {
     133        return params;
     134    }
     135    const Type &ReturnType() const
     136    {
     137        return returnType;
     138    }
    14139};
    15140
    16 class GlobalProc : public UserProcImpl
     141class UserProc : public Procedure, public Jenga::Common::ObjectInHashmap<UserProc>
    17142{
    18     const NamespaceScopes namespaceScopes;
    19     const NamespaceScopesCollection importedNamespaces;
     143public:
     144    string _paramStr;
     145
     146private:
     147    NamespaceScopes namespaceScopes;
     148    NamespaceScopesCollection importedNamespaces;
     149
     150    // 親クラスと対応するメソッド
     151    const CClass *pParentClass;
     152    CMethod *pMethod;
     153
     154    bool isMacro;
     155
     156    // パラメータの追加情報
     157    int secondParmNum;
     158    Parameters realParams;
     159    int realSecondParmNum;
     160
     161    // 各種フラグ
     162    bool isExport;
     163    mutable bool isSystem;
     164    mutable bool isAutoGeneration;
     165    mutable bool isCompiled;
     166
     167    mutable DWORD beginOpAddress;
     168    mutable DWORD endOpAddress;
     169
     170    // ローカル変数
     171    mutable Variables localVars;
     172
     173    // 識別ID
     174    int id;
     175
     176    // XMLシリアライズ用
     177private:
     178    friend class boost::serialization::access;
     179    template<class Archive> void serialize(Archive& ar, const unsigned int version)
     180    {
     181        trace_for_serialize( "serializing - UserProc" );
     182
     183        ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Procedure );
     184        ar & BOOST_SERIALIZATION_NVP( _paramStr );
     185        ar & BOOST_SERIALIZATION_NVP( namespaceScopes );
     186        ar & BOOST_SERIALIZATION_NVP( importedNamespaces );
     187        ar & boost::serialization::make_nvp("pParentClass", const_cast<CClass *&>(pParentClass) );
     188        ar & BOOST_SERIALIZATION_NVP( pMethod );
     189        ar & BOOST_SERIALIZATION_NVP( isMacro );
     190        ar & BOOST_SERIALIZATION_NVP( secondParmNum );
     191        ar & BOOST_SERIALIZATION_NVP( realParams );
     192        ar & BOOST_SERIALIZATION_NVP( realSecondParmNum );
     193        ar & BOOST_SERIALIZATION_NVP( isExport );
     194        ar & BOOST_SERIALIZATION_NVP( isSystem );
     195        ar & BOOST_SERIALIZATION_NVP( isAutoGeneration );
     196        ar & BOOST_SERIALIZATION_NVP( isCompiled );
     197        ar & BOOST_SERIALIZATION_NVP( beginOpAddress );
     198        ar & BOOST_SERIALIZATION_NVP( endOpAddress );
     199        ar & BOOST_SERIALIZATION_NVP( localVars );
     200        ar & BOOST_SERIALIZATION_NVP( id );
     201    }
     202
     203public:
     204
     205    UserProc( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const string &name, Kind kind, bool isMacro, bool isCdecl, bool isExport, int id )
     206        : Procedure( name, kind, isCdecl )
     207        , namespaceScopes( namespaceScopes )
     208        , importedNamespaces( importedNamespaces )
     209        , pParentClass( NULL )
     210        , pMethod( NULL )
     211        , isMacro( isMacro )
     212        , isExport( isExport )
     213        , isSystem( false )
     214        , isAutoGeneration( false )
     215        , isCompiled( false )
     216        , beginOpAddress( 0 )
     217        , endOpAddress( 0 )
     218        , id( id )
     219    {
     220    }
     221    UserProc()
     222    {
     223    }
     224    ~UserProc()
     225    {
     226        BOOST_FOREACH( Parameter *pParam, realParams ){
     227            delete pParam;
     228        }
     229    }
     230
     231    virtual const std::string &GetKeyName() const
     232    {
     233        return GetName();
     234    }
     235
     236    bool IsMacro() const
     237    {
     238        return isMacro;
     239    }
     240
     241    int GetSecondParmNum() const
     242    {
     243        return secondParmNum;
     244    }
     245    const Parameters &RealParams() const
     246    {
     247        return realParams;
     248    }
     249    int GetRealSecondParmNum() const
     250    {
     251        return realSecondParmNum;
     252    }
     253
     254    void ExportOff(){
     255        isExport = false;
     256    }
     257    bool IsExport() const
     258    {
     259        return isExport;
     260    }
     261    void ThisIsSystemProc() const
     262    {
     263        isSystem = true;
     264    }
     265    bool IsSystem() const
     266    {
     267        return isSystem;
     268    }
     269    void ThisIsAutoGenerationProc() const
     270    {
     271        isAutoGeneration = true;
     272    }
     273    bool IsAutoGeneration() const
     274    {
     275        return isAutoGeneration;
     276    }
     277    void CompleteCompile() const
     278    {
     279        isCompiled = true;
     280    }
     281    void KillCompileStatus() const
     282    {
     283        isCompiled = false;
     284    }
     285    bool IsCompiled() const
     286    {
     287        return isCompiled;
     288    }
     289    bool IsDestructor() const
     290    {
     291        return ( GetName()[0] == '~' );
     292    }
     293
     294    // バイナリコード位置とサイズ
     295    DWORD GetBeginOpAddress() const
     296    {
     297        return beginOpAddress;
     298    }
     299    void SetBeginOpAddress( DWORD beginOpAddress ) const
     300    {
     301        this->beginOpAddress = beginOpAddress;
     302    }
     303    DWORD GetEndOpAddress() const
     304    {
     305        return endOpAddress;
     306    }
     307    void SetEndOpAddress( DWORD endOpAddress ) const
     308    {
     309        this->endOpAddress = endOpAddress;
     310    }
     311    int GetCodeSize() const
     312    {
     313        return endOpAddress - beginOpAddress;
     314    }
     315
     316    const NamespaceScopes &GetNamespaceScopes() const;
     317    const NamespaceScopesCollection &GetImportedNamespaces() const;
     318
     319    Variables &GetLocalVars() const
     320    {
     321        return localVars;
     322    }
     323
     324    int GetId() const
     325    {
     326        return id;
     327    }
     328
     329    std::string GetFullName() const;
     330
     331    virtual bool IsDuplication( const UserProc *pUserProc ) const
     332    {
     333        if( this->GetParentClassPtr() == pUserProc->GetParentClassPtr()
     334            && pUserProc->IsEqualSymbol( *this )
     335            && this->Params().Equals( pUserProc->Params() ) )
     336        {
     337            return true;
     338        }
     339        return false;
     340    }
     341
     342    bool IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const;
     343    bool IsEqualSymbol( const UserProc &globalProc ) const;
     344    bool IsEqualSymbol( const string &name ) const;
     345
     346    bool IsVirtual() const;
     347
     348    void SetParentClass( const CClass *pParentClass ){
     349        this->pParentClass = pParentClass;
     350    }
     351    const CClass *GetParentClassPtr() const
     352    {
     353        return pParentClass;
     354    }
     355    const CClass &GetParentClass() const
     356    {
     357        return *pParentClass;
     358    }
     359    bool HasParentClass() const
     360    {
     361        return ( pParentClass != NULL );
     362    }
     363    void SetMethod( CMethod *pMethod ){
     364        this->pMethod = pMethod;
     365    }
     366
     367    bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine, bool isStatic );
     368
     369
     370
     371    /////////////////////////////////////////////////////////////////
     372    // コンパイル中の関数を管理
     373    /////////////////////////////////////////////////////////////////
     374private:
     375    static const UserProc *pCompilingUserProc;
     376public:
     377    static void CompileStartForGlobalArea(){
     378        pCompilingUserProc = NULL;
     379    }
     380    static void CompileStartForUserProc( const UserProc *pUserProc ){
     381        pCompilingUserProc = pUserProc;
     382    }
     383    static bool IsGlobalAreaCompiling(){
     384        return ( pCompilingUserProc == NULL );
     385    }
     386    static bool IsLocalAreaCompiling(){
     387        return ( pCompilingUserProc != NULL );
     388    }
     389    static const UserProc &CompilingUserProc(){
     390        return *pCompilingUserProc;
     391    }
     392};
     393
     394class UserProcs : public Jenga::Common::Hashmap<UserProc>
     395{
     396    std::vector<std::string> macroNames;
     397
     398    // XMLシリアライズ用
     399private:
     400    friend class boost::serialization::access;
     401    template<class Archive> void serialize(Archive& ar, const unsigned int version)
     402    {
     403        trace_for_serialize( "serializing - UserProcs" );
     404
     405        ar & boost::serialization::make_nvp("Hashmap_UserProcImpl",
     406            boost::serialization::base_object<Jenga::Common::Hashmap<UserProc>>(*this));
     407        ar & BOOST_SERIALIZATION_NVP( macroNames );
     408    }
     409
     410
     411public:
     412    UserProcs()
     413    {
     414    }
     415    ~UserProcs()
     416    {
     417    }
     418
     419    bool Insert( UserProc *pUserProc, int nowLine );
     420
     421    UserProc *Add( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, char *buffer,int nowLine,bool isVirtual,CClass *pobj_c, bool isStatic);
     422
     423    void EnumGlobalProcs( const char *simpleName, const char *localName, std::vector<const UserProc *> &subs );
     424
     425    static void CollectUserProcs( const BasicSource &source, UserProcs &userProcs );
     426};
     427
     428class DllProc : public Procedure
     429{
     430    NamespaceScopes namespaceScopes;
     431
     432    string dllFileName;
     433    string alias;
     434    int lookupAddress;
     435
     436    // XMLシリアライズ用
     437private:
     438    friend class boost::serialization::access;
     439    template<class Archive> void serialize(Archive& ar, const unsigned int version)
     440    {
     441        trace_for_serialize( "serializing - DllProc" );
     442
     443        ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Procedure );
     444        ar & BOOST_SERIALIZATION_NVP( namespaceScopes );
     445        ar & BOOST_SERIALIZATION_NVP( dllFileName );
     446        ar & BOOST_SERIALIZATION_NVP( alias );
     447        ar & BOOST_SERIALIZATION_NVP( lookupAddress );
     448    }
     449
    20450public:
    21451    // ハッシュリスト用
    22     GlobalProc *pNextData;
    23 
    24     GlobalProc( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const string &name, Kind kind, bool isMacro, bool isCdecl, bool isExport ):
    25       UserProcImpl( name, kind, isMacro, isCdecl, isExport ),
     452    DllProc *pNextData;
     453
     454    DllProc( const NamespaceScopes &namespaceScopes, const string &name, Kind kind, bool isCdecl, const string &dllFileName, const string &alias ):
     455      Procedure( name, kind, isCdecl ),
    26456      namespaceScopes( namespaceScopes ),
    27       importedNamespaces( importedNamespaces ),
     457      dllFileName( dllFileName ),
     458      alias( alias ),
     459      lookupAddress( 0 ),
    28460      pNextData( NULL )
    29     {}
    30     ~GlobalProc(){}
    31 
    32     virtual const NamespaceScopes &GetNamespaceScopes() const;
    33     virtual const NamespaceScopesCollection &GetImportedNamespaces() const
    34     {
    35         return importedNamespaces;
    36     }
     461    {
     462    }
     463    ~DllProc(){}
    37464
    38465    virtual bool IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const;
    39     virtual bool IsEqualSymbol( const GlobalProc &globalProc ) const;
    40     virtual bool IsEqualSymbol( const string &name ) const;
     466    bool IsEqualSymbol( const string &name ) const;
     467
     468    const NamespaceScopes &GetNamespaceScopes() const
     469    {
     470        return namespaceScopes;
     471    }
     472
     473    const string &GetDllFileName() const
     474    {
     475        return dllFileName;
     476    }
     477    const string &GetAlias() const
     478    {
     479        return alias;
     480    }
     481
     482    void SetLookupAddress( int lookupAddress ){
     483        this->lookupAddress = lookupAddress;
     484    }
     485    int GetLookupAddress() const
     486    {
     487        return lookupAddress;
     488    }
     489
     490    bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine );
    41491};
    42492
    43 class DllProcImpl : public DllProc
     493class ProcPointer : public Procedure
    44494{
    45 public:
    46     DllProcImpl( const NamespaceScopes &namespaceScopes, const string &name, Kind kind, bool isCdecl, const string &dllFileName, const string &alias )
    47         : DllProc( namespaceScopes, name, kind, isCdecl, dllFileName, alias )
    48     {
    49     }
    50 
    51     virtual bool IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const;
     495    // XMLシリアライズ用
     496private:
     497    friend class boost::serialization::access;
     498    template<class Archive> void serialize(Archive& ar, const unsigned int version)
     499    {
     500        trace_for_serialize( "serializing - ProcPointer" );
     501
     502        ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Procedure );
     503    }
     504
     505public:
     506    ProcPointer( Kind kind )
     507        : Procedure( "", kind, false )
     508    {
     509    }
     510    ProcPointer()
     511    {
     512    }
     513    ~ProcPointer(){}
    52514
    53515    virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine );
    54516};
    55517
    56 class ProcPointerImpl : public ProcPointer
     518class ProcPointers : public vector<ProcPointer *>
    57519{
    58 public:
    59     ProcPointerImpl( Kind kind ):
    60       ProcPointer( kind )
    61     {
    62     }
    63 
    64     virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine );
    65 };
    66 
    67 class ProcPointersImpl : public ProcPointers
    68 {
    69 public:
    70     ProcPointersImpl()
    71     {
    72     }
    73     ~ProcPointersImpl()
     520    // XMLシリアライズ用
     521private:
     522    friend class boost::serialization::access;
     523    template<class Archive> void serialize(Archive& ar, const unsigned int version)
     524    {
     525        trace_for_serialize( "serializing - ProcPointers" );
     526
     527        ar & boost::serialization::make_nvp("vector_ProcPointer",
     528            boost::serialization::base_object<vector<ProcPointer *>>(*this));
     529    }
     530
     531public:
     532    ProcPointers()
     533    {
     534    }
     535    ~ProcPointers()
    74536    {
    75537        Clear();
Note: See TracChangeset for help on using the changeset viewer.