Changeset dae881f for src/Parser/ExpressionNode.cc
- Timestamp:
- Aug 5, 2016, 9:25:34 AM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 1b0020a
- Parents:
- 658fafe4 (diff), 51e076e (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
r658fafe4 rdae881f 10 10 // Created On : Sat May 16 13:17:07 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Aug 2 15:10:23 201613 // Update Count : 3 2212 // Last Modified On : Fri Aug 5 07:56:23 2016 13 // Update Count : 375 14 14 // 15 15 … … 258 258 OperatorNode::~OperatorNode() {} 259 259 260 OperatorNode::Type OperatorNode::get_type( void ) const {260 OperatorNode::Type OperatorNode::get_type( void ) const { 261 261 return type; 262 262 } … … 311 311 } 312 312 313 #include "Common/utility.h" 313 314 Expression *build_cast( TypeValueNode * arg, ExpressionNode *expr_node ) { 315 DeclarationNode *decl_node = arg->get_decl(); 316 317 Type *targetType = decl_node->buildType(); 318 if ( dynamic_cast< VoidType* >( targetType ) ) { 319 delete targetType; 320 return new CastExpr( maybeBuild<Expression>(expr_node) ); 321 } else { 322 return new CastExpr( maybeBuild<Expression>(expr_node), targetType ); 323 } // if 324 } 325 326 Expression *build_fieldSel( ExpressionNode *expr_node, VarRefNode *member ) { 327 NameExpr* memberExpr = dynamic_cast<NameExpr*> ( maybeBuild<Expression>( member) ); 328 assert( memberExpr ); 329 UntypedMemberExpr *ret = new UntypedMemberExpr( memberExpr->get_name(), maybeBuild<Expression>(expr_node) ); 330 delete member; 331 return ret; 332 } 333 334 Expression *build_pfieldSel( ExpressionNode *expr_node, VarRefNode *member ) { 335 NameExpr* memberExpr = dynamic_cast<NameExpr*> ( maybeBuild<Expression>( member) ); 336 assert( memberExpr ); 337 UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) ); 338 deref->get_args().push_back( maybeBuild<Expression>(expr_node) ); 339 UntypedMemberExpr *ret = new UntypedMemberExpr( memberExpr->get_name(), deref ); 340 delete member; 341 return ret; 342 } 343 344 Expression *build_addressOf( ExpressionNode *expr_node ) { 345 return new AddressExpr( maybeBuild<Expression>(expr_node) ); 346 } 347 Expression *build_sizeOf( ExpressionNode *expr_node ) { 348 if ( TypeValueNode * arg = dynamic_cast<TypeValueNode *>( expr_node ) ) { 349 return new SizeofExpr( arg->get_decl()->buildType() ); 350 } else { 351 return new SizeofExpr( maybeBuild<Expression>(expr_node) ); 352 } // if 353 } 354 Expression *build_alignOf( ExpressionNode *expr_node ) { 355 if ( TypeValueNode * arg = dynamic_cast<TypeValueNode *>( expr_node ) ) { 356 return new AlignofExpr( arg->get_decl()->buildType() ); 357 } else { 358 return new AlignofExpr( maybeBuild<Expression>(expr_node) ); 359 } // if 360 } 361 Expression *build_offsetOf( TypeValueNode * arg, VarRefNode *member ) { 362 NameExpr *memberExpr = dynamic_cast<NameExpr *>( maybeBuild<Expression>( member ) ); 363 assert( memberExpr ); 364 return new UntypedOffsetofExpr( arg->get_decl()->buildType(), memberExpr->get_name() ); 365 } 366 367 Expression *build_and_or( ExpressionNode *expr_node1, ExpressionNode *expr_node2, bool kind ) { 368 return new LogicalExpr( notZeroExpr( maybeBuild<Expression>(expr_node1) ), notZeroExpr( maybeBuild<Expression>(expr_node2) ), kind ); 369 } 370 371 Expression *build_opr1( OperatorNode::Type op, ExpressionNode *expr_node ) { 372 std::list<Expression *> args; 373 args.push_back( new AddressExpr( maybeBuild<Expression>(expr_node) ) ); 374 return new UntypedExpr( new NameExpr( opName[ op ] ), args ); 375 } 376 Expression *build_opr2( OperatorNode::Type op, ExpressionNode *expr_node1, ExpressionNode *expr_node2 ) { 377 std::list<Expression *> args; 378 args.push_back( maybeBuild<Expression>(expr_node1) ); 379 args.push_back( maybeBuild<Expression>(expr_node2) ); 380 return new UntypedExpr( new NameExpr( opName[ op ] ), args ); 381 } 382 383 Expression *build_cond( ExpressionNode *expr_node1, ExpressionNode *expr_node2, ExpressionNode *expr_node3 ) { 384 return new ConditionalExpr( notZeroExpr( maybeBuild<Expression>(expr_node1) ), maybeBuild<Expression>(expr_node2), maybeBuild<Expression>(expr_node3) ); 385 } 386 387 Expression *build_comma( ExpressionNode *expr_node1, ExpressionNode *expr_node2 ) { 388 return new CommaExpr( maybeBuild<Expression>(expr_node1), maybeBuild<Expression>(expr_node2) ); 389 } 390 391 CompositeExprNode2::CompositeExprNode2( Expression *expr ) : expr( expr ) {} 392 CompositeExprNode2::CompositeExprNode2( const CompositeExprNode2 &other ) : expr( other.expr->clone() ) {} 393 CompositeExprNode2::~CompositeExprNode2() { delete expr; } 394 void CompositeExprNode2::print( std::ostream &, int indent ) const { assert( false ); } 395 void CompositeExprNode2::printOneLine( std::ostream &, int indent ) const { assert( false ); } 396 314 397 315 398 Expression *CompositeExprNode::build() const { … … 323 406 } // if 324 407 325 switch ( op->get_type()) { 326 case OperatorNode::Incr: 327 case OperatorNode::Decr: 328 case OperatorNode::IncrPost: 329 case OperatorNode::DecrPost: 408 switch ( op->get_type() ) { 330 409 case OperatorNode::Assign: 331 410 case OperatorNode::MulAssn: … … 339 418 case OperatorNode::ERAssn: 340 419 case OperatorNode::OrAssn: 341 // the rewrite rules for these expressions specify that the first argument has its address taken342 420 assert( ! args.empty() ); 343 421 args.front() = new AddressExpr( args.front() ); 344 break;345 default: // do nothing346 ;347 } // switch348 349 switch ( op->get_type() ) {350 case OperatorNode::Incr:351 case OperatorNode::Decr:352 case OperatorNode::IncrPost:353 case OperatorNode::DecrPost:354 case OperatorNode::Assign:355 case OperatorNode::MulAssn:356 case OperatorNode::DivAssn:357 case OperatorNode::ModAssn:358 case OperatorNode::PlusAssn:359 case OperatorNode::MinusAssn:360 case OperatorNode::LSAssn:361 case OperatorNode::RSAssn:362 case OperatorNode::AndAssn:363 case OperatorNode::ERAssn:364 case OperatorNode::OrAssn:365 case OperatorNode::Plus:366 case OperatorNode::Minus:367 case OperatorNode::Mul:368 case OperatorNode::Div:369 case OperatorNode::Mod:370 case OperatorNode::BitOr:371 case OperatorNode::BitAnd:372 case OperatorNode::Xor:373 case OperatorNode::LShift:374 case OperatorNode::RShift:375 case OperatorNode::LThan:376 case OperatorNode::GThan:377 case OperatorNode::LEThan:378 case OperatorNode::GEThan:379 case OperatorNode::Eq:380 case OperatorNode::Neq:381 case OperatorNode::Index:382 case OperatorNode::Range:383 422 case OperatorNode::UnPlus: 384 423 case OperatorNode::UnMinus: … … 388 427 case OperatorNode::LabelAddress: 389 428 return new UntypedExpr( new NameExpr( opName[ op->get_type() ] ), args ); 390 case OperatorNode::AddressOf: 391 assert( args.size() == 1 ); 392 assert( args.front() ); 393 394 return new AddressExpr( args.front() ); 395 case OperatorNode::Cast: 396 { 397 TypeValueNode * arg = dynamic_cast<TypeValueNode *>( get_args()); 398 assert( arg ); 399 400 DeclarationNode *decl_node = arg->get_decl(); 401 ExpressionNode *expr_node = dynamic_cast<ExpressionNode *>( arg->get_link()); 402 403 Type *targetType = decl_node->buildType(); 404 if ( dynamic_cast< VoidType* >( targetType ) ) { 405 delete targetType; 406 return new CastExpr( maybeBuild<Expression>(expr_node), maybeBuild< Expression >( get_argName() ) ); 407 } else { 408 return new CastExpr( maybeBuild<Expression>(expr_node),targetType, maybeBuild< Expression >( get_argName() ) ); 409 } // if 410 } 411 case OperatorNode::FieldSel: 412 { 413 assert( args.size() == 2 ); 414 415 NameExpr *member = dynamic_cast<NameExpr *>( args.back()); 416 // TupleExpr *memberTup = dynamic_cast<TupleExpr *>( args.back()); 417 418 if ( member != 0 ) { 419 UntypedMemberExpr *ret = new UntypedMemberExpr( member->get_name(), args.front()); 420 delete member; 421 return ret; 422 /* else if ( memberTup != 0 ) 423 { 424 UntypedMemberExpr *ret = new UntypedMemberExpr( memberTup->get_name(), args.front()); 425 delete member; 426 return ret; 427 } */ 428 } else 429 assert( false ); 430 } 431 case OperatorNode::PFieldSel: 432 { 433 assert( args.size() == 2 ); 434 435 NameExpr *member = dynamic_cast<NameExpr *>( args.back()); // modify for Tuples xxx 436 assert( member != 0 ); 437 438 UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) ); 439 deref->get_args().push_back( args.front() ); 440 441 UntypedMemberExpr *ret = new UntypedMemberExpr( member->get_name(), deref ); 442 delete member; 443 return ret; 444 } 445 case OperatorNode::SizeOf: 446 { 447 if ( TypeValueNode * arg = dynamic_cast<TypeValueNode *>( get_args()) ) { 448 return new SizeofExpr( arg->get_decl()->buildType()); 449 } else { 450 return new SizeofExpr( args.front()); 451 } // if 452 } 453 case OperatorNode::AlignOf: 454 { 455 if ( TypeValueNode * arg = dynamic_cast<TypeValueNode *>( get_args()) ) { 456 return new AlignofExpr( arg->get_decl()->buildType()); 457 } else { 458 return new AlignofExpr( args.front()); 459 } // if 460 } 461 case OperatorNode::OffsetOf: 462 { 463 assert( args.size() == 2 ); 464 465 if ( TypeValueNode * arg = dynamic_cast<TypeValueNode *>( get_args() ) ) { 466 NameExpr *member = dynamic_cast<NameExpr *>( args.back() ); 467 assert( member != 0 ); 468 469 return new UntypedOffsetofExpr( arg->get_decl()->buildType(), member->get_name() ); 470 } else assert( false ); 471 } 429 472 430 case OperatorNode::Attr: 473 431 { 474 VarRefNode *var = dynamic_cast<VarRefNode *>( get_args() );432 VarRefNode *var = dynamic_cast<VarRefNode *>( get_args() ); 475 433 assert( var ); 476 434 if ( ! get_args()->get_link() ) { 477 435 return new AttrExpr( maybeBuild<Expression>(var), ( Expression*)0); 478 } else if ( TypeValueNode * arg = dynamic_cast<TypeValueNode *>( get_args()->get_link() ) ) {479 return new AttrExpr( maybeBuild<Expression>(var), arg->get_decl()->buildType() );436 } else if ( TypeValueNode * arg = dynamic_cast<TypeValueNode *>( get_args()->get_link() ) ) { 437 return new AttrExpr( maybeBuild<Expression>(var), arg->get_decl()->buildType() ); 480 438 } else { 481 return new AttrExpr( maybeBuild<Expression>(var), args.back() );439 return new AttrExpr( maybeBuild<Expression>(var), args.back() ); 482 440 } // if 483 441 } 484 case OperatorNode::Or:485 case OperatorNode::And:486 assert( args.size() == 2);487 return new LogicalExpr( notZeroExpr( args.front() ), notZeroExpr( args.back() ), ( op->get_type() == OperatorNode::And ) );488 442 case OperatorNode::Cond: 489 443 { … … 497 451 case OperatorNode::NCond: 498 452 throw UnimplementedError( "GNU 2-argument conditional expression" ); 499 case OperatorNode::Comma:500 {501 assert( args.size() == 2);502 std::list< Expression * >::const_iterator i = args.begin();503 Expression *ret = *i++;504 while ( i != args.end() ) {505 ret = new CommaExpr( ret, *i++ );506 }507 return ret;508 }509 453 // Tuples 510 454 case OperatorNode::TupleC: … … 515 459 } 516 460 default: 517 // shouldn't happen 518 assert( false ); 461 assert( ((void)"CompositeExprNode::build", false) ); 519 462 return 0; 520 463 } // switch … … 755 698 } 756 699 757 758 700 ExpressionNode *flattenCommas( ExpressionNode *list ) { 759 701 if ( CompositeExprNode *composite = dynamic_cast< CompositeExprNode * >( list ) ) {
Note: See TracChangeset
for help on using the changeset viewer.