Add -Z unpretty
flags for the AST
This commit is contained in:
parent
939b14334d
commit
61114453ae
3 changed files with 46 additions and 22 deletions
|
@ -9,7 +9,7 @@ use rustc_hir_pretty as pprust_hir;
|
||||||
use rustc_middle::hir::map as hir_map;
|
use rustc_middle::hir::map as hir_map;
|
||||||
use rustc_middle::ty::{self, TyCtxt};
|
use rustc_middle::ty::{self, TyCtxt};
|
||||||
use rustc_mir::util::{write_mir_graphviz, write_mir_pretty};
|
use rustc_mir::util::{write_mir_graphviz, write_mir_pretty};
|
||||||
use rustc_session::config::{Input, PpHirMode, PpMode, PpSourceMode};
|
use rustc_session::config::{Input, PpAstTreeMode, PpHirMode, PpMode, PpSourceMode};
|
||||||
use rustc_session::Session;
|
use rustc_session::Session;
|
||||||
use rustc_span::symbol::Ident;
|
use rustc_span::symbol::Ident;
|
||||||
use rustc_span::FileName;
|
use rustc_span::FileName;
|
||||||
|
@ -391,24 +391,29 @@ pub fn print_after_parsing(
|
||||||
) {
|
) {
|
||||||
let (src, src_name) = get_source(input, sess);
|
let (src, src_name) = get_source(input, sess);
|
||||||
|
|
||||||
let out = if let Source(s) = ppm {
|
let out = match ppm {
|
||||||
// Silently ignores an identified node.
|
Source(s) => {
|
||||||
call_with_pp_support(&s, sess, None, move |annotation| {
|
// Silently ignores an identified node.
|
||||||
debug!("pretty printing source code {:?}", s);
|
call_with_pp_support(&s, sess, None, move |annotation| {
|
||||||
let sess = annotation.sess();
|
debug!("pretty printing source code {:?}", s);
|
||||||
let parse = &sess.parse_sess;
|
let sess = annotation.sess();
|
||||||
pprust::print_crate(
|
let parse = &sess.parse_sess;
|
||||||
sess.source_map(),
|
pprust::print_crate(
|
||||||
krate,
|
sess.source_map(),
|
||||||
src_name,
|
krate,
|
||||||
src,
|
src_name,
|
||||||
annotation.pp_ann(),
|
src,
|
||||||
false,
|
annotation.pp_ann(),
|
||||||
parse.edition,
|
false,
|
||||||
)
|
parse.edition,
|
||||||
})
|
)
|
||||||
} else {
|
})
|
||||||
unreachable!()
|
}
|
||||||
|
AstTree(PpAstTreeMode::Normal) => {
|
||||||
|
debug!("pretty printing AST tree");
|
||||||
|
format!("{:#?}", krate)
|
||||||
|
}
|
||||||
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
write_or_print(&out, ofile);
|
write_or_print(&out, ofile);
|
||||||
|
@ -447,6 +452,11 @@ pub fn print_after_hir_lowering<'tcx>(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AstTree(PpAstTreeMode::Expanded) => {
|
||||||
|
debug!("pretty-printing expanded AST");
|
||||||
|
format!("{:#?}", krate)
|
||||||
|
}
|
||||||
|
|
||||||
Hir(s) => call_with_pp_support_hir(&s, tcx, move |annotation, krate| {
|
Hir(s) => call_with_pp_support_hir(&s, tcx, move |annotation, krate| {
|
||||||
debug!("pretty printing HIR {:?}", s);
|
debug!("pretty printing HIR {:?}", s);
|
||||||
let sess = annotation.sess();
|
let sess = annotation.sess();
|
||||||
|
|
|
@ -2066,6 +2066,8 @@ fn parse_pretty(
|
||||||
("expanded", _) => Source(PpSourceMode::Expanded),
|
("expanded", _) => Source(PpSourceMode::Expanded),
|
||||||
("expanded,identified", _) => Source(PpSourceMode::ExpandedIdentified),
|
("expanded,identified", _) => Source(PpSourceMode::ExpandedIdentified),
|
||||||
("expanded,hygiene", _) => Source(PpSourceMode::ExpandedHygiene),
|
("expanded,hygiene", _) => Source(PpSourceMode::ExpandedHygiene),
|
||||||
|
("ast-tree", true) => AstTree(PpAstTreeMode::Normal),
|
||||||
|
("ast-tree,expanded", true) => AstTree(PpAstTreeMode::Expanded),
|
||||||
("hir", true) => Hir(PpHirMode::Normal),
|
("hir", true) => Hir(PpHirMode::Normal),
|
||||||
("hir,identified", true) => Hir(PpHirMode::Identified),
|
("hir,identified", true) => Hir(PpHirMode::Identified),
|
||||||
("hir,typed", true) => Hir(PpHirMode::Typed),
|
("hir,typed", true) => Hir(PpHirMode::Typed),
|
||||||
|
@ -2080,8 +2082,8 @@ fn parse_pretty(
|
||||||
"argument to `unpretty` must be one of `normal`, \
|
"argument to `unpretty` must be one of `normal`, \
|
||||||
`expanded`, `identified`, `expanded,identified`, \
|
`expanded`, `identified`, `expanded,identified`, \
|
||||||
`expanded,hygiene`, `everybody_loops`, \
|
`expanded,hygiene`, `everybody_loops`, \
|
||||||
`hir`, `hir,identified`, `hir,typed`, `hir-tree`, \
|
`ast-tree`, `ast-tree,expanded`, `hir`, `hir,identified`, \
|
||||||
`mir` or `mir-cfg`; got {}",
|
`hir,typed`, `hir-tree`, `mir` or `mir-cfg`; got {}",
|
||||||
name
|
name
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -2233,6 +2235,14 @@ pub enum PpSourceMode {
|
||||||
ExpandedHygiene,
|
ExpandedHygiene,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, PartialEq, Debug)]
|
||||||
|
pub enum PpAstTreeMode {
|
||||||
|
/// `-Zunpretty=ast`
|
||||||
|
Normal,
|
||||||
|
/// `-Zunpretty=ast,expanded`
|
||||||
|
Expanded,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, PartialEq, Debug)]
|
#[derive(Copy, Clone, PartialEq, Debug)]
|
||||||
pub enum PpHirMode {
|
pub enum PpHirMode {
|
||||||
/// `-Zunpretty=hir`
|
/// `-Zunpretty=hir`
|
||||||
|
@ -2248,6 +2258,7 @@ pub enum PpMode {
|
||||||
/// Options that print the source code, i.e.
|
/// Options that print the source code, i.e.
|
||||||
/// `--pretty` and `-Zunpretty=everybody_loops`
|
/// `--pretty` and `-Zunpretty=everybody_loops`
|
||||||
Source(PpSourceMode),
|
Source(PpSourceMode),
|
||||||
|
AstTree(PpAstTreeMode),
|
||||||
/// Options that print the HIR, i.e. `-Zunpretty=hir`
|
/// Options that print the HIR, i.e. `-Zunpretty=hir`
|
||||||
Hir(PpHirMode),
|
Hir(PpHirMode),
|
||||||
/// `-Zunpretty=hir-tree`
|
/// `-Zunpretty=hir-tree`
|
||||||
|
@ -2263,9 +2274,10 @@ impl PpMode {
|
||||||
use PpMode::*;
|
use PpMode::*;
|
||||||
use PpSourceMode::*;
|
use PpSourceMode::*;
|
||||||
match *self {
|
match *self {
|
||||||
Source(Normal | Identified) => false,
|
Source(Normal | Identified) | AstTree(PpAstTreeMode::Normal) => false,
|
||||||
|
|
||||||
Source(Expanded | EveryBodyLoops | ExpandedIdentified | ExpandedHygiene)
|
Source(Expanded | EveryBodyLoops | ExpandedIdentified | ExpandedHygiene)
|
||||||
|
| AstTree(PpAstTreeMode::Expanded)
|
||||||
| Hir(_)
|
| Hir(_)
|
||||||
| HirTree
|
| HirTree
|
||||||
| Mir
|
| Mir
|
||||||
|
|
|
@ -1158,6 +1158,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
|
||||||
`expanded`, `expanded,identified`,
|
`expanded`, `expanded,identified`,
|
||||||
`expanded,hygiene` (with internal representations),
|
`expanded,hygiene` (with internal representations),
|
||||||
`everybody_loops` (all function bodies replaced with `loop {}`),
|
`everybody_loops` (all function bodies replaced with `loop {}`),
|
||||||
|
`ast-tree` (raw AST before expansion),
|
||||||
|
`ast-tree,expanded` (raw AST after expansion),
|
||||||
`hir` (the HIR), `hir,identified`,
|
`hir` (the HIR), `hir,identified`,
|
||||||
`hir,typed` (HIR with types for each node),
|
`hir,typed` (HIR with types for each node),
|
||||||
`hir-tree` (dump the raw HIR),
|
`hir-tree` (dump the raw HIR),
|
||||||
|
|
Loading…
Add table
Reference in a new issue