Changeset 51 in dev for BasicCompiler_Common/Class.cpp


Ignore:
Timestamp:
Feb 10, 2007, 8:30:19 PM (17 years ago)
Author:
dai_9181
Message:

ppobj_Member及びppobj_StaticMemberを廃止し、vectorに統一した(methods及びstaticMethods)。

File:
1 edited

Legend:

Unmodified
Added
Removed
  • BasicCompiler_Common/Class.cpp

    r50 r51  
    207207    }
    208208
    209     if(ppobj_Method){
    210         //メソッド
    211         for(i=0;i<iMethodNum;i++){
    212             delete ppobj_Method[i];
    213         }
    214         HeapDefaultFree(ppobj_Method);
    215         ppobj_Method=0;
    216     }
    217 
    218209    if(ppobj_StaticMember){
    219210        //静的メンバ
     
    225216    }
    226217
    227     foreach( CMethod *method, StaticMethods ){
     218    //メソッド
     219    foreach( CMethod *method, methods ){
     220        delete method;
     221    }
     222
     223    //静的メソッド
     224    foreach( CMethod *method, staticMethods ){
    228225        delete method;
    229226    }
     
    249246
    250247    //メソッドをコピー
    251     ppobj_Method=(CMethod **)HeapReAlloc(
    252         hHeap,
    253         0,
    254         ppobj_Method,
    255         pInheritsClass->iMethodNum*sizeof(CMethod *));
    256     iMethodNum=pInheritsClass->iMethodNum;
    257     for(i3=0;i3<pInheritsClass->iMethodNum;i3++){
    258         ppobj_Method[i3]=new CMethod(pInheritsClass->ppobj_Method[i3]);
     248    foreach( CMethod *baseMethod, pInheritsClass->methods ){
     249        CMethod *method = new CMethod( baseMethod );
    259250
    260251        //dwAccess
    261         if(pInheritsClass->ppobj_Method[i3]->dwAccess==ACCESS_PRIVATE)
    262             ppobj_Method[i3]->dwAccess=ACCESS_NON;
    263         else ppobj_Method[i3]->dwAccess=pInheritsClass->ppobj_Method[i3]->dwAccess;
     252        if(baseMethod->dwAccess==ACCESS_PRIVATE)
     253            method->dwAccess=ACCESS_NON;
     254        else method->dwAccess=baseMethod->dwAccess;
    264255
    265256        //pobj_Inherits
    266257        // ※継承元のClassIndexをセット(入れ子継承を考慮する)
    267         if(pInheritsClass->ppobj_Method[i3]->pobj_InheritsClass==0)
    268             ppobj_Method[i3]->pobj_InheritsClass=pInheritsClass;
     258        if(baseMethod->pobj_InheritsClass==0)
     259            method->pobj_InheritsClass=pInheritsClass;
    269260        else
    270             ppobj_Method[i3]->pobj_InheritsClass=
    271                 pInheritsClass->ppobj_Method[i3]->pobj_InheritsClass;
     261            method->pobj_InheritsClass=
     262                baseMethod->pobj_InheritsClass;
     263
     264        methods.push_back( method );
    272265    }
    273266
     
    289282}
    290283void CClass::AddMethod( SUBINFO *psi,DWORD dwAccess, bool isConst, BOOL bAbstract, BOOL bVirtual ){
    291     ppobj_Method = (CMethod **)HeapReAlloc( hHeap, 0, ppobj_Method, (iMethodNum + 1) * sizeof(CMethod *) );
    292     ppobj_Method[iMethodNum] = new CMethod();
    293     ppobj_Method[iMethodNum]->psi = psi;
    294     ppobj_Method[iMethodNum]->dwAccess = dwAccess;
    295     ppobj_Method[iMethodNum]->isConst = isConst;
    296     ppobj_Method[iMethodNum]->bAbstract = bAbstract;
    297     ppobj_Method[iMethodNum]->bVirtual = bVirtual;
    298     ppobj_Method[iMethodNum]->pobj_InheritsClass = 0;
    299 
    300     iMethodNum++;
     284    CMethod *method = new CMethod();
     285    method->psi = psi;
     286    method->dwAccess = dwAccess;
     287    method->isConst = isConst;
     288    method->bAbstract = bAbstract;
     289    method->bVirtual = bVirtual;
     290    method->pobj_InheritsClass = 0;
     291
     292    methods.push_back( method );
    301293}
    302294void CClass::AddStaticMethod(SUBINFO *psi,DWORD dwAccess){
     
    308300    method->pobj_InheritsClass=0;
    309301
    310     StaticMethods.push_back( method );
     302    staticMethods.push_back( method );
    311303}
    312304BOOL CClass::DupliCheckAll(const char *name){
    313305    //重複チェック
    314306
    315     int i;
    316 
    317307    //メンバ
    318308    if(DupliCheckMember(name)) return 1;
    319309
    320310    //メソッド
    321     for(i=0;i<iMethodNum;i++){
    322         if(lstrcmp(name,ppobj_Method[i]->psi->name)==0){
     311    foreach( CMethod *method, methods ){
     312        if( lstrcmp( name, method->psi->name ) == 0 ){
    323313            return 1;
    324314        }
     
    349339}
    350340CMethod *CClass::GetMethodInfo( SUBINFO *psi ){
    351     for( int i=iMethodNum-1; i>=0; i-- ){
    352         if( psi == ppobj_Method[i]->psi ) return ppobj_Method[i];
     341    for( int i=(int)methods.size()-1; i>=0; i-- ){
     342        if( psi == methods[i]->psi ) return methods[i];
    353343    }
    354344    return NULL;
    355345}
    356346CMethod *CClass::GetStaticMethodInfo( SUBINFO *psi ){
    357     for( int i=(int)StaticMethods.size()-1; i>=0; i-- ){
    358         if( psi == StaticMethods[i]->psi ) return StaticMethods[i];
     347    for( int i=(int)staticMethods.size()-1; i>=0; i-- ){
     348        if( psi == staticMethods[i]->psi ) return staticMethods[i];
    359349    }
    360350    return NULL;
    361351}
    362352bool CClass::IsExistMethod( const char *name ){
    363     for( int i=0; i<iMethodNum; i++ ){
    364         if( lstrcmp( ppobj_Method[i]->psi->name, name ) == 0 ) return true;
     353    foreach( CMethod *method, methods ){
     354        if( lstrcmp( method->psi->name, name ) == 0 ) return true;
    365355    }
    366356    return false;
    367357}
    368358bool CClass::IsExistStaticMethod( const char *name ){
    369     foreach( CMethod *method, StaticMethods ){
     359    foreach( CMethod *method, staticMethods ){
    370360        if( lstrcmp( method->psi->name, name ) == 0 ) return true;
    371361    }
     
    375365void CClass::EnumStaticMethod( const char *methodName, std::vector<SUBINFO *> &subs ) const
    376366{
    377     foreach( CMethod *method, StaticMethods ){
     367    foreach( CMethod *method, staticMethods ){
    378368        if(lstrcmp(methodName,method->psi->name)==0){
    379369            subs.push_back( method->psi );
     
    386376    //オブジェクトのメンバ関数の場合
    387377    //※オーバーライドされた関数を先にサーチする必要があるため、バックサーチを行う
    388     for(int i=iMethodNum-1;i>=0;i--){
    389         if(lstrcmp(name,ppobj_Method[i]->psi->name)==0){
    390             subs.push_back( ppobj_Method[i]->psi );
     378    for( int i=(int)methods.size()-1; i>=0; i-- ){
     379        if(lstrcmp(methodName,methods[i]->psi->name)==0){
     380            subs.push_back( methods[i]->psi );
    391381        }
    392382    }
     
    395385void CClass::EnumMethod( const BYTE idOperatorCalc, std::vector<SUBINFO *> &subs ) const
    396386{
    397     for(int i=0;i<iMethodNum;i++){
     387    //オブジェクトのメンバ関数の場合
     388    //※オーバーライドされた関数を先にサーチする必要があるため、バックサーチを行う
     389    for( int i=(int)methods.size()-1; i>=0; i-- ){
    398390        char *temp;
    399         temp=ppobj_Method[i]->psi->name;
     391        temp=methods[i]->psi->name;
    400392        if(temp[0]==1&&temp[1]==ESC_OPERATOR){
    401393            if((BYTE)temp[2]==idOperatorCalc){
    402                 subs.push_back( ppobj_Method[i]->psi );
    403             }
    404         }
    405     }
     394                subs.push_back( methods[i]->psi );
     395            }
     396        }
     397    }
     398}
     399
     400//デフォルト コンストラクタ メソッドを取得
     401CMethod *CClass::GetConstructorMethod() const
     402{
     403    if( ConstructorMemberSubIndex == -1 ) return NULL;
     404    return methods[ConstructorMemberSubIndex];
     405}
     406
     407//デフォルト コピーコンストラクタ メソッドを取得
     408CMethod *CClass::GetCopyConstructorMethod() const
     409{
     410    if( CopyConstructorMemberSubIndex == -1 ) return NULL;
     411    return methods[CopyConstructorMemberSubIndex];
     412}
     413
     414//デストラクタ メソッドを取得
     415CMethod *CClass::GetDestructorMethod() const
     416{
     417    if( DestructorMemberSubIndex == -1 ) return NULL;
     418    return methods[DestructorMemberSubIndex];
    406419}
    407420
     
    409422LONG_PTR CClass::AddVtblDataTable(SUBINFO **ppsi,int length){
    410423    return AddDataTable((char *)ppsi,length);
     424}
     425int CClass::GetFuncNumInVtbl( const SUBINFO *psi ) const
     426{
     427    int n = 0;
     428    foreach( CMethod *method, methods ){
     429        if( method->psi == psi ) break;
     430        if( method->psi->bVirtual ) n++;
     431    }
     432    return n;
    411433}
    412434LONG_PTR CClass::GetVtblGlobalOffset(void){
     
    424446
    425447    //関数テーブルに値をセット
    426     for( int i=0, i2=0; i < iMethodNum; i++ ){
    427         if(ppobj_Method[i]->bVirtual){
    428             ppobj_Method[i]->psi->bUse=1;
    429 
    430             if(ppobj_Method[i]->bAbstract){
     448    int i2 = 0;
     449    foreach( CMethod *method, methods ){
     450        if(method->bVirtual){
     451            method->psi->bUse=1;
     452
     453            if(method->bAbstract){
    431454                extern int cp;
    432455                SetError(300,NULL,cp);
     
    434457                ppsi[i2]=0;
    435458            }
    436             else ppsi[i2]=ppobj_Method[i]->psi;
     459            else ppsi[i2]=method->psi;
    437460            i2++;
    438461        }
     
    465488}
    466489bool CClass::IsAbstract(){
    467     //未実装の仮想関数を持つ場合は1を返す
    468 
    469     for( int i=0; i < iMethodNum; i++ ){
    470         if(ppobj_Method[i]->bVirtual){
    471             if(ppobj_Method[i]->bAbstract){
     490    //未実装の仮想関数を持つ場合はtrueを返す
     491
     492    foreach( CMethod *method, methods ){
     493        if(method->bVirtual){
     494            if(method->bAbstract){
    472495                return true;
    473496            }
     
    744767
    745768    if( fConstructor == 1 )
    746         pobj_c->ConstructorMemberSubIndex = pobj_c->iMethodNum;
     769        pobj_c->ConstructorMemberSubIndex = (int)pobj_c->methods.size();
    747770    else if( fConstructor == 2 )
    748         pobj_c->CopyConstructorMemberSubIndex = pobj_c->iMethodNum;
     771        pobj_c->CopyConstructorMemberSubIndex = (int)pobj_c->methods.size();
    749772    else if( bDestructor )
    750         pobj_c->DestructorMemberSubIndex = pobj_c->iMethodNum;
     773        pobj_c->DestructorMemberSubIndex = (int)pobj_c->methods.size();
    751774
    752775
     
    761784    }
    762785
    763     //メンバ関数
    764     for(i=0;i<pobj_c->iMethodNum;i++){
     786    //メソッド
     787    foreach( CMethod *method, pobj_c->methods ){
    765788        //基底クラスと重複する場合はオーバーライドを行う
    766         if(pobj_c->ppobj_Method[i]->pobj_InheritsClass) continue;
    767 
    768         if(lstrcmp(temporary,pobj_c->ppobj_Method[i]->psi->name)==0){
     789        if(method->pobj_InheritsClass) continue;
     790
     791        if(lstrcmp(temporary,method->psi->name)==0){
    769792            if(CompareParameter(
    770                 pobj_c->ppobj_Method[i]->psi->pParmInfo,pobj_c->ppobj_Method[i]->psi->ParmNum,
     793                method->psi->pParmInfo,method->psi->ParmNum,
    771794                psi->pParmInfo,psi->ParmNum
    772795                )==0){
     
    781804    if(bAbstract) psi->bCompile=1;
    782805
    783 
    784     for(i=0;i<pobj_c->iMethodNum;i++){
    785         if(lstrcmp(temporary,pobj_c->ppobj_Method[i]->psi->name)==0){
     806    //メソッドのオーバーライド
     807    foreach( CMethod *method, pobj_c->methods ){
     808        if(lstrcmp(temporary,method->psi->name)==0){
    786809            if(CompareParameter(
    787                 pobj_c->ppobj_Method[i]->psi->pParmInfo,pobj_c->ppobj_Method[i]->psi->ParmNum,
     810                method->psi->pParmInfo,method->psi->ParmNum,
    788811                psi->pParmInfo,psi->ParmNum
    789812                )==0){
    790813
    791                 if(pobj_c->ppobj_Method[i]->psi->bVirtual){
     814                if(method->psi->bVirtual){
    792815                    //メンバ関数を上書き
    793                     pobj_c->ppobj_Method[i]->psi=psi;
    794                     pobj_c->ppobj_Method[i]->bAbstract=0;
     816                    method->psi=psi;
     817                    method->bAbstract=0;
    795818
    796819                    if(!bOverride){
    797820                        SetError(127,NULL,NowLine);
    798821                    }
    799                     if(pobj_c->ppobj_Method[i]->dwAccess!=dwAccess){
     822                    if(method->dwAccess!=dwAccess){
    800823                        SetError(128,NULL,NowLine);
    801824                    }
     
    890913            pobj_c->ppobj_StaticMember=(CMember **)HeapAlloc(hHeap,0,1);
    891914            pobj_c->iStaticMemberNum=0;
    892             pobj_c->ppobj_Method=(CMethod **)HeapAlloc(hHeap,0,1);
    893             pobj_c->iMethodNum=0;
    894915
    895916            pobj_c->ConstructorMemberSubIndex=-1;
     
    10501071            pobj_c->ppobj_StaticMember=(CMember **)HeapAlloc(hHeap,0,1);
    10511072            pobj_c->iStaticMemberNum=0;
    1052             pobj_c->ppobj_Method=(CMethod **)HeapAlloc(hHeap,0,1);
    1053             pobj_c->iMethodNum=0;
    10541073
    10551074            pobj_c->ConstructorMemberSubIndex=-1;
Note: See TracChangeset for help on using the changeset viewer.