@@ -11,7 +11,8 @@ export strip_unconfigured_items;
11
11
fn strip_unconfigured_items ( @ast:: crate crate) -> @ast:: crate {
12
12
auto cfg = crate . node . config ;
13
13
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, _, _)
15
16
with * fold:: default_ast_fold ( ) ) ;
16
17
17
18
auto fold = fold:: make_fold ( precursor) ;
@@ -38,6 +39,34 @@ fn fold_mod(&ast::crate_cfg cfg, &ast::_mod m,
38
39
items=vec:: map ( fld. fold_item , filtered_items) ) ;
39
40
}
40
41
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
+
41
70
// Determine if an item should be translated in the current crate
42
71
// configuration based on the item's attributes
43
72
fn in_cfg ( & ast:: crate_cfg cfg, & @ast:: item item) -> bool {
0 commit comments