Changeset 370 in dev for trunk/abdev/BasicCompiler_Common


Ignore:
Timestamp:
Nov 15, 2007, 3:18:41 AM (16 years ago)
Author:
dai_9181
Message:

COM修飾子に対応。COMインターフェイスを呼び出せるようにした

Location:
trunk/abdev/BasicCompiler_Common
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/abdev/BasicCompiler_Common/VariableOpe.cpp

    r368 r370  
    850850        if( !compiler.StringToType( temporary, type ) ){
    851851            SetError(3,temporary,cp);
    852             type.SetBasicType( DEF_LONG );
     852            return false;
    853853        }
    854854
  • trunk/abdev/BasicCompiler_Common/error.cpp

    r366 r370  
    207207    if(num==133) lstrcpy(msg,"Thisに代入はできません。");
    208208    if(num==134) lstrcpy( msg,"ObjPtr関数にはオブジェクト インスタンス以外を指定できません。" );
    209     if(num==135) lstrcpy( msg, "クラスまたはインターフェイス以外の型を継承元として指定することはできません。" );
     209    if(num==135) lstrcpy( msg, "クラス以外の型を継承元として指定することはできません。" );
    210210    if(num==136) lstrcpy( msg, "非仮想関数に対してオーバーライドしようとしました。" );
    211211    if(num==137) lstrcpy(msg,"ImplementsはClass定義内の先頭に記述する必要があります。");
     
    322322
    323323            i2=0;
     324
     325            if( num == 300 )
     326            {
     327                // 内部エラー
     328                i2=0;
     329            }
    324330        }
    325331
  • trunk/abdev/BasicCompiler_Common/include/Class.h

    r369 r370  
    122122        Class,
    123123        Interface,
     124        ComInterface,
    124125        Enum,
    125126        Delegate,
     
    204205        , vtblNum( 0 )
    205206        , vtbl_offset( -1 )
     207        , comVtblOffset( 0 )
    206208        , isCompilingConstructor( false )
    207209        , isCompilingDestructor( false )
     
    221223        , vtblNum( 0 )
    222224        , vtbl_offset( -1 )
     225        , comVtblOffset( 0 )
    223226        , isCompilingConstructor( false )
    224227        , isCompilingDestructor( false )
     
    339342    bool IsClass() const;
    340343    bool IsInterface() const;
     344    bool IsComInterface() const;
    341345    bool IsEnum() const;
    342346    bool IsDelegate() const;
     
    516520private:
    517521    long vtbl_offset;
     522    long comVtblOffset;
    518523    long vtblMasterListOffset;
    519524    std::vector<long> vtblMasterList;
     
    521526    void GetVtblMasterListIndexAndVtblIndex( const UserProc *pUserProc, int &vtblMasterListIndex, int &vtblIndex ) const;
    522527    int GetVtblMasterListIndex( const CClass *pClass ) const;
     528    long GetComVtblOffset() const;
    523529    long GetVtblMasterListOffset() const;
    524530    void GenerateVTableMasterList( const std::vector<long> &vtableMasterList, long &offset );
  • trunk/abdev/BasicCompiler_Common/include/CodeGenerator.h

    r364 r370  
    374374    void op_ret();
    375375    void op_addressof( int reg, const UserProc *pUserProc );
     376    void op_mov_RV_com_vtbl( int reg, const CClass *pClass );
    376377    void op_mov_RV_vtbl( int reg, const CClass *pClass );
    377378
     
    455456    void op_ret( short stackFrameSize );
    456457    void op_addressof( int reg, const UserProc *pUserProc );
     458    void op_mov_RV_com_vtbl( int reg, const CClass *pClass );
    457459    void op_mov_RV_vtbl( int reg, const CClass *pClass );
    458460#endif
  • trunk/abdev/BasicCompiler_Common/include/NativeCode.h

    r357 r370  
    2424        AddressOf,      // ユーザ定義関数位置スケジュール
    2525        DllProc,        // DLL関数位置スケジュール
     26        ComVtbl,        // com_vtblスケジュール
    2627        Vtbl,           // vtblスケジュール
    2728        TypeInfo,       // TypeInfoスケジュール
     
    5960            ar & boost::serialization::make_nvp("pDllProc", const_cast<::DllProc *&>(pDllProc));
    6061            break;
     62        case ComVtbl:
    6163        case Vtbl:
    6264        case TypeInfo:
     
    9193    {
    9294    }
    93     Schedule( const ::CClass *pClass, long offset )
    94         : type( Schedule::Vtbl )
    95         , offset( offset )
    96         , pClass( pClass )
    97     {
    98     }
    9995    Schedule( Type type, const ::CClass *pClass, long offset )
    10096        : type( type )
     
    10298        , offset( offset )
    10399    {
     100        if( !( type == Schedule::ComVtbl || type == Schedule::Vtbl || type == Schedule::TypeInfo ) )
     101        {
     102            DebugBreak();
     103        }
    104104    }
    105105    ~Schedule()
     
    137137    const ::CClass &GetClass() const
    138138    {
    139         if( !( type == Schedule::Vtbl || type == Schedule::TypeInfo ) )
     139        if( !( type == Schedule::ComVtbl || type == Schedule::Vtbl || type == Schedule::TypeInfo ) )
    140140        {
    141141            SetError();
     
    293293    void PutCatchAddressSchedule( const UserProc *pUserProc, long codePos );
    294294    void PutDllProcSchedule( const DllProc *pDllProc );
     295    void PutComVtblSchedule( const CClass *pClass );
    295296    void PutVtblSchedule( const CClass *pClass );
    296297
  • trunk/abdev/BasicCompiler_Common/include/Type.h

    r350 r370  
    190190    bool IsDelegate() const;
    191191    bool IsInterface() const;
     192    bool IsComInterface() const;
    192193
    193194    // オブジェクトや構造体など、メンバを持つ型かどうかを判別する
  • trunk/abdev/BasicCompiler_Common/src/Class.cpp

    r369 r370  
    116116    return classType == CClass::Interface;
    117117}
     118bool CClass::IsComInterface() const
     119{
     120    return classType == CClass::ComInterface;
     121}
    118122bool CClass::IsEnum() const
    119123{
     
    241245        }
    242246
    243         if( pInheritsClass->IsInterface() ){
    244             // インターフェイスはあとで継承する
    245         }
    246         else if( pInheritsClass->IsClass() ){
     247        if( pInheritsClass->IsClass() ){
    247248            // クラスを継承する
    248249            isInheritsClass = true;
     
    253254        }
    254255        else{
    255             SmoothieException::Throw(135,NULL,nowLine);
     256            SetError(135,pInheritsClass->GetFullName().c_str(),nowLine);
    256257            return false;
    257258        }
     
    268269            return false;
    269270        }
    270     }
    271 
    272     i=0;
    273     while( true ){
    274 
    275         char temporary[VN_SIZE];
    276         for( int i2=0;; i++, i2++ ){
    277             if( inheritNames[i] == '\0' || inheritNames[i] == ',' ){
    278                 temporary[i2] = 0;
    279                 break;
    280             }
    281             temporary[i2] = inheritNames[i];
    282         }
    283 
    284         char className[VN_SIZE];
    285         Jenga::Common::Strings typeParameters;
    286         SplitGenericClassInstance( temporary, className, typeParameters );
    287 
    288         //継承元クラスを取得
    289         const CClass *pInheritsClass = compiler.GetObjectModule().meta.GetClasses().Find(className);
    290         if( !pInheritsClass ){
    291             SmoothieException::Throw(106,className,nowLine);
    292             return false;
    293         }
    294 
    295         if( pInheritsClass->IsInterface() ){
    296             // インターフェイスを継承する
    297             if( !InheritsInterface( *pInheritsClass, nowLine ) ){
    298                 return false;
    299             }
    300         }
    301         else if( pInheritsClass->IsClass() ){
    302             // クラスはさっき継承した
    303         }
    304         else{
    305             SmoothieException::Throw(135,NULL,nowLine);
    306             return false;
    307         }
    308 
    309         if( inheritNames[i] == '\0' ){
    310             break;
    311         }
    312         i++;
    313271    }
    314272
     
    388346    }
    389347
     348    if( this->IsInterface() && inheritsClass.IsComInterface() )
     349    {
     350        // COMインターフェイスを継承した場合はCOMインターフェイスにする
     351        this->SetClassType( CClass::ComInterface );
     352    }
     353
    390354    return true;
    391355}
    392 bool CClass::InheritsInterface( const CClass &inheritsInterface, int nowLine ){
    393 
    394     //ループ継承でないかをチェック
    395     if(pobj_LoopRefCheck->check(inheritsInterface)){
    396         SmoothieException::Throw(123,inheritsInterface.GetName(),nowLine);
    397         return false;
    398     }
    399 
    400     if( !inheritsInterface.IsReady() ){
    401         //継承先が読み取られていないとき
    402         pobj_LoopRefCheck->add(this->GetName().c_str());
    403         compiler.GetObjectModule().meta.GetClasses().GetClass_recur(inheritsInterface.GetName().c_str());
    404         pobj_LoopRefCheck->del(this->GetName().c_str());
    405     }
    406 
    407     //メソッドをコピー
    408     BOOST_FOREACH( const CMethod *pBaseMethod, inheritsInterface.GetDynamicMethods() ){
    409         CMethod *pMethod = new DynamicMethod( *pBaseMethod );
    410 
    411         // アクセシビリティ
    412         if(pBaseMethod->GetAccessibility() == Prototype::Private){
    413             pMethod->SetAccessibility( Prototype::None );
    414         }
    415         else{
    416             pMethod->SetAccessibility( pBaseMethod->GetAccessibility() );
    417         }
    418 
    419         //pobj_Inherits
    420         // ※継承元のClassIndexをセット(入れ子継承を考慮する)
    421         if(pBaseMethod->GetInheritsClassPtr()==0){
    422             pMethod->SetInheritsClassPtr( &inheritsInterface );
    423         }
    424         else{
    425             pMethod->SetInheritsClassPtr( pBaseMethod->GetInheritsClassPtr() );
    426         }
    427 
    428         GetDynamicMethods().push_back( pMethod );
    429     }
    430 
    431     //interfaces.push_back( Interface( &inheritsInterface, vtblNum ) );
    432 
    433     //仮想関数の数
    434     AddVtblNum( inheritsInterface.GetVtblNum() );
    435 
    436     return true;
    437 }
    438356
    439357bool CClass::Implements( const CClass &interfaceClass, int nowLine )
    440358{
    441     if( !interfaceClass.IsInterface() )
     359    if( !interfaceClass.IsInterface() && !interfaceClass.IsComInterface() )
    442360    {
    443361        // インターフェイスではないとき
     
    477395    // キャストメソッドを追加(内部コードは自動生成すること)
    478396    /////////////////////////////////////////////////////////////////
     397    if( interfaceClass.IsInterface() )
    479398    {
    480399        // Function Operator() As ITest
     
    793712    int i2;
    794713
    795     //仮想関数が存在する場合は関数リストへのポインタのサイズを追加
    796     int offset = IsExistVirtualFunctions() ? PTR_SIZE : 0;
     714    //仮想関数が存在する場合はvtbl及びvtblMasterListへのポインタのサイズを追加
     715    int offset = IsExistVirtualFunctions() ? PTR_SIZE*2 : 0;
    797716
    798717    int alignment = 1;
     
    944863    return 0;
    945864}
     865long CClass::GetComVtblOffset() const
     866{
     867    return comVtblOffset;
     868}
    946869long CClass::GetVtblMasterListOffset() const
    947870{
     
    992915
    993916        pInterface->SetVtblOffset( tempVtblOffset );
     917
     918        if( pInterface->GetClass().IsComInterface() )
     919        {
     920            if( this->comVtblOffset )
     921            {
     922                SetError();
     923            }
     924            this->comVtblOffset = tempVtblOffset;
     925        }
    994926    }
    995927
     
    14451377            pobj_c->SetConstructorMemberSubIndex( -1 );
    14461378            pobj_c->SetDestructorMemberSubIndex( -1 );
     1379
     1380            if( memcmp( basbuf+i+1, "__COM", 5 ) == 0 && IsCommandDelimitation( basbuf[i+1+5] ) )
     1381            {
     1382                // COMインターフェイス
     1383                pobj_c->SetClassType( CClass::ComInterface );
     1384
     1385                i += 6;
     1386            }
    14471387
    14481388            if(basbuf[i+1]==1&&basbuf[i+2]==ESC_INHERITS){
  • trunk/abdev/BasicCompiler_Common/src/Compiler.cpp

    r318 r370  
    3636        if( !pGenericClass )
    3737        {
    38             extern int cp;
    39             SetError(106, className, cp );
    4038            return false;
    4139        }
  • trunk/abdev/BasicCompiler_Common/src/DataTable.cpp

    r355 r370  
    8484    this->lastMadeConstObjectDataTableOffset = dataTableOffset;
    8585
     86    // com_vtblスケジュール
     87    this->schedules.push_back( Schedule( Schedule::ComVtbl, &objClass, dataTableOffset ) );
     88
    8689    // vtblスケジュール
    87     this->schedules.push_back( Schedule( &objClass, dataTableOffset ) );
     90    this->schedules.push_back( Schedule( Schedule::Vtbl, &objClass, dataTableOffset + PTR_SIZE ) );
    8891
    8992    // TypeInfoスケジュール
     
    235238
    236239    // スケジューリング
    237     this->schedules.push_back( Schedule( &strClass, headOffset ) );
     240    this->schedules.push_back( Schedule( Schedule::ComVtbl, &strClass, headOffset ) );
     241    this->schedules.push_back( Schedule( Schedule::Vtbl, &strClass, headOffset + PTR_SIZE ) );
    238242    this->schedules.push_back( Schedule( Schedule::TypeInfo, &strClass, headOffset + offsetForTypeInfo ) );
    239243    this->schedules.push_back( Schedule( Schedule::DataTable, headOffset + offsetForChars ) );
  • trunk/abdev/BasicCompiler_Common/src/Linker.cpp

    r361 r370  
    165165    BOOST_FOREACH( const Schedule &schedule, nativeCode.GetSchedules() )
    166166    {
     167        if( schedule.GetType() == Schedule::ComVtbl )
     168        {
     169            LONG_PTR vtblOffset = schedule.GetClass().GetComVtblOffset();
     170
     171            nativeCode.Overwrite(
     172                schedule.GetOffset(),
     173                static_cast<long>( vtblOffset + imageBase + dataSectionBaseOffset )
     174            );
     175        }
     176
    167177        if( schedule.GetType() == Schedule::Vtbl )
    168178        {
     
    178188    BOOST_FOREACH( const Schedule &schedule, dataTable.schedules )
    179189    {
     190        if( schedule.GetType() == Schedule::ComVtbl )
     191        {
     192            LONG_PTR vtblOffset = schedule.GetClass().GetComVtblOffset();
     193
     194#ifdef _WIN64
     195            dataTable.OverwriteInt64(
     196                schedule.GetOffset(),
     197                vtblOffset + imageBase + dataSectionBaseOffset
     198            );
     199#else
     200            dataTable.Overwrite(
     201                schedule.GetOffset(),
     202                vtblOffset + imageBase + dataSectionBaseOffset
     203            );
     204#endif
     205        }
     206
    180207        if( schedule.GetType() == Schedule::Vtbl )
    181208        {
  • trunk/abdev/BasicCompiler_Common/src/Method.cpp

    r353 r370  
    155155            if( !pMethod->GetUserProc().IsUsing() )
    156156            {
    157                 ts((char *)pMethod->GetUserProc().GetFullName().c_str());
     157                //ts((char *)pMethod->GetUserProc().GetFullName().c_str());
    158158            }
    159159            pMethod->GetUserProc().Using();
  • trunk/abdev/BasicCompiler_Common/src/NativeCode.cpp

    r364 r370  
    9595}
    9696
     97void NativeCode::PutComVtblSchedule( const CClass *pClass )
     98{
     99    schedules.push_back( Schedule( Schedule::ComVtbl, pClass, GetSize() ) );
     100
     101    Put( (long)0 );
     102}
     103
    97104void NativeCode::PutVtblSchedule( const CClass *pClass )
    98105{
    99     schedules.push_back( Schedule( pClass, GetSize() ) );
     106    schedules.push_back( Schedule( Schedule::Vtbl, pClass, GetSize() ) );
    100107
    101108    Put( (long)0 );
  • trunk/abdev/BasicCompiler_Common/src/Type.cpp

    r350 r370  
    452452{
    453453    return ( IsObject() && GetClass().IsInterface() );
     454}
     455bool Type::IsComInterface() const
     456{
     457    return ( IsObject() && GetClass().IsComInterface() );
    454458}
    455459
Note: See TracChangeset for help on using the changeset viewer.