Generalized the pretty-print entry points to support -o <file>
.
This commit is contained in:
parent
a70f8d9cf3
commit
da25539c1a
@ -664,7 +664,8 @@ impl pprust::PpAnn for TypedAnnotation {
|
||||
pub fn pretty_print_input(sess: Session,
|
||||
cfg: ast::CrateConfig,
|
||||
input: &Input,
|
||||
ppm: PpMode) {
|
||||
ppm: PpMode,
|
||||
ofile: Option<Path>) {
|
||||
let krate = phase_1_parse_input(&sess, cfg, input);
|
||||
let id = link::find_crate_id(krate.attrs.as_slice(), input.filestem());
|
||||
|
||||
@ -682,6 +683,17 @@ pub fn pretty_print_input(sess: Session,
|
||||
let src = Vec::from_slice(sess.codemap().get_filemap(src_name).src.as_bytes());
|
||||
let mut rdr = MemReader::new(src);
|
||||
|
||||
let out = match ofile {
|
||||
None => ~io::stdout() as ~Writer,
|
||||
Some(p) => {
|
||||
let r = io::File::create(&p);
|
||||
match r {
|
||||
Ok(w) => ~w as ~Writer,
|
||||
Err(e) => fail!("print-print failed to open {} due to {}",
|
||||
p.display(), e),
|
||||
}
|
||||
}
|
||||
};
|
||||
match ppm {
|
||||
PpmIdentified | PpmExpandedIdentified => {
|
||||
pprust::print_crate(sess.codemap(),
|
||||
@ -689,7 +701,7 @@ pub fn pretty_print_input(sess: Session,
|
||||
&krate,
|
||||
src_name,
|
||||
&mut rdr,
|
||||
~io::stdout(),
|
||||
out,
|
||||
&IdentifiedAnnotation,
|
||||
is_expanded)
|
||||
}
|
||||
@ -704,7 +716,7 @@ pub fn pretty_print_input(sess: Session,
|
||||
&krate,
|
||||
src_name,
|
||||
&mut rdr,
|
||||
~io::stdout(),
|
||||
out,
|
||||
&annotation,
|
||||
is_expanded)
|
||||
}
|
||||
@ -714,7 +726,7 @@ pub fn pretty_print_input(sess: Session,
|
||||
&krate,
|
||||
src_name,
|
||||
&mut rdr,
|
||||
~io::stdout(),
|
||||
out,
|
||||
&pprust::NoAnn,
|
||||
is_expanded)
|
||||
}
|
||||
|
@ -293,7 +293,7 @@ pub fn run_compiler(args: &[~str]) {
|
||||
});
|
||||
match pretty {
|
||||
Some::<d::PpMode>(ppm) => {
|
||||
d::pretty_print_input(sess, cfg, &input, ppm);
|
||||
d::pretty_print_input(sess, cfg, &input, ppm, ofile);
|
||||
return;
|
||||
}
|
||||
None::<d::PpMode> => {/* continue */ }
|
||||
|
5
src/test/run-make/pretty-print-to-file/Makefile
Normal file
5
src/test/run-make/pretty-print-to-file/Makefile
Normal file
@ -0,0 +1,5 @@
|
||||
-include ../tools.mk
|
||||
|
||||
all:
|
||||
$(RUSTC) -o $(TMPDIR)/input.out --pretty=normal input.rs
|
||||
diff -u $(TMPDIR)/input.out input.pp
|
13
src/test/run-make/pretty-print-to-file/input.pp
Normal file
13
src/test/run-make/pretty-print-to-file/input.pp
Normal file
@ -0,0 +1,13 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
|
||||
#[crate_type = "lib"]
|
||||
pub fn foo() -> i32 { 45 }
|
15
src/test/run-make/pretty-print-to-file/input.rs
Normal file
15
src/test/run-make/pretty-print-to-file/input.rs
Normal file
@ -0,0 +1,15 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
#[crate_type="lib"]
|
||||
|
||||
pub fn
|
||||
foo() -> i32
|
||||
{ 45 }
|
Loading…
x
Reference in New Issue
Block a user