Remove a bunch of primitive-compiler-workarounds from pprust.rs

This commit is contained in:
Marijn Haverbeke 2011-06-14 17:09:01 +02:00
parent 471436a299
commit fa2b4d3a8d
1 changed files with 23 additions and 41 deletions

View File

@ -164,9 +164,7 @@ fn commasep_cmnt[IN](&ps s, breaks b, vec[IN] elts, fn(&ps, &IN) op,
fn commasep_exprs(&ps s, breaks b, vec[@ast::expr] exprs) { fn commasep_exprs(&ps s, breaks b, vec[@ast::expr] exprs) {
fn expr_span(&@ast::expr expr) -> common::span {ret expr.span;} fn expr_span(&@ast::expr expr) -> common::span {ret expr.span;}
auto f = print_expr; commasep_cmnt(s, b, exprs, print_expr, expr_span);
auto gs = expr_span;
commasep_cmnt[@ast::expr](s, b, exprs, f, gs);
} }
fn print_mod(&ps s, ast::_mod _mod) { fn print_mod(&ps s, ast::_mod _mod) {
@ -210,8 +208,7 @@ fn print_type(&ps s, &ast::ty ty) {
case (ast::ty_tup(?elts)) { case (ast::ty_tup(?elts)) {
word(s.s, "tup"); word(s.s, "tup");
popen(s); popen(s);
auto f = print_mt; commasep(s, inconsistent, elts, print_mt);
commasep[ast::mt](s, inconsistent, elts, f);
pclose(s); pclose(s);
} }
case (ast::ty_rec(?fields)) { case (ast::ty_rec(?fields)) {
@ -227,9 +224,7 @@ fn print_type(&ps s, &ast::ty ty) {
fn get_span(&ast::ty_field f) -> common::span { fn get_span(&ast::ty_field f) -> common::span {
ret f.span; ret f.span;
} }
auto f = print_field; commasep_cmnt(s, consistent, fields, print_field, get_span);
auto gs = get_span;
commasep_cmnt[ast::ty_field](s, consistent, fields, f, gs);
pclose(s); pclose(s);
} }
case (ast::ty_obj(?methods)) { case (ast::ty_obj(?methods)) {
@ -346,13 +341,12 @@ fn print_item(&ps s, &@ast::item item) {
space(s.s); space(s.s);
maybe_print_comment(s, v.span.lo); maybe_print_comment(s, v.span.lo);
word(s.s, v.node.name); word(s.s, v.node.name);
if (vec::len[ast::variant_arg](v.node.args) > 0u) { if (vec::len(v.node.args) > 0u) {
popen(s); popen(s);
fn print_variant_arg(&ps s, &ast::variant_arg arg) { fn print_variant_arg(&ps s, &ast::variant_arg arg) {
print_type(s, *arg.ty); print_type(s, *arg.ty);
} }
auto f = print_variant_arg; commasep(s, consistent, v.node.args, print_variant_arg);
commasep[ast::variant_arg](s, consistent, v.node.args, f);
pclose(s); pclose(s);
} }
word(s.s, ";"); word(s.s, ";");
@ -373,9 +367,7 @@ fn print_item(&ps s, &@ast::item item) {
end(s); end(s);
} }
fn get_span(&ast::obj_field f) -> common::span {ret f.ty.span;} fn get_span(&ast::obj_field f) -> common::span {ret f.ty.span;}
auto f = print_field; commasep_cmnt(s, consistent, _obj.fields, print_field, get_span);
auto gs = get_span;
commasep_cmnt[ast::obj_field](s, consistent, _obj.fields, f, gs);
pclose(s); pclose(s);
space(s.s); space(s.s);
bopen(s); bopen(s);
@ -488,9 +480,7 @@ fn print_expr(&ps s, &@ast::expr expr) {
fn get_span(&ast::elt elt) -> common::span {ret elt.expr.span;} fn get_span(&ast::elt elt) -> common::span {ret elt.expr.span;}
word(s.s, "tup"); word(s.s, "tup");
popen(s); popen(s);
auto f = printElt; commasep_cmnt(s, inconsistent, exprs, printElt, get_span);
auto gs = get_span;
commasep_cmnt[ast::elt](s, inconsistent, exprs, f, gs);
pclose(s); pclose(s);
} }
case (ast::expr_rec(?fields,?wth,_)) { case (ast::expr_rec(?fields,?wth,_)) {
@ -507,12 +497,10 @@ fn print_expr(&ps s, &@ast::expr expr) {
} }
word(s.s, "rec"); word(s.s, "rec");
popen(s); popen(s);
auto f = print_field; commasep_cmnt(s, consistent, fields, print_field, get_span);
auto gs = get_span;
commasep_cmnt[ast::field](s, consistent, fields, f, gs);
alt (wth) { alt (wth) {
case (some(?expr)) { case (some(?expr)) {
if (vec::len[ast::field](fields) > 0u) {space(s.s);} if (vec::len(fields) > 0u) {space(s.s);}
ibox(s, indent_unit); ibox(s, indent_unit);
word_space(s, "with"); word_space(s, "with");
print_expr(s, expr); print_expr(s, expr);
@ -544,8 +532,7 @@ fn print_expr(&ps s, &@ast::expr expr) {
word_nbsp(s, "bind"); word_nbsp(s, "bind");
print_expr(s, func); print_expr(s, func);
popen(s); popen(s);
auto f = print_opt; commasep(s, inconsistent, args, print_opt);
commasep[option::t[@ast::expr]](s, inconsistent, args, f);
pclose(s); pclose(s);
} }
case (ast::expr_spawn(_,_,?e,?es,_)) { case (ast::expr_spawn(_,_,?e,?es,_)) {
@ -792,7 +779,7 @@ fn print_expr(&ps s, &@ast::expr expr) {
case (ast::expr_ext(?path, ?args, ?body, _, _)) { case (ast::expr_ext(?path, ?args, ?body, _, _)) {
word(s.s, "#"); word(s.s, "#");
print_path(s, path); print_path(s, path);
if (vec::len[@ast::expr](args) > 0u) { if (vec::len(args) > 0u) {
popen(s); popen(s);
commasep_exprs(s, inconsistent, args); commasep_exprs(s, inconsistent, args);
pclose(s); pclose(s);
@ -896,7 +883,7 @@ fn print_ident(&ps s, &ast::ident ident) {
} }
fn print_for_decl(&ps s, @ast::local loc) { fn print_for_decl(&ps s, @ast::local loc) {
print_type(s, *option::get[@ast::ty](loc.node.ty)); print_type(s, *option::get(loc.node.ty));
space(s.s); space(s.s);
word(s.s, loc.node.ident); word(s.s, loc.node.ident);
} }
@ -909,10 +896,9 @@ fn print_path(&ps s, &ast::path path) {
else {word(s.s, "::");} else {word(s.s, "::");}
word(s.s, id); word(s.s, id);
} }
if (vec::len[@ast::ty](path.node.types) > 0u) { if (vec::len(path.node.types) > 0u) {
word(s.s, "["); word(s.s, "[");
auto f = print_boxed_type; commasep(s, inconsistent, path.node.types, print_boxed_type);
commasep[@ast::ty](s, inconsistent, path.node.types, f);
word(s.s, "]"); word(s.s, "]");
} }
} }
@ -925,10 +911,9 @@ fn print_pat(&ps s, &@ast::pat pat) {
case (ast::pat_lit(?lit,_)) {print_literal(s, lit);} case (ast::pat_lit(?lit,_)) {print_literal(s, lit);}
case (ast::pat_tag(?path,?args,_)) { case (ast::pat_tag(?path,?args,_)) {
print_path(s, path); print_path(s, path);
if (vec::len[@ast::pat](args) > 0u) { if (vec::len(args) > 0u) {
popen(s); popen(s);
auto f = print_pat; commasep(s, inconsistent, args, print_pat);
commasep[@ast::pat](s, inconsistent, args, f);
pclose(s); pclose(s);
} }
} }
@ -973,7 +958,7 @@ fn print_fn_args_and_ret(&ps s, &ast::fn_decl decl) {
word(s.s, x.ident); word(s.s, x.ident);
end(s); end(s);
} }
commasep[ast::arg](s, inconsistent, decl.inputs, print_arg); commasep(s, inconsistent, decl.inputs, print_arg);
pclose(s); pclose(s);
maybe_print_comment(s, decl.output.span.lo); maybe_print_comment(s, decl.output.span.lo);
if (decl.output.node != ast::ty_nil) { if (decl.output.node != ast::ty_nil) {
@ -992,13 +977,12 @@ fn print_alias(&ps s, ast::mode m) {
} }
fn print_type_params(&ps s, &vec[ast::ty_param] params) { fn print_type_params(&ps s, &vec[ast::ty_param] params) {
if (vec::len[ast::ty_param](params) > 0u) { if (vec::len(params) > 0u) {
word(s.s, "["); word(s.s, "[");
fn printParam(&ps s, &ast::ty_param param) { fn printParam(&ps s, &ast::ty_param param) {
word(s.s, param); word(s.s, param);
} }
auto f = printParam; commasep(s, inconsistent, params, printParam);
commasep[ast::ty_param](s, inconsistent, params, f);
word(s.s, "]"); word(s.s, "]");
} }
} }
@ -1010,7 +994,7 @@ fn print_view_item(&ps s, &@ast::view_item item) {
case (ast::view_item_use(?id,?mta,_,_)) { case (ast::view_item_use(?id,?mta,_,_)) {
head(s, "use"); head(s, "use");
word(s.s, id); word(s.s, id);
if (vec::len[@ast::meta_item](mta) > 0u) { if (vec::len(mta) > 0u) {
popen(s); popen(s);
fn print_meta(&ps s, &@ast::meta_item item) { fn print_meta(&ps s, &@ast::meta_item item) {
ibox(s, indent_unit); ibox(s, indent_unit);
@ -1019,14 +1003,13 @@ fn print_view_item(&ps s, &@ast::view_item item) {
print_string(s, item.node.value); print_string(s, item.node.value);
end(s); end(s);
} }
auto f = print_meta; commasep(s, consistent, mta, print_meta);
commasep[@ast::meta_item](s, consistent, mta, f);
pclose(s); pclose(s);
} }
} }
case (ast::view_item_import(?id,?ids,_)) { case (ast::view_item_import(?id,?ids,_)) {
head(s, "import"); head(s, "import");
if (!str::eq(id, ids.(vec::len[str](ids)-1u))) { if (!str::eq(id, ids.(vec::len(ids)-1u))) {
word_space(s, id); word_space(s, id);
word_space(s, "="); word_space(s, "=");
} }
@ -1112,8 +1095,7 @@ fn print_ty_fn(&ps s, &ast::proto proto, &option::t[str] id,
print_alias(s, input.node.mode); print_alias(s, input.node.mode);
print_type(s, *input.node.ty); print_type(s, *input.node.ty);
} }
auto f = print_arg; commasep(s, inconsistent, inputs, print_arg);
commasep[ast::ty_arg](s, inconsistent, inputs, f);
pclose(s); pclose(s);
maybe_print_comment(s, output.span.lo); maybe_print_comment(s, output.span.lo);
if (output.node != ast::ty_nil) { if (output.node != ast::ty_nil) {