Changes in src/SynTree/Expression.cc [312029a:5d00425]
- File:
-
- 1 edited
-
src/SynTree/Expression.cc (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/Expression.cc
r312029a r5d00425 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Wed Dec 11 07:55:15201913 // Update Count : 7011 // Last Modified By : Andrew Beach 12 // Last Modified On : Thr Aug 15 13:43:00 2019 13 // Update Count : 64 14 14 // 15 15 … … 19 19 #include <iostream> // for ostream, operator<<, basic_ostream 20 20 #include <list> // for list, _List_iterator, list<>::co... 21 #include <set> // for set22 21 23 22 #include "Common/utility.h" // for maybeClone, cloneAll, deleteAll 23 #include "Declaration.h" // for ObjectDecl, DeclarationWithType 24 24 #include "Expression.h" // for Expression, ImplicitCopyCtorExpr 25 25 #include "InitTweak/InitTweak.h" // for getCallArg, getPointerBase … … 64 64 65 65 bool Expression::get_lvalue() const { 66 assert( !result->get_lvalue() ); 66 67 return false; 67 68 } … … 114 115 assert( var->get_type() ); 115 116 Type * type = var->get_type()->clone(); 117 type->set_lvalue( true ); 116 118 117 119 // xxx - doesn't quite work yet - get different alternatives with the same cost … … 123 125 // long long int value; 124 126 // if ( decl->valueOf( var, value ) ) { 125 // type->set_lvalue( false ); // Would have to move to get_lvalue.127 // type->set_lvalue( false ); 126 128 // } 127 129 // } … … 138 140 139 141 bool VariableExpr::get_lvalue() const { 140 // It isn't always an lvalue, but it is never an rvalue. 141 return true; 142 return result->get_lvalue(); 142 143 } 143 144 … … 276 277 277 278 bool CastExpr::get_lvalue() const { 278 // This is actually wrong by C, but it works with our current set-up. 279 return arg->get_lvalue(); 279 return result->get_lvalue(); 280 280 } 281 281 … … 293 293 } 294 294 295 KeywordCastExpr::KeywordCastExpr( Expression * arg, AggregateDecl::Aggregatetarget ) : Expression(), arg(arg), target( target ) {295 KeywordCastExpr::KeywordCastExpr( Expression * arg, Target target ) : Expression(), arg(arg), target( target ) { 296 296 } 297 297 … … 303 303 } 304 304 305 const char * KeywordCastExpr::targetString() const { 306 return AggregateDecl::aggrString( target ); 305 const std::string & KeywordCastExpr::targetString() const { 306 static const std::string targetStrs[] = { 307 "coroutine", "thread", "monitor" 308 }; 309 static_assert( 310 (sizeof(targetStrs) / sizeof(targetStrs[0])) == ((unsigned long)NUMBER_OF_TARGETS), 311 "Each KeywordCastExpr::Target should have a corresponding string representation" 312 ); 313 return targetStrs[(unsigned long)target]; 307 314 } 308 315 … … 353 360 } 354 361 355 bool UntypedMemberExpr::get_lvalue() const {356 return aggregate->get_lvalue();357 }358 359 362 void UntypedMemberExpr::print( std::ostream & os, Indenter indent ) const { 360 363 os << "Untyped Member Expression, with field: " << std::endl << indent+1; … … 375 378 sub.apply( res ); 376 379 result = res; 380 result->set_lvalue( true ); 377 381 result->get_qualifiers() |= aggregate->result->get_qualifiers(); 378 382 } … … 388 392 389 393 bool MemberExpr::get_lvalue() const { 390 // This is actually wrong by C, but it works with our current set-up.394 assert( result->get_lvalue() ); 391 395 return true; 392 396 } … … 423 427 // if references are still allowed in the AST, dereference returns a reference 424 428 ret->set_result( new ReferenceType( Type::Qualifiers(), ret->get_result() ) ); 429 } else { 430 // references have been removed, in which case dereference returns an lvalue of the base type. 431 ret->result->set_lvalue( true ); 425 432 } 426 433 } … … 440 447 441 448 bool UntypedExpr::get_lvalue() const { 442 // from src/GenPoly/Lvalue.cc: isIntrinsicReference 443 static std::set<std::string> lvalueFunctions = { "*?", "?[?]" }; 444 std::string fname = InitTweak::getFunctionName( const_cast< UntypedExpr * >( this ) ); 445 return lvalueFunctions.count(fname); 449 return result->get_lvalue(); 446 450 } 447 451 … … 506 510 507 511 bool ConditionalExpr::get_lvalue() const { 508 return false;512 return result->get_lvalue(); 509 513 } 510 514 … … 519 523 } 520 524 521 AsmExpr::AsmExpr( const AsmExpr & other ) : Expression( other ), inout( other.inout), constraint( maybeClone( other.constraint ) ), operand( maybeClone( other.operand ) ) {}525 AsmExpr::AsmExpr( const AsmExpr & other ) : Expression( other ), inout( maybeClone( other.inout ) ), constraint( maybeClone( other.constraint ) ), operand( maybeClone( other.operand ) ) {} 522 526 523 527 524 528 void AsmExpr::print( std::ostream & os, Indenter indent ) const { 525 529 os << "Asm Expression: " << std::endl; 526 if ( !inout.empty() ) os << "[" << inout << "] ";530 if ( inout ) inout->print( os, indent+1 ); 527 531 if ( constraint ) constraint->print( os, indent+1 ); 528 532 if ( operand ) operand->print( os, indent+1 ); … … 566 570 567 571 bool ConstructorExpr::get_lvalue() const { 568 return false;572 return result->get_lvalue(); 569 573 } 570 574 … … 578 582 CompoundLiteralExpr::CompoundLiteralExpr( Type * type, Initializer * initializer ) : initializer( initializer ) { 579 583 assert( type && initializer ); 584 type->set_lvalue( true ); 580 585 set_result( type ); 581 586 } … … 588 593 589 594 bool CompoundLiteralExpr::get_lvalue() const { 595 assert( result->get_lvalue() ); 590 596 return true; 591 597 } … … 642 648 } 643 649 bool StmtExpr::get_lvalue() const { 644 return false;650 return result->get_lvalue(); 645 651 } 646 652 void StmtExpr::print( std::ostream & os, Indenter indent ) const {
Note:
See TracChangeset
for help on using the changeset viewer.