Changeset 18 in dev for BasicCompiler_Common/Class.cpp


Ignore:
Timestamp:
Dec 24, 2006, 4:46:12 AM (17 years ago)
Author:
dai_9181
Message:

オブジェクト定数に対応。

File:
1 edited

Legend:

Unmodified
Added
Removed
  • BasicCompiler_Common/Class.cpp

    r17 r18  
    1111CClass *pobj_CompilingClass;
    1212CClass *pobj_StringClass;
     13
     14CMember *pCompilingMethod;
    1315
    1416int AddDataTable(char *buffer,int length);
     
    170172    lstrcpy(this->name,name);
    171173
    172     isCompilingConstructor = 0;
     174    isCompilingConstructor = false;
     175    isCompilingDestructor = false;
    173176}
    174177CClass::~CClass(){
     
    224227    iStaticMemberNum++;
    225228}
    226 void CClass::AddMethod(SUBINFO *psi,DWORD dwAccess,BOOL bAbstract,BOOL bVirtual){
    227     ppobj_Method=(CMethod **)HeapReAlloc(hHeap,0,ppobj_Method,(iMethodNum+1)*sizeof(CMethod *));
    228     ppobj_Method[iMethodNum]=new CMethod();
    229     ppobj_Method[iMethodNum]->psi=psi;
    230     ppobj_Method[iMethodNum]->dwAccess=dwAccess;
    231     ppobj_Method[iMethodNum]->bAbstract=bAbstract;
    232     ppobj_Method[iMethodNum]->bVirtual=bVirtual;
    233     ppobj_Method[iMethodNum]->pobj_InheritsClass=0;
     229void CClass::AddMethod( SUBINFO *psi,DWORD dwAccess, bool isConst, BOOL bAbstract, BOOL bVirtual ){
     230    ppobj_Method = (CMethod **)HeapReAlloc( hHeap, 0, ppobj_Method, (iMethodNum + 1) * sizeof(CMethod *) );
     231    ppobj_Method[iMethodNum] = new CMethod();
     232    ppobj_Method[iMethodNum]->psi = psi;
     233    ppobj_Method[iMethodNum]->dwAccess = dwAccess;
     234    ppobj_Method[iMethodNum]->isConst = isConst;
     235    ppobj_Method[iMethodNum]->bAbstract = bAbstract;
     236    ppobj_Method[iMethodNum]->bVirtual = bVirtual;
     237    ppobj_Method[iMethodNum]->pobj_InheritsClass = 0;
    234238
    235239    iMethodNum++;
     
    284288    return 0;
    285289}
     290CMethod *CClass::GetMethodInfo( SUBINFO *psi ){
     291    int i;
     292    for( i=0; i<iMethodNum; i++ ){
     293        if( psi == ppobj_Method[i]->psi ) break;
     294    }
     295    if( i == iMethodNum ){
     296        return NULL;
     297    }
     298    return ppobj_Method[i];
     299}
     300CMethod *CClass::GetStaticMethodInfo( SUBINFO *psi ){
     301    int i;
     302    for( i=0; i<iStaticMethodNum; i++ ){
     303        if( psi == ppobj_StaticMethod[i]->psi ) break;
     304    }
     305    if( i == iMethodNum ){
     306        return NULL;
     307    }
     308    return ppobj_StaticMethod[i];
     309}
    286310
    287311LONG_PTR CClass::AddVtblDataTable(SUBINFO **ppsi,int length){
     
    409433}
    410434
     435//デストラクタのコンパイルを開始
     436void CClass::NotifyStartDestructorCompile(){
     437    isCompilingDestructor = true;
     438}
     439
     440//デストラクタのコンパイルを終了
     441void CClass::NotifyFinishDestructorCompile(){
     442    isCompilingDestructor = false;
     443}
     444
     445//デストラクタをコンパイル中かどうかを判別
     446bool CClass::IsCompilingDestructor(){
     447    return isCompilingDestructor;
     448}
     449
    411450
    412451int CDBClass::hash(char *name){
     
    559598
    560599
    561 void CDBClass::AddMemberSub(CClass *pobj_c,DWORD dwAccess,BOOL bStatic,BOOL bAbstract,BOOL bVirtual,BOOL bOverride,char *buffer,int NowLine){
     600void CDBClass::AddMethod(CClass *pobj_c, DWORD dwAccess, BOOL bStatic, bool isConst, BOOL bAbstract,
     601                         BOOL bVirtual, BOOL bOverride, char *buffer, int NowLine){
    562602    int i,i2;
    563603    char temporary[VN_SIZE];
     
    580620
    581621    ////////////////////////////////////////////////////////////
    582     // コンストラクタ、デストラクタのアクセシビリティをチェック
     622    // コンストラクタ、デストラクタの場合の処理
    583623    ////////////////////////////////////////////////////////////
    584624    BOOL fConstructor=0,bDestructor=0;
    585625
    586626    if(lstrcmp(temporary,pobj_c->name)==0){
     627        //コンストラクタの場合
     628
     629        //標準コンストラクタ(引数なし)
    587630        if(psi->ParmNum==1) fConstructor=1;
     631
     632        //コピーコンストラクタ
    588633        if(psi->ParmNum==2){
    589634            if(psi->pParmInfo[1].type==DEF_OBJECT&&
    590635                psi->pParmInfo[1].u.pobj_c==pobj_c) fConstructor=2;
    591636        }
     637
     638        //強制的にConst修飾子をつける
     639        isConst = true;
    592640    }
    593641    else if(temporary[0]=='~'){
     
    599647    }
    600648    if(fConstructor||bDestructor){
     649        // コンストラクタ、デストラクタのアクセシビリティをチェック
    601650        if(dwAccess!=ACCESS_PUBLIC){
    602651            SetError(116,NULL,NowLine);
    603652            dwAccess=ACCESS_PUBLIC;
    604653        }
    605     }
    606 
    607 
    608     if(fConstructor==1) pobj_c->ConstructorMemberSubIndex=pobj_c->iMethodNum;
    609     else if(fConstructor==2) pobj_c->CopyConstructorMemberSubIndex=pobj_c->iMethodNum;
    610     else if(bDestructor) pobj_c->DestructorMemberSubIndex=pobj_c->iMethodNum;
     654
     655        //強制的にConst修飾子をつける
     656        isConst = true;
     657    }
     658
     659    if( fConstructor == 1 )
     660        pobj_c->ConstructorMemberSubIndex = pobj_c->iMethodNum;
     661    else if( fConstructor == 2 )
     662        pobj_c->CopyConstructorMemberSubIndex = pobj_c->iMethodNum;
     663    else if( bDestructor )
     664        pobj_c->DestructorMemberSubIndex = pobj_c->iMethodNum;
    611665
    612666
     
    678732    }
    679733    else{
    680         pobj_c->AddMethod(psi,dwAccess,bAbstract,bVirtual);
     734        pobj_c->AddMethod(psi, dwAccess, isConst, bAbstract, bVirtual);
    681735    }
    682736}
     
    890944
    891945                //メンバ関数を追加
    892                 AddMemberSub(pobj_c,ACCESS_PUBLIC,0,1,1,0,temporary,sub_address);
     946                AddMethod(pobj_c,
     947                    ACCESS_PUBLIC,      //Publicアクセス権
     948                    0,                  //Static指定なし
     949                    false,              //Constではない
     950                    1,                  //Abstract
     951                    1,                  //Virtual
     952                    0,
     953                    temporary,
     954                    sub_address
     955                    );
    893956            }
    894957        }
     
    9901053                }
    9911054
    992                 //メンバ変数をコピー
     1055                //メンバをコピー
    9931056                pobj_c->ppobj_Member=(CMember **)HeapReAlloc(
    9941057                    hHeap,
     
    10061069                }
    10071070
    1008                 //メンバ関数をコピー
     1071                //メソッドをコピー
    10091072                pobj_c->ppobj_Method=(CMethod **)HeapReAlloc(
    10101073                    hHeap,
     
    10421105InheritsError:
    10431106
    1044             //メンバ変数、関数を取得
     1107            //メンバとメソッドを取得
    10451108            while(1){
    10461109                i++;
     
    11801243                    //メソッドを追加
    11811244                    cp=i;   //エラー用
    1182                     AddMemberSub(pobj_c,dwAccess,bStatic,bAbstract,bVirtual,bOverride,temporary,sub_address);
     1245                    AddMethod(pobj_c,
     1246                        dwAccess,
     1247                        bStatic,
     1248                        isConst,
     1249                        bAbstract,
     1250                        bVirtual,
     1251                        bOverride,
     1252                        temporary,
     1253                        sub_address);
    11831254
    11841255                    if(bAbstract) continue;
     
    12231294}
    12241295
     1296void CDBClass::StartCompile( SUBINFO *psi ){
     1297    pCompilingClass = psi->pobj_ParentClass;
     1298    if( pCompilingClass ){
     1299        pCompilingMethod = pCompilingClass->GetMethodInfo( psi );
     1300        if( !pCompilingMethod ){
     1301            pCompilingMethod = pCompilingClass->GetStaticMethodInfo( psi );
     1302            if( !pCompilingMethod ){
     1303                SetError(300,NULL,cp);
     1304            }
     1305        }
     1306    }
     1307    else{
     1308        pCompilingMethod = NULL;
     1309    }
     1310}
     1311CClass *CDBClass::GetNowCompilingClass(){
     1312    return pCompilingClass;
     1313}
     1314CMethod *CDBClass::GetNowCompilingMethodInfo(){
     1315    return pCompilingMethod;
     1316}
     1317
    12251318
    12261319
Note: See TracChangeset for help on using the changeset viewer.