about summary refs log tree commit diff
path: root/src/libsyntax/print
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2012-11-30 11:18:25 -0800
committerPatrick Walton <pcwalton@mimiga.net>2012-11-30 20:41:46 -0800
commitf34833abfce74cf178c0589a4b7cf5fba9d2a2db (patch)
tree08943a296d704c10303fbd6b33b3d7e8fb704ac6 /src/libsyntax/print
parent54ae377ec26ed47bbb627bdcb58bb10658cf03c4 (diff)
downloadrust-f34833abfce74cf178c0589a4b7cf5fba9d2a2db.tar.gz
rust-f34833abfce74cf178c0589a4b7cf5fba9d2a2db.zip
librustc: Make `a.b()` always a method call. r=nmatsakis
Diffstat (limited to 'src/libsyntax/print')
-rw-r--r--src/libsyntax/print/pprust.rs89
1 files changed, 59 insertions, 30 deletions
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs
index 5ad3c051c59..e13c6da403f 100644
--- a/src/libsyntax/print/pprust.rs
+++ b/src/libsyntax/print/pprust.rs
@@ -1041,6 +1041,50 @@ fn print_expr_vstore(s: ps, t: ast::expr_vstore) {
     }
 }
 
+fn print_call_pre(s: ps,
+                  has_block: bool,
+                  base_args: &mut ~[@ast::expr])
+               -> Option<@ast::expr> {
+    if has_block {
+        let blk_arg = base_args.pop();
+        match blk_arg.node {
+          ast::expr_loop_body(_) => { head(s, ~"for"); }
+          ast::expr_do_body(_) => { head(s, ~"do"); }
+          _ => {}
+        }
+        Some(blk_arg)
+    } else {
+        None
+    }
+}
+
+fn print_call_post(s: ps,
+                   has_block: bool,
+                   blk: &Option<@ast::expr>,
+                   base_args: &mut ~[@ast::expr]) {
+    if !has_block || base_args.is_not_empty() {
+        popen(s);
+        commasep_exprs(s, inconsistent, *base_args);
+        pclose(s);
+    }
+    if has_block {
+        nbsp(s);
+        match blk.get().node {
+          // need to handle closures specifically
+          ast::expr_do_body(e) | ast::expr_loop_body(e) => {
+            end(s); // we close our head box; closure
+                    // will create it's own.
+            print_expr(s, e);
+            end(s); // close outer box, as closures don't
+          }
+          _ => {
+            // not sure if this can happen.
+            print_expr(s, blk.get());
+          }
+        }
+    }
+}
+
 fn print_expr(s: ps, &&expr: @ast::expr) {
     fn print_field(s: ps, field: ast::field) {
         ibox(s, indent_unit);
@@ -1135,38 +1179,23 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
         pclose(s);
       }
       ast::expr_call(func, args, has_block) => {
-        let mut base_args = args;
-        let blk = if has_block {
-            let blk_arg = base_args.pop();
-            match blk_arg.node {
-              ast::expr_loop_body(_) => { head(s, ~"for"); }
-              ast::expr_do_body(_) => { head(s, ~"do"); }
-              _ => {}
-            }
-            Some(blk_arg)
-        } else { None };
+        let mut base_args = copy args;
+        let blk = print_call_pre(s, has_block, &mut base_args);
         print_expr(s, func);
-        if !has_block || base_args.is_not_empty() {
-            popen(s);
-            commasep_exprs(s, inconsistent, base_args);
-            pclose(s);
-        }
-        if has_block {
-            nbsp(s);
-            match blk.get().node {
-              // need to handle closures specifically
-              ast::expr_do_body(e) | ast::expr_loop_body(e) => {
-                end(s); // we close our head box; closure
-                        // will create it's own.
-                print_expr(s, e);
-                end(s); // close outer box, as closures don't
-              }
-              _ => {
-                // not sure if this can happen.
-                print_expr(s, blk.get());
-              }
-            }
+        print_call_post(s, has_block, &blk, &mut base_args);
+      }
+      ast::expr_method_call(func, ident, tys, args, has_block) => {
+        let mut base_args = copy args;
+        let blk = print_call_pre(s, has_block, &mut base_args);
+        print_expr(s, func);
+        word(s.s, ~".");
+        print_ident(s, ident);
+        if vec::len(tys) > 0u {
+            word(s.s, ~"::<");
+            commasep(s, inconsistent, tys, print_type);
+            word(s.s, ~">");
         }
+        print_call_post(s, has_block, &blk, &mut base_args);
       }
       ast::expr_binary(op, lhs, rhs) => {
         print_expr(s, lhs);