@@ -12,7 +12,8 @@ fn strip_unconfigured_items(@ast::crate crate) -> @ast::crate {
12
12
auto cfg = crate . node . config ;
13
13
14
14
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, _, _)
16
17
with * fold:: default_ast_fold ( ) ) ;
17
18
18
19
auto fold = fold:: make_fold ( precursor) ;
@@ -24,7 +25,7 @@ fn strip_unconfigured_items(@ast::crate crate) -> @ast::crate {
24
25
25
26
fn filter_item ( & ast:: crate_cfg cfg,
26
27
& @ast:: item item) -> option:: t[ @ast:: item ] {
27
- if ( in_cfg ( cfg, item) ) {
28
+ if ( item_in_cfg ( cfg, item) ) {
28
29
option:: some ( item)
29
30
} else {
30
31
option:: none
@@ -39,13 +40,32 @@ fn fold_mod(&ast::crate_cfg cfg, &ast::_mod m,
39
40
items=vec:: map ( fld. fold_item , filtered_items) ) ;
40
41
}
41
42
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
+
42
62
fn filter_stmt ( & ast:: crate_cfg cfg,
43
63
& @ast:: stmt stmt) -> option:: t[ @ast:: stmt ] {
44
64
alt ( stmt. node ) {
45
65
case ( ast:: stmt_decl ( ?decl, _) ) {
46
66
alt ( decl. node ) {
47
67
case ( ast:: decl_item ( ?item) ) {
48
- if ( in_cfg ( cfg, item) ) {
68
+ if ( item_in_cfg ( cfg, item) ) {
49
69
option:: some ( stmt)
50
70
} else {
51
71
option:: none
@@ -67,12 +87,20 @@ fn fold_block(&ast::crate_cfg cfg, &ast::block_ b,
67
87
id=b. id ) ;
68
88
}
69
89
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
+
70
98
// Determine if an item should be translated in the current crate
71
99
// 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 {
73
101
74
102
// 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" ) ;
76
104
auto item_has_cfg_attrs = vec:: len ( item_cfg_attrs) > 0 u;
77
105
if ( !item_has_cfg_attrs) { ret true ; }
78
106
0 commit comments