Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/ExpressionNode.cc

    r9a705dc8 r68f9c43  
    1010// Created On       : Sat May 16 13:17:07 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar 22 11:57:39 2018
    13 // Update Count     : 801
     12// Last Modified On : Sat Mar  3 18:22:33 2018
     13// Update Count     : 796
    1414//
    1515
     
    9494} // checkLNInt
    9595
     96static void sepNumeric( string & str, string & units ) {
     97        string::size_type posn = str.find_first_of( "`" );
     98        if ( posn != string::npos ) {
     99                units = "?" + str.substr( posn );                               // extract units
     100                str.erase( posn );                                                              // remove units
     101        } // if
     102} // sepNumeric
     103
    96104Expression * build_constantInteger( string & str ) {
    97105        static const BasicType::Kind kind[2][6] = {
     
    100108                { BasicType::ShortUnsignedInt, BasicType::UnsignedChar, BasicType::UnsignedInt, BasicType::LongUnsignedInt, BasicType::LongLongUnsignedInt, BasicType::UnsignedInt128, },
    101109        };
     110
     111        string units;
     112        sepNumeric( str, units );                                                       // separate constant from units
    102113
    103114        bool dec = true, Unsigned = false;                                      // decimal, unsigned constant
     
    211222        if ( Unsigned && size < 2 ) {                                           // hh or h, less than int ?
    212223                // int i = -1uh => 65535 not -1, so cast is necessary for unsigned, which unfortunately eliminates warnings for large values.
    213                 ret = new CastExpr( ret, new BasicType( Type::Qualifiers(), kind[Unsigned][size] ), false );
     224                ret = new CastExpr( ret, new BasicType( Type::Qualifiers(), kind[Unsigned][size] ) );
    214225        } else if ( lnth != -1 ) {                                                      // explicit length ?
    215226                if ( lnth == 5 ) {                                                              // int128 ?
    216227                        size = 5;
    217                         ret = new CastExpr( ret, new BasicType( Type::Qualifiers(), kind[Unsigned][size] ), false );
     228                        ret = new CastExpr( ret, new BasicType( Type::Qualifiers(), kind[Unsigned][size] ) );
    218229                } else {
    219                         ret = new CastExpr( ret, new TypeInstType( Type::Qualifiers(), lnthsInt[Unsigned][lnth], false ), false );
     230                        ret = new CastExpr( ret, new TypeInstType( Type::Qualifiers(), lnthsInt[Unsigned][lnth], false ) );
    220231                } // if
    221232        } // if
    222233  CLEANUP:
     234        if ( units.length() != 0 ) {
     235                ret = new UntypedExpr( new NameExpr( units ), { ret } );
     236        } // if
    223237
    224238        delete &str;                                                                            // created by lex
     
    254268        };
    255269
     270        string units;
     271        sepNumeric( str, units );                                                       // separate constant from units
     272
    256273        bool complx = false;                                                            // real, complex
    257274        int size = 1;                                                                           // 0 => float, 1 => double, 2 => long double
     
    285302        Expression * ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[complx][size] ), str, v ) );
    286303        if ( lnth != -1 ) {                                                                     // explicit length ?
    287                 ret = new CastExpr( ret, new BasicType( Type::Qualifiers(), kind[complx][size] ), false );
     304                ret = new CastExpr( ret, new BasicType( Type::Qualifiers(), kind[complx][size] ) );
     305        } // if
     306        if ( units.length() != 0 ) {
     307                ret = new UntypedExpr( new NameExpr( units ), { ret } );
    288308        } // if
    289309
     
    407427        Type * targetType = maybeMoveBuildType( decl_node );
    408428        if ( dynamic_cast< VoidType * >( targetType ) ) {
    409                 delete targetType;
    410                 return new CastExpr( maybeMoveBuild< Expression >(expr_node), false );
     429                return new CastExpr( maybeMoveBuild< Expression >(expr_node) );
    411430        } else {
    412                 return new CastExpr( maybeMoveBuild< Expression >(expr_node), targetType, false );
     431                return new CastExpr( maybeMoveBuild< Expression >(expr_node), targetType );
    413432        } // if
    414433} // build_cast
    415 
    416 Expression * build_keyword_cast( KeywordCastExpr::Target target, ExpressionNode * expr_node ) {
    417         return new KeywordCastExpr( maybeMoveBuild< Expression >(expr_node), target );
    418 }
    419434
    420435Expression * build_virtual_cast( DeclarationNode * decl_node, ExpressionNode * expr_node ) {
     
    435450
    436451Expression * build_offsetOf( DeclarationNode * decl_node, NameExpr * member ) {
    437         Expression * ret = new UntypedOffsetofExpr( maybeMoveBuildType( decl_node ), member->get_name() );
    438         delete member;
    439         return ret;
     452        return new UntypedOffsetofExpr{ maybeMoveBuildType( decl_node ), member->get_name() };
    440453} // build_offsetOf
    441454
Note: See TracChangeset for help on using the changeset viewer.