Changeset 90152a4 for src/Parser/ExpressionNode.cc
- Timestamp:
- Aug 27, 2018, 4:40:34 PM (7 years ago)
- 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:
- b7c89aa
- Parents:
- f9feab8 (diff), 305581d (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/ExpressionNode.cc
rf9feab8 r90152a4 10 10 // Created On : Sat May 16 13:17:07 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Sep 27 22:51:55 201713 // Update Count : 78112 // Last Modified On : Mon Jun 4 21:24:45 2018 13 // Update Count : 802 14 14 // 15 15 … … 58 58 static inline bool checkD( char c ) { return c == 'd' || c == 'D'; } 59 59 static inline bool checkI( char c ) { return c == 'i' || c == 'I'; } 60 static inline bool checkB( char c ) { return c == 'b' || c == 'B'; } 60 61 static inline bool checkX( char c ) { return c == 'x' || c == 'X'; } 61 62 … … 93 94 } // checkLNInt 94 95 95 static void sepNumeric( string & str, string & units ) {96 string::size_type posn = str.find_first_of( "`" );97 if ( posn != string::npos ) {98 units = "?" + str.substr( posn ); // extract units99 str.erase( posn ); // remove units100 } // if101 } // sepNumeric102 103 96 Expression * build_constantInteger( string & str ) { 104 97 static const BasicType::Kind kind[2][6] = { … … 108 101 }; 109 102 110 string units;111 sepNumeric( str, units ); // separate constant from units112 113 103 bool dec = true, Unsigned = false; // decimal, unsigned constant 114 104 int size; // 0 => short, 1 => char, 2 => int, 3 => long int, 4 => long long int, 5 => int128 … … 116 106 117 107 unsigned long long int v; // converted integral value 118 size_t last = str.length() - 1; // last characterof constant108 size_t last = str.length() - 1; // last subscript of constant 119 109 Expression * ret; 120 110 … … 129 119 } // if 130 120 131 if ( str[0] == '0' ) { // octal/hex constant ? 121 // Cannot be "0" 122 123 if ( str[0] == '0' ) { // radix character ? 132 124 dec = false; 133 if ( last != 0 && checkX( str[1] ) ) {// hex constant ?125 if ( checkX( str[1] ) ) { // hex constant ? 134 126 sscanf( (char *)str.c_str(), "%llx", &v ); 127 //printf( "%llx %llu\n", v, v ); 128 } else if ( checkB( str[1] ) ) { // binary constant ? 129 v = 0; 130 for ( unsigned int i = 2;; i += 1 ) { // compute value 131 if ( str[i] == '1' ) v |= 1; 132 if ( i == last ) break; 133 v <<= 1; 134 } // for 135 135 //printf( "%llx %llu\n", v, v ); 136 136 } else { // octal constant … … 211 211 if ( Unsigned && size < 2 ) { // hh or h, less than int ? 212 212 // 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] ) );213 ret = new CastExpr( ret, new BasicType( Type::Qualifiers(), kind[Unsigned][size] ), false ); 214 214 } else if ( lnth != -1 ) { // explicit length ? 215 215 if ( lnth == 5 ) { // int128 ? 216 216 size = 5; 217 ret = new CastExpr( ret, new BasicType( Type::Qualifiers(), kind[Unsigned][size] ) );217 ret = new CastExpr( ret, new BasicType( Type::Qualifiers(), kind[Unsigned][size] ), false ); 218 218 } else { 219 ret = new CastExpr( ret, new TypeInstType( Type::Qualifiers(), lnthsInt[Unsigned][lnth], false ) );219 ret = new CastExpr( ret, new TypeInstType( Type::Qualifiers(), lnthsInt[Unsigned][lnth], false ), false ); 220 220 } // if 221 221 } // if 222 222 CLEANUP: 223 if ( units.length() != 0 ) {224 ret = new UntypedExpr( new NameExpr( units ), { ret } );225 } // if226 223 227 224 delete &str; // created by lex … … 257 254 }; 258 255 259 string units;260 sepNumeric( str, units ); // separate constant from units261 262 256 bool complx = false; // real, complex 263 257 int size = 1; // 0 => float, 1 => double, 2 => long double … … 291 285 Expression * ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[complx][size] ), str, v ) ); 292 286 if ( lnth != -1 ) { // explicit length ? 293 ret = new CastExpr( ret, new BasicType( Type::Qualifiers(), kind[complx][size] ) ); 294 } // if 295 if ( units.length() != 0 ) { 296 ret = new UntypedExpr( new NameExpr( units ), { ret } ); 287 ret = new CastExpr( ret, new BasicType( Type::Qualifiers(), kind[complx][size] ), false ); 297 288 } // if 298 289 … … 323 314 324 315 Expression * build_constantStr( string & str ) { 316 assert( str.length() > 0 ); 325 317 string units; // units 326 318 sepString( str, units, '"' ); // separate constant from units … … 356 348 357 349 Expression * build_field_name_FLOATING_FRACTIONconstant( const string & str ) { 358 if ( str.find_first_not_of( "0123456789", 1 ) != string::npos ) throw SemanticError("invalid tuple index " + str );350 if ( str.find_first_not_of( "0123456789", 1 ) != string::npos ) SemanticError( yylloc, "invalid tuple index " + str ); 359 351 Expression * ret = build_constantInteger( *new string( str.substr(1) ) ); 360 352 delete &str; … … 363 355 364 356 Expression * build_field_name_FLOATING_DECIMALconstant( const string & str ) { 365 if ( str[str.size()-1] != '.' ) throw SemanticError("invalid tuple index " + str );357 if ( str[str.size()-1] != '.' ) SemanticError( yylloc, "invalid tuple index " + str ); 366 358 Expression * ret = build_constantInteger( *new string( str.substr( 0, str.size()-1 ) ) ); 367 359 delete &str; … … 417 409 if ( dynamic_cast< VoidType * >( targetType ) ) { 418 410 delete targetType; 419 return new CastExpr( maybeMoveBuild< Expression >(expr_node) );411 return new CastExpr( maybeMoveBuild< Expression >(expr_node), false ); 420 412 } else { 421 return new CastExpr( maybeMoveBuild< Expression >(expr_node), targetType );413 return new CastExpr( maybeMoveBuild< Expression >(expr_node), targetType, false ); 422 414 } // if 423 415 } // build_cast 416 417 Expression * build_keyword_cast( KeywordCastExpr::Target target, ExpressionNode * expr_node ) { 418 return new KeywordCastExpr( maybeMoveBuild< Expression >(expr_node), target ); 419 } 424 420 425 421 Expression * build_virtual_cast( DeclarationNode * decl_node, ExpressionNode * expr_node ) {
Note:
See TracChangeset
for help on using the changeset viewer.