Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/ExpressionNode.cc

    r201aeb9 rdb70fe4  
    1010// Created On       : Sat May 16 13:17:07 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Sep 26 11:23:36 2017
    13 // Update Count     : 780
     12// Last Modified On : Thu Sep 14 23:09:34 2017
     13// Update Count     : 690
    1414//
    1515
     
    6060static inline bool checkX( char c ) { return c == 'x' || c == 'X'; }
    6161
    62 static const char * lnthsInt[2][6] = {
    63         { "int8_t", "int16_t", "int32_t", "int64_t", "size_t", },
    64         { "uint8_t", "uint16_t", "uint32_t", "uint64_t", "size_t", }
    65 }; // lnthsInt
    66 
    67 static inline void checkLNInt( string & str, int & lnth, int & size ) {
    68         string::size_type posn = str.find_first_of( "lL" ), start = posn;
    69   if ( posn == string::npos ) return;
    70         size = 4;                                                                                       // assume largest size
    71         posn += 1;                                                                                      // advance to size
    72         if ( str[posn] == '8' ) {                                                       // 8
    73                 lnth = 0;
    74         } else if ( str[posn] == '1' ) {
    75                 posn += 1;
    76                 if ( str[posn] == '6' ) {                                               // 16
    77                         lnth = 1;
    78                 } else {                                                                                // 128
    79                         posn += 1;
    80                         lnth = 5;
    81                 } // if
    82         } else {
    83                 if ( str[posn] == '3' ) {                                               // 32
    84                         lnth = 2;
    85                 } else if ( str[posn] == '6' ) {                                // 64
    86                         lnth = 3;
    87                 } else {
    88                         assertf( false, "internal error, bad integral length %s", str.c_str() );
    89                 } // if         
    90                 posn += 1;
    91         } // if
    92         str.erase( start, posn - start + 1 );                           // remove length suffix
    93 } // checkLNInt
    94 
    9562static void sepNumeric( string & str, string & units ) {
    9663        string::size_type posn = str.find_first_of( "`" );
     
    10269
    10370Expression * build_constantInteger( string & str ) {
    104         static const BasicType::Kind kind[2][6] = {
     71        static const BasicType::Kind kind[2][5] = {
    10572                // short (h) must be before char (hh)
    106                 { BasicType::ShortSignedInt, BasicType::SignedChar, BasicType::SignedInt, BasicType::LongSignedInt, BasicType::LongLongSignedInt, BasicType::SignedInt128, },
    107                 { BasicType::ShortUnsignedInt, BasicType::UnsignedChar, BasicType::UnsignedInt, BasicType::LongUnsignedInt, BasicType::LongLongUnsignedInt, BasicType::UnsignedInt128, },
     73                { BasicType::ShortSignedInt, BasicType::SignedChar, BasicType::SignedInt, BasicType::LongSignedInt, BasicType::LongLongSignedInt },
     74                { BasicType::ShortUnsignedInt, BasicType::UnsignedChar, BasicType::UnsignedInt, BasicType::LongUnsignedInt, BasicType::LongLongUnsignedInt },
    10875        };
    10976
    110         string units;
     77        string units;                                                                           // units
    11178        sepNumeric( str, units );                                                       // separate constant from units
    11279
    11380        bool dec = true, Unsigned = false;                                      // decimal, unsigned constant
    114         int size;                                                                                       // 0 => short, 1 => char, 2 => int, 3 => long int, 4 => long long int, 5 => int128
    115         int lnth = -1;                                                                          // literal length
    116 
     81        int size;                                                                                       // 0 => short, 1 => char, 2 => int, 3 => long int, 4 => long long int, 5 => size_t
    11782        unsigned long long int v;                                                       // converted integral value
    11883        size_t last = str.length() - 1;                                         // last character of constant
     
    175140                        } // if
    176141                        str.erase( last - size - 1, size + 1 );         // remove 'h'/"hh"
    177                 } else {                                                                                // suffix "ln" ?
    178                         checkLNInt( str, lnth, size );
    179142                } // if
    180143        } else if ( checkL( str[ last ] ) ) {                           // suffix 'l' ?
     
    200163                str.erase( last - size, size + 1 );                             // remove 'h'/"hh"
    201164        } else if ( checkZ( str[last] ) ) {                                     // suffix 'z' ?
    202                 lnth = 4;
     165                size = 5;
    203166                str.erase( last, 1 );                                                   // remove 'z'
    204         } else {                                                                                        // suffix "ln" ?
    205                 checkLNInt( str, lnth, size );
    206         } // if
    207 
    208         assert( 0 <= size && size < 6 );
     167        } // if
     168
    209169        ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[Unsigned][size] ), str, v ) );
    210         if ( size < 2 ) {                                                                       // hh or h, less than int ?
    211                 // int i = -1uh => 65535 not -1, so cast is necessary for unsigned, which unfortunately eliminates warnings for large values.
     170        if ( Unsigned && size < 2 ) {                                           // less than int ?
     171                // int i = -1uh => 65535 not -1, so cast is necessary for unsigned, which eliminates warnings for large values.
    212172                ret = new CastExpr( ret, new BasicType( Type::Qualifiers(), kind[Unsigned][size] ) );
    213         } else if ( lnth != -1 ) {                                                      // explicit length ?
    214                 if ( lnth == 5 ) {                                                              // int128 ?
    215                         size = 5;
    216                         ret = new CastExpr( ret, new BasicType( Type::Qualifiers(), kind[Unsigned][size] ) );
    217                 } else {
    218                         ret = new CastExpr( ret, new TypeInstType( Type::Qualifiers(), lnthsInt[Unsigned][lnth], false ) );
    219                 } // if
     173        } else if ( size == 5 ) {                                                       // explicit cast to size_t
     174                ret = new CastExpr( ret, new TypeInstType( Type::Qualifiers(), "size_t", false ) );
    220175        } // if
    221176  CLEANUP:
     
    227182        return ret;
    228183} // build_constantInteger
    229 
    230 
    231 static inline void checkLNFloat( string & str, int & lnth, int & size ) {
    232         string::size_type posn = str.find_first_of( "lL" ), start = posn;
    233   if ( posn == string::npos ) return;
    234         size = 2;                                                                                       // assume largest size
    235         lnth = 0;
    236         posn += 1;                                                                                      // advance to size
    237         if ( str[posn] == '3' ) {                                                       // 32
    238                 size = 0;
    239         } else if ( str[posn] == '6' ) {                                        // 64
    240                 size = 1;
    241         } else if ( str[posn] == '8' || str[posn] == '1' ) { // 80, 128
    242                 size = 2;
    243                 if ( str[posn] == '1' ) posn += 1;
    244         } else {
    245                 assertf( false, "internal error, bad floating point length %s", str.c_str() );
    246         } // if
    247         posn += 1;
    248         str.erase( start, posn - start + 1 );                           // remove length suffix
    249 } // checkLNFloat
    250 
    251184
    252185Expression * build_constantFloat( string & str ) {
     
    256189        };
    257190
    258         string units;
     191        string units;                                                                           // units
    259192        sepNumeric( str, units );                                                       // separate constant from units
    260193
    261194        bool complx = false;                                                            // real, complex
    262         int size = 1;                                                                           // 0 => float, 1 => double, 2 => long double
    263         int lnth = -1;                                                                          // literal length
     195        int size = 1;                                                                           // 0 => float, 1 => double (default), 2 => long double
    264196        // floating-point constant has minimum of 2 characters: 1. or .1
    265197        size_t last = str.length() - 1;
     
    279211        } else if ( checkL( str[last] ) ) {                                     // long double ?
    280212                size = 2;
    281         } else {
    282                 size = 1;                                                                               // double (default)
    283                 checkLNFloat( str, lnth, size );
    284213        } // if
    285214        if ( ! complx && checkI( str[last - 1] ) ) {            // imaginary ?
     
    287216        } // if
    288217
    289         assert( 0 <= size && size < 3 );
    290218        Expression * ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[complx][size] ), str, v ) );
    291         if ( lnth != -1 ) {                                                                     // explicit length ?
    292                 ret = new CastExpr( ret, new BasicType( Type::Qualifiers(), kind[complx][size] ) );
    293         } // if
    294219        if ( units.length() != 0 ) {
    295220                ret = new UntypedExpr( new NameExpr( units ), { ret } );
Note: See TracChangeset for help on using the changeset viewer.