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());
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(),
&krate,
src_name,
&mut rdr,
- ~io::stdout(),
+ out,
&IdentifiedAnnotation,
is_expanded)
}
&krate,
src_name,
&mut rdr,
- ~io::stdout(),
+ out,
&annotation,
is_expanded)
}
&krate,
src_name,
&mut rdr,
- ~io::stdout(),
+ out,
&pprust::NoAnn,
is_expanded)
}
});
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 */ }
--- /dev/null
+-include ../tools.mk
+
+all:
+ $(RUSTC) -o $(TMPDIR)/input.out --pretty=normal input.rs
+ diff -u $(TMPDIR)/input.out input.pp
--- /dev/null
+// 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 }
--- /dev/null
+// 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 }