about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFelix S. Klock II <pnkfelix@pnkfx.org>2014-12-17 15:13:38 +0100
committerFelix S. Klock II <pnkfelix@pnkfx.org>2014-12-22 16:06:22 +0100
commitbf2f84bfe367d5a1f4b8f092fb22f535e6e95a40 (patch)
tree602c25ed20b220ad50b17a21fdf4df9541d5e245
parent41def27bda80eb5e1b3bfa75d34fd4f9e31e0988 (diff)
downloadrust-bf2f84bfe367d5a1f4b8f092fb22f535e6e95a40.tar.gz
rust-bf2f84bfe367d5a1f4b8f092fb22f535e6e95a40.zip
Add an unstable `--xpretty _` option to `rustc`. Moved `flowgraph`
and `everybody_loops` options to `--xpretty`.
-rw-r--r--src/librustc/session/config.rs11
-rw-r--r--src/librustc_driver/lib.rs13
-rw-r--r--src/librustc_driver/pretty.rs37
3 files changed, 43 insertions, 18 deletions
diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs
index fd381952753..e3bd2648588 100644
--- a/src/librustc/session/config.rs
+++ b/src/librustc/session/config.rs
@@ -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"),
diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs
index 7a0a8fd50d4..64f4d8bdc78 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 266907e0bcd..3b6ad75243e 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<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);