Changes in src/InitTweak/FixInit.cc [6dfa2e1:ba3706f]
- File:
-
- 1 edited
-
src/InitTweak/FixInit.cc (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/FixInit.cc
r6dfa2e1 rba3706f 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // FixInit. cc--7 // FixInit.h -- 8 8 // 9 9 // Author : Rob Schluntz … … 365 365 // arrays are not copy constructed, so this should always be an ExprStmt 366 366 ImplicitCtorDtorStmt * stmt = genCtorDtor( fname, var, cpArg ); 367 assertf( stmt, "ResolveCopyCtors: genCtorDtor returned nullptr: %s / %s / %s", fname.c_str(), toString( var ).c_str(), toString( cpArg ).c_str() ); 368 ExprStmt * exprStmt = strict_dynamic_cast< ExprStmt * >( stmt->callStmt ); 367 ExprStmt * exprStmt = strict_dynamic_cast< ExprStmt * >( stmt->get_callStmt() ); 369 368 Expression * resolved = exprStmt->expr; 370 369 exprStmt->expr = nullptr; // take ownership of expr … … 383 382 } // if 384 383 delete stmt; 385 if ( TupleAssignExpr * assign = dynamic_cast< TupleAssignExpr * >( resolved ) ) {386 // fix newly generated StmtExpr387 postvisit( assign->stmtExpr );388 }389 384 return resolved; 390 385 } … … 480 475 static UniqueName retNamer("_tmp_stmtexpr_ret"); 481 476 477 // create variable that will hold the result of the stmt expr 482 478 result = result->clone(); 483 479 env->apply( result ); 484 if ( ! InitTweak::isConstructable( result ) ) {485 delete result;486 return;487 }488 489 // create variable that will hold the result of the stmt expr490 480 ObjectDecl * ret = ObjectDecl::newObject( retNamer.newName(), result, nullptr ); 491 ret-> type->set_const( false );492 stmtExpr-> returnDecls.push_front( ret );481 ret->get_type()->set_const( false ); 482 stmtExpr->get_returnDecls().push_front( ret ); 493 483 494 484 // must have a non-empty body, otherwise it wouldn't have a result 495 CompoundStmt * body = stmtExpr-> statements;485 CompoundStmt * body = stmtExpr->get_statements(); 496 486 assert( ! body->get_kids().empty() ); 497 487 // must be an ExprStmt, otherwise it wouldn't have a result 498 488 ExprStmt * last = strict_dynamic_cast< ExprStmt * >( body->get_kids().back() ); 499 last-> expr = makeCtorDtor( "?{}", ret, last->get_expr() );500 501 stmtExpr-> dtors.push_front( makeCtorDtor( "^?{}", ret ) );489 last->set_expr( makeCtorDtor( "?{}", ret, last->get_expr() ) ); 490 491 stmtExpr->get_dtors().push_front( makeCtorDtor( "^?{}", ret ) ); 502 492 } // if 503 493 } … … 600 590 // to the outer context, rather than inside of the statement expression. 601 591 visit_children = false; 602 std::list< Statement * > & stmts = stmtExpr-> statements->get_kids();592 std::list< Statement * > & stmts = stmtExpr->get_statements()->get_kids(); 603 593 for ( Statement *& stmt : stmts ) { 604 594 stmt = stmt->acceptMutator( *visitor ); 605 595 } // for 606 assert( stmtExpr-> result);607 Type * result = stmtExpr-> result;596 assert( stmtExpr->get_result() ); 597 Type * result = stmtExpr->get_result(); 608 598 if ( ! result->isVoid() ) { 609 for ( ObjectDecl * obj : stmtExpr-> returnDecls) {599 for ( ObjectDecl * obj : stmtExpr->get_returnDecls() ) { 610 600 stmtsToAddBefore.push_back( new DeclStmt( obj ) ); 611 601 } // for 612 602 // add destructors after current statement 613 for ( Expression * dtor : stmtExpr-> dtors) {603 for ( Expression * dtor : stmtExpr->get_dtors() ) { 614 604 stmtsToAddAfter.push_back( new ExprStmt( dtor ) ); 615 605 } // for 616 606 // must have a non-empty body, otherwise it wouldn't have a result 617 607 assert( ! stmts.empty() ); 618 assertf( ! stmtExpr->returnDecls.empty() || stmtExpr->dtors.empty(), "StmtExpr returns non-void, but no return decls: %s", toString( stmtExpr ).c_str() ); 619 // if there is a return decl, add a use as the last statement; will not have return decl on non-constructable returns 620 if ( ! stmtExpr->returnDecls.empty() ) { 621 stmts.push_back( new ExprStmt( new VariableExpr( stmtExpr->returnDecls.front() ) ) ); 622 } 623 stmtExpr->returnDecls.clear(); 624 stmtExpr->dtors.clear(); 625 } 626 assert( stmtExpr->returnDecls.empty() ); 627 assert( stmtExpr->dtors.empty() ); 608 assert( ! stmtExpr->get_returnDecls().empty() ); 609 stmts.push_back( new ExprStmt( new VariableExpr( stmtExpr->get_returnDecls().front() ) ) ); 610 stmtExpr->get_returnDecls().clear(); 611 stmtExpr->get_dtors().clear(); 612 } 613 assert( stmtExpr->get_returnDecls().empty() ); 614 assert( stmtExpr->get_dtors().empty() ); 628 615 } 629 616
Note:
See TracChangeset
for help on using the changeset viewer.