1
Fork 0

Try to fix pretty-printer failure

I can't reproduce it on my side, unfortunately.
This commit is contained in:
Marijn Haverbeke 2012-01-17 17:12:58 +01:00
parent 08c16b17e9
commit 54d5a9846f

View file

@ -81,22 +81,21 @@ fn parse_input(sess: session, cfg: ast::crate_cfg, input: str) ->
if !input_is_stdin(input) { if !input_is_stdin(input) {
parser::parse_crate_from_file(input, cfg, sess.parse_sess) parser::parse_crate_from_file(input, cfg, sess.parse_sess)
} else { } else {
let srcbytes = get_input_stream(sess, input).read_whole_stream(); let src = get_input_str(sess, input);
let srcstring = str::unsafe_from_bytes(srcbytes); parser::parse_crate_from_source_str(input, src, cfg, sess.parse_sess)
parser::parse_crate_from_source_str(input, srcstring, cfg,
sess.parse_sess)
} }
} }
fn get_input_stream(sess: session, infile: str) -> io::reader { fn get_input_str(sess: session, infile: str) -> str {
if !input_is_stdin(infile) { let stream = if !input_is_stdin(infile) {
alt io::file_reader(infile) { alt io::file_reader(infile) {
result::ok(reader) { reader } result::ok(reader) { reader }
result::err(e) { result::err(e) {
sess.fatal(e) sess.fatal(e)
} }
} }
} else { io::stdin() } } else { io::stdin() };
str::unsafe_from_bytes(stream.read_whole_stream())
} }
fn time<T>(do_it: bool, what: str, thunk: fn@() -> T) -> T { fn time<T>(do_it: bool, what: str, thunk: fn@() -> T) -> T {
@ -285,7 +284,7 @@ fn pretty_print_input(sess: session, cfg: ast::crate_cfg, input: str,
_ { cu_parse } _ { cu_parse }
}; };
let {crate, tcx} = compile_upto(sess, cfg, input, upto, none); let {crate, tcx} = compile_upto(sess, cfg, input, upto, none);
let src = get_input_stream(sess, input); let src = get_input_str(sess, input);
let ann: pprust::pp_ann = pprust::no_ann(); let ann: pprust::pp_ann = pprust::no_ann();
alt ppm { alt ppm {
@ -299,7 +298,7 @@ fn pretty_print_input(sess: session, cfg: ast::crate_cfg, input: str,
ppm_expanded. | ppm_normal. {} ppm_expanded. | ppm_normal. {}
} }
pprust::print_crate(sess.codemap, sess.diagnostic, crate, input, pprust::print_crate(sess.codemap, sess.diagnostic, crate, input,
src, io::stdout(), ann); io::string_reader(src), io::stdout(), ann);
} }
fn get_os(triple: str) -> option<session::os> { fn get_os(triple: str) -> option<session::os> {