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_Const.cpp

    r637 r828  
    8585
    8686    int i2;
    87     char temporary[1024];
    8887
    8988    // 名前空間管理
     
    9190    namespaceScopes.clear();
    9291
    93     for(int i=0;;i++){
     92    for (int i = 0; ; ++i)
     93    {
    9494        if( source[i] == '\0' ) break;
    9595
    9696        if( source[i] == 1 && source[i+1] == ESC_NAMESPACE ){
    97             for(i+=2,i2=0;;i2++,i++){
    98                 if( IsCommandDelimitation( source[i] ) ){
    99                     temporary[i2]=0;
    100                     break;
    101                 }
    102                 temporary[i2]=source[i];
    103             }
    104             namespaceScopes.push_back( temporary );
     97            i+=2;
     98            char const* p = &source[i];
     99            while (!IsCommandDelimitation(source[i]))
     100            {
     101                ++i;
     102            }
     103            namespaceScopes.push_back(std::string(p, &source[i]));
    105104
    106105            continue;
     
    131130                }
    132131
     132                char const* beginTemp = &source[i];
     133                char const* endTemp = &source[i];
     134
    133135                for(i2=0;;i++,i2++){
    134136                    if(source[i]=='\"'){
    135                         temporary[i2]=source[i];
    136137                        for(i++,i2++;;i++,i2++){
    137                             temporary[i2]=source[i];
    138138                            if(source[i]=='\"') break;
    139139                        }
     
    141141                    }
    142142                    if(IsCommandDelimitation(source[i])){
    143                         temporary[i2]=0;
     143                        endTemp = beginTemp + i2;
    144144                        break;
    145145                    }
    146                     temporary[i2]=source[i];
    147146                }
    148147
    149148                //名前を取得
    150                 char name[VN_SIZE];
     149                char const* nameEnd;
    151150                for(i2=0;;i2++){
    152                     if(temporary[i2]=='\0'){
     151                    if(beginTemp[i2]=='\0'){
    153152                        compiler.errorMessenger.Output(10,"Const",cp);
    154153                        return;
    155154                    }
    156                     if(temporary[i2]=='='||temporary[i2]=='('){
    157                         name[i2]=0;
     155                    if(beginTemp[i2]=='='||beginTemp[i2]=='('){
     156                        nameEnd = beginTemp + i2;
    158157                        break;
    159158                    }
    160                     name[i2]=temporary[i2];
    161                 }
     159                }
     160                std::string name(beginTemp, nameEnd);
    162161
    163162                //重複チェック
     
    165164                    || compiler.GetObjectModule().meta.GetGlobalConsts().IsExistDuplicationKeyName( name ) )
    166165                {
    167                     compiler.errorMessenger.Output(15,name,cp);
     166                    compiler.errorMessenger.Output(15, name, cp);
    168167                    return;
    169168                }
    170169
    171                 if( temporary[i2] == '=' )
     170                if( beginTemp[i2] == '=' )
    172171                {
    173172                    // 定数
    174                     const char *expression = temporary + i2 + 1;
     173                    std::string expression(beginTemp + i2 + 1, endTemp);
    175174
    176175                    _int64 i64data;
    177176                    Type resultType;
    178                     if( StaticCalculation(false, expression, 0, &i64data, resultType) )
     177                    if( StaticCalculation(false, expression.c_str(), 0, &i64data, resultType) )
    179178                    {
    180179                        consts.Add( Symbol( namespaceScopes, name ), i64data, resultType );
     
    184183                {
    185184                    // 定数マクロ
    186                     const char *params = temporary + i2;
    187                     if( !constMacros.Add( Symbol( namespaceScopes, name ), params ) )
     185                    std::string params(beginTemp + i2, endTemp);
     186                    if( !constMacros.Add( Symbol( namespaceScopes, name ), params.c_str() ) )
    188187                    {
    189188                        compiler.errorMessenger.Output( 1, NULL, i );
     
    206205        }
    207206    }
    208 
    209     // イテレータを初期化
    210     compiler.GetObjectModule().meta.GetGlobalConsts().Iterator_Init();
    211     compiler.GetObjectModule().meta.GetGlobalConstMacros().Iterator_Init();
    212 }
    213 
    214 bool LexicalAnalyzer::ConstMacroToExpression( const ConstMacro &constMacro, const char *parameterStr, char *dest )
    215 {
    216     extern HANDLE hHeap;
    217     int i2,i3,i4,num;
     207}
     208
     209bool LexicalAnalyzer::ConstMacroToExpression( const ConstMacro &constMacro, const char *parameterStr, char *dest, std::size_t destSize )
     210{
     211    std::string s;
     212    auto ret = ConstMacroToExpression(constMacro, parameterStr, s);
     213    strcpy_s(dest, destSize, s.c_str());
     214    return ret;
     215}
     216
     217bool LexicalAnalyzer::ConstMacroToExpression( const ConstMacro &constMacro, const char *parameterStr, std::string& dest )
     218{
     219    int i2,i3;
    218220    char temporary[VN_SIZE];
    219     char *pParms[MAX_PARMS];
    220     num=0;
     221    std::vector<std::string> Parms;
     222    dest.reserve(8192);
    221223    i2=0;
    222224    while(1){
    223225        i2=GetOneParameter(parameterStr,i2,temporary);
    224226
    225         pParms[num]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);
    226         lstrcpy(pParms[num],temporary);
    227 
    228         num++;
     227        Parms.push_back(temporary);
     228
    229229        if(parameterStr[i2]=='\0') break;
    230230    }
    231     if( num != constMacro.GetParameters().size() ){
     231    if( Parms.size() != constMacro.GetParameters().size() ){
    232232        extern int cp;
    233         for(i2=0;i2<num;i2++) HeapDefaultFree(pParms[i2]);
    234233        compiler.errorMessenger.Output(10,constMacro.GetName().c_str(),cp);
    235         lstrcpy(dest,"0");
     234        dest = '0';
    236235        return true;
    237236    }
    238237
    239238    i2=0;
    240     i4=0;
    241239    while(1){
    242240
     
    257255        if( i3 == (int)constMacro.GetParameters().size() ){
    258256            //パラメータでないとき
    259             lstrcpy(dest+i4,temporary);
    260             i4+=lstrlen(temporary);
     257            dest += temporary;
    261258        }
    262259        else{
    263260            //パラメータのとき
    264             lstrcpy(dest+i4,pParms[i3]);
    265             i4+=lstrlen(pParms[i3]);
     261            dest += Parms[i3];
    266262        }
    267263
    268264        //演算子をコピー
    269         for(;;i2++,i4++){
     265        for(;;i2++){
    270266            if( constMacro.GetExpression()[i2] == 1 ){
    271                 dest[i4++] = constMacro.GetExpression()[i2++];
    272                 dest[i4] = constMacro.GetExpression()[i2];
     267                dest += constMacro.GetExpression()[i2++];
     268                dest += constMacro.GetExpression()[i2];
    273269                continue;
    274270            }
    275271            if(IsVariableTopChar( constMacro.GetExpression()[i2] )) break;
    276             dest[i4] = constMacro.GetExpression()[i2];
     272            dest += constMacro.GetExpression()[i2];
    277273            if( constMacro.GetExpression()[i2] == '\0' ) break;
    278274        }
     
    281277    }
    282278
    283     for(i2=0;i2<num;i2++) HeapDefaultFree(pParms[i2]);
    284 
    285279    return true;
    286280}
Note: See TracChangeset for help on using the changeset viewer.