Ignore:
Timestamp:
Apr 16, 2007, 3:52:40 AM (17 years ago)
Author:
dai_9181
Message:

関数の戻り値オブジェクトのメンバ・メソッドを一時オブジェクトを介さずに参照できるようにした。

File:
1 edited

Legend:

Unmodified
Added
Removed
  • BasicCompiler_Common/NumOpe_GetType.cpp

    r96 r97  
    294294}
    295295
     296bool GetTermType( const char *term, Type &resultType, bool &isLiteral, bool *pIsClassName = NULL ){
     297    char parameter[VN_SIZE];
     298
     299    // Withを解決
     300    char termFull[VN_SIZE];
     301    if(term[0]=='.'){
     302        GetWithName(termFull);
     303        lstrcat(termFull,term);
     304    }
     305    else lstrcpy(termFull,term);
     306
     307    char termLeft[VN_SIZE];
     308    lstrcpy(termLeft,termFull);
     309
     310    // パース
     311    char member[VN_SIZE];
     312    CClass::RefType refType;
     313    if( SplitMemberName( termFull, termLeft, member, refType ) ){
     314        ///////////////////////////////////////////////////////////////////
     315        // オブジェクトとメンバに分解できるとき
     316        // termLeft.member
     317        ///////////////////////////////////////////////////////////////////
     318
     319        isLiteral = false;
     320
     321        // オブジェクト側の型を取得
     322        bool isClassName = false;
     323        Type leftType;
     324        if( !GetTermType( termLeft, leftType, isLiteral, &isClassName ) ){
     325            return false;
     326        }
     327
     328        if( isClassName ){
     329            // 静的メンバ/メソッドの場合
     330            goto globalArea;
     331        }
     332
     333        if( !leftType.HasMember() ){
     334            // メンバを持たない型の場合
     335            return false;
     336        }
     337
     338        const CClass &objClass = leftType.GetClass();
     339
     340
     341        ///////////////////////////////////////////////////////////////////
     342        // メンバを検索
     343        ///////////////////////////////////////////////////////////////////
     344        if( GetMemberType( objClass, member, resultType, 0, false ) ){
     345            // メンバが見つかったとき
     346            return true;
     347        }
     348
     349
     350        ///////////////////////////////////////////////////////////////////
     351        // 動的メソッドを検索
     352        ///////////////////////////////////////////////////////////////////
     353        vector<UserProc *> userProcs;
     354
     355        char methodName[VN_SIZE] ,lpPtrOffset[VN_SIZE];
     356        lstrcpy( methodName, member );
     357        GetVarFormatString(methodName,parameter,lpPtrOffset,member,refType);
     358
     359        objClass.EnumMethod( methodName, userProcs );
     360        UserProc *pUserProc;
     361        if(userProcs.size()){
     362            //オーバーロードを解決
     363            pUserProc=OverloadSolutionWithStrParam(termFull,userProcs,parameter,termLeft);
     364
     365            if( pUserProc ){
     366                resultType = pUserProc->ReturnType();
     367                return true;
     368            }
     369        }
     370
     371        return false;
     372    }
     373
     374
     375    //////////////////////////////////////////////
     376    // クラス名かどうかをチェック(静的メンバ用)
     377    //////////////////////////////////////////////
     378
     379    if( pIsClassName ){
     380        if( pobj_DBClass->check( termFull ) ){
     381            *pIsClassName = true;
     382            return true;
     383        }
     384    }
     385
     386
     387    /////////////////////////////////////////////////////////////////
     388    // グローバル属性
     389    /////////////////////////////////////////////////////////////////
     390globalArea:
     391
     392
     393    if(lstrcmpi(termFull,"This")==0){
     394        //Thisオブジェクト
     395        resultType.SetType( DEF_OBJECT, pobj_CompilingClass );
     396        return true;
     397    }
     398
     399
     400    //////////////////////////////////////
     401    // 関数(DLL、ユーザー定義、組み込み)
     402    //////////////////////////////////////
     403    char procName[VN_SIZE];
     404    char temporary[8192];
     405
     406    int i2=GetCallProcName(termFull,procName);
     407    if(termFull[i2]=='('){
     408        int i4=GetStringInPare_RemovePare(parameter,termFull+i2+1);
     409
     410        void *pProc;
     411        int idProc=GetProc(procName,(void **)&pProc);
     412
     413        if(idProc){
     414            //閉じカッコ")"に続く文字がNULLでないとき
     415            if(termFull[i2+1+i4+1]!='\0'){
     416                SetError(42,NULL,cp);
     417            }
     418
     419
     420            ////////////////
     421            // 呼び出し
     422            ////////////////
     423
     424            if( !CallProc(idProc,pProc,procName,parameter, resultType, false ) ){
     425                return false;
     426            }
     427            if( resultType.IsNull() ){
     428                //戻り値が存在しないとき
     429                return false;
     430            }
     431
     432            isLiteral = false;
     433
     434            return true;
     435        }
     436        else if(GetConstCalcBuffer(procName,parameter,temporary)){
     437            /////////////////////////
     438            // マクロ関数
     439            /////////////////////////
     440
     441            //閉じカッコ")"に続く文字がNULLでないときはエラーにする
     442            if(termFull[i2+1+i4+1]!='\0') SetError(42,NULL,cp);
     443
     444            //マクロ関数の場合
     445            if( !NumOpe_GetType(temporary,Type(),resultType) ){
     446                return false;
     447            }
     448
     449            if( !IS_LITERAL( resultType.GetIndex() ) ){
     450                //リテラル値ではなかったとき
     451                isLiteral = false;
     452            }
     453
     454            return true;
     455        }
     456    }
     457
     458
     459    ////////////////////////////////
     460    // インデクサ(getアクセサ)
     461    ////////////////////////////////
     462
     463    char VarName[VN_SIZE],ArrayElements[VN_SIZE];
     464    GetArrayElement(termFull,VarName,ArrayElements);
     465    if(ArrayElements[0]){
     466        GetVarType(VarName,resultType,false);
     467        if( resultType.IsObject() ){
     468            if( !GetReturnTypeOfIndexerGetterProc( resultType.GetClass(),resultType) ){
     469                SetError(1,NULL,cp);
     470                return false;
     471            }
     472
     473            isLiteral = false;
     474
     475            return true;
     476        }
     477    }
     478
     479
     480    ////////////////////////////////
     481    // 変数
     482    ////////////////////////////////
     483
     484    if( GetVarType( termFull, resultType, false ) ){
     485        if( resultType.GetBasicType() & FLAG_PTR ){
     486            //配列ポインタ
     487            resultType.SetBasicType( GetPtrType( resultType.GetBasicType()^FLAG_PTR ) );
     488        }
     489
     490        isLiteral = false;
     491
     492        return true;
     493    }
     494
     495
     496    /////////////////////////////////
     497    // プロパティ用のメソッド
     498    /////////////////////////////////
     499
     500    //配列要素を排除
     501    GetArrayElement(termFull,VarName,ArrayElements);
     502
     503    if(GetSubHash(VarName,0)){
     504        GetReturnTypeOfPropertyMethod(termFull,NULL,resultType);
     505
     506        isLiteral = false;
     507
     508        return true;
     509    }
     510
     511
     512    return false;
     513}
     514
    296515bool NumOpe_GetType( const char *expression, const Type &baseType, Type &resultType ){
    297516    extern int cp;
    298     int i,i2,i3,i4;
    299     char temporary[1024],temp2[1024],temp3[1024];
     517    int i,i3;
    300518
    301519    if(expression[0]=='\0'){
     
    392610                term = values[i];
    393611
     612                if( calc[i+1]%100 == CALC_AS ){
     613                    // As演算子の右辺値
     614                    //型名
     615                    if( Type::StringToType( term, resultType ) ){
     616                        resultType.SetBasicType( resultType.GetBasicType() | FLAG_CAST );
     617                    }
     618                    else{
     619                        SetError(3, term, cp );
     620                        goto error;
     621                    }
     622
     623                    type_stack[sp] = resultType.GetBasicType();
     624                    index_stack[sp] = resultType.GetIndex();
     625                    sp++;
     626
     627                    break;
     628                }
     629
    394630                if(term[0]=='\"'){
    395631StrLiteral:
    396632
    397                     if( baseType.IsStringObject() ){
    398                         //要求タイプがオブジェクトであり、Stringの受け入れが可能な場合
     633                    if( baseType.IsObject() || baseType.IsNull() ){
     634                        //要求タイプがオブジェクト、または未定のとき
    399635                        extern CClass *pobj_StringClass;
    400636                        type_stack[sp]=DEF_OBJECT;
     
    421657                    // 何らかの識別子
    422658
    423                     //////////////////////////////////////
    424                     // 関数(DLL、ユーザー定義、組み込み)
    425                     //////////////////////////////////////
    426 
    427                     i2=GetCallProcName(term,temporary);
    428                     if(term[i2]=='('){
    429                         i4=GetStringInPare_RemovePare(temp2,term+i2+1);
    430 
    431                         int idProc;
    432                         void *pProc;
    433                         idProc=GetProc(temporary,(void **)&pProc);
    434 
    435                         if(idProc){
    436                             //閉じカッコ")"に続く文字がNULLでないとき
    437                             if(term[i2+1+i4+1]!='\0'){
    438                                 if( term[i2+1+i4+1] == '.'
    439                                     || term[i2+1+i4+1] == 1 && term[i2+1+i4+2] == ESC_PSMEM ){
    440                                         goto NonProc;
    441                                 }
    442                                 else{
    443                                     SetError(42,NULL,cp);
    444                                 }
    445                             }
    446 
    447 
    448                             ////////////////
    449                             // 呼び出し
    450                             ////////////////
    451 
    452                             Type resultType;
    453                             if( !CallProc(idProc,pProc,temporary,temp2, resultType, false ) ){
    454                                 goto error;
    455                             }
    456                             if( resultType.IsNull() ){
    457                                 //戻り値が存在しないとき
    458                                 goto error;
    459                             }
    460 
    461                             type_stack[sp] = resultType.GetBasicType();
    462                             index_stack[sp] = resultType.GetIndex();
    463 
     659                    bool isLiteral = true;
     660                    if( GetTermType( term, resultType, isLiteral ) ){
     661                        type_stack[sp] = resultType.GetBasicType();
     662                        index_stack[sp] = resultType.GetIndex();
     663
     664                        if( !isLiteral ){
    464665                            bLiteralCalculation=0;
    465 
    466                             sp++;
    467                             break;
    468666                        }
    469                         else if(GetConstCalcBuffer(temporary,temp2,temp3)){
    470                             /////////////////////////
    471                             // マクロ関数
    472                             /////////////////////////
    473 
    474                             //閉じカッコ")"に続く文字がNULLでないときはエラーにする
    475                             if(term[i2+1+i4+1]!='\0') SetError(42,NULL,cp);
    476 
    477                             //マクロ関数の場合
    478                             Type tempType;
    479                             NumOpe_GetType(temp3,Type(),tempType);
    480 
    481                             if(!IS_LITERAL(tempType.GetIndex())){
    482                                 //リテラル値ではなかったとき
    483                                 bLiteralCalculation=0;
    484                             }
    485 
    486                             type_stack[sp] = tempType.GetBasicType();
    487                             index_stack[sp] = tempType.GetIndex();
    488 
    489                             sp++;
    490                             break;
    491                         }
    492                     }
    493 NonProc:
    494 
    495                     //インデクサ(getアクセサ)
    496                     char VarName[VN_SIZE],ArrayElements[VN_SIZE];
    497                     GetArrayElement(term,VarName,ArrayElements);
    498                     if(ArrayElements[0]){
    499                         Type type;
    500                         GetVarType(VarName,type,false);
    501                         if( type.IsObject() ){
    502                             if( !GetReturnTypeOfIndexerGetterProc( type.GetClass(),type) ){
    503                                 SetError(1,NULL,cp);
    504                                 goto error;
    505                             }
    506                             type_stack[sp]=type.GetBasicType();
    507                             index_stack[sp]=type.GetIndex();
    508                             bLiteralCalculation=0;
    509 
    510                             sp++;
    511                             break;
    512                         }
     667
     668                        sp++;
     669                        break;
    513670                    }
    514671
     
    526683                        }
    527684                        bLiteralCalculation = 0;
    528                         sp++;
    529                         break;
    530                     }
    531 
    532                     if( (string)term == "s.GetType().Name" ){
    533                         int test=0;
    534                     }
    535 
    536 
    537                     Type varType;
    538                     if( GetVarType(term,varType,0) ){
    539                         //////////
    540                         // 変数
    541                         //////////
    542 
    543                         if( varType.GetBasicType() & FLAG_PTR ){
    544                             //配列ポインタ
    545                             type_stack[sp]=GetPtrType( varType.GetBasicType()^FLAG_PTR );
    546                         }
    547                         else{
    548                             type_stack[sp]=varType.GetBasicType();
    549                         }
    550                         index_stack[sp] = varType.GetIndex();
    551 
    552                         bLiteralCalculation=0;
    553685                        sp++;
    554686                        break;
     
    586718
    587719
    588                     //////////////
    589                     // 型名の場合
    590                     //////////////
    591 
    592                     Type tempType;
    593                     if( Type::StringToType( term, tempType ) ){
    594                         type_stack[sp] = tempType.GetBasicType() | FLAG_CAST;
    595                         index_stack[sp] = tempType.GetIndex();
    596                         sp++;
    597                         break;
    598                     }
    599 
    600 
    601720                    /////////////////////////////////
    602721                    // プロパティ用のメソッド
     
    604723
    605724                    //配列要素を排除
     725                    char VarName[VN_SIZE],ArrayElements[VN_SIZE];
    606726                    GetArrayElement(term,VarName,ArrayElements);
    607727
    608728                    if(GetSubHash(VarName,0)){
     729                        SetError();
    609730                        Type tempType;
    610731                        GetReturnTypeOfPropertyMethod(term,NULL,tempType);
Note: See TracChangeset for help on using the changeset viewer.