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/Subroutine.cpp

    r73 r75  
    66#include "../BasicCompiler32/opcode.h"
    77#endif
    8 
    9 //コンパイル中の関数情報
    10 SubInfo *pCompilingSubInfo;
    118
    129int GetCallProcName(char *buffer,char *name){
     
    5653
    5754    //関数ポインタ
    58     int type;
    59     LONG_PTR lpIndex;
    60     type=GetVarType(name,&lpIndex,0);
    61     if(type==DEF_PTR_PROC) return PROC_PTR;
     55    Type type;
     56    if( !GetVarType( name, type, false ) ){
     57        return 0;
     58    }
     59    if( type.IsProcPtr() ){
     60        return PROC_PTR;
     61    }
    6262
    6363    return 0;
     
    105105}
    106106
    107 
    108 int CallProc(int idProc,void *pInfo,char *name,char *Parameter,LONG_PTR *plpRetIndex){
    109     int ret_type;
    110 
    111     if(idProc==PROC_DEFAULT){
     107bool CallProc( int kind, const void *pProc, const char *fullCallName, const char *lpszParms, Type &resultType, bool isCallOn ){
     108
     109    //GetSubHash内でエラー提示が行われた場合
     110    if(pProc==(Procedure *)-1){
     111        return false;
     112    }
     113
     114    if(kind==PROC_DEFAULT){
    112115        /////////////////////
    113116        // ユーザー定義関数
    114117        /////////////////////
    115118
    116         SubInfo *pSub;
    117         pSub=(SubInfo *)pInfo;
    118 
    119         //GetSubHash内でエラー提示が行われた場合
    120         if(pSub==(SubInfo *)-1) return -1;
    121 
     119        UserProc *pUserProc = (UserProc *)pProc;
    122120
    123121        //オブジェクト名を取得
    124122        char ObjectName[VN_SIZE];
    125123        int RefType;
    126         SplitObjectName(name,ObjectName,&RefType);
     124        SplitObjectName(fullCallName,ObjectName,&RefType);
    127125
    128126
     
    131129        ////////////////////////
    132130
    133         std::vector<SubInfo *> subs;
    134         GetOverloadSubHash(name,subs);
     131        std::vector<UserProc *> subs;
     132        GetOverloadSubHash(fullCallName,subs);
    135133        if(subs.size()){
    136134            //オーバーロードを解決
    137             pSub=OverloadSolutionWithStrParam(name,subs,Parameter,ObjectName,NULL);
    138 
    139             if(!pSub) return 0;
    140         }
    141 
    142 
    143         Opcode_CallProc(Parameter,pSub,0,ObjectName,RefType);
    144         if( plpRetIndex ){
    145             *plpRetIndex = pSub->u.ReturnIndex;
    146         }
    147         return pSub->ReturnType;
    148     }
    149     else if(idProc==PROC_DLL){
     135            pUserProc=OverloadSolutionWithStrParam(fullCallName,subs,lpszParms,ObjectName);
     136
     137            if(!pUserProc){
     138                return false;
     139            }
     140        }
     141
     142        resultType = pUserProc->ReturnType();
     143
     144        if( isCallOn ){
     145            if( !Opcode_CallProc(lpszParms,pUserProc,0,ObjectName,RefType) ){
     146                return false;
     147            }
     148        }
     149    }
     150    else if(kind==PROC_DLL){
    150151        /////////////////////////
    151152        // DLL関数
    152153        /////////////////////////
    153         DECLAREINFO *pdi;
    154         pdi=(DECLAREINFO *)pInfo;
    155 
    156         ret_type=Opcode_CallDllProc(Parameter,pdi,plpRetIndex);
    157     }
    158     else if(idProc==PROC_BUILTIN){
     154        DllProc *pDllProc = (DllProc *)pProc;
     155
     156        resultType = pDllProc->ReturnType();
     157
     158        if( isCallOn ){
     159            if( !Opcode_CallDllProc(lpszParms,pDllProc) ){
     160                return false;
     161            }
     162        }
     163    }
     164    else if(kind==PROC_BUILTIN){
    159165        /////////////////////////
    160166        // 組み込み関数
    161167        /////////////////////////
    162         int FuncId;
    163         FuncId=(int)(_int64)pInfo;
    164 
    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;
    171     }
    172     else if(idProc==PROC_PTR){
     168        int FuncId = (int)(_int64)pProc;
     169
     170        if( !Opcode_CallFunc( lpszParms, FuncId, resultType, isCallOn ) ){
     171            return false;
     172        }
     173    }
     174    else if(kind==PROC_PTR){
    173175        /////////////////
    174176        // 関数ポインタ
    175177        /////////////////
    176178
    177         LONG_PTR lpIndex;
    178         GetVarType(name,&lpIndex,0);
    179 
    180         extern PROCPTRINFO *pProcPtrInfo;
    181         ret_type=Opcode_CallProcPtr(name,Parameter,&pProcPtrInfo[lpIndex],plpRetIndex);
    182     }
    183 
    184     return ret_type;
    185 }
    186 BOOL CallPropertyMethod(char *variable,char *RightSide,TYPEINFO *pRetTypeInfo){
     179        Type type;
     180        GetVarType(fullCallName,type,false);
     181
     182        extern ProcPointer **ppProcPointer;
     183        ProcPointer *pProcPtr = ppProcPointer[type.GetIndex()];
     184        resultType = pProcPtr->ReturnType();
     185
     186        if( isCallOn ){
     187            if( !Opcode_CallProcPtr(fullCallName,lpszParms,pProcPtr) ){
     188                return false;
     189            }
     190        }
     191    }
     192    else{
     193        return false;
     194    }
     195
     196    return true;
     197}
     198bool CallPropertyMethod( const char *variable, const char *rightSide, Type &resultType){
    187199    //プロパティ用のメソッドを呼び出す
    188200
     
    197209
    198210    //オーバーロード用の関数リストを作成
    199     std::vector<SubInfo *> subs;
     211    std::vector<UserProc *> subs;
    200212    GetOverloadSubHash(VarName,subs);
    201213    if(subs.size()==0){
    202         return 0;
     214        return false;
    203215    }
    204216
    205217    //パラメータを整備
    206218    char *Parameter;
    207     Parameter=(char *)HeapAlloc(hHeap,0,lstrlen(ArrayElements)+lstrlen(RightSide)+32);
     219    Parameter=(char *)HeapAlloc(hHeap,0,lstrlen(ArrayElements)+lstrlen(rightSide)+32);
    208220    lstrcpy(Parameter,ArrayElements);
    209     if(RightSide){
    210         if(Parameter[0]&&RightSide[0]) lstrcat(Parameter,",");
    211         lstrcat(Parameter,RightSide);
     221    if(rightSide){
     222        if(Parameter[0]&&rightSide[0]) lstrcat(Parameter,",");
     223        lstrcat(Parameter,rightSide);
    212224    }
    213225
    214226    //オーバーロードを解決
    215     SubInfo *pSub;
    216     pSub=OverloadSolutionWithStrParam(VarName,subs,Parameter,ObjectName,NULL);
    217 
    218     if(pSub){
     227    UserProc *pUserProc;
     228    pUserProc=OverloadSolutionWithStrParam(VarName,subs,Parameter,ObjectName);
     229
     230    if(pUserProc){
    219231        //呼び出し
    220         Opcode_CallProc(Parameter,pSub,0,ObjectName,RefType);
    221 
    222         if( pRetTypeInfo ){
    223             pRetTypeInfo->type = pSub->ReturnType;
    224             pRetTypeInfo->u.lpIndex = pSub->u.ReturnIndex;
    225         }
     232        Opcode_CallProc(Parameter,pUserProc,0,ObjectName,RefType);
     233
     234        resultType = pUserProc->ReturnType();
    226235    }
    227236
    228237    HeapDefaultFree(Parameter);
    229238
    230     return 1;
    231 }
    232 
    233 
    234 int 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 *pSub;
    243         pSub=(SubInfo *)pInfo;
    244 
    245         //GetSubHash内でエラー提示が行われた場合
    246         if(pSub==(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             pSub=OverloadSolutionWithStrParam(name,subs,Parameter,ObjectName,NULL);
    264 
    265             if(!pSub) return 0;
    266         }
    267 
    268 
    269         ret_type=pSub->ReturnType;
    270         *plpRetIndex=pSub->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 }
    307 BOOL GetReturnTypeOfPropertyMethod(char *variable,char *RightSide,TYPEINFO *pRetTypeInfo){
     239    return true;
     240}
     241
     242bool GetReturnTypeOfPropertyMethod( const char *variable, const char *rightSide, Type &resultType ){
    308243    //プロパティ用のメソッドを呼び出す
    309244
     
    318253
    319254    //オーバーロード用の関数リストを作成
    320     std::vector<SubInfo *> subs;
     255    std::vector<UserProc *> subs;
    321256    GetOverloadSubHash(VarName,subs);
    322257    if(subs.size()==0){
     
    326261    //パラメータを整備
    327262    char *Parameter;
    328     Parameter=(char *)HeapAlloc(hHeap,0,lstrlen(ArrayElements)+lstrlen(RightSide)+32);
     263    Parameter=(char *)HeapAlloc(hHeap,0,lstrlen(ArrayElements)+lstrlen(rightSide)+32);
    329264    lstrcpy(Parameter,ArrayElements);
    330     if(RightSide){
    331         if(Parameter[0]&&RightSide[0]) lstrcat(Parameter,",");
    332         lstrcat(Parameter,RightSide);
     265    if(rightSide){
     266        if(Parameter[0]&&rightSide[0]) lstrcat(Parameter,",");
     267        lstrcat(Parameter,rightSide);
    333268    }
    334269
    335270    //オーバーロードを解決
    336     SubInfo *pSub;
    337     pSub=OverloadSolutionWithStrParam(VarName,subs,Parameter,ObjectName,NULL);
    338 
    339     if(pSub){
    340         if(pRetTypeInfo){
    341             pRetTypeInfo->type=pSub->ReturnType;
    342             pRetTypeInfo->u.lpIndex=pSub->u.ReturnIndex;
    343         }
     271    UserProc *pUserProc;
     272    pUserProc=OverloadSolutionWithStrParam(VarName,subs,Parameter,ObjectName);
     273
     274    if(pUserProc){
     275        resultType = pUserProc->ReturnType();
    344276    }
    345277
     
    348280
    349281//インデクサ(getter)の戻り値を取得
    350 bool GetReturnTypeOfIndexerGetterProc(CClass *pobj_Class,TYPEINFO &RetTypeInfo){
    351     std::vector<SubInfo *> subs;
    352     pobj_Class->EnumMethod( CALC_ARRAY_GET, subs );
     282bool GetReturnTypeOfIndexerGetterProc( const CClass &objClass, Type &resultType ){
     283    std::vector<UserProc *> subs;
     284    objClass.EnumMethod( CALC_ARRAY_GET, subs );
    353285    if( subs.size() == 0 ){
    354286        return false;
    355287    }
    356288
    357     RetTypeInfo.type = subs[0]->ReturnType;
    358     RetTypeInfo.u.lpIndex = subs[0]->u.ReturnIndex;
     289    resultType = subs[0]->ReturnType();
    359290
    360291    return true;
     
    362293
    363294
    364 void AddDeclareData(char *buffer,int NowLine){
     295void AddDeclareData(char *buffer,int nowLine){
    365296    extern HANDLE hHeap;
    366     int i,i2,i3,i4,sw,IsFunction;
    367     char temporary[VN_SIZE];
    368 
    369     i=0;
    370 
    371     DWORD dwType;
    372     BOOL bCdecl=0;
    373 
    374     //Static/Dynamic
    375     if(buffer[i]==ESC_STATIC){
    376         dwType=DECLARE_STATIC;
    377         i++;
    378     }
    379     else dwType=DECLARE_DYNAMIC;
     297    int i2;
     298
     299    int i=0;
    380300
    381301    //Sub/Function
    382     if(buffer[i]==ESC_SUB) IsFunction=0;
    383     else if(buffer[i]==ESC_FUNCTION) IsFunction=1;
     302    Procedure::Kind kind = Procedure::Sub;
     303    if(buffer[i]==ESC_SUB){
     304    }
     305    else if(buffer[i]==ESC_FUNCTION){
     306        kind = Procedure::Function;
     307    }
    384308    else{
    385         SetError(1,NULL,NowLine);
     309        SetError(1,NULL,nowLine);
    386310        return;
    387311    }
     
    389313
    390314    //プロシージャ名
     315    char procName[VN_SIZE];
     316    bool isCdecl = false;
    391317    for(i2=0;;i++,i2++){
    392318        if(buffer[i]==1&&buffer[i+1]==ESC_CDECL){
    393             bCdecl=1;
     319            isCdecl = true;
    394320
    395321            i+=2;
    396             temporary[i2]=0;
     322            procName[i2]=0;
    397323            break;
    398324        }
    399325        if(buffer[i]==','){
    400             temporary[i2]=0;
     326            procName[i2]=0;
    401327            break;
    402328        }
    403329        if(buffer[i]=='\0'){
    404             SetError(1,NULL,NowLine);
     330            SetError(1,NULL,nowLine);
    405331            return;
    406332        }
    407         temporary[i2]=buffer[i];
    408     }
     333        procName[i2]=buffer[i];
     334    }
     335    i++;
    409336
    410337    //ユーザー定義関数との重複チェック
    411     if(GetSubHash(temporary)){
    412         SetError(15,temporary,NowLine);
     338    if(GetSubHash(procName)){
     339        SetError(15,procName,nowLine);
    413340        return;
    414341    }
    415342
    416343
     344    //ライブラリ
     345    char dllFileName[MAX_PATH];
     346    i = GetOneParameter( buffer, i, dllFileName );
     347    Type resultType;
     348    _int64 i64data;
     349    if( !StaticCalculation( true, dllFileName, 0, &i64data, resultType ) ){
     350        return;
     351    }
     352    if( resultType.GetBasicType() != typeOfPtrChar ){
     353        SetError(1,NULL,nowLine);
     354        return;
     355    }
     356    lstrcpy( dllFileName, (char *)i64data );
     357    CharUpper(dllFileName);
     358    if(!strstr(dllFileName,".")){
     359        lstrcat(dllFileName,".DLL");
     360        if(lstrlen(dllFileName)>=16){
     361            SetError(7,NULL,nowLine);
     362            return;
     363        }
     364    }
     365
     366    //エイリアス
     367    char alias[VN_SIZE];
     368    i = GetOneParameter( buffer, i, alias );
     369    if( alias[0] ){
     370        if( !StaticCalculation( true, alias, 0, &i64data, resultType ) ){
     371            return;
     372        }
     373        if( resultType.GetBasicType() != typeOfPtrChar ){
     374            SetError(1,NULL,nowLine);
     375            return;
     376        }
     377        lstrcpy( alias, (char *)i64data );
     378    }
     379    else{
     380        //省略されたときは関数名
     381        lstrcpy( alias, procName );
     382    }
     383
     384
     385    // オブジェクトを生成
     386    DllProc *pDllProc = new DllProc( procName, kind, isCdecl, dllFileName, alias );
     387
     388    // パラメータを解析
     389    // ※第1パラメータにに指定するデータの例:"( s As String ) As String"
     390    pDllProc->SetParamsAndReturnType( buffer + i, nowLine );
     391
     392    // パラメータのエラーチェック
     393    foreach( const Parameter *pParam, pDllProc->Params() ){
     394        if( pParam->IsObject() ){
     395            SetError(25,pParam->GetVarName(),nowLine);
     396        }
     397        if( !pParam->IsRef() ){
     398            if( pParam->IsStruct() ){
     399                SetError(28,pParam->GetVarName(),nowLine);
     400            }
     401        }
     402    }
     403
     404    //戻り値のエラーチェック
     405    if( pDllProc->IsFunction() ){
     406        // Function定義
     407
     408        if( pDllProc->ReturnType().IsObject() ){
     409            // DLL関数ではオブジェクトを戻り値にできない
     410            SetError(40,pDllProc->GetName(),nowLine);
     411        }
     412    }
     413
     414
    417415    /////////////////////////////////
    418     // 格納位置を計算してpciにセット
     416    // 格納位置を計算してppDeclareHashにセット
    419417    /////////////////////////////////
    420418
    421419    //ハッシュ値を取得
    422420    int key;
    423     key=hash_default(temporary);
    424 
    425     extern DECLAREINFO **ppDeclareHash;
    426     DECLAREINFO *pdi;
     421    key=hash_default(procName);
     422
     423    extern DllProc **ppDeclareHash;
    427424    if(ppDeclareHash[key]){
    428         pdi=ppDeclareHash[key];
     425        DllProc *pTempProc;
     426        pTempProc=ppDeclareHash[key];
    429427        while(1){
    430             if(lstrcmpi(pdi->name,temporary)==0){
     428            if( pDllProc->GetName() == pTempProc->GetName() ){
    431429                //重複エラー
    432                 SetError(15,temporary,NowLine);
     430                SetError(15,procName,nowLine);
    433431                return;
    434432            }
    435433
    436             if(pdi->pNextData==0){
    437                 pdi->pNextData=(DECLAREINFO *)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,sizeof(DECLAREINFO));
     434            if(pTempProc->pNextData==0){
     435                pTempProc->pNextData=pDllProc;
    438436                break;
    439437            }
    440             pdi=pdi->pNextData;
    441         }
    442         pdi=pdi->pNextData;
     438            pTempProc=pTempProc->pNextData;
     439        }
     440        pTempProc=pTempProc->pNextData;
    443441    }
    444442    else{
    445         ppDeclareHash[key]=(DECLAREINFO *)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,sizeof(DECLAREINFO));
    446         pdi=ppDeclareHash[key];
    447     }
    448 
    449     pdi->dwType=dwType;
    450     pdi->bCdecl=bCdecl;
    451 
    452     pdi->name=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);
    453     lstrcpy(pdi->name,temporary);
     443        ppDeclareHash[key]=pDllProc;
     444    }
     445}
     446
     447UserProc *AddSubData(char *buffer,int nowLine,BOOL bVirtual,CClass *pobj_c, bool isStatic){
     448    int i2,i3;
     449    char temporary[8192];
     450
     451    int i=1;
     452
     453    UserProc::Kind kind = Procedure::Sub;
     454    bool isMacro = false;
     455    if(buffer[i]==ESC_FUNCTION) kind = Procedure::Function;
     456    if(buffer[i]==ESC_MACRO){
     457        isMacro = true;
     458    }
     459
    454460    i++;
    455461
    456     //ライブラリ
    457     i = GetOneParameter( buffer, i, temporary );
    458     int type;
    459     LONG_PTR lpIndex;
    460     _int64 i64data;
    461     type = StaticCalculation( true, temporary, 0, &i64data, &lpIndex );
    462     if( type != typeOfPtrChar ){
    463         SetError(1,NULL,NowLine);
    464         return;
    465     }
    466     lstrcpy( temporary, (char *)i64data );
    467     CharUpper(temporary);
    468     if(!strstr(temporary,".")){
    469         if(pdi->dwType==DECLARE_STATIC) lstrcat(temporary,".LIB");
    470         else{
    471             lstrcat(temporary,".DLL");
    472             if(lstrlen(temporary)>=16){
    473                 SetError(7,NULL,NowLine);
    474                 return;
    475             }
    476         }
    477     }
    478     pdi->file=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);
    479     lstrcpy(pdi->file,temporary);
    480 
    481     //エイリアス
    482     i = GetOneParameter( buffer, i, temporary );
    483     if( temporary[0] ){
    484         type = StaticCalculation( true, temporary, 0, &i64data, &lpIndex );
    485         if( type != typeOfPtrChar ){
    486             SetError(1,NULL,NowLine);
    487             return;
    488         }
    489         lstrcpy( temporary, (char *)i64data );
    490 
    491         pdi->alias=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);
    492         lstrcpy(pdi->alias,temporary);
    493     }
    494     else{
    495         //省略されたときは関数名
    496         pdi->alias=(char *)HeapAlloc(hHeap,0,lstrlen(pdi->name)+1);
    497         lstrcpy(pdi->alias,pdi->name);
    498     }
    499 
    500     //パラメータの始めのカッコ
    501     if(buffer[i]!='('){
    502         SetError(1,NULL,NowLine);
    503         return;
    504     }
    505     i++;
    506 
    507     pdi->pParmInfo=(PARAMETER_INFO *)HeapAlloc(hHeap,0,1);
    508 
    509     //各パラメータ
    510     for(i3=0;;i3++){
    511         if(buffer[i]==')') break;
    512 
    513         pdi->pParmInfo=(PARAMETER_INFO *)HeapReAlloc(hHeap,0,pdi->pParmInfo,(i3+1)*sizeof(PARAMETER_INFO));
    514 
    515         //ByVal
    516         if(buffer[i]==1&&buffer[i+1]==ESC_BYVAL){
    517             pdi->pParmInfo[i3].bByVal=1;
     462    bool isCdecl = false;
     463    bool isExport = false;
     464    while(1){
     465        if(buffer[i]==1&&buffer[i+1]==ESC_CDECL&& isCdecl == false ){
     466            isCdecl = true;
     467
    518468            i+=2;
    519469        }
    520         else if(buffer[i]==1&&buffer[i+1]==ESC_BYREF){
    521             pdi->pParmInfo[i3].bByVal=0;
    522             i+=2;
    523         }
    524         else pdi->pParmInfo[i3].bByVal=1;
    525 
    526         //変数名は無視(temporaryの変数名は型宣言文字判断のため)
    527         sw=0;
    528         for(i2=0;;i++,i2++){
    529             if(buffer[i]=='('){
    530                 if(!sw) sw=1;
    531 
    532                 i4=GetStringInPare(temporary+i2,buffer+i);
    533                 i2+=i4-1;
    534                 i+=i4-1;
    535                 continue;
    536             }
    537             if(buffer[i]=='['){
    538                 if(!sw) sw=1;
    539 
    540                 i4=GetStringInBracket(temporary+i2,buffer+i);
    541                 i2+=i4-1;
    542                 i+=i4-1;
    543                 continue;
    544             }
    545             if(!IsVariableChar(buffer[i])){
    546                 temporary[i2]=0;
    547                 break;
    548             }
    549             temporary[i2]=buffer[i];
    550         }
    551         if(lstrcmp(temporary,"...")==0) pdi->pParmInfo[i3].type=DEF_ELLIPSE;
    552         else{
    553             //型
    554             if(buffer[i]==1&&buffer[i+1]==ESC_AS){
    555                 i+=2;
    556                 for(i2=0;;i++,i2++){
    557                     if(!(IsVariableChar(buffer[i])||buffer[i]=='*')){
    558                         temporary[i2]=0;
    559                         break;
    560                     }
    561                     temporary[i2]=buffer[i];
    562                 }
    563                 pdi->pParmInfo[i3].type=GetTypeFixed(temporary,&pdi->pParmInfo[i3].u.index);
    564             }
    565             else{
    566                 pdi->pParmInfo[i3].type=GetTypeFromSimpleName(temporary);
    567                 SetError(-103,temporary,NowLine);
    568             }
    569 
    570             if(sw){
    571                 //配列ポインタを引き渡すとき
    572                 pdi->pParmInfo[i3].type=GetPtrType(pdi->pParmInfo[i3].type,pdi->pParmInfo[i3].u.index);
    573             }
    574         }
    575 
    576         //名前はダミー(使用しないため)
    577         pdi->pParmInfo[i3].name="";
    578 
    579         //構造体の場合はエラーチェック
    580         if(pdi->pParmInfo[i3].type==-1) SetError(3,temporary,NowLine);
    581         if(pdi->pParmInfo[i3].type==DEF_OBJECT){
    582             if(pdi->pParmInfo[i3].bByVal) pdi->pParmInfo[i3].type=DEF_LONG;//SetError(28,temporary,NowLine);
    583         }
    584 
    585         //構造体アドレスの空白部
    586         while(buffer[i]==' ') i++;
    587 
    588         if(buffer[i]==','){
    589             i++;
    590             continue;
    591         }
    592         else if(buffer[i]==')') continue;
    593         else{
    594             SetError(1,NULL,NowLine);
    595             break;
    596         }
    597     }
    598     pdi->ParmNum=i3;
    599 
    600     //戻り値
    601     i++;
    602     if(buffer[i]==1&&buffer[i+1]==ESC_AS){
    603         if(IsFunction==0) SetError(1,NULL,NowLine);
    604         i+=2;
    605         pdi->ReturnType=GetTypeFixed(buffer+i,&pdi->u.ReturnIndex);
    606         if(pdi->ReturnType==DEF_NON) SetError(3,buffer+i,NowLine);
    607         if(pdi->ReturnType==DEF_OBJECT) SetError(40,NULL,NowLine);
    608     }
    609     else if(buffer[i]) SetError(1,NULL,NowLine);
    610     else pdi->ReturnType=DEF_NON;
    611 
    612     pdi->pos=NowLine;
    613 }
    614 
    615 BOOL CompareParameter(PARAMETER_INFO *ppi1,int pi_num1,PARAMETER_INFO *ppi2,int pi_num2){
    616     if(pi_num1!=pi_num2) return 1;
    617 
    618     int i;
    619     for(i=0;i<pi_num1;i++){
    620         if(ppi1[i].type!=ppi2[i].type){
    621 
    622             if(ppi1[i].bByVal==0&&ppi1[i].type==DEF_ANY&&
    623                 ppi2[i].bByVal==1&&IsPtrType(ppi2[i].type)||
    624                 ppi1[i].bByVal==1&&IsPtrType(ppi1[i].type)&&
    625                 ppi2[i].bByVal==0&&ppi2[i].type==DEF_ANY){
    626                     /* ByRef var As Any
    627                             と
    628                         var As VoidPtr
    629                         は同等
    630                     */
    631                     continue;
    632             }
    633 
    634             return 1;
    635         }
    636         else{
    637             if(NATURAL_TYPE(ppi1[i].type)==DEF_OBJECT
    638                 || NATURAL_TYPE(ppi1[i].type)==DEF_STRUCT ){
    639                 if(ppi1[i].u.index!=ppi2[i].u.index) return 1;
    640             }
    641         }
    642     }
    643 
    644     return 0;
    645 }
    646 SubInfo *AddSubData(char *buffer,int NowLine,BOOL bVirtual,CClass *pobj_c,BOOL bStatic){
    647     int i,i2,i3,sw;
    648     DWORD dwType;
    649     char temporary[8192],temp2[VN_SIZE];
    650 
    651     i=1;
    652     if(buffer[i]==ESC_SUB) dwType=SUBTYPE_SUB;
    653     else if(buffer[i]==ESC_FUNCTION) dwType=SUBTYPE_FUNCTION;
    654     else if(buffer[i]==ESC_MACRO) dwType=SUBTYPE_MACRO;
    655 
    656     i++;
    657 
    658     BOOL bExport=0,bCdecl=0;
    659     while(1){
    660         if(buffer[i]==1&&buffer[i+1]==ESC_EXPORT&&bExport==0){
    661             bExport=1;
    662 
    663             i+=2;
    664         }
    665         else if(buffer[i]==1&&buffer[i+1]==ESC_CDECL&&bCdecl==0){
    666             bCdecl=1;
     470        else if(buffer[i]==1&&buffer[i+1]==ESC_EXPORT&& isExport == false ){
     471            isExport = true;
    667472
    668473            i+=2;
     
    674479    if(buffer[i]==1&&buffer[i+1]==ESC_OPERATOR){
    675480        if(!pobj_c){
    676             SetError(126,NULL,NowLine);
     481            SetError(126,NULL,nowLine);
    677482            return 0;
    678483        }
     
    708513        }
    709514        if(!iCalcId){
    710             SetError(1,NULL,NowLine);
     515            SetError(1,NULL,nowLine);
    711516            return 0;
    712517        }
     
    735540    }
    736541
    737     if(dwType==SUBTYPE_MACRO){
     542    if( isMacro ){
    738543        //大文字に変換
    739544        CharUpper(temporary);
     
    753558
    754559        if(GetDeclareHash(temporary)){
    755             SetError(15,temporary,NowLine);
     560            SetError(15,temporary,nowLine);
    756561            return 0;
    757562        }
     
    761566    SubNum++;
    762567
    763     SubInfo *pSub = new SubInfo();
    764 
    765     //クラス名
    766     pSub->pobj_ParentClass=pobj_c;
     568
     569    UserProc *pUserProc = new UserProc( temporary, kind, isMacro, isCdecl, isExport );
     570    pUserProc->SetParentClass( pobj_c );
    767571
    768572    //ID
    769573    static int id_base=0;
    770     pSub->id=(id_base++);
    771 
    772     //関数名
    773     pSub->name=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);
    774     lstrcpy(pSub->name,temporary);
    775 
    776     //ソースコードの位置
    777     pSub->address=NowLine;
    778 
    779     pSub->bExport=bExport;
    780     pSub->bCdecl=bCdecl;
    781     pSub->bVirtual=bVirtual;
    782     if(bExport) pSub->bUse=1;
    783     else pSub->bUse=0;
    784     pSub->bCompile=0;
    785     pSub->bSystem=0;
    786 
    787     pSub->dwType=dwType;
    788 
    789 
    790     if(pSub->dwType==SUBTYPE_FUNCTION){
    791         ///////////////////
    792         // 戻り値を取得
    793         ///////////////////
    794 
    795         pSub->isReturnRef = false;
    796 
    797         if(pobj_c){
    798             if(lstrcmp(pSub->name,pobj_c->name)==0||
    799                 pSub->name[0]=='~'){
    800                 //クラスのコンストラクタ、デストラクタがFunction定義の場合はエラーをだす
    801                 SetError(115,NULL,NowLine);
    802             }
    803         }
    804 
    805 
    806         i2=lstrlen(buffer)-2;
    807 
    808         int sw_as=0;
    809         for(;i2>0;i2--){
    810             if(buffer[i2]==')') break;
    811 
    812             if(buffer[i2]==1&&buffer[i2+1]==ESC_AS){
    813                 if( buffer[i2-2] == 1 && buffer[i2-1] == ESC_BYREF ){
    814                     //参照型
    815                     pSub->isReturnRef = true;
    816                 }
    817 
    818                 i2+=2;
    819                 i3=0;
    820                 while(buffer[i2]=='*') temporary[i3++]=buffer[i2++];
    821                 for(;;i2++,i3++){
    822                     if(!IsVariableChar(buffer[i2])){
    823                         temporary[i3]=0;
    824                         break;
    825                     }
    826                     temporary[i3]=buffer[i2];
    827                 }
    828                 pSub->ReturnType=GetTypeFixed(temporary,&pSub->u.ReturnIndex);
    829                 if(pSub->ReturnType==DEF_NON) SetError(3,temporary,NowLine);
    830 
    831                 sw_as=1;
    832                 break;
    833             }
    834         }
    835 
    836         if(!sw_as){
    837             SetError(-104,pSub->name,NowLine);
    838 
    839             pSub->ReturnType=DEF_DOUBLE;
    840         }
    841     }
    842     else{
    843         //戻り値なしのSub定義
    844         pSub->ReturnType=DEF_NON;
    845         pSub->u.ReturnIndex=-1;
    846     }
    847 
    848     //パラメータ
    849     if(buffer[i]!='('){
    850         SetError(1,NULL,NowLine);
    851         return 0;
    852     }
    853     i++;
    854     if(buffer[i]!=')'&&pobj_c){
    855         //クラスのメンバ関数の場合のみ、デストラクタにパラメータがある場合にエラーをだす
    856         if(pSub->name[0]=='~'){
    857             SetError(114,NULL,NowLine);
    858             i=JumpStringInPare(buffer,i);
    859         }
    860     }
    861     while(1){
    862         if(buffer[i]==')') break;
    863 
    864         //ByRef
    865         bool isRef;
    866         if(buffer[i]==1&&buffer[i+1]==ESC_BYVAL){
    867             isRef = false;
    868             i+=2;
    869         }
    870         else if(buffer[i]==1&&buffer[i+1]==ESC_BYREF){
    871             isRef = true;
    872             i+=2;
    873         }
    874         else isRef = false;
    875 
    876         //パラメータ名
    877         bool isArray = false;
    878         int subScripts[MAX_ARRAYDIM];
    879         char name[VN_SIZE];
    880         sw=0;
    881         for(i2=0;;i++,i2++){
    882             if(buffer[i]=='('){
    883                 if(!sw) sw=1;
    884 
    885                 i3=GetStringInPare(name+i2,buffer+i);
    886                 i2+=i3-1;
    887                 i+=i3-1;
    888                 continue;
    889             }
    890             if(buffer[i]=='['){
    891                 if(!sw) sw=1;
    892 
    893                 i3=GetStringInBracket(name+i2,buffer+i);
    894                 i2+=i3-1;
    895                 i+=i3-1;
    896                 continue;
    897             }
    898             if(!IsVariableChar(buffer[i])){
    899                 name[i2]=0;
    900                 break;
    901             }
    902             name[i2]=buffer[i];
    903         }
    904         if(sw){
    905             //配列パラメータ
    906             if( isRef == false ) SetError(29,NULL,NowLine);
    907             isArray = true;
    908 
    909             if((name[i2-2]=='('&&name[i2-1]==')')||
    910                 (name[i2-2]=='['&&name[i2-1]==']')){
    911                 subScripts[0]=LONG_MAX;
    912                 subScripts[1]=-1;
    913 
    914                 name[i2-2]=0;
    915             }
    916             else{
    917                 GetArrange(name,temp2,subScripts);
    918                 lstrcpy(name,temp2);
    919             }
    920 
    921             i2=lstrlen(name);
    922         }
    923 
    924         //型
    925         Type type( DEF_NON );
    926         if(buffer[i]==1&&buffer[i+1]==ESC_AS){
    927             i+=2;
    928 
    929             i2=0;
    930             while(buffer[i]=='*'){
    931                 temporary[i2]=buffer[i];
    932                 i++;
    933                 i2++;
    934             }
    935             for(;;i++,i2++){
    936                 if(!IsVariableChar(buffer[i])){
    937                     if(buffer[i]==1&&(buffer[i+1]==ESC_FUNCTION||buffer[i+1]==ESC_SUB)){
    938                         temporary[i2++]=buffer[i++];
    939                         temporary[i2]=buffer[i];
    940                         continue;
    941                     }
    942                     temporary[i2]=0;
    943                     break;
    944                 }
    945                 temporary[i2]=buffer[i];
    946             }
    947 
    948             Type::StringToType( temporary, type );
    949 
    950             if(temporary[0]=='*'&&
    951                 temporary[1]==1&&
    952                 (temporary[2]==ESC_FUNCTION||temporary[2]==ESC_SUB)){
    953                 if(buffer[i]!='('){
    954                     SetError(10,temporary,NowLine);
    955                     break;
    956                 }
    957                 i3=GetStringInPare(temporary+i2,buffer+i);
    958                 i+=i3;
    959                 i2+=i3;
    960 
    961                 if(temporary[2]==ESC_FUNCTION&&buffer[i]==1&&buffer[i+1]==ESC_AS){
    962                     temporary[i2++]=buffer[i++];
    963                     temporary[i2++]=buffer[i++];
    964                     for(;;i++,i2++){
    965                         if(!IsVariableChar(buffer[i])){
    966                             temporary[i2]=0;
    967                             break;
    968                         }
    969                         temporary[i2]=buffer[i];
    970                     }
    971                 }
    972             }
    973             else{
    974                 //TypeDefをする前のベース型を取得
    975                 GetOriginalTypeName(temporary);
    976             }
    977 
    978             if( type.IsNull() ){
    979                 SetError(3,temporary,NowLine);
    980                 type.SetBasicType( DEF_PTR_VOID );
    981             }
    982         }
    983         else{
    984             type.SetBasicType( GetTypeFromSimpleName(temporary) );
    985             SetError(-103,temporary,NowLine);
    986         }
    987 
    988         if( type.IsProcPtr() ){
    989             //関数ポインタの場合
    990             type.SetIndex( AddProcPtrInfo(temporary+3,temporary[2]) );
    991         }
    992 
    993         Parameter *pParam = new Parameter( name, type, isRef );
    994         if( isArray ){
    995             pParam->SetArray( subScripts );
    996         }
    997 
    998         //パラメータを追加
    999         pSub->params.push_back( pParam );
    1000 
    1001         if(buffer[i]==','){
    1002             i++;
    1003             continue;
    1004         }
    1005         else if(buffer[i]==')') continue;
    1006         else{
    1007             SetError(1,NULL,NowLine);
    1008             break;
    1009         }
    1010     }
    1011     pSub->SecondParmNum = (int)pSub->params.size();
    1012     i++;
    1013     if(buffer[i]=='('){
    1014         i++;
    1015         while(1){
    1016             if(buffer[i]==')') break;
    1017 
    1018             //ByRef
    1019             bool isRef;
    1020             if(buffer[i]==1&&buffer[i+1]==ESC_BYVAL){
    1021                 isRef = false;
    1022                 i+=2;
    1023             }
    1024             else if(buffer[i]==1&&buffer[i+1]==ESC_BYREF){
    1025                 isRef = true;
    1026                 i+=2;
    1027             }
    1028             else isRef = false;
    1029 
    1030             //パラメータ名
    1031             bool isArray = false;
    1032             int subScripts[MAX_ARRAYDIM];
    1033             char name[VN_SIZE];
    1034             sw=0;
    1035             for(i2=0;;i++,i2++){
    1036                 if(buffer[i]=='('){
    1037                     if(!sw) sw=1;
    1038 
    1039                     i3=GetStringInPare(name+i2,buffer+i);
    1040                     i2+=i3-1;
    1041                     i+=i3-1;
    1042                     continue;
    1043                 }
    1044                 if(buffer[i]=='['){
    1045                     if(!sw) sw=1;
    1046 
    1047                     i3=GetStringInBracket(name+i2,buffer+i);
    1048                     i2+=i3-1;
    1049                     i+=i3-1;
    1050                     continue;
    1051                 }
    1052                 if(!IsVariableChar(buffer[i])){
    1053                     name[i2]=0;
    1054                     break;
    1055                 }
    1056                 name[i2]=buffer[i];
    1057             }
    1058             if(sw){
    1059                 //配列パラメータ
    1060                 if( isRef == false ) SetError(29,NULL,NowLine);
    1061                 isArray = true;
    1062 
    1063                 if((name[i2-2]=='('&&name[i2-1]==')')||
    1064                     (name[i2-2]=='['&&name[i2-1]==']')){
    1065                     subScripts[0]=LONG_MAX;
    1066                     subScripts[1]=-1;
    1067 
    1068                     name[i2-2]=0;
    1069                 }
    1070                 else{
    1071                     GetArrange(name,temp2,subScripts);
    1072                     lstrcpy(name,temp2);
    1073                 }
    1074 
    1075                 i2=lstrlen(name);
    1076             }
    1077 
    1078             //型
    1079             Type type( DEF_NON );
    1080             if(buffer[i]==1&&buffer[i+1]==ESC_AS){
    1081                 i+=2;
    1082 
    1083                 i2=0;
    1084                 while(buffer[i]=='*'){
    1085                     temporary[i2]=buffer[i];
    1086                     i++;
    1087                     i2++;
    1088                 }
    1089                 for(;;i++,i2++){
    1090                     if(!IsVariableChar(buffer[i])){
    1091                         if(buffer[i]==1&&(buffer[i+1]==ESC_FUNCTION||buffer[i+1]==ESC_SUB)){
    1092                             temporary[i2++]=buffer[i++];
    1093                             temporary[i2]=buffer[i];
    1094                             continue;
    1095                         }
    1096                         temporary[i2]=0;
    1097                         break;
    1098                     }
    1099                     temporary[i2]=buffer[i];
    1100                 }
    1101 
    1102                 Type::StringToType( temporary, type );
    1103 
    1104                 if(temporary[0]=='*'&&
    1105                     temporary[1]==1&&
    1106                     (temporary[2]==ESC_FUNCTION||temporary[2]==ESC_SUB)){
    1107                     if(buffer[i]!='('){
    1108                         SetError(10,temporary,NowLine);
    1109                         break;
    1110                     }
    1111                     i3=GetStringInPare(temporary+i2,buffer+i);
    1112                     i+=i3;
    1113                     i2+=i3;
    1114 
    1115                     if(temporary[2]==ESC_FUNCTION&&buffer[i]==1&&buffer[i+1]==ESC_AS){
    1116                         temporary[i2++]=buffer[i++];
    1117                         temporary[i2++]=buffer[i++];
    1118                         for(;;i++,i2++){
    1119                             if(!IsVariableChar(buffer[i])){
    1120                                 temporary[i2]=0;
    1121                                 break;
    1122                             }
    1123                             temporary[i2]=buffer[i];
    1124                         }
    1125                     }
    1126                 }
    1127                 else{
    1128                     //TypeDefをする前のベース型を取得
    1129                     GetOriginalTypeName(temporary);
    1130                 }
    1131 
    1132                 if( type.IsNull() ){
    1133                     SetError(3,temporary,NowLine);
    1134                     type.SetBasicType( DEF_PTR_VOID );
    1135                 }
    1136             }
    1137             else{
    1138                 type.SetBasicType( GetTypeFromSimpleName(temporary) );
    1139                 SetError(-103,temporary,NowLine);
    1140             }
    1141 
    1142             if( type.IsProcPtr() ){
    1143                 //関数ポインタの場合
    1144                 type.SetIndex( AddProcPtrInfo(temporary+3,temporary[2]) );
    1145             }
    1146 
    1147             Parameter *pParam = new Parameter( name, type, isRef );
    1148             if( isArray ){
    1149                 pParam->SetArray( subScripts );
    1150             }
    1151 
    1152             //パラメータを追加
    1153             pSub->params.push_back( pParam );
    1154 
    1155             if(buffer[i]==','){
    1156                 i++;
    1157                 continue;
    1158             }
    1159             else if(buffer[i]==')') continue;
    1160             else{
    1161                 SetError(1,NULL,NowLine);
    1162                 break;
    1163             }
    1164         }
    1165         i++;
    1166     }
    1167 
    1168     //リアルパラメータ領域を取得(_System_LocalThisを考慮して2つだけ多く確保する場合がある)
    1169 
    1170     if(pobj_c&&bStatic==0){
    1171         //オブジェクトメンバの場合は、第一パラメータを_System_LocalThis引き渡し用として利用
    1172         string name = "_System_LocalThis";
    1173         Type type( DEF_PTR_VOID );
    1174         pSub->realParams.push_back( new Parameter( name, type ) );
    1175     }
    1176 
    1177     if(pSub->ReturnType==DEF_STRUCT){
    1178         //構造体を戻り値として持つ場合
    1179         //※第一パラメータ(Thisポインタありの場合は第二パラメータ)を戻り値用の参照宣言にする
    1180 
    1181         string name = pSub->name;
    1182         if(pSub->name[0]==1&&pSub->name[1]==ESC_OPERATOR){
    1183             name="_System_ReturnValue";
    1184         }
    1185         Type type( DEF_STRUCT, pSub->u.ReturnIndex );
    1186         pSub->realParams.push_back( new Parameter( name, type, true ) );
    1187     }
    1188 
    1189     //パラメータをコピー
    1190     foreach( Parameter *pParam, pSub->params ){
    1191         pSub->realParams.push_back( new Parameter( *pParam ) );
    1192     }
     574    pUserProc->id = (id_base++);
     575
     576    if(isExport){
     577        pUserProc->Using();
     578    }
     579
     580    // パラメータを解析
     581    // ※第1パラメータにに指定するデータの例:"( s As String ) As String"
     582    pUserProc->SetParamsAndReturnType( buffer + i, nowLine, isStatic );
    1193583
    1194584
     
    1198588
    1199589    int key;
    1200     key=hash_default(pSub->name);
    1201 
    1202     extern SubInfo **ppSubHash;
     590    key=hash_default(pUserProc->GetName().c_str());
     591
     592    extern UserProc **ppSubHash;
    1203593    if(ppSubHash[key]){
    1204         SubInfo *psi2;
     594        UserProc *psi2;
    1205595        psi2=ppSubHash[key];
    1206596        while(1){
    1207             if(pobj_c==psi2->pobj_ParentClass){
     597            if(pobj_c==psi2->GetParentClassPtr()){
    1208598                //重複エラーチェックを行う
    1209                 if(lstrcmp(psi2->name,pSub->name)==0){
    1210                     if( Parameter::Equals( psi2->params, pSub->params ) ){
    1211                         SetError(15,pSub->name,NowLine);
     599                if( pUserProc->GetName() == psi2->GetName() ){
     600                    if( Parameter::Equals( psi2->Params(), pUserProc->Params() ) ){
     601                        SetError(15,pUserProc->GetName().c_str(),nowLine);
    1212602                        return 0;
    1213603                    }
     
    1218608            psi2=psi2->pNextData;
    1219609        }
    1220         psi2->pNextData=pSub;
     610        psi2->pNextData=pUserProc;
    1221611    }
    1222612    else{
    1223         ppSubHash[key]=pSub;
    1224     }
    1225 
    1226     return pSub;
     613        ppSubHash[key]=pUserProc;
     614    }
     615
     616    return pUserProc;
    1227617}
    1228618
     
    1234624
    1235625    //Declare(DLL関数)情報を初期化
    1236     extern DECLAREINFO **ppDeclareHash;
    1237     ppDeclareHash=(DECLAREINFO **)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,MAX_HASH*sizeof(DECLAREINFO *));
     626    extern DllProc **ppDeclareHash;
     627    ppDeclareHash=(DllProc **)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,MAX_HASH*sizeof(DllProc *));
    1238628
    1239629    //サブルーチン(ユーザー定義)情報を初期化
    1240     extern SubInfo **ppSubHash;
     630    extern UserProc **ppSubHash;
    1241631    extern int SubNum;
    1242     ppSubHash=(SubInfo **)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,MAX_HASH*sizeof(SubInfo *));
     632    ppSubHash=(UserProc **)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,MAX_HASH*sizeof(UserProc *));
    1243633    SubNum=0;
    1244634
     
    1334724    AddSubData(temporary,0,0,0);
    1335725}
    1336 void Delete_si(SubInfo *pSub){
    1337     foreach( Parameter *pParam, pSub->params ){
    1338         delete pParam;
    1339     }
    1340 
    1341     foreach( Parameter *pParam, pSub->realParams ){
    1342         delete pParam;
    1343     }
    1344 
    1345     if(pSub->pNextData) Delete_si(pSub->pNextData);
    1346 
    1347     HeapDefaultFree(pSub->name);
    1348     delete pSub;
    1349 }
    1350 void DeleteSubInfo(SubInfo **ppSubHash,char **ppMacroNames,int MacroNum){   //サブルーチン情報のメモリ解放
     726void Delete_si(UserProc *pUserProc){
     727    if(pUserProc->pNextData) Delete_si(pUserProc->pNextData);
     728    delete pUserProc;
     729}
     730void DeleteSubInfo(UserProc **ppSubHash,char **ppMacroNames,int MacroNum){  //サブルーチン情報のメモリ解放
    1351731    int i;
    1352732    for(i=0;i<MAX_HASH;i++){
     
    1365745    }
    1366746}
    1367 void Delete_di(DECLAREINFO *pdi){
    1368     if(pdi->pParmInfo) HeapDefaultFree(pdi->pParmInfo);
    1369 
    1370     HeapDefaultFree(pdi->name);
    1371     if(pdi->file) HeapDefaultFree(pdi->file);
    1372     if(pdi->alias) HeapDefaultFree(pdi->alias);
    1373 
    1374     if(pdi->pNextData) Delete_di(pdi->pNextData);
    1375 
    1376     HeapDefaultFree(pdi);
     747void Delete_di(DllProc *pDllProc){
     748    if(pDllProc->pNextData) Delete_di(pDllProc->pNextData);
     749
     750    delete pDllProc;
    1377751}
    1378752void DeleteDeclareInfo(void){
    1379753    //DLL情報を解放
    1380     extern DECLAREINFO **ppDeclareHash;
     754    extern DllProc **ppDeclareHash;
    1381755    int i;
    1382756    for(i=0;i<MAX_HASH;i++){
     
    1394768///////////////////////
    1395769
    1396 int AddProcPtrInfo(char *buffer,DWORD dwProcType){
    1397     extern HANDLE hHeap;
    1398     extern int cp;
    1399     extern PROCPTRINFO *pProcPtrInfo;
     770int AddProcPtrInfo( char *buffer, DWORD dwProcType, int nowLine ){
     771
     772    Procedure::Kind kind = Procedure::Sub;
     773    if( dwProcType == ESC_FUNCTION ){
     774        kind = Procedure::Function;
     775    }
     776
     777    ProcPointer *pProcPointer = new ProcPointer( kind );
     778
     779    //buffer[0]は'('となっている
     780    pProcPointer->SetParamsAndReturnType( buffer, nowLine );
     781
     782    extern ProcPointer **ppProcPointer;
    1400783    extern int ProcPtrInfoNum;
    1401     int i,i2,i3,sw;
    1402     PROCPTRINFO *pi;
    1403     char temporary[VN_SIZE],temp2[VN_SIZE];
    1404 
    1405     pProcPtrInfo=(PROCPTRINFO *)HeapReAlloc(hHeap,0,pProcPtrInfo,(ProcPtrInfoNum+1)*sizeof(PROCPTRINFO));
    1406     pi=&pProcPtrInfo[ProcPtrInfoNum];
     784    ppProcPointer=(ProcPointer **)HeapReAlloc(hHeap,0,ppProcPointer,(ProcPtrInfoNum+1)*sizeof(ProcPointer *));
     785    ppProcPointer[ProcPtrInfoNum] = pProcPointer;
    1407786    ProcPtrInfoNum++;
    1408787
    1409     pi->pParmInfo=(PARAMETER_INFO *)HeapAlloc(hHeap,0,1);
    1410     pi->ParmNum=0;
    1411 
    1412     //buffer[0]は'('となっている
    1413     i=1;
    1414 
    1415     while(1){
    1416         if(buffer[i]==')') break;
    1417 
    1418         pi->pParmInfo=(PARAMETER_INFO *)HeapReAlloc(hHeap,0,pi->pParmInfo,(pi->ParmNum+1)*sizeof(PARAMETER_INFO));
    1419 
    1420         //ByVal
    1421         if(buffer[i]==1&&buffer[i+1]==ESC_BYVAL){
    1422             pi->pParmInfo[pi->ParmNum].bByVal=1;
    1423             i+=2;
    1424         }
    1425         else if(buffer[i]==1&&buffer[i+1]==ESC_BYREF){
    1426             pi->pParmInfo[pi->ParmNum].bByVal=0;
    1427             i+=2;
    1428         }
    1429         else pi->pParmInfo[pi->ParmNum].bByVal=1;
    1430 
    1431         //パラメータ名
    1432         sw=0;
    1433         for(i2=0;;i++,i2++){
    1434             if(buffer[i]=='('){
    1435                 if(!sw) sw=1;
    1436 
    1437                 i3=GetStringInPare(temporary+i2,buffer+i);
    1438                 i2+=i3-1;
    1439                 i+=i3-1;
    1440                 continue;
    1441             }
    1442             if(buffer[i]=='['){
    1443                 if(!sw) sw=1;
    1444 
    1445                 i3=GetStringInBracket(temporary+i2,buffer+i);
    1446                 i2+=i3-1;
    1447                 i+=i3-1;
    1448                 continue;
    1449             }
    1450             if(!IsVariableChar(buffer[i])){
    1451                 temporary[i2]=0;
    1452                 break;
    1453             }
    1454             temporary[i2]=buffer[i];
    1455         }
    1456         pi->pParmInfo[pi->ParmNum].name=0;
    1457 
    1458         if(sw){
    1459             //配列パラメータ
    1460             if(pi->pParmInfo[pi->ParmNum].bByVal) SetError(29,NULL,cp);
    1461             pi->pParmInfo[pi->ParmNum].bArray=1;
    1462 
    1463             if((temporary[i2-2]=='('&&temporary[i2-1]==')')||
    1464                 (temporary[i2-2]=='['&&temporary[i2-1]==']')){
    1465                 pi->pParmInfo[pi->ParmNum].SubScripts[0]=LONG_MAX;
    1466                 pi->pParmInfo[pi->ParmNum].SubScripts[1]=-1;
    1467 
    1468                 temporary[i2-2]=0;
    1469             }
    1470             else{
    1471                 GetArrange(temporary,temp2,pi->pParmInfo[pi->ParmNum].SubScripts);
    1472                 lstrcpy(temporary,temp2);
    1473             }
    1474 
    1475             i2=lstrlen(temporary);
    1476         }
    1477         else{
    1478             pi->pParmInfo[pi->ParmNum].bArray=0;
    1479             pi->pParmInfo[pi->ParmNum].SubScripts[0]=-1;
    1480         }
    1481 
    1482         //型
    1483         if(buffer[i]==1&&buffer[i+1]==ESC_AS){
    1484             i+=2;
    1485 
    1486             i2=0;
    1487             while(buffer[i]=='*'){
    1488                 temporary[i2]=buffer[i];
    1489                 i++;
    1490                 i2++;
    1491             }
    1492             for(;;i++,i2++){
    1493                 if(!IsVariableChar(buffer[i])){
    1494                     temporary[i2]=0;
    1495                     break;
    1496                 }
    1497                 temporary[i2]=buffer[i];
    1498             }
    1499 
    1500             pi->pParmInfo[pi->ParmNum].type=
    1501                 GetTypeFixed(temporary,&pi->pParmInfo[pi->ParmNum].u.index);
    1502             if(pi->pParmInfo[pi->ParmNum].type==-1){
    1503                 SetError(3,temporary,cp);
    1504                 pi->pParmInfo[pi->ParmNum].type=DEF_PTR_VOID;
    1505             }
    1506             if(pi->pParmInfo[pi->ParmNum].type==DEF_OBJECT){
    1507                 if(pi->pParmInfo[pi->ParmNum].bByVal) SetError(28,temporary,cp);
    1508             }
    1509         }
    1510         else{
    1511             pi->pParmInfo[pi->ParmNum].type=GetTypeFromSimpleName(temporary);
    1512             SetError(-103,temporary,cp);
    1513         }
    1514 
    1515         pi->ParmNum++;
    1516 
    1517         if(buffer[i]==','){
    1518             i++;
    1519             continue;
    1520         }
    1521         else if(buffer[i]==')') continue;
    1522         else{
    1523             SetError(1,NULL,cp);
    1524             return 0;
    1525         }
    1526     }
    1527     i++;
    1528 
    1529     //戻り値
    1530     if(dwProcType==ESC_FUNCTION){
    1531         if(buffer[i]==1&&buffer[i+1]==ESC_AS){
    1532             i+=2;
    1533             i2=0;
    1534             if(buffer[i]=='*') temporary[i2++]=buffer[i++];
    1535             for(;;i++,i2++){
    1536                 if(!IsVariableChar(buffer[i])){
    1537                     temporary[i2]=0;
    1538                     break;
    1539                 }
    1540                 temporary[i2]=buffer[i];
    1541             }
    1542             pi->ReturnType=GetTypeFixed(temporary,&pi->u.ReturnIndex);
    1543             if(pi->ReturnType==DEF_NON) SetError(3,temporary,cp);
    1544         }
    1545         else pi->ReturnType=DEF_DOUBLE;
    1546     }
    1547     else pi->ReturnType=DEF_NON;
    1548 
    1549788    return ProcPtrInfoNum-1;
    1550789}
    1551790void DeleteProcPtrInfo(void){
    1552     extern PROCPTRINFO *pProcPtrInfo;
     791    extern ProcPointer **ppProcPointer;
    1553792    extern int ProcPtrInfoNum;
    1554     int i;
    1555 
    1556     for(i=0;i<ProcPtrInfoNum;i++){
    1557         HeapDefaultFree(pProcPtrInfo[i].pParmInfo);
    1558     }
    1559 
    1560     HeapDefaultFree(pProcPtrInfo);
    1561 }
     793
     794    for(int i=0;i<ProcPtrInfoNum;i++){
     795        delete ppProcPointer[i];
     796    }
     797
     798    HeapDefaultFree(ppProcPointer);
     799}
Note: See TracChangeset for help on using the changeset viewer.