Skip to content

Commit ef05389

Browse files
committed
---
yaml --- r: 69602 b: refs/heads/auto c: 2460170 h: refs/heads/master v: v3
1 parent d6cce0c commit ef05389

File tree

5 files changed

+84
-1
lines changed

5 files changed

+84
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1414
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1515
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1616
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
17-
refs/heads/auto: dbde42e59e6854979085f3b8a949f307b4da8ffa
17+
refs/heads/auto: 2460170e6aea8dd7aa3e316456047baf18f2f680
1818
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1919
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ pub fn syntax_expander_table() -> SyntaxEnv {
199199
ext::source_util::expand_mod));
200200
syntax_expanders.insert(intern(&"asm"),
201201
builtin_normal_tt(ext::asm::expand_asm));
202+
syntax_expanders.insert(intern(&"cfg"),
203+
builtin_normal_tt(ext::cfg::expand_cfg));
202204
syntax_expanders.insert(
203205
intern(&"trace_macros"),
204206
builtin_normal_tt(ext::trace_macros::expand_trace_macros));
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2013 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+
11+
/**
12+
The compiler code necessary to support the cfg! extension, which
13+
expands to a literal `true` or `false` based on whether the given cfgs
14+
match the current compilation environment.
15+
*/
16+
17+
use ast;
18+
use codemap::span;
19+
use ext::base::*;
20+
use ext::base;
21+
use ext::build::AstBuilder;
22+
use attr;
23+
use attr::*;
24+
use parse;
25+
use parse::token;
26+
use parse::attr::parser_attr;
27+
28+
pub fn expand_cfg(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult {
29+
let p = parse::new_parser_from_tts(cx.parse_sess(), cx.cfg(), tts.to_owned());
30+
31+
let mut cfgs = ~[];
32+
// parse `cfg!(meta_item, meta_item(x,y), meta_item="foo", ...)`
33+
while *p.token != token::EOF {
34+
cfgs.push(p.parse_meta_item());
35+
if p.eat(&token::EOF) { break } // trailing comma is optional,.
36+
p.expect(&token::COMMA);
37+
}
38+
39+
// test_cfg searches for meta items looking like `cfg(foo, ...)`
40+
let in_cfg = &[cx.meta_list(sp, @"cfg", cfgs)];
41+
42+
let matches_cfg = attr::test_cfg(cx.cfg(), in_cfg.iter().transform(|&x| x));
43+
let e = cx.expr_bool(sp, matches_cfg);
44+
MRExpr(e)
45+
}

branches/auto/src/libsyntax/syntax.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ pub mod ext {
7070
}
7171

7272

73+
pub mod cfg;
7374
pub mod fmt;
7475
pub mod env;
7576
pub mod bytes;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2013 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+
11+
// xfail-fast compile-flags doesn't work with fast-check
12+
// compile-flags: --cfg foo --cfg bar(baz) --cfg qux="foo"
13+
14+
fn main() {
15+
// check
16+
if ! cfg!(foo) { fail!() }
17+
if cfg!(not(foo)) { fail!() }
18+
19+
if ! cfg!(bar(baz)) { fail!() }
20+
if cfg!(not(bar(baz))) { fail!() }
21+
22+
if ! cfg!(qux="foo") { fail!() }
23+
if cfg!(not(qux="foo")) { fail!() }
24+
25+
if ! cfg!(foo, bar(baz), qux="foo") { fail!() }
26+
if cfg!(not(foo, bar(baz), qux="foo")) { fail!() }
27+
28+
if cfg!(not_a_cfg) { fail!() }
29+
if cfg!(not_a_cfg, foo, bar(baz), qux="foo") { fail!() }
30+
31+
if ! cfg!(not(not_a_cfg)) { fail!() }
32+
if ! cfg!(not(not_a_cfg), foo, bar(baz), qux="foo") { fail!() }
33+
34+
if cfg!(trailing_comma, ) { fail!() }
35+
}

0 commit comments

Comments
 (0)