Changes in / [98a8290:4ae2364]
- Location:
- src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/FixInit.cc
r98a8290 r4ae2364 72 72 }; 73 73 74 struct StmtExprResult {75 static void link( std::list< Declaration * > & translationUnit );76 77 void previsit( StmtExpr * stmtExpr );78 };79 80 74 struct InsertImplicitCalls : public WithConstTypeSubstitution { 81 75 /// wrap function application expressions as ImplicitCopyCtorExpr nodes so that it is easy to identify which … … 232 226 acceptAll( translationUnit, checker ); 233 227 234 // fixes StmtExpr to properly link to their resulting expression235 StmtExprResult::link( translationUnit );236 237 228 // fixes ConstructorInit for global variables. should happen before fixInitializers. 238 229 InitTweak::fixGlobalInit( translationUnit, inLibrary ); … … 308 299 309 300 return dtorFunc; 310 }311 312 void StmtExprResult::link( std::list< Declaration * > & translationUnit ) {313 PassVisitor<StmtExprResult> linker;314 acceptAll( translationUnit, linker );315 301 } 316 302 … … 363 349 PassVisitor<FixCtorExprs> fixer; 364 350 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 back369 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 }376 351 } 377 352 … … 680 655 // function call temporaries should be placed at statement-level, rather than nested inside of a new statement expression, 681 656 // since temporaries can be shared across sub-expressions, e.g. 682 // [A, A] f(); // decl683 // g([A] x, [A] y); // decl684 // g(f()); // call657 // [A, A] f(); 658 // g([A] x, [A] y); 659 // g(f()); 685 660 // f is executed once, so the return temporary is shared across the tuple constructors for x and y. 686 661 // Explicitly mutating children instead of mutating the inner compound statement forces the temporaries to be added … … 690 665 assert( env ); 691 666 692 indexer.enterScope();693 667 // visit all statements 694 668 std::list< Statement * > & stmts = stmtExpr->statements->get_kids(); … … 696 670 stmt = stmt->acceptMutator( *visitor ); 697 671 } // for 698 indexer.leaveScope();699 672 700 673 assert( stmtExpr->result ); … … 715 688 stmtsToAddBefore.push_back( new DeclStmt( ret ) ); 716 689 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 } 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 ); 732 696 733 697 // add destructors after current statement -
src/SynTree/Expression.cc
r98a8290 r4ae2364 610 610 computeResult(); 611 611 } 612 StmtExpr::StmtExpr( const StmtExpr & other ) : Expression( other ), statements( other.statements->clone() ) , resultExpr( other.resultExpr ){612 StmtExpr::StmtExpr( const StmtExpr & other ) : Expression( other ), statements( other.statements->clone() ) { 613 613 cloneAll( other.returnDecls, returnDecls ); 614 614 cloneAll( other.dtors, dtors ); -
src/SynTree/Expression.h
r98a8290 r4ae2364 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 // readonly747 ExprStmt * resultExpr = nullptr;748 749 746 StmtExpr( CompoundStmt * statements ); 750 747 StmtExpr( const StmtExpr & other );
Note: See TracChangeset
for help on using the changeset viewer.