Changes in / [ee574a2:de8dfac2]
- Location:
- src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/FixInit.cc
ree574a2 rde8dfac2 72 72 }; 73 73 74 struct StmtExprResult { 75 static void link( std::list< Declaration * > & translationUnit ); 76 77 void previsit( StmtExpr * stmtExpr ); 78 }; 79 74 80 struct InsertImplicitCalls : public WithConstTypeSubstitution { 75 81 /// wrap function application expressions as ImplicitCopyCtorExpr nodes so that it is easy to identify which … … 226 232 acceptAll( translationUnit, checker ); 227 233 234 // fixes StmtExpr to properly link to their resulting expression 235 StmtExprResult::link( translationUnit ); 236 228 237 // fixes ConstructorInit for global variables. should happen before fixInitializers. 229 238 InitTweak::fixGlobalInit( translationUnit, inLibrary ); … … 299 308 300 309 return dtorFunc; 310 } 311 312 void StmtExprResult::link( std::list< Declaration * > & translationUnit ) { 313 PassVisitor<StmtExprResult> linker; 314 acceptAll( translationUnit, linker ); 301 315 } 302 316 … … 349 363 PassVisitor<FixCtorExprs> fixer; 350 364 mutateAll( translationUnit, fixer ); 365 } 366 367 void StmtExprResult::previsit( StmtExpr * stmtExpr ) { 368 // we might loose the result expression here so add a pointer to trace back 369 assert( stmtExpr->result ); 370 Type * result = stmtExpr->result; 371 if ( ! result->isVoid() ) { 372 CompoundStmt * body = stmtExpr->statements; 373 assert( ! body->kids.empty() ); 374 stmtExpr->resultExpr = strict_dynamic_cast< ExprStmt * >( body->kids.back() ); 375 } 351 376 } 352 377 … … 655 680 // function call temporaries should be placed at statement-level, rather than nested inside of a new statement expression, 656 681 // since temporaries can be shared across sub-expressions, e.g. 657 // [A, A] f(); 658 // g([A] x, [A] y); 659 // g(f()); 682 // [A, A] f(); // decl 683 // g([A] x, [A] y); // decl 684 // g(f()); // call 660 685 // f is executed once, so the return temporary is shared across the tuple constructors for x and y. 661 686 // Explicitly mutating children instead of mutating the inner compound statement forces the temporaries to be added … … 665 690 assert( env ); 666 691 692 indexer.enterScope(); 667 693 // visit all statements 668 694 std::list< Statement * > & stmts = stmtExpr->statements->get_kids(); … … 670 696 stmt = stmt->acceptMutator( *visitor ); 671 697 } // for 698 indexer.leaveScope(); 672 699 673 700 assert( stmtExpr->result ); … … 688 715 stmtsToAddBefore.push_back( new DeclStmt( ret ) ); 689 716 690 // must have a non-empty body, otherwise it wouldn't have a result 691 CompoundStmt * body = stmtExpr->statements; 692 assert( ! body->kids.empty() ); 693 // must be an ExprStmt, otherwise it wouldn't have a result 694 ExprStmt * last = strict_dynamic_cast< ExprStmt * >( body->kids.back() ); 695 last->expr = makeCtorDtor( "?{}", ret, last->expr ); 717 if(!stmtExpr->resultExpr) { 718 SemanticError(stmtExpr, "Statment-Expression should have a resulting expression"); 719 } 720 ExprStmt * last = stmtExpr->resultExpr; 721 try { 722 last->expr = makeCtorDtor( "?{}", ret, last->expr ); 723 } catch(...) { 724 std::cerr << "=======================" << std::endl; 725 std::cerr << "ERROR, can't resolve" << std::endl; 726 ret->print(std::cerr); 727 std::cerr << std::endl << "---" << std::endl; 728 last->expr->print(std::cerr); 729 730 abort(); 731 } 696 732 697 733 // add destructors after current statement -
src/SynTree/Expression.cc
ree574a2 rde8dfac2 610 610 computeResult(); 611 611 } 612 StmtExpr::StmtExpr( const StmtExpr & other ) : Expression( other ), statements( other.statements->clone() ) {612 StmtExpr::StmtExpr( const StmtExpr & other ) : Expression( other ), statements( other.statements->clone() ), resultExpr( other.resultExpr ) { 613 613 cloneAll( other.returnDecls, returnDecls ); 614 614 cloneAll( other.dtors, dtors ); -
src/SynTree/Expression.h
ree574a2 rde8dfac2 62 62 InferredParams inferParams; ///< Post-resolution inferred parameter slots 63 63 std::vector<UniqueId> resnSlots; ///< Pre-resolution inferred parameter slots 64 64 65 65 // xxx - should turn inferParams+resnSlots into a union to save some memory 66 66 … … 744 744 std::list< Expression * > dtors; // destructor(s) for return variable(s) 745 745 746 // readonly 747 ExprStmt * resultExpr = nullptr; 748 746 749 StmtExpr( CompoundStmt * statements ); 747 750 StmtExpr( const StmtExpr & other );
Note: See TracChangeset
for help on using the changeset viewer.