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

VtblGeneratorクラスを追加。Classes/CClassクラスのvtbl生成関連の実装をVtblGeneratorクラスに移動した。

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ab5.0/abdev/BasicCompiler_Common/src/Class.cpp

    r558 r559  
    724724    return 0;
    725725}
    726 long CClass::GetComVtblOffset() const
    727 {
    728     return comVtblOffset;
    729 }
    730726long CClass::GetVtblMasterListOffset() const
    731727{
     
    737733
    738734    return vtblMasterListOffset;
    739 }
    740 void CClass::GenerateVTableMasterList( const std::vector<long> &vtableMasterList, long &offset )
    741 {
    742     offset = compiler.GetObjectModule().dataTable.AddBinary(
    743         (void *)&vtableMasterList[0],
    744         static_cast<int>(vtableMasterList.size()*sizeof(LONG_PTR))
    745     );
    746 }
    747 void CClass::GenerateFullVTables()
    748 {
    749     if( IsAbstract() )
    750     {
    751         // 抽象クラスは無視
    752         return;
    753     }
    754     if( !IsUsing() )
    755     {
    756         // 使われていないクラスは無視
    757         return;
    758     }
    759 
    760     // vtblマスターリストの元データに不要なデータが含まれていたらエラー
    761     if( vtblMasterList.size() )
    762     {
    763         compiler.errorMessenger.OutputFatalError();
    764     }
    765 
    766     // 自身のクラスのvtblを生成
    767     GetDynamicMethods().GenerateVTablePart( this->vtbl_offset );
    768     vtblMasterList.push_back( this->vtbl_offset );
    769 
    770     // インターフェイスのvtblを生成
    771     BOOST_FOREACH( const ::Interface *pInterface, interfaces )
    772     {
    773         long tempVtblOffset;
    774         pInterface->GetDynamicMethods().GenerateVTablePart( tempVtblOffset );
    775         vtblMasterList.push_back( tempVtblOffset );
    776 
    777         pInterface->SetVtblOffset( tempVtblOffset );
    778 
    779         if( pInterface->GetClass().IsComInterface() )
    780         {
    781             if( this->comVtblOffset )
    782             {
    783                 compiler.errorMessenger.OutputFatalError();
    784             }
    785             this->comVtblOffset = tempVtblOffset;
    786         }
    787     }
    788 
    789     // vtblマスターリストを生成
    790     GenerateVTableMasterList( vtblMasterList, this->vtblMasterListOffset );
    791 }
    792 void CClass::ActionVtblSchedule( LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection, LONG_PTR MemPos_DataSection )
    793 {
    794     if( IsAbstract() )
    795     {
    796         // 抽象クラスは無視
    797         return;
    798     }
    799     if( !IsUsing() )
    800     {
    801         // 使われていないクラスは無視
    802         return;
    803     }
    804     if(vtbl_offset==-1) return;
    805 
    806     // 自身のクラスのvtbl
    807     {
    808         LONG_PTR *pVtbl = (LONG_PTR *)((char *)compiler.GetObjectModule().dataTable.GetPtr() + vtbl_offset);
    809 
    810         for( int i=0; i<GetVtblNum(); i++ ){
    811             const UserProc *pUserProc = (UserProc *)pVtbl[i];
    812             if(!pUserProc) continue;
    813 
    814             if( pUserProc->GetBeginOpAddress() == 0
    815                 && pUserProc->GetEndOpAddress() == 0 )
    816             {
    817                 Jenga::Throw( "未解決の仮想関数が存在する" );
    818             }
    819 
    820             pVtbl[i] = pUserProc->GetBeginOpAddress() + ImageBase + MemPos_CodeSection;
    821         }
    822     }
    823 
    824     // インターフェイスのvtbl
    825     BOOST_FOREACH( const ::Interface *pInterface, interfaces )
    826     {
    827         LONG_PTR *pVtbl = (LONG_PTR *)((char *)compiler.GetObjectModule().dataTable.GetPtr() + pInterface->GetVtblOffset());
    828 
    829         for( int i=0; i<pInterface->GetClass().GetVtblNum(); i++ ){
    830             const UserProc *pUserProc = (UserProc *)pVtbl[i];
    831             if(!pUserProc) continue;
    832 
    833             if( pUserProc->GetBeginOpAddress() == 0
    834                 && pUserProc->GetEndOpAddress() == 0 )
    835             {
    836                 Jenga::Throw( "未解決の仮想関数が存在する" );
    837             }
    838 
    839             pVtbl[i] = pUserProc->GetBeginOpAddress() + ImageBase + MemPos_CodeSection;
    840         }
    841     }
    842 
    843     // vtblマスターリスト
    844     LONG_PTR *pVtblMasterList = (LONG_PTR *)((char *)compiler.GetObjectModule().dataTable.GetPtr() + vtblMasterListOffset );
    845     for( int i=0; i<static_cast<int>(vtblMasterList.size()); i++ )
    846     {
    847         pVtblMasterList[i] = vtblMasterList[i] + ImageBase + MemPos_DataSection;
    848     }
    849735}
    850736bool CClass::IsAbstract() const
     
    905791
    906792    return pClass; 
    907 }
    908 
    909 void Classes::GenerateVTables()
    910 {
    911     Iterator_Reset();
    912     while( Iterator_HasNext() )
    913     {
    914         CClass *pClass = Iterator_GetNext();
    915         pClass->GenerateFullVTables();
    916     }
    917 }
    918 
    919 void Classes::ActionVtblSchedule( LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection, LONG_PTR MemPos_DataSection ){
    920     Iterator_Reset();
    921     while( Iterator_HasNext() )
    922     {
    923         CClass *pClass = Iterator_GetNext();
    924         pClass->ActionVtblSchedule( ImageBase, MemPos_CodeSection, MemPos_DataSection);
    925     }
    926793}
    927794
Note: See TracChangeset for help on using the changeset viewer.