about summary refs log tree commit diff
path: root/src/comp
diff options
context:
space:
mode:
authorMichael Sullivan <sully@msully.net>2011-07-19 18:17:49 -0700
committerMichael Sullivan <sully@msully.net>2011-07-19 18:30:08 -0700
commitda2a7e5bd25055de1573a7f862986522213ed1ca (patch)
tree78dc94e4508362f1f9d753cd485e2decc1d04621 /src/comp
parent9bd945639be45325e61bb26a90faf58fe7e56c17 (diff)
downloadrust-da2a7e5bd25055de1573a7f862986522213ed1ca.tar.gz
rust-da2a7e5bd25055de1573a7f862986522213ed1ca.zip
Simple refactoring in the pretty printer.
Introduce a proto_to_str function to find the string representation of a given
proto instead of casing on the proto in multiple places.
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/syntax/print/pprust.rs17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs
index facf0152430..caeba63ffd5 100644
--- a/src/comp/syntax/print/pprust.rs
+++ b/src/comp/syntax/print/pprust.rs
@@ -848,7 +848,7 @@ fn print_expr(&ps s, &@ast::expr expr) {
             bclose(s, expr.span);
         }
         case (ast::expr_fn(?f)) {
-            head(s, "fn");
+            head(s, proto_to_str(f.proto));
             print_fn_args_and_ret(s, f.decl);
             space(s.s);
             print_block(s, f.body);
@@ -1147,9 +1147,7 @@ fn print_fn(&ps s, ast::fn_decl decl, ast::proto proto, str name,
             &ast::ty_param[] typarams) {
     alt (decl.purity) {
         case (ast::impure_fn) {
-            if (proto == ast::proto_iter) {
-                head(s, "iter");
-            } else { head(s, "fn"); }
+            head(s, proto_to_str(proto));
         }
         case (_) { head(s, "pred"); }
     }
@@ -1308,9 +1306,7 @@ fn print_ty_fn(&ps s, &ast::proto proto, &option::t[str] id,
                &ast::ty_arg[] inputs, &@ast::ty output,
                &ast::controlflow cf, &(@ast::constr)[] constrs) {
     ibox(s, indent_unit);
-    if (proto == ast::proto_fn) {
-        word(s.s, "fn");
-    } else { word(s.s, "iter"); }
+    word(s.s, proto_to_str(proto));
     alt (id) {
         case (some(?id)) { word(s.s, " "); word(s.s, id); }
         case (_) { }
@@ -1565,6 +1561,13 @@ fn ast_constrs_str(&(@ast::constr)[] constrs) -> str {
     ret s;
 }
 
+fn proto_to_str(&ast::proto p) -> str {
+    ret alt (p) {
+        ast::proto_fn { "fn" }
+        ast::proto_iter { "iter" }
+    };
+}
+
 //
 // Local Variables:
 // mode: rust