Skip to content

Commit

Permalink
Recursively expand items, and keep expansion stack, per Paul's code r…
Browse files Browse the repository at this point in the history
…eview comments.
  • Loading branch information
eholk committed Jul 6, 2012
1 parent d09bcc0 commit 84434bc
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ fn expand_item(exts: hashmap<str, syntax_extension>,
};
let it = alt it.node {
ast::item_mac(*) {
expand_item_mac(exts, cx, it)
expand_item_mac(exts, cx, it, fld)
}
_ { it }
};
Expand All @@ -150,7 +150,8 @@ fn expand_item(exts: hashmap<str, syntax_extension>,
}

fn expand_item_mac(exts: hashmap<str, syntax_extension>,
cx: ext_ctxt, &&it: @ast::item) -> @ast::item {
cx: ext_ctxt, &&it: @ast::item,
fld: ast_fold) -> @ast::item {
alt it.node {
item_mac({node: mac_invoc_tt(pth, tt), span}) {
let extname = pth.idents[0];
Expand All @@ -160,7 +161,13 @@ fn expand_item_mac(exts: hashmap<str, syntax_extension>,
#fmt("macro undefined: '%s'", *extname))
}
some(item_tt(expand)) {
expand.expander(cx, it.span, it.ident, tt)
cx.bt_push(expanded_from({call_site: it.span,
callie: {name: *extname,
span: expand.span}}));
let it = fld.fold_item(
expand.expander(cx, it.span, it.ident, tt));
cx.bt_pop();
ret it
}
_ { cx.span_fatal(it.span,
#fmt("%s is not a legal here", *extname)) }
Expand Down

0 comments on commit 84434bc

Please sign in to comment.