Ignore:
Timestamp:
Mar 20, 2007, 4:36:16 AM (17 years ago)
Author:
dai_9181
Message:

TYPEINFO→Typeへのリファクタリングを実施。64bitはほぼ完了。32bitが全般的に未完成。

File:
1 edited

Legend:

Unmodified
Added
Removed
  • BasicCompiler_Common/NumOpe_GetType.cpp

    r73 r75  
    2828    type=CalcType;
    2929
    30     if(!BaseType){
     30    if(BaseType==0||BaseType==-1){
    3131        //ベースタイプが未定のとき
    3232        return type;
     
    3838    }
    3939
    40     if(BaseType==DEF_OBJECT){
     40    if(BaseType==DEF_OBJECT||BaseType==DEF_STRUCT){
    4141        //ベースタイプがオブジェクトのときは暗黙の変換は必要なし
    4242        return type;
     
    188188}
    189189
    190 int GetReturnType_OperatorProc(int idCalc,TYPEINFO *pBaseTypeInfo,int *type,LONG_PTR *index_stack,int &sp){
     190int GetReturnType_OperatorProc(int idCalc,const Type &baseType,int *type,LONG_PTR *index_stack,int &sp){
    191191    //オーバーロードされたオペレータ関数の戻り値を取得
    192192    CClass *pobj_c;
    193193    pobj_c=(CClass *)index_stack[sp-2];
    194194
    195     std::vector<SubInfo *> subs;
     195    std::vector<UserProc *> subs;
    196196    pobj_c->EnumMethod( idCalc, subs );
    197197    if( subs.size() == 0 ){
     
    212212
    213213    //_System_LocalThis
    214     PARAMETER_INFO *ppi = (PARAMETER_INFO *)HeapAlloc(hHeap,0,sizeof(PARAMETER_INFO)*3);
    215     int iParmNum=0;
     214    Parameters params;
    216215
    217216    if(bTwoTerm){
    218         ppi[iParmNum].bArray=0;
    219         ppi[iParmNum].bByVal=0;
    220         ppi[iParmNum].name=0;
    221         ppi[iParmNum].type=type[sp-1];
    222         ppi[iParmNum].u.index=index_stack[sp-1];
    223         ppi[iParmNum].SubScripts[0]=-1;
    224         iParmNum++;
     217        params.push_back( new Parameter( "", Type( type[sp-1], index_stack[sp-1] ) ) );
    225218    }
    226219
     
    230223    if(idCalc==CALC_EQUAL) lstrcpy(temporary,"==");
    231224    else GetCalcName(idCalc,temporary);
    232     SubInfo *psi;
    233     psi=OverloadSolution(temporary,subs,ppi,iParmNum,pBaseTypeInfo);
    234 
    235 
    236     if(!psi){
    237         HeapDefaultFree(ppi);
     225    UserProc *pUserProc = OverloadSolution( temporary, subs, params, baseType );
     226
     227    if(bTwoTerm){
     228        delete params[0];
     229    }
     230
     231    if(!pUserProc){
    238232        return 0;
    239233    }
    240234    else{
    241235        //オーバーロードされていないが、パラメータ個数が一致しないとき
    242         if(iParmNum!=psi->params.size()){
    243             HeapDefaultFree(ppi);
     236        if(params.size()!=pUserProc->Params().size()){
    244237            return 0;
    245238        }
    246239    }
    247240
    248     HeapDefaultFree(ppi);
    249 
    250241    sp--;
    251     type[sp-1]=psi->ReturnType;
    252     index_stack[sp-1]=psi->u.ReturnIndex;
     242    type[sp-1]=pUserProc->ReturnType().GetBasicType();
     243    index_stack[sp-1]=pUserProc->ReturnType().GetIndex();
    253244
    254245    return 1;
    255246}
    256247
    257 int Operator_New_GetType(const char *Parameter,LONG_PTR *plpIndex,const TYPEINFO &baseTypeInfo ){
     248bool Operator_New_GetType(const char *Parameter,const Type &baseType, Type &resultType ){
    258249    char TypeName[VN_SIZE],CreateParameter[VN_SIZE],objectSizeStr[VN_SIZE];
    259250    int i,i2;
     
    279270            if(Parameter[i]!='\0'){
    280271                SetError(42,NULL,cp);
    281                 return 0;
     272                return false;
    282273            }
    283274            break;
     
    290281    }
    291282
    292     int type;
    293     type=GetTypeFixed(TypeName,plpIndex);
    294 
    295     if( baseTypeInfo.type == DEF_OBJECT ){
    296         return DEF_OBJECT;
    297     }
    298     return DEF_PTR_OBJECT;
     283    if( !Type::StringToType( TypeName, resultType ) ){
     284        return false;
     285    }
     286
     287    if( baseType.IsObject() ){
     288        resultType.SetBasicType( DEF_OBJECT );
     289    }
     290    else{
     291        resultType.SetBasicType( DEF_PTR_OBJECT );
     292    }
     293    return true;
    299294}
    300295
    301 int NumOpe_GetType_Old( const char *Command,TYPEINFO *pBaseType,LONG_PTR *plpIndex){
     296bool NumOpe_GetType( const char *expression, const Type &baseType, Type &resultType ){
    302297    extern int cp;
    303298    int i,i2,i3,i4;
    304299    char temporary[1024],temp2[1024],temp3[1024];
    305300
    306     if(Command[0]=='\0'){
     301    if(expression[0]=='\0'){
    307302        SetError(1,NULL,cp);
    308         return 0;
    309     }
    310 
    311     if(Command[0]==1&& Command[1]==ESC_NEW ){
     303        return false;
     304    }
     305
     306    if(expression[0]==1&& expression[1]==ESC_NEW ){
    312307        //New演算子(オブジェクト生成)
    313         return Operator_New_GetType(Command+2,plpIndex, *pBaseType );
     308        return Operator_New_GetType(expression+2,baseType, resultType );
    314309    }
    315310
     
    323318    long stack[255];
    324319    int pnum;
    325     if(!GetNumOpeElements(Command,&pnum,values,calc,stack)){
     320    if(!GetNumOpeElements(expression,&pnum,values,calc,stack)){
    326321        for(i=0;i<pnum;i++){
    327322            if(values[i]) HeapDefaultFree(values[i]);
    328323        }
    329         return 0;
     324        return false;
    330325    }
    331326
     
    343338
    344339    int sp;
    345     int type[255];
     340    int type_stack[255];
    346341    LONG_PTR index_stack[255];
    347342    _int64 i64data;
     
    351346
    352347        if(idCalc){
    353             if(type[sp-2]==DEF_OBJECT){
     348            if(type_stack[sp-2]==DEF_OBJECT){
    354349                //オーバーロードされたオペレータを呼び出す
    355                 if(!GetReturnType_OperatorProc(idCalc,pBaseType,type,index_stack,sp)){
     350                if(!GetReturnType_OperatorProc(idCalc,baseType,type_stack,index_stack,sp)){
    356351                    goto error;
    357352                }
     
    360355            }
    361356
    362             if(!CheckCalcType(idCalc,type,sp)) goto error;
     357            if(!CheckCalcType(idCalc,type_stack,sp)) goto error;
    363358        }
    364359
     
    374369StrLiteral:
    375370
    376                     if(pBaseType){
    377                         if(pBaseType->type==DEF_OBJECT){
    378                             if(IsStringObjectType(*pBaseType)){
    379                                 //要求タイプがオブジェクトであり、Stringの受け入れが可能な場合
    380                                 extern CClass *pobj_StringClass;
    381                                 type[sp]=DEF_OBJECT;
    382                                 index_stack[sp]=(LONG_PTR)pobj_StringClass;
    383                                 bLiteralCalculation=0;
    384 
    385                                 sp++;
    386                                 break;
    387                             }
    388                         }
     371                    if( baseType.IsStringObject() ){
     372                        //要求タイプがオブジェクトであり、Stringの受け入れが可能な場合
     373                        extern CClass *pobj_StringClass;
     374                        type_stack[sp]=DEF_OBJECT;
     375                        index_stack[sp]=(LONG_PTR)pobj_StringClass;
     376                        bLiteralCalculation=0;
     377
     378                        sp++;
     379                        break;
    389380                    }
    390381
    391                     type[sp]=typeOfPtrChar;
     382                    type_stack[sp]=typeOfPtrChar;
    392383                    bLiteralCalculation=0;
    393384                }
     
    413404
    414405                        int idProc;
    415                         void *pInfo;
    416                         idProc=GetProc(temporary,&pInfo);
     406                        void *pProc;
     407                        idProc=GetProc(temporary,(void **)&pProc);
    417408
    418409                        if(idProc){
     
    433424                            ////////////////
    434425
    435                             i2=GetReturnTypeOfProc(idProc,pInfo,temporary,temp2,&index_stack[sp]);
    436                             if(i2==-1){
     426                            Type resultType;
     427                            if( !CallProc(idProc,pProc,temporary,temp2, resultType, false ) ){
     428                                goto error;
     429                            }
     430                            if( resultType.IsNull() ){
    437431                                //戻り値が存在しないとき
    438432                                goto error;
    439433                            }
    440434
    441                             type[sp]=i2;
     435                            type_stack[sp] = resultType.GetBasicType();
     436                            index_stack[sp] = resultType.GetIndex();
     437
    442438                            bLiteralCalculation=0;
    443439
     
    454450
    455451                            //マクロ関数の場合
    456                             i2=NumOpe_GetType_Old(temp3,NULL,&index_stack[sp]);
    457 
    458                             if(!IS_LITERAL(index_stack[sp])){
     452                            Type tempType;
     453                            NumOpe_GetType(temp3,Type(),tempType);
     454
     455                            if(!IS_LITERAL(tempType.GetIndex())){
    459456                                //リテラル値ではなかったとき
    460457                                bLiteralCalculation=0;
    461458                            }
    462459
    463                             type[sp]=i2;
     460                            type_stack[sp] = tempType.GetBasicType();
     461                            index_stack[sp] = tempType.GetIndex();
    464462
    465463                            sp++;
     
    473471                    GetArrayElement(term,VarName,ArrayElements);
    474472                    if(ArrayElements[0]){
    475                         CClass *pobj_c;
    476                         i2=GetVarType(VarName,(LONG_PTR *)&pobj_c,0);
    477                         if(i2==DEF_OBJECT){
    478                             TYPEINFO RetTypeInfo;
    479                             if( !GetReturnTypeOfIndexerGetterProc(pobj_c,RetTypeInfo) ){
     473                        Type type;
     474                        GetVarType(VarName,type,false);
     475                        if( type.IsObject() ){
     476                            if( !GetReturnTypeOfIndexerGetterProc( type.GetClass(),type) ){
    480477                                SetError(1,NULL,cp);
    481478                                goto error;
    482479                            }
    483                             type[sp]=RetTypeInfo.type;
    484                             index_stack[sp]=RetTypeInfo.u.lpIndex;
     480                            type_stack[sp]=type.GetBasicType();
     481                            index_stack[sp]=type.GetIndex();
    485482                            bLiteralCalculation=0;
    486483
     
    493490                    // Nothing
    494491                    if( lstrcmp( term, "Nothing" ) == 0 ){
    495                         type[sp] = DEF_OBJECT;
    496                         if( pBaseType && pBaseType->type == DEF_OBJECT ){
    497                             index_stack[sp] = pBaseType->u.lpIndex;
     492                        type_stack[sp] = DEF_OBJECT;
     493                        if( baseType.IsObject() ){
     494                            index_stack[sp] = baseType.GetIndex();
    498495                        }
    499496                        else{
     
    506503
    507504
    508                     i2=GetVarType(term,&index_stack[sp],0);
    509                     if(i2!=-1){
     505                    Type varType;
     506                    if( GetVarType(term,varType,0) ){
    510507                        //////////
    511508                        // 変数
    512509                        //////////
    513510
    514                         if(i2&FLAG_PTR){
     511                        if( varType.GetBasicType() & FLAG_PTR ){
    515512                            //配列ポインタ
    516                             type[sp]=GetPtrType(i2^FLAG_PTR,index_stack[sp]);
     513                            type_stack[sp]=GetPtrType( varType.GetBasicType()^FLAG_PTR );
    517514                        }
    518515                        else{
    519                             type[sp]=i2;
    520                         }
     516                            type_stack[sp]=varType.GetBasicType();
     517                        }
     518                        index_stack[sp] = varType.GetIndex();
    521519
    522520                        bLiteralCalculation=0;
     
    532530                    i3 = CDBConst::obj.GetType(term);
    533531                    if(i3){
    534                         type[sp]=i3;
     532                        type_stack[sp]=i3;
    535533                        if(IsRealNumberType(i3)){
    536534                            //実数
     
    563561                    i3=GetTypeFixed(term,&lp);
    564562                    if(i3!=-1){
    565                         type[sp]=i3|FLAG_CAST;
     563                        type_stack[sp]=i3|FLAG_CAST;
    566564                        index_stack[sp]=lp;
    567565                        sp++;
     
    579577
    580578                    if(GetSubHash(VarName,0)){
    581                         TYPEINFO RetTypeInfo;
    582                         GetReturnTypeOfPropertyMethod(term,NULL,&RetTypeInfo);
     579                        Type tempType;
     580                        GetReturnTypeOfPropertyMethod(term,NULL,tempType);
    583581
    584582                        //大きな型への暗黙の変換
    585                         type[sp]=RetTypeInfo.type;
    586 
    587                         index_stack[sp]=RetTypeInfo.u.lpIndex;
     583                        type_stack[sp]=tempType.GetBasicType();
     584
     585                        index_stack[sp]=tempType.GetIndex();
    588586                        bLiteralCalculation=0;
    589587
     
    597595                    bError=1;
    598596                    SetError(3,term,cp);
    599                     type[sp]=DEF_DOUBLE;
     597                    type_stack[sp]=DEF_DOUBLE;
    600598                }
    601599                else{
    602600                    //リテラル値
    603                     int base_type;
    604                     base_type=0;
    605                     if(pBaseType) base_type=pBaseType->type;
    606                     type[sp]=GetLiteralValue(term,&i64data,base_type);
     601                    int base_type = 0;
     602                    if( !baseType.IsNull() ) base_type = baseType.GetBasicType();
     603                    type_stack[sp]=GetLiteralValue(term,&i64data,base_type);
    607604Literal:
    608605                    if((long)i64data==0&&index_stack[sp]==-1) index_stack[sp]=LITERAL_NULL;
     
    617614            case CALC_AND:
    618615                sp--;
    619                 type[sp-1]=NeutralizationType(type[sp-1],index_stack[sp-1],type[sp],index_stack[sp]);
     616                type_stack[sp-1]=NeutralizationType(type_stack[sp-1],index_stack[sp-1],type_stack[sp],index_stack[sp]);
    620617                break;
    621618            case CALC_NOT:
     
    632629            case CALC_EQUAL:    //values[sp-2] =  values[sp-1] 
    633630                sp--;
    634                 type[sp-1]=DEF_LONG;
     631                type_stack[sp-1]=DEF_LONG;
    635632                break;
    636633
     
    646643            case CALC_PRODUCT:
    647644                sp--;
    648                 type[sp-1]=NeutralizationType(type[sp-1],index_stack[sp-1],type[sp],index_stack[sp]);
     645                type_stack[sp-1]=NeutralizationType(type_stack[sp-1],index_stack[sp-1],type_stack[sp],index_stack[sp]);
    649646                break;
    650647            case CALC_MOD:
     
    652649                //剰余演算
    653650                sp--;
    654                 type[sp-1]=NeutralizationType(type[sp-1],index_stack[sp-1],type[sp],index_stack[sp]);
     651                type_stack[sp-1]=NeutralizationType(type_stack[sp-1],index_stack[sp-1],type_stack[sp],index_stack[sp]);
    655652                break;
    656653            case CALC_QUOTIENT:
     
    658655                //除算
    659656                sp--;
    660                 type[sp-1]=NeutralizationType(type[sp-1],index_stack[sp-1],type[sp],index_stack[sp]);
     657                type_stack[sp-1]=NeutralizationType(type_stack[sp-1],index_stack[sp-1],type_stack[sp],index_stack[sp]);
    661658                break;
    662659            case CALC_INTQUOTIENT:
     
    664661                //整数除算
    665662                sp--;
    666                 type[sp-1]=NeutralizationType(type[sp-1],index_stack[sp-1],type[sp],index_stack[sp]);
     663                type_stack[sp-1]=NeutralizationType(type_stack[sp-1],index_stack[sp-1],type_stack[sp],index_stack[sp]);
    667664                break;
    668665            case CALC_MINUSMARK:
     
    677674            case CALC_AS:
    678675                //キャスト
    679                 type[sp-2]=type[sp-1]&(~FLAG_CAST);
     676                type_stack[sp-2]=type_stack[sp-1]&(~FLAG_CAST);
    680677                index_stack[sp-2]=index_stack[sp-1];
    681678
     
    685682            case CALC_BYVAL:
    686683                //ポインタ型→参照型
    687                 if( PTR_LEVEL( type[sp-1] ) <= 0 ){
     684                if( PTR_LEVEL( type_stack[sp-1] ) <= 0 ){
    688685                    //ポインタ型ではないとき
    689686                    SetError( 3, NULL, cp );
     
    691688                }
    692689
    693                 type[sp-1] = PTR_LEVEL_DOWN( type[sp-1] );
     690                type_stack[sp-1] = PTR_LEVEL_DOWN( type_stack[sp-1] );
    694691                break;
    695692        }
     
    705702    if(bLiteralCalculation){
    706703        //右辺値が数値の定数式の場合
    707         LONG_PTR lpCalcIndex;
    708         int base_type=0;
    709         if(pBaseType) base_type=pBaseType->type;
    710         i2=StaticCalculation(true, Command,base_type,&i64data,&lpCalcIndex);
    711 
    712         type[0]=i2;
    713         index_stack[0]=lpCalcIndex;
     704        int base_type = 0;
     705        if( !baseType.IsNull() ) base_type = baseType.GetBasicType();
     706        Type tempType;
     707        StaticCalculation(true, expression,base_type,&i64data,tempType);
     708
     709        type_stack[0]=tempType.GetBasicType();
     710        index_stack[0]=tempType.GetIndex();
    714711    }
    715712    else{
     
    718715    }
    719716
    720     if(plpIndex) *plpIndex=index_stack[0];
    721 
    722     int RetType;
    723     RetType=type[0];
     717    resultType.SetType( type_stack[0], index_stack[0] );
     718
     719    bool isSuccessful = true;
    724720    goto finish;
    725721
     
    730726
    731727error:
    732     RetType=-1;
     728    isSuccessful = false;
    733729    goto finish;
    734730
     
    738734        if(values[i]) HeapDefaultFree(values[i]);
    739735    }
    740     return RetType;
     736    return isSuccessful;
    741737}
    742 
    743 bool NumOpe_GetType( const char *expression, const Type &baseType, Type &resultType ){
    744     TYPEINFO baseTypeInfo = {
    745         baseType.GetBasicType(),
    746         baseType.GetIndex()
    747     };
    748     LONG_PTR lpIndex;
    749     int basicType = NumOpe_GetType_Old( expression,
    750         baseType.IsNull() ? NULL:&baseTypeInfo,
    751         &lpIndex );
    752 
    753     resultType.SetBasicType( basicType );
    754     resultType.SetIndex( lpIndex );
    755 
    756     return ( basicType != -1 );
    757 }
Note: See TracChangeset for help on using the changeset viewer.