Skip to content

Commit 71f0584

Browse files
brsongraydon
authored andcommitted
Refactor ast.local to make room for initialization via recv
1 parent ef1bcde commit 71f0584

File tree

6 files changed

+29
-17
lines changed

6 files changed

+29
-17
lines changed

src/comp/front/ast.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,18 @@ tag stmt_ {
194194
stmt_crate_directive(@crate_directive);
195195
}
196196
197+
tag init_op {
198+
init_assign;
199+
init_recv;
200+
}
201+
202+
type initializer = rec(init_op op,
203+
@expr expr);
204+
197205
type local = rec(option.t[@ty] ty,
198206
bool infer,
199207
ident ident,
200-
option.t[@expr] init,
208+
option.t[initializer] init,
201209
def_id id,
202210
ann ann);
203211

src/comp/front/parser.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,13 +1364,14 @@ impure fn parse_expr_inner(parser p) -> @ast.expr {
13641364
}
13651365
}
13661366

1367-
impure fn parse_initializer(parser p) -> option.t[@ast.expr] {
1367+
impure fn parse_initializer(parser p) -> option.t[ast.initializer] {
13681368
if (p.peek() == token.EQ) {
13691369
p.bump();
1370-
ret some(parse_expr(p));
1370+
ret some(rec(op = ast.init_assign,
1371+
expr = parse_expr(p)));
13711372
}
13721373

1373-
ret none[@ast.expr];
1374+
ret none[ast.initializer];
13741375
}
13751376

13761377
impure fn parse_pat(parser p) -> @ast.pat {

src/comp/middle/fold.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -437,20 +437,22 @@ fn fold_decl[ENV](&ENV env, ast_fold[ENV] fld, @decl d) -> @decl {
437437
alt (d.node) {
438438
case (ast.decl_local(?local)) {
439439
auto ty_ = none[@ast.ty];
440-
auto init_ = none[@ast.expr];
440+
auto initopt = none[ast.initializer];
441441
alt (local.ty) {
442442
case (some[@ast.ty](?t)) {
443443
ty_ = some[@ast.ty](fold_ty(env, fld, t));
444444
}
445445
case (_) { /* fall through */ }
446446
}
447447
alt (local.init) {
448-
case (some[@ast.expr](?e)) {
449-
init_ = some[@ast.expr](fold_expr(env, fld, e));
448+
case (some[ast.initializer](?init)) {
449+
auto init_ = rec(expr = fold_expr(env, fld, init.expr)
450+
with init);
451+
initopt = some[ast.initializer](init_);
450452
}
451453
case (_) { /* fall through */ }
452454
}
453-
let @ast.local local_ = @rec(ty=ty_, init=init_ with *local);
455+
let @ast.local local_ = @rec(ty=ty_, init=initopt with *local);
454456
ret fld.fold_decl_local(env_, d.span, local_);
455457
}
456458

src/comp/middle/trans.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4869,8 +4869,8 @@ fn init_local(@block_ctxt cx, @ast.local local) -> result {
48694869
vec(clean(bind drop_slot(_, llptr, ty)));
48704870

48714871
alt (local.init) {
4872-
case (some[@ast.expr](?e)) {
4873-
auto sub = trans_expr(bcx, e);
4872+
case (some[ast.initializer](?init)) {
4873+
auto sub = trans_expr(bcx, init.expr);
48744874
bcx = copy_ty(sub.bcx, INIT, llptr, sub.val, ty).bcx;
48754875
}
48764876
case (_) {

src/comp/middle/typeck.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2404,17 +2404,18 @@ fn check_decl_local(&@fn_ctxt fcx, &@ast.decl decl) -> @ast.decl {
24042404
}
24052405
}
24062406

2407-
auto init = local.init;
2407+
auto initopt = local.init;
24082408
alt (local.init) {
2409-
case (some[@ast.expr](?expr)) {
2410-
auto expr_0 = check_expr(fcx, expr);
2409+
case (some[ast.initializer](?init)) {
2410+
auto expr_0 = check_expr(fcx, init.expr);
24112411
auto lty = plain_ty(ty.ty_local(local.id));
24122412
auto expr_1 = demand_expr(fcx, lty, expr_0);
2413-
init = some[@ast.expr](expr_1);
2413+
auto init_0 = rec(expr = expr_1 with init);
2414+
initopt = some[ast.initializer](init_0);
24142415
}
24152416
case (_) { /* fall through */ }
24162417
}
2417-
auto local_1 = @rec(init = init with *local);
2418+
auto local_1 = @rec(init = initopt with *local);
24182419
ret @rec(node=ast.decl_local(local_1)
24192420
with *decl);
24202421
}

src/comp/pretty/pprust.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,10 +561,10 @@ impure fn print_decl(ps s, @ast.decl decl) {
561561
}
562562
wrd(s, loc.ident);
563563
alt (loc.init) {
564-
case (option.some[@ast.expr](?init)) {
564+
case (option.some[ast.initializer](?init)) {
565565
space(s);
566566
wrd1(s, "=");
567-
print_expr(s, init);
567+
print_expr(s, init.expr);
568568
}
569569
case (_) {}
570570
}

0 commit comments

Comments
 (0)