Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/FixInit.cc

    r6dfa2e1 rba3706f  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // FixInit.cc --
     7// FixInit.h --
    88//
    99// Author           : Rob Schluntz
     
    365365                        // arrays are not copy constructed, so this should always be an ExprStmt
    366366                        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() );
    369368                        Expression * resolved = exprStmt->expr;
    370369                        exprStmt->expr = nullptr; // take ownership of expr
     
    383382                        } // if
    384383                        delete stmt;
    385                         if ( TupleAssignExpr * assign = dynamic_cast< TupleAssignExpr * >( resolved ) ) {
    386                                 // fix newly generated StmtExpr
    387                                 postvisit( assign->stmtExpr );
    388                         }
    389384                        return resolved;
    390385                }
     
    480475                                static UniqueName retNamer("_tmp_stmtexpr_ret");
    481476
     477                                // create variable that will hold the result of the stmt expr
    482478                                result = result->clone();
    483479                                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
    490480                                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 );
    493483
    494484                                // must have a non-empty body, otherwise it wouldn't have a result
    495                                 CompoundStmt * body = stmtExpr->statements;
     485                                CompoundStmt * body = stmtExpr->get_statements();
    496486                                assert( ! body->get_kids().empty() );
    497487                                // must be an ExprStmt, otherwise it wouldn't have a result
    498488                                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 ) );
    502492                        } // if
    503493                }
     
    600590                        // to the outer context, rather than inside of the statement expression.
    601591                        visit_children = false;
    602                         std::list< Statement * > & stmts = stmtExpr->statements->get_kids();
     592                        std::list< Statement * > & stmts = stmtExpr->get_statements()->get_kids();
    603593                        for ( Statement *& stmt : stmts ) {
    604594                                stmt = stmt->acceptMutator( *visitor );
    605595                        } // for
    606                         assert( stmtExpr->result );
    607                         Type * result = stmtExpr->result;
     596                        assert( stmtExpr->get_result() );
     597                        Type * result = stmtExpr->get_result();
    608598                        if ( ! result->isVoid() ) {
    609                                 for ( ObjectDecl * obj : stmtExpr->returnDecls ) {
     599                                for ( ObjectDecl * obj : stmtExpr->get_returnDecls() ) {
    610600                                        stmtsToAddBefore.push_back( new DeclStmt( obj ) );
    611601                                } // for
    612602                                // add destructors after current statement
    613                                 for ( Expression * dtor : stmtExpr->dtors ) {
     603                                for ( Expression * dtor : stmtExpr->get_dtors() ) {
    614604                                        stmtsToAddAfter.push_back( new ExprStmt( dtor ) );
    615605                                } // for
    616606                                // must have a non-empty body, otherwise it wouldn't have a result
    617607                                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() );
    628615                }
    629616
Note: See TracChangeset for help on using the changeset viewer.