about summary refs log tree commit diff
path: root/src/comp/syntax
diff options
context:
space:
mode:
authorMarijn Haverbeke <marijnh@gmail.com>2011-09-14 17:18:48 +0200
committerMarijn Haverbeke <marijnh@gmail.com>2011-09-14 17:30:38 +0200
commit93de2f0b7498cbc6a304ba3cb80f5a3ea57b8bc7 (patch)
treedd42794a80d712ff07af81493bd12231924e3e21 /src/comp/syntax
parent1cabe37155bf83af04ce7814186fbef096a253cb (diff)
Add syntax and representation for return-by-mutably-rooted-ref
This will be used in the near future to decide what can safely
be done with the returned reference.

Issue #918
Diffstat (limited to 'src/comp/syntax')
-rw-r--r--src/comp/syntax/ast.rs2
-rw-r--r--src/comp/syntax/ast_util.rs7
-rw-r--r--src/comp/syntax/parse/parser.rs2
-rw-r--r--src/comp/syntax/print/pprust.rs10
4 files changed, 17 insertions, 4 deletions
diff --git a/src/comp/syntax/ast.rs b/src/comp/syntax/ast.rs
index 15d05cfe243..f064519cca3 100644
--- a/src/comp/syntax/ast.rs
+++ b/src/comp/syntax/ast.rs
@@ -381,7 +381,7 @@ tag ret_style {
     noreturn; // functions with return type _|_ that always
               // raise an error or exit (i.e. never return to the caller)
     return_val; // everything else
-    return_ref;
+    return_ref(bool);
 }
 
 type _fn = {decl: fn_decl, proto: proto, body: blk};
diff --git a/src/comp/syntax/ast_util.rs b/src/comp/syntax/ast_util.rs
index 1c11a56272e..b6c4eb9a929 100644
--- a/src/comp/syntax/ast_util.rs
+++ b/src/comp/syntax/ast_util.rs
@@ -213,6 +213,13 @@ fn ternary_to_if(e: @expr) -> @expr {
     }
 }
 
+fn ret_by_ref(style: ret_style) -> bool {
+    alt style {
+      return_ref(_) { true }
+      _ { false }
+    }
+}
+
 // Local Variables:
 // mode: rust
 // fill-column: 78;
diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs
index 8309afb85a2..543f2e65383 100644
--- a/src/comp/syntax/parse/parser.rs
+++ b/src/comp/syntax/parse/parser.rs
@@ -445,7 +445,7 @@ fn parse_ret_ty(p: parser) -> (ast::ret_style, @ast::ty) {
         } else {
             let style = ast::return_val;
             if eat(p, token::BINOP(token::AND)) {
-                style = ast::return_ref;
+                style = ast::return_ref(eat(p, token::NOT));
             };
             (style, parse_ty(p, false))
         }
diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs
index beb22544fda..92ecceb7ad1 100644
--- a/src/comp/syntax/print/pprust.rs
+++ b/src/comp/syntax/print/pprust.rs
@@ -1224,7 +1224,10 @@ fn print_fn_args_and_ret(s: ps, decl: ast::fn_decl, constrs: [@ast::constr]) {
     if decl.output.node != ast::ty_nil {
         space_if_not_bol(s);
         word_space(s, "->");
-        if decl.cf == ast::return_ref { word(s.s, "&"); }
+        alt decl.cf {
+          ast::return_ref(mut) { word(s.s, mut ? "&!" : "&"); }
+          _ {}
+        }
         print_type(s, decl.output);
     }
 }
@@ -1423,7 +1426,10 @@ fn print_ty_fn(s: ps, proto: ast::proto, id: option::t<ast::ident>,
         if cf == ast::noreturn {
             word_nbsp(s, "!")
         } else {
-            if cf == ast::return_ref { word(s.s, "&"); }
+            alt cf {
+              ast::return_ref(mut) { word(s.s, mut ? "&!" : "&"); }
+              _ {}
+            }
             print_type(s, output);
         }
         end(s);