@@ -203,52 +203,6 @@ pub fn expand_expr(e: @ast::Expr, fld: &mut MacroExpander) -> @ast::Expr {
203
203
}
204
204
}
205
205
206
- // This is a secondary mechanism for invoking syntax extensions on items:
207
- // "decorator" attributes, such as #[auto_encode]. These are invoked by an
208
- // attribute prefixing an item, and are interpreted by feeding the item
209
- // through the named attribute _as a syntax extension_ and splicing in the
210
- // resulting item vec into place in favour of the decorator. Note that
211
- // these do _not_ work for macro extensions, just ItemDecorator ones.
212
- //
213
- // NB: there is some redundancy between this and expand_item, below, and
214
- // they might benefit from some amount of semantic and language-UI merger.
215
- pub fn expand_mod_items ( module_ : & ast:: Mod , fld : & mut MacroExpander ) -> ast:: Mod {
216
- // Fold the contents first:
217
- let module_ = noop_fold_mod ( module_, fld) ;
218
-
219
- // For each item, look through the attributes. If any of them are
220
- // decorated with "item decorators", then use that function to transform
221
- // the item into a new set of items.
222
- let mut new_items = module_. items . clone ( ) ;
223
- for item in module_. items . iter ( ) {
224
- for attr in item. attrs . rev_iter ( ) {
225
- let mname = attr. name ( ) ;
226
-
227
- match fld. extsbox . find ( & intern ( mname. get ( ) ) ) {
228
- Some ( & ItemDecorator ( dec_fn) ) => {
229
- fld. cx . bt_push ( ExpnInfo {
230
- call_site : attr. span ,
231
- callee : NameAndSpan {
232
- name : mname. get ( ) . to_str ( ) ,
233
- format : MacroAttribute ,
234
- span : None
235
- }
236
- } ) ;
237
- dec_fn ( fld. cx , attr. span , attr. node . value , * item,
238
- |item| new_items. push ( item) ) ;
239
- fld. cx . bt_pop ( ) ;
240
- } ,
241
- _ => { } ,
242
- }
243
- }
244
- }
245
-
246
- ast:: Mod {
247
- items : new_items,
248
- ..module_
249
- }
250
- }
251
-
252
206
// eval $e with a new exts frame:
253
207
macro_rules! with_exts_frame (
254
208
( $extsboxexpr: expr, $macros_escape: expr, $e: expr) =>
@@ -263,7 +217,35 @@ macro_rules! with_exts_frame (
263
217
// When we enter a module, record it, for the sake of `module!`
264
218
pub fn expand_item ( it : @ast:: Item , fld : & mut MacroExpander )
265
219
-> SmallVector < @ast:: Item > {
266
- match it. node {
220
+ let mut decorator_items = SmallVector :: zero ( ) ;
221
+ for attr in it. attrs . rev_iter ( ) {
222
+ let mname = attr. name ( ) ;
223
+
224
+ match fld. extsbox . find ( & intern ( mname. get ( ) ) ) {
225
+ Some ( & ItemDecorator ( dec_fn) ) => {
226
+ fld. cx . bt_push ( ExpnInfo {
227
+ call_site : attr. span ,
228
+ callee : NameAndSpan {
229
+ name : mname. get ( ) . to_str ( ) ,
230
+ format : MacroAttribute ,
231
+ span : None
232
+ }
233
+ } ) ;
234
+ // we'd ideally decorator_items.push_all(expand_item(item, fld)),
235
+ // but that double-mut-borrows fld
236
+ dec_fn ( fld. cx , attr. span , attr. node . value , it,
237
+ |item| decorator_items. push ( item) ) ;
238
+ fld. cx . bt_pop ( ) ;
239
+ }
240
+ _ => { }
241
+ }
242
+ }
243
+
244
+ let decorator_items = decorator_items. move_iter ( )
245
+ . flat_map ( |item| expand_item ( item, fld) . move_iter ( ) )
246
+ . collect ( ) ;
247
+
248
+ let mut new_items = match it. node {
267
249
ast:: ItemMac ( ..) => expand_item_mac ( it, fld) ,
268
250
ast:: ItemMod ( _) | ast:: ItemForeignMod ( _) => {
269
251
fld. cx . mod_push ( it. ident ) ;
@@ -275,7 +257,10 @@ pub fn expand_item(it: @ast::Item, fld: &mut MacroExpander)
275
257
result
276
258
} ,
277
259
_ => noop_fold_item ( it, fld)
278
- }
260
+ } ;
261
+
262
+ new_items. push_all ( decorator_items) ;
263
+ new_items
279
264
}
280
265
281
266
// does this attribute list contain "macro_escape" ?
@@ -783,10 +768,6 @@ impl<'a> Folder for MacroExpander<'a> {
783
768
expand_expr ( expr, self )
784
769
}
785
770
786
- fn fold_mod ( & mut self , module : & ast:: Mod ) -> ast:: Mod {
787
- expand_mod_items ( module, self )
788
- }
789
-
790
771
fn fold_item ( & mut self , item : @ast:: Item ) -> SmallVector < @ast:: Item > {
791
772
expand_item ( item, self )
792
773
}
0 commit comments