Refactor ast.local to make room for initialization via recv

This commit is contained in:
Brian Anderson 2011-03-24 21:04:29 -04:00 committed by Graydon Hoare
parent ef1bcdea70
commit 71f058499a
6 changed files with 29 additions and 17 deletions

View file

@ -437,7 +437,7 @@ fn fold_decl[ENV](&ENV env, ast_fold[ENV] fld, @decl d) -> @decl {
alt (d.node) {
case (ast.decl_local(?local)) {
auto ty_ = none[@ast.ty];
auto init_ = none[@ast.expr];
auto initopt = none[ast.initializer];
alt (local.ty) {
case (some[@ast.ty](?t)) {
ty_ = some[@ast.ty](fold_ty(env, fld, t));
@ -445,12 +445,14 @@ fn fold_decl[ENV](&ENV env, ast_fold[ENV] fld, @decl d) -> @decl {
case (_) { /* fall through */ }
}
alt (local.init) {
case (some[@ast.expr](?e)) {
init_ = some[@ast.expr](fold_expr(env, fld, e));
case (some[ast.initializer](?init)) {
auto init_ = rec(expr = fold_expr(env, fld, init.expr)
with init);
initopt = some[ast.initializer](init_);
}
case (_) { /* fall through */ }
}
let @ast.local local_ = @rec(ty=ty_, init=init_ with *local);
let @ast.local local_ = @rec(ty=ty_, init=initopt with *local);
ret fld.fold_decl_local(env_, d.span, local_);
}

View file

@ -4869,8 +4869,8 @@ fn init_local(@block_ctxt cx, @ast.local local) -> result {
vec(clean(bind drop_slot(_, llptr, ty)));
alt (local.init) {
case (some[@ast.expr](?e)) {
auto sub = trans_expr(bcx, e);
case (some[ast.initializer](?init)) {
auto sub = trans_expr(bcx, init.expr);
bcx = copy_ty(sub.bcx, INIT, llptr, sub.val, ty).bcx;
}
case (_) {

View file

@ -2404,17 +2404,18 @@ fn check_decl_local(&@fn_ctxt fcx, &@ast.decl decl) -> @ast.decl {
}
}
auto init = local.init;
auto initopt = local.init;
alt (local.init) {
case (some[@ast.expr](?expr)) {
auto expr_0 = check_expr(fcx, expr);
case (some[ast.initializer](?init)) {
auto expr_0 = check_expr(fcx, init.expr);
auto lty = plain_ty(ty.ty_local(local.id));
auto expr_1 = demand_expr(fcx, lty, expr_0);
init = some[@ast.expr](expr_1);
auto init_0 = rec(expr = expr_1 with init);
initopt = some[ast.initializer](init_0);
}
case (_) { /* fall through */ }
}
auto local_1 = @rec(init = init with *local);
auto local_1 = @rec(init = initopt with *local);
ret @rec(node=ast.decl_local(local_1)
with *decl);
}