Skip to content

Commit b9396ed

Browse files
committed
---
yaml --- r: 29847 b: refs/heads/incoming c: 1e96099 h: refs/heads/master i: 29845: f22b7f8 29843: 2cc1c3e 29839: 207d73b v: v3
1 parent b19cdd9 commit b9396ed

File tree

5 files changed

+52
-8
lines changed

5 files changed

+52
-8
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
9-
refs/heads/incoming: 00ef5418d44a191b464db87b99d8034202c86c7d
9+
refs/heads/incoming: 1e960999185ecba7525285fc72695b7407833268
1010
refs/heads/dist-snap: 2f32a1581f522e524009138b33b1c7049ced668d
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/src/libsyntax/ext/base.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ fn syntax_expander_table() -> hashmap<~str, syntax_extension> {
111111
builtin(ext::source_util::expand_mod));
112112
syntax_expanders.insert(~"proto",
113113
builtin_item_tt(ext::pipes::expand_proto));
114+
syntax_expanders.insert(
115+
~"trace_macros",
116+
builtin_expr_tt(ext::trace_macros::expand_trace_macros));
114117
return syntax_expanders;
115118
}
116119

@@ -136,14 +139,17 @@ trait ext_ctxt {
136139
fn span_bug(sp: span, msg: ~str) -> !;
137140
fn bug(msg: ~str) -> !;
138141
fn next_id() -> ast::node_id;
142+
pure fn trace_macros() -> bool;
143+
fn set_trace_macros(x: bool);
139144
}
140145

141146
fn mk_ctxt(parse_sess: parse::parse_sess,
142147
cfg: ast::crate_cfg) -> ext_ctxt {
143148
type ctxt_repr = {parse_sess: parse::parse_sess,
144149
cfg: ast::crate_cfg,
145150
mut backtrace: expn_info,
146-
mut mod_path: ~[ast::ident]};
151+
mut mod_path: ~[ast::ident],
152+
mut trace_mac: bool};
147153
impl ctxt_repr: ext_ctxt {
148154
fn codemap() -> codemap { self.parse_sess.cm }
149155
fn parse_sess() -> parse::parse_sess { self.parse_sess }
@@ -199,12 +205,19 @@ fn mk_ctxt(parse_sess: parse::parse_sess,
199205
fn next_id() -> ast::node_id {
200206
return parse::next_node_id(self.parse_sess);
201207
}
208+
pure fn trace_macros() -> bool {
209+
self.trace_mac
210+
}
211+
fn set_trace_macros(x: bool) {
212+
self.trace_mac = x
213+
}
202214
}
203215
let imp : ctxt_repr = {
204216
parse_sess: parse_sess,
205217
cfg: cfg,
206218
mut backtrace: none,
207-
mut mod_path: ~[]
219+
mut mod_path: ~[],
220+
mut trace_mac: false
208221
};
209222
return imp as ext_ctxt
210223
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import codemap::span;
2+
import ext::base::ext_ctxt;
3+
import ast::tt_delim;
4+
import parse::lexer::{new_tt_reader, reader};
5+
import parse::parser::{parser, SOURCE_FILE};
6+
import parse::common::parser_common;
7+
8+
fn expand_trace_macros(cx: ext_ctxt, sp: span,
9+
tt: ~[ast::token_tree]) -> base::mac_result
10+
{
11+
let sess = cx.parse_sess();
12+
let cfg = cx.cfg();
13+
let tt_rdr = new_tt_reader(cx.parse_sess().span_diagnostic,
14+
cx.parse_sess().interner, none, tt);
15+
let rdr = tt_rdr as reader;
16+
let rust_parser = parser(sess, cfg, rdr.dup(), SOURCE_FILE);
17+
18+
let arg = rust_parser.parse_ident();
19+
match arg {
20+
@~"true" => cx.set_trace_macros(true),
21+
@~"false" => cx.set_trace_macros(false),
22+
_ => cx.span_fatal(sp, ~"trace_macros! only accepts `true` or `false`")
23+
}
24+
let rust_parser = parser(sess, cfg, rdr.dup(), SOURCE_FILE);
25+
let result = rust_parser.parse_expr();
26+
base::mr_expr(result)
27+
}

branches/incoming/src/libsyntax/ext/tt/macro_rules.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,17 @@ fn add_new_extension(cx: ext_ctxt, sp: span, name: ident,
4747
};
4848

4949
// Given `lhses` and `rhses`, this is the new macro we create
50-
fn generic_extension(cx: ext_ctxt, sp: span, _name: ident,
50+
fn generic_extension(cx: ext_ctxt, sp: span, name: ident,
5151
arg: ~[ast::token_tree],
5252
lhses: ~[@named_match], rhses: ~[@named_match])
5353
-> mac_result {
5454

55-
//io::println(fmt!("%s! { %s }", *name,
56-
// print::pprust::unexpanded_tt_to_str(
57-
// ast::tt_delim(arg),
58-
// cx.parse_sess().interner)));
55+
if cx.trace_macros() {
56+
io::println(fmt!("%s! { %s }", *name,
57+
print::pprust::unexpanded_tt_to_str(
58+
ast::tt_delim(arg),
59+
cx.parse_sess().interner)));
60+
}
5961

6062
// Which arm's failure should we report? (the one furthest along)
6163
let mut best_fail_spot = {lo: 0u, hi: 0u, expn_info: none};

branches/incoming/src/libsyntax/syntax.rc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,6 @@ mod ext {
8989
mod check;
9090
mod liveness;
9191
}
92+
93+
mod trace_macros;
9294
}

0 commit comments

Comments
 (0)