Ignore:
Timestamp:
May 6, 2008, 8:23:41 PM (16 years ago)
Author:
dai_9181
Message:

Parameters::Analyze → LexicalAnalyzer::AnalyzeParameter

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_Procedure.cpp

    r552 r568  
    22
    33using namespace ActiveBasic::Compiler;
     4
     5bool LexicalAnalyzer::AnalyzeParameter( Parameters &params, const char *sourceOfParams, int nowLine )
     6{
     7    int i2,i3,sw;
     8    char temporary[8192],temp2[VN_SIZE];
     9
     10    //パラメータ
     11    int i = 0;
     12    while(1){
     13        if( sourceOfParams[i] == '\0' )
     14        {
     15            break;
     16        }
     17
     18        //ByRef
     19        bool isRef;
     20        if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_BYVAL){
     21            isRef = false;
     22            i+=2;
     23        }
     24        else if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_BYREF){
     25            isRef = true;
     26            i+=2;
     27        }
     28        else isRef = false;
     29
     30        //パラメータ名
     31        bool isArray = false;
     32        Subscripts subscripts;
     33        char name[VN_SIZE];
     34        sw=0;
     35        for(i2=0;;i++,i2++){
     36            if(sourceOfParams[i]=='('){
     37                if(!sw) sw=1;
     38
     39                i3=GetStringInPare(name+i2,sourceOfParams+i);
     40                i2+=i3-1;
     41                i+=i3-1;
     42                continue;
     43            }
     44            if(sourceOfParams[i]=='['){
     45                if(!sw) sw=1;
     46
     47                i3=GetStringInBracket(name+i2,sourceOfParams+i);
     48                i2+=i3-1;
     49                i+=i3-1;
     50                continue;
     51            }
     52            if(!IsVariableChar(sourceOfParams[i])){
     53                name[i2]=0;
     54                break;
     55            }
     56            name[i2]=sourceOfParams[i];
     57        }
     58        if(sw){
     59            //配列パラメータ
     60            if( isRef == false )
     61            {
     62                compiler.errorMessenger.Output(29,NULL,nowLine);
     63            }
     64            isArray = true;
     65
     66            if((name[i2-2]=='('&&name[i2-1]==')')||
     67                (name[i2-2]=='['&&name[i2-1]==']'))
     68            {
     69                subscripts.push_back( LONG_MAX );
     70
     71                name[i2-2]=0;
     72            }
     73            else{
     74                GetArrange(name,temp2,subscripts);
     75                lstrcpy(name,temp2);
     76            }
     77
     78            i2=lstrlen(name);
     79        }
     80
     81        Type type( DEF_NON );
     82        char initValue[8192] = "";
     83        if( sourceOfParams[i] == '=' ){
     84            i++;
     85            i = GetOneParameter( sourceOfParams, i, initValue );
     86
     87            // TODO: エラー用 fix me!!!
     88            //cp = nowLine;
     89
     90            NumOpe_GetType( initValue, GetStringTypeInfo(), type );
     91           
     92            if( IS_LITERAL(type.GetIndex()) )
     93            {
     94                type.SetIndex( -1 );
     95            }
     96        }
     97        else if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_AS){
     98            // As指定
     99            i+=2;
     100
     101            i2=0;
     102            while(sourceOfParams[i]=='*'){
     103                temporary[i2]=sourceOfParams[i];
     104                i++;
     105                i2++;
     106            }
     107            for(;;i++,i2++){
     108                if(!IsVariableChar(sourceOfParams[i])){
     109                    if(sourceOfParams[i]==1&&(sourceOfParams[i+1]==ESC_FUNCTION||sourceOfParams[i+1]==ESC_SUB)){
     110                        temporary[i2++]=sourceOfParams[i++];
     111                        temporary[i2]=sourceOfParams[i];
     112                        continue;
     113                    }
     114                    temporary[i2]=0;
     115                    break;
     116                }
     117                temporary[i2]=sourceOfParams[i];
     118            }
     119
     120            compiler.StringToType( temporary, type );
     121
     122            if( type.IsNull() ){
     123                compiler.errorMessenger.Output(3,temporary,nowLine);
     124                type.SetBasicType( DEF_PTR_VOID );
     125            }
     126
     127            if( type.IsObject() ){
     128                if( type.GetClass().IsBlittableType() ){
     129                    // Blittable型のときは基本型として扱う
     130                    type = type.GetClass().GetBlittableType();
     131                }
     132            }
     133        }
     134        else{
     135            type.SetBasicType( Type::GetBasicTypeFromSimpleName(temporary) );
     136            compiler.errorMessenger.Output(-103,temporary,nowLine);
     137        }
     138
     139        Parameter *pParam = new Parameter( name, type, isRef, initValue );
     140        if( isArray ){
     141            pParam->SetArray( subscripts );
     142        }
     143
     144        //パラメータを追加
     145        params.push_back( pParam );
     146
     147        if( sourceOfParams[i] == ',' )
     148        {
     149            i++;
     150            continue;
     151        }
     152        else if( sourceOfParams[i] == '\0' )
     153        {
     154            break;
     155        }
     156        else{
     157            compiler.errorMessenger.Output(1,NULL,nowLine);
     158            break;
     159        }
     160    }
     161
     162    return true;
     163}
    4164
    5165UserProc* LexicalAnalyzer::ParseUserProc( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, char *buffer,int nowLine,bool isVirtual,CClass *pobj_c, bool isStatic, char *interfaceName )
Note: See TracChangeset for help on using the changeset viewer.