Skip to content

Commit c282e5e

Browse files
committed
---
yaml --- r: 3583 b: refs/heads/master c: b79ea48 h: refs/heads/master i: 3581: 1234b4d 3579: 902e4d2 3575: 917e879 3567: 0c3b199 3551: 539e528 3519: e34a593 3455: 54d66c0 3327: fae2cb5 3071: fa4a634 v: v3
1 parent c3c9e99 commit c282e5e

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
lines changed

[refs]

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 6853e04fc40d02522a57660b043e220402d11416
2+
refs/heads/master: b79ea489e35b7030bba344fcb5d940a660d8012e

trunk/src/comp/front/config.rs

+33-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ fn strip_unconfigured_items(@ast::crate crate) -> @ast::crate {
1212
auto cfg = crate.node.config;
1313

1414
auto precursor = rec(fold_mod = bind fold_mod(cfg, _, _),
15-
fold_block = bind fold_block(cfg, _, _)
15+
fold_block = bind fold_block(cfg, _, _),
16+
fold_native_mod = bind fold_native_mod(cfg, _, _)
1617
with *fold::default_ast_fold());
1718

1819
auto fold = fold::make_fold(precursor);
@@ -24,7 +25,7 @@ fn strip_unconfigured_items(@ast::crate crate) -> @ast::crate {
2425

2526
fn filter_item(&ast::crate_cfg cfg,
2627
&@ast::item item) -> option::t[@ast::item] {
27-
if (in_cfg(cfg, item)) {
28+
if (item_in_cfg(cfg, item)) {
2829
option::some(item)
2930
} else {
3031
option::none
@@ -39,13 +40,32 @@ fn fold_mod(&ast::crate_cfg cfg, &ast::_mod m,
3940
items=vec::map(fld.fold_item, filtered_items));
4041
}
4142

43+
fn filter_native_item(&ast::crate_cfg cfg, &@ast::native_item item)
44+
-> option::t[@ast::native_item] {
45+
if (native_item_in_cfg(cfg, item)) {
46+
option::some(item)
47+
} else {
48+
option::none
49+
}
50+
}
51+
52+
fn fold_native_mod(&ast::crate_cfg cfg, &ast::native_mod nm,
53+
fold::ast_fold fld) -> ast::native_mod {
54+
auto filter = bind filter_native_item(cfg, _);
55+
auto filtered_items = vec::filter_map(filter, nm.items);
56+
ret rec(native_name=nm.native_name,
57+
abi=nm.abi,
58+
view_items=vec::map(fld.fold_view_item, nm.view_items),
59+
items=filtered_items);
60+
}
61+
4262
fn filter_stmt(&ast::crate_cfg cfg,
4363
&@ast::stmt stmt) -> option::t[@ast::stmt] {
4464
alt (stmt.node) {
4565
case (ast::stmt_decl(?decl, _)) {
4666
alt (decl.node) {
4767
case (ast::decl_item(?item)) {
48-
if (in_cfg(cfg, item)) {
68+
if (item_in_cfg(cfg, item)) {
4969
option::some(stmt)
5070
} else {
5171
option::none
@@ -67,12 +87,20 @@ fn fold_block(&ast::crate_cfg cfg, &ast::block_ b,
6787
id=b.id);
6888
}
6989

90+
fn item_in_cfg(&ast::crate_cfg cfg, &@ast::item item) -> bool {
91+
ret in_cfg(cfg, item.attrs);
92+
}
93+
94+
fn native_item_in_cfg(&ast::crate_cfg cfg, &@ast::native_item item) -> bool {
95+
ret in_cfg(cfg, item.attrs);
96+
}
97+
7098
// Determine if an item should be translated in the current crate
7199
// configuration based on the item's attributes
72-
fn in_cfg(&ast::crate_cfg cfg, &@ast::item item) -> bool {
100+
fn in_cfg(&ast::crate_cfg cfg, &vec[ast::attribute] attrs) -> bool {
73101

74102
// The "cfg" attributes on the item
75-
auto item_cfg_attrs = attr::find_attrs_by_name(item.attrs, "cfg");
103+
auto item_cfg_attrs = attr::find_attrs_by_name(attrs, "cfg");
76104
auto item_has_cfg_attrs = vec::len(item_cfg_attrs) > 0u;
77105
if (!item_has_cfg_attrs) { ret true; }
78106

trunk/src/test/run-pass/conditional-compile.rs

+8
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,11 @@ fn test_in_fn_ctxt() {
8585
const int i = 1;
8686
assert i == 1;
8787
}
88+
89+
mod test_native_items {
90+
native "rust" mod rustrt {
91+
#[cfg(bogus)]
92+
fn str_vec(str s) -> vec[u8];
93+
fn str_vec(str s) -> vec[u8];
94+
}
95+
}

0 commit comments

Comments
 (0)