]>
Commit | Line | Data |
---|---|---|
223e47cc LB |
1 | // Copyright 2012 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 | ||
9cc50fc6 SL |
11 | use syntax::ext::base::ExtCtxt; |
12 | use syntax::ext::base; | |
13 | use syntax::feature_gate; | |
14 | use syntax::parse::token::keywords; | |
3157f602 XL |
15 | use syntax_pos::Span; |
16 | use syntax::tokenstream::TokenTree; | |
223e47cc | 17 | |
1a4d82fc JJ |
18 | pub fn expand_trace_macros(cx: &mut ExtCtxt, |
19 | sp: Span, | |
92a42be0 | 20 | tt: &[TokenTree]) |
9e0c209e | 21 | -> Box<base::MacResult + 'static> { |
85aaf69f | 22 | if !cx.ecfg.enable_trace_macros() { |
9e0c209e | 23 | feature_gate::emit_feature_err(&cx.parse_sess, |
85aaf69f SL |
24 | "trace_macros", |
25 | sp, | |
e9174d1e | 26 | feature_gate::GateIssue::Language, |
85aaf69f SL |
27 | feature_gate::EXPLAIN_TRACE_MACROS); |
28 | return base::DummyResult::any(sp); | |
29 | } | |
30 | ||
d9579d0f | 31 | match (tt.len(), tt.first()) { |
92a42be0 | 32 | (1, Some(&TokenTree::Token(_, ref tok))) if tok.is_keyword(keywords::True) => { |
1a4d82fc JJ |
33 | cx.set_trace_macros(true); |
34 | } | |
92a42be0 | 35 | (1, Some(&TokenTree::Token(_, ref tok))) if tok.is_keyword(keywords::False) => { |
1a4d82fc JJ |
36 | cx.set_trace_macros(false); |
37 | } | |
38 | _ => cx.span_err(sp, "trace_macros! accepts only `true` or `false`"), | |
223e47cc LB |
39 | } |
40 | ||
1a4d82fc | 41 | base::DummyResult::any(sp) |
223e47cc | 42 | } |