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

    r465 r568  
    8888}
    8989
    90 bool Parameters::Analyze( const char *sourceOfParams, int nowLine )
    91 {
    92     int i2,i3,sw;
    93     char temporary[8192],temp2[VN_SIZE];
    94 
    95     //パラメータ
    96     int i = 0;
    97     while(1){
    98         if( sourceOfParams[i] == '\0' )
    99         {
    100             break;
    101         }
    102 
    103         //ByRef
    104         bool isRef;
    105         if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_BYVAL){
    106             isRef = false;
    107             i+=2;
    108         }
    109         else if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_BYREF){
    110             isRef = true;
    111             i+=2;
    112         }
    113         else isRef = false;
    114 
    115         //パラメータ名
    116         bool isArray = false;
    117         Subscripts subscripts;
    118         char name[VN_SIZE];
    119         sw=0;
    120         for(i2=0;;i++,i2++){
    121             if(sourceOfParams[i]=='('){
    122                 if(!sw) sw=1;
    123 
    124                 i3=GetStringInPare(name+i2,sourceOfParams+i);
    125                 i2+=i3-1;
    126                 i+=i3-1;
    127                 continue;
    128             }
    129             if(sourceOfParams[i]=='['){
    130                 if(!sw) sw=1;
    131 
    132                 i3=GetStringInBracket(name+i2,sourceOfParams+i);
    133                 i2+=i3-1;
    134                 i+=i3-1;
    135                 continue;
    136             }
    137             if(!IsVariableChar(sourceOfParams[i])){
    138                 name[i2]=0;
    139                 break;
    140             }
    141             name[i2]=sourceOfParams[i];
    142         }
    143         if(sw){
    144             //配列パラメータ
    145             if( isRef == false )
    146             {
    147                 compiler.errorMessenger.Output(29,NULL,nowLine);
    148             }
    149             isArray = true;
    150 
    151             if((name[i2-2]=='('&&name[i2-1]==')')||
    152                 (name[i2-2]=='['&&name[i2-1]==']'))
    153             {
    154                 subscripts.push_back( LONG_MAX );
    155 
    156                 name[i2-2]=0;
    157             }
    158             else{
    159                 GetArrange(name,temp2,subscripts);
    160                 lstrcpy(name,temp2);
    161             }
    162 
    163             i2=lstrlen(name);
    164         }
    165 
    166         Type type( DEF_NON );
    167         char initValue[8192] = "";
    168         if( sourceOfParams[i] == '=' ){
    169             i++;
    170             i = GetOneParameter( sourceOfParams, i, initValue );
    171 
    172             // TODO: エラー用 fix me!!!
    173             //cp = nowLine;
    174 
    175             NumOpe_GetType( initValue, GetStringTypeInfo(), type );
    176            
    177             if( IS_LITERAL(type.GetIndex()) )
    178             {
    179                 type.SetIndex( -1 );
    180             }
    181         }
    182         else if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_AS){
    183             // As指定
    184             i+=2;
    185 
    186             i2=0;
    187             while(sourceOfParams[i]=='*'){
    188                 temporary[i2]=sourceOfParams[i];
    189                 i++;
    190                 i2++;
    191             }
    192             for(;;i++,i2++){
    193                 if(!IsVariableChar(sourceOfParams[i])){
    194                     if(sourceOfParams[i]==1&&(sourceOfParams[i+1]==ESC_FUNCTION||sourceOfParams[i+1]==ESC_SUB)){
    195                         temporary[i2++]=sourceOfParams[i++];
    196                         temporary[i2]=sourceOfParams[i];
    197                         continue;
    198                     }
    199                     temporary[i2]=0;
    200                     break;
    201                 }
    202                 temporary[i2]=sourceOfParams[i];
    203             }
    204 
    205             compiler.StringToType( temporary, type );
    206 
    207             if( type.IsNull() ){
    208                 compiler.errorMessenger.Output(3,temporary,nowLine);
    209                 type.SetBasicType( DEF_PTR_VOID );
    210             }
    211 
    212             if( type.IsObject() ){
    213                 if( type.GetClass().IsBlittableType() ){
    214                     // Blittable型のときは基本型として扱う
    215                     type = type.GetClass().GetBlittableType();
    216                 }
    217             }
    218         }
    219         else{
    220             type.SetBasicType( Type::GetBasicTypeFromSimpleName(temporary) );
    221             compiler.errorMessenger.Output(-103,temporary,nowLine);
    222         }
    223 
    224         Parameter *pParam = new Parameter( name, type, isRef, initValue );
    225         if( isArray ){
    226             pParam->SetArray( subscripts );
    227         }
    228 
    229         //パラメータを追加
    230         this->push_back( pParam );
    231 
    232         if( sourceOfParams[i] == ',' )
    233         {
    234             i++;
    235             continue;
    236         }
    237         else if( sourceOfParams[i] == '\0' )
    238         {
    239             break;
    240         }
    241         else{
    242             compiler.errorMessenger.Output(1,NULL,nowLine);
    243             break;
    244         }
    245     }
    246 
    247     return true;
    248 }
    249 
    25090std::string Parameters::GetString() const
    25191{
Note: See TracChangeset for help on using the changeset viewer.