@@ -39,15 +39,44 @@ pub struct MacroDef {
3939 pub ext : SyntaxExtension
4040}
4141
42- pub type ItemDecorator =
43- fn ( & mut ExtCtxt , Span , Gc < ast:: MetaItem > , Gc < ast:: Item > , |Gc < ast:: Item > |) ;
42+ pub trait ItemDecorator {
43+ fn expand ( & self ,
44+ ecx : & mut ExtCtxt ,
45+ sp : Span ,
46+ meta_item : Gc < ast:: MetaItem > ,
47+ item : Gc < ast:: Item > ,
48+ push: |Gc < ast:: Item > |) ;
49+ }
4450
45- pub type ItemModifier =
46- fn ( & mut ExtCtxt , Span , Gc < ast:: MetaItem > , Gc < ast:: Item > ) -> Gc < ast:: Item > ;
51+ impl ItemDecorator for fn ( & mut ExtCtxt , Span , Gc < ast:: MetaItem > , Gc < ast:: Item > , |Gc < ast:: Item > |) {
52+ fn expand ( & self ,
53+ ecx : & mut ExtCtxt ,
54+ sp : Span ,
55+ meta_item : Gc < ast:: MetaItem > ,
56+ item : Gc < ast:: Item > ,
57+ push: |Gc < ast:: Item > |) {
58+ ( * self ) ( ecx, sp, meta_item, item, push)
59+ }
60+ }
4761
48- pub struct BasicMacroExpander {
49- pub expander : MacroExpanderFn ,
50- pub span : Option < Span >
62+ pub trait ItemModifier {
63+ fn expand ( & self ,
64+ ecx : & mut ExtCtxt ,
65+ span : Span ,
66+ meta_item : Gc < ast:: MetaItem > ,
67+ item : Gc < ast:: Item > )
68+ -> Gc < ast:: Item > ;
69+ }
70+
71+ impl ItemModifier for fn ( & mut ExtCtxt , Span , Gc < ast:: MetaItem > , Gc < ast:: Item > ) -> Gc < ast:: Item > {
72+ fn expand ( & self ,
73+ ecx : & mut ExtCtxt ,
74+ span : Span ,
75+ meta_item : Gc < ast:: MetaItem > ,
76+ item : Gc < ast:: Item > )
77+ -> Gc < ast:: Item > {
78+ ( * self ) ( ecx, span, meta_item, item)
79+ }
5180}
5281
5382/// Represents a thing that maps token trees to Macro Results
@@ -60,24 +89,18 @@ pub trait TTMacroExpander {
6089}
6190
6291pub type MacroExpanderFn =
63- fn <' cx >( ecx : & ' cx mut ExtCtxt , span : codemap:: Span , token_tree : & [ ast:: TokenTree ] )
64- -> Box < MacResult +' cx > ;
92+ fn <' cx >( & ' cx mut ExtCtxt , Span , & [ ast:: TokenTree ] ) -> Box < MacResult +' cx > ;
6593
66- impl TTMacroExpander for BasicMacroExpander {
94+ impl TTMacroExpander for MacroExpanderFn {
6795 fn expand < ' cx > ( & self ,
6896 ecx : & ' cx mut ExtCtxt ,
6997 span : Span ,
7098 token_tree : & [ ast:: TokenTree ] )
7199 -> Box < MacResult +' cx > {
72- ( self . expander ) ( ecx , span , token_tree )
100+ ( * self) ( ecx , span , token_tree )
73101 }
74102}
75103
76- pub struct BasicIdentMacroExpander {
77- pub expander : IdentMacroExpanderFn ,
78- pub span : Option < Span >
79- }
80-
81104pub trait IdentMacroExpander {
82105 fn expand < ' cx > ( & self ,
83106 cx : & ' cx mut ExtCtxt ,
@@ -87,20 +110,20 @@ pub trait IdentMacroExpander {
87110 -> Box < MacResult +' cx > ;
88111}
89112
90- impl IdentMacroExpander for BasicIdentMacroExpander {
113+ pub type IdentMacroExpanderFn =
114+ fn <' cx >( & ' cx mut ExtCtxt , Span , ast:: Ident , Vec < ast:: TokenTree > ) -> Box < MacResult +' cx > ;
115+
116+ impl IdentMacroExpander for IdentMacroExpanderFn {
91117 fn expand < ' cx > ( & self ,
92118 cx : & ' cx mut ExtCtxt ,
93119 sp : Span ,
94120 ident : ast:: Ident ,
95121 token_tree : Vec < ast:: TokenTree > )
96122 -> Box < MacResult +' cx > {
97- ( self . expander ) ( cx , sp , ident , token_tree )
123+ ( * self) ( cx , sp , ident , token_tree )
98124 }
99125}
100126
101- pub type IdentMacroExpanderFn =
102- fn <' cx >( & ' cx mut ExtCtxt , Span , ast:: Ident , Vec < ast:: TokenTree > ) -> Box < MacResult +' cx > ;
103-
104127/// The result of a macro expansion. The return values of the various
105128 /// methods are spliced into the AST at the callsite of the macro ( or
106129/// just into the compiler's internal macro table, for `make_def`).
@@ -281,11 +304,11 @@ pub enum SyntaxExtension {
281304 /// based upon it.
282305 ///
283306 /// `#[deriving(...)]` is an `ItemDecorator`.
284- ItemDecorator ( ItemDecorator ) ,
307+ ItemDecorator ( Box < ItemDecorator + ' static > ) ,
285308
286309 /// A syntax extension that is attached to an item and modifies it
287310 /// in-place.
288- ItemModifier ( ItemModifier ) ,
311+ ItemModifier ( Box < ItemModifier + ' static > ) ,
289312
290313 /// A normal, function-like syntax extension.
291314 ///
@@ -329,20 +352,12 @@ impl BlockInfo {
329352fn initial_syntax_expander_table ( ) -> SyntaxEnv {
330353 // utility function to simplify creating NormalTT syntax extensions
331354 fn builtin_normal_expander ( f : MacroExpanderFn ) -> SyntaxExtension {
332- NormalTT ( box BasicMacroExpander {
333- expander : f,
334- span : None ,
335- } ,
336- None )
355+ NormalTT ( box f, None )
337356 }
338357
339358 let mut syntax_expanders = SyntaxEnv :: new ( ) ;
340359 syntax_expanders. insert ( intern( "macro_rules" ) ,
341- LetSyntaxTT ( box BasicIdentMacroExpander {
342- expander : ext:: tt:: macro_rules:: add_new_extension,
343- span : None ,
344- } ,
345- None ) ) ;
360+ LetSyntaxTT ( box ext:: tt:: macro_rules:: add_new_extension , None ) ) ;
346361 syntax_expanders. insert ( intern( "fmt" ) ,
347362 builtin_normal_expander (
348363 ext:: fmt:: expand_syntax_ext ) ) ;
@@ -371,7 +386,7 @@ fn initial_syntax_expander_table() -> SyntaxEnv {
371386 builtin_normal_expander (
372387 ext:: log_syntax:: expand_syntax_ext ) ) ;
373388 syntax_expanders. insert ( intern( "deriving" ) ,
374- ItemDecorator ( ext:: deriving:: expand_meta_deriving) ) ;
389+ ItemDecorator ( box ext:: deriving:: expand_meta_deriving ) ) ;
375390
376391 // Quasi-quoting expanders
377392 syntax_expanders . insert( intern( "quote_tokens" ) ,
0 commit comments