Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -Zast and -Zast-noexpand to pretty-print AST (without the JSON conversion) #38083

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1236,8 +1236,9 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
valid types are any of the types for `--pretty`, as well as:
`flowgraph=<nodeid>` (graphviz formatted flowgraph for node),
`everybody_loops` (all function bodies replaced with `loop {}`),
`hir` (the HIR), `hir,identified`, or
`hir,typed` (HIR with types for each node).",
`hir` (the HIR), `hir,identified`,
`hir,typed` (HIR with types for each node), or
`ast` (pretty-printed internal AST).",
"TYPE"),

// new options here should **not** use the `_ubnr` functions, all new
Expand Down
42 changes: 24 additions & 18 deletions src/librustc_driver/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ pub enum PpMode {
PpmFlowGraph(PpFlowGraphMode),
PpmMir,
PpmMirCFG,
PpmAST,
}

impl PpMode {
Expand All @@ -90,6 +91,8 @@ impl PpMode {
PpmSource(PpmEveryBodyLoops) |
PpmSource(PpmIdentified) => opt_uii.is_some(),

PpmAST => false,

PpmSource(PpmExpanded) |
PpmSource(PpmExpandedIdentified) |
PpmSource(PpmExpandedHygiene) |
Expand Down Expand Up @@ -130,6 +133,7 @@ pub fn parse_pretty(sess: &Session,
("mir-cfg", true) => PpmMirCFG,
("flowgraph", true) => PpmFlowGraph(PpFlowGraphMode::Default),
("flowgraph,unlabelled", true) => PpmFlowGraph(PpFlowGraphMode::UnlabelledEdges),
("ast", true) => PpmAST,
_ => {
if extended {
sess.fatal(&format!("argument to `unpretty` must be one of `normal`, \
Expand Down Expand Up @@ -831,24 +835,26 @@ pub fn print_after_parsing(sess: &Session,
let mut rdr = &*src;
let mut out = Vec::new();

if let PpmSource(s) = ppm {
// Silently ignores an identified node.
let out: &mut Write = &mut out;
s.call_with_pp_support(sess, None, box out, |annotation, out| {
debug!("pretty printing source code {:?}", s);
let sess = annotation.sess();
pprust::print_crate(sess.codemap(),
&sess.parse_sess,
krate,
src_name.to_string(),
&mut rdr,
out,
annotation.pp_ann(),
false)
})
.unwrap()
} else {
unreachable!();
match ppm {
PpmSource(s) => {
// Silently ignores an identified node.
let out: &mut Write = &mut out;
s.call_with_pp_support(sess, None, box out, |annotation, out| {
debug!("pretty printing source code {:?}", s);
let sess = annotation.sess();
pprust::print_crate(sess.codemap(),
&sess.parse_sess,
krate,
src_name.to_string(),
&mut rdr,
out,
annotation.pp_ann(),
false)
})
.unwrap()
}
PpmAST => write!(out, "{:#?}", krate).unwrap(),
_ => unreachable!(),
};

write_output(out, ofile);
Expand Down