Feed the interner to the pretty-printer, in anticipation of pretty-printing token trees.

This commit is contained in:
Paul Stansifer 2012-07-27 14:21:15 -07:00
parent 4e9c475527
commit 19922fcd93
3 changed files with 33 additions and 19 deletions
src
fuzzer
libsyntax/print
rustc/driver

@ -263,6 +263,9 @@ fn check_variants_T<T: copy>(
let str3 =
@as_str(|a|pprust::print_crate(
codemap,
// Assuming we're not generating any token_trees
@syntax::util::interner::mk::<@~str>(
|x| str::hash(*x), |x,y| str::eq(*x,*y)),
diagnostic::mk_span_handler(handler, codemap),
crate2,
filename,
@ -420,13 +423,18 @@ fn parse_and_print(code: @~str) -> ~str {
let crate = parse::parse_crate_from_source_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(),
false) )
as_str(|a|
pprust::print_crate(
sess.cm,
// Assuming there are no token_trees
@syntax::util::interner::mk::<@~str>(
|x| str::hash(*x), |x,y| str::eq(*x,*y)),
sess.span_diagnostic,
crate,
filename,
rdr, a,
pprust::no_ann(),
false) )
})
}
@ -565,13 +573,17 @@ fn check_variants(files: ~[~str], cx: context) {
s, ~[], sess);
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(),
false) ))
as_str(|a| pprust::print_crate(
sess.cm,
// Assuming no token_trees
@syntax::util::interner::mk::<@~str>(
|x| str::hash(*x), |x,y| str::eq(*x,*y)),
sess.span_diagnostic,
crate,
file,
rdr, a,
pprust::no_ann(),
false) ))
});
check_variants_of_ast(*crate, sess.cm, file, cx);
}

@ -28,7 +28,7 @@ fn no_ann() -> pp_ann {
type ps =
@{s: pp::printer,
cm: option<codemap>,
//in: interner::interner<@~str>,
intr: @interner::interner<@~str>,
comments: option<~[comments::cmnt]>,
literals: option<~[comments::lit]>,
mut cur_cmnt: uint,
@ -49,7 +49,8 @@ fn end(s: ps) {
fn rust_printer(writer: io::writer) -> ps {
ret @{s: pp::mk_printer(writer, default_columns),
cm: none::<codemap>,
//in: interner::mk::<@~str>(|x| str::hash(*x), |x,y| str::eq(*x, *y)),
intr: @interner::mk::<@~str>(|x| str::hash(*x),
|x,y| str::eq(*x, *y)),
comments: none::<~[comments::cmnt]>,
literals: none::<~[comments::lit]>,
mut cur_cmnt: 0u,
@ -66,7 +67,7 @@ const default_columns: uint = 78u;
// Requires you to pass an input filename and reader so that
// it can scan the input text for comments and literals to
// copy forward.
fn print_crate(cm: codemap, //in: interner::interner<@~str>,
fn print_crate(cm: codemap, intr: @interner::interner<@~str>,
span_diagnostic: diagnostic::span_handler,
crate: @ast::crate, filename: ~str, in: io::reader,
out: io::writer, ann: pp_ann, is_expanded: bool) {
@ -75,7 +76,7 @@ fn print_crate(cm: codemap, //in: interner::interner<@~str>,
let s =
@{s: pp::mk_printer(out, default_columns),
cm: some(cm),
//in: in,
intr: intr,
comments: some(r.cmnts),
// If the code is post expansion, don't use the table of
// literals, since it doesn't correspond with the literals

@ -327,7 +327,8 @@ fn pretty_print_input(sess: session, cfg: ast::crate_cfg, input: input,
let is_expanded = upto != cu_parse;
let src = codemap::get_filemap(sess.codemap, source_name(input)).src;
do io::with_str_reader(*src) |rdr| {
pprust::print_crate(sess.codemap, sess.span_diagnostic, crate,
pprust::print_crate(sess.codemap, sess.parse_sess.interner,
sess.span_diagnostic, crate,
source_name(input),
rdr, io::stdout(), ann, is_expanded);
}