about summary refs log tree commit diff
path: root/src/comp/syntax/ext
diff options
context:
space:
mode:
authorPaul Stansifer <paul.stansifer@gmail.com>2011-08-15 13:33:12 -0700
committerPaul Stansifer <paul.stansifer@gmail.com>2011-08-15 15:35:28 -0700
commitebb16e6a25da9694dabe19ecea24baeb7007ba1f (patch)
tree180e6854766f09a97f0ef887eada5bad88403327 /src/comp/syntax/ext
parentc48036c0b7d10606dc8c63b87351fb394cf7d4a6 (diff)
downloadrust-ebb16e6a25da9694dabe19ecea24baeb7007ba1f.tar.gz
rust-ebb16e6a25da9694dabe19ecea24baeb7007ba1f.zip
Use span stacks to track macro expansion for less troublesome error messages.
Diffstat (limited to 'src/comp/syntax/ext')
-rw-r--r--src/comp/syntax/ext/base.rs24
-rw-r--r--src/comp/syntax/ext/simplext.rs7
2 files changed, 23 insertions, 8 deletions
diff --git a/src/comp/syntax/ext/base.rs b/src/comp/syntax/ext/base.rs
index 62c480ad96b..9ad3d8d1b2e 100644
--- a/src/comp/syntax/ext/base.rs
+++ b/src/comp/syntax/ext/base.rs
@@ -35,19 +35,29 @@ fn syntax_expander_table() -> hashmap[str, syntax_extension] {
 }
 
 obj ext_ctxt(sess: @session, crate_file_name_hack: str,
-             mutable backtrace: span[]) {
+             mutable backtrace: codemap::opt_span) {
     fn crate_file_name() -> str { ret crate_file_name_hack; }
 
     fn session() -> @session { ret sess; }
 
     fn print_backtrace() {
-        for sp: span in backtrace {
-            sess.span_note(sp, "(while expanding this)")
-        }
     }
 
-    fn bt_push(sp: span) { backtrace += ~[sp]; }
-    fn bt_pop() { ivec::pop(backtrace); }
+    fn backtrace() -> codemap::opt_span { ret backtrace; }
+
+    fn bt_push(sp: span) {
+        backtrace = codemap::os_some(@{lo: sp.lo, hi: sp.hi,
+                                       expanded_from: backtrace});
+    }
+    fn bt_pop() {
+        alt backtrace {
+          codemap::os_some(@{expanded_from: pre, _}) {
+            let tmp = pre;
+            backtrace = tmp;
+          }
+          _ { self.bug("tried to pop without a push"); }
+        }
+    }
 
     fn span_fatal(sp: span, msg: str) -> ! {
         self.print_backtrace();
@@ -85,7 +95,7 @@ fn mk_ctxt(sess: &session) -> ext_ctxt {
     // super-ugly and needs a better solution.
     let crate_file_name_hack = sess.get_codemap().files.(0).name;
 
-    ret ext_ctxt(@sess, crate_file_name_hack, ~[]);
+    ret ext_ctxt(@sess, crate_file_name_hack, codemap::os_none);
 }
 
 fn expr_to_str(cx: &ext_ctxt, expr: @ast::expr, error: str) -> str {
diff --git a/src/comp/syntax/ext/simplext.rs b/src/comp/syntax/ext/simplext.rs
index 2a0e7859b10..b57812cb1d2 100644
--- a/src/comp/syntax/ext/simplext.rs
+++ b/src/comp/syntax/ext/simplext.rs
@@ -205,6 +205,10 @@ fn use_selectors_to_bind(b: &binders, e: @expr) -> option::t[bindings] {
 fn transcribe(cx: &ext_ctxt, b: &bindings, body: @expr) -> @expr {
     let idx_path: @mutable [uint] = @mutable ~[];
     fn new_id(old: node_id, cx: &ext_ctxt) -> node_id { ret cx.next_id(); }
+    fn new_span(cx: &ext_ctxt, sp: &span) -> span {
+        /* this discards information in the case of macro-defining macros */
+        ret {lo: sp.lo, hi: sp.hi, expanded_from: cx.backtrace()};
+    }
     let afp = default_ast_fold();
     let f_pre =
         {fold_ident: bind transcribe_ident(cx, b, idx_path, _, _),
@@ -215,7 +219,8 @@ fn transcribe(cx: &ext_ctxt, b: &bindings, body: @expr) -> @expr {
          fold_block:
              bind transcribe_block(cx, b, idx_path, _, _, afp.fold_block),
          map_exprs: bind transcribe_exprs(cx, b, idx_path, _, _),
-         new_id: bind new_id(_, cx) with *afp};
+         new_id: bind new_id(_, cx),
+         new_span: bind new_span(cx, _) with *afp};
     let f = make_fold(f_pre);
     let result = f.fold_expr(body);
     dummy_out(f); //temporary: kill circular reference