Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/ExpressionNode.cc

    rcccc534 re8ccca3  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 13:17:07 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Wed Aug  2 11:12:00 2017
    13 // Update Count     : 568
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Sep  1 15:07:09 2017
     13// Update Count     : 618
    1414//
    1515
     
    5858static inline bool checkX( char c ) { return c == 'x' || c == 'X'; }
    5959
    60 Expression * build_constantInteger( const std::string & str ) {
     60static void sepNumeric( string & str, string & units ) {
     61        string::size_type posn = str.find_first_of( "`" );
     62        if ( posn != string::npos ) {
     63                units = "?" + str.substr( posn );                               // extract units
     64                str.erase( posn );                                                              // remove units
     65        } // if
     66} // sepNumeric
     67
     68Expression * build_constantInteger( std::string & str ) {
    6169        static const BasicType::Kind kind[2][3] = {
    6270                { BasicType::SignedInt, BasicType::LongSignedInt, BasicType::LongLongSignedInt },
    6371                { BasicType::UnsignedInt, BasicType::LongUnsignedInt, BasicType::LongLongUnsignedInt },
    6472        };
     73
     74        string units;                                                                           // units
     75        sepNumeric( str, units );                                                       // separate constant from units
     76
    6577        bool dec = true, Unsigned = false;                                      // decimal, unsigned constant
    6678        int size;                                                                                       // 0 => int, 1 => long, 2 => long long
     
    6981        Expression * ret;
    7082
     83        // ROB: what do we do with units on 0 and 1?
    7184        // special constants
    7285        if ( str == "0" ) {
     
    134147        ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[Unsigned][size] ), str, v ) );
    135148  CLEANUP:
     149        if ( units.length() != 0 ) {
     150                ret = new UntypedExpr( new NameExpr( units, ret ) );
     151        } // if
     152
    136153        delete &str;                                                                            // created by lex
    137154        return ret;
    138155} // build_constantInteger
    139156
    140 Expression * build_constantFloat( const std::string & str ) {
     157Expression * build_constantFloat( std::string & str ) {
    141158        static const BasicType::Kind kind[2][3] = {
    142159                { BasicType::Float, BasicType::Double, BasicType::LongDouble },
    143160                { BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex },
    144161        };
     162
     163        string units;                                                                           // units
     164        sepNumeric( str, units );                                                       // separate constant from units
    145165
    146166        bool complx = false;                                                            // real, complex
     
    169189
    170190        Expression * ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[complx][size] ), str, v ) );
     191        if ( units.length() != 0 ) {
     192                ret = new UntypedExpr( new NameExpr( units, ret ) );
     193        } // if
     194
    171195        delete &str;                                                                            // created by lex
    172196        return ret;
    173197} // build_constantFloat
    174198
    175 Expression * build_constantChar( const std::string & str ) {
     199static void sepString( string & str, string & units, char delimit ) {
     200        string::size_type posn = str.find_last_of( delimit ) + 1;
     201        if ( posn != str.length() ) {
     202                units = "?" + str.substr( posn );                               // extract units
     203                str.erase( posn );                                                              // remove units
     204        } // if
     205} // sepString
     206
     207Expression * build_constantChar( std::string & str ) {
     208        string units;                                                                           // units
     209        sepString( str, units, '\'' );                                          // separate constant from units
     210
    176211        Expression * ret = new ConstantExpr( Constant( new BasicType( noQualifiers, BasicType::Char ), str, (unsigned long long int)(unsigned char)str[1] ) );
     212        if ( units.length() != 0 ) {
     213                ret = new UntypedExpr( new NameExpr( units, ret ) );
     214        } // if
     215
    177216        delete &str;                                                                            // created by lex
    178217        return ret;
    179218} // build_constantChar
    180219
    181 ConstantExpr * build_constantStr( const std::string & str ) {
    182         // string should probably be a primitive type
     220ConstantExpr * build_constantStr( std::string & str ) {
     221        string units;                                                                           // units
     222        sepString( str, units, '"' );                                           // separate constant from units
     223
    183224        ArrayType * at = new ArrayType( noQualifiers, new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ),
    184                                                                    new ConstantExpr( Constant::from_ulong( str.size() + 1 - 2 ) ), // +1 for '\0' and -2 for '"'
    185                                                                    false, false );
     225                                                                        new ConstantExpr( Constant::from_ulong( str.size() + 1 - 2 ) ), // +1 for '\0' and -2 for '"'
     226                                                                        false, false );
    186227        ConstantExpr * ret = new ConstantExpr( Constant( at, str, (unsigned long long int)0 ) ); // constant 0 is ignored for pure string value
     228// ROB: type mismatch
     229        // if ( units.length() != 0 ) {
     230        //      ret = new UntypedExpr( new NameExpr( units, ret ) );
     231        // } // if
     232               
    187233        delete &str;                                                                            // created by lex
    188234        return ret;
     
    314360Expression * build_unary_ptr( OperKinds op, ExpressionNode * expr_node ) {
    315361        std::list< Expression * > args;
    316         args.push_back(  maybeMoveBuild< Expression >(expr_node) ); // xxx -- this is exactly the same as the val case now, refactor this code.
     362        args.push_back(  maybeMoveBuild< Expression >(expr_node) ); // xxx
    317363        return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
    318364} // build_unary_ptr
Note: See TracChangeset for help on using the changeset viewer.