about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-02-07 03:26:34 -0800
committerbors <bors@rust-lang.org>2014-02-07 03:26:34 -0800
commitc3ccaacc6c90fc678cbba9c3c0427f0a7dece75c (patch)
treef9e1c89e0fb4d03228e4c41fb9a561178a5ba0d8
parent14cb4be6e90d0c5eb42a3eef58d083acc8e51837 (diff)
parente5463b996c84b34c6f7cb55a7e9e5cfdc29ca028 (diff)
downloadrust-c3ccaacc6c90fc678cbba9c3c0427f0a7dece75c.tar.gz
rust-c3ccaacc6c90fc678cbba9c3c0427f0a7dece75c.zip
auto merge of #12087 : sanxiyn/rust/show-span, r=huonw
-rw-r--r--src/librustc/driver/driver.rs4
-rw-r--r--src/librustc/driver/session.rs5
-rw-r--r--src/librustc/front/show_span.rs36
-rw-r--r--src/librustc/lib.rs1
-rw-r--r--src/libsyntax/parse/parser.rs6
5 files changed, 49 insertions, 3 deletions
diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs
index d2c2763eab1..3e5ecc605d6 100644
--- a/src/librustc/driver/driver.rs
+++ b/src/librustc/driver/driver.rs
@@ -518,6 +518,10 @@ pub fn compile_input(sess: Session, cfg: ast::CrateConfig, input: &Input,
     let (outputs, trans) = {
         let (expanded_crate, ast_map) = {
             let crate = phase_1_parse_input(sess, cfg, input);
+            if sess.show_span() {
+                front::show_span::run(sess, &crate);
+                return;
+            }
             if stop_after_phase_1(sess) { return; }
             let loader = &mut Loader::new(sess);
             phase_2_configure_and_expand(sess, loader, crate)
diff --git a/src/librustc/driver/session.rs b/src/librustc/driver/session.rs
index 859d09b5962..6fb7e749475 100644
--- a/src/librustc/driver/session.rs
+++ b/src/librustc/driver/session.rs
@@ -60,6 +60,7 @@ debugging_opts!(
         BORROWCK_STATS,
         NO_LANDING_PADS,
         DEBUG_LLVM,
+        SHOW_SPAN,
         COUNT_TYPE_SIZES,
         META_STATS,
         NO_OPT,
@@ -95,6 +96,7 @@ pub fn debugging_opts_map() -> ~[(&'static str, &'static str, u64)] {
      ("no-landing-pads", "omit landing pads for unwinding",
       NO_LANDING_PADS),
      ("debug-llvm", "enable debug output from LLVM", DEBUG_LLVM),
+     ("show-span", "show spans for compiler debugging", SHOW_SPAN),
      ("count-type-sizes", "count the sizes of aggregate types",
       COUNT_TYPE_SIZES),
      ("meta-stats", "gather metadata statistics", META_STATS),
@@ -351,6 +353,9 @@ impl Session_ {
     pub fn no_landing_pads(&self) -> bool {
         self.debugging_opt(NO_LANDING_PADS)
     }
+    pub fn show_span(&self) -> bool {
+        self.debugging_opt(SHOW_SPAN)
+    }
 
     // DEPRECATED. This function results in a lot of allocations when they
     // are not necessary.
diff --git a/src/librustc/front/show_span.rs b/src/librustc/front/show_span.rs
new file mode 100644
index 00000000000..2c076aac095
--- /dev/null
+++ b/src/librustc/front/show_span.rs
@@ -0,0 +1,36 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! Span debugger
+//!
+//! This module shows spans for all expressions in the crate
+//! to help with compiler debugging.
+
+use syntax::ast;
+use syntax::visit;
+use syntax::visit::Visitor;
+
+use driver::session::Session;
+
+struct ShowSpanVisitor {
+    sess: Session
+}
+
+impl Visitor<()> for ShowSpanVisitor {
+    fn visit_expr(&mut self, e: &ast::Expr, _: ()) {
+        self.sess.span_note(e.span, "expression");
+        visit::walk_expr(self, e, ());
+    }
+}
+
+pub fn run(sess: Session, crate: &ast::Crate) {
+    let mut v = ShowSpanVisitor { sess: sess };
+    visit::walk_crate(&mut v, crate, ());
+}
diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs
index b6efd66dfbd..edcefdf6594 100644
--- a/src/librustc/lib.rs
+++ b/src/librustc/lib.rs
@@ -97,6 +97,7 @@ pub mod front {
     pub mod std_inject;
     pub mod assign_node_ids_and_map;
     pub mod feature_gate;
+    pub mod show_span;
 }
 
 pub mod back {
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index e1cbdd12bd3..aeeae94238b 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -1771,7 +1771,7 @@ impl Parser {
             self.commit_expr_expecting(*es.last().unwrap(), token::RPAREN);
 
             return if es.len() == 1 && !trailing_comma {
-                self.mk_expr(lo, self.span.hi, ExprParen(es[0]))
+                self.mk_expr(lo, hi, ExprParen(es[0]))
             }
             else {
                 self.mk_expr(lo, hi, ExprTup(es))
@@ -1994,7 +1994,7 @@ impl Parser {
                                 seq_sep_trailing_disallowed(token::COMMA),
                                 |p| p.parse_expr()
                             );
-                            hi = self.span.hi;
+                            hi = self.last_span.hi;
 
                             es.unshift(e);
                             let nd = self.mk_method_call(i, tys, es, NoSugar);
@@ -2510,7 +2510,7 @@ impl Parser {
                               parse_decl: |&mut Parser| -> P<FnDecl>,
                               parse_body: |&mut Parser| -> @Expr)
                               -> @Expr {
-        let lo = self.last_span.lo;
+        let lo = self.span.lo;
         let decl = parse_decl(self);
         let body = parse_body(self);
         let fakeblock = P(ast::Block {