From bf2f84bfe367d5a1f4b8f092fb22f535e6e95a40 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Wed, 17 Dec 2014 15:13:38 +0100 Subject: [PATCH] Add an unstable `--xpretty _` option to `rustc`. Moved `flowgraph` and `everybody_loops` options to `--xpretty`. --- src/librustc/session/config.rs | 11 +++++++--- src/librustc_driver/lib.rs | 13 +++++++++++- src/librustc_driver/pretty.rs | 37 +++++++++++++++++++++------------- 3 files changed, 43 insertions(+), 18 deletions(-) diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index fd38195275381..e3bd2648588d6 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -811,10 +811,15 @@ pub fn rustc_optgroups() -> Vec { "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=` (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=` (graphviz formatted flowgraph for node), or + `everybody_loops` (all function bodies replaced with `loop {}`).", + "TYPE"), opt::flagopt("", "dep-info", "Output dependency info to after compiling, \ in a format suitable for use by Makefiles", "FILENAME"), diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 7a0a8fd50d444..64f4d8bdc783f 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -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); diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index 266907e0bcdbe..3b6ad75243e22 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -59,24 +59,33 @@ pub enum PpMode { PpmFlowGraph, } -pub fn parse_pretty(sess: &Session, name: &str) -> (PpMode, Option) { +pub fn parse_pretty(sess: &Session, + name: &str, + extended: bool) -> (PpMode, Option) { 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=`, `typed`, `identified`, \ - or `expanded,identified`; got {}", name).as_slice()); + if extended { + sess.fatal(format!( + "argument to `xpretty` must be one of `normal`, \ + `expanded`, `flowgraph=`, `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::(from_str);