about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorSeo Sanghyeon <sanxiyn@gmail.com>2014-12-27 21:00:48 +0900
committerSeo Sanghyeon <sanxiyn@gmail.com>2014-12-27 21:00:48 +0900
commit98aeac2930dfd64ef1cb52c3a20e1f3609feee8e (patch)
tree934e07e7cd4da35c2b03a7750e1cdb6362e07469 /src
parentd4da75892219ee8fed5fc8801a37ffe82520083d (diff)
downloadrust-98aeac2930dfd64ef1cb52c3a20e1f3609feee8e.tar.gz
rust-98aeac2930dfd64ef1cb52c3a20e1f3609feee8e.zip
Extend span debugger
Diffstat (limited to 'src')
-rw-r--r--src/librustc_driver/driver.rs4
-rw-r--r--src/libsyntax/show_span.rs52
2 files changed, 51 insertions, 5 deletions
diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs
index 69e439c1bbe..5e563ae9d6d 100644
--- a/src/librustc_driver/driver.rs
+++ b/src/librustc_driver/driver.rs
@@ -138,8 +138,8 @@ pub fn phase_1_parse_input(sess: &Session, cfg: ast::CrateConfig, input: &Input)
         krate.encode(&mut json).unwrap();
     }
 
-    if sess.opts.show_span.is_some() {
-        syntax::show_span::run(sess.diagnostic(), &krate);
+    if let Some(ref s) = sess.opts.show_span {
+        syntax::show_span::run(sess.diagnostic(), s.as_slice(), &krate);
     }
 
     krate
diff --git a/src/libsyntax/show_span.rs b/src/libsyntax/show_span.rs
index 354ba854b10..51d655ec0f2 100644
--- a/src/libsyntax/show_span.rs
+++ b/src/libsyntax/show_span.rs
@@ -13,27 +13,73 @@
 //! This module shows spans for all expressions in the crate
 //! to help with compiler debugging.
 
+use std::str::FromStr;
+
 use ast;
 use diagnostic;
 use visit;
 use visit::Visitor;
 
+enum Mode {
+    Expression,
+    Pattern,
+    Type,
+}
+
+impl FromStr for Mode {
+    fn from_str(s: &str) -> Option<Mode> {
+        let mode = match s {
+            "expr" => Mode::Expression,
+            "pat" => Mode::Pattern,
+            "ty" => Mode::Type,
+            _ => return None
+        };
+        Some(mode)
+    }
+}
+
 struct ShowSpanVisitor<'a> {
     span_diagnostic: &'a diagnostic::SpanHandler,
+    mode: Mode,
 }
 
 impl<'a, 'v> Visitor<'v> for ShowSpanVisitor<'a> {
     fn visit_expr(&mut self, e: &ast::Expr) {
-        self.span_diagnostic.span_note(e.span, "expression");
+        if let Mode::Expression = self.mode {
+            self.span_diagnostic.span_note(e.span, "expression");
+        }
         visit::walk_expr(self, e);
     }
 
+    fn visit_pat(&mut self, p: &ast::Pat) {
+        if let Mode::Pattern = self.mode {
+            self.span_diagnostic.span_note(p.span, "pattern");
+        }
+        visit::walk_pat(self, p);
+    }
+
+    fn visit_ty(&mut self, t: &ast::Ty) {
+        if let Mode::Type = self.mode {
+            self.span_diagnostic.span_note(t.span, "type");
+        }
+        visit::walk_ty(self, t);
+    }
+
     fn visit_mac(&mut self, macro: &ast::Mac) {
         visit::walk_mac(self, macro);
     }
 }
 
-pub fn run(span_diagnostic: &diagnostic::SpanHandler, krate: &ast::Crate) {
-    let mut v = ShowSpanVisitor { span_diagnostic: span_diagnostic };
+pub fn run(span_diagnostic: &diagnostic::SpanHandler,
+           mode: &str,
+           krate: &ast::Crate) {
+    let mode = match mode.parse() {
+        Some(mode) => mode,
+        None => return
+    };
+    let mut v = ShowSpanVisitor {
+        span_diagnostic: span_diagnostic,
+        mode: mode,
+    };
     visit::walk_crate(&mut v, krate);
 }