Changes in / [379b6ea:8ef0bf7]
- Location:
- src
- Files:
-
- 5 edited
-
AST/Expr.cpp (modified) (1 diff)
-
AST/Expr.hpp (modified) (1 diff)
-
AST/Pass.impl.hpp (modified) (1 diff)
-
AST/Print.cpp (modified) (1 diff)
-
InitTweak/FixInit.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Expr.cpp
r379b6ea r8ef0bf7 393 393 394 394 StmtExpr::StmtExpr( const CodeLocation & loc, const CompoundStmt * ss ) 395 : Expr( loc ), stmts( ss ) { computeResult(); }395 : Expr( loc ), stmts( ss ), returnDecls(), dtors() { computeResult(); } 396 396 397 397 void StmtExpr::computeResult() { 398 398 assert( stmts ); 399 399 const std::list<ptr<Stmt>> & body = stmts->kids; 400 // If there is a tail expression, its result is entire result. 401 if ( !body.empty() && ( resultExpr = body.back().as<ExprStmt>() ) ) { 402 result = resultExpr->expr->result; 403 // Otherwise, fill in the result with void so there is a result type. 404 } else { 405 result = new VoidType(); 406 } 400 if ( ! returnDecls.empty() ) { 401 // prioritize return decl for result type, since if a return decl exists, then the StmtExpr 402 // is currently in an intermediate state where the body will always give a void result type 403 result = returnDecls.front()->get_type(); 404 } else if ( ! body.empty() ) { 405 if ( const ExprStmt * exprStmt = body.back().as< ExprStmt >() ) { 406 result = exprStmt->expr->result; 407 } 408 } 409 // ensure a result type exists 410 if ( ! result ) { result = new VoidType{}; } 407 411 } 408 412 -
src/AST/Expr.hpp
r379b6ea r8ef0bf7 782 782 public: 783 783 ptr<CompoundStmt> stmts; 784 std::vector<ptr<ObjectDecl>> returnDecls; ///< return variable(s) for statement expression 785 std::vector<ptr<Expr>> dtors; ///< destructor(s) for return variable(s) 784 786 785 787 readonly<ExprStmt> resultExpr; -
src/AST/Pass.impl.hpp
r379b6ea r8ef0bf7 1697 1697 } 1698 1698 maybe_accept( node, &StmtExpr::stmts ); 1699 maybe_accept( node, &StmtExpr::returnDecls ); 1700 maybe_accept( node, &StmtExpr::dtors ); 1699 1701 } 1700 1702 -
src/AST/Print.cpp
r379b6ea r8ef0bf7 1406 1406 os << "Statement Expression:" << endl << indent; 1407 1407 safe_print( node->stmts ); 1408 if ( ! node->returnDecls.empty() ) { 1409 os << indent << "... with returnDecls: "; 1410 printAll( node->returnDecls ); 1411 } 1412 if ( ! node->dtors.empty() ) { 1413 os << indent << "... with dtors: "; 1414 printAll( node->dtors ); 1415 } 1408 1416 --indent; 1409 1417 postprint( node ); -
src/InitTweak/FixInit.cpp
r379b6ea r8ef0bf7 697 697 assert( stmtExpr->result ); 698 698 if ( stmtExpr->result->isVoid() ) { 699 assert( stmtExpr->returnDecls.empty() ); 700 assert( stmtExpr->dtors.empty() ); 701 699 702 return stmtExpr; 700 703 } … … 744 747 // if there is a return decl, add a use as the last statement; will not have return decl on non-constructable returns 745 748 stmts.push_back( new ast::ExprStmt(loc, new ast::VariableExpr(loc, ret ) ) ); 749 750 assert( stmtExpr->returnDecls.empty() ); 751 assert( stmtExpr->dtors.empty() ); 746 752 747 753 return stmtExpr;
Note:
See TracChangeset
for help on using the changeset viewer.