about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBrian Anderson <andersrb@gmail.com>2011-03-24 21:04:29 -0400
committerGraydon Hoare <graydon@mozilla.com>2011-03-25 11:01:52 -0700
commit71f058499a0e551d2b8deb5d098bdb04387dc021 (patch)
tree4e14a52c8c0092f332c3c9477b85b97799310244
parentef1bcdea7025f6fd18fcd645804f83186546fa97 (diff)
downloadrust-71f058499a0e551d2b8deb5d098bdb04387dc021.tar.gz
rust-71f058499a0e551d2b8deb5d098bdb04387dc021.zip
Refactor ast.local to make room for initialization via recv
-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 349f887a2f9..0d70c993b3b 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 063bc0e178f..23b4a9366fc 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 a1b7761201b..b59a1f3b990 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 a65bb284121..5c7c8ff7c79 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 47ef81c1952..a381ae931ce 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 25eb60edd36..10cc5355204 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 (_) {}
       }