Ignore:
Timestamp:
Oct 19, 2017, 12:01:04 PM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
837ce06
Parents:
b96ec83 (diff), a15b72c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into cleanup-dtors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/ExpressionNode.cc

    rb96ec83 r6840e7c  
    1010// Created On       : Sat May 16 13:17:07 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Sep 14 23:09:34 2017
    13 // Update Count     : 690
     12// Last Modified On : Wed Sep 27 22:51:55 2017
     13// Update Count     : 781
    1414//
    1515
     
    6060static inline bool checkX( char c ) { return c == 'x' || c == 'X'; }
    6161
     62static 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
     67static 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
    6295static void sepNumeric( string & str, string & units ) {
    6396        string::size_type posn = str.find_first_of( "`" );
     
    69102
    70103Expression * build_constantInteger( string & str ) {
    71         static const BasicType::Kind kind[2][5] = {
     104        static const BasicType::Kind kind[2][6] = {
    72105                // short (h) must be before char (hh)
    73                 { BasicType::ShortSignedInt, BasicType::SignedChar, BasicType::SignedInt, BasicType::LongSignedInt, BasicType::LongLongSignedInt },
    74                 { BasicType::ShortUnsignedInt, BasicType::UnsignedChar, BasicType::UnsignedInt, BasicType::LongUnsignedInt, BasicType::LongLongUnsignedInt },
     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, },
    75108        };
    76109
    77         string units;                                                                           // units
     110        string units;
    78111        sepNumeric( str, units );                                                       // separate constant from units
    79112
    80113        bool dec = true, Unsigned = false;                                      // decimal, unsigned constant
    81         int size;                                                                                       // 0 => short, 1 => char, 2 => int, 3 => long int, 4 => long long int, 5 => size_t
     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
    82117        unsigned long long int v;                                                       // converted integral value
    83118        size_t last = str.length() - 1;                                         // last character of constant
     
    140175                        } // if
    141176                        str.erase( last - size - 1, size + 1 );         // remove 'h'/"hh"
     177                } else {                                                                                // suffix "ln" ?
     178                        checkLNInt( str, lnth, size );
    142179                } // if
    143180        } else if ( checkL( str[ last ] ) ) {                           // suffix 'l' ?
     
    163200                str.erase( last - size, size + 1 );                             // remove 'h'/"hh"
    164201        } else if ( checkZ( str[last] ) ) {                                     // suffix 'z' ?
    165                 size = 5;
     202                lnth = 4;
    166203                str.erase( last, 1 );                                                   // remove 'z'
    167         } // if
    168 
     204        } else {                                                                                        // suffix "ln" ?
     205                checkLNInt( str, lnth, size );
     206        } // if
     207
     208        assert( 0 <= size && size < 6 );
     209        // Constant type is correct for overload resolving.
    169210        ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[Unsigned][size] ), str, v ) );
    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.
     211        if ( Unsigned && size < 2 ) {                                           // hh or h, less than int ?
     212                // int i = -1uh => 65535 not -1, so cast is necessary for unsigned, which unfortunately eliminates warnings for large values.
    172213                ret = new CastExpr( ret, new BasicType( Type::Qualifiers(), kind[Unsigned][size] ) );
    173         } else if ( size == 5 ) {                                                       // explicit cast to size_t
    174                 ret = new CastExpr( ret, new TypeInstType( Type::Qualifiers(), "size_t", false ) );
     214        } else if ( lnth != -1 ) {                                                      // explicit length ?
     215                if ( lnth == 5 ) {                                                              // int128 ?
     216                        size = 5;
     217                        ret = new CastExpr( ret, new BasicType( Type::Qualifiers(), kind[Unsigned][size] ) );
     218                } else {
     219                        ret = new CastExpr( ret, new TypeInstType( Type::Qualifiers(), lnthsInt[Unsigned][lnth], false ) );
     220                } // if
    175221        } // if
    176222  CLEANUP:
     
    182228        return ret;
    183229} // build_constantInteger
     230
     231
     232static inline void checkLNFloat( string & str, int & lnth, int & size ) {
     233        string::size_type posn = str.find_first_of( "lL" ), start = posn;
     234  if ( posn == string::npos ) return;
     235        size = 2;                                                                                       // assume largest size
     236        lnth = 0;
     237        posn += 1;                                                                                      // advance to size
     238        if ( str[posn] == '3' ) {                                                       // 32
     239                size = 0;
     240        } else if ( str[posn] == '6' ) {                                        // 64
     241                size = 1;
     242        } else if ( str[posn] == '8' || str[posn] == '1' ) { // 80, 128
     243                size = 2;
     244                if ( str[posn] == '1' ) posn += 1;
     245        } else {
     246                assertf( false, "internal error, bad floating point length %s", str.c_str() );
     247        } // if
     248        posn += 1;
     249        str.erase( start, posn - start + 1 );                           // remove length suffix
     250} // checkLNFloat
     251
    184252
    185253Expression * build_constantFloat( string & str ) {
     
    189257        };
    190258
    191         string units;                                                                           // units
     259        string units;
    192260        sepNumeric( str, units );                                                       // separate constant from units
    193261
    194262        bool complx = false;                                                            // real, complex
    195         int size = 1;                                                                           // 0 => float, 1 => double (default), 2 => long double
     263        int size = 1;                                                                           // 0 => float, 1 => double, 2 => long double
     264        int lnth = -1;                                                                          // literal length
    196265        // floating-point constant has minimum of 2 characters: 1. or .1
    197266        size_t last = str.length() - 1;
     
    211280        } else if ( checkL( str[last] ) ) {                                     // long double ?
    212281                size = 2;
     282        } else {
     283                size = 1;                                                                               // double (default)
     284                checkLNFloat( str, lnth, size );
    213285        } // if
    214286        if ( ! complx && checkI( str[last - 1] ) ) {            // imaginary ?
     
    216288        } // if
    217289
     290        assert( 0 <= size && size < 3 );
    218291        Expression * ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[complx][size] ), str, v ) );
     292        if ( lnth != -1 ) {                                                                     // explicit length ?
     293                ret = new CastExpr( ret, new BasicType( Type::Qualifiers(), kind[complx][size] ) );
     294        } // if
    219295        if ( units.length() != 0 ) {
    220296                ret = new UntypedExpr( new NameExpr( units ), { ret } );
     
    321397
    322398NameExpr * build_varref( const string * name ) {
    323         NameExpr * expr = new NameExpr( *name, nullptr );
     399        NameExpr * expr = new NameExpr( *name );
    324400        delete name;
    325401        return expr;
     
    412488        list< Expression * > args;
    413489        buildMoveList( expr_node, args );
    414         return new UntypedExpr( maybeMoveBuild< Expression >(function), args, nullptr );
     490        return new UntypedExpr( maybeMoveBuild< Expression >(function), args );
    415491} // build_func
    416492
Note: See TracChangeset for help on using the changeset viewer.