Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/ExpressionNode.cc

    re8ccca3 rcccc534  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 13:17:07 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Sep  1 15:07:09 2017
    13 // Update Count     : 618
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed Aug  2 11:12:00 2017
     13// Update Count     : 568
    1414//
    1515
     
    5858static inline bool checkX( char c ) { return c == 'x' || c == 'X'; }
    5959
    60 static 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 
    68 Expression * build_constantInteger( std::string & str ) {
     60Expression * build_constantInteger( const std::string & str ) {
    6961        static const BasicType::Kind kind[2][3] = {
    7062                { BasicType::SignedInt, BasicType::LongSignedInt, BasicType::LongLongSignedInt },
    7163                { BasicType::UnsignedInt, BasicType::LongUnsignedInt, BasicType::LongLongUnsignedInt },
    7264        };
    73 
    74         string units;                                                                           // units
    75         sepNumeric( str, units );                                                       // separate constant from units
    76 
    7765        bool dec = true, Unsigned = false;                                      // decimal, unsigned constant
    7866        int size;                                                                                       // 0 => int, 1 => long, 2 => long long
     
    8169        Expression * ret;
    8270
    83         // ROB: what do we do with units on 0 and 1?
    8471        // special constants
    8572        if ( str == "0" ) {
     
    147134        ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[Unsigned][size] ), str, v ) );
    148135  CLEANUP:
    149         if ( units.length() != 0 ) {
    150                 ret = new UntypedExpr( new NameExpr( units, ret ) );
    151         } // if
    152 
    153136        delete &str;                                                                            // created by lex
    154137        return ret;
    155138} // build_constantInteger
    156139
    157 Expression * build_constantFloat( std::string & str ) {
     140Expression * build_constantFloat( const std::string & str ) {
    158141        static const BasicType::Kind kind[2][3] = {
    159142                { BasicType::Float, BasicType::Double, BasicType::LongDouble },
    160143                { BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex },
    161144        };
    162 
    163         string units;                                                                           // units
    164         sepNumeric( str, units );                                                       // separate constant from units
    165145
    166146        bool complx = false;                                                            // real, complex
     
    189169
    190170        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 
    195171        delete &str;                                                                            // created by lex
    196172        return ret;
    197173} // build_constantFloat
    198174
    199 static 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 
    207 Expression * build_constantChar( std::string & str ) {
    208         string units;                                                                           // units
    209         sepString( str, units, '\'' );                                          // separate constant from units
    210 
     175Expression * build_constantChar( const std::string & str ) {
    211176        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 
    216177        delete &str;                                                                            // created by lex
    217178        return ret;
    218179} // build_constantChar
    219180
    220 ConstantExpr * build_constantStr( std::string & str ) {
    221         string units;                                                                           // units
    222         sepString( str, units, '"' );                                           // separate constant from units
    223 
     181ConstantExpr * build_constantStr( const std::string & str ) {
     182        // string should probably be a primitive type
    224183        ArrayType * at = new ArrayType( noQualifiers, new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ),
    225                                                                         new ConstantExpr( Constant::from_ulong( str.size() + 1 - 2 ) ), // +1 for '\0' and -2 for '"'
    226                                                                         false, false );
     184                                                                   new ConstantExpr( Constant::from_ulong( str.size() + 1 - 2 ) ), // +1 for '\0' and -2 for '"'
     185                                                                   false, false );
    227186        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                
    233187        delete &str;                                                                            // created by lex
    234188        return ret;
     
    360314Expression * build_unary_ptr( OperKinds op, ExpressionNode * expr_node ) {
    361315        std::list< Expression * > args;
    362         args.push_back(  maybeMoveBuild< Expression >(expr_node) ); // xxx
     316        args.push_back(  maybeMoveBuild< Expression >(expr_node) ); // xxx -- this is exactly the same as the val case now, refactor this code.
    363317        return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
    364318} // build_unary_ptr
Note: See TracChangeset for help on using the changeset viewer.