about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMarijn Haverbeke <marijnh@gmail.com>2012-02-22 11:16:25 +0100
committerMarijn Haverbeke <marijnh@gmail.com>2012-02-22 11:16:25 +0100
commite57b6775c3a2d9dbe7fae69c189b8ae9032315cb (patch)
tree6f07cb4bd6ce573cadbdc89ac559c95c729b366f
parent40cd1a7c455afc55be01a988ae0c55f3d07fbcf5 (diff)
downloadrust-e57b6775c3a2d9dbe7fae69c189b8ae9032315cb.tar.gz
rust-e57b6775c3a2d9dbe7fae69c189b8ae9032315cb.zip
Clean up small things in syntax submodules
-rw-r--r--src/comp/syntax/ext/simplext.rs2
-rw-r--r--src/comp/syntax/parse/parser.rs4
-rw-r--r--src/comp/syntax/print/pprust.rs72
3 files changed, 27 insertions, 51 deletions
diff --git a/src/comp/syntax/ext/simplext.rs b/src/comp/syntax/ext/simplext.rs
index b8f9dd2c140..1baf5f97d20 100644
--- a/src/comp/syntax/ext/simplext.rs
+++ b/src/comp/syntax/ext/simplext.rs
@@ -459,7 +459,7 @@ fn p_t_s_rec(cx: ext_ctxt, m: matchable, s: selector, b: binders) {
               }
             }
           }
-          /* TODO: handle embedded types and blocks, at least */
+          /* FIXME: handle embedded types and blocks, at least */
           expr_mac(mac) {
             p_t_s_r_mac(cx, mac, s, b);
           }
diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs
index 35d5119c4e6..a6f56b611d7 100644
--- a/src/comp/syntax/parse/parser.rs
+++ b/src/comp/syntax/parse/parser.rs
@@ -1581,7 +1581,7 @@ fn parse_local(p: parser, allow_init: bool) -> @ast::local {
 
 fn parse_let(p: parser) -> @ast::decl {
     if eat_word(p, "mut") {
-        /* TODO */
+        /* FIXME */
     }
     let lo = p.span.lo;
     let locals = [parse_local(p, true)];
@@ -2027,7 +2027,7 @@ enum class_contents { ctor_decl(ast::fn_decl, ast::blk),
         let body = parse_block(p);
         ret ctor_decl(decl, body);
     }
-    // TODO: refactor
+    // FIXME: refactor
     else if eat_word(p, "priv") {
             expect(p, token::LBRACE);
             let results = [];
diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs
index 7159d7310d6..2b29bf57eaa 100644
--- a/src/comp/syntax/print/pprust.rs
+++ b/src/comp/syntax/print/pprust.rs
@@ -8,7 +8,6 @@ import pp::{break_offset, word, printer,
 import driver::diagnostic;
 
 // The ps is stored here to prevent recursive type.
-// FIXME use a nominal enum instead
 enum ann_node {
     node_block(ps, ast::blk),
     node_item(ps, @ast::item),
@@ -357,7 +356,7 @@ fn print_type(s: ps, &&ty: @ast::ty) {
       ast::ty_constr(t, cs) {
         print_type(s, t);
         space(s.s);
-        word(s.s, ast_ty_constrs_str(cs));
+        word(s.s, constrs_str(cs, ty_constr_to_str));
       }
       ast::ty_mac(_) {
           fail "print_type doesn't know how to print a ty_mac";
@@ -482,7 +481,7 @@ fn print_item(s: ps, &&item: @ast::item) {
           print_block(s, ctor_body);
           for ci in items {
                   /*
-                     TODO: collect all private items and print them
+                     FIXME: collect all private items and print them
                      in a single "priv" section
                    */
              hardbreak_if_not_bol(s);
@@ -1249,7 +1248,10 @@ fn print_fn_args_and_ret(s: ps, decl: ast::fn_decl) {
     }
     commasep(s, inconsistent, decl.inputs, print_arg);
     pclose(s);
-    word(s.s, ast_fn_constrs_str(decl, decl.constraints));
+    word(s.s, constrs_str(decl.constraints, {|c|
+        ast_fn_constr_to_str(decl, c)
+    }));
+
     maybe_print_comment(s, decl.output.span.lo);
     if decl.output.node != ast::ty_nil {
         space_if_not_bol(s);
@@ -1479,7 +1481,7 @@ fn print_ty_fn(s: ps, opt_proto: option<ast::proto>,
         else { print_type(s, decl.output); }
         end(s);
     }
-    word(s.s, ast_ty_fn_constrs_str(decl.constraints));
+    word(s.s, constrs_str(decl.constraints, ast_ty_fn_constr_to_str));
     end(s);
 }
 
@@ -1684,8 +1686,6 @@ fn next_comment(s: ps) -> option<lexer::cmnt> {
     }
 }
 
-// Removing the aliases from the type of f in the next two functions
-// triggers memory corruption, but I haven't isolated the bug yet. FIXME
 fn constr_args_to_str<T>(f: fn@(T) -> str, args: [@ast::sp_constr_arg<T>]) ->
    str {
     let comma = false;
@@ -1712,43 +1712,38 @@ fn constr_arg_to_str<T>(f: fn@(T) -> str, c: ast::constr_arg_general_<T>) ->
 // (argh)
 fn uint_to_str(&&i: uint) -> str { ret uint::str(i); }
 
-fn ast_ty_fn_constr_to_str(c: @ast::constr) -> str {
+fn ast_ty_fn_constr_to_str(&&c: @ast::constr) -> str {
     ret path_to_str(c.node.path) +
             constr_args_to_str(uint_to_str, c.node.args);
 }
 
-// FIXME: fix repeated code
-fn ast_ty_fn_constrs_str(constrs: [@ast::constr]) -> str {
-    let s = "";
-    let colon = true;
-    for c: @ast::constr in constrs {
-        if colon { s += " : "; colon = false; } else { s += ", "; }
-        s += ast_ty_fn_constr_to_str(c);
-    }
-    ret s;
+fn ast_fn_constr_to_str(decl: ast::fn_decl, &&c: @ast::constr) -> str {
+    let arg_to_str = bind fn_arg_idx_to_str(decl, _);
+    ret path_to_str(c.node.path) +
+            constr_args_to_str(arg_to_str, c.node.args);
 }
 
-fn fn_arg_idx_to_str(decl: ast::fn_decl, &&idx: uint) -> str {
-    decl.inputs[idx].ident
-}
+fn ty_constr_to_str(&&c: @ast::ty_constr) -> str {
+    fn ty_constr_path_to_str(&&p: @ast::path) -> str { "*." + path_to_str(p) }
 
-fn ast_fn_constr_to_str(decl: ast::fn_decl, c: @ast::constr) -> str {
-    let arg_to_str = bind fn_arg_idx_to_str(decl, _);
     ret path_to_str(c.node.path) +
-            constr_args_to_str(arg_to_str, c.node.args);
+            constr_args_to_str::<@ast::path>(ty_constr_path_to_str,
+                                             c.node.args);
 }
 
-// FIXME: fix repeated code
-fn ast_fn_constrs_str(decl: ast::fn_decl, constrs: [@ast::constr]) -> str {
-    let s = "";
-    let colon = true;
-    for c: @ast::constr in constrs {
+fn constrs_str<T>(constrs: [T], elt: fn(T) -> str) -> str {
+    let s = "", colon = true;
+    for c in constrs {
         if colon { s += " : "; colon = false; } else { s += ", "; }
-        s += ast_fn_constr_to_str(decl, c);
+        s += elt(c);
     }
     ret s;
 }
 
+fn fn_arg_idx_to_str(decl: ast::fn_decl, &&idx: uint) -> str {
+    decl.inputs[idx].ident
+}
+
 fn opt_proto_to_str(opt_p: option<ast::proto>) -> str {
     alt opt_p {
       none { "fn" }
@@ -1766,25 +1761,6 @@ fn proto_to_str(p: ast::proto) -> str {
     };
 }
 
-fn ty_constr_to_str(c: @ast::ty_constr) -> str {
-    fn ty_constr_path_to_str(&&p: @ast::path) -> str { "*." + path_to_str(p) }
-
-    ret path_to_str(c.node.path) +
-            constr_args_to_str::<@ast::path>(ty_constr_path_to_str,
-                                             c.node.args);
-}
-
-
-fn ast_ty_constrs_str(constrs: [@ast::ty_constr]) -> str {
-    let s = "";
-    let colon = true;
-    for c: @ast::ty_constr in constrs {
-        if colon { s += " : "; colon = false; } else { s += ", "; }
-        s += ty_constr_to_str(c);
-    }
-    ret s;
-}
-
 fn ends_in_lit_int(ex: @ast::expr) -> bool {
     alt ex.node {
       ast::expr_lit(@{node: ast::lit_int(_, ast::ty_i), _}) { true }