aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/comp/front/ast.rs10
-rw-r--r--src/comp/front/parser.rs7
-rw-r--r--src/comp/middle/fold.rs10
-rw-r--r--src/comp/middle/trans.rs4
-rw-r--r--src/comp/middle/typeck.rs11
-rw-r--r--src/comp/pretty/pprust.rs4
6 files changed, 29 insertions, 17 deletions
diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs
index 349f887a..0d70c993 100644
--- a/src/comp/front/ast.rs
+++ b/src/comp/front/ast.rs
@@ -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);
diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs
index 063bc0e1..23b4a936 100644
--- a/src/comp/front/parser.rs
+++ b/src/comp/front/parser.rs
@@ -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 {
diff --git a/src/comp/middle/fold.rs b/src/comp/middle/fold.rs
index a1b77612..b59a1f3b 100644
--- a/src/comp/middle/fold.rs
+++ b/src/comp/middle/fold.rs
@@ -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_);
}
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index a65bb284..5c7c8ff7 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -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 (_) {
diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs
index 47ef81c1..a381ae93 100644
--- a/src/comp/middle/typeck.rs
+++ b/src/comp/middle/typeck.rs
@@ -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);
}
diff --git a/src/comp/pretty/pprust.rs b/src/comp/pretty/pprust.rs
index 25eb60ed..10cc5355 100644
--- a/src/comp/pretty/pprust.rs
+++ b/src/comp/pretty/pprust.rs
@@ -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 (_) {}
}