removed unneccessary SyntaxExpander structs

This commit is contained in:
John Clements
2013-05-28 14:53:38 -07:00
parent d8276e75f0
commit 431ede40df
3 changed files with 18 additions and 33 deletions

View File

@@ -22,8 +22,7 @@ use std::hashmap::HashMap;
// new-style macro! tt code: // new-style macro! tt code:
// //
// SyntaxExpanderTT, SyntaxExpanderTTItem, MacResult, // MacResult, NormalTT, IdentTT
// NormalTT, IdentTT
// //
// also note that ast::mac used to have a bunch of extraneous cases and // also note that ast::mac used to have a bunch of extraneous cases and
// is now probably a redundant AST node, can be merged with // is now probably a redundant AST node, can be merged with
@@ -40,21 +39,11 @@ pub type ItemDecorator = @fn(@ExtCtxt,
~[@ast::item]) ~[@ast::item])
-> ~[@ast::item]; -> ~[@ast::item];
pub struct SyntaxExpanderTT {
expander: SyntaxExpanderTTFun,
span: Option<Span>
}
pub type SyntaxExpanderTTFun = @fn(@ExtCtxt, pub type SyntaxExpanderTTFun = @fn(@ExtCtxt,
Span, Span,
&[ast::token_tree]) &[ast::token_tree])
-> MacResult; -> MacResult;
pub struct SyntaxExpanderTTItem {
expander: SyntaxExpanderTTItemFun,
span: Option<Span>
}
pub type SyntaxExpanderTTItemFun = @fn(@ExtCtxt, pub type SyntaxExpanderTTItemFun = @fn(@ExtCtxt,
Span, Span,
ast::Ident, ast::Ident,
@@ -76,7 +65,7 @@ pub enum SyntaxExtension {
ItemDecorator(ItemDecorator), ItemDecorator(ItemDecorator),
// Token-tree expanders // Token-tree expanders
NormalTT(SyntaxExpanderTT), NormalTT(SyntaxExpanderTTFun, Option<Span>),
// An IdentTT is a macro that has an // An IdentTT is a macro that has an
// identifier in between the name of the // identifier in between the name of the
@@ -86,7 +75,7 @@ pub enum SyntaxExtension {
// perhaps macro_rules! will lose its odd special identifier argument, // perhaps macro_rules! will lose its odd special identifier argument,
// and this can go away also // and this can go away also
IdentTT(SyntaxExpanderTTItem), IdentTT(SyntaxExpanderTTItemFun, Option<Span>),
} }
// The SyntaxEnv is the environment that's threaded through the expansion // The SyntaxEnv is the environment that's threaded through the expansion
@@ -121,11 +110,11 @@ type RenameList = ~[(ast::Ident,Name)];
pub fn syntax_expander_table() -> SyntaxEnv { pub fn syntax_expander_table() -> SyntaxEnv {
// utility function to simplify creating NormalTT syntax extensions // utility function to simplify creating NormalTT syntax extensions
fn builtin_normal_tt(f: SyntaxExpanderTTFun) -> @Transformer { fn builtin_normal_tt(f: SyntaxExpanderTTFun) -> @Transformer {
@SE(NormalTT(SyntaxExpanderTT{expander: f, span: None})) @SE(NormalTT(f, None))
} }
// utility function to simplify creating IdentTT syntax extensions // utility function to simplify creating IdentTT syntax extensions
fn builtin_item_tt(f: SyntaxExpanderTTItemFun) -> @Transformer { fn builtin_item_tt(f: SyntaxExpanderTTItemFun) -> @Transformer {
@SE(IdentTT(SyntaxExpanderTTItem{expander: f, span: None})) @SE(IdentTT(f, None))
} }
let mut syntax_expanders = HashMap::new(); let mut syntax_expanders = HashMap::new();
// NB identifier starts with space, and can't conflict with legal idents // NB identifier starts with space, and can't conflict with legal idents

View File

@@ -58,19 +58,16 @@ pub fn expand_expr(extsbox: @mut SyntaxEnv,
pth.span, pth.span,
fmt!("macro undefined: '%s'", extnamestr)) fmt!("macro undefined: '%s'", extnamestr))
} }
Some(@SE(NormalTT(SyntaxExpanderTT{ Some(@SE(NormalTT(expandfun, exp_span))) => {
expander: exp,
span: exp_sp
}))) => {
cx.bt_push(ExpnInfo { cx.bt_push(ExpnInfo {
call_site: s, call_site: s,
callee: NameAndSpan { callee: NameAndSpan {
name: extnamestr, name: extnamestr,
span: exp_sp, span: exp_span,
}, },
}); });
let expanded = match exp(cx, mac.span, *tts) { let expanded = match expandfun(cx, mac.span, *tts) {
MRExpr(e) => e, MRExpr(e) => e,
MRAny(expr_maker,_,_) => expr_maker(), MRAny(expr_maker,_,_) => expr_maker(),
_ => { _ => {
@@ -379,7 +376,7 @@ pub fn expand_item_mac(extsbox: @mut SyntaxEnv,
None => cx.span_fatal(pth.span, None => cx.span_fatal(pth.span,
fmt!("macro undefined: '%s!'", extnamestr)), fmt!("macro undefined: '%s!'", extnamestr)),
Some(@SE(NormalTT(ref expand))) => { Some(@SE(NormalTT(expander, span))) => {
if it.ident != parse::token::special_idents::invalid { if it.ident != parse::token::special_idents::invalid {
cx.span_fatal(pth.span, cx.span_fatal(pth.span,
fmt!("macro %s! expects no ident argument, \ fmt!("macro %s! expects no ident argument, \
@@ -390,12 +387,12 @@ pub fn expand_item_mac(extsbox: @mut SyntaxEnv,
call_site: it.span, call_site: it.span,
callee: NameAndSpan { callee: NameAndSpan {
name: extnamestr, name: extnamestr,
span: expand.span span: span
} }
}); });
((*expand).expander)(cx, it.span, tts) expander(cx, it.span, tts)
} }
Some(@SE(IdentTT(ref expand))) => { Some(@SE(IdentTT(expander, span))) => {
if it.ident == parse::token::special_idents::invalid { if it.ident == parse::token::special_idents::invalid {
cx.span_fatal(pth.span, cx.span_fatal(pth.span,
fmt!("macro %s! expects an ident argument", fmt!("macro %s! expects an ident argument",
@@ -405,10 +402,10 @@ pub fn expand_item_mac(extsbox: @mut SyntaxEnv,
call_site: it.span, call_site: it.span,
callee: NameAndSpan { callee: NameAndSpan {
name: extnamestr, name: extnamestr,
span: expand.span span: span
} }
}); });
((*expand).expander)(cx, it.span, it.ident, tts) expander(cx, it.span, it.ident, tts)
} }
_ => cx.span_fatal( _ => cx.span_fatal(
it.span, fmt!("%s! is not legal in item position", extnamestr)) it.span, fmt!("%s! is not legal in item position", extnamestr))
@@ -476,13 +473,12 @@ pub fn expand_stmt(extsbox: @mut SyntaxEnv,
None => None =>
cx.span_fatal(pth.span, fmt!("macro undefined: '%s'", extnamestr)), cx.span_fatal(pth.span, fmt!("macro undefined: '%s'", extnamestr)),
Some(@SE(NormalTT( Some(@SE(NormalTT(expandfun, exp_span))) => {
SyntaxExpanderTT{expander: exp, span: exp_sp}))) => {
cx.bt_push(ExpnInfo { cx.bt_push(ExpnInfo {
call_site: sp, call_site: sp,
callee: NameAndSpan { name: extnamestr, span: exp_sp } callee: NameAndSpan { name: extnamestr, span: exp_span }
}); });
let expanded = match exp(cx, mac.span, tts) { let expanded = match expandfun(cx, mac.span, tts) {
MRExpr(e) => MRExpr(e) =>
@codemap::Spanned { node: StmtExpr(e, cx.next_id()), @codemap::Spanned { node: StmtExpr(e, cx.next_id()),
span: e.span}, span: e.span},

View File

@@ -149,6 +149,6 @@ pub fn add_new_extension(cx: @ExtCtxt,
return MRDef(MacroDef{ return MRDef(MacroDef{
name: ident_to_str(&name), name: ident_to_str(&name),
ext: NormalTT(base::SyntaxExpanderTT{expander: exp, span: Some(sp)}) ext: NormalTT(exp, Some(sp))
}); });
} }