2012-04-15 10:27:24 +00:00
|
|
|
import parse::comments;
|
2011-07-05 09:48:19 +00:00
|
|
|
import parse::lexer;
|
2012-03-23 01:01:08 +00:00
|
|
|
import codemap::codemap;
|
2012-01-13 08:32:05 +00:00
|
|
|
import pp::{break_offset, word, printer,
|
2011-09-12 23:13:28 +00:00
|
|
|
space, zerobreak, hardbreak, breaks, consistent,
|
|
|
|
inconsistent, eof};
|
2012-03-23 01:01:08 +00:00
|
|
|
import diagnostic;
|
2012-07-10 20:44:20 +00:00
|
|
|
import ast::{required, provided};
|
2012-08-01 23:16:53 +00:00
|
|
|
import ast_util::{operator_prec};
|
2012-08-08 01:10:06 +00:00
|
|
|
import dvec::dvec;
|
2012-05-22 17:54:12 +00:00
|
|
|
import parse::classify::*;
|
2012-07-17 18:22:11 +00:00
|
|
|
import util::interner;
|
2011-05-31 17:58:30 +00:00
|
|
|
|
2012-08-07 00:50:45 +00:00
|
|
|
type ident_interner = @interner::interner<@~str>;
|
|
|
|
|
2011-07-05 09:48:19 +00:00
|
|
|
// The ps is stored here to prevent recursive type.
|
2012-01-19 22:24:03 +00:00
|
|
|
enum ann_node {
|
2012-01-20 01:56:05 +00:00
|
|
|
node_block(ps, ast::blk),
|
|
|
|
node_item(ps, @ast::item),
|
|
|
|
node_expr(ps, @ast::expr),
|
|
|
|
node_pat(ps, @ast::pat),
|
2011-07-05 09:48:19 +00:00
|
|
|
}
|
2011-10-18 22:07:40 +00:00
|
|
|
type pp_ann = {pre: fn@(ann_node), post: fn@(ann_node)};
|
2011-07-05 09:48:19 +00:00
|
|
|
|
|
|
|
fn no_ann() -> pp_ann {
|
2011-09-12 09:27:30 +00:00
|
|
|
fn ignore(_node: ann_node) { }
|
2012-08-02 00:30:05 +00:00
|
|
|
return {pre: ignore, post: ignore};
|
2011-07-05 09:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type ps =
|
2011-07-27 12:19:39 +00:00
|
|
|
@{s: pp::printer,
|
2012-02-01 01:05:20 +00:00
|
|
|
cm: option<codemap>,
|
2012-07-27 21:21:15 +00:00
|
|
|
intr: @interner::interner<@~str>,
|
2012-06-29 23:26:56 +00:00
|
|
|
comments: option<~[comments::cmnt]>,
|
|
|
|
literals: option<~[comments::lit]>,
|
2012-03-27 01:35:18 +00:00
|
|
|
mut cur_cmnt: uint,
|
|
|
|
mut cur_lit: uint,
|
2012-05-10 14:24:56 +00:00
|
|
|
boxes: dvec<pp::breaks>,
|
2011-07-27 12:19:39 +00:00
|
|
|
ann: pp_ann};
|
2011-07-05 09:48:19 +00:00
|
|
|
|
2012-05-10 14:24:56 +00:00
|
|
|
fn ibox(s: ps, u: uint) {
|
|
|
|
s.boxes.push(pp::inconsistent);
|
|
|
|
pp::ibox(s.s, u);
|
|
|
|
}
|
2011-07-05 09:48:19 +00:00
|
|
|
|
2012-05-10 14:24:56 +00:00
|
|
|
fn end(s: ps) {
|
|
|
|
s.boxes.pop();
|
|
|
|
pp::end(s.s);
|
|
|
|
}
|
2011-07-05 09:48:19 +00:00
|
|
|
|
2011-08-12 02:14:38 +00:00
|
|
|
fn rust_printer(writer: io::writer) -> ps {
|
2012-08-02 00:30:05 +00:00
|
|
|
return @{s: pp::mk_printer(writer, default_columns),
|
2012-08-07 00:50:45 +00:00
|
|
|
cm: none::<codemap>,
|
|
|
|
intr: @interner::mk::<@~str>(|x| str::hash(*x),
|
|
|
|
|x,y| str::eq(*x, *y)),
|
|
|
|
comments: none::<~[comments::cmnt]>,
|
|
|
|
literals: none::<~[comments::lit]>,
|
|
|
|
mut cur_cmnt: 0u,
|
|
|
|
mut cur_lit: 0u,
|
|
|
|
boxes: dvec(),
|
|
|
|
ann: no_ann()};
|
|
|
|
}
|
|
|
|
|
|
|
|
fn unexpanded_rust_printer(writer: io::writer, intr: ident_interner) -> ps {
|
|
|
|
return @{s: pp::mk_printer(writer, default_columns),
|
|
|
|
cm: none::<codemap>,
|
|
|
|
intr: intr,
|
|
|
|
comments: none::<~[comments::cmnt]>,
|
|
|
|
literals: none::<~[comments::lit]>,
|
|
|
|
mut cur_cmnt: 0u,
|
|
|
|
mut cur_lit: 0u,
|
|
|
|
boxes: dvec(),
|
|
|
|
ann: no_ann()};
|
2011-07-05 09:48:19 +00:00
|
|
|
}
|
|
|
|
|
2011-07-27 12:19:39 +00:00
|
|
|
const indent_unit: uint = 4u;
|
|
|
|
const alt_indent_unit: uint = 2u;
|
2011-07-05 09:48:19 +00:00
|
|
|
|
2011-07-27 12:19:39 +00:00
|
|
|
const default_columns: uint = 78u;
|
2011-07-05 09:48:19 +00:00
|
|
|
|
2011-07-25 21:04:38 +00:00
|
|
|
// Requires you to pass an input filename and reader so that
|
|
|
|
// it can scan the input text for comments and literals to
|
|
|
|
// copy forward.
|
2012-07-27 21:21:15 +00:00
|
|
|
fn print_crate(cm: codemap, intr: @interner::interner<@~str>,
|
2012-07-17 18:22:11 +00:00
|
|
|
span_diagnostic: diagnostic::span_handler,
|
2012-07-14 05:57:48 +00:00
|
|
|
crate: @ast::crate, filename: ~str, in: io::reader,
|
2012-06-28 22:29:15 +00:00
|
|
|
out: io::writer, ann: pp_ann, is_expanded: bool) {
|
2012-04-15 10:57:24 +00:00
|
|
|
let r = comments::gather_comments_and_literals(span_diagnostic,
|
2012-04-15 10:27:24 +00:00
|
|
|
filename, in);
|
2011-07-27 12:19:39 +00:00
|
|
|
let s =
|
|
|
|
@{s: pp::mk_printer(out, default_columns),
|
|
|
|
cm: some(cm),
|
2012-07-27 21:21:15 +00:00
|
|
|
intr: intr,
|
2011-07-27 12:19:39 +00:00
|
|
|
comments: some(r.cmnts),
|
2012-06-28 22:29:15 +00:00
|
|
|
// If the code is post expansion, don't use the table of
|
|
|
|
// literals, since it doesn't correspond with the literals
|
|
|
|
// in the AST anymore.
|
|
|
|
literals: if is_expanded { none } else { some(r.lits) },
|
2012-03-27 01:35:18 +00:00
|
|
|
mut cur_cmnt: 0u,
|
|
|
|
mut cur_lit: 0u,
|
2012-05-10 14:24:56 +00:00
|
|
|
boxes: dvec(),
|
2011-07-27 12:19:39 +00:00
|
|
|
ann: ann};
|
2012-02-21 23:34:26 +00:00
|
|
|
print_crate_(s, crate);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn print_crate_(s: ps, &&crate: @ast::crate) {
|
2011-06-30 23:03:07 +00:00
|
|
|
print_mod(s, crate.node.module, crate.node.attrs);
|
2011-07-05 21:34:34 +00:00
|
|
|
print_remaining_comments(s);
|
2011-05-29 02:16:18 +00:00
|
|
|
eof(s.s);
|
2011-03-04 06:22:43 +00:00
|
|
|
}
|
|
|
|
|
2012-08-02 00:30:05 +00:00
|
|
|
fn ty_to_str(ty: @ast::ty) -> ~str { return to_str(ty, print_type); }
|
2011-06-15 18:19:50 +00:00
|
|
|
|
2012-08-02 00:30:05 +00:00
|
|
|
fn pat_to_str(pat: @ast::pat) -> ~str { return to_str(pat, print_pat); }
|
2011-06-15 18:19:50 +00:00
|
|
|
|
2012-08-02 00:30:05 +00:00
|
|
|
fn expr_to_str(e: @ast::expr) -> ~str { return to_str(e, print_expr); }
|
2011-06-15 18:19:50 +00:00
|
|
|
|
2012-08-07 00:50:45 +00:00
|
|
|
fn unexpanded_tt_to_str(tt: ast::token_tree, intr: ident_interner)
|
|
|
|
-> ~str {
|
|
|
|
let buffer = io::mem_buffer();
|
|
|
|
let s = unexpanded_rust_printer(io::mem_buffer_writer(buffer), intr);
|
|
|
|
print_tt(s, tt);
|
|
|
|
eof(s.s);
|
|
|
|
io::mem_buffer_str(buffer)
|
|
|
|
}
|
|
|
|
|
2012-08-02 00:30:05 +00:00
|
|
|
fn stmt_to_str(s: ast::stmt) -> ~str { return to_str(s, print_stmt); }
|
2011-06-15 18:19:50 +00:00
|
|
|
|
2012-08-02 00:30:05 +00:00
|
|
|
fn item_to_str(i: @ast::item) -> ~str { return to_str(i, print_item); }
|
2011-06-15 18:19:50 +00:00
|
|
|
|
2012-08-02 00:30:05 +00:00
|
|
|
fn attr_to_str(i: ast::attribute) -> ~str {
|
|
|
|
return to_str(i, print_attribute);
|
|
|
|
}
|
2012-02-14 23:21:53 +00:00
|
|
|
|
2012-07-14 05:57:48 +00:00
|
|
|
fn typarams_to_str(tps: ~[ast::ty_param]) -> ~str {
|
2012-08-02 00:30:05 +00:00
|
|
|
return to_str(tps, print_type_params)
|
2012-02-02 06:41:41 +00:00
|
|
|
}
|
|
|
|
|
2012-07-14 05:57:48 +00:00
|
|
|
fn path_to_str(&&p: @ast::path) -> ~str {
|
2012-08-02 00:30:05 +00:00
|
|
|
return to_str(p, |a,b| print_path(a, b, false));
|
2011-08-16 16:03:58 +00:00
|
|
|
}
|
2011-05-31 17:58:30 +00:00
|
|
|
|
2011-12-22 16:49:54 +00:00
|
|
|
fn fun_to_str(decl: ast::fn_decl, name: ast::ident,
|
2012-07-14 05:57:48 +00:00
|
|
|
params: ~[ast::ty_param]) -> ~str {
|
2012-03-13 14:55:45 +00:00
|
|
|
let buffer = io::mem_buffer();
|
2012-01-11 14:15:54 +00:00
|
|
|
let s = rust_printer(io::mem_buffer_writer(buffer));
|
2012-08-02 23:01:38 +00:00
|
|
|
print_fn(s, decl, name, params, none);
|
2012-01-20 02:09:06 +00:00
|
|
|
end(s); // Close the head box
|
|
|
|
end(s); // Close the outer box
|
2011-05-29 02:16:18 +00:00
|
|
|
eof(s.s);
|
2012-01-11 14:15:54 +00:00
|
|
|
io::mem_buffer_str(buffer)
|
2011-03-09 10:41:50 +00:00
|
|
|
}
|
|
|
|
|
2012-01-20 02:09:06 +00:00
|
|
|
#[test]
|
|
|
|
fn test_fun_to_str() {
|
|
|
|
let decl: ast::fn_decl = {
|
2012-06-29 23:26:56 +00:00
|
|
|
inputs: ~[],
|
2012-03-12 23:26:31 +00:00
|
|
|
output: @{id: 0,
|
|
|
|
node: ast::ty_nil,
|
|
|
|
span: ast_util::dummy_sp()},
|
2012-01-20 02:09:06 +00:00
|
|
|
purity: ast::impure_fn,
|
2012-07-14 01:43:52 +00:00
|
|
|
cf: ast::return_val
|
2012-01-20 02:09:06 +00:00
|
|
|
};
|
2012-06-29 23:26:56 +00:00
|
|
|
assert fun_to_str(decl, "a", ~[]) == "fn a()";
|
2012-01-20 02:09:06 +00:00
|
|
|
}
|
|
|
|
|
2012-07-14 05:57:48 +00:00
|
|
|
fn block_to_str(blk: ast::blk) -> ~str {
|
2012-03-13 14:55:45 +00:00
|
|
|
let buffer = io::mem_buffer();
|
2012-01-11 14:15:54 +00:00
|
|
|
let s = rust_printer(io::mem_buffer_writer(buffer));
|
2011-05-31 16:54:18 +00:00
|
|
|
// containing cbox, will be closed by print-block at }
|
2011-06-15 18:19:50 +00:00
|
|
|
cbox(s, indent_unit);
|
2011-05-31 16:54:18 +00:00
|
|
|
// head-ibox, will be closed by print-block after {
|
2011-06-01 22:29:38 +00:00
|
|
|
ibox(s, 0u);
|
2011-04-01 00:29:59 +00:00
|
|
|
print_block(s, blk);
|
2011-05-29 02:16:18 +00:00
|
|
|
eof(s.s);
|
2012-01-11 14:15:54 +00:00
|
|
|
io::mem_buffer_str(buffer)
|
2011-04-01 00:29:59 +00:00
|
|
|
}
|
|
|
|
|
2012-07-14 05:57:48 +00:00
|
|
|
fn meta_item_to_str(mi: ast::meta_item) -> ~str {
|
2012-08-02 00:30:05 +00:00
|
|
|
return to_str(@mi, print_meta_item);
|
2011-06-28 01:32:15 +00:00
|
|
|
}
|
|
|
|
|
2012-07-14 05:57:48 +00:00
|
|
|
fn attribute_to_str(attr: ast::attribute) -> ~str {
|
2012-08-02 00:30:05 +00:00
|
|
|
return to_str(attr, print_attribute);
|
2011-06-28 02:41:48 +00:00
|
|
|
}
|
|
|
|
|
2012-07-14 05:57:48 +00:00
|
|
|
fn variant_to_str(var: ast::variant) -> ~str {
|
2012-08-02 00:30:05 +00:00
|
|
|
return to_str(var, print_variant);
|
2012-01-26 01:22:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_variant_to_str() {
|
|
|
|
let var = ast_util::respan(ast_util::dummy_sp(), {
|
|
|
|
name: "principle_skinner",
|
2012-06-29 23:26:56 +00:00
|
|
|
attrs: ~[],
|
|
|
|
args: ~[],
|
2012-01-26 01:22:08 +00:00
|
|
|
id: 0,
|
|
|
|
disr_expr: none
|
|
|
|
});
|
|
|
|
|
|
|
|
let varstr = variant_to_str(var);
|
|
|
|
assert varstr == "principle_skinner";
|
|
|
|
}
|
|
|
|
|
2012-05-10 14:24:56 +00:00
|
|
|
fn cbox(s: ps, u: uint) {
|
|
|
|
s.boxes.push(pp::consistent);
|
|
|
|
pp::cbox(s.s, u);
|
|
|
|
}
|
2011-06-01 22:29:38 +00:00
|
|
|
|
2012-05-10 14:24:56 +00:00
|
|
|
fn box(s: ps, u: uint, b: pp::breaks) {
|
|
|
|
s.boxes.push(b);
|
|
|
|
pp::box(s.s, u, b);
|
|
|
|
}
|
2011-06-01 22:29:38 +00:00
|
|
|
|
2012-07-14 05:57:48 +00:00
|
|
|
fn nbsp(s: ps) { word(s.s, ~" "); }
|
2011-07-26 22:58:43 +00:00
|
|
|
|
2012-07-14 05:57:48 +00:00
|
|
|
fn word_nbsp(s: ps, w: ~str) { word(s.s, w); nbsp(s); }
|
2011-05-29 02:16:18 +00:00
|
|
|
|
2012-07-14 05:57:48 +00:00
|
|
|
fn word_space(s: ps, w: ~str) { word(s.s, w); space(s.s); }
|
2011-05-29 02:16:18 +00:00
|
|
|
|
2012-07-14 05:57:48 +00:00
|
|
|
fn popen(s: ps) { word(s.s, ~"("); }
|
2011-05-29 02:16:18 +00:00
|
|
|
|
2012-07-14 05:57:48 +00:00
|
|
|
fn pclose(s: ps) { word(s.s, ~")"); }
|
2011-05-29 02:16:18 +00:00
|
|
|
|
2012-07-14 05:57:48 +00:00
|
|
|
fn head(s: ps, w: ~str) {
|
2011-05-29 02:16:18 +00:00
|
|
|
// outer-box is consistent
|
2011-06-01 22:29:38 +00:00
|
|
|
cbox(s, indent_unit);
|
2011-05-29 02:16:18 +00:00
|
|
|
// head-box is inconsistent
|
2012-07-17 02:16:19 +00:00
|
|
|
ibox(s, str::len(w) + 1);
|
2011-05-29 02:16:18 +00:00
|
|
|
// keyword that starts the head
|
2011-05-30 21:10:54 +00:00
|
|
|
word_nbsp(s, w);
|
2011-05-29 02:16:18 +00:00
|
|
|
}
|
|
|
|
|
2011-09-12 09:27:30 +00:00
|
|
|
fn bopen(s: ps) {
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~"{");
|
2011-06-01 22:29:38 +00:00
|
|
|
end(s); // close the head-box
|
2011-03-24 15:33:20 +00:00
|
|
|
}
|
2011-05-29 02:16:18 +00:00
|
|
|
|
2011-09-12 09:27:30 +00:00
|
|
|
fn bclose_(s: ps, span: codemap::span, indented: uint) {
|
2011-03-24 15:33:20 +00:00
|
|
|
maybe_print_comment(s, span.hi);
|
2011-07-26 22:37:05 +00:00
|
|
|
break_offset_if_not_bol(s, 1u, -(indented as int));
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~"}");
|
2011-06-01 22:29:38 +00:00
|
|
|
end(s); // close the outer-box
|
2011-07-21 13:36:41 +00:00
|
|
|
}
|
2011-09-12 09:27:30 +00:00
|
|
|
fn bclose(s: ps, span: codemap::span) { bclose_(s, span, indent_unit); }
|
2011-05-29 02:16:18 +00:00
|
|
|
|
2011-09-12 09:27:30 +00:00
|
|
|
fn is_begin(s: ps) -> bool {
|
2012-08-06 19:34:08 +00:00
|
|
|
match s.s.last_token() { pp::BEGIN(_) => true, _ => false }
|
2011-08-02 22:25:06 +00:00
|
|
|
}
|
|
|
|
|
2011-09-12 09:27:30 +00:00
|
|
|
fn is_end(s: ps) -> bool {
|
2012-08-06 19:34:08 +00:00
|
|
|
match s.s.last_token() { pp::END => true, _ => false }
|
2011-08-02 22:25:06 +00:00
|
|
|
}
|
|
|
|
|
2011-09-12 09:27:30 +00:00
|
|
|
fn is_bol(s: ps) -> bool {
|
2012-08-02 00:30:05 +00:00
|
|
|
return s.s.last_token() == pp::EOF ||
|
2011-08-19 22:16:48 +00:00
|
|
|
s.s.last_token() == pp::hardbreak_tok();
|
2011-06-20 14:45:05 +00:00
|
|
|
}
|
|
|
|
|
2012-04-19 21:46:11 +00:00
|
|
|
fn in_cbox(s: ps) -> bool {
|
2012-05-10 14:24:56 +00:00
|
|
|
let len = s.boxes.len();
|
2012-08-02 00:30:05 +00:00
|
|
|
if len == 0u { return false; }
|
|
|
|
return s.boxes[len - 1u] == pp::consistent;
|
2012-04-19 21:46:11 +00:00
|
|
|
}
|
|
|
|
|
2011-09-12 09:27:30 +00:00
|
|
|
fn hardbreak_if_not_bol(s: ps) { if !is_bol(s) { hardbreak(s.s); } }
|
|
|
|
fn space_if_not_bol(s: ps) { if !is_bol(s) { space(s.s); } }
|
|
|
|
fn break_offset_if_not_bol(s: ps, n: uint, off: int) {
|
2011-07-27 12:19:39 +00:00
|
|
|
if !is_bol(s) {
|
2011-07-26 22:37:05 +00:00
|
|
|
break_offset(s.s, n, off);
|
|
|
|
} else {
|
2011-07-27 12:19:39 +00:00
|
|
|
if off != 0 && s.s.last_token() == pp::hardbreak_tok() {
|
2011-07-26 22:37:05 +00:00
|
|
|
// We do something pretty sketchy here: tuck the nonzero
|
|
|
|
// offset-adjustment we were going to deposit along with the
|
|
|
|
// break into the previous hardbreak.
|
|
|
|
s.s.replace_last_token(pp::hardbreak_tok_offset(off));
|
|
|
|
}
|
2011-06-20 02:55:28 +00:00
|
|
|
}
|
|
|
|
}
|
2011-06-15 18:19:50 +00:00
|
|
|
|
2011-06-02 01:53:52 +00:00
|
|
|
// Synthesizes a comment that was not textually present in the original source
|
|
|
|
// file.
|
2012-07-14 05:57:48 +00:00
|
|
|
fn synth_comment(s: ps, text: ~str) {
|
|
|
|
word(s.s, ~"/*");
|
2011-06-02 01:53:52 +00:00
|
|
|
space(s.s);
|
|
|
|
word(s.s, text);
|
|
|
|
space(s.s);
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~"*/");
|
2011-06-02 01:53:52 +00:00
|
|
|
}
|
|
|
|
|
2012-06-29 23:26:56 +00:00
|
|
|
fn commasep<IN>(s: ps, b: breaks, elts: ~[IN], op: fn(ps, IN)) {
|
2011-07-05 23:23:07 +00:00
|
|
|
box(s, 0u, b);
|
2012-03-15 13:47:03 +00:00
|
|
|
let mut first = true;
|
2012-06-30 23:19:07 +00:00
|
|
|
for elts.each |elt| {
|
2012-07-14 05:57:48 +00:00
|
|
|
if first { first = false; } else { word_space(s, ~","); }
|
2011-07-05 23:23:07 +00:00
|
|
|
op(s, elt);
|
|
|
|
}
|
|
|
|
end(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-29 23:26:56 +00:00
|
|
|
fn commasep_cmnt<IN>(s: ps, b: breaks, elts: ~[IN], op: fn(ps, IN),
|
2012-01-23 22:59:00 +00:00
|
|
|
get_span: fn(IN) -> codemap::span) {
|
2011-06-01 22:29:38 +00:00
|
|
|
box(s, 0u, b);
|
2011-08-13 07:09:25 +00:00
|
|
|
let len = vec::len::<IN>(elts);
|
2012-03-15 13:47:03 +00:00
|
|
|
let mut i = 0u;
|
2012-06-30 23:19:07 +00:00
|
|
|
for elts.each |elt| {
|
2011-07-06 23:01:47 +00:00
|
|
|
maybe_print_comment(s, get_span(elt).hi);
|
|
|
|
op(s, elt);
|
|
|
|
i += 1u;
|
2011-07-27 12:19:39 +00:00
|
|
|
if i < len {
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~",");
|
2011-07-06 23:01:47 +00:00
|
|
|
maybe_print_trailing_comment(s, get_span(elt),
|
2011-08-19 22:16:48 +00:00
|
|
|
some(get_span(elts[i]).hi));
|
2011-07-26 22:37:05 +00:00
|
|
|
space_if_not_bol(s);
|
2011-07-06 23:01:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
end(s);
|
|
|
|
}
|
|
|
|
|
2012-06-29 23:26:56 +00:00
|
|
|
fn commasep_exprs(s: ps, b: breaks, exprs: ~[@ast::expr]) {
|
2012-08-02 00:30:05 +00:00
|
|
|
fn expr_span(&&expr: @ast::expr) -> codemap::span { return expr.span; }
|
2011-07-12 23:13:30 +00:00
|
|
|
commasep_cmnt(s, b, exprs, print_expr, expr_span);
|
2011-03-29 10:46:55 +00:00
|
|
|
}
|
2011-03-04 06:22:43 +00:00
|
|
|
|
2012-06-29 23:26:56 +00:00
|
|
|
fn print_mod(s: ps, _mod: ast::_mod, attrs: ~[ast::attribute]) {
|
2011-06-30 23:03:07 +00:00
|
|
|
print_inner_attributes(s, attrs);
|
2012-06-30 23:19:07 +00:00
|
|
|
for _mod.view_items.each |vitem| {
|
2011-05-12 15:24:54 +00:00
|
|
|
print_view_item(s, vitem);
|
|
|
|
}
|
2012-06-30 23:19:07 +00:00
|
|
|
for _mod.items.each |item| { print_item(s, item); }
|
2011-03-18 00:39:47 +00:00
|
|
|
}
|
|
|
|
|
2012-06-26 23:18:37 +00:00
|
|
|
fn print_foreign_mod(s: ps, nmod: ast::foreign_mod,
|
2012-06-29 23:26:56 +00:00
|
|
|
attrs: ~[ast::attribute]) {
|
2011-07-26 22:37:36 +00:00
|
|
|
print_inner_attributes(s, attrs);
|
2012-06-30 23:19:07 +00:00
|
|
|
for nmod.view_items.each |vitem| {
|
2011-07-26 22:37:36 +00:00
|
|
|
print_view_item(s, vitem);
|
|
|
|
}
|
2012-06-30 23:19:07 +00:00
|
|
|
for nmod.items.each |item| { print_foreign_item(s, item); }
|
2011-07-26 22:37:36 +00:00
|
|
|
}
|
|
|
|
|
2012-04-24 22:52:52 +00:00
|
|
|
fn print_region(s: ps, region: @ast::region) {
|
2012-08-06 19:34:08 +00:00
|
|
|
match region.node {
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::re_anon => word_space(s, ~"&"),
|
|
|
|
ast::re_named(name) => {
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~"&");
|
2012-07-12 23:24:22 +00:00
|
|
|
word(s.s, *name);
|
2012-04-24 22:52:52 +00:00
|
|
|
}
|
2012-03-09 02:10:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-06 10:26:12 +00:00
|
|
|
fn print_type(s: ps, &&ty: @ast::ty) {
|
2012-05-15 21:51:33 +00:00
|
|
|
print_type_ex(s, ty, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn print_type_ex(s: ps, &&ty: @ast::ty, print_colons: bool) {
|
2011-03-24 15:33:20 +00:00
|
|
|
maybe_print_comment(s, ty.span.lo);
|
2011-06-01 22:29:38 +00:00
|
|
|
ibox(s, 0u);
|
2012-08-06 19:34:08 +00:00
|
|
|
match ty.node {
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::ty_nil => word(s.s, ~"()"),
|
|
|
|
ast::ty_bot => word(s.s, ~"!"),
|
|
|
|
ast::ty_box(mt) => { word(s.s, ~"@"); print_mt(s, mt); }
|
|
|
|
ast::ty_uniq(mt) => { word(s.s, ~"~"); print_mt(s, mt); }
|
|
|
|
ast::ty_vec(mt) => {
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~"[");
|
2012-08-06 19:34:08 +00:00
|
|
|
match mt.mutbl {
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::m_mutbl => word_space(s, ~"mut"),
|
|
|
|
ast::m_const => word_space(s, ~"const"),
|
|
|
|
ast::m_imm => ()
|
2011-07-27 19:20:51 +00:00
|
|
|
}
|
2011-08-15 11:45:04 +00:00
|
|
|
print_type(s, mt.ty);
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~"]");
|
2011-07-27 12:19:39 +00:00
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::ty_ptr(mt) => { word(s.s, ~"*"); print_mt(s, mt); }
|
|
|
|
ast::ty_rptr(region, mt) => {
|
2012-08-06 19:34:08 +00:00
|
|
|
match region.node {
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::re_anon => word(s.s, ~"&"),
|
|
|
|
_ => { print_region(s, region); word(s.s, ~"/"); }
|
2012-04-24 22:52:52 +00:00
|
|
|
}
|
2012-03-09 02:10:07 +00:00
|
|
|
print_mt(s, mt);
|
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::ty_rec(fields) => {
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~"{");
|
2011-09-12 09:27:30 +00:00
|
|
|
fn print_field(s: ps, f: ast::ty_field) {
|
2011-07-27 12:19:39 +00:00
|
|
|
cbox(s, indent_unit);
|
2012-02-15 19:25:39 +00:00
|
|
|
print_mutability(s, f.node.mt.mutbl);
|
2012-06-10 07:49:59 +00:00
|
|
|
word(s.s, *f.node.ident);
|
2012-07-14 05:57:48 +00:00
|
|
|
word_space(s, ~":");
|
2011-08-15 11:45:04 +00:00
|
|
|
print_type(s, f.node.mt.ty);
|
2011-07-27 12:19:39 +00:00
|
|
|
end(s);
|
2011-03-24 15:33:20 +00:00
|
|
|
}
|
2012-08-02 00:30:05 +00:00
|
|
|
fn get_span(f: ast::ty_field) -> codemap::span { return f.span; }
|
2011-07-27 12:19:39 +00:00
|
|
|
commasep_cmnt(s, consistent, fields, print_field, get_span);
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~",}");
|
2011-07-27 12:19:39 +00:00
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::ty_tup(elts) => {
|
2011-08-19 22:16:48 +00:00
|
|
|
popen(s);
|
|
|
|
commasep(s, inconsistent, elts, print_type);
|
|
|
|
pclose(s);
|
2011-08-15 09:40:26 +00:00
|
|
|
}
|
2012-08-07 01:54:20 +00:00
|
|
|
ast::ty_fn(proto, bounds, d) => {
|
2012-08-02 23:01:38 +00:00
|
|
|
print_ty_fn(s, some(proto), bounds, d, none, none, none);
|
2011-07-27 12:19:39 +00:00
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::ty_path(path, _) => print_path(s, path, print_colons),
|
|
|
|
ast::ty_fixed_length(t, v) => {
|
2012-07-14 19:45:45 +00:00
|
|
|
print_type(s, t);
|
|
|
|
word(s.s, ~"/");
|
|
|
|
print_vstore(s, ast::vstore_fixed(v));
|
2012-04-10 00:32:49 +00:00
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::ty_mac(_) => {
|
2012-07-14 05:57:48 +00:00
|
|
|
fail ~"print_type doesn't know how to print a ty_mac";
|
2012-01-31 05:00:57 +00:00
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::ty_infer => {
|
2012-07-14 05:57:48 +00:00
|
|
|
fail ~"print_type shouldn't see a ty_infer";
|
2012-01-31 05:00:57 +00:00
|
|
|
}
|
|
|
|
|
2011-03-04 06:22:43 +00:00
|
|
|
}
|
2011-06-01 22:29:38 +00:00
|
|
|
end(s);
|
2011-03-04 06:22:43 +00:00
|
|
|
}
|
|
|
|
|
2012-06-26 23:18:37 +00:00
|
|
|
fn print_foreign_item(s: ps, item: @ast::foreign_item) {
|
2011-07-26 22:37:36 +00:00
|
|
|
hardbreak_if_not_bol(s);
|
|
|
|
maybe_print_comment(s, item.span.lo);
|
|
|
|
print_outer_attributes(s, item.attrs);
|
2012-08-06 19:34:08 +00:00
|
|
|
match item.node {
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::foreign_item_fn(decl, typarams) => {
|
2012-08-02 23:01:38 +00:00
|
|
|
print_fn(s, decl, item.ident, typarams, none);
|
2011-07-26 22:37:36 +00:00
|
|
|
end(s); // end head-ibox
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~";");
|
2011-07-26 22:37:36 +00:00
|
|
|
end(s); // end the outer fn box
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-06 10:26:12 +00:00
|
|
|
fn print_item(s: ps, &&item: @ast::item) {
|
2011-06-20 16:15:11 +00:00
|
|
|
hardbreak_if_not_bol(s);
|
2011-03-24 15:33:20 +00:00
|
|
|
maybe_print_comment(s, item.span.lo);
|
2011-06-16 20:00:19 +00:00
|
|
|
print_outer_attributes(s, item.attrs);
|
2011-07-27 12:19:39 +00:00
|
|
|
let ann_node = node_item(s, item);
|
2011-07-05 08:38:35 +00:00
|
|
|
s.ann.pre(ann_node);
|
2012-08-06 19:34:08 +00:00
|
|
|
match item.node {
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::item_const(ty, expr) => {
|
2012-07-14 05:57:48 +00:00
|
|
|
head(s, ~"const");
|
|
|
|
word_space(s, *item.ident + ~":");
|
2011-08-15 11:45:04 +00:00
|
|
|
print_type(s, ty);
|
2011-07-27 12:19:39 +00:00
|
|
|
space(s.s);
|
|
|
|
end(s); // end the head-ibox
|
|
|
|
|
2012-07-14 05:57:48 +00:00
|
|
|
word_space(s, ~"=");
|
2011-07-27 12:19:39 +00:00
|
|
|
print_expr(s, expr);
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~";");
|
2011-07-27 12:19:39 +00:00
|
|
|
end(s); // end the outer cbox
|
2011-06-15 18:19:50 +00:00
|
|
|
|
2011-07-27 12:19:39 +00:00
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::item_fn(decl, typarams, body) => {
|
2012-08-02 23:01:38 +00:00
|
|
|
print_fn(s, decl, item.ident, typarams, none);
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~" ");
|
2012-01-16 01:23:59 +00:00
|
|
|
print_block_with_attrs(s, body, item.attrs);
|
2011-07-27 12:19:39 +00:00
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::item_mod(_mod) => {
|
2012-07-14 05:57:48 +00:00
|
|
|
head(s, ~"mod");
|
2012-06-10 07:49:59 +00:00
|
|
|
word_nbsp(s, *item.ident);
|
2011-07-27 12:19:39 +00:00
|
|
|
bopen(s);
|
|
|
|
print_mod(s, _mod, item.attrs);
|
|
|
|
bclose(s, item.span);
|
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::item_foreign_mod(nmod) => {
|
2012-07-14 05:57:48 +00:00
|
|
|
head(s, ~"extern");
|
|
|
|
word_nbsp(s, ~"mod");
|
2012-06-10 07:49:59 +00:00
|
|
|
word_nbsp(s, *item.ident);
|
2011-07-27 12:19:39 +00:00
|
|
|
bopen(s);
|
2012-06-26 23:18:37 +00:00
|
|
|
print_foreign_mod(s, nmod, item.attrs);
|
2011-07-27 12:19:39 +00:00
|
|
|
bclose(s, item.span);
|
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::item_ty(ty, params) => {
|
2011-07-27 12:19:39 +00:00
|
|
|
ibox(s, indent_unit);
|
|
|
|
ibox(s, 0u);
|
2012-07-14 05:57:48 +00:00
|
|
|
word_nbsp(s, ~"type");
|
2012-06-10 07:49:59 +00:00
|
|
|
word(s.s, *item.ident);
|
2011-07-27 12:19:39 +00:00
|
|
|
print_type_params(s, params);
|
|
|
|
end(s); // end the inner ibox
|
|
|
|
|
|
|
|
space(s.s);
|
2012-07-14 05:57:48 +00:00
|
|
|
word_space(s, ~"=");
|
2011-08-15 11:45:04 +00:00
|
|
|
print_type(s, ty);
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~";");
|
2011-07-27 12:19:39 +00:00
|
|
|
end(s); // end the outer ibox
|
|
|
|
}
|
2012-08-09 00:14:25 +00:00
|
|
|
ast::item_enum(enum_definition, params) => {
|
|
|
|
print_enum_def(s, enum_definition, params, item.ident, item.span);
|
2011-07-27 12:19:39 +00:00
|
|
|
}
|
2012-08-07 22:34:07 +00:00
|
|
|
ast::item_class(struct_def, tps) => {
|
2012-07-14 05:57:48 +00:00
|
|
|
head(s, ~"class");
|
2012-08-07 23:08:09 +00:00
|
|
|
print_struct(s, struct_def, tps, item.ident, item.span);
|
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::item_impl(tps, traits, ty, methods) => {
|
2012-07-14 05:57:48 +00:00
|
|
|
head(s, ~"impl");
|
2012-08-08 23:26:10 +00:00
|
|
|
if tps.is_not_empty() {
|
|
|
|
print_type_params(s, tps);
|
|
|
|
space(s.s);
|
|
|
|
}
|
|
|
|
print_type(s, ty);
|
|
|
|
|
2012-07-18 16:31:53 +00:00
|
|
|
if vec::len(traits) != 0u {
|
2012-08-08 23:26:10 +00:00
|
|
|
word_space(s, ~":");
|
2012-07-18 16:31:53 +00:00
|
|
|
do commasep(s, inconsistent, traits) |s, p| {
|
|
|
|
print_path(s, p.path, false);
|
|
|
|
}
|
|
|
|
}
|
2011-12-16 09:42:28 +00:00
|
|
|
space(s.s);
|
2012-08-08 23:26:10 +00:00
|
|
|
|
2011-12-13 12:19:56 +00:00
|
|
|
bopen(s);
|
2012-06-30 23:19:07 +00:00
|
|
|
for methods.each |meth| {
|
2012-03-19 17:19:00 +00:00
|
|
|
print_method(s, meth);
|
2011-12-13 12:19:56 +00:00
|
|
|
}
|
|
|
|
bclose(s, item.span);
|
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::item_trait(tps, traits, methods) => {
|
2012-07-31 17:27:51 +00:00
|
|
|
head(s, ~"trait");
|
2012-06-10 07:49:59 +00:00
|
|
|
word(s.s, *item.ident);
|
2012-01-30 10:36:18 +00:00
|
|
|
print_type_params(s, tps);
|
2012-08-03 22:02:01 +00:00
|
|
|
if vec::len(traits) != 0u {
|
|
|
|
word_space(s, ~":");
|
|
|
|
commasep(s, inconsistent, traits, |s, p|
|
|
|
|
print_path(s, p.path, false));
|
|
|
|
}
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~" ");
|
2011-12-20 15:33:55 +00:00
|
|
|
bopen(s);
|
2012-07-10 20:44:20 +00:00
|
|
|
for methods.each |meth| { print_trait_method(s, meth); }
|
2011-12-20 15:33:55 +00:00
|
|
|
bclose(s, item.span);
|
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::item_mac({node: ast::mac_invoc_tt(pth, tts), _}) => {
|
2012-08-03 18:22:35 +00:00
|
|
|
head(s, path_to_str(pth) + ~"! " + *item.ident);
|
2012-07-11 17:42:25 +00:00
|
|
|
bopen(s);
|
2012-07-28 00:38:01 +00:00
|
|
|
for tts.each |tt| { print_tt(s, tt); }
|
2012-07-11 17:42:25 +00:00
|
|
|
bclose(s, item.span);
|
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::item_mac(_) => {
|
2012-07-14 05:57:48 +00:00
|
|
|
fail ~"invalid item-position syntax bit"
|
2012-07-05 19:10:33 +00:00
|
|
|
}
|
2011-03-04 06:22:43 +00:00
|
|
|
}
|
2011-07-05 08:38:35 +00:00
|
|
|
s.ann.post(ann_node);
|
2012-08-07 23:08:09 +00:00
|
|
|
}
|
|
|
|
|
2012-08-09 00:14:25 +00:00
|
|
|
fn print_enum_def(s: ps, enum_definition: ast::enum_def,
|
|
|
|
params: ~[ast::ty_param], ident: ast::ident,
|
|
|
|
span: ast::span) {
|
|
|
|
let mut newtype =
|
|
|
|
vec::len(enum_definition.variants) == 1u &&
|
|
|
|
str::eq(ident, enum_definition.variants[0].node.name);
|
|
|
|
if newtype {
|
|
|
|
match enum_definition.variants[0].node.kind {
|
|
|
|
ast::tuple_variant_kind(args) if args.len() == 1 => {}
|
|
|
|
_ => newtype = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if newtype {
|
|
|
|
ibox(s, indent_unit);
|
|
|
|
word_space(s, ~"enum");
|
|
|
|
} else {
|
|
|
|
head(s, ~"enum");
|
|
|
|
}
|
|
|
|
|
|
|
|
word(s.s, *ident);
|
|
|
|
print_type_params(s, params);
|
|
|
|
space(s.s);
|
|
|
|
if newtype {
|
|
|
|
word_space(s, ~"=");
|
|
|
|
match enum_definition.variants[0].node.kind {
|
|
|
|
ast::tuple_variant_kind(args) => print_type(s, args[0].ty),
|
|
|
|
_ => fail ~"newtype syntax with struct?"
|
|
|
|
}
|
|
|
|
word(s.s, ~";");
|
|
|
|
end(s);
|
|
|
|
} else {
|
|
|
|
print_variants(s, enum_definition.variants, span);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-08 21:17:52 +00:00
|
|
|
fn print_variants(s: ps, variants: ~[ast::variant], span: ast::span) {
|
|
|
|
bopen(s);
|
|
|
|
for variants.each |v| {
|
|
|
|
space_if_not_bol(s);
|
|
|
|
maybe_print_comment(s, v.span.lo);
|
|
|
|
print_outer_attributes(s, v.node.attrs);
|
|
|
|
ibox(s, indent_unit);
|
|
|
|
print_variant(s, v);
|
|
|
|
word(s.s, ~",");
|
|
|
|
end(s);
|
|
|
|
maybe_print_trailing_comment(s, v.span, none::<uint>);
|
|
|
|
}
|
|
|
|
bclose(s, span);
|
|
|
|
}
|
|
|
|
|
2012-08-08 00:46:07 +00:00
|
|
|
fn print_struct(s: ps, struct_def: @ast::struct_def, tps: ~[ast::ty_param],
|
2012-08-07 23:08:09 +00:00
|
|
|
ident: ast::ident, span: ast::span) {
|
|
|
|
word_nbsp(s, *ident);
|
|
|
|
print_type_params(s, tps);
|
|
|
|
if vec::len(struct_def.traits) != 0u {
|
|
|
|
word_space(s, ~":");
|
|
|
|
commasep(s, inconsistent, struct_def.traits, |s, p|
|
|
|
|
print_path(s, p.path, false));
|
|
|
|
}
|
|
|
|
bopen(s);
|
|
|
|
hardbreak_if_not_bol(s);
|
|
|
|
do option::iter(struct_def.ctor) |ctor| {
|
|
|
|
maybe_print_comment(s, ctor.span.lo);
|
|
|
|
print_outer_attributes(s, ctor.node.attrs);
|
|
|
|
// Doesn't call head because there shouldn't be a space after new.
|
|
|
|
cbox(s, indent_unit);
|
|
|
|
ibox(s, 4);
|
|
|
|
word(s.s, ~"new(");
|
|
|
|
print_fn_args(s, ctor.node.dec, ~[]);
|
|
|
|
word(s.s, ~")");
|
|
|
|
space(s.s);
|
|
|
|
print_block(s, ctor.node.body);
|
|
|
|
}
|
|
|
|
do option::iter(struct_def.dtor) |dtor| {
|
|
|
|
hardbreak_if_not_bol(s);
|
|
|
|
maybe_print_comment(s, dtor.span.lo);
|
|
|
|
print_outer_attributes(s, dtor.node.attrs);
|
|
|
|
head(s, ~"drop");
|
|
|
|
print_block(s, dtor.node.body);
|
|
|
|
}
|
|
|
|
for struct_def.members.each |ci| {
|
|
|
|
/*
|
|
|
|
FIXME (#1893): collect all private items and print
|
|
|
|
them in a single "priv" section
|
|
|
|
|
|
|
|
tjc: I'm not going to fix this yet b/c we might
|
|
|
|
change how exports work, including for class items
|
|
|
|
*/
|
|
|
|
hardbreak_if_not_bol(s);
|
|
|
|
maybe_print_comment(s, ci.span.lo);
|
|
|
|
let pr = ast_util::class_member_visibility(ci);
|
|
|
|
match pr {
|
|
|
|
ast::private => {
|
|
|
|
head(s, ~"priv");
|
|
|
|
bopen(s);
|
|
|
|
hardbreak_if_not_bol(s);
|
|
|
|
}
|
|
|
|
_ => ()
|
|
|
|
}
|
|
|
|
match ci.node {
|
|
|
|
ast::instance_var(nm, t, mt, _,_) => {
|
|
|
|
word_nbsp(s, ~"let");
|
|
|
|
match mt {
|
|
|
|
ast::class_mutable => word_nbsp(s, ~"mut"),
|
|
|
|
_ => ()
|
|
|
|
}
|
|
|
|
word(s.s, *nm);
|
|
|
|
word_nbsp(s, ~":");
|
|
|
|
print_type(s, t);
|
|
|
|
word(s.s, ~";");
|
|
|
|
}
|
|
|
|
ast::class_method(m) => {
|
|
|
|
print_method(s, m);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
match pr {
|
|
|
|
ast::private => bclose(s, ci.span),
|
|
|
|
_ => ()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bclose(s, span);
|
2011-03-04 06:22:43 +00:00
|
|
|
}
|
|
|
|
|
2012-07-28 00:38:01 +00:00
|
|
|
/// This doesn't deserve to be called "pretty" printing, but it should be
|
|
|
|
/// meaning-preserving. A quick hack that might help would be to look at the
|
|
|
|
/// spans embedded in the TTs to decide where to put spaces and newlines.
|
|
|
|
/// But it'd be better to parse these according to the grammar of the
|
|
|
|
/// appropriate macro, transcribe back into the grammar we just parsed from,
|
|
|
|
/// and then pretty-print the resulting AST nodes (so, e.g., we print
|
|
|
|
/// expression arguments as expressions). It can be done! I think.
|
|
|
|
fn print_tt(s: ps, tt: ast::token_tree) {
|
2012-08-06 19:34:08 +00:00
|
|
|
match tt {
|
2012-08-07 00:14:32 +00:00
|
|
|
ast::tt_delim(tts) => for tts.each() |tt_elt| { print_tt(s, tt_elt); },
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::tt_tok(_, tk) => {
|
2012-08-06 19:34:08 +00:00
|
|
|
match tk {
|
2012-08-04 02:59:04 +00:00
|
|
|
parse::token::IDENT(*) => { // don't let idents run together
|
2012-07-31 00:56:53 +00:00
|
|
|
if s.s.token_tree_last_was_ident { word(s.s, ~" ") }
|
|
|
|
s.s.token_tree_last_was_ident = true;
|
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
_ => { s.s.token_tree_last_was_ident = false; }
|
2012-07-28 00:38:01 +00:00
|
|
|
}
|
2012-07-31 00:56:53 +00:00
|
|
|
word(s.s, parse::token::to_str(*s.intr, tk));
|
2012-07-28 00:38:01 +00:00
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::tt_seq(_, tts, sep, zerok) => {
|
2012-07-28 00:38:01 +00:00
|
|
|
word(s.s, ~"$(");
|
|
|
|
for tts.each() |tt_elt| { print_tt(s, tt_elt); }
|
|
|
|
word(s.s, ~")");
|
2012-08-06 19:34:08 +00:00
|
|
|
match sep {
|
2012-08-04 02:59:04 +00:00
|
|
|
some(tk) => word(s.s, parse::token::to_str(*s.intr, tk)),
|
|
|
|
none => ()
|
2012-07-28 00:38:01 +00:00
|
|
|
}
|
|
|
|
word(s.s, if zerok { ~"*" } else { ~"+" });
|
2012-07-31 00:56:53 +00:00
|
|
|
s.s.token_tree_last_was_ident = false;
|
2012-07-28 00:38:01 +00:00
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::tt_nonterminal(_, name) => {
|
2012-07-28 00:38:01 +00:00
|
|
|
word(s.s, ~"$" + *name);
|
2012-07-31 00:56:53 +00:00
|
|
|
s.s.token_tree_last_was_ident = true;
|
2012-07-28 00:38:01 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-11 17:42:25 +00:00
|
|
|
}
|
|
|
|
|
2012-01-26 01:22:08 +00:00
|
|
|
fn print_variant(s: ps, v: ast::variant) {
|
2012-08-07 21:24:04 +00:00
|
|
|
match v.node.kind {
|
|
|
|
ast::tuple_variant_kind(args) => {
|
2012-08-08 01:54:44 +00:00
|
|
|
word(s.s, *v.node.name);
|
2012-08-07 21:24:04 +00:00
|
|
|
if vec::len(args) > 0u {
|
|
|
|
popen(s);
|
|
|
|
fn print_variant_arg(s: ps, arg: ast::variant_arg) {
|
|
|
|
print_type(s, arg.ty);
|
|
|
|
}
|
|
|
|
commasep(s, consistent, args, print_variant_arg);
|
|
|
|
pclose(s);
|
|
|
|
}
|
2012-01-26 01:22:08 +00:00
|
|
|
}
|
2012-08-08 01:54:44 +00:00
|
|
|
ast::struct_variant_kind(struct_def) => {
|
|
|
|
head(s, ~"");
|
|
|
|
print_struct(s, struct_def, ~[], v.node.name, v.span);
|
|
|
|
}
|
2012-08-09 00:14:25 +00:00
|
|
|
ast::enum_variant_kind(enum_definition) => {
|
|
|
|
print_variants(s, enum_definition.variants, v.span);
|
2012-08-08 21:17:52 +00:00
|
|
|
}
|
2012-01-26 01:22:08 +00:00
|
|
|
}
|
2012-08-06 19:34:08 +00:00
|
|
|
match v.node.disr_expr {
|
2012-08-04 02:59:04 +00:00
|
|
|
some(d) => {
|
2012-01-26 01:22:08 +00:00
|
|
|
space(s.s);
|
2012-07-14 05:57:48 +00:00
|
|
|
word_space(s, ~"=");
|
2012-01-26 01:22:08 +00:00
|
|
|
print_expr(s, d);
|
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
_ => ()
|
2012-01-26 01:22:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-20 15:33:55 +00:00
|
|
|
fn print_ty_method(s: ps, m: ast::ty_method) {
|
|
|
|
hardbreak_if_not_bol(s);
|
|
|
|
maybe_print_comment(s, m.span.lo);
|
2012-01-30 19:43:45 +00:00
|
|
|
print_outer_attributes(s, m.attrs);
|
2012-08-02 23:01:38 +00:00
|
|
|
print_ty_fn(s, none, @~[], m.decl, some(m.ident), some(m.tps),
|
|
|
|
some(m.self_ty.node));
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~";");
|
2011-12-20 15:33:55 +00:00
|
|
|
}
|
|
|
|
|
2012-07-10 20:44:20 +00:00
|
|
|
fn print_trait_method(s: ps, m: ast::trait_method) {
|
2012-08-06 19:34:08 +00:00
|
|
|
match m {
|
2012-08-04 02:59:04 +00:00
|
|
|
required(ty_m) => print_ty_method(s, ty_m),
|
|
|
|
provided(m) => print_method(s, m)
|
2012-07-10 20:44:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-19 17:19:00 +00:00
|
|
|
fn print_method(s: ps, meth: @ast::method) {
|
|
|
|
hardbreak_if_not_bol(s);
|
|
|
|
maybe_print_comment(s, meth.span.lo);
|
|
|
|
print_outer_attributes(s, meth.attrs);
|
2012-08-02 23:01:38 +00:00
|
|
|
print_fn(s, meth.decl, meth.ident, meth.tps, some(meth.self_ty.node));
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~" ");
|
2012-03-19 17:19:00 +00:00
|
|
|
print_block_with_attrs(s, meth.body, meth.attrs);
|
|
|
|
}
|
|
|
|
|
2012-06-29 23:26:56 +00:00
|
|
|
fn print_outer_attributes(s: ps, attrs: ~[ast::attribute]) {
|
2012-03-15 13:47:03 +00:00
|
|
|
let mut count = 0;
|
2012-06-30 23:19:07 +00:00
|
|
|
for attrs.each |attr| {
|
2012-08-06 19:34:08 +00:00
|
|
|
match attr.node.style {
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::attr_outer => { print_attribute(s, attr); count += 1; }
|
|
|
|
_ => {/* fallthrough */ }
|
2011-06-15 01:53:12 +00:00
|
|
|
}
|
|
|
|
}
|
2011-07-27 12:19:39 +00:00
|
|
|
if count > 0 { hardbreak_if_not_bol(s); }
|
2011-06-15 01:53:12 +00:00
|
|
|
}
|
|
|
|
|
2012-06-29 23:26:56 +00:00
|
|
|
fn print_inner_attributes(s: ps, attrs: ~[ast::attribute]) {
|
2012-03-15 13:47:03 +00:00
|
|
|
let mut count = 0;
|
2012-06-30 23:19:07 +00:00
|
|
|
for attrs.each |attr| {
|
2012-08-06 19:34:08 +00:00
|
|
|
match attr.node.style {
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::attr_inner => {
|
2011-07-27 12:19:39 +00:00
|
|
|
print_attribute(s, attr);
|
2012-06-30 10:54:54 +00:00
|
|
|
if !attr.node.is_sugared_doc {
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~";");
|
2012-06-30 10:54:54 +00:00
|
|
|
}
|
2011-07-27 12:19:39 +00:00
|
|
|
count += 1;
|
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
_ => {/* fallthrough */ }
|
2011-06-16 20:00:19 +00:00
|
|
|
}
|
|
|
|
}
|
2011-07-27 12:19:39 +00:00
|
|
|
if count > 0 { hardbreak_if_not_bol(s); }
|
2011-06-16 20:00:19 +00:00
|
|
|
}
|
|
|
|
|
2011-09-12 09:27:30 +00:00
|
|
|
fn print_attribute(s: ps, attr: ast::attribute) {
|
2011-07-01 00:25:13 +00:00
|
|
|
hardbreak_if_not_bol(s);
|
2011-06-15 01:53:12 +00:00
|
|
|
maybe_print_comment(s, attr.span.lo);
|
2012-06-30 10:54:54 +00:00
|
|
|
if attr.node.is_sugared_doc {
|
|
|
|
let meta = attr::attr_meta(attr);
|
|
|
|
let comment = attr::get_meta_item_value_str(meta).get();
|
|
|
|
word(s.s, *comment);
|
|
|
|
} else {
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~"#[");
|
2012-06-30 10:54:54 +00:00
|
|
|
print_meta_item(s, @attr.node.value);
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~"]");
|
2012-06-30 10:54:54 +00:00
|
|
|
}
|
2011-06-15 01:53:12 +00:00
|
|
|
}
|
|
|
|
|
2011-12-29 20:03:39 +00:00
|
|
|
|
2011-09-12 09:27:30 +00:00
|
|
|
fn print_stmt(s: ps, st: ast::stmt) {
|
2011-05-31 17:58:30 +00:00
|
|
|
maybe_print_comment(s, st.span.lo);
|
2012-08-06 19:34:08 +00:00
|
|
|
match st.node {
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::stmt_decl(decl, _) => {
|
2011-12-29 20:03:39 +00:00
|
|
|
print_decl(s, decl);
|
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::stmt_expr(expr, _) => {
|
2011-12-29 20:03:39 +00:00
|
|
|
space_if_not_bol(s);
|
2012-01-05 06:01:58 +00:00
|
|
|
print_expr(s, expr);
|
2012-07-04 00:30:25 +00:00
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::stmt_semi(expr, _) => {
|
2012-07-04 00:30:25 +00:00
|
|
|
space_if_not_bol(s);
|
|
|
|
print_expr(s, expr);
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~";");
|
2012-01-04 22:16:41 +00:00
|
|
|
}
|
2011-05-31 17:58:30 +00:00
|
|
|
}
|
2012-07-14 05:57:48 +00:00
|
|
|
if parse::classify::stmt_ends_with_semi(st) { word(s.s, ~";"); }
|
2011-08-13 07:09:25 +00:00
|
|
|
maybe_print_trailing_comment(s, st.span, none::<uint>);
|
2011-05-31 17:58:30 +00:00
|
|
|
}
|
|
|
|
|
2011-09-12 09:27:30 +00:00
|
|
|
fn print_block(s: ps, blk: ast::blk) {
|
2011-08-15 21:42:33 +00:00
|
|
|
print_possibly_embedded_block(s, blk, block_normal, indent_unit);
|
2011-07-13 22:44:09 +00:00
|
|
|
}
|
2011-07-08 23:35:09 +00:00
|
|
|
|
2012-06-29 23:26:56 +00:00
|
|
|
fn print_block_with_attrs(s: ps, blk: ast::blk, attrs: ~[ast::attribute]) {
|
2012-01-16 01:23:59 +00:00
|
|
|
print_possibly_embedded_block_(s, blk, block_normal, indent_unit, attrs);
|
|
|
|
}
|
|
|
|
|
2012-07-28 01:06:24 +00:00
|
|
|
enum embed_type { block_block_fn, block_normal, }
|
2011-08-15 21:42:33 +00:00
|
|
|
|
2011-09-12 09:27:30 +00:00
|
|
|
fn print_possibly_embedded_block(s: ps, blk: ast::blk, embedded: embed_type,
|
2011-07-27 12:19:39 +00:00
|
|
|
indented: uint) {
|
2012-01-16 01:23:59 +00:00
|
|
|
print_possibly_embedded_block_(
|
2012-06-29 23:26:56 +00:00
|
|
|
s, blk, embedded, indented, ~[]);
|
2012-01-16 01:23:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn print_possibly_embedded_block_(s: ps, blk: ast::blk, embedded: embed_type,
|
2012-06-29 23:26:56 +00:00
|
|
|
indented: uint, attrs: ~[ast::attribute]) {
|
2012-08-06 19:34:08 +00:00
|
|
|
match blk.node.rules {
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::unchecked_blk => word(s.s, ~"unchecked"),
|
|
|
|
ast::unsafe_blk => word(s.s, ~"unsafe"),
|
|
|
|
ast::default_blk => ()
|
2011-10-06 23:42:27 +00:00
|
|
|
}
|
2011-03-24 15:33:20 +00:00
|
|
|
maybe_print_comment(s, blk.span.lo);
|
2011-07-27 12:19:39 +00:00
|
|
|
let ann_node = node_block(s, blk);
|
2011-07-05 08:38:35 +00:00
|
|
|
s.ann.pre(ann_node);
|
2012-08-06 19:34:08 +00:00
|
|
|
match embedded {
|
2012-08-04 02:59:04 +00:00
|
|
|
block_block_fn => end(s),
|
|
|
|
block_normal => bopen(s)
|
2011-08-15 21:42:33 +00:00
|
|
|
}
|
2011-08-03 03:46:36 +00:00
|
|
|
|
2012-01-16 01:23:59 +00:00
|
|
|
print_inner_attributes(s, attrs);
|
|
|
|
|
2012-06-30 23:19:07 +00:00
|
|
|
for blk.node.view_items.each |vi| { print_view_item(s, vi); }
|
|
|
|
for blk.node.stmts.each |st| {
|
2011-08-03 03:46:36 +00:00
|
|
|
print_stmt(s, *st);
|
|
|
|
}
|
2012-08-06 19:34:08 +00:00
|
|
|
match blk.node.expr {
|
2012-08-04 02:59:04 +00:00
|
|
|
some(expr) => {
|
2011-07-27 12:19:39 +00:00
|
|
|
space_if_not_bol(s);
|
2012-01-05 06:01:58 +00:00
|
|
|
print_expr(s, expr);
|
2011-07-27 12:19:39 +00:00
|
|
|
maybe_print_trailing_comment(s, expr.span, some(blk.span.hi));
|
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
_ => ()
|
2011-03-04 06:22:43 +00:00
|
|
|
}
|
2011-07-21 13:36:41 +00:00
|
|
|
bclose_(s, blk.span, indented);
|
2011-07-05 08:38:35 +00:00
|
|
|
s.ann.post(ann_node);
|
2011-03-04 06:22:43 +00:00
|
|
|
}
|
|
|
|
|
2012-08-02 00:30:05 +00:00
|
|
|
// return and fail, without arguments cannot appear is the discriminant of if,
|
2011-08-19 05:39:03 +00:00
|
|
|
// alt, do, & while unambiguously without being parenthesized
|
2011-09-12 09:27:30 +00:00
|
|
|
fn print_maybe_parens_discrim(s: ps, e: @ast::expr) {
|
2012-08-06 19:34:08 +00:00
|
|
|
let disambig = match e.node {
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::expr_ret(none) | ast::expr_fail(none) => true,
|
|
|
|
_ => false
|
2011-09-15 08:12:09 +00:00
|
|
|
};
|
2011-09-16 14:57:54 +00:00
|
|
|
if disambig { popen(s); }
|
2011-08-19 05:39:03 +00:00
|
|
|
print_expr(s, e);
|
2011-09-16 14:57:54 +00:00
|
|
|
if disambig { pclose(s); }
|
2011-08-19 05:39:03 +00:00
|
|
|
}
|
|
|
|
|
2011-09-12 09:27:30 +00:00
|
|
|
fn print_if(s: ps, test: @ast::expr, blk: ast::blk,
|
2012-02-01 01:05:20 +00:00
|
|
|
elseopt: option<@ast::expr>, chk: bool) {
|
2012-07-14 05:57:48 +00:00
|
|
|
head(s, ~"if");
|
|
|
|
if chk { word_nbsp(s, ~"check"); }
|
2011-08-19 05:39:03 +00:00
|
|
|
print_maybe_parens_discrim(s, test);
|
2011-06-16 21:08:17 +00:00
|
|
|
space(s.s);
|
2011-07-25 20:42:38 +00:00
|
|
|
print_block(s, blk);
|
2012-02-01 01:05:20 +00:00
|
|
|
fn do_else(s: ps, els: option<@ast::expr>) {
|
2012-08-06 19:34:08 +00:00
|
|
|
match els {
|
2012-08-04 02:59:04 +00:00
|
|
|
some(_else) => {
|
2012-08-06 19:34:08 +00:00
|
|
|
match _else.node {
|
2011-07-27 12:19:39 +00:00
|
|
|
// "another else-if"
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::expr_if(i, t, e) => {
|
2011-07-27 12:19:39 +00:00
|
|
|
cbox(s, indent_unit - 1u);
|
|
|
|
ibox(s, 0u);
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~" else if ");
|
2011-09-16 04:24:24 +00:00
|
|
|
print_maybe_parens_discrim(s, i);
|
2011-07-27 12:19:39 +00:00
|
|
|
space(s.s);
|
|
|
|
print_block(s, t);
|
|
|
|
do_else(s, e);
|
|
|
|
}
|
|
|
|
// "final else"
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::expr_block(b) => {
|
2011-07-27 12:19:39 +00:00
|
|
|
cbox(s, indent_unit - 1u);
|
|
|
|
ibox(s, 0u);
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~" else ");
|
2011-07-27 12:19:39 +00:00
|
|
|
print_block(s, b);
|
|
|
|
}
|
2012-01-31 05:00:57 +00:00
|
|
|
// BLEAH, constraints would be great here
|
2012-08-04 02:59:04 +00:00
|
|
|
_ => {
|
2012-07-14 05:57:48 +00:00
|
|
|
fail ~"print_if saw if with weird alternative";
|
2012-01-31 05:00:57 +00:00
|
|
|
}
|
2011-06-16 21:08:17 +00:00
|
|
|
}
|
2011-07-27 12:19:39 +00:00
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
_ => {/* fall through */ }
|
2011-06-16 21:08:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
do_else(s, elseopt);
|
|
|
|
}
|
|
|
|
|
2011-09-12 09:27:30 +00:00
|
|
|
fn print_mac(s: ps, m: ast::mac) {
|
2012-08-06 19:34:08 +00:00
|
|
|
match m.node {
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::mac_invoc(path, arg, body) => {
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~"#");
|
2011-08-16 16:03:58 +00:00
|
|
|
print_path(s, path, false);
|
2012-08-06 19:34:08 +00:00
|
|
|
match arg {
|
2012-08-04 02:59:04 +00:00
|
|
|
some(@{node: ast::expr_vec(_, _), _}) => (),
|
|
|
|
_ => word(s.s, ~" ")
|
2012-02-01 07:20:31 +00:00
|
|
|
}
|
2012-06-30 23:19:07 +00:00
|
|
|
option::iter(arg, |a| print_expr(s, a));
|
2012-05-03 20:04:40 +00:00
|
|
|
// FIXME: extension 'body' (#2339)
|
2011-07-27 12:19:39 +00:00
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::mac_invoc_tt(pth, tts) => {
|
2012-08-03 18:22:35 +00:00
|
|
|
head(s, path_to_str(pth) + ~"!");
|
2012-07-11 17:42:25 +00:00
|
|
|
bopen(s);
|
|
|
|
for tts.each() |tt| { print_tt(s, tt); }
|
|
|
|
bclose(s, m.span);
|
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::mac_ellipsis => word(s.s, ~"..."),
|
|
|
|
ast::mac_var(v) => word(s.s, fmt!{"$%u", v}),
|
|
|
|
_ => { /* fixme */ }
|
2011-07-08 23:35:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-10 00:32:49 +00:00
|
|
|
fn print_vstore(s: ps, t: ast::vstore) {
|
2012-08-06 19:34:08 +00:00
|
|
|
match t {
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::vstore_fixed(some(i)) => word(s.s, fmt!{"%u", i}),
|
|
|
|
ast::vstore_fixed(none) => word(s.s, ~"_"),
|
|
|
|
ast::vstore_uniq => word(s.s, ~"~"),
|
|
|
|
ast::vstore_box => word(s.s, ~"@"),
|
2012-08-06 19:34:08 +00:00
|
|
|
ast::vstore_slice(r) => match r.node {
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::re_anon => word(s.s, ~"&"),
|
|
|
|
ast::re_named(name) => {
|
|
|
|
word(s.s, ~"&");
|
|
|
|
word(s.s, *name);
|
|
|
|
word(s.s, ~".");
|
|
|
|
}
|
2012-07-13 01:09:12 +00:00
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
}
|
2012-04-10 00:32:49 +00:00
|
|
|
}
|
|
|
|
|
2011-10-06 10:26:12 +00:00
|
|
|
fn print_expr(s: ps, &&expr: @ast::expr) {
|
2012-07-23 23:39:18 +00:00
|
|
|
fn print_field(s: ps, field: ast::field) {
|
|
|
|
ibox(s, indent_unit);
|
|
|
|
if field.node.mutbl == ast::m_mutbl { word_nbsp(s, ~"mut"); }
|
|
|
|
word(s.s, *field.node.ident);
|
|
|
|
word_space(s, ~":");
|
|
|
|
print_expr(s, field.node.expr);
|
|
|
|
end(s);
|
|
|
|
}
|
2012-08-02 00:30:05 +00:00
|
|
|
fn get_span(field: ast::field) -> codemap::span { return field.span; }
|
2012-07-23 23:39:18 +00:00
|
|
|
|
2011-03-24 15:33:20 +00:00
|
|
|
maybe_print_comment(s, expr.span.lo);
|
2011-06-01 22:29:38 +00:00
|
|
|
ibox(s, indent_unit);
|
2011-07-27 12:19:39 +00:00
|
|
|
let ann_node = node_expr(s, expr);
|
2011-07-05 08:38:35 +00:00
|
|
|
s.ann.pre(ann_node);
|
2012-08-06 19:34:08 +00:00
|
|
|
match expr.node {
|
|
|
|
ast::expr_vstore(e, v) => match v {
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::vstore_fixed(_) => {
|
2012-07-10 20:55:19 +00:00
|
|
|
print_expr(s, e);
|
2012-08-04 02:59:04 +00:00
|
|
|
word(s.s, ~"/");
|
|
|
|
print_vstore(s, v);
|
2012-07-10 20:55:19 +00:00
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
_ => {
|
2012-07-10 20:55:19 +00:00
|
|
|
print_vstore(s, v);
|
2012-08-04 02:59:04 +00:00
|
|
|
print_expr(s, e);
|
2012-07-10 20:55:19 +00:00
|
|
|
}
|
2012-08-07 00:14:32 +00:00
|
|
|
},
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::expr_vec(exprs, mutbl) => {
|
2011-07-27 12:19:39 +00:00
|
|
|
ibox(s, indent_unit);
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~"[");
|
2012-02-15 19:25:39 +00:00
|
|
|
if mutbl == ast::m_mutbl {
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~"mut");
|
2011-08-15 23:38:23 +00:00
|
|
|
if vec::len(exprs) > 0u { nbsp(s); }
|
2011-07-27 19:20:51 +00:00
|
|
|
}
|
2011-07-27 12:19:39 +00:00
|
|
|
commasep_exprs(s, inconsistent, exprs);
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~"]");
|
2011-07-27 12:19:39 +00:00
|
|
|
end(s);
|
|
|
|
}
|
2012-08-04 01:01:30 +00:00
|
|
|
|
|
|
|
ast::expr_repeat(element, count, mutbl) => {
|
|
|
|
ibox(s, indent_unit);
|
|
|
|
word(s.s, ~"[");
|
|
|
|
if mutbl == ast::m_mutbl {
|
|
|
|
word(s.s, ~"mut");
|
|
|
|
nbsp(s);
|
|
|
|
}
|
|
|
|
print_expr(s, element);
|
|
|
|
word(s.s, ~",");
|
|
|
|
word(s.s, ~"..");
|
|
|
|
print_expr(s, count);
|
|
|
|
word(s.s, ~"]");
|
|
|
|
end(s);
|
|
|
|
}
|
|
|
|
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::expr_rec(fields, wth) => {
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~"{");
|
2011-07-27 12:19:39 +00:00
|
|
|
commasep_cmnt(s, consistent, fields, print_field, get_span);
|
2012-08-06 19:34:08 +00:00
|
|
|
match wth {
|
2012-08-04 02:59:04 +00:00
|
|
|
some(expr) => {
|
2011-08-15 23:38:23 +00:00
|
|
|
if vec::len(fields) > 0u { space(s.s); }
|
2011-07-27 12:19:39 +00:00
|
|
|
ibox(s, indent_unit);
|
2012-07-14 05:57:48 +00:00
|
|
|
word_space(s, ~"with");
|
2011-03-24 15:33:20 +00:00
|
|
|
print_expr(s, expr);
|
2011-07-27 12:19:39 +00:00
|
|
|
end(s);
|
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
_ => word(s.s, ~",")
|
2011-03-24 15:33:20 +00:00
|
|
|
}
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~"}");
|
2011-07-27 12:19:39 +00:00
|
|
|
}
|
2012-08-06 20:15:40 +00:00
|
|
|
ast::expr_struct(path, fields, wth) => {
|
2012-07-23 23:39:18 +00:00
|
|
|
print_path(s, path, true);
|
|
|
|
word(s.s, ~"{");
|
|
|
|
commasep_cmnt(s, consistent, fields, print_field, get_span);
|
2012-08-06 19:34:08 +00:00
|
|
|
match wth {
|
2012-08-06 20:15:40 +00:00
|
|
|
some(expr) => {
|
|
|
|
if vec::len(fields) > 0u { space(s.s); }
|
|
|
|
ibox(s, indent_unit);
|
|
|
|
word_space(s, ~"with");
|
|
|
|
print_expr(s, expr);
|
|
|
|
end(s);
|
|
|
|
}
|
|
|
|
_ => word(s.s, ~",")
|
|
|
|
}
|
2012-07-23 23:39:18 +00:00
|
|
|
word(s.s, ~"}");
|
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::expr_tup(exprs) => {
|
2011-08-15 09:40:26 +00:00
|
|
|
popen(s);
|
2011-08-15 10:08:05 +00:00
|
|
|
commasep_exprs(s, inconsistent, exprs);
|
2011-08-15 09:40:26 +00:00
|
|
|
pclose(s);
|
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::expr_call(func, args, has_block) => {
|
2012-03-26 14:09:27 +00:00
|
|
|
let mut base_args = args;
|
|
|
|
let blk = if has_block {
|
|
|
|
let blk_arg = vec::pop(base_args);
|
2012-08-06 19:34:08 +00:00
|
|
|
match blk_arg.node {
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::expr_loop_body(_) => word_nbsp(s, ~"for"),
|
|
|
|
ast::expr_do_body(_) => word_nbsp(s, ~"do"),
|
|
|
|
_ => ()
|
2012-03-26 14:09:27 +00:00
|
|
|
}
|
|
|
|
some(blk_arg)
|
|
|
|
} else { none };
|
2011-09-15 09:15:14 +00:00
|
|
|
print_expr_parens_if_not_bot(s, func);
|
2011-10-21 12:11:24 +00:00
|
|
|
if !has_block || vec::len(base_args) > 0u {
|
|
|
|
popen(s);
|
|
|
|
commasep_exprs(s, inconsistent, base_args);
|
|
|
|
pclose(s);
|
|
|
|
}
|
|
|
|
if has_block {
|
|
|
|
nbsp(s);
|
|
|
|
print_expr(s, option::get(blk));
|
|
|
|
}
|
2011-07-27 12:19:39 +00:00
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::expr_binary(op, lhs, rhs) => {
|
2011-07-27 12:19:39 +00:00
|
|
|
let prec = operator_prec(op);
|
2011-09-13 15:02:36 +00:00
|
|
|
print_op_maybe_parens(s, lhs, prec);
|
2011-07-27 12:19:39 +00:00
|
|
|
space(s.s);
|
2011-08-27 21:42:29 +00:00
|
|
|
word_space(s, ast_util::binop_to_str(op));
|
2012-04-26 23:13:59 +00:00
|
|
|
print_op_maybe_parens(s, rhs, prec + 1u);
|
2011-07-27 12:19:39 +00:00
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::expr_unary(op, expr) => {
|
2011-08-27 21:42:29 +00:00
|
|
|
word(s.s, ast_util::unop_to_str(op));
|
2012-04-18 03:41:04 +00:00
|
|
|
print_op_maybe_parens(s, expr, parse::prec::unop_prec);
|
2011-07-27 12:19:39 +00:00
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::expr_addr_of(m, expr) => {
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~"&");
|
2012-03-09 00:34:36 +00:00
|
|
|
print_mutability(s, m);
|
|
|
|
print_expr(s, expr);
|
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::expr_lit(lit) => print_literal(s, lit),
|
|
|
|
ast::expr_cast(expr, ty) => {
|
2012-04-18 03:41:04 +00:00
|
|
|
print_op_maybe_parens(s, expr, parse::prec::as_prec);
|
2011-07-27 12:19:39 +00:00
|
|
|
space(s.s);
|
2012-07-14 05:57:48 +00:00
|
|
|
word_space(s, ~"as");
|
2012-05-15 21:51:33 +00:00
|
|
|
print_type_ex(s, ty, true);
|
2011-07-27 12:19:39 +00:00
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::expr_if(test, blk, elseopt) => {
|
2011-07-27 12:19:39 +00:00
|
|
|
print_if(s, test, blk, elseopt, false);
|
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::expr_while(test, blk) => {
|
2012-07-14 05:57:48 +00:00
|
|
|
head(s, ~"while");
|
2011-08-19 05:39:03 +00:00
|
|
|
print_maybe_parens_discrim(s, test);
|
2011-07-27 12:19:39 +00:00
|
|
|
space(s.s);
|
|
|
|
print_block(s, blk);
|
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::expr_loop(blk) => {
|
2012-07-14 05:57:48 +00:00
|
|
|
head(s, ~"loop");
|
2012-03-10 00:11:56 +00:00
|
|
|
space(s.s);
|
|
|
|
print_block(s, blk);
|
|
|
|
}
|
2012-08-07 20:35:51 +00:00
|
|
|
ast::expr_match(expr, arms, mode) => {
|
2011-07-27 12:19:39 +00:00
|
|
|
cbox(s, alt_indent_unit);
|
|
|
|
ibox(s, 4u);
|
2012-08-06 19:34:08 +00:00
|
|
|
word_nbsp(s, ~"match");
|
2012-07-14 05:57:48 +00:00
|
|
|
if mode == ast::alt_check { word_nbsp(s, ~"check"); }
|
2011-08-19 05:39:03 +00:00
|
|
|
print_maybe_parens_discrim(s, expr);
|
2011-07-27 12:19:39 +00:00
|
|
|
space(s.s);
|
|
|
|
bopen(s);
|
2012-07-10 17:37:05 +00:00
|
|
|
let len = arms.len();
|
|
|
|
for arms.eachi |i, arm| {
|
2011-03-24 15:33:20 +00:00
|
|
|
space(s.s);
|
2011-07-21 13:36:41 +00:00
|
|
|
cbox(s, alt_indent_unit);
|
2011-07-27 12:19:39 +00:00
|
|
|
ibox(s, 0u);
|
2012-03-15 13:47:03 +00:00
|
|
|
let mut first = true;
|
2012-06-30 23:19:07 +00:00
|
|
|
for arm.pats.each |p| {
|
2011-07-27 12:19:39 +00:00
|
|
|
if first {
|
|
|
|
first = false;
|
2012-07-14 05:57:48 +00:00
|
|
|
} else { space(s.s); word_space(s, ~"|"); }
|
2011-07-27 12:19:39 +00:00
|
|
|
print_pat(s, p);
|
2011-03-24 15:33:20 +00:00
|
|
|
}
|
2011-06-14 13:20:04 +00:00
|
|
|
space(s.s);
|
2012-08-06 19:34:08 +00:00
|
|
|
match arm.guard {
|
2012-08-04 02:59:04 +00:00
|
|
|
some(e) => {
|
|
|
|
word_space(s, ~"if");
|
|
|
|
print_expr(s, e);
|
|
|
|
space(s.s);
|
|
|
|
}
|
|
|
|
none => ()
|
2011-08-22 12:38:48 +00:00
|
|
|
}
|
2012-07-10 17:37:05 +00:00
|
|
|
word_space(s, ~"=>");
|
2012-08-01 23:16:53 +00:00
|
|
|
// Extract the expression from the extra block the parser adds
|
|
|
|
assert arm.body.node.view_items.is_empty();
|
|
|
|
assert arm.body.node.stmts.is_empty();
|
|
|
|
assert arm.body.node.rules == ast::default_blk;
|
2012-08-06 19:34:08 +00:00
|
|
|
match arm.body.node.expr {
|
2012-07-10 17:37:05 +00:00
|
|
|
some(expr) => {
|
|
|
|
end(s); // close the ibox for the pattern
|
|
|
|
print_expr(s, expr);
|
2012-08-07 00:14:32 +00:00
|
|
|
if !expr_is_simple_block(expr)
|
2012-08-01 23:16:53 +00:00
|
|
|
&& i < len - 1 {
|
|
|
|
word(s.s, ~",");
|
|
|
|
}
|
2012-07-10 17:37:05 +00:00
|
|
|
end(s); // close enclosing cbox
|
|
|
|
}
|
2012-08-01 23:16:53 +00:00
|
|
|
none => fail
|
2012-07-10 17:37:05 +00:00
|
|
|
}
|
2011-06-14 13:20:04 +00:00
|
|
|
}
|
2011-07-27 12:19:39 +00:00
|
|
|
bclose_(s, expr.span, alt_indent_unit);
|
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::expr_fn(proto, decl, body, cap_clause) => {
|
2011-12-30 21:32:42 +00:00
|
|
|
// containing cbox, will be closed by print-block at }
|
|
|
|
cbox(s, indent_unit);
|
|
|
|
// head-box, will be closed by print-block at start
|
|
|
|
ibox(s, 0u);
|
2012-08-02 23:01:38 +00:00
|
|
|
word(s.s, fn_header_info_to_str(none, decl.purity, some(proto)));
|
2012-05-07 18:31:57 +00:00
|
|
|
print_fn_args_and_ret(s, decl, *cap_clause);
|
2011-12-20 19:03:21 +00:00
|
|
|
space(s.s);
|
2011-12-22 16:49:54 +00:00
|
|
|
print_block(s, body);
|
2011-12-20 19:03:21 +00:00
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::expr_fn_block(decl, body, cap_clause) => {
|
2012-05-07 18:31:57 +00:00
|
|
|
print_fn_block_args(s, decl, *cap_clause);
|
2012-07-01 23:40:15 +00:00
|
|
|
// The parser always adds an extra implicit block around lambdas
|
|
|
|
assert body.node.stmts.is_empty();
|
|
|
|
assert body.node.expr.is_some();
|
|
|
|
space(s.s);
|
|
|
|
print_expr(s, body.node.expr.get());
|
2011-07-27 12:19:39 +00:00
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::expr_loop_body(body) => {
|
2012-03-26 14:09:27 +00:00
|
|
|
print_expr(s, body);
|
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::expr_do_body(body) => {
|
2012-06-19 00:42:09 +00:00
|
|
|
print_expr(s, body);
|
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::expr_block(blk) => {
|
2011-07-27 12:19:39 +00:00
|
|
|
// containing cbox, will be closed by print-block at }
|
|
|
|
cbox(s, indent_unit);
|
|
|
|
// head-box, will be closed by print-block after {
|
|
|
|
ibox(s, 0u);
|
|
|
|
print_block(s, blk);
|
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::expr_copy(e) => { word_space(s, ~"copy"); print_expr(s, e); }
|
|
|
|
ast::expr_unary_move(e) => { word_space(s, ~"move"); print_expr(s, e); }
|
|
|
|
ast::expr_move(lhs, rhs) => {
|
2011-07-27 12:19:39 +00:00
|
|
|
print_expr(s, lhs);
|
|
|
|
space(s.s);
|
2012-07-14 05:57:48 +00:00
|
|
|
word_space(s, ~"<-");
|
2011-07-27 12:19:39 +00:00
|
|
|
print_expr(s, rhs);
|
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::expr_assign(lhs, rhs) => {
|
2011-07-27 12:19:39 +00:00
|
|
|
print_expr(s, lhs);
|
|
|
|
space(s.s);
|
2012-07-14 05:57:48 +00:00
|
|
|
word_space(s, ~"=");
|
2011-07-27 12:19:39 +00:00
|
|
|
print_expr(s, rhs);
|
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::expr_swap(lhs, rhs) => {
|
2011-07-27 12:19:39 +00:00
|
|
|
print_expr(s, lhs);
|
|
|
|
space(s.s);
|
2012-07-14 05:57:48 +00:00
|
|
|
word_space(s, ~"<->");
|
2011-07-27 12:19:39 +00:00
|
|
|
print_expr(s, rhs);
|
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::expr_assign_op(op, lhs, rhs) => {
|
2011-07-27 12:19:39 +00:00
|
|
|
print_expr(s, lhs);
|
|
|
|
space(s.s);
|
2011-08-27 21:42:29 +00:00
|
|
|
word(s.s, ast_util::binop_to_str(op));
|
2012-07-14 05:57:48 +00:00
|
|
|
word_space(s, ~"=");
|
2011-07-27 12:19:39 +00:00
|
|
|
print_expr(s, rhs);
|
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::expr_field(expr, id, tys) => {
|
2011-09-13 15:08:59 +00:00
|
|
|
// Deal with '10.x'
|
2011-09-15 08:59:06 +00:00
|
|
|
if ends_in_lit_int(expr) {
|
2011-09-13 15:08:59 +00:00
|
|
|
popen(s); print_expr(s, expr); pclose(s);
|
2011-09-15 08:59:06 +00:00
|
|
|
} else {
|
2011-09-15 09:15:14 +00:00
|
|
|
print_expr_parens_if_not_bot(s, expr);
|
2011-09-13 15:08:59 +00:00
|
|
|
}
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~".");
|
2012-06-10 07:49:59 +00:00
|
|
|
word(s.s, *id);
|
2011-12-19 09:21:31 +00:00
|
|
|
if vec::len(tys) > 0u {
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~"::<");
|
2011-12-19 09:21:31 +00:00
|
|
|
commasep(s, inconsistent, tys, print_type);
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~">");
|
2011-12-19 09:21:31 +00:00
|
|
|
}
|
2011-07-27 12:19:39 +00:00
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::expr_index(expr, index) => {
|
2011-09-15 09:15:14 +00:00
|
|
|
print_expr_parens_if_not_bot(s, expr);
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~"[");
|
2011-07-27 12:19:39 +00:00
|
|
|
print_expr(s, index);
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~"]");
|
2011-07-27 12:19:39 +00:00
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::expr_path(path) => print_path(s, path, true),
|
|
|
|
ast::expr_fail(maybe_fail_val) => {
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~"fail");
|
2012-08-06 19:34:08 +00:00
|
|
|
match maybe_fail_val {
|
2012-08-04 02:59:04 +00:00
|
|
|
some(expr) => { word(s.s, ~" "); print_expr(s, expr); }
|
|
|
|
_ => ()
|
2011-05-28 00:38:52 +00:00
|
|
|
}
|
2011-07-27 12:19:39 +00:00
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::expr_break => word(s.s, ~"break"),
|
|
|
|
ast::expr_again => word(s.s, ~"again"),
|
|
|
|
ast::expr_ret(result) => {
|
2012-08-02 00:30:05 +00:00
|
|
|
word(s.s, ~"return");
|
2012-08-06 19:34:08 +00:00
|
|
|
match result {
|
2012-08-04 02:59:04 +00:00
|
|
|
some(expr) => { word(s.s, ~" "); print_expr(s, expr); }
|
|
|
|
_ => ()
|
2011-03-24 15:33:20 +00:00
|
|
|
}
|
2011-07-27 12:19:39 +00:00
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::expr_log(lvl, lexp, expr) => {
|
2012-08-06 19:34:08 +00:00
|
|
|
match check lvl {
|
2012-08-04 02:59:04 +00:00
|
|
|
1 => { word_nbsp(s, ~"log"); print_expr(s, expr); }
|
|
|
|
0 => { word_nbsp(s, ~"log_err"); print_expr(s, expr); }
|
|
|
|
2 => {
|
2012-07-14 05:57:48 +00:00
|
|
|
word_nbsp(s, ~"log");
|
2011-12-22 02:05:08 +00:00
|
|
|
popen(s);
|
2011-12-21 22:31:31 +00:00
|
|
|
print_expr(s, lexp);
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~",");
|
2011-12-22 02:05:08 +00:00
|
|
|
space_if_not_bol(s);
|
|
|
|
print_expr(s, expr);
|
|
|
|
pclose(s);
|
2011-12-21 22:31:31 +00:00
|
|
|
}
|
|
|
|
}
|
2011-07-27 12:19:39 +00:00
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::expr_assert(expr) => {
|
2012-07-14 05:57:48 +00:00
|
|
|
word_nbsp(s, ~"assert");
|
2011-07-27 12:19:39 +00:00
|
|
|
print_expr(s, expr);
|
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::expr_mac(m) => print_mac(s, m),
|
2011-03-25 03:03:12 +00:00
|
|
|
}
|
2011-07-05 08:38:35 +00:00
|
|
|
s.ann.post(ann_node);
|
2011-06-01 22:29:38 +00:00
|
|
|
end(s);
|
2011-03-04 06:22:43 +00:00
|
|
|
}
|
|
|
|
|
2011-09-15 09:15:14 +00:00
|
|
|
fn print_expr_parens_if_not_bot(s: ps, ex: @ast::expr) {
|
2012-08-06 19:34:08 +00:00
|
|
|
let parens = match ex.node {
|
2011-10-21 11:42:26 +00:00
|
|
|
ast::expr_fail(_) | ast::expr_ret(_) |
|
2011-09-15 09:15:14 +00:00
|
|
|
ast::expr_binary(_, _, _) | ast::expr_unary(_, _) |
|
2012-01-30 16:40:54 +00:00
|
|
|
ast::expr_move(_, _) | ast::expr_copy(_) |
|
2012-05-14 23:55:01 +00:00
|
|
|
ast::expr_assign(_, _) |
|
2011-09-15 09:15:14 +00:00
|
|
|
ast::expr_assign_op(_, _, _) | ast::expr_swap(_, _) |
|
2011-12-21 22:31:31 +00:00
|
|
|
ast::expr_log(_, _, _) | ast::expr_assert(_) |
|
2012-01-05 06:01:58 +00:00
|
|
|
ast::expr_call(_, _, true) |
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::expr_vstore(_, _) => true,
|
|
|
|
_ => false
|
2011-09-13 15:02:36 +00:00
|
|
|
};
|
2011-07-27 11:48:28 +00:00
|
|
|
if parens { popen(s); }
|
|
|
|
print_expr(s, ex);
|
|
|
|
if parens { pclose(s); }
|
|
|
|
}
|
|
|
|
|
2011-09-12 09:27:30 +00:00
|
|
|
fn print_local_decl(s: ps, loc: @ast::local) {
|
2011-08-10 19:51:50 +00:00
|
|
|
print_pat(s, loc.node.pat);
|
2012-08-06 19:34:08 +00:00
|
|
|
match loc.node.ty.node {
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::ty_infer => (),
|
|
|
|
_ => { word_space(s, ~":"); print_type(s, loc.node.ty); }
|
2011-08-10 19:51:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-12 09:27:30 +00:00
|
|
|
fn print_decl(s: ps, decl: @ast::decl) {
|
2011-03-24 15:33:20 +00:00
|
|
|
maybe_print_comment(s, decl.span.lo);
|
2012-08-06 19:34:08 +00:00
|
|
|
match decl.node {
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::decl_local(locs) => {
|
2011-07-27 12:19:39 +00:00
|
|
|
space_if_not_bol(s);
|
|
|
|
ibox(s, indent_unit);
|
2012-07-14 05:57:48 +00:00
|
|
|
word_nbsp(s, ~"let");
|
2012-03-22 15:39:41 +00:00
|
|
|
|
2012-03-27 01:35:18 +00:00
|
|
|
// if any are mut, all are mut
|
2012-06-30 23:19:07 +00:00
|
|
|
if vec::any(locs, |l| l.node.is_mutbl) {
|
|
|
|
assert vec::all(locs, |l| l.node.is_mutbl);
|
2012-07-14 05:57:48 +00:00
|
|
|
word_nbsp(s, ~"mut");
|
2012-03-22 15:39:41 +00:00
|
|
|
}
|
|
|
|
|
2012-02-10 13:33:36 +00:00
|
|
|
fn print_local(s: ps, &&loc: @ast::local) {
|
2011-07-28 10:01:45 +00:00
|
|
|
ibox(s, indent_unit);
|
2011-08-10 19:51:50 +00:00
|
|
|
print_local_decl(s, loc);
|
2011-07-28 10:01:45 +00:00
|
|
|
end(s);
|
2012-08-06 19:34:08 +00:00
|
|
|
match loc.node.init {
|
2012-08-04 02:59:04 +00:00
|
|
|
some(init) => {
|
2011-07-27 12:19:39 +00:00
|
|
|
nbsp(s);
|
2012-08-06 19:34:08 +00:00
|
|
|
match init.op {
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::init_assign => word_space(s, ~"="),
|
|
|
|
ast::init_move => word_space(s, ~"<-")
|
2011-03-24 15:33:20 +00:00
|
|
|
}
|
2011-07-27 12:19:39 +00:00
|
|
|
print_expr(s, init.expr);
|
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
_ => ()
|
2011-03-25 03:03:12 +00:00
|
|
|
}
|
2011-03-04 06:22:43 +00:00
|
|
|
}
|
2011-07-27 14:24:41 +00:00
|
|
|
commasep(s, consistent, locs, print_local);
|
2011-07-27 12:19:39 +00:00
|
|
|
end(s);
|
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::decl_item(item) => print_item(s, item)
|
2011-03-04 06:22:43 +00:00
|
|
|
}
|
2011-03-24 15:33:20 +00:00
|
|
|
}
|
|
|
|
|
2012-06-10 07:49:59 +00:00
|
|
|
fn print_ident(s: ps, ident: ast::ident) { word(s.s, *ident); }
|
2011-04-05 21:18:44 +00:00
|
|
|
|
2011-09-12 09:27:30 +00:00
|
|
|
fn print_for_decl(s: ps, loc: @ast::local, coll: @ast::expr) {
|
2011-08-10 19:51:50 +00:00
|
|
|
print_local_decl(s, loc);
|
2011-06-14 00:04:15 +00:00
|
|
|
space(s.s);
|
2012-07-14 05:57:48 +00:00
|
|
|
word_space(s, ~"in");
|
2011-07-27 15:18:53 +00:00
|
|
|
print_expr(s, coll);
|
2011-03-04 06:22:43 +00:00
|
|
|
}
|
|
|
|
|
2011-11-30 12:38:38 +00:00
|
|
|
fn print_path(s: ps, &&path: @ast::path, colons_before_params: bool) {
|
2011-03-24 15:33:20 +00:00
|
|
|
maybe_print_comment(s, path.span.lo);
|
2012-07-14 05:57:48 +00:00
|
|
|
if path.global { word(s.s, ~"::"); }
|
2012-03-15 13:47:03 +00:00
|
|
|
let mut first = true;
|
2012-06-30 23:19:07 +00:00
|
|
|
for path.idents.each |id| {
|
2012-07-14 05:57:48 +00:00
|
|
|
if first { first = false; } else { word(s.s, ~"::"); }
|
2012-06-10 07:49:59 +00:00
|
|
|
word(s.s, *id);
|
2011-03-24 15:33:20 +00:00
|
|
|
}
|
2012-04-24 22:52:52 +00:00
|
|
|
if path.rp.is_some() || !path.types.is_empty() {
|
2012-07-14 05:57:48 +00:00
|
|
|
if colons_before_params { word(s.s, ~"::"); }
|
2012-04-24 22:52:52 +00:00
|
|
|
|
2012-08-06 19:34:08 +00:00
|
|
|
match path.rp {
|
2012-08-04 02:59:04 +00:00
|
|
|
none => { /* ok */ }
|
|
|
|
some(r) => {
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~"/");
|
2012-04-24 22:52:52 +00:00
|
|
|
print_region(s, r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !path.types.is_empty() {
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~"<");
|
2012-04-24 22:52:52 +00:00
|
|
|
commasep(s, inconsistent, path.types, print_type);
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~">");
|
2012-04-24 22:52:52 +00:00
|
|
|
}
|
2011-03-24 15:33:20 +00:00
|
|
|
}
|
2011-03-04 06:22:43 +00:00
|
|
|
}
|
|
|
|
|
2011-10-06 10:26:12 +00:00
|
|
|
fn print_pat(s: ps, &&pat: @ast::pat) {
|
2011-03-24 15:33:20 +00:00
|
|
|
maybe_print_comment(s, pat.span.lo);
|
2011-07-27 12:19:39 +00:00
|
|
|
let ann_node = node_pat(s, pat);
|
2011-07-05 08:38:35 +00:00
|
|
|
s.ann.pre(ann_node);
|
2012-01-15 00:05:07 +00:00
|
|
|
/* Pat isn't normalized, but the beauty of it
|
|
|
|
is that it doesn't matter */
|
2012-08-06 19:34:08 +00:00
|
|
|
match pat.node {
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::pat_wild => word(s.s, ~"_"),
|
|
|
|
ast::pat_ident(binding_mode, path, sub) => {
|
2012-08-06 19:34:08 +00:00
|
|
|
match binding_mode {
|
2012-08-06 14:20:23 +00:00
|
|
|
ast::bind_by_ref(mutbl) => {
|
|
|
|
word_nbsp(s, ~"ref");
|
|
|
|
print_mutability(s, mutbl);
|
|
|
|
}
|
|
|
|
ast::bind_by_implicit_ref |
|
|
|
|
ast::bind_by_value => {}
|
2012-08-01 02:25:24 +00:00
|
|
|
}
|
2012-01-15 00:05:07 +00:00
|
|
|
print_path(s, path, true);
|
2012-08-06 19:34:08 +00:00
|
|
|
match sub {
|
2012-08-01 02:25:24 +00:00
|
|
|
some(p) => { word(s.s, ~"@"); print_pat(s, p); }
|
2012-08-04 02:59:04 +00:00
|
|
|
none => ()
|
2011-12-08 10:56:16 +00:00
|
|
|
}
|
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::pat_enum(path, args_) => {
|
2011-08-16 16:03:58 +00:00
|
|
|
print_path(s, path, true);
|
2012-08-06 19:34:08 +00:00
|
|
|
match args_ {
|
2012-08-04 02:59:04 +00:00
|
|
|
none => word(s.s, ~"(*)"),
|
|
|
|
some(args) => {
|
2012-04-20 07:54:42 +00:00
|
|
|
if vec::len(args) > 0u {
|
|
|
|
popen(s);
|
|
|
|
commasep(s, inconsistent, args, print_pat);
|
|
|
|
pclose(s);
|
|
|
|
} else { }
|
|
|
|
}
|
|
|
|
}
|
2011-07-27 12:19:39 +00:00
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::pat_rec(fields, etc) => {
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~"{");
|
2011-09-12 09:27:30 +00:00
|
|
|
fn print_field(s: ps, f: ast::field_pat) {
|
2011-07-27 12:19:39 +00:00
|
|
|
cbox(s, indent_unit);
|
2012-06-10 07:49:59 +00:00
|
|
|
word(s.s, *f.ident);
|
2012-07-14 05:57:48 +00:00
|
|
|
word_space(s, ~":");
|
2012-08-07 00:01:14 +00:00
|
|
|
print_pat(s, f.pat);
|
|
|
|
end(s);
|
|
|
|
}
|
|
|
|
fn get_span(f: ast::field_pat) -> codemap::span { return f.pat.span; }
|
|
|
|
commasep_cmnt(s, consistent, fields, print_field, get_span);
|
|
|
|
if etc {
|
|
|
|
if vec::len(fields) != 0u { word_space(s, ~","); }
|
|
|
|
word(s.s, ~"_");
|
|
|
|
}
|
|
|
|
word(s.s, ~"}");
|
|
|
|
}
|
|
|
|
ast::pat_struct(path, fields, etc) => {
|
|
|
|
print_path(s, path, true);
|
|
|
|
word(s.s, ~"{");
|
|
|
|
fn print_field(s: ps, f: ast::field_pat) {
|
|
|
|
cbox(s, indent_unit);
|
|
|
|
word(s.s, *f.ident);
|
|
|
|
word_space(s, ~":");
|
2011-07-27 12:19:39 +00:00
|
|
|
print_pat(s, f.pat);
|
|
|
|
end(s);
|
2011-07-11 12:13:20 +00:00
|
|
|
}
|
2012-08-02 00:30:05 +00:00
|
|
|
fn get_span(f: ast::field_pat) -> codemap::span { return f.pat.span; }
|
2011-07-27 12:19:39 +00:00
|
|
|
commasep_cmnt(s, consistent, fields, print_field, get_span);
|
|
|
|
if etc {
|
2012-07-14 05:57:48 +00:00
|
|
|
if vec::len(fields) != 0u { word_space(s, ~","); }
|
|
|
|
word(s.s, ~"_");
|
2011-07-13 08:50:16 +00:00
|
|
|
}
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~"}");
|
2011-07-27 12:19:39 +00:00
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::pat_tup(elts) => {
|
2011-08-15 11:15:19 +00:00
|
|
|
popen(s);
|
|
|
|
commasep(s, inconsistent, elts, print_pat);
|
|
|
|
pclose(s);
|
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::pat_box(inner) => { word(s.s, ~"@"); print_pat(s, inner); }
|
|
|
|
ast::pat_uniq(inner) => { word(s.s, ~"~"); print_pat(s, inner); }
|
|
|
|
ast::pat_lit(e) => print_expr(s, e),
|
|
|
|
ast::pat_range(begin, end) => {
|
2011-12-02 12:42:51 +00:00
|
|
|
print_expr(s, begin);
|
2011-09-28 19:07:33 +00:00
|
|
|
space(s.s);
|
2012-07-14 05:57:48 +00:00
|
|
|
word_space(s, ~"to");
|
2011-12-02 12:42:51 +00:00
|
|
|
print_expr(s, end);
|
2011-09-28 19:07:33 +00:00
|
|
|
}
|
2011-03-04 06:22:43 +00:00
|
|
|
}
|
2011-07-05 08:38:35 +00:00
|
|
|
s.ann.post(ann_node);
|
2011-03-04 06:22:43 +00:00
|
|
|
}
|
|
|
|
|
2011-12-22 16:49:54 +00:00
|
|
|
fn print_fn(s: ps, decl: ast::fn_decl, name: ast::ident,
|
2012-08-02 23:01:38 +00:00
|
|
|
typarams: ~[ast::ty_param],
|
|
|
|
opt_self_ty: option<ast::self_ty_>) {
|
|
|
|
head(s, fn_header_info_to_str(opt_self_ty, decl.purity, none));
|
2012-06-10 07:49:59 +00:00
|
|
|
word(s.s, *name);
|
2011-03-24 15:33:20 +00:00
|
|
|
print_type_params(s, typarams);
|
2012-06-29 23:26:56 +00:00
|
|
|
print_fn_args_and_ret(s, decl, ~[]);
|
2011-06-14 13:20:04 +00:00
|
|
|
}
|
|
|
|
|
2012-05-04 19:33:04 +00:00
|
|
|
fn print_fn_args(s: ps, decl: ast::fn_decl,
|
2012-06-29 23:26:56 +00:00
|
|
|
cap_items: ~[ast::capture_item]) {
|
2012-05-04 19:33:04 +00:00
|
|
|
commasep(s, inconsistent, decl.inputs, print_arg);
|
|
|
|
if cap_items.is_not_empty() {
|
|
|
|
let mut first = decl.inputs.is_empty();
|
2012-06-30 23:19:07 +00:00
|
|
|
for cap_items.each |cap_item| {
|
2012-07-14 05:57:48 +00:00
|
|
|
if first { first = false; } else { word_space(s, ~","); }
|
|
|
|
if cap_item.is_move { word_nbsp(s, ~"move") }
|
|
|
|
else { word_nbsp(s, ~"copy") }
|
2012-06-10 07:49:59 +00:00
|
|
|
word(s.s, *cap_item.name);
|
2011-12-30 21:32:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-04 19:33:04 +00:00
|
|
|
fn print_fn_args_and_ret(s: ps, decl: ast::fn_decl,
|
2012-06-29 23:26:56 +00:00
|
|
|
cap_items: ~[ast::capture_item]) {
|
2011-03-24 15:33:20 +00:00
|
|
|
popen(s);
|
2012-05-04 19:33:04 +00:00
|
|
|
print_fn_args(s, decl, cap_items);
|
2011-03-24 15:33:20 +00:00
|
|
|
pclose(s);
|
2012-02-22 10:16:25 +00:00
|
|
|
|
2011-03-24 15:33:20 +00:00
|
|
|
maybe_print_comment(s, decl.output.span.lo);
|
2011-07-27 12:19:39 +00:00
|
|
|
if decl.output.node != ast::ty_nil {
|
2011-07-26 22:37:05 +00:00
|
|
|
space_if_not_bol(s);
|
2012-07-14 05:57:48 +00:00
|
|
|
word_space(s, ~"->");
|
2011-08-15 11:45:04 +00:00
|
|
|
print_type(s, decl.output);
|
2011-03-24 15:33:20 +00:00
|
|
|
}
|
2011-03-04 06:22:43 +00:00
|
|
|
}
|
|
|
|
|
2012-05-04 19:33:04 +00:00
|
|
|
fn print_fn_block_args(s: ps, decl: ast::fn_decl,
|
2012-06-29 23:26:56 +00:00
|
|
|
cap_items: ~[ast::capture_item]) {
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~"|");
|
2012-05-04 19:33:04 +00:00
|
|
|
print_fn_args(s, decl, cap_items);
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~"|");
|
2011-12-21 00:18:18 +00:00
|
|
|
if decl.output.node != ast::ty_infer {
|
|
|
|
space_if_not_bol(s);
|
2012-07-14 05:57:48 +00:00
|
|
|
word_space(s, ~"->");
|
2011-12-21 00:18:18 +00:00
|
|
|
print_type(s, decl.output);
|
|
|
|
}
|
2011-08-15 21:42:33 +00:00
|
|
|
maybe_print_comment(s, decl.output.span.lo);
|
|
|
|
}
|
|
|
|
|
2012-07-14 05:57:48 +00:00
|
|
|
fn mode_to_str(m: ast::mode) -> ~str {
|
2012-08-06 19:34:08 +00:00
|
|
|
match m {
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::expl(ast::by_mutbl_ref) => ~"&",
|
|
|
|
ast::expl(ast::by_move) => ~"-",
|
|
|
|
ast::expl(ast::by_ref) => ~"&&",
|
|
|
|
ast::expl(ast::by_val) => ~"++",
|
|
|
|
ast::expl(ast::by_copy) => ~"+",
|
|
|
|
ast::infer(_) => ~""
|
2011-06-10 10:03:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-03 00:50:17 +00:00
|
|
|
fn print_arg_mode(s: ps, m: ast::mode) {
|
|
|
|
let ms = mode_to_str(m);
|
2012-07-14 05:57:48 +00:00
|
|
|
if ms != ~"" { word(s.s, ms); }
|
2012-02-03 00:50:17 +00:00
|
|
|
}
|
|
|
|
|
2012-06-29 23:26:56 +00:00
|
|
|
fn print_bounds(s: ps, bounds: @~[ast::ty_param_bound]) {
|
2011-12-28 16:50:12 +00:00
|
|
|
if vec::len(*bounds) > 0u {
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~":");
|
2012-06-30 23:19:07 +00:00
|
|
|
for vec::each(*bounds) |bound| {
|
2011-12-28 16:50:12 +00:00
|
|
|
nbsp(s);
|
2012-08-06 19:34:08 +00:00
|
|
|
match bound {
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::bound_copy => word(s.s, ~"copy"),
|
|
|
|
ast::bound_send => word(s.s, ~"send"),
|
|
|
|
ast::bound_const => word(s.s, ~"const"),
|
|
|
|
ast::bound_owned => word(s.s, ~"owned"),
|
|
|
|
ast::bound_trait(t) => print_type(s, t)
|
2011-12-28 16:50:12 +00:00
|
|
|
}
|
|
|
|
}
|
2011-08-03 04:26:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-29 23:26:56 +00:00
|
|
|
fn print_type_params(s: ps, &¶ms: ~[ast::ty_param]) {
|
2011-08-15 23:38:23 +00:00
|
|
|
if vec::len(params) > 0u {
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~"<");
|
2011-09-12 09:27:30 +00:00
|
|
|
fn printParam(s: ps, param: ast::ty_param) {
|
2012-06-10 07:49:59 +00:00
|
|
|
word(s.s, *param.ident);
|
2011-12-28 16:50:12 +00:00
|
|
|
print_bounds(s, param.bounds);
|
2011-07-28 17:22:59 +00:00
|
|
|
}
|
2011-07-12 23:13:30 +00:00
|
|
|
commasep(s, inconsistent, params, printParam);
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~">");
|
2011-03-24 15:33:20 +00:00
|
|
|
}
|
2011-03-04 06:22:43 +00:00
|
|
|
}
|
|
|
|
|
2011-10-06 10:26:12 +00:00
|
|
|
fn print_meta_item(s: ps, &&item: @ast::meta_item) {
|
2011-06-15 01:53:12 +00:00
|
|
|
ibox(s, indent_unit);
|
2012-08-06 19:34:08 +00:00
|
|
|
match item.node {
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::meta_word(name) => word(s.s, *name),
|
|
|
|
ast::meta_name_value(name, value) => {
|
2012-06-10 07:49:59 +00:00
|
|
|
word_space(s, *name);
|
2012-07-14 05:57:48 +00:00
|
|
|
word_space(s, ~"=");
|
2011-07-27 12:19:39 +00:00
|
|
|
print_literal(s, @value);
|
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::meta_list(name, items) => {
|
2012-06-10 07:49:59 +00:00
|
|
|
word(s.s, *name);
|
2011-07-27 12:19:39 +00:00
|
|
|
popen(s);
|
|
|
|
commasep(s, consistent, items, print_meta_item);
|
|
|
|
pclose(s);
|
|
|
|
}
|
2011-06-21 21:23:16 +00:00
|
|
|
}
|
2011-06-15 01:53:12 +00:00
|
|
|
end(s);
|
|
|
|
}
|
|
|
|
|
2012-02-18 07:05:20 +00:00
|
|
|
fn print_view_path(s: ps, &&vp: @ast::view_path) {
|
2012-08-06 19:34:08 +00:00
|
|
|
match vp.node {
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::view_path_simple(ident, path, _) => {
|
2012-04-23 11:04:46 +00:00
|
|
|
if path.idents[vec::len(path.idents)-1u] != ident {
|
2012-06-10 07:49:59 +00:00
|
|
|
word_space(s, *ident);
|
2012-07-14 05:57:48 +00:00
|
|
|
word_space(s, ~"=");
|
2012-02-18 07:05:20 +00:00
|
|
|
}
|
2012-04-13 08:46:56 +00:00
|
|
|
print_path(s, path, false);
|
2012-02-18 07:05:20 +00:00
|
|
|
}
|
|
|
|
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::view_path_glob(path, _) => {
|
2012-04-13 08:46:56 +00:00
|
|
|
print_path(s, path, false);
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~"::*");
|
2012-02-18 07:05:20 +00:00
|
|
|
}
|
|
|
|
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::view_path_list(path, idents, _) => {
|
2012-04-13 08:46:56 +00:00
|
|
|
print_path(s, path, false);
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~"::{");
|
2012-06-30 23:19:07 +00:00
|
|
|
do commasep(s, inconsistent, idents) |s, w| {
|
2012-06-10 07:49:59 +00:00
|
|
|
word(s.s, *w.node.name)
|
2012-02-18 07:05:20 +00:00
|
|
|
}
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~"}");
|
2012-02-18 07:05:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-29 23:26:56 +00:00
|
|
|
fn print_view_paths(s: ps, vps: ~[@ast::view_path]) {
|
2012-02-18 07:05:20 +00:00
|
|
|
commasep(s, inconsistent, vps, print_view_path);
|
|
|
|
}
|
|
|
|
|
2011-09-12 09:27:30 +00:00
|
|
|
fn print_view_item(s: ps, item: @ast::view_item) {
|
2011-06-20 16:15:11 +00:00
|
|
|
hardbreak_if_not_bol(s);
|
2011-03-24 15:33:20 +00:00
|
|
|
maybe_print_comment(s, item.span.lo);
|
2012-07-09 22:39:56 +00:00
|
|
|
print_outer_attributes(s, item.attrs);
|
2012-08-06 19:34:08 +00:00
|
|
|
match item.node {
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::view_item_use(id, mta, _) => {
|
2012-07-14 05:57:48 +00:00
|
|
|
head(s, ~"use");
|
2012-06-10 07:49:59 +00:00
|
|
|
word(s.s, *id);
|
2011-08-15 23:38:23 +00:00
|
|
|
if vec::len(mta) > 0u {
|
2011-07-27 12:19:39 +00:00
|
|
|
popen(s);
|
|
|
|
commasep(s, consistent, mta, print_meta_item);
|
|
|
|
pclose(s);
|
2011-03-24 15:33:20 +00:00
|
|
|
}
|
2011-07-27 12:19:39 +00:00
|
|
|
}
|
2012-02-18 07:05:20 +00:00
|
|
|
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::view_item_import(vps) => {
|
2012-07-14 05:57:48 +00:00
|
|
|
head(s, ~"import");
|
2012-02-18 07:05:20 +00:00
|
|
|
print_view_paths(s, vps);
|
2011-07-27 12:19:39 +00:00
|
|
|
}
|
2012-02-18 07:05:20 +00:00
|
|
|
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::view_item_export(vps) => {
|
2012-07-14 05:57:48 +00:00
|
|
|
head(s, ~"export");
|
2012-02-18 07:05:20 +00:00
|
|
|
print_view_paths(s, vps);
|
Export all enum variants by default; new syntax for selectively exporting variants
See issue 1426 for details. Now, the semantics of "export t;" where t is a tag are
to export all of t's variants as well. "export t{};" exports t but not its
variants, while "export t{a, b, c};" exports only variants a, b, c of t.
To do:
- documentation
- there's currently no checking that a, b, c are actually variants of t in the
above example
- there's also no checking that t is an enum type, in the second two examples above
- change the modules listed in issue 1426 that should have the old export
semantics to use the t{} syntax
I deleted the test export-no-tag-variants since we're doing the opposite now,
and other tests cover the same behavior.
2012-01-23 05:09:43 +00:00
|
|
|
}
|
2011-03-04 06:22:43 +00:00
|
|
|
}
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~";");
|
2011-06-01 22:29:38 +00:00
|
|
|
end(s); // end inner head-block
|
|
|
|
end(s); // end outer head-block
|
2011-03-04 06:22:43 +00:00
|
|
|
}
|
|
|
|
|
2012-04-26 23:13:59 +00:00
|
|
|
fn print_op_maybe_parens(s: ps, expr: @ast::expr, outer_prec: uint) {
|
2011-08-19 00:33:12 +00:00
|
|
|
let add_them = need_parens(expr, outer_prec);
|
2011-07-27 12:19:39 +00:00
|
|
|
if add_them { popen(s); }
|
2011-03-24 15:33:20 +00:00
|
|
|
print_expr(s, expr);
|
2011-07-27 12:19:39 +00:00
|
|
|
if add_them { pclose(s); }
|
2011-03-04 06:22:43 +00:00
|
|
|
}
|
|
|
|
|
2012-02-15 19:25:39 +00:00
|
|
|
fn print_mutability(s: ps, mutbl: ast::mutability) {
|
2012-08-06 19:34:08 +00:00
|
|
|
match mutbl {
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::m_mutbl => word_nbsp(s, ~"mut"),
|
|
|
|
ast::m_const => word_nbsp(s, ~"const"),
|
|
|
|
ast::m_imm => {/* nothing */ }
|
2011-03-24 15:33:20 +00:00
|
|
|
}
|
2011-06-15 17:25:23 +00:00
|
|
|
}
|
|
|
|
|
2011-09-12 09:27:30 +00:00
|
|
|
fn print_mt(s: ps, mt: ast::mt) {
|
2012-02-15 19:25:39 +00:00
|
|
|
print_mutability(s, mt.mutbl);
|
2011-08-15 11:45:04 +00:00
|
|
|
print_type(s, mt.ty);
|
2011-03-04 06:22:43 +00:00
|
|
|
}
|
|
|
|
|
2012-05-04 19:33:04 +00:00
|
|
|
fn print_arg(s: ps, input: ast::arg) {
|
|
|
|
ibox(s, indent_unit);
|
|
|
|
print_arg_mode(s, input.mode);
|
2012-08-06 19:34:08 +00:00
|
|
|
match input.ty.node {
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::ty_infer => word(s.s, *input.ident),
|
|
|
|
_ => {
|
2012-06-10 07:49:59 +00:00
|
|
|
if str::len(*input.ident) > 0u {
|
2012-07-14 05:57:48 +00:00
|
|
|
word_space(s, *input.ident + ~":");
|
2012-05-04 19:33:04 +00:00
|
|
|
}
|
|
|
|
print_type(s, input.ty);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end(s);
|
|
|
|
}
|
|
|
|
|
2012-01-11 20:52:25 +00:00
|
|
|
fn print_ty_fn(s: ps, opt_proto: option<ast::proto>,
|
2012-08-07 01:54:20 +00:00
|
|
|
bounds: @~[ast::ty_param_bound],
|
2012-02-01 01:05:20 +00:00
|
|
|
decl: ast::fn_decl, id: option<ast::ident>,
|
2012-08-02 23:01:38 +00:00
|
|
|
tps: option<~[ast::ty_param]>,
|
|
|
|
opt_self_ty: option<ast::self_ty_>) {
|
2011-06-01 22:29:38 +00:00
|
|
|
ibox(s, indent_unit);
|
2012-08-02 23:01:38 +00:00
|
|
|
word(s.s, fn_header_info_to_str(opt_self_ty, decl.purity, opt_proto));
|
2012-08-07 01:54:20 +00:00
|
|
|
print_bounds(s, bounds);
|
2012-08-06 19:34:08 +00:00
|
|
|
match id { some(id) => { word(s.s, ~" "); word(s.s, *id); } _ => () }
|
|
|
|
match tps { some(tps) => print_type_params(s, tps), _ => () }
|
2011-06-03 00:36:28 +00:00
|
|
|
zerobreak(s.s);
|
2011-05-29 02:16:18 +00:00
|
|
|
popen(s);
|
2011-12-23 12:32:17 +00:00
|
|
|
commasep(s, inconsistent, decl.inputs, print_arg);
|
2011-03-24 15:33:20 +00:00
|
|
|
pclose(s);
|
2011-12-23 12:32:17 +00:00
|
|
|
maybe_print_comment(s, decl.output.span.lo);
|
|
|
|
if decl.output.node != ast::ty_nil {
|
2011-07-26 22:37:05 +00:00
|
|
|
space_if_not_bol(s);
|
2011-06-01 22:29:38 +00:00
|
|
|
ibox(s, indent_unit);
|
2012-07-14 05:57:48 +00:00
|
|
|
word_space(s, ~"->");
|
|
|
|
if decl.cf == ast::noreturn { word_nbsp(s, ~"!"); }
|
2011-12-23 12:32:17 +00:00
|
|
|
else { print_type(s, decl.output); }
|
2011-06-01 22:29:38 +00:00
|
|
|
end(s);
|
2011-03-24 15:33:20 +00:00
|
|
|
}
|
2011-06-01 22:29:38 +00:00
|
|
|
end(s);
|
2011-03-24 15:33:20 +00:00
|
|
|
}
|
|
|
|
|
2011-09-12 09:27:30 +00:00
|
|
|
fn maybe_print_trailing_comment(s: ps, span: codemap::span,
|
2012-02-01 01:05:20 +00:00
|
|
|
next_pos: option<uint>) {
|
2012-03-15 13:47:03 +00:00
|
|
|
let mut cm;
|
2012-08-06 19:34:08 +00:00
|
|
|
match s.cm { some(ccm) => cm = ccm, _ => return }
|
|
|
|
match next_comment(s) {
|
2012-08-04 02:59:04 +00:00
|
|
|
some(cmnt) => {
|
2012-08-02 00:30:05 +00:00
|
|
|
if cmnt.style != comments::trailing { return; }
|
2011-07-27 12:19:39 +00:00
|
|
|
let span_line = codemap::lookup_char_pos(cm, span.hi);
|
|
|
|
let comment_line = codemap::lookup_char_pos(cm, cmnt.pos);
|
2012-03-15 13:47:03 +00:00
|
|
|
let mut next = cmnt.pos + 1u;
|
2012-08-06 19:34:08 +00:00
|
|
|
match next_pos { none => (), some(p) => next = p }
|
2011-07-27 12:19:39 +00:00
|
|
|
if span.hi < cmnt.pos && cmnt.pos < next &&
|
|
|
|
span_line.line == comment_line.line {
|
|
|
|
print_comment(s, cmnt);
|
|
|
|
s.cur_cmnt += 1u;
|
2011-03-24 15:33:20 +00:00
|
|
|
}
|
2011-07-27 12:19:39 +00:00
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
_ => ()
|
2011-03-24 15:33:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-12 09:27:30 +00:00
|
|
|
fn print_remaining_comments(s: ps) {
|
2011-08-04 00:52:25 +00:00
|
|
|
// If there aren't any remaining comments, then we need to manually
|
|
|
|
// make sure there is a line break at the end.
|
|
|
|
if option::is_none(next_comment(s)) { hardbreak(s.s); }
|
2012-03-11 04:34:17 +00:00
|
|
|
loop {
|
2012-08-06 19:34:08 +00:00
|
|
|
match next_comment(s) {
|
2012-08-04 02:59:04 +00:00
|
|
|
some(cmnt) => { print_comment(s, cmnt); s.cur_cmnt += 1u; }
|
|
|
|
_ => break
|
2011-03-24 15:33:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-06 10:26:12 +00:00
|
|
|
fn print_literal(s: ps, &&lit: @ast::lit) {
|
2011-07-05 09:48:19 +00:00
|
|
|
maybe_print_comment(s, lit.span.lo);
|
2012-08-06 19:34:08 +00:00
|
|
|
match next_lit(s, lit.span.lo) {
|
2012-08-04 02:59:04 +00:00
|
|
|
some(ltrl) => {
|
2012-06-27 23:16:38 +00:00
|
|
|
word(s.s, ltrl.lit);
|
2012-08-02 00:30:05 +00:00
|
|
|
return;
|
2011-07-27 12:19:39 +00:00
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
_ => ()
|
2011-07-05 09:48:19 +00:00
|
|
|
}
|
2012-08-06 19:34:08 +00:00
|
|
|
match lit.node {
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::lit_str(st) => print_string(s, *st),
|
|
|
|
ast::lit_int(ch, ast::ty_char) => {
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~"'" + char::escape_default(ch as char) + ~"'");
|
2011-12-07 20:06:12 +00:00
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::lit_int(i, t) => {
|
2012-02-04 01:39:39 +00:00
|
|
|
if i < 0_i64 {
|
|
|
|
word(s.s,
|
2012-07-14 05:57:48 +00:00
|
|
|
~"-" + u64::to_str(-i as u64, 10u)
|
2012-02-04 01:39:39 +00:00
|
|
|
+ ast_util::int_ty_to_str(t));
|
|
|
|
} else {
|
|
|
|
word(s.s,
|
|
|
|
u64::to_str(i as u64, 10u)
|
|
|
|
+ ast_util::int_ty_to_str(t));
|
|
|
|
}
|
2011-12-07 20:06:12 +00:00
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::lit_uint(u, t) => {
|
2012-02-04 01:39:39 +00:00
|
|
|
word(s.s,
|
|
|
|
u64::to_str(u, 10u)
|
|
|
|
+ ast_util::uint_ty_to_str(t));
|
2011-12-07 20:06:12 +00:00
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::lit_int_unsuffixed(i) => {
|
2012-06-11 23:31:03 +00:00
|
|
|
if i < 0_i64 {
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~"-" + u64::to_str(-i as u64, 10u));
|
2012-06-11 23:31:03 +00:00
|
|
|
} else {
|
2012-06-15 02:41:40 +00:00
|
|
|
word(s.s, u64::to_str(i as u64, 10u));
|
2012-06-11 23:31:03 +00:00
|
|
|
}
|
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::lit_float(f, t) => {
|
2012-06-10 07:49:59 +00:00
|
|
|
word(s.s, *f + ast_util::float_ty_to_str(t));
|
2011-07-27 12:19:39 +00:00
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::lit_nil => word(s.s, ~"()"),
|
|
|
|
ast::lit_bool(val) => {
|
2012-07-14 05:57:48 +00:00
|
|
|
if val { word(s.s, ~"true"); } else { word(s.s, ~"false"); }
|
2011-07-27 12:19:39 +00:00
|
|
|
}
|
2011-07-05 09:48:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-02 00:30:05 +00:00
|
|
|
fn lit_to_str(l: @ast::lit) -> ~str { return to_str(l, print_literal); }
|
2011-07-05 09:48:19 +00:00
|
|
|
|
2012-04-15 10:27:24 +00:00
|
|
|
fn next_lit(s: ps, pos: uint) -> option<comments::lit> {
|
2012-08-06 19:34:08 +00:00
|
|
|
match s.literals {
|
2012-08-04 02:59:04 +00:00
|
|
|
some(lits) => {
|
2012-01-16 09:50:34 +00:00
|
|
|
while s.cur_lit < vec::len(lits) {
|
2012-06-27 23:16:38 +00:00
|
|
|
let ltrl = lits[s.cur_lit];
|
2012-08-02 00:30:05 +00:00
|
|
|
if ltrl.pos > pos { return none; }
|
2012-01-16 09:50:34 +00:00
|
|
|
s.cur_lit += 1u;
|
2012-08-02 00:30:05 +00:00
|
|
|
if ltrl.pos == pos { return some(ltrl); }
|
2012-01-16 09:50:34 +00:00
|
|
|
}
|
2012-08-02 00:30:05 +00:00
|
|
|
return none;
|
2011-07-27 12:19:39 +00:00
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
_ => return none
|
2011-07-05 09:48:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-12 09:27:30 +00:00
|
|
|
fn maybe_print_comment(s: ps, pos: uint) {
|
2012-03-11 04:34:17 +00:00
|
|
|
loop {
|
2012-08-06 19:34:08 +00:00
|
|
|
match next_comment(s) {
|
2012-08-04 02:59:04 +00:00
|
|
|
some(cmnt) => {
|
2011-07-27 12:19:39 +00:00
|
|
|
if cmnt.pos < pos {
|
|
|
|
print_comment(s, cmnt);
|
|
|
|
s.cur_cmnt += 1u;
|
|
|
|
} else { break; }
|
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
_ => break
|
2011-07-05 09:48:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-15 10:27:24 +00:00
|
|
|
fn print_comment(s: ps, cmnt: comments::cmnt) {
|
2012-08-06 19:34:08 +00:00
|
|
|
match cmnt.style {
|
2012-08-04 02:59:04 +00:00
|
|
|
comments::mixed => {
|
2011-08-15 23:38:23 +00:00
|
|
|
assert (vec::len(cmnt.lines) == 1u);
|
2011-07-27 12:19:39 +00:00
|
|
|
zerobreak(s.s);
|
2011-08-27 08:16:40 +00:00
|
|
|
word(s.s, cmnt.lines[0]);
|
2011-07-27 12:19:39 +00:00
|
|
|
zerobreak(s.s);
|
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
comments::isolated => {
|
2011-07-27 12:19:39 +00:00
|
|
|
pprust::hardbreak_if_not_bol(s);
|
2012-06-30 23:19:07 +00:00
|
|
|
for cmnt.lines.each |line| {
|
2011-08-19 02:19:38 +00:00
|
|
|
// Don't print empty lines because they will end up as trailing
|
|
|
|
// whitespace
|
2011-09-02 22:34:58 +00:00
|
|
|
if str::is_not_empty(line) { word(s.s, line); }
|
2011-08-19 02:19:38 +00:00
|
|
|
hardbreak(s.s);
|
|
|
|
}
|
2011-07-27 12:19:39 +00:00
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
comments::trailing => {
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~" ");
|
2011-08-15 23:38:23 +00:00
|
|
|
if vec::len(cmnt.lines) == 1u {
|
2011-08-27 08:16:40 +00:00
|
|
|
word(s.s, cmnt.lines[0]);
|
2011-07-05 09:48:19 +00:00
|
|
|
hardbreak(s.s);
|
2011-07-27 12:19:39 +00:00
|
|
|
} else {
|
|
|
|
ibox(s, 0u);
|
2012-06-30 23:19:07 +00:00
|
|
|
for cmnt.lines.each |line| {
|
2011-09-02 22:34:58 +00:00
|
|
|
if str::is_not_empty(line) { word(s.s, line); }
|
2011-08-19 02:19:38 +00:00
|
|
|
hardbreak(s.s);
|
|
|
|
}
|
2011-07-27 12:19:39 +00:00
|
|
|
end(s);
|
2011-07-05 09:48:19 +00:00
|
|
|
}
|
2011-07-27 12:19:39 +00:00
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
comments::blank_line => {
|
2011-07-27 12:19:39 +00:00
|
|
|
// We need to do at least one, possibly two hardbreaks.
|
2011-08-19 22:16:48 +00:00
|
|
|
let is_semi =
|
2012-08-06 19:34:08 +00:00
|
|
|
match s.s.last_token() {
|
2012-08-04 02:59:04 +00:00
|
|
|
pp::STRING(s, _) => *s == ~";",
|
|
|
|
_ => false
|
2011-08-19 22:16:48 +00:00
|
|
|
};
|
2011-09-16 14:57:54 +00:00
|
|
|
if is_semi || is_begin(s) || is_end(s) { hardbreak(s.s); }
|
2011-07-27 12:19:39 +00:00
|
|
|
hardbreak(s.s);
|
|
|
|
}
|
2011-07-05 09:48:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-14 05:57:48 +00:00
|
|
|
fn print_string(s: ps, st: ~str) {
|
|
|
|
word(s.s, ~"\"");
|
2012-05-31 22:31:13 +00:00
|
|
|
word(s.s, str::escape_default(st));
|
2012-07-14 05:57:48 +00:00
|
|
|
word(s.s, ~"\"");
|
2011-07-05 09:48:19 +00:00
|
|
|
}
|
|
|
|
|
2012-07-14 05:57:48 +00:00
|
|
|
fn to_str<T>(t: T, f: fn@(ps, T)) -> ~str {
|
2012-03-13 14:55:45 +00:00
|
|
|
let buffer = io::mem_buffer();
|
2012-01-11 14:15:54 +00:00
|
|
|
let s = rust_printer(io::mem_buffer_writer(buffer));
|
2011-07-05 09:48:19 +00:00
|
|
|
f(s, t);
|
|
|
|
eof(s.s);
|
2012-01-11 14:15:54 +00:00
|
|
|
io::mem_buffer_str(buffer)
|
2011-07-05 09:48:19 +00:00
|
|
|
}
|
|
|
|
|
2012-04-15 10:27:24 +00:00
|
|
|
fn next_comment(s: ps) -> option<comments::cmnt> {
|
2012-08-06 19:34:08 +00:00
|
|
|
match s.comments {
|
2012-08-04 02:59:04 +00:00
|
|
|
some(cmnts) => {
|
2011-08-15 23:38:23 +00:00
|
|
|
if s.cur_cmnt < vec::len(cmnts) {
|
2012-08-02 00:30:05 +00:00
|
|
|
return some(cmnts[s.cur_cmnt]);
|
|
|
|
} else { return none::<comments::cmnt>; }
|
2011-07-27 12:19:39 +00:00
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
_ => return none::<comments::cmnt>
|
2011-07-05 09:48:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-02 23:01:38 +00:00
|
|
|
fn fn_header_info_to_str(opt_sty: option<ast::self_ty_>,
|
|
|
|
purity: ast::purity,
|
|
|
|
opt_p: option<ast::proto>) -> ~str {
|
|
|
|
let mut s = match opt_sty {
|
|
|
|
some(ast::sty_static) => ~"static ",
|
|
|
|
_ => ~ ""
|
|
|
|
};
|
|
|
|
|
|
|
|
match purity {
|
|
|
|
ast::impure_fn => { }
|
|
|
|
_ => {
|
|
|
|
str::push_str(s, purity_to_str(purity));
|
|
|
|
str::push_char(s, ' ');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
str::push_str(s, opt_proto_to_str(opt_p));
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2012-07-14 05:57:48 +00:00
|
|
|
fn opt_proto_to_str(opt_p: option<ast::proto>) -> ~str {
|
2012-08-06 19:34:08 +00:00
|
|
|
match opt_p {
|
2012-08-04 02:59:04 +00:00
|
|
|
none => ~"fn",
|
|
|
|
some(p) => proto_to_str(p)
|
2012-01-11 20:52:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-02 22:42:56 +00:00
|
|
|
pure fn purity_to_str(p: ast::purity) -> ~str {
|
2012-08-06 19:34:08 +00:00
|
|
|
match p {
|
2012-08-02 22:42:56 +00:00
|
|
|
ast::impure_fn => ~"impure",
|
|
|
|
ast::unsafe_fn => ~"unsafe",
|
|
|
|
ast::pure_fn => ~"pure",
|
|
|
|
ast::extern_fn => ~"extern"
|
2012-05-25 06:44:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn print_purity(s: ps, p: ast::purity) {
|
2012-08-06 19:34:08 +00:00
|
|
|
match p {
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::impure_fn => (),
|
|
|
|
_ => word_nbsp(s, purity_to_str(p))
|
2012-05-25 06:44:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-14 05:57:48 +00:00
|
|
|
fn proto_to_str(p: ast::proto) -> ~str {
|
2012-08-06 19:34:08 +00:00
|
|
|
return match p {
|
2012-08-04 02:59:04 +00:00
|
|
|
ast::proto_bare => ~"extern fn",
|
|
|
|
ast::proto_block => ~"fn&",
|
|
|
|
ast::proto_uniq => ~"fn~",
|
|
|
|
ast::proto_box => ~"fn@"
|
2012-01-12 23:38:44 +00:00
|
|
|
};
|
2011-07-20 01:17:49 +00:00
|
|
|
}
|
|
|
|
|
Handle nested items correctly in typestate_check
Summary says it all. Actually, only nested objects and functions
are handled, but that's better than before. The fold that I was using
before to traverse a crate wasn't working correctly, because annotations
have to reflect the number of local variables of the nearest enclosing
function (in turn, because annotations are represented as bit vectors).
The fold was traversing the AST in the wrong order, first filling in
the annotations correctly, but then re-traversing them with the bit
vector length for any outer nested functions, and so on.
Remedying this required writing a lot of tedious boilerplate code
because I scrapped the idea of using a fold altogether.
I also made typestate_check handle unary, field, alt, and fail.
Also, some miscellaneous changes:
* added annotations to blocks in typeck
* fix pprust so it can handle spawn
* added more logging functions in util.common
* fixed _vec.or
* added maybe and from_maybe in option
* removed fold_block field from ast_fold, since it was never used
2011-04-18 22:33:10 +00:00
|
|
|
//
|
|
|
|
// Local Variables:
|
|
|
|
// mode: rust
|
|
|
|
// fill-column: 78;
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
// c-basic-offset: 4
|
|
|
|
// buffer-file-coding-system: utf-8-unix
|
|
|
|
// End:
|
|
|
|
//
|