@@ -116,11 +116,43 @@ fn fold_arg_(a: arg, fld: @ast_fold) -> arg {
116
116
id : fld. new_id( a. id) ,
117
117
}
118
118
}
119
+
119
120
//used in noop_fold_expr, and possibly elsewhere in the future
120
121
fn fold_mac_ ( m : & mac , fld : @ast_fold ) -> mac {
121
122
spanned {
122
- node : match m. node { mac_invoc_tt( * ) => copy m. node } ,
123
- span : fld. new_span( m. span) ,
123
+ node : match m. node {
124
+ mac_invoc_tt( p, ref tts) =>
125
+ mac_invoc_tt( fld. fold_path( p) ,
126
+ fold_tts( * tts, fld) )
127
+ } ,
128
+ span : fld. new_span ( m. span )
129
+ }
130
+ }
131
+
132
+ fn fold_tts ( tts : & [ token_tree ] , fld : @ast_fold ) -> ~[ token_tree ] {
133
+ do tts. map |tt| {
134
+ match * tt {
135
+ tt_tok( span, ref tok) =>
136
+ tt_tok ( span , maybe_fold_ident ( tok , fld ) ) ,
137
+ tt_delim( ref tts) =>
138
+ tt_delim ( fold_tts ( * tts , fld ) ) ,
139
+ tt_seq( span, ref pattern, ref sep, is_optional) =>
140
+ tt_seq ( span ,
141
+ fold_tts ( * pattern , fld ) ,
142
+ sep. map( |tok|maybe_fold_ident( tok, fld) ) ,
143
+ is_optional ) ,
144
+ tt_nonterminal( sp, ref ident) =>
145
+ tt_nonterminal( sp, fld. fold_ident( * ident) )
146
+ }
147
+ }
148
+ }
149
+
150
+ // apply ident folder if it's an ident, otherwise leave it alone
151
+ fn maybe_fold_ident ( t : & token:: Token , fld : @ast_fold ) -> token:: Token {
152
+ match * t {
153
+ token:: IDENT ( id, followed_by_colons) =>
154
+ token:: IDENT ( fld. fold_ident ( id) , followed_by_colons) ,
155
+ _ => copy * t
124
156
}
125
157
}
126
158
@@ -291,7 +323,10 @@ pub fn noop_fold_item_underscore(i: &item_, fld: @ast_fold) -> item_ {
291
323
}
292
324
item_mac( ref m) => {
293
325
// FIXME #2888: we might actually want to do something here.
294
- item_mac ( copy * m)
326
+ // ... okay, we're doing something. It would probably be nicer
327
+ // to add something to the ast_fold trait, but I'll defer
328
+ // that work.
329
+ item_mac ( fold_mac_ ( m, fld) )
295
330
}
296
331
}
297
332
}
0 commit comments