Changeset 559 in dev for trunk


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

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

Location:
trunk/ab5.0/abdev
Files:
2 added
7 edited

Legend:

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

    r558 r559  
    437437    long comVtblOffset;
    438438    long vtblMasterListOffset;
     439public:
    439440    std::vector<long> vtblMasterList;
    440 public:
     441    LONG_PTR GetVtblOffset() const
     442    {
     443        return vtbl_offset;
     444    }
     445    void SetVtblOffset( int vtblOffset )
     446    {
     447        this->vtbl_offset = vtblOffset;
     448    }
     449    long GetComVtblOffset() const
     450    {
     451        return comVtblOffset;
     452    }
     453    void SetComVtblOffset( int comVtblOffset )
     454    {
     455        this->comVtblOffset = comVtblOffset;
     456    }
    441457    void GetVtblMasterListIndexAndVtblIndex( const UserProc *pUserProc, int &vtblMasterListIndex, int &vtblIndex ) const;
    442458    int GetVtblMasterListIndex( const CClass *pClass ) const;
    443     long GetComVtblOffset() const;
    444459    long GetVtblMasterListOffset() const;
    445     void GenerateVTableMasterList( const std::vector<long> &vtableMasterList, long &offset );
    446     void GenerateFullVTables();
    447     void ActionVtblSchedule( LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection, LONG_PTR MemPos_DataSection );
     460    void SetVtblMasterListOffset( int vtblMasterListOffset )
     461    {
     462        this->vtblMasterListOffset = vtblMasterListOffset;
     463    }
    448464    bool IsAbstract() const;
    449465
     
    484500    bool Insert( CClass *pClass, int nowLine );
    485501    CClass *Add( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const char *name,int nowLine);
    486 
    487     // vtblを一時的に生成
    488     void GenerateVTables();
    489 
    490     // vtblのを正規のオフセットで再構築
    491     void ActionVtblSchedule(LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection, LONG_PTR MemPos_DataSection );
    492502
    493503    virtual void InitStaticMember();
  • trunk/ab5.0/abdev/BasicCompiler_Common/include/Method.h

    r558 r559  
    273273    // 仮想メソッドの個数を取得
    274274    int GetVtblNum() const;
    275 
    276     // vtblを生成
    277     void GenerateVTablePart( long &vtableDataTableOffset ) const;
    278 };
     275};
  • 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
  • trunk/ab5.0/abdev/BasicCompiler_Common/src/Method.cpp

    r558 r559  
    3636{
    3737    // 静的メソッドがコピーコンストラトされることは想定しない
    38     compiler.errorMessenger.OutputFatalError();
     38    throw;
    3939}
    4040
     
    144144    return count;
    145145}
    146 
    147 void Methods::GenerateVTablePart( long &vtableDataTableOffset ) const
    148 {
    149     const UserProc **ppsi = (const UserProc **)malloc(GetVtblNum()*sizeof(UserProc *));
    150 
    151     //関数テーブルに値をセット
    152     int i2 = 0;
    153     const Methods &methods = *this;
    154     BOOST_FOREACH( const CMethod *pMethod, methods ){
    155         if(pMethod->IsVirtual()){
    156             if( !pMethod->GetUserProc().IsUsing() )
    157             {
    158                 //ts((char *)pMethod->GetUserProc().GetFullName().c_str());
    159             }
    160             pMethod->GetUserProc().Using();
    161 
    162             if(pMethod->IsAbstract()){
    163                 compiler.errorMessenger.OutputFatalError();
    164 
    165                 ppsi[i2]=0;
    166             }
    167             else{
    168                 ppsi[i2]=&pMethod->GetUserProc();
    169             }
    170             i2++;
    171         }
    172     }
    173 
    174     vtableDataTableOffset = compiler.GetObjectModule().dataTable.AddBinary( (void *)ppsi, GetVtblNum()*sizeof(LONG_PTR) );
    175 
    176     for( int i=0; i < GetVtblNum(); i++ ){
    177         pobj_Reloc->AddSchedule_DataSection(static_cast<DWORD>(vtableDataTableOffset+i*sizeof(LONG_PTR)));
    178     }
    179 
    180     free(ppsi);
    181 }
  • trunk/ab5.0/abdev/compiler_x86/MakePeHdr.cpp

    r552 r559  
    537537    /////////////////////////////////////////////////////////////////
    538538
    539     compiler.GetObjectModule().meta.GetClasses().GenerateVTables();
     539    ActiveBasic::Compiler::VtblGenerator::GenerateVTablesForAllClasses(
     540        compiler.GetObjectModule().meta.GetClasses()
     541    );
    540542
    541543
     
    10891091    ////////////////////////////////////////
    10901092    //仮想関数データテーブルスケジュール
    1091     compiler.GetObjectModule().meta.GetClasses().ActionVtblSchedule( ImageBase, MemPos_CodeSection, MemPos_DataSection );
     1093    ActiveBasic::Compiler::VtblGenerator::ActionVtblScheduleForAllClasses(
     1094        compiler.GetObjectModule().meta.GetClasses(),
     1095        ImageBase,
     1096        MemPos_CodeSection,
     1097        MemPos_DataSection
     1098    );
    10921099
    10931100
  • trunk/ab5.0/abdev/compiler_x86/compiler_x86.vcproj

    r547 r559  
    12881288                    >
    12891289                </File>
     1290                <File
     1291                    RelativePath="..\BasicCompiler_Common\src\VtblGenerator.cpp"
     1292                    >
     1293                </File>
    12901294                <Filter
    12911295                    Name="Langauge Classes"
     
    14811485                    >
    14821486                </File>
     1487                <File
     1488                    RelativePath="..\BasicCompiler_Common\include\VtblGenerator.h"
     1489                    >
     1490                </File>
    14831491                <Filter
    14841492                    Name="Language Classes"
  • trunk/ab5.0/abdev/compiler_x86/stdafx.h

    r548 r559  
    7171#include <Program.h>
    7272#include <LexicalAnalyzer.h>
     73#include <VtblGenerator.h>
Note: See TracChangeset for help on using the changeset viewer.