Skip to content

Commit

Permalink
Add an unstable --xpretty _ option to rustc. Moved flowgraph
Browse files Browse the repository at this point in the history
and `everybody_loops` options to `--xpretty`.
  • Loading branch information
pnkfelix committed Dec 22, 2014
1 parent 41def27 commit bf2f84b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 18 deletions.
11 changes: 8 additions & 3 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -811,10 +811,15 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
"Pretty-print the input instead of compiling;
valid types are: `normal` (un-annotated source),
`expanded` (crates expanded),
`typed` (crates expanded, with type annotations),
`expanded,identified` (fully parenthesized, AST nodes with IDs), or
`flowgraph=<nodeid>` (graphviz formatted flowgraph for node)",
`typed` (crates expanded, with type annotations), or
`expanded,identified` (fully parenthesized, AST nodes with IDs).",
"TYPE"),
opt::flagopt_u("", "xpretty",
"Pretty-print the input instead of compiling, unstable variants;
valid types are any of the types for `--pretty`, as well as:
`flowgraph=<nodeid>` (graphviz formatted flowgraph for node), or
`everybody_loops` (all function bodies replaced with `loop {}`).",
"TYPE"),
opt::flagopt("", "dep-info",
"Output dependency info to <filename> after compiling, \
in a format suitable for use by Makefiles", "FILENAME"),
Expand Down
13 changes: 12 additions & 1 deletion src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,19 @@ fn run_compiler(args: &[String]) {
}

let pretty = matches.opt_default("pretty", "normal").map(|a| {
pretty::parse_pretty(&sess, a.as_slice())
// stable pretty-print variants only
pretty::parse_pretty(&sess, a.as_slice(), false)
});
let pretty = if pretty.is_none() &&
sess.debugging_opt(config::UNSTABLE_OPTIONS) {
matches.opt_str("xpretty").map(|a| {
// extended with unstable pretty-print variants
pretty::parse_pretty(&sess, a.as_slice(), true)
})
} else {
pretty
};

match pretty.into_iter().next() {
Some((ppm, opt_uii)) => {
pretty::pretty_print_input(sess, cfg, &input, ppm, opt_uii, ofile);
Expand Down
37 changes: 23 additions & 14 deletions src/librustc_driver/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,33 @@ pub enum PpMode {
PpmFlowGraph,
}

pub fn parse_pretty(sess: &Session, name: &str) -> (PpMode, Option<UserIdentifiedItem>) {
pub fn parse_pretty(sess: &Session,
name: &str,
extended: bool) -> (PpMode, Option<UserIdentifiedItem>) {
let mut split = name.splitn(1, '=');
let first = split.next().unwrap();
let opt_second = split.next();
let first = match first {
"normal" => PpmSource(PpmNormal),
"everybody_loops" => PpmSource(PpmEveryBodyLoops),
"expanded" => PpmSource(PpmExpanded),
"typed" => PpmSource(PpmTyped),
"expanded,identified" => PpmSource(PpmExpandedIdentified),
"expanded,hygiene" => PpmSource(PpmExpandedHygiene),
"identified" => PpmSource(PpmIdentified),
"flowgraph" => PpmFlowGraph,
let first = match (first, extended) {
("normal", _) => PpmSource(PpmNormal),
("everybody_loops", true) => PpmSource(PpmEveryBodyLoops),
("expanded", _) => PpmSource(PpmExpanded),
("typed", _) => PpmSource(PpmTyped),
("expanded,identified", _) => PpmSource(PpmExpandedIdentified),
("expanded,hygiene", _) => PpmSource(PpmExpandedHygiene),
("identified", _) => PpmSource(PpmIdentified),
("flowgraph", true) => PpmFlowGraph,
_ => {
sess.fatal(format!(
"argument to `pretty` must be one of `normal`, \
`expanded`, `flowgraph=<nodeid>`, `typed`, `identified`, \
or `expanded,identified`; got {}", name).as_slice());
if extended {
sess.fatal(format!(
"argument to `xpretty` must be one of `normal`, \
`expanded`, `flowgraph=<nodeid>`, `typed`, `identified`, \
`expanded,identified`, or `everybody_loops`; got {}", name).as_slice());
} else {
sess.fatal(format!(
"argument to `pretty` must be one of `normal`, \
`expanded`, `typed`, `identified`, \
or `expanded,identified`; got {}", name).as_slice());
}
}
};
let opt_second = opt_second.and_then::<UserIdentifiedItem, _>(from_str);
Expand Down

1 comment on commit bf2f84b

@pnkfelix
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=alexcrichton

Please sign in to comment.