Skip to content

Commit f50a582

Browse files
committed
Add a syntax extension to log syntax, for debugging macros.
1 parent e7139e2 commit f50a582

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

src/comp/rustc.rc

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ mod middle {
4949

5050
mod syntax {
5151
mod ast;
52+
5253
mod fold;
5354
mod visit;
5455
mod codemap;
@@ -67,6 +68,7 @@ mod syntax {
6768
mod simplext;
6869
mod concat_idents;
6970
mod ident_to_str;
71+
mod log_syntax;
7072
}
7173
mod print {
7274
mod pprust;

src/comp/syntax/ext/base.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,23 @@ fn syntax_expander_table() -> hashmap[str, syntax_extension] {
2929
normal(ext::concat_idents::expand_syntax_ext));
3030
syntax_expanders.insert("ident_to_str",
3131
normal(ext::ident_to_str::expand_syntax_ext));
32+
syntax_expanders.insert("log_syntax",
33+
normal(ext::log_syntax::expand_syntax_ext));
3234
ret syntax_expanders;
3335
}
3436

35-
obj ext_ctxt(sess: @session, crate_file_name_hack: str,
37+
obj ext_ctxt(sess: @session, crate_file_name_hack: str,
3638
mutable backtrace: span[]) {
3739
fn crate_file_name() -> str { ret crate_file_name_hack; }
3840

41+
fn session() -> @session { ret sess; }
42+
3943
fn print_backtrace() {
4044
for sp: span in backtrace {
4145
sess.span_note(sp, "(while expanding this)")
4246
}
4347
}
44-
48+
4549
fn bt_push(sp: span) { backtrace += ~[sp]; }
4650
fn bt_pop() { ivec::pop(backtrace); }
4751

@@ -59,7 +63,7 @@ obj ext_ctxt(sess: @session, crate_file_name_hack: str,
5963
}
6064
fn span_bug(sp:span, msg: str) -> ! {
6165
self.print_backtrace();
62-
sess.span_bug(sp, msg);
66+
sess.span_bug(sp, msg);
6367
}
6468
fn bug(msg: str) -> ! {
6569
self.print_backtrace();

src/comp/syntax/ext/log_syntax.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import std::option;
2+
import base::*;
3+
import syntax::ast;
4+
5+
fn expand_syntax_ext(cx: &ext_ctxt, sp: codemap::span, arg: @ast::expr,
6+
body: option::t[str]) -> @ast::expr {
7+
8+
cx.print_backtrace();
9+
std::io::stdout().write_line(print::pprust::expr_to_str(arg));
10+
11+
//trivial expression
12+
ret @{id: cx.next_id(), node: ast::expr_rec(~[], option::none), span: sp};
13+
}

0 commit comments

Comments
 (0)