Refactor ast.local to make room for initialization via recv
This commit is contained in:
parent
ef1bcdea70
commit
71f058499a
6 changed files with 29 additions and 17 deletions
|
|
@ -194,10 +194,18 @@ tag stmt_ {
|
|||
stmt_crate_directive(@crate_directive);
|
||||
}
|
||||
|
||||
tag init_op {
|
||||
init_assign;
|
||||
init_recv;
|
||||
}
|
||||
|
||||
type initializer = rec(init_op op,
|
||||
@expr expr);
|
||||
|
||||
type local = rec(option.t[@ty] ty,
|
||||
bool infer,
|
||||
ident ident,
|
||||
option.t[@expr] init,
|
||||
option.t[initializer] init,
|
||||
def_id id,
|
||||
ann ann);
|
||||
|
||||
|
|
|
|||
|
|
@ -1364,13 +1364,14 @@ impure fn parse_expr_inner(parser p) -> @ast.expr {
|
|||
}
|
||||
}
|
||||
|
||||
impure fn parse_initializer(parser p) -> option.t[@ast.expr] {
|
||||
impure fn parse_initializer(parser p) -> option.t[ast.initializer] {
|
||||
if (p.peek() == token.EQ) {
|
||||
p.bump();
|
||||
ret some(parse_expr(p));
|
||||
ret some(rec(op = ast.init_assign,
|
||||
expr = parse_expr(p)));
|
||||
}
|
||||
|
||||
ret none[@ast.expr];
|
||||
ret none[ast.initializer];
|
||||
}
|
||||
|
||||
impure fn parse_pat(parser p) -> @ast.pat {
|
||||
|
|
|
|||
|
|
@ -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_);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 (_) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -561,10 +561,10 @@ impure fn print_decl(ps s, @ast.decl decl) {
|
|||
}
|
||||
wrd(s, loc.ident);
|
||||
alt (loc.init) {
|
||||
case (option.some[@ast.expr](?init)) {
|
||||
case (option.some[ast.initializer](?init)) {
|
||||
space(s);
|
||||
wrd1(s, "=");
|
||||
print_expr(s, init);
|
||||
print_expr(s, init.expr);
|
||||
}
|
||||
case (_) {}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue