Changeset 18 in dev for BasicCompiler_Common


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

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

Location:
BasicCompiler_Common
Files:
4 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
  • BasicCompiler_Common/Class.h

    r17 r18  
    4949    BOOL bAbstract;
    5050    BOOL bVirtual;
     51    bool isConst;
    5152
    5253    CClass *pobj_InheritsClass;
     
    9697    void AddMember( DWORD dwAccess, bool idConst, char *buffer );
    9798    void AddStaticMember( DWORD dwAccess, bool isConst, char *buffer, int NowLine );
    98     void AddMethod(SUBINFO *psi,DWORD dwAccess,BOOL bAbstract,BOOL bVirtual);
     99    void AddMethod( SUBINFO *psi,DWORD dwAccess, bool isConst, BOOL bAbstract, BOOL bVirtual );
    99100    void AddStaticMethod(SUBINFO *psi,DWORD dwAccess);
    100101
    101102    BOOL DupliCheckAll(char *name);
    102103    BOOL DupliCheckMember(char *name);
     104
     105    CMethod *GetMethodInfo( SUBINFO *psi );
     106    CMethod *GetStaticMethodInfo( SUBINFO *psi );
    103107
    104108
     
    124128    void NotifyFinishConstructorCompile();
    125129    bool IsCompilingConstructor();
     130
     131    //デストラクタをコンパイルしているかどうかのチェックフラグ
     132private:
     133    bool isCompilingDestructor;
     134public:
     135    void NotifyStartDestructorCompile();
     136    void NotifyFinishDestructorCompile();
     137    bool IsCompilingDestructor();
    126138
    127139
     
    147159
    148160private:
    149     void AddMemberSub(CClass *pobj_c,DWORD dwAccess,BOOL bStatic,BOOL bAbstract,BOOL bVirtual,BOOL bOverride,char *buffer,int NowLine);
     161    void AddMethod(CClass *pobj_c, DWORD dwAccess, BOOL bStatic, bool isConst, BOOL bAbstract,
     162        BOOL bVirtual, BOOL bOverride, char *buffer, int NowLine);
    150163    BOOL MemberVar_LoopRefCheck(CClass *pobj_c);
    151164public:
     
    155168
    156169
    157     //イテレータ
     170    /////////////////////////////
     171    // 現在コンパイル中の情報
     172    /////////////////////////////
     173private:
     174    CClass *pCompilingClass;
     175    CMethod *pCompilingMethod;
     176public:
     177    //コンパイル開始の通知を受け取るメソッド
     178    void StartCompile( SUBINFO *psi );
     179
     180    //現在コンパイル中のメソッド情報を取得
     181    CClass *GetNowCompilingClass();
     182    CMethod *GetNowCompilingMethodInfo();
     183
     184
     185    /////////////////////
     186    // イテレータ
     187    /////////////////////
    158188private:
    159189    CClass **ppobj_IteClass;
  • BasicCompiler_Common/Intermediate_Step2.cpp

    r16 r18  
    3333    return pci;
    3434}
     35
     36// マクロ定数を追加するための関数
    3537void AddConstData(char *Command){
    3638    extern HANDLE hHeap;
     
    4446            return;
    4547        }
    46         if(Command[i]=='='){
     48        if(Command[i]=='=' ||  Command[i] == 1 && Command[i+1] == ESC_AS ){
    4749            //定数定義は新しいクラスモジュール(CDBConst)へ移行
     50            // ※この関数はマクロ定数のみを扱う
    4851            return;
    4952        }
  • BasicCompiler_Common/error.cpp

    r17 r18  
    142142    if(num==59) sprintf(msg,"マニフェスト ファイル \"%s\" の読み込みに失敗。",KeyWord);
    143143    if(num==60) lstrcpy(msg,"Staticステートメントはグローバル領域では使用できません。");
    144     if(num==61) sprintf(msg,"\"%s\" は定数です。書き込ません。",KeyWord);
     144    if(num==61) sprintf(msg,"\"%s\" は定数です。書き込みアクセスはできません。",KeyWord);
    145145
    146146
     
    174174    if(num==128) lstrcpy(msg,"オーバーライドを行うときはアクセシビリティを同一にしなければなりません。");
    175175    if(num==129) sprintf(msg,"静的メンバ \"%s\" は定義されていません。",KeyWord);
     176    if(num==130) sprintf(msg,"\"%s\" はオブジェクト定数です。書き込みアクセスはできません。",KeyWord);
     177    if(num==131) lstrcpy(msg,"Const定義されたメソッド内でクラスメンバへの書き込みアクセスはできません。");
    176178
    177179    //Enum関連
Note: See TracChangeset for help on using the changeset viewer.