Changeset 20 in dev for BasicCompiler64/CParameter.cpp


Ignore:
Timestamp:
Dec 28, 2006, 5:24:48 AM (17 years ago)
Author:
dai_9181
Message:

参照型パラメータに関数の戻り値オブジェクトを指定した場合などの、一時オブジェクトの扱いを可能にした。
Dimで指定される初期値を見分けることで、As指定を省略できるようにした。

File:
1 edited

Legend:

Unmodified
Added
Removed
  • BasicCompiler64/CParameter.cpp

    r11 r20  
    329329    }
    330330}
     331
     332void CParameter::NewTempParameters( char *FuncName,PARAMETER_INFO *ppi,int pi_num,int SecondParmNum ){
     333    ///////////////////////////////////////////////////////
     334    // 一時オブジェクトをあらかじめスタックに積んでおく
     335    ///////////////////////////////////////////////////////
     336
     337    useTempObject = false;
     338
     339    BOOL bEllipse;
     340    if(pi_num){
     341        if(ppi[pi_num-1].type==DEF_ELLIPSE) bEllipse=1;
     342        else bEllipse=0;
     343    }
     344    else bEllipse=0;
     345
     346    for(int i2=ParmsNum-1;i2>=0;i2--){
     347        useTempParameters[i2] = false;
     348
     349        if(bEllipse&&i2<=pi_num-2) bEllipse=0;
     350
     351        if(i2==0&&ppi[i2].name){
     352            if(lstrcmp(ppi[i2].name,"_System_LocalThis")==0){
     353                //オブジェクトメンバの第一パラメータのThisポインタ
     354                continue;
     355            }
     356        }
     357        if((i2==0||i2==1)&&ppi[i2].name){
     358            if(lstrcmp(ppi[i2].name,FuncName)==0){
     359                //オブジェクトメンバの第一または第二パラメータの戻り値用オブジェクト
     360                continue;
     361            }
     362        }
     363
     364        TYPEINFO DummyTypeInfo;
     365        BOOL bByVal;
     366        if(bEllipse){
     367            DummyTypeInfo.type=NumOpe_GetType(Parms[i2],NULL,&DummyTypeInfo.u.lpIndex);
     368            bByVal=1;
     369        }
     370        else{
     371            DummyTypeInfo.type=ppi[i2].type;
     372            DummyTypeInfo.u.lpIndex=ppi[i2].u.index;
     373            bByVal=ppi[i2].bByVal;
     374        }
     375
     376
     377        if( !bByVal ){
     378            //ポインタ参照
     379            if(Parms[i2][0]==1&&Parms[i2][1]==ESC_BYVAL){
     380                //ポインタ指定
     381                continue;
     382            }
     383
     384            LONG_PTR lpVarIndex;
     385            if( GetVarType( Parms[i2], &lpVarIndex, FALSE ) == -1 ){
     386                //変数ではないとき
     387                int reg = REG_RAX;
     388                int type = NumOpe( &reg, Parms[i2], DummyTypeInfo.type, DummyTypeInfo.u.lpIndex, &lpVarIndex );
     389
     390                //スタックフレームへコピー
     391                StackOffsetOfTempObject[i2] = pobj_sf->push(reg);
     392
     393                useTempParameters[i2] = true;
     394                useTempObject = true;
     395
     396                types[i2].type = type;
     397                types[i2].u.lpIndex = lpVarIndex;
     398            }
     399        }
     400    }
     401}
     402void CParameter::DeleteTempParameters(){
     403    ///////////////////////////////////////////////////////
     404    // 一時オブジェクトを破棄
     405    ///////////////////////////////////////////////////////
     406    if( !useTempObject ) return;
     407
     408    for(int i2=ParmsNum-1;i2>=0;i2--){
     409        if( useTempParameters[i2] ){
     410            //スタックフレームから取得
     411            pobj_sf->ref(REG_RCX);
     412
     413            //デストラクタを呼び出す
     414
     415            //call destructor
     416            int i5 = types[i2].u.pobj_Class->DestructorMemberSubIndex;
     417            op_call( types[i2].u.pobj_Class->ppobj_Method[i5]->psi );
     418
     419            //メモリを解放する
     420
     421            pobj_sf->pop(REG_RCX);
     422
     423            //call free
     424            extern SUBINFO *pSub_free;
     425            op_call(pSub_free);
     426        }
     427    }
     428}
     429
    331430void CParameter::SetObjectParameter(int reg,CClass *pobj_Class,LPSTR Parameter){
    332431    //////////////////////////////////////////////////////
     
    427526    op_mov_RR(reg,REG_R11);
    428527}
     528
    429529void CParameter::SetParameter(char *FuncName,PARAMETER_INFO *ppi,int pi_num,int SecondParmNum){
    430530    ///////////////////////////////////////////////////////////
     
    616716                int VarType;
    617717                LONG_PTR lpVarIndex;
    618                 if(!GetVarOffsetReadOnly(
     718                if(GetVarOffset(
     719                    false,
     720                    false,
    619721                    Parms[i2],
    620722                    &VarType,
    621723                    &RelativeVar,
    622                     &lpVarIndex)) continue;
    623 
    624                 if(DummyTypeInfo.type!=DEF_ANY){
    625                     //型チェックを行う
    626                     if(DummyTypeInfo.type==VarType){
    627                         if(DummyTypeInfo.type==DEF_OBJECT){
    628                             if(DummyTypeInfo.u.lpIndex!=lpVarIndex){
     724                    &lpVarIndex)){
     725
     726                        if(DummyTypeInfo.type!=DEF_ANY){
     727                            //型チェックを行う
     728                            if(DummyTypeInfo.type==VarType){
     729                                if(DummyTypeInfo.type==DEF_OBJECT){
     730                                    if(DummyTypeInfo.u.lpIndex!=lpVarIndex){
     731                                        SetError(11,Parms[i2],cp);
     732                                    }
     733                                }
     734                            }
     735                            else if((VarType&FLAG_PTR)&&((VarType^FLAG_PTR)==DummyTypeInfo.type)){
     736                                //仮引数がポインタ参照で、実引数が配列の先頭ポインタのとき
     737                            }
     738                            else{
    629739                                SetError(11,Parms[i2],cp);
    630740                            }
    631741                        }
    632                     }
    633                     else if((VarType&FLAG_PTR)&&((VarType^FLAG_PTR)==DummyTypeInfo.type)){
    634                         //仮引数がポインタ参照で、実引数が配列の先頭ポインタのとき
    635                     }
    636                     else{
    637                         SetError(11,Parms[i2],cp);
    638                     }
    639                 }
    640 
    641                 //変数アドレスをレジスタにセット
    642                 SetVarPtrToReg(reg,&RelativeVar);
     742
     743                        //変数アドレスをレジスタにセット
     744                        SetVarPtrToReg(reg,&RelativeVar);
     745
     746                }
     747                else{
     748                    //一時オブジェクトをコピー
     749
     750                    //mov reg, qword ptr[rsp+offset]
     751                    pobj_sf->ref_offset_data( reg, StackOffsetOfTempObject[i2] );
     752
     753                    //VarType = NumOpe( &reg, Parms[i2], DummyTypeInfo.type, DummyTypeInfo.u.lpIndex, &lpVarIndex );
     754                }
    643755            }
    644756        }
Note: See TracChangeset for help on using the changeset viewer.