Skip to content

Commit 5613229

Browse files
committed
---
yaml --- r: 3508 b: refs/heads/master c: 39fccf3 h: refs/heads/master v: v3
1 parent 616a507 commit 5613229

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 6346a67cbd96f0c1faf483851e1f120334862309
2+
refs/heads/master: 39fccf3bc78c53924dd0b5676dc114d62ab8d1b0

trunk/src/comp/front/config.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ export strip_unconfigured_items;
1111
fn strip_unconfigured_items(@ast::crate crate) -> @ast::crate {
1212
auto cfg = crate.node.config;
1313

14-
auto precursor = rec(fold_mod = bind fold_mod(cfg, _, _)
14+
auto precursor = rec(fold_mod = bind fold_mod(cfg, _, _),
15+
fold_block = bind fold_block(cfg, _, _)
1516
with *fold::default_ast_fold());
1617

1718
auto fold = fold::make_fold(precursor);
@@ -38,6 +39,34 @@ fn fold_mod(&ast::crate_cfg cfg, &ast::_mod m,
3839
items=vec::map(fld.fold_item, filtered_items));
3940
}
4041

42+
fn filter_stmt(&ast::crate_cfg cfg,
43+
&@ast::stmt stmt) -> option::t[@ast::stmt] {
44+
alt (stmt.node) {
45+
case (ast::stmt_decl(?decl, _)) {
46+
alt (decl.node) {
47+
case (ast::decl_item(?item)) {
48+
if (in_cfg(cfg, item)) {
49+
option::some(stmt)
50+
} else {
51+
option::none
52+
}
53+
}
54+
case (_) { option::some(stmt) }
55+
}
56+
}
57+
case (_) { option::some(stmt) }
58+
}
59+
}
60+
61+
fn fold_block(&ast::crate_cfg cfg, &ast::block_ b,
62+
fold::ast_fold fld) -> ast::block_ {
63+
auto filter = bind filter_stmt(cfg, _);
64+
auto filtered_stmts = vec::filter_map(filter, b.stmts);
65+
ret rec(stmts=vec::map(fld.fold_stmt, filtered_stmts),
66+
expr=option::map(fld.fold_expr, b.expr),
67+
id=b.id);
68+
}
69+
4170
// Determine if an item should be translated in the current crate
4271
// configuration based on the item's attributes
4372
fn in_cfg(&ast::crate_cfg cfg, &@ast::item item) -> bool {

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,18 @@ fn main() {
7070
assert b;
7171
let t x = true;
7272
let tg y = bar;
73+
74+
test_in_fn_ctxt();
7375
}
7476

77+
fn test_in_fn_ctxt() {
78+
#[cfg(bogus)]
79+
fn f() { fail }
80+
fn f() {}
81+
f();
82+
83+
#[cfg(bogus)]
84+
const int i = 0;
85+
const int i = 1;
86+
assert i == 1;
87+
}

0 commit comments

Comments
 (0)