Ignore:
Timestamp:
Mar 19, 2011, 1:29:12 AM (13 years ago)
Author:
イグトランス (egtra)
Message:

LexicalAnalyzer周りの修正

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/egtra/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_TypeDef.cpp

    r812 r814  
    44#include "Compiler.h"
    55#include "StrOperation.h"
     6#include <boost/algorithm/string/predicate.hpp>
    67
    78using namespace ActiveBasic::Compiler;
    89
    9 void LexicalAnalyzer::AddTypeDef( TypeDefCollection &typeDefs, const NamespaceScopes &namespaceScopes, const std::string &expression, int nowLine )
     10void LexicalAnalyzer::AddTypeDef( TypeDefCollection &typeDefs, const NamespaceScopes &namespaceScopes, const boost::iterator_range<char const*> &expression, int nowLine )
    1011{
    11     int i;
    12     char temporary[VN_SIZE];
     12    auto name = boost::find<boost::return_begin_found>(expression, '=');
    1313
    14     for(i=0;;i++){
    15         if(expression[i]=='='||expression[i]=='\0'){
    16             temporary[i]=0;
    17             break;
    18         }
    19         temporary[i]=expression[i];
    20     }
    21 
    22     if(expression[i]!='='){
    23         compiler.errorMessenger.Output(10,"TypeDef",nowLine);
     14    if (boost::end(name) == boost::end(expression))
     15    {
     16        compiler.errorMessenger.Output(10, "TypeDef", nowLine);
    2417        return;
    2518    }
    2619
    27     const char *pTemp=expression.c_str()+i+1;
     20    const char *pTemp = expression.begin() + boost::size(name) + 1;
    2821
    2922    //識別文字のエラーチェック(新しい型)
    30     i=0;
    31     for(;;i++){
    32         if(temporary[i]=='\0') break;
    33         if( !( IsVariableChar( temporary[i], true) ) ){
    34             compiler.errorMessenger.Output(10,"TypeDef",nowLine);
    35             return;
    36         }
     23    if (!boost::algorithm::all(name, [](char c) {return IsVariableChar(c, true);}))
     24    {
     25        compiler.errorMessenger.Output(10, "TypeDef", nowLine);
     26        return;
    3727    }
    3828
     
    4535        }
    4636    }
    47     else{
    48         i=0;
     37    else
     38    {
     39        int i=0;
    4940        while(pTemp[i]=='*') i++;
    50         for(;;i++){
    51             if(pTemp[i]=='\0') break;
    52             if( !( IsVariableChar( pTemp[i], true) ) )
    53             {
    54                 compiler.errorMessenger.Output(10,"TypeDef",nowLine);
    55                 return;
    56             }
     41        if (!boost::algorithm::all(name, [](char c) {return IsVariableChar(c, true);}))
     42        {
     43            compiler.errorMessenger.Output(10,"TypeDef",nowLine);
     44            return;
    5745        }
    5846    }
    5947
     48    std::string baseName(pTemp, expression.end());
     49
    6050    //識別子が重複している場合はエラーにする
    61     if(lstrcmp(temporary,pTemp)==0){
     51    if (boost::algorithm::equals(name, baseName))
     52    {
    6253        compiler.errorMessenger.Output(1,NULL,nowLine);
    6354        return;
     
    7162
    7263    Type baseType;
    73     if( !compiler.StringToType( pTemp, baseType ) )
     64    if( !compiler.StringToType( baseName, baseType ) )
    7465    {
    75         compiler.errorMessenger.Output(3, pTemp, nowLine );
     66        compiler.errorMessenger.Output(3, baseName, nowLine );
    7667        return;
    7768    }
     
    7970    typeDefs.push_back(
    8071        TypeDef(
    81             Symbol( namespaceScopes, temporary ),
    82             pTemp,
     72            Symbol(namespaceScopes, boost::copy_range<std::string>(name)),
     73            baseName,
    8374            baseType
    8475        )
     
    9485    compiler.GetNamespaceSupporter().ClearImportedNamespaces();
    9586
    96     int i=-1, i2;
    97     char temporary[VN_SIZE];
    98     while(1){
    99 
    100         i++;
    101 
     87    for (int i = 0; ; ++i)
     88    {
    10289        if( source[i] == 1 && source[i+1] == ESC_NAMESPACE ){
    103             for(i+=2,i2=0;;i2++,i++){
    104                 if( IsCommandDelimitation( source[i] ) ){
    105                     temporary[i2]=0;
    106                     break;
    107                 }
    108                 temporary[i2]=source[i];
     90            i+=2;
     91            char const* p = &source[i];
     92            while (!IsCommandDelimitation(source[i]))
     93            {
     94                ++i;
    10995            }
    110             namespaceScopes.push_back( temporary );
     96            namespaceScopes.push_back(std::string(p, &source[i]));
    11197
    11298            continue;
     
    124110        }
    125111        else if( source[i] == 1 && source[i+1] == ESC_IMPORTS ){
    126             for(i+=2,i2=0;;i2++,i++){
    127                 if( IsCommandDelimitation( source[i] ) ){
    128                     temporary[i2]=0;
    129                     break;
    130                 }
    131                 temporary[i2]=source[i];
     112            i+=2;
     113            char const* p = &source[i];
     114            while (!IsCommandDelimitation(source[i]))
     115            {
     116                ++i;
    132117            }
    133             if( !compiler.GetNamespaceSupporter().ImportsNamespace( temporary ) )
     118            std::string s(p, &source[i]);
     119            if (!compiler.GetNamespaceSupporter().ImportsNamespace(s))
    134120            {
    135                 compiler.errorMessenger.Output(64,temporary,i );
     121                compiler.errorMessenger.Output(64, s.c_str(), i);
    136122            }
    137123
     
    148134            char temporary[VN_SIZE];
    149135            if(source[i+1]==ESC_TYPEDEF){
    150                 int i2 = 0;
    151                 for(i+=2;;i2++,i++){
    152                     if(source[i]=='\n'){
    153                         temporary[i2]=0;
    154                         break;
    155                     }
    156                     temporary[i2]=source[i];
    157                     if(source[i]=='\0') break;
     136                i+=2;
     137                char const* p = &source[i];
     138                while (!IsCommandDelimitation(source[i]))
     139                {
     140                    ++i;
    158141                }
    159                 AddTypeDef( typeDefs, namespaceScopes, temporary, i );
    160 
     142                AddTypeDef(typeDefs, namespaceScopes, boost::make_iterator_range(p, &source[i]), i);
    161143                continue;
    162144            }
     
    172154                }
    173155
    174                 Type baseType;
    175                 if( !compiler.StringToType( "Long", baseType ) )
    176                 {
    177                     throw;
    178                 }
    179 
    180156                typeDefs.push_back(
    181157                    TypeDef(
    182158                        Symbol( namespaceScopes, temporary ),
    183159                        "Long",
    184                         baseType
     160                        Type(DEF_LONG)
    185161                    )
    186162                );
Note: See TracChangeset for help on using the changeset viewer.