Ignore:
Timestamp:
Mar 19, 2012, 1:59:48 AM (12 years ago)
Author:
イグトランス (egtra)
Message:

egtraブランチの内容をマージ。

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/ab5.0/abdev

    • Property svn:ignore set to
      *.opensdf
      *.sdf
      *.suo
      *.user
      int
      ipch
      out
  • trunk/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_TypeDef.cpp

    r668 r828  
    11#include "stdafx.h"
     2#include <abdev/ab_common/include/ab_common.h>
     3#include "LexicalAnalyzer.h"
     4#include "Compiler.h"
     5#include "StrOperation.h"
     6#include <boost/algorithm/string/predicate.hpp>
    27
    38using namespace ActiveBasic::Compiler;
    49
    5 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 )
    611{
    7     int i;
    8     char temporary[VN_SIZE];
     12    auto name = boost::find<boost::return_begin_found>(expression, '=');
    913
    10     for(i=0;;i++){
    11         if(expression[i]=='='||expression[i]=='\0'){
    12             temporary[i]=0;
    13             break;
    14         }
    15         temporary[i]=expression[i];
    16     }
    17 
    18     if(expression[i]!='='){
    19         compiler.errorMessenger.Output(10,"TypeDef",nowLine);
     14    if (boost::end(name) == boost::end(expression))
     15    {
     16        compiler.errorMessenger.Output(10, "TypeDef", nowLine);
    2017        return;
    2118    }
    2219
    23     const char *pTemp=expression.c_str()+i+1;
     20    const char *pTemp = expression.begin() + boost::size(name) + 1;
    2421
    2522    //識別文字のエラーチェック(新しい型)
    26     i=0;
    27     for(;;i++){
    28         if(temporary[i]=='\0') break;
    29         if( !( IsVariableChar( temporary[i], true) ) ){
    30             compiler.errorMessenger.Output(10,"TypeDef",nowLine);
    31             return;
    32         }
     23    if (!boost::algorithm::all(name, [](char c) {return IsVariableChar(c, true);}))
     24    {
     25        compiler.errorMessenger.Output(10, "TypeDef", nowLine);
     26        return;
    3327    }
    3428
     
    4135        }
    4236    }
    43     else{
    44         i=0;
     37    else
     38    {
     39        int i=0;
    4540        while(pTemp[i]=='*') i++;
    46         for(;;i++){
    47             if(pTemp[i]=='\0') break;
    48             if( !( IsVariableChar( pTemp[i], true) ) )
    49             {
    50                 compiler.errorMessenger.Output(10,"TypeDef",nowLine);
    51                 return;
    52             }
     41        if (!boost::algorithm::all(name, [](char c) {return IsVariableChar(c, true);}))
     42        {
     43            compiler.errorMessenger.Output(10,"TypeDef",nowLine);
     44            return;
    5345        }
    5446    }
    5547
     48    std::string baseName(pTemp, expression.end());
     49
    5650    //識別子が重複している場合はエラーにする
    57     if(lstrcmp(temporary,pTemp)==0){
     51    if (boost::algorithm::equals(name, baseName))
     52    {
    5853        compiler.errorMessenger.Output(1,NULL,nowLine);
    5954        return;
     
    6762
    6863    Type baseType;
    69     if( !compiler.StringToType( pTemp, baseType ) )
     64    if( !compiler.StringToType( baseName, baseType ) )
    7065    {
    71         compiler.errorMessenger.Output(3, pTemp, nowLine );
     66        compiler.errorMessenger.Output(3, baseName, nowLine );
    7267        return;
    7368    }
     
    7570    typeDefs.push_back(
    7671        TypeDef(
    77             Symbol( namespaceScopes, temporary ),
    78             pTemp,
     72            Symbol(namespaceScopes, boost::copy_range<std::string>(name)),
     73            baseName,
    7974            baseType
    8075        )
     
    9085    compiler.GetNamespaceSupporter().ClearImportedNamespaces();
    9186
    92     int i=-1, i2;
    93     char temporary[VN_SIZE];
    94     while(1){
    95 
    96         i++;
    97 
     87    for (int i = 0; ; ++i)
     88    {
    9889        if( source[i] == 1 && source[i+1] == ESC_NAMESPACE ){
    99             for(i+=2,i2=0;;i2++,i++){
    100                 if( IsCommandDelimitation( source[i] ) ){
    101                     temporary[i2]=0;
    102                     break;
    103                 }
    104                 temporary[i2]=source[i];
     90            i+=2;
     91            char const* p = &source[i];
     92            while (!IsCommandDelimitation(source[i]))
     93            {
     94                ++i;
    10595            }
    106             namespaceScopes.push_back( temporary );
     96            namespaceScopes.push_back(std::string(p, &source[i]));
    10797
    10898            continue;
     
    120110        }
    121111        else if( source[i] == 1 && source[i+1] == ESC_IMPORTS ){
    122             for(i+=2,i2=0;;i2++,i++){
    123                 if( IsCommandDelimitation( source[i] ) ){
    124                     temporary[i2]=0;
    125                     break;
    126                 }
    127                 temporary[i2]=source[i];
     112            i+=2;
     113            char const* p = &source[i];
     114            while (!IsCommandDelimitation(source[i]))
     115            {
     116                ++i;
    128117            }
    129             if( !compiler.GetNamespaceSupporter().ImportsNamespace( temporary ) )
     118            std::string s(p, &source[i]);
     119            if (!compiler.GetNamespaceSupporter().ImportsNamespace(s))
    130120            {
    131                 compiler.errorMessenger.Output(64,temporary,i );
     121                compiler.errorMessenger.Output(64, s.c_str(), i);
    132122            }
    133123
     
    144134            char temporary[VN_SIZE];
    145135            if(source[i+1]==ESC_TYPEDEF){
    146                 int i2 = 0;
    147                 for(i+=2;;i2++,i++){
    148                     if(source[i]=='\n'){
    149                         temporary[i2]=0;
    150                         break;
    151                     }
    152                     temporary[i2]=source[i];
    153                     if(source[i]=='\0') break;
     136                i+=2;
     137                char const* p = &source[i];
     138                while (!IsCommandDelimitation(source[i]))
     139                {
     140                    ++i;
    154141                }
    155                 AddTypeDef( typeDefs, namespaceScopes, temporary, i );
    156 
     142                AddTypeDef(typeDefs, namespaceScopes, boost::make_iterator_range(p, &source[i]), i);
    157143                continue;
    158144            }
     
    168154                }
    169155
    170                 Type baseType;
    171                 if( !compiler.StringToType( "Long", baseType ) )
    172                 {
    173                     throw;
    174                 }
    175 
    176156                typeDefs.push_back(
    177157                    TypeDef(
    178158                        Symbol( namespaceScopes, temporary ),
    179159                        "Long",
    180                         baseType
     160                        Type(DEF_LONG)
    181161                    )
    182162                );
Note: See TracChangeset for help on using the changeset viewer.