summary refs log tree commit diff
path: root/src/comp/syntax
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2012-02-28 19:28:29 -0800
committerNiko Matsakis <niko@alum.mit.edu>2012-02-29 19:31:15 -0800
commit2dd5b3ace6562597d7d268eb7a10fc6f1def2d0f (patch)
treecaa535fdeffef9f338b96ac9f40acec31e34ebe4 /src/comp/syntax
parent99f231f3477c276c84b1335490c3942453095dad (diff)
downloadrust-2dd5b3ace6562597d7d268eb7a10fc6f1def2d0f.tar.gz
rust-2dd5b3ace6562597d7d268eb7a10fc6f1def2d0f.zip
optionally enforce local variable mutability
Diffstat (limited to 'src/comp/syntax')
-rw-r--r--src/comp/syntax/ast.rs5
-rw-r--r--src/comp/syntax/ast_util.rs2
-rw-r--r--src/comp/syntax/fold.rs3
-rw-r--r--src/comp/syntax/parse/parser.rs16
4 files changed, 14 insertions, 12 deletions
diff --git a/src/comp/syntax/ast.rs b/src/comp/syntax/ast.rs
index 9e84cb9cd90..edc5ade4062 100644
--- a/src/comp/syntax/ast.rs
+++ b/src/comp/syntax/ast.rs
@@ -38,7 +38,7 @@ enum def {
     def_native_mod(def_id),
     def_const(def_id),
     def_arg(node_id, mode),
-    def_local(node_id),
+    def_local(node_id, bool /* is_mutbl */),
     def_variant(def_id /* enum */, def_id /* variant */),
     def_ty(def_id),
     def_prim_ty(prim_ty),
@@ -194,7 +194,8 @@ enum init_op { init_assign, init_move, }
 type initializer = {op: init_op, expr: @expr};
 
 type local_ =  // FIXME: should really be a refinement on pat
-    {ty: @ty, pat: @pat, init: option<initializer>, id: node_id};
+    {is_mutbl: bool, ty: @ty, pat: @pat,
+     init: option<initializer>, id: node_id};
 
 type local = spanned<local_>;
 
diff --git a/src/comp/syntax/ast_util.rs b/src/comp/syntax/ast_util.rs
index fb36fc17216..5f303b8c4a8 100644
--- a/src/comp/syntax/ast_util.rs
+++ b/src/comp/syntax/ast_util.rs
@@ -41,7 +41,7 @@ fn def_id_of_def(d: def) -> def_id {
       def_use(id) |
       def_class(id) | def_class_field(_, id) | def_class_method(_, id) { id }
 
-      def_self(id) | def_arg(id, _) | def_local(id) |
+      def_self(id) | def_arg(id, _) | def_local(id, _) |
       def_upvar(id, _, _) | def_binding(id) {
         local_def(id)
       }
diff --git a/src/comp/syntax/fold.rs b/src/comp/syntax/fold.rs
index 00624bdf270..94a0ff6b879 100644
--- a/src/comp/syntax/fold.rs
+++ b/src/comp/syntax/fold.rs
@@ -532,7 +532,8 @@ fn noop_fold_path(&&p: path_, fld: ast_fold) -> path_ {
 }
 
 fn noop_fold_local(l: local_, fld: ast_fold) -> local_ {
-    ret {ty: fld.fold_ty(l.ty),
+    ret {is_mutbl: l.is_mutbl,
+         ty: fld.fold_ty(l.ty),
          pat: fld.fold_pat(l.pat),
          init:
              alt l.init {
diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs
index 0de75d88422..5837baf1ff9 100644
--- a/src/comp/syntax/parse/parser.rs
+++ b/src/comp/syntax/parse/parser.rs
@@ -1346,7 +1346,7 @@ fn parse_else_expr(p: parser) -> @ast::expr {
 
 fn parse_for_expr(p: parser) -> @ast::expr {
     let lo = p.last_span.lo;
-    let decl = parse_local(p, false);
+    let decl = parse_local(p, false, false);
     expect_word(p, "in");
     let seq = parse_expr(p);
     let body = parse_block_no_value(p);
@@ -1568,24 +1568,24 @@ fn parse_pat(p: parser) -> @ast::pat {
     ret @{id: p.get_id(), node: pat, span: ast_util::mk_sp(lo, hi)};
 }
 
-fn parse_local(p: parser, allow_init: bool) -> @ast::local {
+fn parse_local(p: parser, is_mutbl: bool,
+               allow_init: bool) -> @ast::local {
     let lo = p.span.lo;
     let pat = parse_pat(p);
     let ty = @spanned(lo, lo, ast::ty_infer);
     if eat(p, token::COLON) { ty = parse_ty(p, false); }
     let init = if allow_init { parse_initializer(p) } else { none };
     ret @spanned(lo, p.last_span.hi,
-                 {ty: ty, pat: pat, init: init, id: p.get_id()});
+                 {is_mutbl: is_mutbl, ty: ty, pat: pat,
+                  init: init, id: p.get_id()});
 }
 
 fn parse_let(p: parser) -> @ast::decl {
-    if eat_word(p, "mut") {
-        /* FIXME */
-    }
+    let is_mutbl = eat_word(p, "mut");
     let lo = p.span.lo;
-    let locals = [parse_local(p, true)];
+    let locals = [parse_local(p, is_mutbl, true)];
     while eat(p, token::COMMA) {
-        locals += [parse_local(p, true)];
+        locals += [parse_local(p, is_mutbl, true)];
     }
     ret @spanned(lo, p.last_span.hi, ast::decl_local(locals));
 }