Don't use literal info from the original source when pretty printing expanded ASTs.

This commit is contained in:
Michael Sullivan 2012-06-28 15:29:15 -07:00
parent 571d866c0d
commit d91e310982
3 changed files with 27 additions and 21 deletions

View File

@ -274,7 +274,8 @@ fn check_variants_T<T: copy>(
crate2,
filename,
io::str_reader(""), a,
pprust::no_ann())});
pprust::no_ann(),
false)});
alt cx.mode {
tm_converge {
check_roundtrip_convergence(str3, 1u);
@ -422,11 +423,12 @@ fn parse_and_print(code: @str) -> str {
filename, code, []/~, sess);
io::with_str_reader(*code) { |rdr|
as_str({|a|pprust::print_crate(sess.cm,
sess.span_diagnostic,
crate,
filename,
rdr, a,
pprust::no_ann())})
sess.span_diagnostic,
crate,
filename,
rdr, a,
pprust::no_ann(),
false)})
}
}
@ -566,11 +568,12 @@ fn check_variants(files: [str]/~, cx: context) {
io::with_str_reader(*s) { |rdr|
#error("%s",
as_str({|a|pprust::print_crate(sess.cm,
sess.span_diagnostic,
crate,
file,
rdr, a,
pprust::no_ann())}));
sess.span_diagnostic,
crate,
file,
rdr, a,
pprust::no_ann(),
false)}));
}
check_variants_of_ast(*crate, sess.cm, file, cx);
}

View File

@ -64,14 +64,17 @@ const default_columns: uint = 78u;
// copy forward.
fn print_crate(cm: codemap, span_diagnostic: diagnostic::span_handler,
crate: @ast::crate, filename: str, in: io::reader,
out: io::writer, ann: pp_ann) {
out: io::writer, ann: pp_ann, is_expanded: bool) {
let r = comments::gather_comments_and_literals(span_diagnostic,
filename, in);
let s =
@{s: pp::mk_printer(out, default_columns),
cm: some(cm),
comments: some(r.cmnts),
literals: some(r.lits),
// If the code is post expansion, don't use the table of
// literals, since it doesn't correspond with the literals
// in the AST anymore.
literals: if is_expanded { none } else { some(r.lits) },
mut cur_cmnt: 0u,
mut cur_lit: 0u,
boxes: dvec(),

View File

@ -310,22 +310,22 @@ fn pretty_print_input(sess: session, cfg: ast::crate_cfg, input: input,
};
let {crate, tcx} = compile_upto(sess, cfg, input, upto, none);
let mut ann: pprust::pp_ann = pprust::no_ann();
alt ppm {
let ann = alt ppm {
ppm_typed {
ann = {pre: ann_paren_for_expr,
post: {|a|ann_typed_post(option::get(tcx), a)}};
{pre: ann_paren_for_expr,
post: {|a|ann_typed_post(option::get(tcx), a)}}
}
ppm_identified | ppm_expanded_identified {
ann = {pre: ann_paren_for_expr, post: ann_identified_post};
{pre: ann_paren_for_expr, post: ann_identified_post}
}
ppm_expanded | ppm_normal {}
}
ppm_expanded | ppm_normal { pprust::no_ann() }
};
let is_expanded = upto != cu_parse;
let src = codemap::get_filemap(sess.codemap, source_name(input)).src;
io::with_str_reader(*src) { |rdr|
pprust::print_crate(sess.codemap, sess.span_diagnostic, crate,
source_name(input),
rdr, io::stdout(), ann);
rdr, io::stdout(), ann, is_expanded);
}
}