Changeset 5b51f5e for src/InitTweak/FixInit.cc
- Timestamp:
- Jan 5, 2018, 3:21:42 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 65deb18, cae28da
- Parents:
- 5c4f2c2 (diff), b834e98 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/FixInit.cc
r5c4f2c2 r5b51f5e 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // FixInit. h--7 // FixInit.cc -- 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 ExprStmt * exprStmt = strict_dynamic_cast< ExprStmt * >( stmt->get_callStmt() ); 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 ); 368 369 Expression * resolved = exprStmt->expr; 369 370 exprStmt->expr = nullptr; // take ownership of expr … … 382 383 } // if 383 384 delete stmt; 385 if ( TupleAssignExpr * assign = dynamic_cast< TupleAssignExpr * >( resolved ) ) { 386 // fix newly generated StmtExpr 387 postvisit( assign->stmtExpr ); 388 } 384 389 return resolved; 385 390 } … … 475 480 static UniqueName retNamer("_tmp_stmtexpr_ret"); 476 481 477 // create variable that will hold the result of the stmt expr478 482 result = result->clone(); 479 483 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 expr 480 490 ObjectDecl * ret = ObjectDecl::newObject( retNamer.newName(), result, nullptr ); 481 ret-> get_type()->set_const( false );482 stmtExpr-> get_returnDecls().push_front( ret );491 ret->type->set_const( false ); 492 stmtExpr->returnDecls.push_front( ret ); 483 493 484 494 // must have a non-empty body, otherwise it wouldn't have a result 485 CompoundStmt * body = stmtExpr-> get_statements();495 CompoundStmt * body = stmtExpr->statements; 486 496 assert( ! body->get_kids().empty() ); 487 497 // must be an ExprStmt, otherwise it wouldn't have a result 488 498 ExprStmt * last = strict_dynamic_cast< ExprStmt * >( body->get_kids().back() ); 489 last-> set_expr( makeCtorDtor( "?{}", ret, last->get_expr()) );490 491 stmtExpr-> get_dtors().push_front( makeCtorDtor( "^?{}", ret ) );499 last->expr = makeCtorDtor( "?{}", ret, last->get_expr() ); 500 501 stmtExpr->dtors.push_front( makeCtorDtor( "^?{}", ret ) ); 492 502 } // if 493 503 } … … 590 600 // to the outer context, rather than inside of the statement expression. 591 601 visit_children = false; 592 std::list< Statement * > & stmts = stmtExpr-> get_statements()->get_kids();602 std::list< Statement * > & stmts = stmtExpr->statements->get_kids(); 593 603 for ( Statement *& stmt : stmts ) { 594 604 stmt = stmt->acceptMutator( *visitor ); 595 605 } // for 596 assert( stmtExpr-> get_result());597 Type * result = stmtExpr-> get_result();606 assert( stmtExpr->result ); 607 Type * result = stmtExpr->result; 598 608 if ( ! result->isVoid() ) { 599 for ( ObjectDecl * obj : stmtExpr-> get_returnDecls()) {609 for ( ObjectDecl * obj : stmtExpr->returnDecls ) { 600 610 stmtsToAddBefore.push_back( new DeclStmt( obj ) ); 601 611 } // for 602 612 // add destructors after current statement 603 for ( Expression * dtor : stmtExpr-> get_dtors()) {613 for ( Expression * dtor : stmtExpr->dtors ) { 604 614 stmtsToAddAfter.push_back( new ExprStmt( dtor ) ); 605 615 } // for 606 616 // must have a non-empty body, otherwise it wouldn't have a result 607 617 assert( ! stmts.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() ); 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() ); 615 628 } 616 629
Note:
See TracChangeset
for help on using the changeset viewer.