Skip to content

Commit bf2f84b

Browse files
committed
Add an unstable --xpretty _ option to rustc. Moved flowgraph
and `everybody_loops` options to `--xpretty`.
1 parent 41def27 commit bf2f84b

File tree

3 files changed

+43
-18
lines changed

3 files changed

+43
-18
lines changed

src/librustc/session/config.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -811,10 +811,15 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
811811
"Pretty-print the input instead of compiling;
812812
valid types are: `normal` (un-annotated source),
813813
`expanded` (crates expanded),
814-
`typed` (crates expanded, with type annotations),
815-
`expanded,identified` (fully parenthesized, AST nodes with IDs), or
816-
`flowgraph=<nodeid>` (graphviz formatted flowgraph for node)",
814+
`typed` (crates expanded, with type annotations), or
815+
`expanded,identified` (fully parenthesized, AST nodes with IDs).",
817816
"TYPE"),
817+
opt::flagopt_u("", "xpretty",
818+
"Pretty-print the input instead of compiling, unstable variants;
819+
valid types are any of the types for `--pretty`, as well as:
820+
`flowgraph=<nodeid>` (graphviz formatted flowgraph for node), or
821+
`everybody_loops` (all function bodies replaced with `loop {}`).",
822+
"TYPE"),
818823
opt::flagopt("", "dep-info",
819824
"Output dependency info to <filename> after compiling, \
820825
in a format suitable for use by Makefiles", "FILENAME"),

src/librustc_driver/lib.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,19 @@ fn run_compiler(args: &[String]) {
138138
}
139139

140140
let pretty = matches.opt_default("pretty", "normal").map(|a| {
141-
pretty::parse_pretty(&sess, a.as_slice())
141+
// stable pretty-print variants only
142+
pretty::parse_pretty(&sess, a.as_slice(), false)
142143
});
144+
let pretty = if pretty.is_none() &&
145+
sess.debugging_opt(config::UNSTABLE_OPTIONS) {
146+
matches.opt_str("xpretty").map(|a| {
147+
// extended with unstable pretty-print variants
148+
pretty::parse_pretty(&sess, a.as_slice(), true)
149+
})
150+
} else {
151+
pretty
152+
};
153+
143154
match pretty.into_iter().next() {
144155
Some((ppm, opt_uii)) => {
145156
pretty::pretty_print_input(sess, cfg, &input, ppm, opt_uii, ofile);

src/librustc_driver/pretty.rs

+23-14
Original file line numberDiff line numberDiff line change
@@ -59,24 +59,33 @@ pub enum PpMode {
5959
PpmFlowGraph,
6060
}
6161

62-
pub fn parse_pretty(sess: &Session, name: &str) -> (PpMode, Option<UserIdentifiedItem>) {
62+
pub fn parse_pretty(sess: &Session,
63+
name: &str,
64+
extended: bool) -> (PpMode, Option<UserIdentifiedItem>) {
6365
let mut split = name.splitn(1, '=');
6466
let first = split.next().unwrap();
6567
let opt_second = split.next();
66-
let first = match first {
67-
"normal" => PpmSource(PpmNormal),
68-
"everybody_loops" => PpmSource(PpmEveryBodyLoops),
69-
"expanded" => PpmSource(PpmExpanded),
70-
"typed" => PpmSource(PpmTyped),
71-
"expanded,identified" => PpmSource(PpmExpandedIdentified),
72-
"expanded,hygiene" => PpmSource(PpmExpandedHygiene),
73-
"identified" => PpmSource(PpmIdentified),
74-
"flowgraph" => PpmFlowGraph,
68+
let first = match (first, extended) {
69+
("normal", _) => PpmSource(PpmNormal),
70+
("everybody_loops", true) => PpmSource(PpmEveryBodyLoops),
71+
("expanded", _) => PpmSource(PpmExpanded),
72+
("typed", _) => PpmSource(PpmTyped),
73+
("expanded,identified", _) => PpmSource(PpmExpandedIdentified),
74+
("expanded,hygiene", _) => PpmSource(PpmExpandedHygiene),
75+
("identified", _) => PpmSource(PpmIdentified),
76+
("flowgraph", true) => PpmFlowGraph,
7577
_ => {
76-
sess.fatal(format!(
77-
"argument to `pretty` must be one of `normal`, \
78-
`expanded`, `flowgraph=<nodeid>`, `typed`, `identified`, \
79-
or `expanded,identified`; got {}", name).as_slice());
78+
if extended {
79+
sess.fatal(format!(
80+
"argument to `xpretty` must be one of `normal`, \
81+
`expanded`, `flowgraph=<nodeid>`, `typed`, `identified`, \
82+
`expanded,identified`, or `everybody_loops`; got {}", name).as_slice());
83+
} else {
84+
sess.fatal(format!(
85+
"argument to `pretty` must be one of `normal`, \
86+
`expanded`, `typed`, `identified`, \
87+
or `expanded,identified`; got {}", name).as_slice());
88+
}
8089
}
8190
};
8291
let opt_second = opt_second.and_then::<UserIdentifiedItem, _>(from_str);

0 commit comments

Comments
 (0)