2012-12-03 16:48:01 -08:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2015-12-10 23:23:14 +09:00
|
|
|
use syntax::ext::base::ExtCtxt;
|
|
|
|
use syntax::ext::base;
|
|
|
|
use syntax::feature_gate;
|
|
|
|
use syntax::parse::token::keywords;
|
2016-06-21 18:08:13 -04:00
|
|
|
use syntax_pos::Span;
|
2016-06-20 08:49:33 -07:00
|
|
|
use syntax::tokenstream::TokenTree;
|
2014-05-05 18:56:44 -07:00
|
|
|
|
2013-12-28 22:06:22 -07:00
|
|
|
pub fn expand_trace_macros(cx: &mut ExtCtxt,
|
2013-08-31 18:13:04 +02:00
|
|
|
sp: Span,
|
2015-11-06 14:52:02 +01:00
|
|
|
tt: &[TokenTree])
|
2016-06-06 20:22:48 +05:30
|
|
|
-> Box<base::MacResult + 'static> {
|
2015-02-15 23:49:55 +01:00
|
|
|
if !cx.ecfg.enable_trace_macros() {
|
|
|
|
feature_gate::emit_feature_err(&cx.parse_sess.span_diagnostic,
|
|
|
|
"trace_macros",
|
|
|
|
sp,
|
2015-09-04 16:37:22 -07:00
|
|
|
feature_gate::GateIssue::Language,
|
2015-02-15 23:49:55 +01:00
|
|
|
feature_gate::EXPLAIN_TRACE_MACROS);
|
|
|
|
return base::DummyResult::any(sp);
|
|
|
|
}
|
|
|
|
|
2015-04-15 22:12:12 -07:00
|
|
|
match (tt.len(), tt.first()) {
|
2015-11-06 14:52:02 +01:00
|
|
|
(1, Some(&TokenTree::Token(_, ref tok))) if tok.is_keyword(keywords::True) => {
|
2014-03-18 23:14:08 +11:00
|
|
|
cx.set_trace_macros(true);
|
|
|
|
}
|
2015-11-06 14:52:02 +01:00
|
|
|
(1, Some(&TokenTree::Token(_, ref tok))) if tok.is_keyword(keywords::False) => {
|
2014-03-18 23:14:08 +11:00
|
|
|
cx.set_trace_macros(false);
|
|
|
|
}
|
|
|
|
_ => cx.span_err(sp, "trace_macros! accepts only `true` or `false`"),
|
2012-08-15 10:45:10 -07:00
|
|
|
}
|
2012-11-26 22:12:31 -05:00
|
|
|
|
2014-04-15 22:00:14 +10:00
|
|
|
base::DummyResult::any(sp)
|
2012-08-15 10:45:10 -07:00
|
|
|
}
|