2012-12-03 18:48:01 -06:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2013-05-17 17:28:44 -05:00
|
|
|
use core::prelude::*;
|
2013-01-08 21:37:25 -06:00
|
|
|
|
2013-03-13 21:25:28 -05:00
|
|
|
use abi::AbiSet;
|
2013-01-10 13:16:54 -06:00
|
|
|
use ast::{RegionTyParamBound, TraitTyParamBound, required, provided};
|
2012-12-23 16:41:37 -06:00
|
|
|
use ast;
|
|
|
|
use ast_util;
|
2013-02-14 23:50:03 -06:00
|
|
|
use opt_vec::OptVec;
|
2013-03-27 11:55:18 -05:00
|
|
|
use opt_vec;
|
2012-12-23 16:41:37 -06:00
|
|
|
use attr;
|
|
|
|
use codemap::{CodeMap, BytePos};
|
|
|
|
use codemap;
|
|
|
|
use diagnostic;
|
2013-03-26 15:38:07 -05:00
|
|
|
use parse::classify::expr_is_simple_block;
|
2013-06-04 14:34:25 -05:00
|
|
|
use parse::token::{ident_interner, ident_to_str};
|
2013-03-26 15:38:07 -05:00
|
|
|
use parse::{comments, token};
|
2012-12-23 16:41:37 -06:00
|
|
|
use parse;
|
2013-03-26 15:38:07 -05:00
|
|
|
use print::pp::{break_offset, word, space, zerobreak, hardbreak};
|
2012-12-23 16:41:37 -06:00
|
|
|
use print::pp::{breaks, consistent, inconsistent, eof};
|
|
|
|
use print::pp;
|
|
|
|
use print::pprust;
|
|
|
|
|
2013-05-24 21:35:29 -05:00
|
|
|
use core::char;
|
|
|
|
use core::io;
|
|
|
|
use core::u64;
|
|
|
|
use core::uint;
|
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
// The @ps is stored here to prevent recursive type.
|
2013-02-26 13:34:00 -06:00
|
|
|
pub enum ann_node<'self> {
|
|
|
|
node_block(@ps, &'self ast::blk),
|
2013-02-04 16:02:01 -06:00
|
|
|
node_item(@ps, @ast::item),
|
|
|
|
node_expr(@ps, @ast::expr),
|
|
|
|
node_pat(@ps, @ast::pat),
|
2011-07-05 04:48:19 -05:00
|
|
|
}
|
2013-01-29 16:41:40 -06:00
|
|
|
pub struct pp_ann {
|
2013-03-01 15:30:06 -06:00
|
|
|
pre: @fn(ann_node),
|
|
|
|
post: @fn(ann_node)
|
2013-01-08 16:00:45 -06:00
|
|
|
}
|
2011-07-05 04:48:19 -05:00
|
|
|
|
2013-01-29 16:41:40 -06:00
|
|
|
pub fn no_ann() -> pp_ann {
|
2011-09-12 04:27:30 -05:00
|
|
|
fn ignore(_node: ann_node) { }
|
2013-01-08 16:00:45 -06:00
|
|
|
return pp_ann {pre: ignore, post: ignore};
|
2011-07-05 04:48:19 -05:00
|
|
|
}
|
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub struct CurrentCommentAndLiteral {
|
|
|
|
cur_cmnt: uint,
|
|
|
|
cur_lit: uint,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct ps {
|
|
|
|
s: @mut pp::Printer,
|
|
|
|
cm: Option<@CodeMap>,
|
|
|
|
intr: @token::ident_interner,
|
|
|
|
comments: Option<~[comments::cmnt]>,
|
|
|
|
literals: Option<~[comments::lit]>,
|
|
|
|
cur_cmnt_and_lit: @mut CurrentCommentAndLiteral,
|
2013-03-07 17:37:22 -06:00
|
|
|
boxes: @mut ~[pp::breaks],
|
2013-02-04 16:02:01 -06:00
|
|
|
ann: pp_ann
|
|
|
|
}
|
2011-07-05 04:48:19 -05:00
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn ibox(s: @ps, u: uint) {
|
2012-05-10 09:24:56 -05:00
|
|
|
s.boxes.push(pp::inconsistent);
|
|
|
|
pp::ibox(s.s, u);
|
|
|
|
}
|
2011-07-05 04:48:19 -05:00
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn end(s: @ps) {
|
2012-05-10 09:24:56 -05:00
|
|
|
s.boxes.pop();
|
|
|
|
pp::end(s.s);
|
|
|
|
}
|
2011-07-05 04:48:19 -05:00
|
|
|
|
2013-03-12 15:00:50 -05:00
|
|
|
pub fn rust_printer(writer: @io::Writer, intr: @ident_interner) -> @ps {
|
2013-03-15 14:24:24 -05:00
|
|
|
return rust_printer_annotated(writer, intr, no_ann());
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn rust_printer_annotated(writer: @io::Writer,
|
|
|
|
intr: @ident_interner,
|
|
|
|
ann: pp_ann) -> @ps {
|
2013-02-04 16:02:01 -06:00
|
|
|
return @ps {
|
|
|
|
s: pp::mk_printer(writer, default_columns),
|
|
|
|
cm: None::<@CodeMap>,
|
|
|
|
intr: intr,
|
|
|
|
comments: None::<~[comments::cmnt]>,
|
|
|
|
literals: None::<~[comments::lit]>,
|
|
|
|
cur_cmnt_and_lit: @mut CurrentCommentAndLiteral {
|
|
|
|
cur_cmnt: 0,
|
|
|
|
cur_lit: 0
|
|
|
|
},
|
2013-03-07 17:37:22 -06:00
|
|
|
boxes: @mut ~[],
|
2013-03-15 14:24:24 -05:00
|
|
|
ann: ann
|
2013-02-04 16:02:01 -06:00
|
|
|
};
|
2011-07-05 04:48:19 -05:00
|
|
|
}
|
|
|
|
|
2013-03-22 16:00:15 -05:00
|
|
|
pub static indent_unit: uint = 4u;
|
2011-07-05 04:48:19 -05:00
|
|
|
|
2013-03-22 16:00:15 -05:00
|
|
|
pub static default_columns: uint = 78u;
|
2011-07-05 04:48:19 -05:00
|
|
|
|
2011-07-25 16:04:38 -05: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.
|
2013-03-12 15:00:50 -05:00
|
|
|
pub fn print_crate(cm: @CodeMap,
|
|
|
|
intr: @ident_interner,
|
|
|
|
span_diagnostic: @diagnostic::span_handler,
|
|
|
|
crate: @ast::crate,
|
2013-06-12 12:02:55 -05:00
|
|
|
filename: @str,
|
2013-03-12 15:00:50 -05:00
|
|
|
in: @io::Reader,
|
|
|
|
out: @io::Writer,
|
|
|
|
ann: pp_ann,
|
|
|
|
is_expanded: bool) {
|
2013-02-26 09:43:53 -06:00
|
|
|
let (cmnts, lits) = comments::gather_comments_and_literals(
|
|
|
|
span_diagnostic,
|
2013-06-12 12:02:55 -05:00
|
|
|
filename,
|
2013-02-26 09:43:53 -06:00
|
|
|
in
|
|
|
|
);
|
2013-02-04 16:02:01 -06:00
|
|
|
let s = @ps {
|
|
|
|
s: pp::mk_printer(out, default_columns),
|
|
|
|
cm: Some(cm),
|
|
|
|
intr: intr,
|
2013-02-26 09:43:53 -06:00
|
|
|
comments: Some(copy cmnts),
|
2013-02-04 16:02:01 -06: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.
|
2013-02-26 09:43:53 -06:00
|
|
|
literals: if is_expanded { None } else { Some(copy lits) },
|
2013-02-04 16:02:01 -06:00
|
|
|
cur_cmnt_and_lit: @mut CurrentCommentAndLiteral {
|
|
|
|
cur_cmnt: 0,
|
|
|
|
cur_lit: 0
|
|
|
|
},
|
2013-03-07 17:37:22 -06:00
|
|
|
boxes: @mut ~[],
|
2013-02-04 16:02:01 -06:00
|
|
|
ann: ann
|
|
|
|
};
|
2012-02-21 17:34:26 -06:00
|
|
|
print_crate_(s, crate);
|
|
|
|
}
|
|
|
|
|
2013-04-17 11:15:08 -05:00
|
|
|
pub fn print_crate_(s: @ps, crate: @ast::crate) {
|
2013-03-19 20:24:01 -05:00
|
|
|
print_mod(s, &crate.node.module, crate.node.attrs);
|
2011-07-05 16:34:34 -05:00
|
|
|
print_remaining_comments(s);
|
2011-05-28 21:16:18 -05:00
|
|
|
eof(s.s);
|
2011-03-04 00:22:43 -06:00
|
|
|
}
|
|
|
|
|
2013-01-29 16:41:40 -06:00
|
|
|
pub fn ty_to_str(ty: @ast::Ty, intr: @ident_interner) -> ~str {
|
2012-07-18 18:18:02 -05:00
|
|
|
to_str(ty, print_type, intr)
|
|
|
|
}
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2013-01-29 16:41:40 -06:00
|
|
|
pub fn pat_to_str(pat: @ast::pat, intr: @ident_interner) -> ~str {
|
2012-12-07 16:39:29 -06:00
|
|
|
to_str(pat, print_irrefutable_pat, intr)
|
2012-07-18 18:18:02 -05:00
|
|
|
}
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2013-01-29 16:41:40 -06:00
|
|
|
pub fn expr_to_str(e: @ast::expr, intr: @ident_interner) -> ~str {
|
2012-07-18 18:18:02 -05:00
|
|
|
to_str(e, print_expr, intr)
|
|
|
|
}
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2013-02-27 18:41:02 -06:00
|
|
|
pub fn lifetime_to_str(e: &ast::Lifetime, intr: @ident_interner) -> ~str {
|
|
|
|
to_str(e, print_lifetime, intr)
|
2013-02-27 15:21:07 -06:00
|
|
|
}
|
|
|
|
|
2013-01-29 16:41:40 -06:00
|
|
|
pub fn tt_to_str(tt: ast::token_tree, intr: @ident_interner) -> ~str {
|
2013-05-11 23:25:31 -05:00
|
|
|
to_str(&tt, print_tt, intr)
|
2012-08-06 19:50:45 -05:00
|
|
|
}
|
|
|
|
|
2013-01-29 16:41:40 -06:00
|
|
|
pub fn tts_to_str(tts: &[ast::token_tree], intr: @ident_interner) -> ~str {
|
2012-12-12 19:08:09 -06:00
|
|
|
to_str(tts, print_tts, intr)
|
|
|
|
}
|
|
|
|
|
2013-04-17 11:15:08 -05:00
|
|
|
pub fn stmt_to_str(s: &ast::stmt, intr: @ident_interner) -> ~str {
|
2012-07-18 18:18:02 -05:00
|
|
|
to_str(s, print_stmt, intr)
|
|
|
|
}
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2013-01-29 16:41:40 -06:00
|
|
|
pub fn item_to_str(i: @ast::item, intr: @ident_interner) -> ~str {
|
2012-07-18 18:18:02 -05:00
|
|
|
to_str(i, print_item, intr)
|
|
|
|
}
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2013-02-14 23:50:03 -06:00
|
|
|
pub fn generics_to_str(generics: &ast::Generics,
|
|
|
|
intr: @ident_interner) -> ~str {
|
|
|
|
to_str(generics, print_generics, intr)
|
2012-02-02 00:41:41 -06:00
|
|
|
}
|
|
|
|
|
2013-04-17 11:15:08 -05:00
|
|
|
pub fn path_to_str(p: @ast::Path, intr: @ident_interner) -> ~str {
|
2012-07-18 18:18:02 -05:00
|
|
|
to_str(p, |a,b| print_path(a, b, false), intr)
|
2011-08-16 11:03:58 -05:00
|
|
|
}
|
2011-05-31 12:58:30 -05:00
|
|
|
|
2013-03-25 01:02:42 -05:00
|
|
|
pub fn fun_to_str(decl: &ast::fn_decl, purity: ast::purity, name: ast::ident,
|
2013-04-30 10:49:48 -05:00
|
|
|
opt_explicit_self: Option<ast::explicit_self_>,
|
2013-02-14 23:50:03 -06:00
|
|
|
generics: &ast::Generics, intr: @ident_interner) -> ~str {
|
2012-09-14 11:40:28 -05:00
|
|
|
do io::with_str_writer |wr| {
|
|
|
|
let s = rust_printer(wr, intr);
|
2013-03-13 21:25:28 -05:00
|
|
|
print_fn(s, decl, Some(purity), AbiSet::Rust(),
|
2013-04-30 10:49:48 -05:00
|
|
|
name, generics, opt_explicit_self, ast::inherited);
|
2012-09-14 11:40:28 -05:00
|
|
|
end(s); // Close the head box
|
|
|
|
end(s); // Close the outer box
|
|
|
|
eof(s.s);
|
|
|
|
}
|
2011-03-09 04:41:50 -06:00
|
|
|
}
|
|
|
|
|
2013-02-18 00:20:36 -06:00
|
|
|
pub fn block_to_str(blk: &ast::blk, intr: @ident_interner) -> ~str {
|
2012-09-14 11:40:28 -05:00
|
|
|
do io::with_str_writer |wr| {
|
|
|
|
let s = rust_printer(wr, intr);
|
|
|
|
// containing cbox, will be closed by print-block at }
|
|
|
|
cbox(s, indent_unit);
|
|
|
|
// head-ibox, will be closed by print-block after {
|
|
|
|
ibox(s, 0u);
|
|
|
|
print_block(s, blk);
|
|
|
|
eof(s.s);
|
|
|
|
}
|
2011-03-31 19:29:59 -05:00
|
|
|
}
|
|
|
|
|
2013-01-29 16:41:40 -06:00
|
|
|
pub fn meta_item_to_str(mi: @ast::meta_item, intr: @ident_interner) -> ~str {
|
2012-08-22 18:43:23 -05:00
|
|
|
to_str(mi, print_meta_item, intr)
|
2011-06-27 20:32:15 -05:00
|
|
|
}
|
|
|
|
|
2013-01-29 16:41:40 -06:00
|
|
|
pub fn attribute_to_str(attr: ast::attribute, intr: @ident_interner) -> ~str {
|
2012-07-18 18:18:02 -05:00
|
|
|
to_str(attr, print_attribute, intr)
|
2011-06-27 21:41:48 -05:00
|
|
|
}
|
|
|
|
|
2013-05-11 23:25:31 -05:00
|
|
|
pub fn variant_to_str(var: &ast::variant, intr: @ident_interner) -> ~str {
|
2012-07-18 18:18:02 -05:00
|
|
|
to_str(var, print_variant, intr)
|
2012-01-25 19:22:08 -06:00
|
|
|
}
|
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn cbox(s: @ps, u: uint) {
|
2012-05-10 09:24:56 -05:00
|
|
|
s.boxes.push(pp::consistent);
|
|
|
|
pp::cbox(s.s, u);
|
|
|
|
}
|
2011-06-01 17:29:38 -05:00
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn box(s: @ps, u: uint, b: pp::breaks) {
|
2012-05-10 09:24:56 -05:00
|
|
|
s.boxes.push(b);
|
|
|
|
pp::box(s.s, u, b);
|
|
|
|
}
|
2011-06-01 17:29:38 -05:00
|
|
|
|
2013-05-19 00:07:44 -05:00
|
|
|
pub fn nbsp(s: @ps) { word(s.s, " "); }
|
2011-07-26 17:58:43 -05:00
|
|
|
|
2013-05-11 23:25:31 -05:00
|
|
|
pub fn word_nbsp(s: @ps, w: &str) { word(s.s, w); nbsp(s); }
|
2011-05-28 21:16:18 -05:00
|
|
|
|
2013-05-11 23:25:31 -05:00
|
|
|
pub fn word_space(s: @ps, w: &str) { word(s.s, w); space(s.s); }
|
2011-05-28 21:16:18 -05:00
|
|
|
|
2013-05-19 00:07:44 -05:00
|
|
|
pub fn popen(s: @ps) { word(s.s, "("); }
|
2011-05-28 21:16:18 -05:00
|
|
|
|
2013-05-19 00:07:44 -05:00
|
|
|
pub fn pclose(s: @ps) { word(s.s, ")"); }
|
2011-05-28 21:16:18 -05:00
|
|
|
|
2013-05-19 00:07:44 -05:00
|
|
|
pub fn head(s: @ps, w: &str) {
|
2011-05-28 21:16:18 -05:00
|
|
|
// outer-box is consistent
|
2011-06-01 17:29:38 -05:00
|
|
|
cbox(s, indent_unit);
|
2011-05-28 21:16:18 -05:00
|
|
|
// head-box is inconsistent
|
2013-06-09 09:44:58 -05:00
|
|
|
ibox(s, w.len() + 1);
|
2011-05-28 21:16:18 -05:00
|
|
|
// keyword that starts the head
|
2012-11-04 22:41:00 -06:00
|
|
|
if !w.is_empty() {
|
|
|
|
word_nbsp(s, w);
|
|
|
|
}
|
2011-05-28 21:16:18 -05:00
|
|
|
}
|
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn bopen(s: @ps) {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "{");
|
2011-06-01 17:29:38 -05:00
|
|
|
end(s); // close the head-box
|
2011-03-24 10:33:20 -05:00
|
|
|
}
|
2011-05-28 21:16:18 -05:00
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn bclose_(s: @ps, span: codemap::span, indented: uint) {
|
2012-08-09 18:31:47 -05:00
|
|
|
bclose_maybe_open(s, span, indented, true);
|
|
|
|
}
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn bclose_maybe_open (s: @ps, span: codemap::span, indented: uint,
|
2013-01-29 16:41:40 -06:00
|
|
|
close_box: bool) {
|
2011-03-24 10:33:20 -05:00
|
|
|
maybe_print_comment(s, span.hi);
|
2011-07-26 17:37:05 -05:00
|
|
|
break_offset_if_not_bol(s, 1u, -(indented as int));
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "}");
|
2012-08-09 18:31:47 -05:00
|
|
|
if close_box {
|
|
|
|
end(s); // close the outer-box
|
|
|
|
}
|
2011-07-21 08:36:41 -05:00
|
|
|
}
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn bclose(s: @ps, span: codemap::span) { bclose_(s, span, indent_unit); }
|
2011-05-28 21:16:18 -05:00
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn is_begin(s: @ps) -> bool {
|
2012-08-06 14:34:08 -05:00
|
|
|
match s.s.last_token() { pp::BEGIN(_) => true, _ => false }
|
2011-08-02 17:25:06 -05:00
|
|
|
}
|
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn is_end(s: @ps) -> bool {
|
2012-08-06 14:34:08 -05:00
|
|
|
match s.s.last_token() { pp::END => true, _ => false }
|
2011-08-02 17:25:06 -05:00
|
|
|
}
|
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn is_bol(s: @ps) -> bool {
|
2012-08-27 18:26:35 -05:00
|
|
|
return s.s.last_token().is_eof() || s.s.last_token().is_hardbreak_tok();
|
2011-06-20 09:45:05 -05:00
|
|
|
}
|
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn in_cbox(s: @ps) -> bool {
|
2013-03-16 13:11:31 -05:00
|
|
|
let boxes = &*s.boxes;
|
|
|
|
let len = boxes.len();
|
2012-08-01 19:30:05 -05:00
|
|
|
if len == 0u { return false; }
|
2013-03-16 13:11:31 -05:00
|
|
|
return boxes[len - 1u] == pp::consistent;
|
2012-04-19 16:46:11 -05:00
|
|
|
}
|
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn hardbreak_if_not_bol(s: @ps) { if !is_bol(s) { hardbreak(s.s); } }
|
|
|
|
pub fn space_if_not_bol(s: @ps) { if !is_bol(s) { space(s.s); } }
|
|
|
|
pub fn break_offset_if_not_bol(s: @ps, n: uint, off: int) {
|
2011-07-27 07:19:39 -05:00
|
|
|
if !is_bol(s) {
|
2011-07-26 17:37:05 -05:00
|
|
|
break_offset(s.s, n, off);
|
|
|
|
} else {
|
2012-08-27 18:26:35 -05:00
|
|
|
if off != 0 && s.s.last_token().is_hardbreak_tok() {
|
2011-07-26 17:37:05 -05: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-19 21:55:28 -05:00
|
|
|
}
|
|
|
|
}
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2011-06-01 20:53:52 -05:00
|
|
|
// Synthesizes a comment that was not textually present in the original source
|
|
|
|
// file.
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn synth_comment(s: @ps, text: ~str) {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "/*");
|
2011-06-01 20:53:52 -05:00
|
|
|
space(s.s);
|
|
|
|
word(s.s, text);
|
|
|
|
space(s.s);
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "*/");
|
2011-06-01 20:53:52 -05:00
|
|
|
}
|
|
|
|
|
2013-04-17 11:15:08 -05:00
|
|
|
pub fn commasep<IN: Copy>(s: @ps, b: breaks, elts: &[IN], op: &fn(@ps, IN)) {
|
2011-07-05 18:23:07 -05:00
|
|
|
box(s, 0u, b);
|
2012-03-15 08:47:03 -05:00
|
|
|
let mut first = true;
|
2012-06-30 18:19:07 -05:00
|
|
|
for elts.each |elt| {
|
2013-05-19 00:07:44 -05:00
|
|
|
if first { first = false; } else { word_space(s, ","); }
|
2013-06-15 19:26:59 -05:00
|
|
|
op(s, copy *elt);
|
2011-07-05 18:23:07 -05:00
|
|
|
}
|
|
|
|
end(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-17 11:15:08 -05:00
|
|
|
pub fn commasep_cmnt<IN: Copy>(s: @ps, b: breaks, elts: &[IN], op: &fn(@ps, IN),
|
|
|
|
get_span: &fn(IN) -> codemap::span) {
|
2011-06-01 17:29:38 -05:00
|
|
|
box(s, 0u, b);
|
2013-03-27 09:01:45 -05:00
|
|
|
let len = elts.len();
|
2012-03-15 08:47:03 -05:00
|
|
|
let mut i = 0u;
|
2012-06-30 18:19:07 -05:00
|
|
|
for elts.each |elt| {
|
2013-06-15 19:26:59 -05:00
|
|
|
maybe_print_comment(s, get_span(copy *elt).hi);
|
|
|
|
op(s, copy *elt);
|
2011-07-06 18:01:47 -05:00
|
|
|
i += 1u;
|
2011-07-27 07:19:39 -05:00
|
|
|
if i < len {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, ",");
|
2013-06-15 19:26:59 -05:00
|
|
|
maybe_print_trailing_comment(s, get_span(copy *elt),
|
|
|
|
Some(get_span(copy elts[i]).hi));
|
2011-07-26 17:37:05 -05:00
|
|
|
space_if_not_bol(s);
|
2011-07-06 18:01:47 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
end(s);
|
|
|
|
}
|
|
|
|
|
2013-03-19 20:24:01 -05:00
|
|
|
pub fn commasep_exprs(s: @ps, b: breaks, exprs: &[@ast::expr]) {
|
2013-04-17 11:15:08 -05:00
|
|
|
fn expr_span(expr: @ast::expr) -> codemap::span { return expr.span; }
|
2011-07-12 18:13:30 -05:00
|
|
|
commasep_cmnt(s, b, exprs, print_expr, expr_span);
|
2011-03-29 05:46:55 -05:00
|
|
|
}
|
2011-03-04 00:22:43 -06:00
|
|
|
|
2013-05-11 23:25:31 -05:00
|
|
|
pub fn print_mod(s: @ps, _mod: &ast::_mod, attrs: &[ast::attribute]) {
|
2011-06-30 18:03:07 -05:00
|
|
|
print_inner_attributes(s, attrs);
|
2012-06-30 18:19:07 -05:00
|
|
|
for _mod.view_items.each |vitem| {
|
2012-09-19 18:55:01 -05:00
|
|
|
print_view_item(s, *vitem);
|
2011-05-12 10:24:54 -05:00
|
|
|
}
|
2012-09-19 18:55:01 -05:00
|
|
|
for _mod.items.each |item| { print_item(s, *item); }
|
2011-03-17 19:39:47 -05:00
|
|
|
}
|
|
|
|
|
2013-03-19 20:24:01 -05:00
|
|
|
pub fn print_foreign_mod(s: @ps, nmod: &ast::foreign_mod,
|
2013-05-11 23:25:31 -05:00
|
|
|
attrs: &[ast::attribute]) {
|
2011-07-26 17:37:36 -05:00
|
|
|
print_inner_attributes(s, attrs);
|
2012-06-30 18:19:07 -05:00
|
|
|
for nmod.view_items.each |vitem| {
|
2012-09-19 18:55:01 -05:00
|
|
|
print_view_item(s, *vitem);
|
2011-07-26 17:37:36 -05:00
|
|
|
}
|
2012-09-19 18:55:01 -05:00
|
|
|
for nmod.items.each |item| { print_foreign_item(s, *item); }
|
2011-07-26 17:37:36 -05:00
|
|
|
}
|
|
|
|
|
2013-02-27 18:41:02 -06:00
|
|
|
pub fn print_opt_lifetime(s: @ps, lifetime: Option<@ast::Lifetime>) {
|
2013-06-10 16:50:12 -05:00
|
|
|
for lifetime.iter().advance |l| {
|
2013-02-27 18:41:02 -06:00
|
|
|
print_lifetime(s, *l);
|
|
|
|
nbsp(s);
|
2012-03-08 20:10:07 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-17 11:15:08 -05:00
|
|
|
pub fn print_type(s: @ps, ty: @ast::Ty) {
|
2011-03-24 10:33:20 -05:00
|
|
|
maybe_print_comment(s, ty.span.lo);
|
2011-06-01 17:29:38 -05:00
|
|
|
ibox(s, 0u);
|
2013-03-19 20:24:01 -05:00
|
|
|
match ty.node {
|
2013-05-19 00:07:44 -05:00
|
|
|
ast::ty_nil => word(s.s, "()"),
|
|
|
|
ast::ty_bot => word(s.s, "!"),
|
|
|
|
ast::ty_box(ref mt) => { word(s.s, "@"); print_mt(s, mt); }
|
|
|
|
ast::ty_uniq(ref mt) => { word(s.s, "~"); print_mt(s, mt); }
|
2013-03-19 20:24:01 -05:00
|
|
|
ast::ty_vec(ref mt) => {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "[");
|
2012-08-06 14:34:08 -05:00
|
|
|
match mt.mutbl {
|
2013-05-19 00:07:44 -05:00
|
|
|
ast::m_mutbl => word_space(s, "mut"),
|
|
|
|
ast::m_const => word_space(s, "const"),
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::m_imm => ()
|
2011-07-27 14:20:51 -05:00
|
|
|
}
|
2011-08-15 06:45:04 -05:00
|
|
|
print_type(s, mt.ty);
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "]");
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2013-05-19 00:07:44 -05:00
|
|
|
ast::ty_ptr(ref mt) => { word(s.s, "*"); print_mt(s, mt); }
|
2013-03-19 20:24:01 -05:00
|
|
|
ast::ty_rptr(lifetime, ref mt) => {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "&");
|
2013-02-27 18:41:02 -06:00
|
|
|
print_opt_lifetime(s, lifetime);
|
2012-09-14 17:20:09 -05:00
|
|
|
print_mt(s, mt);
|
2012-03-08 20:10:07 -06:00
|
|
|
}
|
2013-03-19 20:24:01 -05:00
|
|
|
ast::ty_tup(ref elts) => {
|
2011-08-19 17:16:48 -05:00
|
|
|
popen(s);
|
2013-03-19 20:24:01 -05:00
|
|
|
commasep(s, inconsistent, *elts, print_type);
|
2013-02-18 19:45:56 -06:00
|
|
|
if elts.len() == 1 {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, ",");
|
2013-02-18 19:45:56 -06:00
|
|
|
}
|
2011-08-19 17:16:48 -05:00
|
|
|
pclose(s);
|
2011-08-15 04:40:26 -05:00
|
|
|
}
|
2013-01-31 19:12:29 -06:00
|
|
|
ast::ty_bare_fn(f) => {
|
2013-03-27 11:55:18 -05:00
|
|
|
let generics = ast::Generics {lifetimes: copy f.lifetimes,
|
|
|
|
ty_params: opt_vec::Empty};
|
2013-03-13 21:25:28 -05:00
|
|
|
print_ty_fn(s, Some(f.abis), None, None,
|
2013-02-28 09:25:31 -06:00
|
|
|
f.purity, ast::Many, &f.decl, None,
|
2013-03-27 11:55:18 -05:00
|
|
|
Some(&generics), None);
|
2013-01-31 19:12:29 -06:00
|
|
|
}
|
|
|
|
ast::ty_closure(f) => {
|
2013-03-27 11:55:18 -05:00
|
|
|
let generics = ast::Generics {lifetimes: copy f.lifetimes,
|
|
|
|
ty_params: opt_vec::Empty};
|
2013-01-31 19:12:29 -06:00
|
|
|
print_ty_fn(s, None, Some(f.sigil), f.region,
|
2013-02-28 09:25:31 -06:00
|
|
|
f.purity, f.onceness, &f.decl, None,
|
2013-03-27 11:55:18 -05:00
|
|
|
Some(&generics), None);
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2013-03-20 15:24:09 -05:00
|
|
|
ast::ty_path(path, _) => print_path(s, path, false),
|
2013-03-19 20:24:01 -05:00
|
|
|
ast::ty_fixed_length_vec(ref mt, v) => {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "[");
|
2012-11-04 22:41:00 -06:00
|
|
|
match mt.mutbl {
|
2013-05-19 00:07:44 -05:00
|
|
|
ast::m_mutbl => word_space(s, "mut"),
|
|
|
|
ast::m_const => word_space(s, "const"),
|
2012-11-04 22:41:00 -06:00
|
|
|
ast::m_imm => ()
|
2012-10-09 12:42:26 -05:00
|
|
|
}
|
2012-11-04 22:41:00 -06:00
|
|
|
print_type(s, mt.ty);
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, ", ..");
|
2013-03-05 20:09:33 -06:00
|
|
|
print_expr(s, v);
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "]");
|
2012-04-09 19:32:49 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::ty_mac(_) => {
|
2013-05-05 17:18:51 -05:00
|
|
|
fail!("print_type doesn't know how to print a ty_mac");
|
2012-01-30 23:00:57 -06:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::ty_infer => {
|
2013-05-05 17:18:51 -05:00
|
|
|
fail!("print_type shouldn't see a ty_infer");
|
2012-01-30 23:00:57 -06:00
|
|
|
}
|
|
|
|
|
2011-03-04 00:22:43 -06:00
|
|
|
}
|
2011-06-01 17:29:38 -05:00
|
|
|
end(s);
|
2011-03-04 00:22:43 -06:00
|
|
|
}
|
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn print_foreign_item(s: @ps, item: @ast::foreign_item) {
|
2011-07-26 17:37:36 -05:00
|
|
|
hardbreak_if_not_bol(s);
|
|
|
|
maybe_print_comment(s, item.span.lo);
|
|
|
|
print_outer_attributes(s, item.attrs);
|
2013-03-19 20:24:01 -05:00
|
|
|
match item.node {
|
2013-02-28 09:25:31 -06:00
|
|
|
ast::foreign_item_fn(ref decl, purity, ref generics) => {
|
2013-03-13 21:25:28 -05:00
|
|
|
print_fn(s, decl, Some(purity), AbiSet::Rust(), item.ident, generics, None,
|
2012-09-21 20:10:45 -05:00
|
|
|
ast::inherited);
|
2011-07-26 17:37:36 -05:00
|
|
|
end(s); // end head-ibox
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, ";");
|
2011-07-26 17:37:36 -05:00
|
|
|
end(s); // end the outer fn box
|
|
|
|
}
|
2012-08-25 17:09:33 -05:00
|
|
|
ast::foreign_item_const(t) => {
|
2013-05-19 00:07:44 -05:00
|
|
|
head(s, "static");
|
2012-08-25 17:09:33 -05:00
|
|
|
print_ident(s, item.ident);
|
2013-05-19 00:07:44 -05:00
|
|
|
word_space(s, ":");
|
2012-08-25 17:09:33 -05:00
|
|
|
print_type(s, t);
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, ";");
|
2012-08-25 17:09:33 -05:00
|
|
|
end(s); // end the head-ibox
|
2012-10-08 03:36:09 -05:00
|
|
|
end(s); // end the outer cbox
|
2012-08-25 17:09:33 -05:00
|
|
|
}
|
2011-07-26 17:37:36 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-17 11:15:08 -05:00
|
|
|
pub fn print_item(s: @ps, item: @ast::item) {
|
2011-06-20 11:15:11 -05:00
|
|
|
hardbreak_if_not_bol(s);
|
2011-03-24 10:33:20 -05:00
|
|
|
maybe_print_comment(s, item.span.lo);
|
2011-06-16 15:00:19 -05:00
|
|
|
print_outer_attributes(s, item.attrs);
|
2011-07-27 07:19:39 -05:00
|
|
|
let ann_node = node_item(s, item);
|
2012-11-29 19:51:16 -06:00
|
|
|
(s.ann.pre)(ann_node);
|
2013-03-19 20:24:01 -05:00
|
|
|
match item.node {
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::item_const(ty, expr) => {
|
2013-05-21 12:48:56 -05:00
|
|
|
head(s, visibility_qualified(item.vis, "static"));
|
2012-07-18 18:18:02 -05:00
|
|
|
print_ident(s, item.ident);
|
2013-05-19 00:07:44 -05:00
|
|
|
word_space(s, ":");
|
2011-08-15 06:45:04 -05:00
|
|
|
print_type(s, ty);
|
2011-07-27 07:19:39 -05:00
|
|
|
space(s.s);
|
|
|
|
end(s); // end the head-ibox
|
|
|
|
|
2013-05-19 00:07:44 -05:00
|
|
|
word_space(s, "=");
|
2011-07-27 07:19:39 -05:00
|
|
|
print_expr(s, expr);
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, ";");
|
2011-07-27 07:19:39 -05:00
|
|
|
end(s); // end the outer cbox
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2013-03-13 21:25:28 -05:00
|
|
|
ast::item_fn(ref decl, purity, abi, ref typarams, ref body) => {
|
2013-02-17 12:59:09 -06:00
|
|
|
print_fn(
|
|
|
|
s,
|
2013-02-28 09:25:31 -06:00
|
|
|
decl,
|
2013-03-13 21:25:28 -05:00
|
|
|
Some(purity),
|
|
|
|
abi,
|
2013-02-17 12:59:09 -06:00
|
|
|
item.ident,
|
2013-02-14 23:50:03 -06:00
|
|
|
typarams,
|
2013-02-17 12:59:09 -06:00
|
|
|
None,
|
|
|
|
item.vis
|
|
|
|
);
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, " ");
|
2013-02-18 00:20:36 -06:00
|
|
|
print_block_with_attrs(s, body, item.attrs);
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2013-03-19 20:24:01 -05:00
|
|
|
ast::item_mod(ref _mod) => {
|
2013-05-21 12:48:56 -05:00
|
|
|
head(s, visibility_qualified(item.vis, "mod"));
|
2012-07-18 18:18:02 -05:00
|
|
|
print_ident(s, item.ident);
|
|
|
|
nbsp(s);
|
2011-07-27 07:19:39 -05:00
|
|
|
bopen(s);
|
|
|
|
print_mod(s, _mod, item.attrs);
|
|
|
|
bclose(s, item.span);
|
|
|
|
}
|
2013-03-19 20:24:01 -05:00
|
|
|
ast::item_foreign_mod(ref nmod) => {
|
2013-05-21 12:48:56 -05:00
|
|
|
head(s, visibility_qualified(item.vis, "extern"));
|
2013-03-13 21:25:28 -05:00
|
|
|
word_nbsp(s, nmod.abis.to_str());
|
2012-08-29 14:22:05 -05:00
|
|
|
match nmod.sort {
|
2012-08-31 13:19:07 -05:00
|
|
|
ast::named => {
|
2013-05-19 00:07:44 -05:00
|
|
|
word_nbsp(s, "mod");
|
2012-08-31 13:19:07 -05:00
|
|
|
print_ident(s, item.ident);
|
2012-10-14 11:19:54 -05:00
|
|
|
nbsp(s);
|
2012-08-31 13:19:07 -05:00
|
|
|
}
|
|
|
|
ast::anonymous => {}
|
2012-08-29 14:22:05 -05:00
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
bopen(s);
|
2012-06-26 18:18:37 -05:00
|
|
|
print_foreign_mod(s, nmod, item.attrs);
|
2011-07-27 07:19:39 -05:00
|
|
|
bclose(s, item.span);
|
|
|
|
}
|
2013-02-14 23:50:03 -06:00
|
|
|
ast::item_ty(ty, ref params) => {
|
2011-07-27 07:19:39 -05:00
|
|
|
ibox(s, indent_unit);
|
|
|
|
ibox(s, 0u);
|
2013-05-21 12:48:56 -05:00
|
|
|
word_nbsp(s, visibility_qualified(item.vis, "type"));
|
2012-07-18 18:18:02 -05:00
|
|
|
print_ident(s, item.ident);
|
2013-02-14 23:50:03 -06:00
|
|
|
print_generics(s, params);
|
2011-07-27 07:19:39 -05:00
|
|
|
end(s); // end the inner ibox
|
|
|
|
|
|
|
|
space(s.s);
|
2013-05-19 00:07:44 -05:00
|
|
|
word_space(s, "=");
|
2011-08-15 06:45:04 -05:00
|
|
|
print_type(s, ty);
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, ";");
|
2011-07-27 07:19:39 -05:00
|
|
|
end(s); // end the outer ibox
|
|
|
|
}
|
2013-02-17 12:59:09 -06:00
|
|
|
ast::item_enum(ref enum_definition, ref params) => {
|
|
|
|
print_enum_def(
|
|
|
|
s,
|
2013-05-11 23:25:31 -05:00
|
|
|
enum_definition,
|
2013-02-14 23:50:03 -06:00
|
|
|
params,
|
2013-02-17 12:59:09 -06:00
|
|
|
item.ident,
|
|
|
|
item.span,
|
|
|
|
item.vis
|
|
|
|
);
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2013-02-14 23:50:03 -06:00
|
|
|
ast::item_struct(struct_def, ref generics) => {
|
2013-05-21 12:48:56 -05:00
|
|
|
head(s, visibility_qualified(item.vis, "struct"));
|
2013-02-14 23:50:03 -06:00
|
|
|
print_struct(s, struct_def, generics, item.ident, item.span);
|
2012-08-07 18:08:09 -05:00
|
|
|
}
|
2012-07-18 18:18:02 -05:00
|
|
|
|
2013-02-28 09:25:31 -06:00
|
|
|
ast::item_impl(ref generics, opt_trait, ty, ref methods) => {
|
2013-05-21 12:48:56 -05:00
|
|
|
head(s, visibility_qualified(item.vis, "impl"));
|
2013-03-06 11:27:23 -06:00
|
|
|
if generics.is_parameterized() {
|
2013-02-14 23:50:03 -06:00
|
|
|
print_generics(s, generics);
|
2012-08-08 18:26:10 -05:00
|
|
|
space(s.s);
|
|
|
|
}
|
|
|
|
|
2012-09-07 17:11:26 -05:00
|
|
|
match opt_trait {
|
|
|
|
Some(t) => {
|
2013-03-27 05:16:28 -05:00
|
|
|
print_trait_ref(s, t);
|
2013-02-11 01:15:45 -06:00
|
|
|
space(s.s);
|
2013-05-19 00:07:44 -05:00
|
|
|
word_space(s, "for");
|
2012-07-18 11:31:53 -05:00
|
|
|
}
|
2012-09-07 17:11:26 -05:00
|
|
|
None => ()
|
|
|
|
};
|
2013-02-11 01:15:45 -06:00
|
|
|
|
|
|
|
print_type(s, ty);
|
2011-12-16 03:42:28 -06:00
|
|
|
space(s.s);
|
2012-08-08 18:26:10 -05:00
|
|
|
|
2012-11-13 21:08:01 -06:00
|
|
|
if methods.len() == 0 {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, ";");
|
2012-11-13 21:08:01 -06:00
|
|
|
} else {
|
|
|
|
bopen(s);
|
|
|
|
for methods.each |meth| {
|
|
|
|
print_method(s, *meth);
|
2012-10-22 19:57:10 -05:00
|
|
|
}
|
2012-11-13 21:08:01 -06:00
|
|
|
bclose(s, item.span);
|
2011-12-13 06:19:56 -06:00
|
|
|
}
|
|
|
|
}
|
2013-02-14 23:50:03 -06:00
|
|
|
ast::item_trait(ref generics, ref traits, ref methods) => {
|
2013-05-21 12:48:56 -05:00
|
|
|
head(s, visibility_qualified(item.vis, "trait"));
|
2012-07-18 18:18:02 -05:00
|
|
|
print_ident(s, item.ident);
|
2013-02-14 23:50:03 -06:00
|
|
|
print_generics(s, generics);
|
2013-02-17 12:59:09 -06:00
|
|
|
if traits.len() != 0u {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, ":");
|
2013-06-17 18:43:22 -05:00
|
|
|
for traits.iter().enumerate().advance |(i, trait_)| {
|
2012-12-07 19:55:34 -06:00
|
|
|
nbsp(s);
|
2013-03-04 18:11:30 -06:00
|
|
|
if i != 0 {
|
2013-05-19 00:07:44 -05:00
|
|
|
word_space(s, "+");
|
2013-03-04 18:11:30 -06:00
|
|
|
}
|
2012-12-07 19:55:34 -06:00
|
|
|
print_path(s, trait_.path, false);
|
|
|
|
}
|
2012-08-03 17:02:01 -05:00
|
|
|
}
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, " ");
|
2011-12-20 09:33:55 -06:00
|
|
|
bopen(s);
|
2013-02-18 00:20:36 -06:00
|
|
|
for methods.each |meth| {
|
|
|
|
print_trait_method(s, meth);
|
2012-09-19 18:55:01 -05:00
|
|
|
}
|
2011-12-20 09:33:55 -06:00
|
|
|
bclose(s, item.span);
|
|
|
|
}
|
2013-01-30 11:56:33 -06:00
|
|
|
ast::item_mac(codemap::spanned { node: ast::mac_invoc_tt(pth, ref tts),
|
2012-12-27 13:36:00 -06:00
|
|
|
_}) => {
|
2012-10-14 11:19:54 -05:00
|
|
|
print_visibility(s, item.vis);
|
2012-07-18 18:18:02 -05:00
|
|
|
print_path(s, pth, false);
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "! ");
|
2012-07-18 18:18:02 -05:00
|
|
|
print_ident(s, item.ident);
|
2012-08-22 21:08:21 -05:00
|
|
|
cbox(s, indent_unit);
|
|
|
|
popen(s);
|
2012-12-12 19:08:09 -06:00
|
|
|
print_tts(s, *tts);
|
2012-08-22 21:08:21 -05:00
|
|
|
pclose(s);
|
|
|
|
end(s);
|
2012-07-11 12:42:25 -05:00
|
|
|
}
|
2011-03-04 00:22:43 -06:00
|
|
|
}
|
2012-11-29 19:51:16 -06:00
|
|
|
(s.ann.post)(ann_node);
|
2012-08-07 18:08:09 -05:00
|
|
|
}
|
|
|
|
|
2013-03-27 05:16:28 -05:00
|
|
|
fn print_trait_ref(s: @ps, t: &ast::trait_ref) {
|
|
|
|
print_path(s, t.path, false);
|
|
|
|
}
|
|
|
|
|
2013-05-11 23:25:31 -05:00
|
|
|
pub fn print_enum_def(s: @ps, enum_definition: &ast::enum_def,
|
2013-02-14 23:50:03 -06:00
|
|
|
generics: &ast::Generics, ident: ast::ident,
|
2013-01-29 16:41:40 -06:00
|
|
|
span: codemap::span, visibility: ast::visibility) {
|
2013-05-21 12:48:56 -05:00
|
|
|
head(s, visibility_qualified(visibility, "enum"));
|
2012-07-18 18:18:02 -05:00
|
|
|
print_ident(s, ident);
|
2013-02-14 23:50:03 -06:00
|
|
|
print_generics(s, generics);
|
2012-08-08 19:14:25 -05:00
|
|
|
space(s.s);
|
2013-03-08 18:21:58 -06:00
|
|
|
print_variants(s, enum_definition.variants, span);
|
2012-08-08 19:14:25 -05:00
|
|
|
}
|
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn print_variants(s: @ps,
|
2013-05-11 23:25:31 -05:00
|
|
|
variants: &[ast::variant],
|
2013-01-29 16:41:40 -06:00
|
|
|
span: codemap::span) {
|
2012-08-08 16:17:52 -05:00
|
|
|
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);
|
2013-05-11 23:25:31 -05:00
|
|
|
print_variant(s, v);
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, ",");
|
2012-08-08 16:17:52 -05:00
|
|
|
end(s);
|
2012-11-12 21:32:48 -06:00
|
|
|
maybe_print_trailing_comment(s, v.span, None);
|
2012-08-08 16:17:52 -05:00
|
|
|
}
|
|
|
|
bclose(s, span);
|
|
|
|
}
|
|
|
|
|
2013-01-29 16:41:40 -06:00
|
|
|
pub fn visibility_to_str(vis: ast::visibility) -> ~str {
|
2012-09-21 20:10:45 -05:00
|
|
|
match vis {
|
|
|
|
ast::private => ~"priv",
|
|
|
|
ast::public => ~"pub",
|
|
|
|
ast::inherited => ~""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-21 12:32:29 -05:00
|
|
|
pub fn visibility_qualified(vis: ast::visibility, s: &str) -> ~str {
|
2012-09-21 20:10:45 -05:00
|
|
|
match vis {
|
2013-02-26 09:43:53 -06:00
|
|
|
ast::private | ast::public => visibility_to_str(vis) + " " + s,
|
2013-05-21 12:32:29 -05:00
|
|
|
ast::inherited => s.to_owned()
|
2012-09-21 20:10:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn print_visibility(s: @ps, vis: ast::visibility) {
|
2012-09-21 20:10:45 -05:00
|
|
|
match vis {
|
|
|
|
ast::private | ast::public =>
|
|
|
|
word_nbsp(s, visibility_to_str(vis)),
|
|
|
|
ast::inherited => ()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn print_struct(s: @ps,
|
2013-01-29 16:41:40 -06:00
|
|
|
struct_def: @ast::struct_def,
|
2013-02-14 23:50:03 -06:00
|
|
|
generics: &ast::Generics,
|
2013-01-29 16:41:40 -06:00
|
|
|
ident: ast::ident,
|
|
|
|
span: codemap::span) {
|
2012-07-18 18:18:02 -05:00
|
|
|
print_ident(s, ident);
|
2013-02-14 23:50:03 -06:00
|
|
|
print_generics(s, generics);
|
2012-10-26 14:11:14 -05:00
|
|
|
if ast_util::struct_def_is_tuple_like(struct_def) {
|
2013-03-01 20:42:02 -06:00
|
|
|
if !struct_def.fields.is_empty() {
|
|
|
|
popen(s);
|
|
|
|
do commasep(s, inconsistent, struct_def.fields) |s, field| {
|
|
|
|
match field.node.kind {
|
2013-05-05 17:18:51 -05:00
|
|
|
ast::named_field(*) => fail!("unexpected named field"),
|
2013-03-01 20:42:02 -06:00
|
|
|
ast::unnamed_field => {
|
|
|
|
maybe_print_comment(s, field.span.lo);
|
|
|
|
print_type(s, field.node.ty);
|
|
|
|
}
|
2012-08-15 17:53:58 -05:00
|
|
|
}
|
|
|
|
}
|
2013-03-01 20:42:02 -06:00
|
|
|
pclose(s);
|
2012-08-15 17:53:58 -05:00
|
|
|
}
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, ";");
|
2013-03-01 20:42:02 -06:00
|
|
|
end(s);
|
2012-10-26 14:11:14 -05:00
|
|
|
end(s); // close the outer-box
|
|
|
|
} else {
|
2013-03-01 20:42:02 -06:00
|
|
|
nbsp(s);
|
2012-10-26 14:11:14 -05:00
|
|
|
bopen(s);
|
|
|
|
hardbreak_if_not_bol(s);
|
|
|
|
|
|
|
|
for struct_def.fields.each |field| {
|
|
|
|
match field.node.kind {
|
2013-05-05 17:18:51 -05:00
|
|
|
ast::unnamed_field => fail!("unexpected unnamed field"),
|
2013-05-03 20:51:58 -05:00
|
|
|
ast::named_field(ident, visibility) => {
|
2012-10-26 14:11:14 -05:00
|
|
|
hardbreak_if_not_bol(s);
|
|
|
|
maybe_print_comment(s, field.span.lo);
|
2013-04-30 22:20:08 -05:00
|
|
|
print_outer_attributes(s, field.node.attrs);
|
2012-10-26 14:11:14 -05:00
|
|
|
print_visibility(s, visibility);
|
|
|
|
print_ident(s, ident);
|
2013-05-19 00:07:44 -05:00
|
|
|
word_nbsp(s, ":");
|
2012-10-26 14:11:14 -05:00
|
|
|
print_type(s, field.node.ty);
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, ",");
|
2012-10-26 14:11:14 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bclose(s, span);
|
2012-08-15 17:53:58 -05:00
|
|
|
}
|
2011-03-04 00:22:43 -06:00
|
|
|
}
|
|
|
|
|
2012-07-27 19:38:01 -05: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.
|
2013-05-11 23:25:31 -05:00
|
|
|
pub fn print_tt(s: @ps, tt: &ast::token_tree) {
|
|
|
|
match *tt {
|
2012-12-12 19:08:09 -06:00
|
|
|
ast::tt_delim(ref tts) => print_tts(s, *tts),
|
2012-12-04 12:50:00 -06:00
|
|
|
ast::tt_tok(_, ref tk) => {
|
2013-02-24 21:54:37 -06:00
|
|
|
word(s.s, parse::token::to_str(s.intr, tk));
|
2012-07-27 19:38:01 -05:00
|
|
|
}
|
2012-12-04 12:50:00 -06:00
|
|
|
ast::tt_seq(_, ref tts, ref sep, zerok) => {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "$(");
|
2013-05-11 23:25:31 -05:00
|
|
|
for (*tts).each() |tt_elt| { print_tt(s, tt_elt); }
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, ")");
|
2012-12-04 12:50:00 -06:00
|
|
|
match (*sep) {
|
2013-02-24 21:54:37 -06:00
|
|
|
Some(ref tk) => word(s.s, parse::token::to_str(s.intr, tk)),
|
2012-08-20 14:23:37 -05:00
|
|
|
None => ()
|
2012-07-27 19:38:01 -05:00
|
|
|
}
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, if zerok { "*" } else { "+" });
|
2012-07-27 19:38:01 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::tt_nonterminal(_, name) => {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "$");
|
2012-07-18 18:18:02 -05:00
|
|
|
print_ident(s, name);
|
2012-07-27 19:38:01 -05:00
|
|
|
}
|
|
|
|
}
|
2012-07-11 12:42:25 -05:00
|
|
|
}
|
|
|
|
|
2013-04-17 11:15:08 -05:00
|
|
|
pub fn print_tts(s: @ps, tts: &[ast::token_tree]) {
|
2012-12-12 19:08:09 -06:00
|
|
|
ibox(s, 0);
|
2013-06-17 18:43:22 -05:00
|
|
|
for tts.iter().enumerate().advance |(i, tt)| {
|
2012-12-12 19:08:09 -06:00
|
|
|
if i != 0 {
|
|
|
|
space(s.s);
|
|
|
|
}
|
2013-05-11 23:25:31 -05:00
|
|
|
print_tt(s, tt);
|
2012-12-12 19:08:09 -06:00
|
|
|
}
|
|
|
|
end(s);
|
|
|
|
}
|
|
|
|
|
2013-05-11 23:25:31 -05:00
|
|
|
pub fn print_variant(s: @ps, v: &ast::variant) {
|
2012-09-21 20:10:45 -05:00
|
|
|
print_visibility(s, v.node.vis);
|
2013-03-19 20:24:01 -05:00
|
|
|
match v.node.kind {
|
|
|
|
ast::tuple_variant_kind(ref args) => {
|
2012-07-18 18:18:02 -05:00
|
|
|
print_ident(s, v.node.name);
|
2013-01-24 21:19:44 -06:00
|
|
|
if !args.is_empty() {
|
2012-08-07 16:24:04 -05:00
|
|
|
popen(s);
|
2013-02-04 16:02:01 -06:00
|
|
|
fn print_variant_arg(s: @ps, arg: ast::variant_arg) {
|
2012-08-07 16:24:04 -05:00
|
|
|
print_type(s, arg.ty);
|
|
|
|
}
|
2013-03-19 20:24:01 -05:00
|
|
|
commasep(s, consistent, *args, print_variant_arg);
|
2012-08-07 16:24:04 -05:00
|
|
|
pclose(s);
|
|
|
|
}
|
2012-01-25 19:22:08 -06:00
|
|
|
}
|
2012-08-07 20:54:44 -05:00
|
|
|
ast::struct_variant_kind(struct_def) => {
|
2013-05-19 00:07:44 -05:00
|
|
|
head(s, "");
|
2013-02-14 23:50:03 -06:00
|
|
|
let generics = ast_util::empty_generics();
|
|
|
|
print_struct(s, struct_def, &generics, v.node.name, v.span);
|
2012-08-07 20:54:44 -05:00
|
|
|
}
|
2012-01-25 19:22:08 -06:00
|
|
|
}
|
2012-08-06 14:34:08 -05:00
|
|
|
match v.node.disr_expr {
|
2012-08-20 14:23:37 -05:00
|
|
|
Some(d) => {
|
2012-01-25 19:22:08 -06:00
|
|
|
space(s.s);
|
2013-05-19 00:07:44 -05:00
|
|
|
word_space(s, "=");
|
2012-01-25 19:22:08 -06:00
|
|
|
print_expr(s, d);
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => ()
|
2012-01-25 19:22:08 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-18 00:20:36 -06:00
|
|
|
pub fn print_ty_method(s: @ps, m: &ast::ty_method) {
|
2011-12-20 09:33:55 -06:00
|
|
|
hardbreak_if_not_bol(s);
|
|
|
|
maybe_print_comment(s, m.span.lo);
|
2012-01-30 13:43:45 -06:00
|
|
|
print_outer_attributes(s, m.attrs);
|
2013-01-31 19:12:29 -06:00
|
|
|
print_ty_fn(s, None, None, None, m.purity, ast::Many,
|
2013-02-28 09:25:31 -06:00
|
|
|
&m.decl, Some(m.ident), Some(&m.generics),
|
2013-04-30 10:49:48 -05:00
|
|
|
Some(/*bad*/ copy m.explicit_self.node));
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, ";");
|
2011-12-20 09:33:55 -06:00
|
|
|
}
|
|
|
|
|
2013-02-18 00:20:36 -06:00
|
|
|
pub fn print_trait_method(s: @ps, m: &ast::trait_method) {
|
|
|
|
match *m {
|
|
|
|
required(ref ty_m) => print_ty_method(s, ty_m),
|
|
|
|
provided(m) => print_method(s, m)
|
2012-07-10 15:44:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn print_method(s: @ps, meth: @ast::method) {
|
2012-03-19 12:19:00 -05:00
|
|
|
hardbreak_if_not_bol(s);
|
|
|
|
maybe_print_comment(s, meth.span.lo);
|
|
|
|
print_outer_attributes(s, meth.attrs);
|
2013-03-13 21:25:28 -05:00
|
|
|
print_fn(s, &meth.decl, Some(meth.purity), AbiSet::Rust(),
|
2013-04-30 10:49:48 -05:00
|
|
|
meth.ident, &meth.generics, Some(meth.explicit_self.node),
|
2012-09-21 20:10:45 -05:00
|
|
|
meth.vis);
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, " ");
|
2013-02-18 00:20:36 -06:00
|
|
|
print_block_with_attrs(s, &meth.body, meth.attrs);
|
2012-03-19 12:19:00 -05:00
|
|
|
}
|
|
|
|
|
2013-05-11 23:25:31 -05:00
|
|
|
pub fn print_outer_attributes(s: @ps, attrs: &[ast::attribute]) {
|
2012-03-15 08:47:03 -05:00
|
|
|
let mut count = 0;
|
2012-06-30 18:19:07 -05:00
|
|
|
for attrs.each |attr| {
|
2012-08-06 14:34:08 -05:00
|
|
|
match attr.node.style {
|
2012-09-19 18:55:01 -05:00
|
|
|
ast::attr_outer => { print_attribute(s, *attr); count += 1; }
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => {/* fallthrough */ }
|
2011-06-14 20:53:12 -05:00
|
|
|
}
|
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
if count > 0 { hardbreak_if_not_bol(s); }
|
2011-06-14 20:53:12 -05:00
|
|
|
}
|
|
|
|
|
2013-05-11 23:25:31 -05:00
|
|
|
pub fn print_inner_attributes(s: @ps, attrs: &[ast::attribute]) {
|
2012-03-15 08:47:03 -05:00
|
|
|
let mut count = 0;
|
2012-06-30 18:19:07 -05:00
|
|
|
for attrs.each |attr| {
|
2012-08-06 14:34:08 -05:00
|
|
|
match attr.node.style {
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::attr_inner => {
|
2012-09-19 18:55:01 -05:00
|
|
|
print_attribute(s, *attr);
|
2012-06-30 05:54:54 -05:00
|
|
|
if !attr.node.is_sugared_doc {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, ";");
|
2012-06-30 05:54:54 -05:00
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
count += 1;
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => {/* fallthrough */ }
|
2011-06-16 15:00:19 -05:00
|
|
|
}
|
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
if count > 0 { hardbreak_if_not_bol(s); }
|
2011-06-16 15:00:19 -05:00
|
|
|
}
|
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn print_attribute(s: @ps, attr: ast::attribute) {
|
2011-06-30 19:25:13 -05:00
|
|
|
hardbreak_if_not_bol(s);
|
2011-06-14 20:53:12 -05:00
|
|
|
maybe_print_comment(s, attr.span.lo);
|
2012-06-30 05:54:54 -05:00
|
|
|
if attr.node.is_sugared_doc {
|
|
|
|
let meta = attr::attr_meta(attr);
|
2012-09-20 20:15:39 -05:00
|
|
|
let comment = attr::get_meta_item_value_str(meta).get();
|
2013-06-12 12:02:55 -05:00
|
|
|
word(s.s, comment);
|
2012-06-30 05:54:54 -05:00
|
|
|
} else {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "#[");
|
2013-02-25 08:19:44 -06:00
|
|
|
print_meta_item(s, attr.node.value);
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "]");
|
2012-06-30 05:54:54 -05:00
|
|
|
}
|
2011-06-14 20:53:12 -05:00
|
|
|
}
|
|
|
|
|
2011-12-29 14:03:39 -06:00
|
|
|
|
2013-04-17 11:15:08 -05:00
|
|
|
pub fn print_stmt(s: @ps, st: &ast::stmt) {
|
2011-05-31 12:58:30 -05:00
|
|
|
maybe_print_comment(s, st.span.lo);
|
2012-08-06 14:34:08 -05:00
|
|
|
match st.node {
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::stmt_decl(decl, _) => {
|
2011-12-29 14:03:39 -06:00
|
|
|
print_decl(s, decl);
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::stmt_expr(expr, _) => {
|
2011-12-29 14:03:39 -06:00
|
|
|
space_if_not_bol(s);
|
2012-01-05 00:01:58 -06:00
|
|
|
print_expr(s, expr);
|
2012-07-03 19:30:25 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::stmt_semi(expr, _) => {
|
2012-07-03 19:30:25 -05:00
|
|
|
space_if_not_bol(s);
|
|
|
|
print_expr(s, expr);
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, ";");
|
2012-01-04 16:16:41 -06:00
|
|
|
}
|
2012-12-04 12:50:00 -06:00
|
|
|
ast::stmt_mac(ref mac, semi) => {
|
2012-11-12 22:06:55 -06:00
|
|
|
space_if_not_bol(s);
|
2013-05-11 23:25:31 -05:00
|
|
|
print_mac(s, mac);
|
2013-05-19 00:07:44 -05:00
|
|
|
if semi { word(s.s, ";"); }
|
2012-11-12 22:06:55 -06:00
|
|
|
}
|
2011-05-31 12:58:30 -05:00
|
|
|
}
|
2013-05-19 00:07:44 -05:00
|
|
|
if parse::classify::stmt_ends_with_semi(st) { word(s.s, ";"); }
|
2012-11-12 21:32:48 -06:00
|
|
|
maybe_print_trailing_comment(s, st.span, None);
|
2011-05-31 12:58:30 -05:00
|
|
|
}
|
|
|
|
|
2013-02-18 00:20:36 -06:00
|
|
|
pub fn print_block(s: @ps, blk: &ast::blk) {
|
2011-08-15 16:42:33 -05:00
|
|
|
print_possibly_embedded_block(s, blk, block_normal, indent_unit);
|
2011-07-13 17:44:09 -05:00
|
|
|
}
|
2011-07-08 18:35:09 -05:00
|
|
|
|
2013-02-18 00:20:36 -06:00
|
|
|
pub fn print_block_unclosed(s: @ps, blk: &ast::blk) {
|
2013-05-11 23:25:31 -05:00
|
|
|
print_possibly_embedded_block_(s, blk, block_normal, indent_unit, &[],
|
2012-08-09 18:31:47 -05:00
|
|
|
false);
|
|
|
|
}
|
|
|
|
|
2013-02-18 00:20:36 -06:00
|
|
|
pub fn print_block_unclosed_indent(s: @ps, blk: &ast::blk, indented: uint) {
|
2013-05-11 23:25:31 -05:00
|
|
|
print_possibly_embedded_block_(s, blk, block_normal, indented, &[],
|
2012-08-13 20:13:41 -05:00
|
|
|
false);
|
|
|
|
}
|
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn print_block_with_attrs(s: @ps,
|
2013-02-18 00:20:36 -06:00
|
|
|
blk: &ast::blk,
|
2013-05-11 23:25:31 -05:00
|
|
|
attrs: &[ast::attribute]) {
|
2012-08-09 18:31:47 -05:00
|
|
|
print_possibly_embedded_block_(s, blk, block_normal, indent_unit, attrs,
|
|
|
|
true);
|
2012-01-15 19:23:59 -06:00
|
|
|
}
|
|
|
|
|
2013-01-29 16:41:40 -06:00
|
|
|
pub enum embed_type { block_block_fn, block_normal, }
|
2011-08-15 16:42:33 -05:00
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn print_possibly_embedded_block(s: @ps,
|
2013-02-18 00:20:36 -06:00
|
|
|
blk: &ast::blk,
|
2013-01-29 16:41:40 -06:00
|
|
|
embedded: embed_type,
|
|
|
|
indented: uint) {
|
2012-01-15 19:23:59 -06:00
|
|
|
print_possibly_embedded_block_(
|
2013-05-11 23:25:31 -05:00
|
|
|
s, blk, embedded, indented, &[], true);
|
2012-01-15 19:23:59 -06:00
|
|
|
}
|
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn print_possibly_embedded_block_(s: @ps,
|
2013-02-18 00:20:36 -06:00
|
|
|
blk: &ast::blk,
|
2013-01-29 16:41:40 -06:00
|
|
|
embedded: embed_type,
|
|
|
|
indented: uint,
|
2013-05-11 23:25:31 -05:00
|
|
|
attrs: &[ast::attribute],
|
2013-01-29 16:41:40 -06:00
|
|
|
close_box: bool) {
|
2012-08-06 14:34:08 -05:00
|
|
|
match blk.node.rules {
|
2013-05-19 00:07:44 -05:00
|
|
|
ast::unsafe_blk => word_space(s, "unsafe"),
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::default_blk => ()
|
2011-10-06 18:42:27 -05:00
|
|
|
}
|
2011-03-24 10:33:20 -05:00
|
|
|
maybe_print_comment(s, blk.span.lo);
|
2011-07-27 07:19:39 -05:00
|
|
|
let ann_node = node_block(s, blk);
|
2012-11-29 19:51:16 -06:00
|
|
|
(s.ann.pre)(ann_node);
|
2012-08-06 14:34:08 -05:00
|
|
|
match embedded {
|
2012-08-03 21:59:04 -05:00
|
|
|
block_block_fn => end(s),
|
|
|
|
block_normal => bopen(s)
|
2011-08-15 16:42:33 -05:00
|
|
|
}
|
2011-08-02 22:46:36 -05:00
|
|
|
|
2012-01-15 19:23:59 -06:00
|
|
|
print_inner_attributes(s, attrs);
|
|
|
|
|
2012-09-19 18:55:01 -05:00
|
|
|
for blk.node.view_items.each |vi| { print_view_item(s, *vi); }
|
2012-06-30 18:19:07 -05:00
|
|
|
for blk.node.stmts.each |st| {
|
2013-04-17 11:15:08 -05:00
|
|
|
print_stmt(s, *st);
|
2011-08-02 22:46:36 -05:00
|
|
|
}
|
2012-08-06 14:34:08 -05:00
|
|
|
match blk.node.expr {
|
2012-08-20 14:23:37 -05:00
|
|
|
Some(expr) => {
|
2011-07-27 07:19:39 -05:00
|
|
|
space_if_not_bol(s);
|
2012-01-05 00:01:58 -06:00
|
|
|
print_expr(s, expr);
|
2012-08-20 14:23:37 -05:00
|
|
|
maybe_print_trailing_comment(s, expr.span, Some(blk.span.hi));
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => ()
|
2011-03-04 00:22:43 -06:00
|
|
|
}
|
2012-08-09 18:31:47 -05:00
|
|
|
bclose_maybe_open(s, blk.span, indented, close_box);
|
2012-11-29 19:51:16 -06:00
|
|
|
(s.ann.post)(ann_node);
|
2011-03-04 00:22:43 -06:00
|
|
|
}
|
|
|
|
|
2013-02-18 00:20:36 -06:00
|
|
|
pub fn print_if(s: @ps, test: @ast::expr, blk: &ast::blk,
|
2013-01-29 16:41:40 -06:00
|
|
|
elseopt: Option<@ast::expr>, chk: bool) {
|
2013-05-19 00:07:44 -05:00
|
|
|
head(s, "if");
|
|
|
|
if chk { word_nbsp(s, "check"); }
|
2012-10-27 19:14:09 -05:00
|
|
|
print_expr(s, test);
|
2011-06-16 16:08:17 -05:00
|
|
|
space(s.s);
|
2011-07-25 15:42:38 -05:00
|
|
|
print_block(s, blk);
|
2013-02-04 16:02:01 -06:00
|
|
|
fn do_else(s: @ps, els: Option<@ast::expr>) {
|
2012-08-06 14:34:08 -05:00
|
|
|
match els {
|
2012-08-20 14:23:37 -05:00
|
|
|
Some(_else) => {
|
2012-08-06 14:34:08 -05:00
|
|
|
match _else.node {
|
2011-07-27 07:19:39 -05:00
|
|
|
// "another else-if"
|
2012-12-04 12:50:00 -06:00
|
|
|
ast::expr_if(i, ref t, e) => {
|
2011-07-27 07:19:39 -05:00
|
|
|
cbox(s, indent_unit - 1u);
|
|
|
|
ibox(s, 0u);
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, " else if ");
|
2012-10-27 19:14:09 -05:00
|
|
|
print_expr(s, i);
|
2011-07-27 07:19:39 -05:00
|
|
|
space(s.s);
|
2013-02-18 00:20:36 -06:00
|
|
|
print_block(s, t);
|
2011-07-27 07:19:39 -05:00
|
|
|
do_else(s, e);
|
|
|
|
}
|
|
|
|
// "final else"
|
2012-12-04 12:50:00 -06:00
|
|
|
ast::expr_block(ref b) => {
|
2011-07-27 07:19:39 -05:00
|
|
|
cbox(s, indent_unit - 1u);
|
|
|
|
ibox(s, 0u);
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, " else ");
|
2013-02-18 00:20:36 -06:00
|
|
|
print_block(s, b);
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-01-30 23:00:57 -06:00
|
|
|
// BLEAH, constraints would be great here
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => {
|
2013-05-05 17:18:51 -05:00
|
|
|
fail!("print_if saw if with weird alternative");
|
2012-01-30 23:00:57 -06:00
|
|
|
}
|
2011-06-16 16:08:17 -05:00
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => {/* fall through */ }
|
2011-06-16 16:08:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
do_else(s, elseopt);
|
|
|
|
}
|
|
|
|
|
2013-05-11 23:25:31 -05:00
|
|
|
pub fn print_mac(s: @ps, m: &ast::mac) {
|
2012-08-06 14:34:08 -05:00
|
|
|
match m.node {
|
2012-12-04 12:50:00 -06:00
|
|
|
ast::mac_invoc_tt(pth, ref tts) => {
|
2012-07-18 18:18:02 -05:00
|
|
|
print_path(s, pth, false);
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "!");
|
2012-08-22 21:08:21 -05:00
|
|
|
popen(s);
|
2012-12-12 19:08:09 -06:00
|
|
|
print_tts(s, *tts);
|
2012-08-22 21:08:21 -05:00
|
|
|
pclose(s);
|
2012-07-11 12:42:25 -05:00
|
|
|
}
|
2011-07-08 18:35:09 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn print_vstore(s: @ps, t: ast::vstore) {
|
2012-08-06 14:34:08 -05:00
|
|
|
match t {
|
2013-03-05 20:09:33 -06:00
|
|
|
ast::vstore_fixed(Some(i)) => word(s.s, fmt!("%u", i)),
|
2013-05-19 00:07:44 -05:00
|
|
|
ast::vstore_fixed(None) => word(s.s, "_"),
|
|
|
|
ast::vstore_uniq => word(s.s, "~"),
|
|
|
|
ast::vstore_box => word(s.s, "@"),
|
2013-02-27 18:41:02 -06:00
|
|
|
ast::vstore_slice(r) => {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "&");
|
2013-02-27 18:41:02 -06:00
|
|
|
print_opt_lifetime(s, r);
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
}
|
2012-04-09 19:32:49 -05:00
|
|
|
}
|
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn print_expr_vstore(s: @ps, t: ast::expr_vstore) {
|
2012-09-11 23:25:01 -05:00
|
|
|
match t {
|
2013-05-19 00:07:44 -05:00
|
|
|
ast::expr_vstore_uniq => word(s.s, "~"),
|
|
|
|
ast::expr_vstore_box => word(s.s, "@"),
|
2012-11-21 13:39:06 -06:00
|
|
|
ast::expr_vstore_mut_box => {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "@");
|
|
|
|
word(s.s, "mut");
|
2012-11-21 13:39:06 -06:00
|
|
|
}
|
2013-05-19 00:07:44 -05:00
|
|
|
ast::expr_vstore_slice => word(s.s, "&"),
|
2012-12-07 18:26:52 -06:00
|
|
|
ast::expr_vstore_mut_slice => {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "&");
|
|
|
|
word(s.s, "mut");
|
2012-12-07 18:26:52 -06:00
|
|
|
}
|
2012-09-11 23:25:01 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn print_call_pre(s: @ps,
|
2013-01-31 19:12:29 -06:00
|
|
|
sugar: ast::CallSugar,
|
2013-01-29 16:41:40 -06:00
|
|
|
base_args: &mut ~[@ast::expr])
|
|
|
|
-> Option<@ast::expr> {
|
2013-01-31 19:12:29 -06:00
|
|
|
match sugar {
|
|
|
|
ast::DoSugar => {
|
2013-05-19 00:07:44 -05:00
|
|
|
head(s, "do");
|
2013-01-31 19:12:29 -06:00
|
|
|
Some(base_args.pop())
|
|
|
|
}
|
|
|
|
ast::ForSugar => {
|
2013-05-19 00:07:44 -05:00
|
|
|
head(s, "for");
|
2013-01-31 19:12:29 -06:00
|
|
|
Some(base_args.pop())
|
|
|
|
}
|
|
|
|
ast::NoSugar => None
|
2012-11-30 13:18:25 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn print_call_post(s: @ps,
|
2013-01-31 19:12:29 -06:00
|
|
|
sugar: ast::CallSugar,
|
2013-01-29 16:41:40 -06:00
|
|
|
blk: &Option<@ast::expr>,
|
|
|
|
base_args: &mut ~[@ast::expr]) {
|
2013-01-31 19:12:29 -06:00
|
|
|
if sugar == ast::NoSugar || !base_args.is_empty() {
|
2012-11-30 13:18:25 -06:00
|
|
|
popen(s);
|
|
|
|
commasep_exprs(s, inconsistent, *base_args);
|
|
|
|
pclose(s);
|
|
|
|
}
|
2013-01-31 19:12:29 -06:00
|
|
|
if sugar != ast::NoSugar {
|
2012-11-30 13:18:25 -06:00
|
|
|
nbsp(s);
|
|
|
|
match blk.get().node {
|
|
|
|
// need to handle closures specifically
|
|
|
|
ast::expr_do_body(e) | ast::expr_loop_body(e) => {
|
|
|
|
end(s); // we close our head box; closure
|
|
|
|
// will create it's own.
|
|
|
|
print_expr(s, e);
|
|
|
|
end(s); // close outer box, as closures don't
|
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
// not sure if this can happen.
|
|
|
|
print_expr(s, blk.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-17 11:15:08 -05:00
|
|
|
pub fn print_expr(s: @ps, expr: @ast::expr) {
|
2013-02-04 16:02:01 -06:00
|
|
|
fn print_field(s: @ps, field: ast::field) {
|
2012-07-23 18:39:18 -05:00
|
|
|
ibox(s, indent_unit);
|
2012-07-18 18:18:02 -05:00
|
|
|
print_ident(s, field.node.ident);
|
2013-05-19 00:07:44 -05:00
|
|
|
word_space(s, ":");
|
2012-07-23 18:39:18 -05:00
|
|
|
print_expr(s, field.node.expr);
|
|
|
|
end(s);
|
|
|
|
}
|
2012-08-01 19:30:05 -05:00
|
|
|
fn get_span(field: ast::field) -> codemap::span { return field.span; }
|
2012-07-23 18:39:18 -05:00
|
|
|
|
2011-03-24 10:33:20 -05:00
|
|
|
maybe_print_comment(s, expr.span.lo);
|
2011-06-01 17:29:38 -05:00
|
|
|
ibox(s, indent_unit);
|
2011-07-27 07:19:39 -05:00
|
|
|
let ann_node = node_expr(s, expr);
|
2012-11-29 19:51:16 -06:00
|
|
|
(s.ann.pre)(ann_node);
|
2013-03-19 20:24:01 -05:00
|
|
|
match expr.node {
|
2013-03-27 00:24:32 -05:00
|
|
|
ast::expr_vstore(e, v) => {
|
|
|
|
print_expr_vstore(s, v);
|
|
|
|
print_expr(s, e);
|
2012-09-11 23:25:01 -05:00
|
|
|
},
|
2013-03-19 20:24:01 -05:00
|
|
|
ast::expr_vec(ref exprs, mutbl) => {
|
2011-07-27 07:19:39 -05:00
|
|
|
ibox(s, indent_unit);
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "[");
|
2012-02-15 13:25:39 -06:00
|
|
|
if mutbl == ast::m_mutbl {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "mut");
|
2013-03-19 20:24:01 -05:00
|
|
|
if exprs.len() > 0u { nbsp(s); }
|
2011-07-27 14:20:51 -05:00
|
|
|
}
|
2013-03-19 20:24:01 -05:00
|
|
|
commasep_exprs(s, inconsistent, *exprs);
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "]");
|
2011-07-27 07:19:39 -05:00
|
|
|
end(s);
|
|
|
|
}
|
2012-08-03 20:01:30 -05:00
|
|
|
|
|
|
|
ast::expr_repeat(element, count, mutbl) => {
|
|
|
|
ibox(s, indent_unit);
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "[");
|
2012-08-03 20:01:30 -05:00
|
|
|
if mutbl == ast::m_mutbl {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "mut");
|
2012-08-03 20:01:30 -05:00
|
|
|
nbsp(s);
|
|
|
|
}
|
|
|
|
print_expr(s, element);
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, ",");
|
|
|
|
word(s.s, "..");
|
2012-08-03 20:01:30 -05:00
|
|
|
print_expr(s, count);
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "]");
|
2012-08-03 20:01:30 -05:00
|
|
|
end(s);
|
|
|
|
}
|
|
|
|
|
2012-12-04 12:50:00 -06:00
|
|
|
ast::expr_struct(path, ref fields, wth) => {
|
2012-07-23 18:39:18 -05:00
|
|
|
print_path(s, path, true);
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "{");
|
2012-12-04 12:50:00 -06:00
|
|
|
commasep_cmnt(s, consistent, (*fields), print_field, get_span);
|
2012-08-06 14:34:08 -05:00
|
|
|
match wth {
|
2012-08-20 14:23:37 -05:00
|
|
|
Some(expr) => {
|
2012-08-06 15:15:40 -05:00
|
|
|
ibox(s, indent_unit);
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, ",");
|
2012-08-13 18:06:21 -05:00
|
|
|
space(s.s);
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "..");
|
2012-08-06 15:15:40 -05:00
|
|
|
print_expr(s, expr);
|
|
|
|
end(s);
|
|
|
|
}
|
2013-05-19 00:07:44 -05:00
|
|
|
_ => (word(s.s, ","))
|
2012-08-06 15:15:40 -05:00
|
|
|
}
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "}");
|
2012-07-23 18:39:18 -05:00
|
|
|
}
|
2013-03-19 20:24:01 -05:00
|
|
|
ast::expr_tup(ref exprs) => {
|
2011-08-15 04:40:26 -05:00
|
|
|
popen(s);
|
2013-03-19 20:24:01 -05:00
|
|
|
commasep_exprs(s, inconsistent, *exprs);
|
2013-02-17 17:41:47 -06:00
|
|
|
if exprs.len() == 1 {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, ",");
|
2013-02-17 17:41:47 -06:00
|
|
|
}
|
2011-08-15 04:40:26 -05:00
|
|
|
pclose(s);
|
|
|
|
}
|
2013-03-19 20:24:01 -05:00
|
|
|
ast::expr_call(func, ref args, sugar) => {
|
|
|
|
let mut base_args = copy *args;
|
2013-01-31 19:12:29 -06:00
|
|
|
let blk = print_call_pre(s, sugar, &mut base_args);
|
2012-10-27 19:14:09 -05:00
|
|
|
print_expr(s, func);
|
2013-01-31 19:12:29 -06:00
|
|
|
print_call_post(s, sugar, &blk, &mut base_args);
|
2012-11-30 13:18:25 -06:00
|
|
|
}
|
2013-06-01 17:31:56 -05:00
|
|
|
ast::expr_method_call(_, func, ident, ref tys, ref args, sugar) => {
|
2013-03-19 20:24:01 -05:00
|
|
|
let mut base_args = copy *args;
|
2013-01-31 19:12:29 -06:00
|
|
|
let blk = print_call_pre(s, sugar, &mut base_args);
|
2012-11-30 13:18:25 -06:00
|
|
|
print_expr(s, func);
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, ".");
|
2012-11-30 13:18:25 -06:00
|
|
|
print_ident(s, ident);
|
2013-03-19 20:24:01 -05:00
|
|
|
if tys.len() > 0u {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "::<");
|
2013-03-19 20:24:01 -05:00
|
|
|
commasep(s, inconsistent, *tys, print_type);
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, ">");
|
2011-10-21 07:11:24 -05:00
|
|
|
}
|
2013-01-31 19:12:29 -06:00
|
|
|
print_call_post(s, sugar, &blk, &mut base_args);
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2013-06-01 17:31:56 -05:00
|
|
|
ast::expr_binary(_, op, lhs, rhs) => {
|
2012-10-27 19:14:09 -05:00
|
|
|
print_expr(s, lhs);
|
2011-07-27 07:19:39 -05:00
|
|
|
space(s.s);
|
2011-08-27 16:42:29 -05:00
|
|
|
word_space(s, ast_util::binop_to_str(op));
|
2012-10-27 19:14:09 -05:00
|
|
|
print_expr(s, rhs);
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2013-06-01 17:31:56 -05:00
|
|
|
ast::expr_unary(_, op, expr) => {
|
2011-08-27 16:42:29 -05:00
|
|
|
word(s.s, ast_util::unop_to_str(op));
|
2012-10-27 19:14:09 -05:00
|
|
|
print_expr(s, expr);
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::expr_addr_of(m, expr) => {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "&");
|
2012-03-08 18:34:36 -06:00
|
|
|
print_mutability(s, m);
|
2013-03-08 20:43:40 -06:00
|
|
|
// Avoid `& &e` => `&&e`.
|
|
|
|
match (m, &expr.node) {
|
|
|
|
(ast::m_imm, &ast::expr_addr_of(*)) => space(s.s),
|
|
|
|
_ => { }
|
|
|
|
}
|
2012-03-08 18:34:36 -06:00
|
|
|
print_expr(s, expr);
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::expr_lit(lit) => print_literal(s, lit),
|
|
|
|
ast::expr_cast(expr, ty) => {
|
2012-10-27 19:14:09 -05:00
|
|
|
print_expr(s, expr);
|
2011-07-27 07:19:39 -05:00
|
|
|
space(s.s);
|
2013-05-19 00:07:44 -05:00
|
|
|
word_space(s, "as");
|
2013-03-20 15:24:09 -05:00
|
|
|
print_type(s, ty);
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-12-04 12:50:00 -06:00
|
|
|
ast::expr_if(test, ref blk, elseopt) => {
|
2013-02-18 00:20:36 -06:00
|
|
|
print_if(s, test, blk, elseopt, false);
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-12-04 12:50:00 -06:00
|
|
|
ast::expr_while(test, ref blk) => {
|
2013-05-19 00:07:44 -05:00
|
|
|
head(s, "while");
|
2012-10-27 19:14:09 -05:00
|
|
|
print_expr(s, test);
|
2011-07-27 07:19:39 -05:00
|
|
|
space(s.s);
|
2013-02-18 00:20:36 -06:00
|
|
|
print_block(s, blk);
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-12-04 12:50:00 -06:00
|
|
|
ast::expr_loop(ref blk, opt_ident) => {
|
2013-06-10 16:50:12 -05:00
|
|
|
for opt_ident.iter().advance |ident| {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "'");
|
2012-10-18 14:20:18 -05:00
|
|
|
print_ident(s, *ident);
|
2013-05-19 00:07:44 -05:00
|
|
|
word_space(s, ":");
|
2013-03-03 06:33:39 -06:00
|
|
|
}
|
2013-05-19 00:07:44 -05:00
|
|
|
head(s, "loop");
|
2013-04-26 18:19:26 -05:00
|
|
|
space(s.s);
|
2013-02-18 00:20:36 -06:00
|
|
|
print_block(s, blk);
|
2012-03-09 18:11:56 -06:00
|
|
|
}
|
2012-12-04 12:50:00 -06:00
|
|
|
ast::expr_match(expr, ref arms) => {
|
2013-04-07 00:29:37 -05:00
|
|
|
cbox(s, indent_unit);
|
2012-10-27 19:14:09 -05:00
|
|
|
ibox(s, 4);
|
2013-05-19 00:07:44 -05:00
|
|
|
word_nbsp(s, "match");
|
2012-10-27 19:14:09 -05:00
|
|
|
print_expr(s, expr);
|
2011-07-27 07:19:39 -05:00
|
|
|
space(s.s);
|
|
|
|
bopen(s);
|
2013-04-07 00:29:37 -05:00
|
|
|
let len = arms.len();
|
2013-06-17 18:43:22 -05:00
|
|
|
for arms.iter().enumerate().advance |(i, arm)| {
|
2011-03-24 10:33:20 -05:00
|
|
|
space(s.s);
|
2013-04-07 00:29:37 -05:00
|
|
|
cbox(s, indent_unit);
|
2011-07-27 07:19:39 -05:00
|
|
|
ibox(s, 0u);
|
2012-03-15 08:47:03 -05:00
|
|
|
let mut first = true;
|
2012-06-30 18:19:07 -05:00
|
|
|
for arm.pats.each |p| {
|
2011-07-27 07:19:39 -05:00
|
|
|
if first {
|
|
|
|
first = false;
|
2013-05-19 00:07:44 -05:00
|
|
|
} else { space(s.s); word_space(s, "|"); }
|
2012-12-07 16:39:29 -06:00
|
|
|
print_refutable_pat(s, *p);
|
2011-03-24 10:33:20 -05:00
|
|
|
}
|
2011-06-14 08:20:04 -05:00
|
|
|
space(s.s);
|
2012-08-06 14:34:08 -05:00
|
|
|
match arm.guard {
|
2012-08-20 14:23:37 -05:00
|
|
|
Some(e) => {
|
2013-05-19 00:07:44 -05:00
|
|
|
word_space(s, "if");
|
2012-08-03 21:59:04 -05:00
|
|
|
print_expr(s, e);
|
|
|
|
space(s.s);
|
|
|
|
}
|
2012-08-20 14:23:37 -05:00
|
|
|
None => ()
|
2011-08-22 07:38:48 -05:00
|
|
|
}
|
2013-05-19 00:07:44 -05:00
|
|
|
word_space(s, "=>");
|
2012-08-28 17:54:45 -05:00
|
|
|
|
2012-08-01 18:16:53 -05:00
|
|
|
// Extract the expression from the extra block the parser adds
|
2012-08-28 17:54:45 -05:00
|
|
|
// in the case of foo => expr
|
|
|
|
if arm.body.node.view_items.is_empty() &&
|
|
|
|
arm.body.node.stmts.is_empty() &&
|
|
|
|
arm.body.node.rules == ast::default_blk &&
|
|
|
|
arm.body.node.expr.is_some()
|
|
|
|
{
|
|
|
|
match arm.body.node.expr {
|
|
|
|
Some(expr) => {
|
|
|
|
match expr.node {
|
2012-12-04 12:50:00 -06:00
|
|
|
ast::expr_block(ref blk) => {
|
2012-08-28 17:54:45 -05:00
|
|
|
// the block will close the pattern's ibox
|
|
|
|
print_block_unclosed_indent(
|
2013-04-07 00:29:37 -05:00
|
|
|
s, blk, indent_unit);
|
2012-08-28 17:54:45 -05:00
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
end(s); // close the ibox for the pattern
|
|
|
|
print_expr(s, expr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !expr_is_simple_block(expr)
|
|
|
|
&& i < len - 1 {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, ",");
|
2012-08-28 17:54:45 -05:00
|
|
|
}
|
|
|
|
end(s); // close enclosing cbox
|
|
|
|
}
|
2013-02-11 21:26:38 -06:00
|
|
|
None => fail!()
|
2012-08-01 18:16:53 -05:00
|
|
|
}
|
2012-08-28 17:54:45 -05:00
|
|
|
} else {
|
|
|
|
// the block will close the pattern's ibox
|
2013-04-07 00:29:37 -05:00
|
|
|
print_block_unclosed_indent(s, &arm.body, indent_unit);
|
2012-07-10 12:37:05 -05:00
|
|
|
}
|
2011-06-14 08:20:04 -05:00
|
|
|
}
|
2013-04-07 00:29:37 -05:00
|
|
|
bclose_(s, expr.span, indent_unit);
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2013-02-17 12:59:09 -06:00
|
|
|
ast::expr_fn_block(ref decl, ref body) => {
|
2012-08-09 18:31:47 -05:00
|
|
|
// in do/for blocks we don't want to show an empty
|
|
|
|
// argument list, but at this point we don't know which
|
|
|
|
// we are inside.
|
|
|
|
//
|
|
|
|
// if !decl.inputs.is_empty() {
|
2013-02-28 09:25:31 -06:00
|
|
|
print_fn_block_args(s, decl);
|
2012-08-09 18:31:47 -05:00
|
|
|
space(s.s);
|
|
|
|
// }
|
2013-03-28 20:39:09 -05:00
|
|
|
assert!(body.node.stmts.is_empty());
|
|
|
|
assert!(body.node.expr.is_some());
|
2012-08-09 18:31:47 -05:00
|
|
|
// we extract the block, so as not to create another set of boxes
|
2013-02-18 00:20:36 -06:00
|
|
|
match body.node.expr.get().node {
|
2012-12-04 12:50:00 -06:00
|
|
|
ast::expr_block(ref blk) => {
|
2013-02-18 00:20:36 -06:00
|
|
|
print_block_unclosed(s, blk);
|
2012-08-09 18:31:47 -05:00
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
// this is a bare expression
|
2013-02-18 00:20:36 -06:00
|
|
|
print_expr(s, body.node.expr.get());
|
2012-08-09 18:31:47 -05:00
|
|
|
end(s); // need to close a box
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// a box will be closed by print_expr, but we didn't want an overall
|
|
|
|
// wrapper so we closed the corresponding opening. so create an
|
|
|
|
// empty box to satisfy the close.
|
|
|
|
ibox(s, 0);
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::expr_loop_body(body) => {
|
2012-03-26 09:09:27 -05:00
|
|
|
print_expr(s, body);
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::expr_do_body(body) => {
|
2012-06-18 19:42:09 -05:00
|
|
|
print_expr(s, body);
|
|
|
|
}
|
2012-12-04 12:50:00 -06:00
|
|
|
ast::expr_block(ref blk) => {
|
2011-07-27 07:19:39 -05: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);
|
2013-02-18 00:20:36 -06:00
|
|
|
print_block(s, blk);
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2013-05-19 00:07:44 -05:00
|
|
|
ast::expr_copy(e) => { word_space(s, "copy"); print_expr(s, e); }
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::expr_assign(lhs, rhs) => {
|
2011-07-27 07:19:39 -05:00
|
|
|
print_expr(s, lhs);
|
|
|
|
space(s.s);
|
2013-05-19 00:07:44 -05:00
|
|
|
word_space(s, "=");
|
2011-07-27 07:19:39 -05:00
|
|
|
print_expr(s, rhs);
|
|
|
|
}
|
2013-06-01 17:31:56 -05:00
|
|
|
ast::expr_assign_op(_, op, lhs, rhs) => {
|
2011-07-27 07:19:39 -05:00
|
|
|
print_expr(s, lhs);
|
|
|
|
space(s.s);
|
2011-08-27 16:42:29 -05:00
|
|
|
word(s.s, ast_util::binop_to_str(op));
|
2013-05-19 00:07:44 -05:00
|
|
|
word_space(s, "=");
|
2011-07-27 07:19:39 -05:00
|
|
|
print_expr(s, rhs);
|
|
|
|
}
|
2013-03-19 20:24:01 -05:00
|
|
|
ast::expr_field(expr, id, ref tys) => {
|
2012-10-27 19:14:09 -05:00
|
|
|
print_expr(s, expr);
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, ".");
|
2012-07-18 18:18:02 -05:00
|
|
|
print_ident(s, id);
|
2013-03-19 20:24:01 -05:00
|
|
|
if tys.len() > 0u {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "::<");
|
2013-03-19 20:24:01 -05:00
|
|
|
commasep(s, inconsistent, *tys, print_type);
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, ">");
|
2011-12-19 03:21:31 -06:00
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2013-06-01 17:31:56 -05:00
|
|
|
ast::expr_index(_, expr, index) => {
|
2012-10-27 19:14:09 -05:00
|
|
|
print_expr(s, expr);
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "[");
|
2011-07-27 07:19:39 -05:00
|
|
|
print_expr(s, index);
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "]");
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::expr_path(path) => print_path(s, path, true),
|
2013-05-19 00:07:44 -05:00
|
|
|
ast::expr_self => word(s.s, "self"),
|
2012-08-14 21:20:56 -05:00
|
|
|
ast::expr_break(opt_ident) => {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "break");
|
2012-08-14 21:20:56 -05:00
|
|
|
space(s.s);
|
2013-06-10 16:50:12 -05:00
|
|
|
for opt_ident.iter().advance |ident| {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "'");
|
2013-04-26 18:19:26 -05:00
|
|
|
print_ident(s, *ident);
|
|
|
|
space(s.s);
|
|
|
|
}
|
2012-08-14 21:20:56 -05:00
|
|
|
}
|
|
|
|
ast::expr_again(opt_ident) => {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "loop");
|
2012-08-14 21:20:56 -05:00
|
|
|
space(s.s);
|
2013-06-10 16:50:12 -05:00
|
|
|
for opt_ident.iter().advance |ident| {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "'");
|
2013-04-26 18:19:26 -05:00
|
|
|
print_ident(s, *ident);
|
|
|
|
space(s.s)
|
|
|
|
}
|
2012-08-14 21:20:56 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::expr_ret(result) => {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "return");
|
2012-08-06 14:34:08 -05:00
|
|
|
match result {
|
2013-05-19 00:07:44 -05:00
|
|
|
Some(expr) => { word(s.s, " "); print_expr(s, expr); }
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => ()
|
2011-03-24 10:33:20 -05:00
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2013-03-26 23:42:01 -05:00
|
|
|
ast::expr_log(lexp, expr) => {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "__log");
|
2013-03-26 23:42:01 -05:00
|
|
|
popen(s);
|
|
|
|
print_expr(s, lexp);
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, ",");
|
2013-03-26 23:42:01 -05:00
|
|
|
space_if_not_bol(s);
|
|
|
|
print_expr(s, expr);
|
|
|
|
pclose(s);
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2013-05-11 23:25:31 -05:00
|
|
|
ast::expr_inline_asm(ref a) => {
|
2013-03-27 15:42:21 -05:00
|
|
|
if a.volatile {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "__volatile__ asm!");
|
2013-03-12 02:01:09 -05:00
|
|
|
} else {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "asm!");
|
2013-03-12 02:01:09 -05:00
|
|
|
}
|
2013-03-10 00:37:50 -06:00
|
|
|
popen(s);
|
2013-06-12 12:02:55 -05:00
|
|
|
print_string(s, a.asm);
|
2013-05-19 00:07:44 -05:00
|
|
|
word_space(s, ":");
|
2013-03-27 15:42:21 -05:00
|
|
|
for a.outputs.each |&(co, o)| {
|
2013-06-12 12:02:55 -05:00
|
|
|
print_string(s, co);
|
2013-03-12 19:53:25 -05:00
|
|
|
popen(s);
|
|
|
|
print_expr(s, o);
|
|
|
|
pclose(s);
|
2013-05-19 00:07:44 -05:00
|
|
|
word_space(s, ",");
|
2013-03-12 19:53:25 -05:00
|
|
|
}
|
2013-05-19 00:07:44 -05:00
|
|
|
word_space(s, ":");
|
2013-03-27 15:42:21 -05:00
|
|
|
for a.inputs.each |&(co, o)| {
|
2013-06-12 12:02:55 -05:00
|
|
|
print_string(s, co);
|
2013-03-12 19:53:25 -05:00
|
|
|
popen(s);
|
|
|
|
print_expr(s, o);
|
|
|
|
pclose(s);
|
2013-05-19 00:07:44 -05:00
|
|
|
word_space(s, ",");
|
2013-03-12 19:53:25 -05:00
|
|
|
}
|
2013-05-19 00:07:44 -05:00
|
|
|
word_space(s, ":");
|
2013-06-12 12:02:55 -05:00
|
|
|
print_string(s, a.clobbers);
|
2013-03-10 00:37:50 -06:00
|
|
|
pclose(s);
|
|
|
|
}
|
2013-05-11 23:25:31 -05:00
|
|
|
ast::expr_mac(ref m) => print_mac(s, m),
|
2012-10-27 19:14:09 -05:00
|
|
|
ast::expr_paren(e) => {
|
|
|
|
popen(s);
|
|
|
|
print_expr(s, e);
|
|
|
|
pclose(s);
|
|
|
|
}
|
2011-03-24 22:03:12 -05:00
|
|
|
}
|
2012-11-29 19:51:16 -06:00
|
|
|
(s.ann.post)(ann_node);
|
2011-06-01 17:29:38 -05:00
|
|
|
end(s);
|
2011-03-04 00:22:43 -06:00
|
|
|
}
|
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn print_local_decl(s: @ps, loc: @ast::local) {
|
2012-12-07 16:39:29 -06:00
|
|
|
print_irrefutable_pat(s, loc.node.pat);
|
2012-08-06 14:34:08 -05:00
|
|
|
match loc.node.ty.node {
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::ty_infer => (),
|
2013-05-19 00:07:44 -05:00
|
|
|
_ => { word_space(s, ":"); print_type(s, loc.node.ty); }
|
2011-08-10 14:51:50 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn print_decl(s: @ps, decl: @ast::decl) {
|
2011-03-24 10:33:20 -05:00
|
|
|
maybe_print_comment(s, decl.span.lo);
|
2013-03-19 20:24:01 -05:00
|
|
|
match decl.node {
|
2013-06-04 23:43:41 -05:00
|
|
|
ast::decl_local(ref loc) => {
|
2011-07-27 07:19:39 -05:00
|
|
|
space_if_not_bol(s);
|
|
|
|
ibox(s, indent_unit);
|
2013-05-19 00:07:44 -05:00
|
|
|
word_nbsp(s, "let");
|
2012-03-22 10:39:41 -05:00
|
|
|
|
2013-06-04 23:43:41 -05:00
|
|
|
if loc.node.is_mutbl {
|
2013-05-19 00:07:44 -05:00
|
|
|
word_nbsp(s, "mut");
|
2012-03-22 10:39:41 -05:00
|
|
|
}
|
|
|
|
|
2013-04-17 11:15:08 -05:00
|
|
|
fn print_local(s: @ps, loc: @ast::local) {
|
2011-07-28 05:01:45 -05:00
|
|
|
ibox(s, indent_unit);
|
2011-08-10 14:51:50 -05:00
|
|
|
print_local_decl(s, loc);
|
2011-07-28 05:01:45 -05:00
|
|
|
end(s);
|
2012-08-06 14:34:08 -05:00
|
|
|
match loc.node.init {
|
2012-08-20 14:23:37 -05:00
|
|
|
Some(init) => {
|
2011-07-27 07:19:39 -05:00
|
|
|
nbsp(s);
|
2013-05-19 00:07:44 -05:00
|
|
|
word_space(s, "=");
|
2012-10-23 13:28:20 -05:00
|
|
|
print_expr(s, init);
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => ()
|
2011-03-24 22:03:12 -05:00
|
|
|
}
|
2011-03-04 00:22:43 -06:00
|
|
|
}
|
2013-06-04 23:43:41 -05:00
|
|
|
|
|
|
|
print_local(s, *loc);
|
2011-07-27 07:19:39 -05:00
|
|
|
end(s);
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::decl_item(item) => print_item(s, item)
|
2011-03-04 00:22:43 -06:00
|
|
|
}
|
2011-03-24 10:33:20 -05:00
|
|
|
}
|
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn print_ident(s: @ps, ident: ast::ident) {
|
2013-06-12 12:02:55 -05:00
|
|
|
word(s.s, ident_to_str(&ident));
|
2013-01-29 16:41:40 -06:00
|
|
|
}
|
2011-04-05 16:18:44 -05:00
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn print_for_decl(s: @ps, loc: @ast::local, coll: @ast::expr) {
|
2011-08-10 14:51:50 -05:00
|
|
|
print_local_decl(s, loc);
|
2011-06-13 19:04:15 -05:00
|
|
|
space(s.s);
|
2013-05-19 00:07:44 -05:00
|
|
|
word_space(s, "in");
|
2011-07-27 10:18:53 -05:00
|
|
|
print_expr(s, coll);
|
2011-03-04 00:22:43 -06:00
|
|
|
}
|
|
|
|
|
2013-04-17 11:15:08 -05:00
|
|
|
pub fn print_path(s: @ps, path: @ast::Path, colons_before_params: bool) {
|
2011-03-24 10:33:20 -05:00
|
|
|
maybe_print_comment(s, path.span.lo);
|
2013-05-19 00:07:44 -05:00
|
|
|
if path.global { word(s.s, "::"); }
|
2012-03-15 08:47:03 -05:00
|
|
|
let mut first = true;
|
2012-06-30 18:19:07 -05:00
|
|
|
for path.idents.each |id| {
|
2013-05-19 00:07:44 -05:00
|
|
|
if first { first = false; } else { word(s.s, "::"); }
|
2012-09-19 18:55:01 -05:00
|
|
|
print_ident(s, *id);
|
2011-03-24 10:33:20 -05:00
|
|
|
}
|
2012-04-24 17:52:52 -05:00
|
|
|
if path.rp.is_some() || !path.types.is_empty() {
|
2013-05-19 00:07:44 -05:00
|
|
|
if colons_before_params { word(s.s, "::"); }
|
2012-04-24 17:52:52 -05:00
|
|
|
|
2013-02-27 18:41:02 -06:00
|
|
|
if path.rp.is_some() || !path.types.is_empty() {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "<");
|
2013-02-27 18:41:02 -06:00
|
|
|
|
2013-06-10 16:50:12 -05:00
|
|
|
for path.rp.iter().advance |r| {
|
2013-02-27 18:41:02 -06:00
|
|
|
print_lifetime(s, *r);
|
|
|
|
if !path.types.is_empty() {
|
2013-05-19 00:07:44 -05:00
|
|
|
word_space(s, ",");
|
2013-02-27 18:41:02 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-24 17:52:52 -05:00
|
|
|
commasep(s, inconsistent, path.types, print_type);
|
2013-02-27 18:41:02 -06:00
|
|
|
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, ">");
|
2012-04-24 17:52:52 -05:00
|
|
|
}
|
2011-03-24 10:33:20 -05:00
|
|
|
}
|
2011-03-04 00:22:43 -06:00
|
|
|
}
|
|
|
|
|
2013-04-17 11:15:08 -05:00
|
|
|
pub fn print_irrefutable_pat(s: @ps, pat: @ast::pat) {
|
2012-12-07 16:39:29 -06:00
|
|
|
print_pat(s, pat, false)
|
2012-12-07 14:52:01 -06:00
|
|
|
}
|
|
|
|
|
2013-04-17 11:15:08 -05:00
|
|
|
pub fn print_refutable_pat(s: @ps, pat: @ast::pat) {
|
2012-12-07 16:39:29 -06:00
|
|
|
print_pat(s, pat, true)
|
|
|
|
}
|
|
|
|
|
2013-04-17 11:15:08 -05:00
|
|
|
pub fn print_pat(s: @ps, pat: @ast::pat, refutable: bool) {
|
2011-03-24 10:33:20 -05:00
|
|
|
maybe_print_comment(s, pat.span.lo);
|
2011-07-27 07:19:39 -05:00
|
|
|
let ann_node = node_pat(s, pat);
|
2012-11-29 19:51:16 -06:00
|
|
|
(s.ann.pre)(ann_node);
|
2012-01-14 18:05:07 -06:00
|
|
|
/* Pat isn't normalized, but the beauty of it
|
|
|
|
is that it doesn't matter */
|
2013-03-19 20:24:01 -05:00
|
|
|
match pat.node {
|
2013-05-19 00:07:44 -05:00
|
|
|
ast::pat_wild => word(s.s, "_"),
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::pat_ident(binding_mode, path, sub) => {
|
2012-12-07 16:39:29 -06:00
|
|
|
if refutable {
|
2012-12-07 14:52:01 -06:00
|
|
|
match binding_mode {
|
|
|
|
ast::bind_by_ref(mutbl) => {
|
2013-05-19 00:07:44 -05:00
|
|
|
word_nbsp(s, "ref");
|
2012-12-07 14:52:01 -06:00
|
|
|
print_mutability(s, mutbl);
|
|
|
|
}
|
2012-12-07 21:34:57 -06:00
|
|
|
ast::bind_infer => {}
|
2012-12-07 14:52:01 -06:00
|
|
|
}
|
2012-08-24 13:04:07 -05:00
|
|
|
}
|
2012-12-07 14:52:01 -06:00
|
|
|
print_path(s, path, true);
|
|
|
|
match sub {
|
|
|
|
Some(p) => {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "@");
|
2012-12-07 16:39:29 -06:00
|
|
|
print_pat(s, p, refutable);
|
2012-12-07 14:52:01 -06:00
|
|
|
}
|
|
|
|
None => ()
|
2012-12-07 14:29:46 -06:00
|
|
|
}
|
2011-12-08 04:56:16 -06:00
|
|
|
}
|
2013-03-19 20:24:01 -05:00
|
|
|
ast::pat_enum(path, ref args_) => {
|
2011-08-16 11:03:58 -05:00
|
|
|
print_path(s, path, true);
|
2013-03-19 20:24:01 -05:00
|
|
|
match *args_ {
|
2013-05-19 00:07:44 -05:00
|
|
|
None => word(s.s, "(*)"),
|
2013-03-19 20:24:01 -05:00
|
|
|
Some(ref args) => {
|
2013-01-24 21:19:44 -06:00
|
|
|
if !args.is_empty() {
|
2012-04-20 02:54:42 -05:00
|
|
|
popen(s);
|
2013-03-19 20:24:01 -05:00
|
|
|
commasep(s, inconsistent, *args,
|
2012-12-07 16:39:29 -06:00
|
|
|
|s, p| print_pat(s, p, refutable));
|
2012-04-20 02:54:42 -05:00
|
|
|
pclose(s);
|
|
|
|
} else { }
|
|
|
|
}
|
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2013-05-11 23:25:31 -05:00
|
|
|
ast::pat_struct(path, ref fields, etc) => {
|
2012-08-06 19:01:14 -05:00
|
|
|
print_path(s, path, true);
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "{");
|
2013-02-04 16:02:01 -06:00
|
|
|
fn print_field(s: @ps, f: ast::field_pat, refutable: bool) {
|
2012-08-06 19:01:14 -05:00
|
|
|
cbox(s, indent_unit);
|
2012-07-18 18:18:02 -05:00
|
|
|
print_ident(s, f.ident);
|
2013-05-19 00:07:44 -05:00
|
|
|
word_space(s, ":");
|
2012-12-07 16:39:29 -06:00
|
|
|
print_pat(s, f.pat, refutable);
|
2011-07-27 07:19:39 -05:00
|
|
|
end(s);
|
2011-07-11 07:13:20 -05:00
|
|
|
}
|
2012-08-01 19:30:05 -05:00
|
|
|
fn get_span(f: ast::field_pat) -> codemap::span { return f.pat.span; }
|
2013-05-11 23:25:31 -05:00
|
|
|
commasep_cmnt(s, consistent, *fields,
|
2012-12-07 16:39:29 -06:00
|
|
|
|s, f| print_field(s,f,refutable),
|
|
|
|
get_span);
|
2011-07-27 07:19:39 -05:00
|
|
|
if etc {
|
2013-05-19 00:07:44 -05:00
|
|
|
if fields.len() != 0u { word_space(s, ","); }
|
|
|
|
word(s.s, "_");
|
2011-07-13 03:50:16 -05:00
|
|
|
}
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "}");
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2013-05-11 23:25:31 -05:00
|
|
|
ast::pat_tup(ref elts) => {
|
2011-08-15 06:15:19 -05:00
|
|
|
popen(s);
|
2013-05-11 23:25:31 -05:00
|
|
|
commasep(s, inconsistent, *elts, |s, p| print_pat(s, p, refutable));
|
2013-02-17 17:41:47 -06:00
|
|
|
if elts.len() == 1 {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, ",");
|
2013-02-17 17:41:47 -06:00
|
|
|
}
|
2011-08-15 06:15:19 -05:00
|
|
|
pclose(s);
|
|
|
|
}
|
2012-12-07 14:52:01 -06:00
|
|
|
ast::pat_box(inner) => {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "@");
|
2012-12-07 16:39:29 -06:00
|
|
|
print_pat(s, inner, refutable);
|
2012-12-07 14:52:01 -06:00
|
|
|
}
|
|
|
|
ast::pat_uniq(inner) => {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "~");
|
2012-12-07 16:39:29 -06:00
|
|
|
print_pat(s, inner, refutable);
|
2012-12-07 14:52:01 -06:00
|
|
|
}
|
2012-09-07 19:07:32 -05:00
|
|
|
ast::pat_region(inner) => {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "&");
|
2012-12-07 16:39:29 -06:00
|
|
|
print_pat(s, inner, refutable);
|
2012-09-07 19:07:32 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::pat_lit(e) => print_expr(s, e),
|
|
|
|
ast::pat_range(begin, end) => {
|
2011-12-02 06:42:51 -06:00
|
|
|
print_expr(s, begin);
|
2011-09-28 14:07:33 -05:00
|
|
|
space(s.s);
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "..");
|
2011-12-02 06:42:51 -06:00
|
|
|
print_expr(s, end);
|
2011-09-28 14:07:33 -05:00
|
|
|
}
|
2013-05-11 23:25:31 -05:00
|
|
|
ast::pat_vec(ref before, slice, ref after) => {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "[");
|
2013-05-11 23:25:31 -05:00
|
|
|
do commasep(s, inconsistent, *before) |s, p| {
|
2013-02-26 12:58:46 -06:00
|
|
|
print_pat(s, p, refutable);
|
|
|
|
}
|
2013-06-10 16:50:12 -05:00
|
|
|
for slice.iter().advance |&p| {
|
2013-05-19 00:07:44 -05:00
|
|
|
if !before.is_empty() { word_space(s, ","); }
|
|
|
|
word(s.s, "..");
|
2013-02-26 12:58:46 -06:00
|
|
|
print_pat(s, p, refutable);
|
2013-05-19 00:07:44 -05:00
|
|
|
if !after.is_empty() { word_space(s, ","); }
|
2013-02-26 12:58:46 -06:00
|
|
|
}
|
2013-05-11 23:25:31 -05:00
|
|
|
do commasep(s, inconsistent, *after) |s, p| {
|
2013-02-26 12:58:46 -06:00
|
|
|
print_pat(s, p, refutable);
|
2012-12-08 14:22:43 -06:00
|
|
|
}
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "]");
|
2012-12-08 14:22:43 -06:00
|
|
|
}
|
2011-03-04 00:22:43 -06:00
|
|
|
}
|
2012-11-29 19:51:16 -06:00
|
|
|
(s.ann.post)(ann_node);
|
2011-03-04 00:22:43 -06:00
|
|
|
}
|
|
|
|
|
2013-04-30 10:49:48 -05:00
|
|
|
pub fn explicit_self_to_str(explicit_self: ast::explicit_self_, intr: @ident_interner) -> ~str {
|
|
|
|
to_str(explicit_self, |a, b| { print_explicit_self(a, b); () }, intr)
|
2013-04-10 15:11:27 -05:00
|
|
|
}
|
|
|
|
|
2012-08-16 18:44:22 -05:00
|
|
|
// Returns whether it printed anything
|
2013-04-30 10:49:48 -05:00
|
|
|
pub fn print_explicit_self(s: @ps, explicit_self: ast::explicit_self_) -> bool {
|
|
|
|
match explicit_self {
|
2013-03-26 05:05:40 -05:00
|
|
|
ast::sty_static => { return false; }
|
2013-05-19 00:07:44 -05:00
|
|
|
ast::sty_value => { word(s.s, "self"); }
|
2013-03-09 18:43:53 -06:00
|
|
|
ast::sty_region(lt, m) => {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "&");
|
2013-03-09 18:43:53 -06:00
|
|
|
print_opt_lifetime(s, lt);
|
|
|
|
print_mutability(s, m);
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "self");
|
2013-03-09 18:43:53 -06:00
|
|
|
}
|
|
|
|
ast::sty_box(m) => {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "@"); print_mutability(s, m); word(s.s, "self");
|
2013-03-09 18:43:53 -06:00
|
|
|
}
|
|
|
|
ast::sty_uniq(m) => {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "~"); print_mutability(s, m); word(s.s, "self");
|
2013-03-09 18:43:53 -06:00
|
|
|
}
|
2012-08-17 18:14:57 -05:00
|
|
|
}
|
2012-08-16 18:44:22 -05:00
|
|
|
return true;
|
2012-08-17 18:14:57 -05:00
|
|
|
}
|
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn print_fn(s: @ps,
|
2013-02-28 09:25:31 -06:00
|
|
|
decl: &ast::fn_decl,
|
2013-03-13 21:25:28 -05:00
|
|
|
purity: Option<ast::purity>,
|
|
|
|
abis: AbiSet,
|
2013-01-29 16:41:40 -06:00
|
|
|
name: ast::ident,
|
2013-02-14 23:50:03 -06:00
|
|
|
generics: &ast::Generics,
|
2013-04-30 10:49:48 -05:00
|
|
|
opt_explicit_self: Option<ast::explicit_self_>,
|
2013-01-29 16:41:40 -06:00
|
|
|
vis: ast::visibility) {
|
2013-05-19 00:07:44 -05:00
|
|
|
head(s, "");
|
2013-04-30 10:49:48 -05:00
|
|
|
print_fn_header_info(s, opt_explicit_self, purity, abis, ast::Many, None, vis);
|
2012-11-04 22:41:00 -06:00
|
|
|
nbsp(s);
|
2012-07-18 18:18:02 -05:00
|
|
|
print_ident(s, name);
|
2013-02-14 23:50:03 -06:00
|
|
|
print_generics(s, generics);
|
2013-04-30 10:49:48 -05:00
|
|
|
print_fn_args_and_ret(s, decl, opt_explicit_self);
|
2011-06-14 08:20:04 -05:00
|
|
|
}
|
|
|
|
|
2013-02-28 09:25:31 -06:00
|
|
|
pub fn print_fn_args(s: @ps, decl: &ast::fn_decl,
|
2013-04-30 10:49:48 -05:00
|
|
|
opt_explicit_self: Option<ast::explicit_self_>) {
|
2013-06-06 02:38:41 -05:00
|
|
|
// It is unfortunate to duplicate the commasep logic, but we want the
|
2013-01-10 12:59:58 -06:00
|
|
|
// self type and the args all in the same box.
|
|
|
|
box(s, 0u, inconsistent);
|
2012-08-17 18:14:57 -05:00
|
|
|
let mut first = true;
|
2013-06-10 16:50:12 -05:00
|
|
|
for opt_explicit_self.iter().advance |explicit_self| {
|
2013-04-30 10:49:48 -05:00
|
|
|
first = !print_explicit_self(s, *explicit_self);
|
2012-08-17 18:14:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
for decl.inputs.each |arg| {
|
2013-05-19 00:07:44 -05:00
|
|
|
if first { first = false; } else { word_space(s, ","); }
|
2012-09-19 18:55:01 -05:00
|
|
|
print_arg(s, *arg);
|
2011-12-30 15:32:42 -06:00
|
|
|
}
|
2012-08-17 18:14:57 -05:00
|
|
|
|
|
|
|
end(s);
|
2011-12-30 15:32:42 -06:00
|
|
|
}
|
|
|
|
|
2013-02-28 09:25:31 -06:00
|
|
|
pub fn print_fn_args_and_ret(s: @ps, decl: &ast::fn_decl,
|
2013-04-30 10:49:48 -05:00
|
|
|
opt_explicit_self: Option<ast::explicit_self_>) {
|
2011-03-24 10:33:20 -05:00
|
|
|
popen(s);
|
2013-04-30 10:49:48 -05:00
|
|
|
print_fn_args(s, decl, opt_explicit_self);
|
2011-03-24 10:33:20 -05:00
|
|
|
pclose(s);
|
2012-02-22 04:16:25 -06:00
|
|
|
|
2011-03-24 10:33:20 -05:00
|
|
|
maybe_print_comment(s, decl.output.span.lo);
|
2012-09-07 20:53:14 -05:00
|
|
|
match decl.output.node {
|
|
|
|
ast::ty_nil => {}
|
|
|
|
_ => {
|
|
|
|
space_if_not_bol(s);
|
2013-05-19 00:07:44 -05:00
|
|
|
word_space(s, "->");
|
2012-09-07 20:53:14 -05:00
|
|
|
print_type(s, decl.output);
|
|
|
|
}
|
2011-03-24 10:33:20 -05:00
|
|
|
}
|
2011-03-04 00:22:43 -06:00
|
|
|
}
|
|
|
|
|
2013-02-28 09:25:31 -06:00
|
|
|
pub fn print_fn_block_args(s: @ps, decl: &ast::fn_decl) {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "|");
|
2013-01-10 12:59:58 -06:00
|
|
|
print_fn_args(s, decl, None);
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "|");
|
2012-09-07 20:53:14 -05:00
|
|
|
|
|
|
|
match decl.output.node {
|
|
|
|
ast::ty_infer => {}
|
|
|
|
_ => {
|
|
|
|
space_if_not_bol(s);
|
2013-05-19 00:07:44 -05:00
|
|
|
word_space(s, "->");
|
2012-09-07 20:53:14 -05:00
|
|
|
print_type(s, decl.output);
|
|
|
|
}
|
2011-12-20 18:18:18 -06:00
|
|
|
}
|
2012-09-07 20:53:14 -05:00
|
|
|
|
2011-08-15 16:42:33 -05:00
|
|
|
maybe_print_comment(s, decl.output.span.lo);
|
|
|
|
}
|
|
|
|
|
2013-02-14 23:50:03 -06:00
|
|
|
pub fn print_bounds(s: @ps, bounds: @OptVec<ast::TyParamBound>) {
|
2013-01-24 21:19:44 -06:00
|
|
|
if !bounds.is_empty() {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, ":");
|
2013-01-22 16:37:32 -06:00
|
|
|
let mut first = true;
|
2013-02-14 23:50:03 -06:00
|
|
|
for bounds.each |bound| {
|
2011-12-28 10:50:12 -06:00
|
|
|
nbsp(s);
|
2013-01-22 16:37:32 -06:00
|
|
|
if first {
|
|
|
|
first = false;
|
|
|
|
} else {
|
2013-05-19 00:07:44 -05:00
|
|
|
word_space(s, "+");
|
2013-01-22 16:37:32 -06:00
|
|
|
}
|
|
|
|
|
2013-02-14 23:50:03 -06:00
|
|
|
match *bound {
|
2013-03-27 05:16:28 -05:00
|
|
|
TraitTyParamBound(tref) => print_trait_ref(s, tref),
|
2013-05-19 00:07:44 -05:00
|
|
|
RegionTyParamBound => word(s.s, "'static"),
|
2013-01-10 13:16:54 -06:00
|
|
|
}
|
2011-12-28 10:50:12 -06:00
|
|
|
}
|
2011-08-02 23:26:54 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-17 11:15:08 -05:00
|
|
|
pub fn print_lifetime(s: @ps, lifetime: &ast::Lifetime) {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "'");
|
2013-02-14 23:50:03 -06:00
|
|
|
print_ident(s, lifetime.ident);
|
|
|
|
}
|
|
|
|
|
2013-04-17 11:15:08 -05:00
|
|
|
pub fn print_generics(s: @ps, generics: &ast::Generics) {
|
2013-02-14 23:50:03 -06:00
|
|
|
let total = generics.lifetimes.len() + generics.ty_params.len();
|
|
|
|
if total > 0 {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "<");
|
2013-02-14 23:50:03 -06:00
|
|
|
fn print_item(s: @ps, generics: &ast::Generics, idx: uint) {
|
|
|
|
if idx < generics.lifetimes.len() {
|
|
|
|
let lifetime = generics.lifetimes.get(idx);
|
|
|
|
print_lifetime(s, lifetime);
|
|
|
|
} else {
|
2013-03-01 10:25:51 -06:00
|
|
|
let idx = idx - generics.lifetimes.len();
|
2013-02-14 23:50:03 -06:00
|
|
|
let param = generics.ty_params.get(idx);
|
|
|
|
print_ident(s, param.ident);
|
|
|
|
print_bounds(s, param.bounds);
|
|
|
|
}
|
2011-07-28 12:22:59 -05:00
|
|
|
}
|
2013-02-14 23:50:03 -06:00
|
|
|
|
|
|
|
let mut ints = ~[];
|
|
|
|
for uint::range(0, total) |i| {
|
|
|
|
ints.push(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
commasep(s, inconsistent, ints,
|
|
|
|
|s, i| print_item(s, generics, i));
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, ">");
|
2011-03-24 10:33:20 -05:00
|
|
|
}
|
2011-03-04 00:22:43 -06:00
|
|
|
}
|
|
|
|
|
2013-04-17 11:15:08 -05:00
|
|
|
pub fn print_meta_item(s: @ps, item: @ast::meta_item) {
|
2011-06-14 20:53:12 -05:00
|
|
|
ibox(s, indent_unit);
|
2012-08-06 14:34:08 -05:00
|
|
|
match item.node {
|
2013-06-12 12:02:55 -05:00
|
|
|
ast::meta_word(name) => word(s.s, name),
|
2013-02-14 09:34:21 -06:00
|
|
|
ast::meta_name_value(name, value) => {
|
2013-06-12 12:02:55 -05:00
|
|
|
word_space(s, name);
|
2013-05-19 00:07:44 -05:00
|
|
|
word_space(s, "=");
|
2011-07-27 07:19:39 -05:00
|
|
|
print_literal(s, @value);
|
|
|
|
}
|
2013-02-14 09:34:21 -06:00
|
|
|
ast::meta_list(name, ref items) => {
|
2013-06-12 12:02:55 -05:00
|
|
|
word(s.s, name);
|
2011-07-27 07:19:39 -05:00
|
|
|
popen(s);
|
2013-02-17 12:59:09 -06:00
|
|
|
commasep(
|
|
|
|
s,
|
|
|
|
consistent,
|
|
|
|
/* FIXME (#2543) */ copy *items,
|
|
|
|
print_meta_item
|
|
|
|
);
|
2011-07-27 07:19:39 -05:00
|
|
|
pclose(s);
|
|
|
|
}
|
2011-06-21 16:23:16 -05:00
|
|
|
}
|
2011-06-14 20:53:12 -05:00
|
|
|
end(s);
|
|
|
|
}
|
|
|
|
|
2013-04-17 11:15:08 -05:00
|
|
|
pub fn print_view_path(s: @ps, vp: @ast::view_path) {
|
2012-08-06 14:34:08 -05:00
|
|
|
match vp.node {
|
2013-04-22 14:32:59 -05:00
|
|
|
ast::view_path_simple(ident, path, _) => {
|
2013-05-14 04:52:12 -05:00
|
|
|
if path.idents[path.idents.len()-1u] != ident {
|
2012-07-18 18:18:02 -05:00
|
|
|
print_ident(s, ident);
|
|
|
|
space(s.s);
|
2013-05-19 00:07:44 -05:00
|
|
|
word_space(s, "=");
|
2012-02-18 01:05:20 -06:00
|
|
|
}
|
2012-04-13 03:46:56 -05:00
|
|
|
print_path(s, path, false);
|
2012-02-18 01:05:20 -06:00
|
|
|
}
|
|
|
|
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::view_path_glob(path, _) => {
|
2012-04-13 03:46:56 -05:00
|
|
|
print_path(s, path, false);
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "::*");
|
2012-02-18 01:05:20 -06:00
|
|
|
}
|
|
|
|
|
2012-12-04 12:50:00 -06:00
|
|
|
ast::view_path_list(path, ref idents, _) => {
|
2012-04-13 03:46:56 -05:00
|
|
|
print_path(s, path, false);
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "::{");
|
2012-12-04 12:50:00 -06:00
|
|
|
do commasep(s, inconsistent, (*idents)) |s, w| {
|
2012-07-18 18:18:02 -05:00
|
|
|
print_ident(s, w.node.name);
|
2012-02-18 01:05:20 -06:00
|
|
|
}
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "}");
|
2012-02-18 01:05:20 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-19 20:24:01 -05:00
|
|
|
pub fn print_view_paths(s: @ps, vps: &[@ast::view_path]) {
|
2012-02-18 01:05:20 -06:00
|
|
|
commasep(s, inconsistent, vps, print_view_path);
|
|
|
|
}
|
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn print_view_item(s: @ps, item: @ast::view_item) {
|
2011-06-20 11:15:11 -05:00
|
|
|
hardbreak_if_not_bol(s);
|
2011-03-24 10:33:20 -05:00
|
|
|
maybe_print_comment(s, item.span.lo);
|
2012-07-09 17:39:56 -05:00
|
|
|
print_outer_attributes(s, item.attrs);
|
2012-09-21 20:10:45 -05:00
|
|
|
print_visibility(s, item.vis);
|
2013-03-19 20:24:01 -05:00
|
|
|
match item.node {
|
2013-05-11 23:25:31 -05:00
|
|
|
ast::view_item_extern_mod(id, ref mta, _) => {
|
2013-05-19 00:07:44 -05:00
|
|
|
head(s, "extern mod");
|
2013-01-30 19:20:02 -06:00
|
|
|
print_ident(s, id);
|
|
|
|
if !mta.is_empty() {
|
|
|
|
popen(s);
|
2013-05-11 23:25:31 -05:00
|
|
|
commasep(s, consistent, *mta, print_meta_item);
|
2013-01-30 19:20:02 -06:00
|
|
|
pclose(s);
|
|
|
|
}
|
2011-03-24 10:33:20 -05:00
|
|
|
}
|
2012-02-18 01:05:20 -06:00
|
|
|
|
2013-03-19 20:24:01 -05:00
|
|
|
ast::view_item_use(ref vps) => {
|
2013-05-19 00:07:44 -05:00
|
|
|
head(s, "use");
|
2013-03-19 20:24:01 -05:00
|
|
|
print_view_paths(s, *vps);
|
2013-01-30 19:20:02 -06:00
|
|
|
}
|
2011-03-04 00:22:43 -06:00
|
|
|
}
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, ";");
|
2011-06-01 17:29:38 -05:00
|
|
|
end(s); // end inner head-block
|
|
|
|
end(s); // end outer head-block
|
2011-03-04 00:22:43 -06:00
|
|
|
}
|
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn print_mutability(s: @ps, mutbl: ast::mutability) {
|
2012-08-06 14:34:08 -05:00
|
|
|
match mutbl {
|
2013-05-19 00:07:44 -05:00
|
|
|
ast::m_mutbl => word_nbsp(s, "mut"),
|
|
|
|
ast::m_const => word_nbsp(s, "const"),
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::m_imm => {/* nothing */ }
|
2011-03-24 10:33:20 -05:00
|
|
|
}
|
2011-06-15 12:25:23 -05:00
|
|
|
}
|
|
|
|
|
2013-03-19 20:24:01 -05:00
|
|
|
pub fn print_mt(s: @ps, mt: &ast::mt) {
|
2012-02-15 13:25:39 -06:00
|
|
|
print_mutability(s, mt.mutbl);
|
2011-08-15 06:45:04 -05:00
|
|
|
print_type(s, mt.ty);
|
2011-03-04 00:22:43 -06:00
|
|
|
}
|
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn print_arg(s: @ps, input: ast::arg) {
|
2012-05-04 14:33:04 -05:00
|
|
|
ibox(s, indent_unit);
|
2013-01-23 01:33:31 -06:00
|
|
|
if input.is_mutbl {
|
2013-05-19 00:07:44 -05:00
|
|
|
word_space(s, "mut");
|
2013-01-23 01:33:31 -06:00
|
|
|
}
|
2012-08-06 14:34:08 -05:00
|
|
|
match input.ty.node {
|
2012-12-07 16:39:29 -06:00
|
|
|
ast::ty_infer => print_irrefutable_pat(s, input.pat),
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => {
|
2012-11-06 20:41:06 -06:00
|
|
|
match input.pat.node {
|
|
|
|
ast::pat_ident(_, path, _) if
|
|
|
|
path.idents.len() == 1 &&
|
|
|
|
path.idents[0] == parse::token::special_idents::invalid => {
|
|
|
|
// Do nothing.
|
|
|
|
}
|
|
|
|
_ => {
|
2012-12-07 16:39:29 -06:00
|
|
|
print_irrefutable_pat(s, input.pat);
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, ":");
|
2012-11-06 20:41:06 -06:00
|
|
|
space(s.s);
|
|
|
|
}
|
2012-05-04 14:33:04 -05:00
|
|
|
}
|
|
|
|
print_type(s, input.ty);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end(s);
|
|
|
|
}
|
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn print_ty_fn(s: @ps,
|
2013-03-13 21:25:28 -05:00
|
|
|
opt_abis: Option<AbiSet>,
|
2013-01-31 19:12:29 -06:00
|
|
|
opt_sigil: Option<ast::Sigil>,
|
2013-02-27 18:41:02 -06:00
|
|
|
opt_region: Option<@ast::Lifetime>,
|
2013-01-29 16:41:40 -06:00
|
|
|
purity: ast::purity,
|
|
|
|
onceness: ast::Onceness,
|
2013-03-27 11:55:18 -05:00
|
|
|
decl: &ast::fn_decl,
|
|
|
|
id: Option<ast::ident>,
|
2013-02-14 23:50:03 -06:00
|
|
|
generics: Option<&ast::Generics>,
|
2013-04-30 10:49:48 -05:00
|
|
|
opt_explicit_self: Option<ast::explicit_self_>) {
|
2011-06-01 17:29:38 -05:00
|
|
|
ibox(s, indent_unit);
|
2012-11-04 22:41:00 -06:00
|
|
|
|
|
|
|
// Duplicates the logic in `print_fn_header_info()`. This is because that
|
2013-01-31 19:12:29 -06:00
|
|
|
// function prints the sigil in the wrong place. That should be fixed.
|
2013-03-13 21:25:28 -05:00
|
|
|
print_extern_opt_abis(s, opt_abis);
|
2013-01-31 19:12:29 -06:00
|
|
|
print_opt_sigil(s, opt_sigil);
|
2013-02-27 18:41:02 -06:00
|
|
|
print_opt_lifetime(s, opt_region);
|
2012-11-04 22:41:00 -06:00
|
|
|
print_purity(s, purity);
|
|
|
|
print_onceness(s, onceness);
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "fn");
|
|
|
|
match id { Some(id) => { word(s.s, " "); print_ident(s, id); } _ => () }
|
2013-03-19 20:24:01 -05:00
|
|
|
match generics { Some(g) => print_generics(s, g), _ => () }
|
2011-06-02 19:36:28 -05:00
|
|
|
zerobreak(s.s);
|
2012-08-17 18:14:57 -05:00
|
|
|
|
2011-05-28 21:16:18 -05:00
|
|
|
popen(s);
|
2013-06-06 02:38:41 -05:00
|
|
|
// It is unfortunate to duplicate the commasep logic, but we want the
|
2013-01-31 19:12:29 -06:00
|
|
|
// self type and the args all in the same box.
|
2012-08-17 18:14:57 -05:00
|
|
|
box(s, 0u, inconsistent);
|
|
|
|
let mut first = true;
|
2013-06-10 16:50:12 -05:00
|
|
|
for opt_explicit_self.iter().advance |explicit_self| {
|
2013-04-30 10:49:48 -05:00
|
|
|
first = !print_explicit_self(s, *explicit_self);
|
2012-08-17 18:14:57 -05:00
|
|
|
}
|
|
|
|
for decl.inputs.each |arg| {
|
2013-05-19 00:07:44 -05:00
|
|
|
if first { first = false; } else { word_space(s, ","); }
|
2012-09-19 18:55:01 -05:00
|
|
|
print_arg(s, *arg);
|
2012-08-17 18:14:57 -05:00
|
|
|
}
|
|
|
|
end(s);
|
2011-03-24 10:33:20 -05:00
|
|
|
pclose(s);
|
2012-08-17 18:14:57 -05:00
|
|
|
|
2011-12-23 06:32:17 -06:00
|
|
|
maybe_print_comment(s, decl.output.span.lo);
|
2012-09-07 20:53:14 -05:00
|
|
|
|
|
|
|
match decl.output.node {
|
|
|
|
ast::ty_nil => {}
|
|
|
|
_ => {
|
|
|
|
space_if_not_bol(s);
|
|
|
|
ibox(s, indent_unit);
|
2013-05-19 00:07:44 -05:00
|
|
|
word_space(s, "->");
|
|
|
|
if decl.cf == ast::noreturn { word_nbsp(s, "!"); }
|
2012-09-07 20:53:14 -05:00
|
|
|
else { print_type(s, decl.output); }
|
|
|
|
end(s);
|
|
|
|
}
|
2011-03-24 10:33:20 -05:00
|
|
|
}
|
2012-09-07 20:53:14 -05:00
|
|
|
|
2011-06-01 17:29:38 -05:00
|
|
|
end(s);
|
2011-03-24 10:33:20 -05:00
|
|
|
}
|
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn maybe_print_trailing_comment(s: @ps, span: codemap::span,
|
2013-01-29 16:41:40 -06:00
|
|
|
next_pos: Option<BytePos>) {
|
2013-04-12 00:10:31 -05:00
|
|
|
let cm;
|
2012-08-20 14:23:37 -05:00
|
|
|
match s.cm { Some(ccm) => cm = ccm, _ => return }
|
2012-08-06 14:34:08 -05:00
|
|
|
match next_comment(s) {
|
2012-12-04 12:50:00 -06:00
|
|
|
Some(ref cmnt) => {
|
|
|
|
if (*cmnt).style != comments::trailing { return; }
|
2012-11-12 20:24:56 -06:00
|
|
|
let span_line = cm.lookup_char_pos(span.hi);
|
2012-12-04 12:50:00 -06:00
|
|
|
let comment_line = cm.lookup_char_pos((*cmnt).pos);
|
|
|
|
let mut next = (*cmnt).pos + BytePos(1u);
|
2012-08-20 14:23:37 -05:00
|
|
|
match next_pos { None => (), Some(p) => next = p }
|
2012-12-04 12:50:00 -06:00
|
|
|
if span.hi < (*cmnt).pos && (*cmnt).pos < next &&
|
2011-07-27 07:19:39 -05:00
|
|
|
span_line.line == comment_line.line {
|
2013-05-11 23:25:31 -05:00
|
|
|
print_comment(s, cmnt);
|
2013-02-04 16:02:01 -06:00
|
|
|
s.cur_cmnt_and_lit.cur_cmnt += 1u;
|
2011-03-24 10:33:20 -05:00
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => ()
|
2011-03-24 10:33:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn print_remaining_comments(s: @ps) {
|
2011-08-03 19:52:25 -05:00
|
|
|
// If there aren't any remaining comments, then we need to manually
|
|
|
|
// make sure there is a line break at the end.
|
2012-09-21 21:37:57 -05:00
|
|
|
if next_comment(s).is_none() { hardbreak(s.s); }
|
2012-03-10 22:34:17 -06:00
|
|
|
loop {
|
2012-08-06 14:34:08 -05:00
|
|
|
match next_comment(s) {
|
2013-02-04 16:02:01 -06:00
|
|
|
Some(ref cmnt) => {
|
2013-05-11 23:25:31 -05:00
|
|
|
print_comment(s, cmnt);
|
2013-02-04 16:02:01 -06:00
|
|
|
s.cur_cmnt_and_lit.cur_cmnt += 1u;
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => break
|
2011-03-24 10:33:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-17 11:15:08 -05:00
|
|
|
pub fn print_literal(s: @ps, lit: @ast::lit) {
|
2011-07-05 04:48:19 -05:00
|
|
|
maybe_print_comment(s, lit.span.lo);
|
2012-08-06 14:34:08 -05:00
|
|
|
match next_lit(s, lit.span.lo) {
|
2012-12-04 12:50:00 -06:00
|
|
|
Some(ref ltrl) => {
|
|
|
|
word(s.s, (*ltrl).lit);
|
2012-08-01 19:30:05 -05:00
|
|
|
return;
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => ()
|
2011-07-05 04:48:19 -05:00
|
|
|
}
|
2012-08-06 14:34:08 -05:00
|
|
|
match lit.node {
|
2013-06-12 12:02:55 -05:00
|
|
|
ast::lit_str(st) => print_string(s, st),
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::lit_int(ch, ast::ty_char) => {
|
2013-05-23 11:09:11 -05:00
|
|
|
word(s.s, ~"'" + char::escape_default(ch as char) + "'");
|
2011-12-07 14:06:12 -06:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::lit_int(i, t) => {
|
2012-02-03 19:39:39 -06:00
|
|
|
if i < 0_i64 {
|
|
|
|
word(s.s,
|
2013-01-24 14:47:57 -06:00
|
|
|
~"-" + u64::to_str_radix(-i as u64, 10u)
|
2012-02-03 19:39:39 -06:00
|
|
|
+ ast_util::int_ty_to_str(t));
|
|
|
|
} else {
|
|
|
|
word(s.s,
|
2013-01-24 14:47:57 -06:00
|
|
|
u64::to_str_radix(i as u64, 10u)
|
2012-02-03 19:39:39 -06:00
|
|
|
+ ast_util::int_ty_to_str(t));
|
|
|
|
}
|
2011-12-07 14:06:12 -06:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::lit_uint(u, t) => {
|
2012-02-03 19:39:39 -06:00
|
|
|
word(s.s,
|
2013-01-24 14:47:57 -06:00
|
|
|
u64::to_str_radix(u, 10u)
|
2012-02-03 19:39:39 -06:00
|
|
|
+ ast_util::uint_ty_to_str(t));
|
2011-12-07 14:06:12 -06:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::lit_int_unsuffixed(i) => {
|
2012-06-11 18:31:03 -05:00
|
|
|
if i < 0_i64 {
|
2013-01-24 14:47:57 -06:00
|
|
|
word(s.s, ~"-" + u64::to_str_radix(-i as u64, 10u));
|
2012-06-11 18:31:03 -05:00
|
|
|
} else {
|
2013-01-24 14:47:57 -06:00
|
|
|
word(s.s, u64::to_str_radix(i as u64, 10u));
|
2012-06-11 18:31:03 -05:00
|
|
|
}
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::lit_float(f, t) => {
|
2013-06-12 12:02:55 -05:00
|
|
|
word(s.s, f.to_owned() + ast_util::float_ty_to_str(t));
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2013-06-12 12:02:55 -05:00
|
|
|
ast::lit_float_unsuffixed(f) => word(s.s, f),
|
2013-05-19 00:07:44 -05:00
|
|
|
ast::lit_nil => word(s.s, "()"),
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::lit_bool(val) => {
|
2013-05-19 00:07:44 -05:00
|
|
|
if val { word(s.s, "true"); } else { word(s.s, "false"); }
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2011-07-05 04:48:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-29 16:41:40 -06:00
|
|
|
pub fn lit_to_str(l: @ast::lit) -> ~str {
|
2012-07-18 18:18:02 -05:00
|
|
|
return to_str(l, print_literal, parse::token::mk_fake_ident_interner());
|
|
|
|
}
|
2011-07-05 04:48:19 -05:00
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn next_lit(s: @ps, pos: BytePos) -> Option<comments::lit> {
|
2012-08-06 14:34:08 -05:00
|
|
|
match s.literals {
|
2012-12-04 12:50:00 -06:00
|
|
|
Some(ref lits) => {
|
2013-06-08 20:38:47 -05:00
|
|
|
while s.cur_cmnt_and_lit.cur_lit < lits.len() {
|
2013-02-26 09:43:53 -06:00
|
|
|
let ltrl = /*bad*/ copy (*lits)[s.cur_cmnt_and_lit.cur_lit];
|
2012-08-20 14:23:37 -05:00
|
|
|
if ltrl.pos > pos { return None; }
|
2013-02-04 16:02:01 -06:00
|
|
|
s.cur_cmnt_and_lit.cur_lit += 1u;
|
2012-08-20 14:23:37 -05:00
|
|
|
if ltrl.pos == pos { return Some(ltrl); }
|
2012-01-16 03:50:34 -06:00
|
|
|
}
|
2012-08-20 14:23:37 -05:00
|
|
|
return None;
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-08-20 14:23:37 -05:00
|
|
|
_ => return None
|
2011-07-05 04:48:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn maybe_print_comment(s: @ps, pos: BytePos) {
|
2012-03-10 22:34:17 -06:00
|
|
|
loop {
|
2012-08-06 14:34:08 -05:00
|
|
|
match next_comment(s) {
|
2012-12-04 12:50:00 -06:00
|
|
|
Some(ref cmnt) => {
|
|
|
|
if (*cmnt).pos < pos {
|
2013-05-11 23:25:31 -05:00
|
|
|
print_comment(s, cmnt);
|
2013-02-04 16:02:01 -06:00
|
|
|
s.cur_cmnt_and_lit.cur_cmnt += 1u;
|
2011-07-27 07:19:39 -05:00
|
|
|
} else { break; }
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => break
|
2011-07-05 04:48:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-11 23:25:31 -05:00
|
|
|
pub fn print_comment(s: @ps, cmnt: &comments::cmnt) {
|
2012-08-06 14:34:08 -05:00
|
|
|
match cmnt.style {
|
2012-08-03 21:59:04 -05:00
|
|
|
comments::mixed => {
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(cmnt.lines.len(), 1u);
|
2011-07-27 07:19:39 -05:00
|
|
|
zerobreak(s.s);
|
2011-08-27 03:16:40 -05:00
|
|
|
word(s.s, cmnt.lines[0]);
|
2011-07-27 07:19:39 -05:00
|
|
|
zerobreak(s.s);
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
comments::isolated => {
|
2011-07-27 07:19:39 -05:00
|
|
|
pprust::hardbreak_if_not_bol(s);
|
2012-06-30 18:19:07 -05:00
|
|
|
for cmnt.lines.each |line| {
|
2011-08-18 21:19:38 -05:00
|
|
|
// Don't print empty lines because they will end up as trailing
|
|
|
|
// whitespace
|
2013-01-24 21:19:44 -06:00
|
|
|
if !line.is_empty() { word(s.s, *line); }
|
2011-08-18 21:19:38 -05:00
|
|
|
hardbreak(s.s);
|
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
comments::trailing => {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, " ");
|
2013-05-14 04:52:12 -05:00
|
|
|
if cmnt.lines.len() == 1u {
|
2011-08-27 03:16:40 -05:00
|
|
|
word(s.s, cmnt.lines[0]);
|
2011-07-05 04:48:19 -05:00
|
|
|
hardbreak(s.s);
|
2011-07-27 07:19:39 -05:00
|
|
|
} else {
|
|
|
|
ibox(s, 0u);
|
2012-06-30 18:19:07 -05:00
|
|
|
for cmnt.lines.each |line| {
|
2013-01-24 21:19:44 -06:00
|
|
|
if !line.is_empty() { word(s.s, *line); }
|
2011-08-18 21:19:38 -05:00
|
|
|
hardbreak(s.s);
|
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
end(s);
|
2011-07-05 04:48:19 -05:00
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
comments::blank_line => {
|
2011-07-27 07:19:39 -05:00
|
|
|
// We need to do at least one, possibly two hardbreaks.
|
2011-08-19 17:16:48 -05:00
|
|
|
let is_semi =
|
2012-08-06 14:34:08 -05:00
|
|
|
match s.s.last_token() {
|
2013-06-12 12:02:55 -05:00
|
|
|
pp::STRING(s, _) => ";" == s,
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => false
|
2011-08-19 17:16:48 -05:00
|
|
|
};
|
2011-09-16 09:57:54 -05:00
|
|
|
if is_semi || is_begin(s) || is_end(s) { hardbreak(s.s); }
|
2011-07-27 07:19:39 -05:00
|
|
|
hardbreak(s.s);
|
|
|
|
}
|
2011-07-05 04:48:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-27 09:01:45 -05:00
|
|
|
pub fn print_string(s: @ps, st: &str) {
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "\"");
|
2013-06-11 07:13:23 -05:00
|
|
|
word(s.s, st.escape_default());
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "\"");
|
2011-07-05 04:48:19 -05:00
|
|
|
}
|
|
|
|
|
2013-04-17 11:15:08 -05:00
|
|
|
pub fn to_str<T: Copy>(t: T, f: @fn(@ps, T), intr: @ident_interner) -> ~str {
|
2012-09-14 11:40:28 -05:00
|
|
|
do io::with_str_writer |wr| {
|
|
|
|
let s = rust_printer(wr, intr);
|
2013-06-15 19:26:59 -05:00
|
|
|
f(s, copy t);
|
2012-09-14 11:40:28 -05:00
|
|
|
eof(s.s);
|
|
|
|
}
|
2011-07-05 04:48:19 -05:00
|
|
|
}
|
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn next_comment(s: @ps) -> Option<comments::cmnt> {
|
2012-08-06 14:34:08 -05:00
|
|
|
match s.comments {
|
2012-12-04 12:50:00 -06:00
|
|
|
Some(ref cmnts) => {
|
2013-06-08 20:38:47 -05:00
|
|
|
if s.cur_cmnt_and_lit.cur_cmnt < cmnts.len() {
|
2013-02-26 09:43:53 -06:00
|
|
|
return Some(copy cmnts[s.cur_cmnt_and_lit.cur_cmnt]);
|
2012-08-20 14:23:37 -05:00
|
|
|
} else { return None::<comments::cmnt>; }
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-08-20 14:23:37 -05:00
|
|
|
_ => return None::<comments::cmnt>
|
2011-07-05 04:48:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-13 21:25:28 -05:00
|
|
|
pub fn print_opt_purity(s: @ps, opt_purity: Option<ast::purity>) {
|
|
|
|
match opt_purity {
|
|
|
|
Some(ast::impure_fn) => { }
|
|
|
|
Some(purity) => {
|
|
|
|
word_nbsp(s, purity_to_str(purity));
|
|
|
|
}
|
|
|
|
None => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn print_extern_opt_abis(s: @ps, opt_abis: Option<AbiSet>) {
|
|
|
|
match opt_abis {
|
|
|
|
Some(abis) => {
|
2013-05-19 00:07:44 -05:00
|
|
|
word_nbsp(s, "extern");
|
2013-03-13 21:25:28 -05:00
|
|
|
word_nbsp(s, abis.to_str());
|
|
|
|
}
|
2013-01-31 19:12:29 -06:00
|
|
|
None => {}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn print_opt_sigil(s: @ps, opt_sigil: Option<ast::Sigil>) {
|
2013-01-31 19:12:29 -06:00
|
|
|
match opt_sigil {
|
2013-05-19 00:07:44 -05:00
|
|
|
Some(ast::BorrowedSigil) => { word(s.s, "&"); }
|
|
|
|
Some(ast::OwnedSigil) => { word(s.s, "~"); }
|
|
|
|
Some(ast::ManagedSigil) => { word(s.s, "@"); }
|
2012-11-04 22:41:00 -06:00
|
|
|
None => {}
|
|
|
|
};
|
|
|
|
}
|
2012-11-02 15:33:51 -05:00
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn print_fn_header_info(s: @ps,
|
2013-04-30 10:49:48 -05:00
|
|
|
_opt_explicit_self: Option<ast::explicit_self_>,
|
2013-03-13 21:25:28 -05:00
|
|
|
opt_purity: Option<ast::purity>,
|
|
|
|
abis: AbiSet,
|
2013-01-29 16:41:40 -06:00
|
|
|
onceness: ast::Onceness,
|
2013-01-31 19:12:29 -06:00
|
|
|
opt_sigil: Option<ast::Sigil>,
|
2013-01-29 16:41:40 -06:00
|
|
|
vis: ast::visibility) {
|
2013-05-21 12:48:56 -05:00
|
|
|
word(s.s, visibility_qualified(vis, ""));
|
2013-03-13 21:25:28 -05:00
|
|
|
|
|
|
|
if abis != AbiSet::Rust() {
|
2013-05-19 00:07:44 -05:00
|
|
|
word_nbsp(s, "extern");
|
2013-03-13 21:25:28 -05:00
|
|
|
word_nbsp(s, abis.to_str());
|
|
|
|
|
|
|
|
if opt_purity != Some(ast::extern_fn) {
|
|
|
|
print_opt_purity(s, opt_purity);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
print_opt_purity(s, opt_purity);
|
|
|
|
}
|
|
|
|
|
2012-11-04 22:41:00 -06:00
|
|
|
print_onceness(s, onceness);
|
2013-05-19 00:07:44 -05:00
|
|
|
word(s.s, "fn");
|
2013-01-31 19:12:29 -06:00
|
|
|
print_opt_sigil(s, opt_sigil);
|
2012-08-02 18:01:38 -05:00
|
|
|
}
|
|
|
|
|
2013-01-31 19:12:29 -06:00
|
|
|
pub fn opt_sigil_to_str(opt_p: Option<ast::Sigil>) -> ~str {
|
2012-08-06 14:34:08 -05:00
|
|
|
match opt_p {
|
2012-08-20 14:23:37 -05:00
|
|
|
None => ~"fn",
|
2013-01-31 19:12:29 -06:00
|
|
|
Some(p) => fmt!("fn%s", p.to_str())
|
2012-01-11 14:52:25 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-22 13:09:13 -05:00
|
|
|
pub fn purity_to_str(p: ast::purity) -> ~str {
|
2012-08-06 14:34:08 -05:00
|
|
|
match p {
|
2012-08-02 17:42:56 -05:00
|
|
|
ast::impure_fn => ~"impure",
|
|
|
|
ast::unsafe_fn => ~"unsafe",
|
|
|
|
ast::pure_fn => ~"pure",
|
|
|
|
ast::extern_fn => ~"extern"
|
2012-05-25 01:44:58 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-22 13:09:13 -05:00
|
|
|
pub fn onceness_to_str(o: ast::Onceness) -> ~str {
|
2012-11-02 15:33:51 -05:00
|
|
|
match o {
|
|
|
|
ast::Once => ~"once",
|
|
|
|
ast::Many => ~"many"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn print_purity(s: @ps, p: ast::purity) {
|
2012-08-06 14:34:08 -05:00
|
|
|
match p {
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::impure_fn => (),
|
|
|
|
_ => word_nbsp(s, purity_to_str(p))
|
2012-05-25 01:44:58 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn print_onceness(s: @ps, o: ast::Onceness) {
|
2012-11-04 22:41:00 -06:00
|
|
|
match o {
|
2013-05-19 00:07:44 -05:00
|
|
|
ast::Once => { word_nbsp(s, "once"); }
|
2012-11-04 22:41:00 -06:00
|
|
|
ast::Many => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-24 16:10:38 -06:00
|
|
|
#[cfg(test)]
|
2013-04-15 10:08:52 -05:00
|
|
|
mod test {
|
2013-02-25 13:11:21 -06:00
|
|
|
use super::*;
|
|
|
|
|
2013-01-24 16:10:38 -06:00
|
|
|
use ast;
|
|
|
|
use ast_util;
|
2013-02-25 13:11:21 -06:00
|
|
|
use codemap;
|
|
|
|
use core::cmp::Eq;
|
|
|
|
use core::option::None;
|
2013-06-04 14:34:25 -05:00
|
|
|
use parse::token;
|
2013-01-24 16:10:38 -06:00
|
|
|
|
2013-02-20 19:07:17 -06:00
|
|
|
fn string_check<T:Eq> (given : &T, expected: &T) {
|
2013-01-24 16:10:38 -06:00
|
|
|
if !(given == expected) {
|
2013-05-09 06:52:07 -05:00
|
|
|
fail!("given %?, expected %?", given, expected);
|
2013-01-24 16:10:38 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_fun_to_str() {
|
2013-06-04 14:34:25 -05:00
|
|
|
let abba_ident = token::str_to_ident("abba");
|
2013-01-24 16:10:38 -06:00
|
|
|
|
2013-02-28 09:25:31 -06:00
|
|
|
let decl = ast::fn_decl {
|
2013-01-24 16:10:38 -06:00
|
|
|
inputs: ~[],
|
|
|
|
output: @ast::Ty {id: 0,
|
|
|
|
node: ast::ty_nil,
|
2013-01-30 11:56:33 -06:00
|
|
|
span: codemap::dummy_sp()},
|
2013-01-24 16:10:38 -06:00
|
|
|
cf: ast::return_val
|
|
|
|
};
|
2013-02-14 23:50:03 -06:00
|
|
|
let generics = ast_util::empty_generics();
|
2013-03-25 01:02:42 -05:00
|
|
|
assert_eq!(&fun_to_str(&decl, ast::impure_fn, abba_ident,
|
2013-06-04 14:34:25 -05:00
|
|
|
None, &generics, token::get_ident_interner()),
|
2013-03-25 01:02:42 -05:00
|
|
|
&~"fn abba()");
|
2013-01-24 16:10:38 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_variant_to_str() {
|
2013-06-04 14:34:25 -05:00
|
|
|
let ident = token::str_to_ident("principal_skinner");
|
2013-01-24 16:10:38 -06:00
|
|
|
|
2013-01-30 11:56:33 -06:00
|
|
|
let var = codemap::respan(codemap::dummy_sp(), ast::variant_ {
|
2013-01-24 16:10:38 -06:00
|
|
|
name: ident,
|
|
|
|
attrs: ~[],
|
|
|
|
// making this up as I go.... ?
|
|
|
|
kind: ast::tuple_variant_kind(~[]),
|
|
|
|
id: 0,
|
|
|
|
disr_expr: None,
|
|
|
|
vis: ast::public,
|
|
|
|
});
|
|
|
|
|
2013-06-04 14:34:25 -05:00
|
|
|
let varstr = variant_to_str(&var,token::get_ident_interner());
|
2013-03-13 17:30:37 -05:00
|
|
|
assert_eq!(&varstr,&~"pub principal_skinner");
|
2013-01-24 16:10:38 -06:00
|
|
|
}
|
|
|
|
}
|