Changes in src/Parser/ExpressionNode.cc [e612146c:ea6332d]
- File:
-
- 1 edited
-
src/Parser/ExpressionNode.cc (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/ExpressionNode.cc
re612146c rea6332d 7 7 // ExpressionNode.cc -- 8 8 // 9 // Author : Peter A. Buhr9 // Author : Rodolfo G. Esteves 10 10 // Created On : Sat May 16 13:17:07 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Sun Sep 3 22:21:21201713 // Update Count : 63911 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Aug 2 11:12:00 2017 13 // Update Count : 568 14 14 // 15 15 … … 58 58 static inline bool checkX( char c ) { return c == 'x' || c == 'X'; } 59 59 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( string & str ) { 60 Expression * build_constantInteger( const std::string & str ) { 69 61 static const BasicType::Kind kind[2][3] = { 70 62 { BasicType::SignedInt, BasicType::LongSignedInt, BasicType::LongLongSignedInt }, 71 63 { BasicType::UnsignedInt, BasicType::LongUnsignedInt, BasicType::LongLongUnsignedInt }, 72 64 }; 73 74 string units; // units75 sepNumeric( str, units ); // separate constant from units76 77 65 bool dec = true, Unsigned = false; // decimal, unsigned constant 78 66 int size; // 0 => int, 1 => long, 2 => long long … … 81 69 Expression * ret; 82 70 83 // ROB: what do we do with units on 0 and 1?84 71 // special constants 85 72 if ( str == "0" ) { … … 147 134 ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[Unsigned][size] ), str, v ) ); 148 135 CLEANUP: 149 if ( units.length() != 0 ) {150 ret = new UntypedExpr( new NameExpr( units ), { ret } );151 } // if152 153 136 delete &str; // created by lex 154 137 return ret; 155 138 } // build_constantInteger 156 139 157 Expression * build_constantFloat( string & str ) {140 Expression * build_constantFloat( const std::string & str ) { 158 141 static const BasicType::Kind kind[2][3] = { 159 142 { BasicType::Float, BasicType::Double, BasicType::LongDouble }, 160 143 { BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex }, 161 144 }; 162 163 string units; // units164 sepNumeric( str, units ); // separate constant from units165 145 166 146 bool complx = false; // real, complex … … 189 169 190 170 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 } // if194 195 171 delete &str; // created by lex 196 172 return ret; 197 173 } // build_constantFloat 198 174 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( string & str ) { 208 string units; // units 209 sepString( str, units, '\'' ); // separate constant from units 210 175 Expression * build_constantChar( const std::string & str ) { 211 176 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 } // if215 216 177 delete &str; // created by lex 217 178 return ret; 218 179 } // build_constantChar 219 180 220 Expression * build_constantStr( string & str ) { 221 string units; // units 222 sepString( str, units, '"' ); // separate constant from units 223 224 BasicType::Kind strtype = BasicType::Char; // default string type 225 switch ( str[0] ) { // str has >= 2 characters, i.e, null string "" 226 case 'u': 227 if ( str[1] == '8' ) break; // utf-8 characters 228 strtype = BasicType::ShortUnsignedInt; 229 break; 230 case 'U': 231 strtype = BasicType::UnsignedInt; 232 break; 233 case 'L': 234 strtype = BasicType::SignedInt; 235 break; 236 } // switch 237 ArrayType * at = new ArrayType( noQualifiers, new BasicType( Type::Qualifiers( Type::Const ), strtype ), 238 new ConstantExpr( Constant::from_ulong( str.size() + 1 - 2 ) ), // +1 for '\0' and -2 for '"' 239 false, false ); 240 Expression * ret = new ConstantExpr( Constant( at, str, (unsigned long long int)0 ) ); // constant 0 is ignored for pure string value 241 if ( units.length() != 0 ) { 242 ret = new UntypedExpr( new NameExpr( units ), { ret } ); 243 } // if 244 181 ConstantExpr * build_constantStr( const std::string & str ) { 182 // string should probably be a primitive type 183 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 ); 186 ConstantExpr * ret = new ConstantExpr( Constant( at, str, (unsigned long long int)0 ) ); // constant 0 is ignored for pure string value 245 187 delete &str; // created by lex 246 188 return ret; 247 189 } // build_constantStr 248 190 249 Expression * build_field_name_FLOATINGconstant( const st ring & str ) {191 Expression * build_field_name_FLOATINGconstant( const std::string & str ) { 250 192 // str is of the form A.B -> separate at the . and return member expression 251 193 int a, b; 252 194 char dot; 253 st ringstream ss( str );195 std::stringstream ss( str ); 254 196 ss >> a >> dot >> b; 255 197 UntypedMemberExpr * ret = new UntypedMemberExpr( new ConstantExpr( Constant::from_int( b ) ), new ConstantExpr( Constant::from_int( a ) ) ); … … 265 207 } else { 266 208 return new UntypedMemberExpr( fracts, fieldName ); 267 } // if268 } // if209 } 210 } 269 211 return fieldName; 270 212 } // make_field_name_fraction_constants … … 274 216 } // build_field_name_fraction_constants 275 217 276 Expression * build_field_name_REALFRACTIONconstant( const st ring & str ) {218 Expression * build_field_name_REALFRACTIONconstant( const std::string & str ) { 277 219 if ( str.find_first_not_of( "0123456789", 1 ) != string::npos ) throw SemanticError( "invalid tuple index " + str ); 278 Expression * ret = build_constantInteger( *new st ring( str.substr(1) ) );220 Expression * ret = build_constantInteger( *new std::string( str.substr(1) ) ); 279 221 delete &str; 280 222 return ret; 281 223 } // build_field_name_REALFRACTIONconstant 282 224 283 Expression * build_field_name_REALDECIMALconstant( const st ring & str ) {225 Expression * build_field_name_REALDECIMALconstant( const std::string & str ) { 284 226 if ( str[str.size()-1] != '.' ) throw SemanticError( "invalid tuple index " + str ); 285 Expression * ret = build_constantInteger( *new st ring( str.substr( 0, str.size()-1 ) ) );227 Expression * ret = build_constantInteger( *new std::string( str.substr( 0, str.size()-1 ) ) ); 286 228 delete &str; 287 229 return ret; … … 294 236 } // build_varref 295 237 296 // TODO: get rid of this and OperKinds and reuse code from OperatorTable 238 297 239 static const char * OperName[] = { // must harmonize with OperKinds 298 240 // diadic … … 302 244 "?[?]", "...", 303 245 // monadic 304 "+?", "-?", "AddressOf", "*?", "!?", "~?", "++?", "?++", "--?", "?--", 246 "+?", "-?", "AddressOf", "*?", "!?", "~?", "++?", "?++", "--?", "?--", "&&" 305 247 }; // OperName 306 248 … … 365 307 366 308 Expression * build_unary_val( OperKinds op, ExpressionNode * expr_node ) { 367 list< Expression * > args;309 std::list< Expression * > args; 368 310 args.push_back( maybeMoveBuild< Expression >(expr_node) ); 369 311 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args ); … … 371 313 372 314 Expression * build_unary_ptr( OperKinds op, ExpressionNode * expr_node ) { 373 list< Expression * > args;374 args.push_back( maybeMoveBuild< Expression >(expr_node) ); // xxx -- this is exactly the same as the val case now, refactor this code.315 std::list< Expression * > args; 316 args.push_back( new AddressExpr( maybeMoveBuild< Expression >(expr_node) ) ); 375 317 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args ); 376 318 } // build_unary_ptr 377 319 378 320 Expression * build_binary_val( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 ) { 379 list< Expression * > args;321 std::list< Expression * > args; 380 322 args.push_back( maybeMoveBuild< Expression >(expr_node1) ); 381 323 args.push_back( maybeMoveBuild< Expression >(expr_node2) ); … … 384 326 385 327 Expression * build_binary_ptr( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 ) { 386 list< Expression * > args;387 args.push_back( maybeMoveBuild< Expression >(expr_node1) );328 std::list< Expression * > args; 329 args.push_back( new AddressExpr( maybeMoveBuild< Expression >(expr_node1) ) ); 388 330 args.push_back( maybeMoveBuild< Expression >(expr_node2) ); 389 331 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args ); … … 407 349 408 350 Expression * build_tuple( ExpressionNode * expr_node ) { 409 list< Expression * > exprs;351 std::list< Expression * > exprs; 410 352 buildMoveList( expr_node, exprs ); 411 353 return new UntypedTupleExpr( exprs );; … … 413 355 414 356 Expression * build_func( ExpressionNode * function, ExpressionNode * expr_node ) { 415 list< Expression * > args;357 std::list< Expression * > args; 416 358 buildMoveList( expr_node, args ); 417 359 return new UntypedExpr( maybeMoveBuild< Expression >(function), args, nullptr ); … … 422 364 } // build_range 423 365 424 Expression * build_asmexpr( ExpressionNode * inout, Expression* constraint, ExpressionNode * operand ) {366 Expression * build_asmexpr( ExpressionNode * inout, ConstantExpr * constraint, ExpressionNode * operand ) { 425 367 return new AsmExpr( maybeMoveBuild< Expression >( inout ), constraint, maybeMoveBuild< Expression >(operand) ); 426 368 } // build_asmexpr
Note:
See TracChangeset
for help on using the changeset viewer.