Skip to content

Commit 104002b

Browse files
committed
Span debugger
1 parent 21b856d commit 104002b

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

src/librustc/driver/driver.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,10 @@ pub fn compile_input(sess: Session, cfg: ast::CrateConfig, input: &Input,
518518
let (outputs, trans) = {
519519
let (expanded_crate, ast_map) = {
520520
let crate = phase_1_parse_input(sess, cfg, input);
521+
if sess.show_span() {
522+
front::show_span::run(sess, &crate);
523+
return;
524+
}
521525
if stop_after_phase_1(sess) { return; }
522526
let loader = &mut Loader::new(sess);
523527
phase_2_configure_and_expand(sess, loader, crate)

src/librustc/driver/session.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ debugging_opts!(
6060
BORROWCK_STATS,
6161
NO_LANDING_PADS,
6262
DEBUG_LLVM,
63+
SHOW_SPAN,
6364
COUNT_TYPE_SIZES,
6465
META_STATS,
6566
NO_OPT,
@@ -95,6 +96,7 @@ pub fn debugging_opts_map() -> ~[(&'static str, &'static str, u64)] {
9596
("no-landing-pads", "omit landing pads for unwinding",
9697
NO_LANDING_PADS),
9798
("debug-llvm", "enable debug output from LLVM", DEBUG_LLVM),
99+
("show-span", "show spans", SHOW_SPAN),
98100
("count-type-sizes", "count the sizes of aggregate types",
99101
COUNT_TYPE_SIZES),
100102
("meta-stats", "gather metadata statistics", META_STATS),
@@ -351,6 +353,9 @@ impl Session_ {
351353
pub fn no_landing_pads(&self) -> bool {
352354
self.debugging_opt(NO_LANDING_PADS)
353355
}
356+
pub fn show_span(&self) -> bool {
357+
self.debugging_opt(SHOW_SPAN)
358+
}
354359

355360
// DEPRECATED. This function results in a lot of allocations when they
356361
// are not necessary.

src/librustc/front/show_span.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use syntax::ast;
12+
use syntax::visit;
13+
use syntax::visit::Visitor;
14+
15+
use driver::session::Session;
16+
17+
struct ShowSpanVisitor {
18+
sess: Session
19+
}
20+
21+
impl Visitor<()> for ShowSpanVisitor {
22+
fn visit_expr(&mut self, e: &ast::Expr, _: ()) {
23+
self.sess.span_note(e.span, "expression");
24+
visit::walk_expr(self, e, ());
25+
}
26+
}
27+
28+
pub fn run(sess: Session, crate: &ast::Crate) {
29+
let mut v = ShowSpanVisitor { sess: sess };
30+
visit::walk_crate(&mut v, crate, ());
31+
}

src/librustc/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ pub mod front {
9797
pub mod std_inject;
9898
pub mod assign_node_ids_and_map;
9999
pub mod feature_gate;
100+
pub mod show_span;
100101
}
101102

102103
pub mod back {

0 commit comments

Comments
 (0)