Changeset 50 in dev for BasicCompiler_Common


Ignore:
Timestamp:
Feb 10, 2007, 5:44:58 PM (17 years ago)
Author:
dai_9181
Message:

オーバーロード解決用の関数保持リストを "SUBINFO " ではなく、"vector<SUBINFO *>" に変更した。

Location:
BasicCompiler_Common
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • BasicCompiler_Common/Class.cpp

    r46 r50  
    142142                cp=pobj_c->ppobj_StaticMember[i]->source_code_address;
    143143
    144                 CallConstractor(temporary,
     144                CallConstructor(temporary,
    145145                    pobj_c->ppobj_StaticMember[i]->SubScripts,
    146146                    pobj_c->ppobj_StaticMember[i]->TypeInfo,
     
    225225    }
    226226
    227     if(ppobj_StaticMethod){
    228         //静的メソッド
    229         for(i=0;i<iStaticMethodNum;i++){
    230             delete ppobj_StaticMethod[i];
    231         }
    232         HeapDefaultFree(ppobj_StaticMethod);
    233         ppobj_StaticMethod=0;
     227    foreach( CMethod *method, StaticMethods ){
     228        delete method;
    234229    }
    235230}
     
    306301}
    307302void CClass::AddStaticMethod(SUBINFO *psi,DWORD dwAccess){
    308     ppobj_StaticMethod=(CMethod **)HeapReAlloc(hHeap,0,ppobj_StaticMethod,(iStaticMethodNum+1)*sizeof(CMethod *));
    309     ppobj_StaticMethod[iStaticMethodNum]=new CMethod();
    310     ppobj_StaticMethod[iStaticMethodNum]->psi=psi;
    311     ppobj_StaticMethod[iStaticMethodNum]->dwAccess=dwAccess;
    312     ppobj_StaticMethod[iStaticMethodNum]->bAbstract=0;
    313     ppobj_StaticMethod[iStaticMethodNum]->bVirtual=0;
    314     ppobj_StaticMethod[iStaticMethodNum]->pobj_InheritsClass=0;
    315 
    316     iStaticMethodNum++;
     303    CMethod *method = new CMethod();
     304    method->psi=psi;
     305    method->dwAccess=dwAccess;
     306    method->bAbstract=0;
     307    method->bVirtual=0;
     308    method->pobj_InheritsClass=0;
     309
     310    StaticMethods.push_back( method );
    317311}
    318312BOOL CClass::DupliCheckAll(const char *name){
     
    355349}
    356350CMethod *CClass::GetMethodInfo( SUBINFO *psi ){
    357     int i;
    358     for( i=0; i<iMethodNum; i++ ){
    359         if( psi == ppobj_Method[i]->psi ) break;
    360     }
    361     if( i == iMethodNum ){
    362         return NULL;
    363     }
    364     return ppobj_Method[i];
     351    for( int i=iMethodNum-1; i>=0; i-- ){
     352        if( psi == ppobj_Method[i]->psi ) return ppobj_Method[i];
     353    }
     354    return NULL;
    365355}
    366356CMethod *CClass::GetStaticMethodInfo( SUBINFO *psi ){
    367     int i;
    368     for( i=0; i<iStaticMethodNum; i++ ){
    369         if( psi == ppobj_StaticMethod[i]->psi ) break;
    370     }
    371     if( i == iStaticMethodNum ){
    372         return NULL;
    373     }
    374     return ppobj_StaticMethod[i];
     357    for( int i=(int)StaticMethods.size()-1; i>=0; i-- ){
     358        if( psi == StaticMethods[i]->psi ) return StaticMethods[i];
     359    }
     360    return NULL;
    375361}
    376362bool CClass::IsExistMethod( const char *name ){
     
    381367}
    382368bool CClass::IsExistStaticMethod( const char *name ){
    383     for( int i=0; i<iStaticMethodNum; i++ ){
    384         if( lstrcmp( ppobj_StaticMethod[i]->psi->name, name ) == 0 ) return true;
     369    foreach( CMethod *method, StaticMethods ){
     370        if( lstrcmp( method->psi->name, name ) == 0 ) return true;
    385371    }
    386372    return false;
     373}
     374
     375void CClass::EnumStaticMethod( const char *methodName, std::vector<SUBINFO *> &subs ) const
     376{
     377    foreach( CMethod *method, StaticMethods ){
     378        if(lstrcmp(methodName,method->psi->name)==0){
     379            subs.push_back( method->psi );
     380        }
     381    }
     382}
     383
     384void CClass::EnumMethod( const char *methodName, std::vector<SUBINFO *> &subs ) const
     385{
     386    //オブジェクトのメンバ関数の場合
     387    //※オーバーライドされた関数を先にサーチする必要があるため、バックサーチを行う
     388    for(int i=iMethodNum-1;i>=0;i--){
     389        if(lstrcmp(name,ppobj_Method[i]->psi->name)==0){
     390            subs.push_back( ppobj_Method[i]->psi );
     391        }
     392    }
     393}
     394
     395void CClass::EnumMethod( const BYTE idOperatorCalc, std::vector<SUBINFO *> &subs ) const
     396{
     397    for(int i=0;i<iMethodNum;i++){
     398        char *temp;
     399        temp=ppobj_Method[i]->psi->name;
     400        if(temp[0]==1&&temp[1]==ESC_OPERATOR){
     401            if((BYTE)temp[2]==idOperatorCalc){
     402                subs.push_back( ppobj_Method[i]->psi );
     403            }
     404        }
     405    }
    387406}
    388407
     
    465484
    466485    return false;
    467 }
    468 
    469 
    470 SUBINFO **CClass::GetOperatorSubInfo(BYTE idCalc,int &num){
    471     //格納のための構造体配列を用意
    472     SUBINFO **ppArray_si;
    473     ppArray_si=(SUBINFO **)HeapAlloc(hHeap,0,sizeof(SUBINFO *)*1024);
    474     num=0;
    475 
    476     int i;
    477     for(i=0;i<iMethodNum;i++){
    478         char *temp;
    479         temp=ppobj_Method[i]->psi->name;
    480         if(temp[0]==1&&temp[1]==ESC_OPERATOR){
    481             if((BYTE)temp[2]==idCalc){
    482                 ppArray_si[num]=ppobj_Method[i]->psi;
    483                 num++;
    484             }
    485         }
    486     }
    487 
    488     return ppArray_si;
    489486}
    490487
     
    895892            pobj_c->ppobj_Method=(CMethod **)HeapAlloc(hHeap,0,1);
    896893            pobj_c->iMethodNum=0;
    897             pobj_c->ppobj_StaticMethod=(CMethod **)HeapAlloc(hHeap,0,1);
    898             pobj_c->iStaticMethodNum=0;
    899894
    900895            pobj_c->ConstructorMemberSubIndex=-1;
     
    10571052            pobj_c->ppobj_Method=(CMethod **)HeapAlloc(hHeap,0,1);
    10581053            pobj_c->iMethodNum=0;
    1059             pobj_c->ppobj_StaticMethod=(CMethod **)HeapAlloc(hHeap,0,1);
    1060             pobj_c->iStaticMethodNum=0;
    10611054
    10621055            pobj_c->ConstructorMemberSubIndex=-1;
  • BasicCompiler_Common/Class.h

    r46 r50  
    1 
     1#include <vector>
    22
    33class CClass;
     
    6161};
    6262class CClass{
     63    //静的メソッド情報
     64    std::vector<CMethod *> StaticMethods;
     65
    6366public:
    6467    //クラス名
     
    8386    int iStaticMemberNum;
    8487
    85     //静的メソッド情報
    86     CMethod **ppobj_StaticMethod;
    87     int iStaticMethodNum;
    88 
    8988    //仮想関数の数
    9089    int vtbl_num;
     
    117116    bool IsExistStaticMethod( const char *name );
    118117
     118    //メソッドを列挙
     119    void EnumStaticMethod( const char *methodName, std::vector<SUBINFO *> &subs ) const;
     120    void EnumMethod( const char *methodName, std::vector<SUBINFO *> &subs ) const;
     121    void EnumMethod( const BYTE idOperatorCalc, std::vector<SUBINFO *> &subs ) const;
     122
    119123
    120124    //vtbl
     
    126130    void ActionVtblSchedule(LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection);
    127131    bool IsAbstract();
    128 
    129 
    130     //オペレータ関数の取得
    131     SUBINFO **GetOperatorSubInfo(BYTE idCalc,int &num);
    132132
    133133
  • BasicCompiler_Common/NumOpe_GetType.cpp

    r49 r50  
    193193    pobj_c=(CClass *)index_stack[sp-2];
    194194
    195     SUBINFO **ppsi;
    196     int num;
    197     ppsi=pobj_c->GetOperatorSubInfo(idCalc,num);
    198     if(num==0){
    199         HeapDefaultFree(ppsi);
    200 
     195    std::vector<SUBINFO *> subs;
     196    pobj_c->EnumMethod( idCalc, subs );
     197    if( subs.size() == 0 ){
    201198        return 0;
    202199    }
     
    234231    else GetCalcName(idCalc,temporary);
    235232    SUBINFO *psi;
    236     psi=OverloadSolution(temporary,ppsi,num,ppi,iParmNum,pBaseTypeInfo);
    237     HeapDefaultFree(ppsi);
     233    psi=OverloadSolution(temporary,subs,ppi,iParmNum,pBaseTypeInfo);
     234
    238235
    239236    if(!psi){
  • BasicCompiler_Common/Object.cpp

    r40 r50  
    113113
    114114
    115 void CallConstractor(char *ObjectName,int *SubScripts,TYPEINFO &TypeInfo,char *Parameter){
     115void CallConstructor(char *ObjectName,int *SubScripts,TYPEINFO &TypeInfo,char *Parameter){
    116116    if(TypeInfo.type!=DEF_OBJECT) return;
    117117
  • BasicCompiler_Common/Overload.cpp

    r46 r50  
    77#endif
    88
    9 SUBINFO *OverloadSolutionWithStrParam(char *name,SUBINFO **ppsi,int num,char *Parameter,char *ObjectName,TYPEINFO *pReturnTypeInfo){
    10     // オーバーロードの解決
     9SUBINFO *OverloadSolutionWithStrParam(
     10    const char *name,
     11    std::vector<SUBINFO *> &subs,
     12    const char *Parameter,
     13    const char *ObjectName,
     14    TYPEINFO *pReturnTypeInfo){
    1115
    12     //オーバーロードされていないとき
    13     if(num==1) return ppsi[0];
     16        // オーバーロードの解決
     17
     18        //オーバーロードされていないとき
     19        if( subs.size() == 1 ) return subs[0];
    1420
    1521
    16     ////////////////////////
    17     // パラメータをセット
    18     ////////////////////////
     22        ////////////////////////
     23        // パラメータをセット
     24        ////////////////////////
    1925
    20     CParameter *pobj_parameter=0;
     26        CParameter *pobj_parameter=0;
    2127
    22     char MethodName[VN_SIZE];
    23     if( !SplitMemberName( name, NULL, MethodName ) ) lstrcpy( MethodName, name );
     28        char MethodName[VN_SIZE];
     29        if( !SplitMemberName( name, NULL, MethodName ) ) lstrcpy( MethodName, name );
    2430
    25     //メソッドの場合は静的かどうかを調べる
    26     bool isStatic = false;
    27     CClass *pClass = ppsi[0]->pobj_ParentClass;
    28     if( pClass ){
    29         isStatic = pClass->IsExistStaticMethod( MethodName );
    30     }
     31        //メソッドの場合は静的かどうかを調べる
     32        bool isStatic = false;
     33        CClass *pClass = subs[0]->pobj_ParentClass;
     34        if( pClass ){
     35            isStatic = pClass->IsExistStaticMethod( MethodName );
     36        }
    3137
    32     //パラメータオブジェクトを生成
    33     pobj_parameter=new CParameter(Parameter);
    34     if(pReturnTypeInfo) pobj_parameter->SetReturnType(pReturnTypeInfo);
     38        //パラメータオブジェクトを生成
     39        pobj_parameter=new CParameter(Parameter);
     40        if(pReturnTypeInfo) pobj_parameter->SetReturnType(pReturnTypeInfo);
    3541
    3642
    37     SUBINFO *psi;
    38     psi=pobj_parameter->OverloadSolution(name,ppsi,num);
     43        SUBINFO *psi;
     44        psi=pobj_parameter->OverloadSolution(name,subs);
    3945
    4046
    41     //パラメータオブジェクトを破棄
    42     delete pobj_parameter;
    43     pobj_parameter=0;
     47        //パラメータオブジェクトを破棄
     48        delete pobj_parameter;
     49        pobj_parameter=0;
    4450
    45     return psi;
     51        return psi;
    4652}
    4753
    48 SUBINFO *OverloadSolution(const char *name,SUBINFO **ppsi,int num,PARAMETER_INFO *ppi,int ParmNum,TYPEINFO *pReturnTypeInfo){
    49     // オーバーロードの解決
     54SUBINFO *OverloadSolution(
     55    const char *name,
     56    std::vector<SUBINFO *> &subs,
     57    const PARAMETER_INFO *ppi,
     58    const int ParmNum,
     59    TYPEINFO *pReturnTypeInfo){
    5060
    51     //オーバーロードされていないとき
    52     if(num==1) return ppsi[0];
     61        // オーバーロードの解決
     62
     63        //オーバーロードされていないとき
     64        if( subs.size() == 1 ) return subs[0];
    5365
    5466
    55     CParameter *pobj_Parameter=new CParameter(ppi,ParmNum);
    56     if(pReturnTypeInfo) pobj_Parameter->SetReturnType(pReturnTypeInfo);
     67        CParameter *pobj_Parameter=new CParameter(ppi,ParmNum);
     68        if(pReturnTypeInfo) pobj_Parameter->SetReturnType(pReturnTypeInfo);
    5769
    58     SUBINFO *psi;
    59     psi=pobj_Parameter->OverloadSolution(name,ppsi,num);
     70        SUBINFO *psi;
     71        psi=pobj_Parameter->OverloadSolution(name,subs);
    6072
    61     delete pobj_Parameter;
     73        delete pobj_Parameter;
    6274
    63     return psi;
     75        return psi;
    6476}
  • BasicCompiler_Common/Subroutine.cpp

    r46 r50  
    104104    return true;
    105105}
    106 int GetReturnTypeOfProc(int idProc,void *pInfo,char *name,char *Parameter,LONG_PTR *plpRetIndex){
     106
     107
     108int CallProc(int idProc,void *pInfo,char *name,char *Parameter,LONG_PTR *plpRetIndex){
    107109    int ret_type;
    108110
     
    129131        ////////////////////////
    130132
    131         SUBINFO **ppsi;
    132         int num;
    133         ppsi=GetOverloadSubHash(name,&num);
    134         if(num){
     133        std::vector<SUBINFO *> subs;
     134        GetOverloadSubHash(name,subs);
     135        if(subs.size()){
    135136            //オーバーロードを解決
    136             psi=OverloadSolutionWithStrParam(name,ppsi,num,Parameter,ObjectName,NULL);
    137             HeapDefaultFree(ppsi);
     137            psi=OverloadSolutionWithStrParam(name,subs,Parameter,ObjectName,NULL);
    138138
    139139            if(!psi) return 0;
     
    141141
    142142
    143         ret_type=psi->ReturnType;
    144         *plpRetIndex=psi->u.ReturnIndex;
     143        Opcode_CallProc(Parameter,psi,0,ObjectName,RefType);
     144        if( plpRetIndex ){
     145            *plpRetIndex = psi->u.ReturnIndex;
     146        }
     147        return psi->ReturnType;
    145148    }
    146149    else if(idProc==PROC_DLL){
     
    151154        pdi=(DECLAREINFO *)pInfo;
    152155
    153         ret_type=pdi->ReturnType;
    154         *plpRetIndex=pdi->u.ReturnIndex;
     156        ret_type=Opcode_CallDllProc(Parameter,pdi,plpRetIndex);
    155157    }
    156158    else if(idProc==PROC_BUILTIN){
     
    161163        FuncId=(int)(_int64)pInfo;
    162164
    163         ret_type=GetFunctionType(FuncId);
    164         *plpRetIndex=-1;
     165        TYPEINFO ReturnTypeInfo = { DEF_LONG, NULL };
     166        Opcode_CallFunc( Parameter, FuncId, ReturnTypeInfo );
     167        if( plpRetIndex ){
     168            *plpRetIndex = ReturnTypeInfo.u.lpIndex;
     169        }
     170        return ReturnTypeInfo.type;
    165171    }
    166172    else if(idProc==PROC_PTR){
     
    173179
    174180        extern PROCPTRINFO *pProcPtrInfo;
    175         ret_type=pProcPtrInfo[lpIndex].ReturnType;
    176         *plpRetIndex=pProcPtrInfo[lpIndex].u.ReturnIndex;
     181        ret_type=Opcode_CallProcPtr(name,Parameter,&pProcPtrInfo[lpIndex],plpRetIndex);
    177182    }
    178183
    179184    return ret_type;
    180185}
    181 BOOL GetReturnTypeOfPropertyMethod(char *variable,char *RightSide,TYPEINFO *pRetTypeInfo){
     186BOOL CallPropertyMethod(char *variable,char *RightSide,TYPEINFO *pRetTypeInfo){
    182187    //プロパティ用のメソッドを呼び出す
    183188
     
    192197
    193198    //オーバーロード用の関数リストを作成
    194     SUBINFO **ppsi;
    195     int num;
    196     ppsi=GetOverloadSubHash(VarName,&num);
    197     if(num==0){
     199    std::vector<SUBINFO *> subs;
     200    GetOverloadSubHash(VarName,subs);
     201    if(subs.size()==0){
    198202        return 0;
    199203    }
     
    210214    //オーバーロードを解決
    211215    SUBINFO *psi;
    212     psi=OverloadSolutionWithStrParam(VarName,ppsi,num,Parameter,ObjectName,NULL);
    213     HeapDefaultFree(ppsi);
     216    psi=OverloadSolutionWithStrParam(VarName,subs,Parameter,ObjectName,NULL);
     217
     218    if(psi){
     219        //呼び出し
     220        Opcode_CallProc(Parameter,psi,0,ObjectName,RefType);
     221
     222        if( pRetTypeInfo ){
     223            pRetTypeInfo->type = psi->ReturnType;
     224            pRetTypeInfo->u.lpIndex = psi->u.ReturnIndex;
     225        }
     226    }
     227
     228    HeapDefaultFree(Parameter);
     229
     230    return 1;
     231}
     232
     233
     234int GetReturnTypeOfProc(int idProc,void *pInfo,char *name,char *Parameter,LONG_PTR *plpRetIndex){
     235    int ret_type;
     236
     237    if(idProc==PROC_DEFAULT){
     238        /////////////////////
     239        // ユーザー定義関数
     240        /////////////////////
     241
     242        SUBINFO *psi;
     243        psi=(SUBINFO *)pInfo;
     244
     245        //GetSubHash内でエラー提示が行われた場合
     246        if(psi==(SUBINFO *)-1) return -1;
     247
     248
     249        //オブジェクト名を取得
     250        char ObjectName[VN_SIZE];
     251        int RefType;
     252        SplitObjectName(name,ObjectName,&RefType);
     253
     254
     255        ////////////////////////
     256        // オーバーロードを解決
     257        ////////////////////////
     258
     259        std::vector<SUBINFO *> subs;
     260        GetOverloadSubHash(name,subs);
     261        if( subs.size() > 0 ){
     262            //オーバーロードを解決
     263            psi=OverloadSolutionWithStrParam(name,subs,Parameter,ObjectName,NULL);
     264
     265            if(!psi) return 0;
     266        }
     267
     268
     269        ret_type=psi->ReturnType;
     270        *plpRetIndex=psi->u.ReturnIndex;
     271    }
     272    else if(idProc==PROC_DLL){
     273        /////////////////////////
     274        // DLL関数
     275        /////////////////////////
     276        DECLAREINFO *pdi;
     277        pdi=(DECLAREINFO *)pInfo;
     278
     279        ret_type=pdi->ReturnType;
     280        *plpRetIndex=pdi->u.ReturnIndex;
     281    }
     282    else if(idProc==PROC_BUILTIN){
     283        /////////////////////////
     284        // 組み込み関数
     285        /////////////////////////
     286        int FuncId;
     287        FuncId=(int)(_int64)pInfo;
     288
     289        ret_type=GetFunctionType(FuncId);
     290        *plpRetIndex=-1;
     291    }
     292    else if(idProc==PROC_PTR){
     293        /////////////////
     294        // 関数ポインタ
     295        /////////////////
     296
     297        LONG_PTR lpIndex;
     298        GetVarType(name,&lpIndex,0);
     299
     300        extern PROCPTRINFO *pProcPtrInfo;
     301        ret_type=pProcPtrInfo[lpIndex].ReturnType;
     302        *plpRetIndex=pProcPtrInfo[lpIndex].u.ReturnIndex;
     303    }
     304
     305    return ret_type;
     306}
     307BOOL GetReturnTypeOfPropertyMethod(char *variable,char *RightSide,TYPEINFO *pRetTypeInfo){
     308    //プロパティ用のメソッドを呼び出す
     309
     310    //配列要素を取得
     311    char VarName[VN_SIZE],ArrayElements[VN_SIZE];
     312    GetArrayElement(variable,VarName,ArrayElements);
     313
     314    //オブジェクト名を取得
     315    char ObjectName[VN_SIZE];
     316    int RefType;
     317    SplitObjectName(VarName,ObjectName,&RefType);
     318
     319    //オーバーロード用の関数リストを作成
     320    std::vector<SUBINFO *> subs;
     321    GetOverloadSubHash(VarName,subs);
     322    if(subs.size()==0){
     323        return 0;
     324    }
     325
     326    //パラメータを整備
     327    char *Parameter;
     328    Parameter=(char *)HeapAlloc(hHeap,0,lstrlen(ArrayElements)+lstrlen(RightSide)+32);
     329    lstrcpy(Parameter,ArrayElements);
     330    if(RightSide){
     331        if(Parameter[0]&&RightSide[0]) lstrcat(Parameter,",");
     332        lstrcat(Parameter,RightSide);
     333    }
     334
     335    //オーバーロードを解決
     336    SUBINFO *psi;
     337    psi=OverloadSolutionWithStrParam(VarName,subs,Parameter,ObjectName,NULL);
    214338
    215339    if(psi){
     
    225349//インデクサ(getter)の戻り値を取得
    226350bool GetReturnTypeOfIndexerGetterProc(CClass *pobj_Class,TYPEINFO &RetTypeInfo){
    227     SUBINFO **ppsi;
    228     int num;
    229     ppsi=pobj_Class->GetOperatorSubInfo(CALC_ARRAY_GET,num);
    230     if(num==0){
    231         HeapDefaultFree(ppsi);
    232 
     351    std::vector<SUBINFO *> subs;
     352    pobj_Class->EnumMethod( CALC_ARRAY_GET, subs );
     353    if( subs.size() == 0 ){
    233354        return false;
    234355    }
    235356
    236     RetTypeInfo.type = ppsi[0]->ReturnType;
    237     RetTypeInfo.u.lpIndex = ppsi[0]->u.ReturnIndex;
    238 
    239     HeapDefaultFree(ppsi);
     357    RetTypeInfo.type = subs[0]->ReturnType;
     358    RetTypeInfo.u.lpIndex = subs[0]->u.ReturnIndex;
    240359
    241360    return true;
  • BasicCompiler_Common/calculation.cpp

    r49 r50  
    11991199    BOOL bRet=0;
    12001200
    1201     SUBINFO **ppsi;
    1202     int num;
    1203     ppsi=pobj_c->GetOperatorSubInfo(CALC_SUBSITUATION,num);
    1204     if(num==0){
     1201    std::vector<SUBINFO *> subs;
     1202    pobj_c->EnumMethod( CALC_SUBSITUATION, subs );
     1203    if( subs.size() == 0 ){
    12051204        bRet=0;
    12061205        goto finish;
    12071206    }
    12081207
    1209     int i;
    1210     for(i=0;i<num;i++){
    1211         if(ppsi[i]->ParmNum==2){
    1212             TYPEINFO TypeInfo={ppsi[i]->pParmInfo[1].type,ppsi[i]->pParmInfo[1].u.index};
     1208    foreach( SUBINFO *psi, subs ){
     1209        if(psi->ParmNum==2){
     1210            TYPEINFO TypeInfo={psi->pParmInfo[1].type,psi->pParmInfo[1].u.index};
    12131211            if(IsStringObjectType(&TypeInfo)){
    12141212                bRet=1;
     
    12191217
    12201218finish:
    1221     HeapDefaultFree(ppsi);
    12221219    return bRet;
    12231220}
  • BasicCompiler_Common/common.h

    r49 r50  
    1111#include <shlobj.h>
    1212#include <vector>
     13
     14//boost libraries
     15#include <boost/foreach.hpp>
     16
     17#define foreach BOOST_FOREACH
    1318
    1419#ifdef _AMD64_
     
    417422SUBINFO *GetSubHash(const char *name,BOOL bError=0);
    418423SUBINFO *GetMethodHash(char *ObjectName,char *MethodName,char *Parameter,BOOL bError=0);
    419 SUBINFO **GetOverloadObjectSubHash(char *name,CClass *pobj_c, int *pNum);
    420 SUBINFO **GetOverloadSubHash(const char *name,int *pNum);
     424void GetOverloadSubHash( const char *lpszName, std::vector<SUBINFO *> &subs );
    421425
    422426//Object.cpp
     
    424428int GetSizeOfClass(CClass *pobj_c);
    425429void AddClassName(char *Parameter,int NowLine);
    426 void CallConstractor(char *VarName,int *SubScripts,TYPEINFO &TypeInfo,char *Parameter);
     430void CallConstructor(char *VarName,int *SubScripts,TYPEINFO &TypeInfo,char *Parameter);
    427431
    428432//Overload.sbp
    429 SUBINFO *OverloadSolutionWithStrParam(char *name,SUBINFO **ppsi,int num,char *Parameter,char *ObjectName,TYPEINFO *pReturnTypeInfo);
    430 SUBINFO *OverloadSolution(const char *name,SUBINFO **ppsi,int num,PARAMETER_INFO *ppi,int ParmNum,TYPEINFO *pReturnTypeInfo);
     433SUBINFO *OverloadSolutionWithStrParam(
     434    const char *name,
     435    std::vector<SUBINFO *> &subs,
     436    const char *Parameter,
     437    const char *ObjectName,
     438    TYPEINFO *pReturnTypeInfo);
     439SUBINFO *OverloadSolution(
     440    const char *name,
     441    std::vector<SUBINFO *> &subs,
     442    const PARAMETER_INFO *ppi,
     443    const int ParmNum,
     444    TYPEINFO *pReturnTypeInfo);
    431445
    432446//Debug.cpp
     
    550564void SplitObjectName(const char *name,char *ObjectName,int *pRefType);
    551565bool SplitMemberName( const char *desc, char *object, char *member );
     566int CallProc(int idProc,void *pInfo,char *name,char *Parameter,LONG_PTR *plpRetIndex);
     567BOOL CallPropertyMethod(char *variable,char *RightSide,TYPEINFO *pRetTypeInfo);
    552568int GetReturnTypeOfProc(int idProc,void *pInfo,char *name,char *Parameter,LONG_PTR *plpRetIndex);
    553569BOOL GetReturnTypeOfPropertyMethod(char *variable,char *RightSide,TYPEINFO *pRetTypeInfo);
  • BasicCompiler_Common/hash.cpp

    r47 r50  
    5353}
    5454
    55 SUBINFO **GetOverloadObjectSubHash(char *name,CClass *pobj_c, int *pNum){
    56     int i;
    57 
    58 
    59     //格納のための構造体配列を用意
    60     extern HANDLE hHeap;
    61     SUBINFO **ppArray_si;
    62     int num=0;
    63     ppArray_si=(SUBINFO **)HeapAlloc(hHeap,0,sizeof(SUBINFO *)*1024);
    64 
    65 
    66     //オブジェクトのメンバ関数の場合
    67     //※オーバーライドされた関数を先にサーチする必要があるため、バックサーチを行う
    68     for(i=pobj_c->iMethodNum-1;i>=0;i--){
    69         if(lstrcmp(name,pobj_c->ppobj_Method[i]->psi->name)==0){
    70             ppArray_si[num]=pobj_c->ppobj_Method[i]->psi;
    71             num++;
    72         }
    73     }
    74 
    75     *pNum=num;
    76     return ppArray_si;
    77 }
    78 
    79 SUBINFO **GetOverloadSubHash( const char *lpszName, int *pNum ){
     55void GetOverloadSubHash( const char *lpszName, std::vector<SUBINFO *> &subs ){
    8056    extern SUBINFO *pSubInfo;
    8157    extern int SubInfoNum;
     
    9066    }
    9167    else lstrcpy(name,lpszName);
    92 
    93 
    94     //格納のための構造体配列を用意
    95     extern HANDLE hHeap;
    96     SUBINFO **ppArray_si;
    97     int num=0;
    98     ppArray_si=(SUBINFO **)HeapAlloc(hHeap,0,sizeof(SUBINFO *)*1024);
    9968
    10069
     
    12291                }
    12392                else{
    124                     goto finish;
     93                    return;
    12594                }
    12695            }
     
    12998        if( isStatic ){
    13099            // 静的メソッドから取得
    131             for(i=0;i<pobj_c->iStaticMethodNum;i++){
    132                 if(lstrcmp(NestMember,pobj_c->ppobj_StaticMethod[i]->psi->name)==0){
    133                     ppArray_si[num]=pobj_c->ppobj_StaticMethod[i]->psi;
    134                     num++;
    135                 }
    136             }
     100            pobj_c->EnumStaticMethod( NestMember, subs );
    137101        }
    138102        else{
     
    142106            for(i=pobj_c->iMethodNum-1;i>=0;i--){
    143107                if(lstrcmp(NestMember,pobj_c->ppobj_Method[i]->psi->name)==0){
    144                     ppArray_si[num]=pobj_c->ppobj_Method[i]->psi;
    145                     num++;
     108                    subs.push_back( pobj_c->ppobj_Method[i]->psi );
    146109                }
    147110            }
     
    161124            CClass *pobj_c = pobj_CompilingClass;
    162125
    163             for(i=0;i<pobj_c->iStaticMethodNum;i++){
    164                 if(lstrcmp(name,pobj_c->ppobj_StaticMethod[i]->psi->name)==0){
    165                     ppArray_si[num]=pobj_c->ppobj_StaticMethod[i]->psi;
    166                     num++;
    167                 }
    168             }
     126            pobj_c->EnumStaticMethod( NestMember, subs );
    169127
    170128
     
    178136            for(;i<pobj_CompilingClass->iMethodNum;i++){
    179137                if(lstrcmp(name,pobj_CompilingClass->ppobj_Method[i]->psi->name)==0){
    180                     ppArray_si[num]=pobj_CompilingClass->ppobj_Method[i]->psi;
    181                     num++;
     138                    subs.push_back( pobj_CompilingClass->ppobj_Method[i]->psi );
    182139                }
    183140            }
     
    188145                if(pobj_CompilingClass->ppobj_Method[i]->pobj_InheritsClass){
    189146                    if(lstrcmp(name,pobj_CompilingClass->ppobj_Method[i]->psi->name)==0){
    190                         ppArray_si[num]=pobj_CompilingClass->ppobj_Method[i]->psi;
    191                         num++;
     147                        subs.push_back( pobj_CompilingClass->ppobj_Method[i]->psi );
    192148                    }
    193149                }
     
    211167            if(!psi->pobj_ParentClass){
    212168                if(lstrcmp(psi->name,name)==0){
    213                     ppArray_si[num]=psi;
    214                     num++;
     169                    subs.push_back( psi );
    215170                }
    216171            }
     
    220175
    221176    }
    222 finish:
    223 
    224     *pNum=num;
    225     return ppArray_si;
    226177}
    227178
    228179//オーバーロードされていない関数を取得(昔のコンパイラソースコードとの互換性保持)
    229180SUBINFO *GetSubHash(const char *lpszName,BOOL bError){
    230     int num;
    231     SUBINFO **ppsi,*psi;
    232     ppsi = GetOverloadSubHash(lpszName,&num);
     181    std::vector<SUBINFO *> subs;
     182    GetOverloadSubHash(lpszName,subs);
    233183
    234184    //関数が存在しないとき
    235     if(num == 0){
    236         HeapDefaultFree(ppsi);
     185    if(subs.size() == 0){
    237186        return 0;
    238187    }
    239188
    240189    //一つ以上の関数が存在するときは内部エラー(デバッグ用)
    241     if(num > 1){
     190    if(subs.size() > 1){
    242191        if(bError) SetError(300,NULL,cp);
    243192    }
    244193
    245     psi = ppsi[0];
    246 
    247     HeapDefaultFree(ppsi);
     194    SUBINFO *psi;
     195    psi = subs[0];
    248196
    249197    return psi;
     
    253201    sprintf(temporary,"%s.%s",ObjectName,MethodName);
    254202
    255     int num;
    256     SUBINFO **ppsi,*psi;
    257     ppsi = GetOverloadSubHash(temporary,&num);
     203    std::vector<SUBINFO *> subs;
     204    SUBINFO *psi;
     205    GetOverloadSubHash(temporary,subs);
    258206
    259207    //関数が存在しないとき
    260     if(num == 0){
    261         HeapDefaultFree(ppsi);
     208    if(subs.size() == 0){
    262209        return 0;
    263210    }
    264211
    265212    //オーバーロードを解決
    266     psi=OverloadSolutionWithStrParam(temporary,ppsi,num,Parameter,ObjectName,NULL);
    267     HeapDefaultFree(ppsi);
     213    psi=OverloadSolutionWithStrParam(temporary,subs,Parameter,ObjectName,NULL);
    268214
    269215    return psi;
Note: See TracChangeset for help on using the changeset viewer.