Skip to content

Commit f205a0a

Browse files
committed
Move AST printing to an --unpretty option
1 parent ef7ae6d commit f205a0a

File tree

2 files changed

+27
-24
lines changed

2 files changed

+27
-24
lines changed

src/librustc/session/config.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -1240,8 +1240,9 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
12401240
valid types are any of the types for `--pretty`, as well as:
12411241
`flowgraph=<nodeid>` (graphviz formatted flowgraph for node),
12421242
`everybody_loops` (all function bodies replaced with `loop {}`),
1243-
`hir` (the HIR), `hir,identified`, or
1244-
`hir,typed` (HIR with types for each node).",
1243+
`hir` (the HIR), `hir,identified`,
1244+
`hir,typed` (HIR with types for each node), or
1245+
`ast` (pretty-printed internal AST).",
12451246
"TYPE"),
12461247

12471248
// new options here should **not** use the `_ubnr` functions, all new
@@ -2408,10 +2409,6 @@ mod tests {
24082409
assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
24092410
opts.debugging_opts.print_llvm_passes = true;
24102411
assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2411-
opts.debugging_opts.ast = true;
2412-
assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2413-
opts.debugging_opts.ast_noexpand = true;
2414-
assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
24152412
opts.debugging_opts.ast_json = true;
24162413
assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
24172414
opts.debugging_opts.ast_json_noexpand = true;

src/librustc_driver/pretty.rs

+24-18
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ pub enum PpMode {
8181
PpmFlowGraph(PpFlowGraphMode),
8282
PpmMir,
8383
PpmMirCFG,
84+
PpmAST,
8485
}
8586

8687
impl PpMode {
@@ -90,6 +91,8 @@ impl PpMode {
9091
PpmSource(PpmEveryBodyLoops) |
9192
PpmSource(PpmIdentified) => opt_uii.is_some(),
9293

94+
PpmAST => false,
95+
9396
PpmSource(PpmExpanded) |
9497
PpmSource(PpmExpandedIdentified) |
9598
PpmSource(PpmExpandedHygiene) |
@@ -130,6 +133,7 @@ pub fn parse_pretty(sess: &Session,
130133
("mir-cfg", true) => PpmMirCFG,
131134
("flowgraph", true) => PpmFlowGraph(PpFlowGraphMode::Default),
132135
("flowgraph,unlabelled", true) => PpmFlowGraph(PpFlowGraphMode::UnlabelledEdges),
136+
("ast", true) => PpmAST,
133137
_ => {
134138
if extended {
135139
sess.fatal(&format!("argument to `unpretty` must be one of `normal`, \
@@ -831,24 +835,26 @@ pub fn print_after_parsing(sess: &Session,
831835
let mut rdr = &*src;
832836
let mut out = Vec::new();
833837

834-
if let PpmSource(s) = ppm {
835-
// Silently ignores an identified node.
836-
let out: &mut Write = &mut out;
837-
s.call_with_pp_support(sess, None, box out, |annotation, out| {
838-
debug!("pretty printing source code {:?}", s);
839-
let sess = annotation.sess();
840-
pprust::print_crate(sess.codemap(),
841-
&sess.parse_sess,
842-
krate,
843-
src_name.to_string(),
844-
&mut rdr,
845-
out,
846-
annotation.pp_ann(),
847-
false)
848-
})
849-
.unwrap()
850-
} else {
851-
unreachable!();
838+
match ppm {
839+
PpmSource(s) => {
840+
// Silently ignores an identified node.
841+
let out: &mut Write = &mut out;
842+
s.call_with_pp_support(sess, None, box out, |annotation, out| {
843+
debug!("pretty printing source code {:?}", s);
844+
let sess = annotation.sess();
845+
pprust::print_crate(sess.codemap(),
846+
&sess.parse_sess,
847+
krate,
848+
src_name.to_string(),
849+
&mut rdr,
850+
out,
851+
annotation.pp_ann(),
852+
false)
853+
})
854+
.unwrap()
855+
}
856+
PpmAST => write!(out, "{:#?}", krate).unwrap(),
857+
_ => unreachable!(),
852858
};
853859

854860
write_output(out, ofile);

0 commit comments

Comments
 (0)