Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/ExpressionNode.cc

    r013b028 rb81fd95  
    1010// Created On       : Sat May 16 13:17:07 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug 20 14:01:46 2020
    13 // Update Count     : 1076
     12// Last Modified On : Wed Jul 15 08:24:08 2020
     13// Update Count     : 1046
    1414//
    1515
     
    6565
    6666void lnthSuffix( string & str, int & type, int & ltype ) {
    67         // 'u' can appear before or after length suffix
    6867        string::size_type posn = str.find_last_of( "lL" );
    6968
    7069        if ( posn == string::npos ) return;                                     // no suffix
    71         size_t end = str.length() - 1;
    72         if ( posn == end ) { type = 3; return; }                        // no length after 'l' => long
    73        
     70        if ( posn == str.length() - 1 ) { type = 3; return; } // no length => long
     71
    7472        string::size_type next = posn + 1;                                      // advance to length
    7573        if ( str[next] == '3' ) {                                                       // 32
     
    8684                } // if
    8785        } // if
    88 
    89         char fix = '\0';
    90         if ( str[end] == 'u' || str[end] == 'U' ) fix = str[end]; // ends with 'uU' ?
    91         str.erase( posn );                                                                      // remove length suffix and possibly uU
    92         if ( type == 5 ) {                                                                      // L128 does not need uU
    93                 end = str.length() - 1;
    94                 if ( str[end] == 'u' || str[end] == 'U' ) str.erase( end ); // ends with 'uU' ? remove
    95         } else if ( fix != '\0' ) str += fix;                           // put 'uU' back if removed
     86        // remove "lL" for these cases because it may not imply long
     87        str.erase( posn );                                                                      // remove length suffix and "uU"
    9688} // lnthSuffix
    9789
     
    164156        if ( isdigit( str[str.length() - 1] ) ) {                       // no suffix ?
    165157                lnthSuffix( str, type, ltype );                                 // could have length suffix
     158                if ( type == 5 && Unsigned ) str.erase( str.length() - 1 ); // L128 and terminating "uU" ?
    166159        } else {
    167160                // At least one digit in integer constant, so safe to backup while looking for suffix.
     
    202195                        if ( type < 5 ) {                                                       // not L128 ?
    203196                                sscanf( (char *)str.c_str(), "%llx", &v );
    204 #if defined(__SIZEOF_INT128__)
    205197                        } else {                                                                        // hex int128 constant
    206198                                unsigned int len = str.length();
     
    212204                          FHEX1: ;
    213205                                sscanf( (char *)str.c_str(), "%llx", &v );
    214 #endif // __SIZEOF_INT128__
    215206                        } // if
    216207                        //printf( "%llx %llu\n", v, v );
    217208                } else if ( checkB( str[1] ) ) {                                // binary constant ?
    218 #if defined(__SIZEOF_INT128__)
    219209                        unsigned int len = str.length();
    220210                        if ( type == 5 && len > 2 + 64 ) {
     
    224214                                scanbin( str2, v2 );
    225215                        } // if
    226 #endif // __SIZEOF_INT128__
    227216                        scanbin( str, v );
    228217                        //printf( "%#llx %llu\n", v, v );
     
    234223                                unsigned int len = str.length();
    235224                                if ( len > 1 + 43 || (len == 1 + 43 && str[0] > '3') ) SemanticError( yylloc, "128-bit octal constant to large " + str );
    236                                 char buf[32];
    237225                                if ( len <= 1 + 21 ) {                                  // value < 21 octal digitis
    238                                         sscanf( (char *)str.c_str(), "%llo", &v );
     226                                        sscanf( (char *)str.c_str(), "%llo", &v ); // leave value in octal
    239227                                } else {
    240228                                        sscanf( &str[len - 21], "%llo", &v );
     
    249237                                        } // if
    250238                                        v = val >> 64; v2 = (uint64_t)val;      // replace octal constant with 2 hex constants
     239                                        char buf[32];
    251240                                        sprintf( buf, "%#llx", v2 );
    252241                                        str2 = buf;
     242                                        sprintf( buf, "%#llx", v );
     243                                        str = buf;
    253244                                } // if
    254                                 sprintf( buf, "%#llx", v );
    255                                 str = buf;
    256245#endif // __SIZEOF_INT128__
    257246                        } // if
     
    267256                        if ( str.length() == 39 && str > (Unsigned ? "340282366920938463463374607431768211455" : "170141183460469231731687303715884105727") )
    268257                                SemanticError( yylloc, "128-bit decimal constant to large " + str );
    269                         char buf[32];
    270258                        if ( len <= 19 ) {                                                      // value < 19 decimal digitis
    271                                 sscanf( (char *)str.c_str(), "%llu", &v );
     259                                sscanf( (char *)str.c_str(), "%llu", &v ); // leave value in decimal
    272260                        } else {
    273261                                sscanf( &str[len - 19], "%llu", &v );
     
    282270                                } // if
    283271                                v = val >> 64; v2 = (uint64_t)val;              // replace decimal constant with 2 hex constants
     272                                char buf[32];
    284273                                sprintf( buf, "%#llx", v2 );
    285274                                str2 = buf;
     275                                sprintf( buf, "%#llx", v );
     276                                str = buf;
    286277                        } // if
    287                         sprintf( buf, "%#llx", v );
    288                         str = buf;
    289278#endif // __SIZEOF_INT128__
    290279                } // if
Note: See TracChangeset for help on using the changeset viewer.