Ignore:
Timestamp:
May 5, 2008, 12:49:01 PM (16 years ago)
Author:
dai_9181
Message:

ImplementsメソッドをLexicalAnalyzerクラスに移動した。

Location:
trunk/ab5.0/abdev/BasicCompiler_Common
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/ab5.0/abdev/BasicCompiler_Common/include/Class.h

    r559 r560  
    306306        return ( interfaces.size() != 0 );
    307307    }
     308    void AddInterface( ::Interface *pInterface )
     309    {
     310        interfaces.push_back( pInterface );
     311    }
    308312    const Interfaces &GetInterfaces() const
    309313    {
     
    314318    // クラス継承
    315319    bool InheritsClass( const CClass &inheritsClass, const Types &actualTypeParameters, int nowLine );
    316 
    317     // インターフェイス実装
    318     void Implements( const CClass &interfaceClass, const Types &actualTypeParameters, std::vector<DynamicMethod::OverrideResult> &overrideResults );
    319320
    320321    //メンバ、メソッドの追加
  • trunk/ab5.0/abdev/BasicCompiler_Common/include/LexicalAnalyzer.h

    r552 r560  
    4646    static void AddMethod(CClass *pobj_c, UserProc *pUserProc, Prototype::Accessibility accessibility, BOOL bStatic, bool isConst, bool isAbstract,
    4747        bool isVirtual, bool isOverride, const char *interfaceName, bool isAutoGeneration, int nowLine);
    48     static bool Inherits( CClass &currentClass, const char *inheritNames, int nowLine );
    49     static bool Implements( CClass &currentClass, const char *interfaceNames, int nowLine );
     48    static bool Inherits( CClass &_class, const char *inheritNames, int nowLine );
     49    static void Implements( CClass &_class, Interface *pInterface, std::vector<DynamicMethod::OverrideResult> &overrideResults );
     50    static bool Implements( CClass &_class, const char *interfaceNames, int nowLine );
    5051    static void LookaheadClass( const char *className, Classes &classes );
    5152    static bool LoopRefCheck( const CClass &objClass );
  • trunk/ab5.0/abdev/BasicCompiler_Common/src/Class.cpp

    r559 r560  
    183183
    184184    return true;
    185 }
    186 
    187 void CClass::Implements( const CClass &interfaceClass, const Types &actualTypeParameters, std::vector<DynamicMethod::OverrideResult> &overrideResults )
    188 {
    189     ::Interface *pDestInterface = new ::Interface( &interfaceClass, actualTypeParameters );
    190 
    191     interfaces.push_back( pDestInterface );
    192 
    193 
    194     /////////////////////////////////////////////////////////////////
    195     // 基底クラスのメソッドからインターフェイスメソッドを再実装する
    196     /////////////////////////////////////////////////////////////////
    197     BOOST_FOREACH( CMethod *pMethod, GetDynamicMethods() )
    198     {
    199         DynamicMethod *pMethodForOverride = pDestInterface->GetDynamicMethods().FindForOverride( pDestInterface->GetActualTypeParameters(), &pMethod->GetUserProc() );
    200         if( pMethodForOverride )
    201         {
    202             DynamicMethod::OverrideResult result;
    203             result.enumType = pMethodForOverride->Override( &pMethod->GetUserProc(), pMethod->GetAccessibility(), false );
    204             result.pMethod = pMethod;
    205             overrideResults.push_back( result );
    206 
    207             // 実装元になるメソッドは呼び出し不可にしておく(オーバーロードの解決から除外する)
    208             pMethod->SetNotUseMark( true );
    209         }
    210     }
    211 
    212 
    213     /////////////////////////////////////////////////////////////////
    214     // キャストメソッドを追加(内部コードは自動生成すること)
    215     /////////////////////////////////////////////////////////////////
    216     if( interfaceClass.IsInterface() )
    217     {
    218         // Function Operator() As ITest
    219 
    220         char methodName[255] = { 1, ESC_OPERATOR, CALC_AS, '\0' };
    221 
    222         //関数ハッシュへ登録
    223         UserProc *pUserProc = new UserProc(
    224             NamespaceScopes(),
    225             NamespaceScopesCollection(),
    226             methodName,
    227             Procedure::Function,
    228             false,
    229             false,
    230             false );
    231         pUserProc->SetParentClass( this );
    232 
    233         Parameters params;
    234         params.push_back( new Parameter( "_System_LocalThis", Type( DEF_PTR_VOID ) ) );
    235         pUserProc->SetRealParams( params );
    236 
    237         pUserProc->SetReturnType( Type( DEF_OBJECT, interfaceClass ) );
    238         pUserProc->_paramStr = "";
    239         pUserProc->Using();
    240         compiler.GetObjectModule().meta.GetUserProcs().Insert( pUserProc, -1 );
    241 
    242         LexicalAnalyzer::AddMethod(this,
    243             pUserProc,
    244             Prototype::Public,
    245             0,
    246             false,          // isConst
    247             false,          // isAbstract
    248             false,          // isVirtual
    249             false,          // isOverride
    250             "",
    251             true,           // isAutoGeneration
    252             -1
    253         );
    254     }
    255185}
    256186
  • trunk/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_Class.cpp

    r558 r560  
    408408}
    409409
    410 bool LexicalAnalyzer::Inherits( CClass &currentClass, const char *inheritNames, int nowLine ){
     410bool LexicalAnalyzer::Inherits( CClass &_class, const char *inheritNames, int nowLine ){
    411411    int i = 0;
    412412    bool isInheritsClass = false;
     
    462462            }
    463463
    464             if( !currentClass.InheritsClass( *pInheritsClass, actualTypeParameters, nowLine ) ){
     464            if( !_class.InheritsClass( *pInheritsClass, actualTypeParameters, nowLine ) ){
    465465                return false;
    466466            }
     
    495495
    496496        // クラスを一つも継承していないとき
    497         if( !currentClass.InheritsClass( *pObjectClass, Types(), nowLine ) ){
     497        if( !_class.InheritsClass( *pObjectClass, Types(), nowLine ) ){
    498498            return false;
    499499        }
     
    503503}
    504504
    505 bool LexicalAnalyzer::Implements( CClass &currentClass, const char *interfaceNames, int nowLine )
     505void LexicalAnalyzer::Implements( CClass &_class, Interface *pInterface, std::vector<DynamicMethod::OverrideResult> &overrideResults )
     506{
     507    _class.AddInterface( pInterface );
     508
     509
     510    /////////////////////////////////////////////////////////////////
     511    // 基底クラスのメソッドからインターフェイスメソッドを再実装する
     512    /////////////////////////////////////////////////////////////////
     513    BOOST_FOREACH( CMethod *pMethod, _class.GetDynamicMethods() )
     514    {
     515        DynamicMethod *pMethodForOverride = pInterface->GetDynamicMethods().FindForOverride( pInterface->GetActualTypeParameters(), &pMethod->GetUserProc() );
     516        if( pMethodForOverride )
     517        {
     518            DynamicMethod::OverrideResult result;
     519            result.enumType = pMethodForOverride->Override( &pMethod->GetUserProc(), pMethod->GetAccessibility(), false );
     520            result.pMethod = pMethod;
     521            overrideResults.push_back( result );
     522
     523            // 実装元になるメソッドは呼び出し不可にしておく(オーバーロードの解決から除外する)
     524            pMethod->SetNotUseMark( true );
     525        }
     526    }
     527
     528
     529    /////////////////////////////////////////////////////////////////
     530    // キャストメソッドを追加(内部コードは自動生成すること)
     531    // ※COMインターフェイスは除外すること
     532    /////////////////////////////////////////////////////////////////
     533    if( pInterface->GetClass().IsInterface() )
     534    {
     535        // Function Operator() As ITest
     536
     537        char methodName[255] = { 1, ESC_OPERATOR, CALC_AS, '\0' };
     538
     539        //関数ハッシュへ登録
     540        UserProc *pUserProc = new UserProc(
     541            NamespaceScopes(),
     542            NamespaceScopesCollection(),
     543            methodName,
     544            Procedure::Function,
     545            false,
     546            false,
     547            false );
     548        pUserProc->SetParentClass( &_class );
     549
     550        Parameters params;
     551        params.push_back( new Parameter( "_System_LocalThis", Type( DEF_PTR_VOID ) ) );
     552        pUserProc->SetRealParams( params );
     553
     554        pUserProc->SetReturnType( Type( DEF_OBJECT, pInterface->GetClass() ) );
     555        pUserProc->_paramStr = "";
     556        pUserProc->Using();
     557        compiler.GetObjectModule().meta.GetUserProcs().Insert( pUserProc, -1 );
     558
     559        LexicalAnalyzer::AddMethod(
     560            &_class,
     561            pUserProc,
     562            Prototype::Public,
     563            0,
     564            false,          // isConst
     565            false,          // isAbstract
     566            false,          // isVirtual
     567            false,          // isOverride
     568            "",
     569            true,           // isAutoGeneration
     570            -1
     571        );
     572    }
     573}
     574
     575bool LexicalAnalyzer::Implements( CClass &_class, const char *interfaceNames, int nowLine )
    506576{
    507577    Jenga::Common::Strings paramStrs;
     
    541611            // インターフェイスを継承する
    542612            std::vector<DynamicMethod::OverrideResult> overrideResults;
    543             currentClass.Implements( *pInterfaceClass, actualTypeParameters, overrideResults );
     613            Implements(
     614                _class,
     615                new ::Interface( pInterfaceClass, actualTypeParameters ),
     616                overrideResults
     617            );
    544618
    545619            // エラーチェック
Note: See TracChangeset for help on using the changeset viewer.