Changeset 11 in dev for BasicCompiler32


Ignore:
Timestamp:
Dec 8, 2006, 3:25:27 AM (17 years ago)
Author:
dai_9181
Message:

Const変数の書き込み規制を有効化(グローバル/ローカル変数のみ)
定数オブジェクトと定数メンバは未実装。

Location:
BasicCompiler32
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • BasicCompiler32/BasicCompiler.vcproj

    r3 r11  
    736736                    </FileConfiguration>
    737737                </File>
    738                 <File
    739                     RelativePath="..\BasicCompiler_Common\Variable.cpp"
    740                     >
    741                     <FileConfiguration
    742                         Name="Debug|Win32"
    743                         >
    744                         <Tool
    745                             Name="VCCLCompilerTool"
    746                             PreprocessorDefinitions=""
    747                         />
    748                     </FileConfiguration>
    749                     <FileConfiguration
    750                         Name="Release|Win32"
    751                         >
    752                         <Tool
    753                             Name="VCCLCompilerTool"
    754                             PreprocessorDefinitions=""
    755                         />
    756                     </FileConfiguration>
    757                     <FileConfiguration
    758                         Name="English_Rel|Win32"
    759                         >
    760                         <Tool
    761                             Name="VCCLCompilerTool"
    762                             PreprocessorDefinitions=""
    763                         />
    764                     </FileConfiguration>
    765                 </File>
    766738                <Filter
    767739                    Name="Intermediate"
     
    12691241                    <File
    12701242                        RelativePath="..\BasicCompiler_Common\Const.h"
     1243                        >
     1244                    </File>
     1245                </Filter>
     1246                <Filter
     1247                    Name="Variable"
     1248                    >
     1249                    <File
     1250                        RelativePath="..\BasicCompiler_Common\Variable.cpp"
     1251                        >
     1252                        <FileConfiguration
     1253                            Name="Debug|Win32"
     1254                            >
     1255                            <Tool
     1256                                Name="VCCLCompilerTool"
     1257                                PreprocessorDefinitions=""
     1258                            />
     1259                        </FileConfiguration>
     1260                        <FileConfiguration
     1261                            Name="Release|Win32"
     1262                            >
     1263                            <Tool
     1264                                Name="VCCLCompilerTool"
     1265                                PreprocessorDefinitions=""
     1266                            />
     1267                        </FileConfiguration>
     1268                        <FileConfiguration
     1269                            Name="English_Rel|Win32"
     1270                            >
     1271                            <Tool
     1272                                Name="VCCLCompilerTool"
     1273                                PreprocessorDefinitions=""
     1274                            />
     1275                        </FileConfiguration>
     1276                    </File>
     1277                    <File
     1278                        RelativePath="..\BasicCompiler_Common\Variable.h"
    12711279                        >
    12721280                    </File>
  • BasicCompiler32/CParameter.cpp

    r3 r11  
    556556                int VarType;
    557557                LONG_PTR lpVarIndex;
    558                 if(!GetVarOffset(1,Parms[i2],&VarType,&RelativeVar,&lpVarIndex)) continue;
     558                if(!GetVarOffsetReadOnly(Parms[i2],&VarType,&RelativeVar,&lpVarIndex)) continue;
    559559
    560560                if(DummyTypeInfo.type!=DEF_ANY){
  • BasicCompiler32/Compile_Calc.cpp

    r3 r11  
    516516
    517517        //変数アドレスを取得
    518         if(!GetVarOffset(
    519             1,
     518        if(!GetVarOffsetReadWrite(
    520519            variable,
    521520            &VarType,
     
    535534
    536535    //変数アドレスを取得
    537     if(!GetVarOffset(
    538         1,
     536    if(!GetVarOffsetReadWrite(
    539537        variable,
    540538        &VarType,
  • BasicCompiler32/Compile_CallProc.cpp

    r3 r11  
    185185    RELATIVE_VAR RelativeVar;
    186186    LONG_PTR lp;
    187     GetVarOffset(1,variable,&i,&RelativeVar,&lp);
     187    GetVarOffsetReadOnly(variable,&i,&RelativeVar,&lp);
    188188    SetVarPtrToEax(&RelativeVar);
    189189
     
    382382
    383383            RELATIVE_VAR RelativeVar;
    384             if(!GetVarOffset(1,ObjectName,&i2,&RelativeVar,0)) return -1;
     384            if(!GetVarOffsetReadOnly(ObjectName,&i2,&RelativeVar,0)) return -1;
    385385            SetVarPtrToEax(&RelativeVar);
    386386
  • BasicCompiler32/Compile_Func.cpp

    r3 r11  
    223223    int SubScripts[MAX_ARRAYDIM];
    224224    RELATIVE_VAR RelativeVar;
    225     if(!GetVarOffset(1,tempParm,&type,&RelativeVar,&lpIndex,SubScripts)) return;
     225    if(!GetVarOffsetReadOnly(tempParm,&type,&RelativeVar,&lpIndex,SubScripts)) return;
    226226
    227227    if(type&FLAG_PTR){
     
    295295                RELATIVE_VAR RelativeVar;
    296296                int type;
    297                 if(!GetVarOffset(1,ObjectName,&type,&RelativeVar,(LONG_PTR *)&pobj_c)) return;
     297                if(!GetVarOffsetReadOnly(ObjectName,&type,&RelativeVar,(LONG_PTR *)&pobj_c)) return;
    298298                SetVarPtrToEax(&RelativeVar);
    299299
     
    375375
    376376    //変数のアドレスを取得
    377     if(!GetVarOffset(1,Parameter,&type,&RelativeVar,0)) return;
     377    if(!GetVarOffsetReadOnly(Parameter,&type,&RelativeVar,0)) return;
    378378
    379379    SetVarPtrToEax(&RelativeVar);
  • BasicCompiler32/Compile_ProcOp.cpp

    r3 r11  
    282282
    283283        lstrcpy(LocalVar[MaxLocalVarNum].name,psi->pRealParmInfo[i3].name);
     284
     285        // TODO: パラメータのConst定義の指定が未完成
     286        LocalVar[MaxLocalVarNum].bConst=false;
    284287
    285288        LocalVar[MaxLocalVarNum].bArray=psi->pRealParmInfo[i3].bArray;
     
    696699            temp="_System_ReturnValue";
    697700        else temp=psi->name;
    698         GetVarOffset(1,temp,&i3,&RelativeVar,&lpIndex);
     701        GetVarOffsetReadWrite(temp,&i3,&RelativeVar,&lpIndex);
    699702
    700703        i3=psi->ReturnType;
  • BasicCompiler32/Compile_Statement.cpp

    r3 r11  
    15731573
    15741574        LONG_PTR lpIndex;
    1575         RELATIVE_VAR RelativeVar;
    1576         GetVarOffset(1,temporary,&type,&RelativeVar,&lpIndex);
     1575        type = GetVarType(temporary,&lpIndex,1);
    15771576
    15781577        sprintf(temp2,"_System_InputDataPtr[%d]=VarPtr(%s)",i4,temporary);
  • BasicCompiler32/Compile_Var.cpp

    r8 r11  
    157157    return 1;
    158158}
    159 BOOL GetMemberOffset(BOOL bError,CClass *pobj_c,char *member,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpNestIndex,BOOL bPrivateAccess){
     159BOOL GetMemberOffset(bool ErrorEnabled,CClass *pobj_c,char *member,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpNestIndex,BOOL bPrivateAccess){
    160160    int i,offset;
    161161
     
    175175    offset=GetSizeOfClassMember(pobj_c,VarName,&i);
    176176    if(i==pobj_c->iMemberNum){
    177         if(bError) SetError(103,VarName,cp);
     177        if(ErrorEnabled) SetError(103,VarName,cp);
    178178        return 0;
    179179    }
     
    183183        //同一クラスオブジェクトの場合はプライベートアクセスを容認する
    184184        if(pobj_c->ppobj_Member[i]->dwAccess==ACCESS_NON){
    185             if(bError) SetError(107,VarName,cp);
     185            if(ErrorEnabled) SetError(107,VarName,cp);
    186186            return 0;
    187187        }
     
    190190        if((bPrivateAccess==0&&pobj_c->ppobj_Member[i]->dwAccess==ACCESS_PRIVATE)||
    191191            pobj_c->ppobj_Member[i]->dwAccess==ACCESS_NON){
    192             if(bError) SetError(107,VarName,cp);
     192            if(ErrorEnabled) SetError(107,VarName,cp);
    193193            return 0;
    194194        }
    195195        else if(bPrivateAccess==0&&pobj_c->ppobj_Member[i]->dwAccess==ACCESS_PROTECTED){
    196             if(bError) SetError(108,VarName,cp);
     196            if(ErrorEnabled) SetError(108,VarName,cp);
    197197            return 0;
    198198        }
     
    211211    else{
    212212        if(lpPtrOffset[0]){
    213             if(bError) SetError(16,member,cp);
     213            if(ErrorEnabled) SetError(16,member,cp);
    214214            return 0;
    215215        }
     
    227227        //配列オフセット
    228228        if(!GetArrayOffset(pobj_c->ppobj_Member[i]->SubScripts,array,*pType,pobj_c->ppobj_Member[i]->TypeInfo.u.lpIndex))
    229             if(bError) SetError(14,member,cp);
     229            if(ErrorEnabled) SetError(14,member,cp);
    230230    }
    231231    else if(pobj_c->ppobj_Member[i]->SubScripts[0]!=-1){
     
    238238        if(*pType==DEF_OBJECT){
    239239            if(RefType!=DEF_OBJECT){
    240                 if(bError) SetError(104,member,cp);
     240                if(ErrorEnabled) SetError(104,member,cp);
    241241                return 0;
    242242            }
     
    248248                //pObj[n].member
    249249                if(RefType!=DEF_OBJECT){
    250                     if(bError) SetError(104,member,cp);
     250                    if(ErrorEnabled) SetError(104,member,cp);
    251251                    return 0;
    252252                }
     
    261261                //pObj->member
    262262                if(RefType!=DEF_PTR_OBJECT){
    263                     if(bError) SetError(104,member,cp);
     263                    if(ErrorEnabled) SetError(104,member,cp);
    264264                    return 0;
    265265                }
     
    287287                //ppObj[n]->member
    288288                if(RefType!=DEF_PTR_OBJECT){
    289                     if(bError) SetError(104,member,cp);
     289                    if(ErrorEnabled) SetError(104,member,cp);
    290290                    return 0;
    291291                }
     
    302302            }
    303303            else{
    304                 if(bError) SetError(104,member,cp);
     304                if(ErrorEnabled) SetError(104,member,cp);
    305305                return 0;
    306306            }
    307307        }
    308308
    309         if(!GetMemberOffset(bError,pobj_c->ppobj_Member[i]->TypeInfo.u.pobj_Class,
     309        if(!GetMemberOffset(ErrorEnabled,pobj_c->ppobj_Member[i]->TypeInfo.u.pobj_Class,
    310310            NestMember,
    311311            pType,
     
    344344}
    345345
    346 BOOL GetVarOffset(BOOL bError,char *NameBuffer,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss){
     346BOOL GetVarOffset(bool ErrorEnabled,bool WriteAccess,char *NameBuffer,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss){
    347347    extern BOOL bCompilingGlobal;
    348348    int i,RefType;
     
    360360    LONG_PTR lpIndex;
    361361    int *pSubScripts;
     362    bool bConst;
    362363
    363364    if(bCompilingGlobal==0){
     
    395396            if(plpIndex) *plpIndex=lpIndex;
    396397            pSubScripts=LocalVar[i].SubScripts;
     398            bConst = LocalVar[i].bConst;
    397399
    398400            goto ok;
     
    439441
    440442        pRelativeVar->dwKind=VAR_DIRECTMEM;
    441         if(!GetMemberOffset(bError,pobj_CompilingClass,variable,pType,pRelativeVar,&lpIndex,1)) return 0;
     443        if(!GetMemberOffset(ErrorEnabled,pobj_CompilingClass,variable,pType,pRelativeVar,&lpIndex,1)) return 0;
    442444        if(plpIndex) *plpIndex=lpIndex;
    443445        return 1;
     
    511513    }
    512514
    513     if(bError) SetError(3,variable,cp);
     515    if(ErrorEnabled) SetError(3,variable,cp);
    514516    pRelativeVar->dwKind=NON_VAR;
    515517    return 0;
     
    540542    if(plpIndex) *plpIndex=lpIndex;
    541543    pSubScripts=GlobalVar[i].SubScripts;
     544    bConst = GlobalVar[i].bConst;
    542545
    543546
    544547ok:
    545548
     549    if(bConst && WriteAccess){
     550        //Const定義の変数に書き込みアクセスをしようとした場合
     551        SetError(61,VarName,cp);
     552    }
    546553
    547554    if(array[0]==0&&pSubScripts[0]!=-1){
     
    576583
    577584            LONG_PTR lp2;
    578             if(!GetMemberOffset(bError,(CClass *)lpIndex,member,pType,pRelativeVar,&lp2,0)) return 0;
     585            if(!GetMemberOffset(ErrorEnabled,(CClass *)lpIndex,member,pType,pRelativeVar,&lp2,0)) return 0;
    579586            if(plpIndex) *plpIndex=lp2;
    580587        }
     
    592599
    593600                LONG_PTR lp2;
    594                 if(!GetMemberOffset(bError,(CClass *)lpIndex,member,pType,pRelativeVar,&lp2,0)) return 0;
     601                if(!GetMemberOffset(ErrorEnabled,(CClass *)lpIndex,member,pType,pRelativeVar,&lp2,0)) return 0;
    595602                if(plpIndex) *plpIndex=lp2;
    596603            }
     
    611618
    612619                LONG_PTR lp2;
    613                 if(!GetMemberOffset(bError,(CClass *)lpIndex,member,pType,pRelativeVar,&lp2,0)) return 0;
     620                if(!GetMemberOffset(ErrorEnabled,(CClass *)lpIndex,member,pType,pRelativeVar,&lp2,0)) return 0;
    614621                if(plpIndex) *plpIndex=lp2;
    615622            }
     
    636643
    637644                LONG_PTR lp2;
    638                 if(!GetMemberOffset(bError,(CClass *)lpIndex,member,pType,pRelativeVar,&lp2,0)) return 0;
     645                if(!GetMemberOffset(ErrorEnabled,(CClass *)lpIndex,member,pType,pRelativeVar,&lp2,0)) return 0;
    639646                if(plpIndex) *plpIndex=lp2;
    640647            }
     
    11171124            lstrcpy(pVar->name,VarName);
    11181125            pVar->fRef=0;
    1119             if(dwFlag & DIMFLAG_CONST) pVar->bConst = 1;
    1120             else pVar->bConst = 0;
     1126            if(dwFlag & DIMFLAG_CONST) pVar->bConst = true;
     1127            else pVar->bConst = false;
    11211128            if(SubScripts[0]==-1) pVar->bArray=0;
    11221129            else pVar->bArray=1;
     
    11321139
    11331140            if(InitBuf[0]){
     1141                //初期代入時のみ、書き込みアクセスを許可する
     1142                bool bConstBack = pVar->bConst;
     1143                pVar->bConst = false;
     1144
    11341145                int result = InitLocalVar(-pVar->offset,
    11351146                    pVar->type,
     
    11441155                    OpcodeCalc(temporary);
    11451156                }
     1157
     1158                pVar->bConst = bConstBack;
    11461159            }
    11471160            else{
  • BasicCompiler32/NumOpe.cpp

    r8 r11  
    375375
    376376                    RELATIVE_VAR RelativeVar;
    377                     if(GetVarOffset(0,term,&i2,&RelativeVar,&index_stack[sp])){
     377                    if(GetVarOffset(
     378                        false,  //エラー表示あり
     379                        false,  //読み込み専用
     380                        term,&i2,&RelativeVar,&index_stack[sp])){
    378381                        //////////
    379382                        // 変数
  • BasicCompiler32/Opcode.h

    r8 r11  
    172172void GetWithName(char *buffer);
    173173void SetThisPtrToReg(int reg);
    174 BOOL GetVarOffset(BOOL bError,char *NameBuffer,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss=0);
     174BOOL GetVarOffset(bool ErrorEnabled,bool WriteAccess,char *NameBuffer,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss=0);
    175175BOOL SetInitGlobalData(int offset,int type,LONG_PTR lpIndex,int *SubScripts,char *InitBuf);
    176176#define DIMFLAG_INITDEBUGVAR            1
  • BasicCompiler32/increment.cpp

    r3 r11  
    235235    ///////////////////////////
    236236
    237     if(!GetVarOffset(
    238         1,
     237    if(!GetVarOffsetReadWrite(
    239238        lpszLeft,
    240239        &VarType,
Note: See TracChangeset for help on using the changeset viewer.