about summary refs log tree commit diff
path: root/src/comp/syntax
diff options
context:
space:
mode:
Diffstat (limited to 'src/comp/syntax')
-rw-r--r--src/comp/syntax/ast.rs12
-rw-r--r--src/comp/syntax/parse/parser.rs25
-rw-r--r--src/comp/syntax/print/pprust.rs21
3 files changed, 39 insertions, 19 deletions
diff --git a/src/comp/syntax/ast.rs b/src/comp/syntax/ast.rs
index b8e44257f52..8db4573c2b4 100644
--- a/src/comp/syntax/ast.rs
+++ b/src/comp/syntax/ast.rs
@@ -160,7 +160,17 @@ enum unop {
     deref, not, neg,
 }
 
-enum mode { by_ref, by_val, by_mut_ref, by_move, by_copy, mode_infer, }
+// Generally, after typeck you can get the inferred value
+// using ty::resolved_T(...).
+enum inferable<T> {
+    expl(T), infer(node_id)
+}
+
+// "resolved" mode: the real modes.
+enum rmode { by_ref, by_val, by_mut_ref, by_move, by_copy }
+
+// inferable mode.
+type mode = inferable<rmode>;
 
 type stmt = spanned<stmt_>;
 
diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs
index a4ed54f2675..0b321b17b92 100644
--- a/src/comp/syntax/parse/parser.rs
+++ b/src/comp/syntax/parse/parser.rs
@@ -521,14 +521,19 @@ fn parse_ty(p: parser, colons_before_params: bool) -> @ast::ty {
 }
 
 fn parse_arg_mode(p: parser) -> ast::mode {
-    if eat(p, token::BINOP(token::AND)) { ast::by_mut_ref }
-    else if eat(p, token::BINOP(token::MINUS)) { ast::by_move }
-    else if eat(p, token::ANDAND) { ast::by_ref }
-    else if eat(p, token::BINOP(token::PLUS)) {
-        if eat(p, token::BINOP(token::PLUS)) { ast::by_val }
-        else { ast::by_copy }
-    }
-    else { ast::mode_infer }
+    if eat(p, token::BINOP(token::AND)) {
+        ast::expl(ast::by_mut_ref)
+    } else if eat(p, token::BINOP(token::MINUS)) {
+        ast::expl(ast::by_move)
+    } else if eat(p, token::ANDAND) {
+        ast::expl(ast::by_ref)
+    } else if eat(p, token::BINOP(token::PLUS)) {
+        if eat(p, token::BINOP(token::PLUS)) {
+            ast::expl(ast::by_val)
+        } else {
+            ast::expl(ast::by_copy)
+        }
+    } else { ast::infer(p.get_id()) }
 }
 
 fn parse_arg(p: parser) -> ast::arg {
@@ -1984,8 +1989,8 @@ fn parse_item_res(p: parser, attrs: [ast::attribute]) -> @ast::item {
     let dtor = parse_block_no_value(p);
     let decl =
         {inputs:
-             [{mode: ast::by_ref, ty: t, ident: arg_ident,
-               id: p.get_id()}],
+             [{mode: ast::expl(ast::by_ref), ty: t,
+               ident: arg_ident, id: p.get_id()}],
          output: @spanned(lo, lo, ast::ty_nil),
          purity: ast::impure_fn,
          cf: ast::return_val,
diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs
index f4a04c145d7..864702d2ba1 100644
--- a/src/comp/syntax/print/pprust.rs
+++ b/src/comp/syntax/print/pprust.rs
@@ -136,7 +136,7 @@ fn res_to_str(decl: ast::fn_decl, name: ast::ident,
 fn test_res_to_str() {
     let decl: ast::fn_decl = {
         inputs: [{
-            mode: ast::by_val,
+            mode: ast::expl(ast::by_val),
             ty: @ast_util::respan(ast_util::dummy_sp(), ast::ty_bool),
             ident: "b",
             id: 0
@@ -1280,17 +1280,22 @@ fn print_fn_block_args(s: ps, decl: ast::fn_decl) {
     maybe_print_comment(s, decl.output.span.lo);
 }
 
-fn print_arg_mode(s: ps, m: ast::mode) {
+fn mode_to_str(m: ast::mode) -> str {
     alt m {
-      ast::by_mut_ref { word(s.s, "&"); }
-      ast::by_move { word(s.s, "-"); }
-      ast::by_ref { word(s.s, "&&"); }
-      ast::by_val { word(s.s, "++"); }
-      ast::by_copy { word(s.s, "+"); }
-      ast::mode_infer {}
+      ast::expl(ast::by_mut_ref) { "&" }
+      ast::expl(ast::by_move) { "-" }
+      ast::expl(ast::by_ref) { "&&" }
+      ast::expl(ast::by_val) { "++" }
+      ast::expl(ast::by_copy) { "+" }
+      ast::infer(_) { "" }
     }
 }
 
+fn print_arg_mode(s: ps, m: ast::mode) {
+    let ms = mode_to_str(m);
+    if ms != "" { word(s.s, ms); }
+}
+
 fn print_bounds(s: ps, bounds: @[ast::ty_param_bound]) {
     if vec::len(*bounds) > 0u {
         word(s.s, ":");