pub ext: SyntaxExtension
}
-pub type ItemDecorator =
- fn(&mut ExtCtxt, Span, Gc<ast::MetaItem>, Gc<ast::Item>, |Gc<ast::Item>|);
+pub trait ItemDecorator {
+ fn expand(&self,
+ ecx: &mut ExtCtxt,
+ sp: Span,
+ meta_item: Gc<ast::MetaItem>,
+ item: Gc<ast::Item>,
+ push: |Gc<ast::Item>|);
+}
+
+impl ItemDecorator for fn(&mut ExtCtxt, Span, Gc<ast::MetaItem>, Gc<ast::Item>, |Gc<ast::Item>|) {
+ fn expand(&self,
+ ecx: &mut ExtCtxt,
+ sp: Span,
+ meta_item: Gc<ast::MetaItem>,
+ item: Gc<ast::Item>,
+ push: |Gc<ast::Item>|) {
+ (*self)(ecx, sp, meta_item, item, push)
+ }
+}
-pub type ItemModifier =
- fn(&mut ExtCtxt, Span, Gc<ast::MetaItem>, Gc<ast::Item>) -> Gc<ast::Item>;
+pub trait ItemModifier {
+ fn expand(&self,
+ ecx: &mut ExtCtxt,
+ span: Span,
+ meta_item: Gc<ast::MetaItem>,
+ item: Gc<ast::Item>)
+ -> Gc<ast::Item>;
+}
+
+impl ItemModifier for fn(&mut ExtCtxt, Span, Gc<ast::MetaItem>, Gc<ast::Item>) -> Gc<ast::Item> {
+ fn expand(&self,
+ ecx: &mut ExtCtxt,
+ span: Span,
+ meta_item: Gc<ast::MetaItem>,
+ item: Gc<ast::Item>)
+ -> Gc<ast::Item> {
+ (*self)(ecx, span, meta_item, item)
+ }
+}
pub struct BasicMacroExpander {
pub expander: MacroExpanderFn,
/// based upon it.
///
/// `#[deriving(...)]` is an `ItemDecorator`.
- ItemDecorator(ItemDecorator),
+ ItemDecorator(Box<ItemDecorator + 'static>),
/// A syntax extension that is attached to an item and modifies it
/// in-place.
- ItemModifier(ItemModifier),
+ ItemModifier(Box<ItemModifier + 'static>),
/// A normal, function-like syntax extension.
///
builtin_normal_expander(
ext::log_syntax::expand_syntax_ext));
syntax_expanders.insert(intern("deriving"),
- ItemDecorator(ext::deriving::expand_meta_deriving));
+ ItemDecorator(box ext::deriving::expand_meta_deriving));
// Quasi-quoting expanders
syntax_expanders.insert(intern("quote_tokens"),
match fld.cx.syntax_env.find(&intern(mname.get())) {
Some(rc) => match *rc {
- ItemDecorator(dec_fn) => {
+ ItemDecorator(ref dec) => {
attr::mark_used(attr);
fld.cx.bt_push(ExpnInfo {
// we'd ideally decorator_items.push_all(expand_item(item, fld)),
// but that double-mut-borrows fld
let mut items: SmallVector<Gc<ast::Item>> = SmallVector::zero();
- dec_fn(fld.cx, attr.span, attr.node.value, it,
- |item| items.push(item));
+ dec.expand(fld.cx, attr.span, attr.node.value, it, |item| items.push(item));
decorator_items.extend(items.move_iter()
.flat_map(|item| expand_item(item, fld).move_iter()));
match fld.cx.syntax_env.find(&intern(mname.get())) {
Some(rc) => match *rc {
- ItemModifier(dec_fn) => {
+ ItemModifier(ref mac) => {
attr::mark_used(attr);
fld.cx.bt_push(ExpnInfo {
call_site: attr.span,
span: None,
}
});
- it = dec_fn(fld.cx, attr.span, attr.node.value, it);
+ it = mac.expand(fld.cx, attr.span, attr.node.value, it);
fld.cx.bt_pop();
}
_ => unreachable!()