auto merge of #11332 : sfackler/rust/de-at-se, r=huonw
This is necessary for #11151 to make sure dtors run before the libraries are unloaded.
This commit is contained in:
commit
bae091e517
3 changed files with 60 additions and 61 deletions
|
@ -138,7 +138,7 @@ pub enum SyntaxExtension {
|
||||||
ItemDecorator(ItemDecorator),
|
ItemDecorator(ItemDecorator),
|
||||||
|
|
||||||
// Token-tree expanders
|
// Token-tree expanders
|
||||||
NormalTT(@SyntaxExpanderTTTrait, Option<Span>),
|
NormalTT(~SyntaxExpanderTTTrait:'static, 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
|
||||||
|
@ -148,7 +148,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(@SyntaxExpanderTTItemTrait, Option<Span>),
|
IdentTT(~SyntaxExpanderTTItemTrait:'static, Option<Span>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -182,20 +182,20 @@ 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_no_ctxt(f: SyntaxExpanderTTFunNoCtxt)
|
fn builtin_normal_tt_no_ctxt(f: SyntaxExpanderTTFunNoCtxt)
|
||||||
-> SyntaxExtension {
|
-> SyntaxExtension {
|
||||||
NormalTT(@SyntaxExpanderTT{
|
NormalTT(~SyntaxExpanderTT{
|
||||||
expander: SyntaxExpanderTTExpanderWithoutContext(f),
|
expander: SyntaxExpanderTTExpanderWithoutContext(f),
|
||||||
span: None,
|
span: None,
|
||||||
} as @SyntaxExpanderTTTrait,
|
},
|
||||||
None)
|
None)
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut syntax_expanders = MapChain::new();
|
let mut syntax_expanders = MapChain::new();
|
||||||
syntax_expanders.insert(intern(&"macro_rules"),
|
syntax_expanders.insert(intern(&"macro_rules"),
|
||||||
IdentTT(@SyntaxExpanderTTItem {
|
IdentTT(~SyntaxExpanderTTItem {
|
||||||
expander: SyntaxExpanderTTItemExpanderWithContext(
|
expander: SyntaxExpanderTTItemExpanderWithContext(
|
||||||
ext::tt::macro_rules::add_new_extension),
|
ext::tt::macro_rules::add_new_extension),
|
||||||
span: None,
|
span: None,
|
||||||
} as @SyntaxExpanderTTItemTrait,
|
},
|
||||||
None));
|
None));
|
||||||
syntax_expanders.insert(intern(&"fmt"),
|
syntax_expanders.insert(intern(&"fmt"),
|
||||||
builtin_normal_tt_no_ctxt(
|
builtin_normal_tt_no_ctxt(
|
||||||
|
|
|
@ -53,13 +53,13 @@ pub fn expand_expr(e: @ast::Expr, fld: &mut MacroExpander) -> @ast::Expr {
|
||||||
let extname = &pth.segments[0].identifier;
|
let extname = &pth.segments[0].identifier;
|
||||||
let extnamestr = ident_to_str(extname);
|
let extnamestr = ident_to_str(extname);
|
||||||
// leaving explicit deref here to highlight unbox op:
|
// leaving explicit deref here to highlight unbox op:
|
||||||
match fld.extsbox.find(&extname.name) {
|
let marked_after = match fld.extsbox.find(&extname.name) {
|
||||||
None => {
|
None => {
|
||||||
fld.cx.span_fatal(
|
fld.cx.span_fatal(
|
||||||
pth.span,
|
pth.span,
|
||||||
format!("macro undefined: '{}'", extnamestr))
|
format!("macro undefined: '{}'", extnamestr))
|
||||||
}
|
}
|
||||||
Some(&NormalTT(expandfun, exp_span)) => {
|
Some(&NormalTT(ref expandfun, exp_span)) => {
|
||||||
fld.cx.bt_push(ExpnInfo {
|
fld.cx.bt_push(ExpnInfo {
|
||||||
call_site: e.span,
|
call_site: e.span,
|
||||||
callee: NameAndSpan {
|
callee: NameAndSpan {
|
||||||
|
@ -79,8 +79,7 @@ pub fn expand_expr(e: @ast::Expr, fld: &mut MacroExpander) -> @ast::Expr {
|
||||||
// the macro.
|
// the macro.
|
||||||
let mac_span = original_span(fld.cx);
|
let mac_span = original_span(fld.cx);
|
||||||
|
|
||||||
let expanded =
|
let expanded = match expandfun.expand(fld.cx,
|
||||||
match expandfun.expand(fld.cx,
|
|
||||||
mac_span.call_site,
|
mac_span.call_site,
|
||||||
marked_before,
|
marked_before,
|
||||||
marked_ctxt) {
|
marked_ctxt) {
|
||||||
|
@ -96,8 +95,17 @@ pub fn expand_expr(e: @ast::Expr, fld: &mut MacroExpander) -> @ast::Expr {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// mark after:
|
// mark after:
|
||||||
let marked_after = mark_expr(expanded,fm);
|
mark_expr(expanded,fm)
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
fld.cx.span_fatal(
|
||||||
|
pth.span,
|
||||||
|
format!("'{}' is not a tt-style macro", extnamestr)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Keep going, outside-in.
|
// Keep going, outside-in.
|
||||||
//
|
//
|
||||||
|
@ -113,14 +121,6 @@ pub fn expand_expr(e: @ast::Expr, fld: &mut MacroExpander) -> @ast::Expr {
|
||||||
span: e.span,
|
span: e.span,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
|
||||||
fld.cx.span_fatal(
|
|
||||||
pth.span,
|
|
||||||
format!("'{}' is not a tt-style macro", extnamestr)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -301,7 +301,7 @@ pub fn expand_item_mac(it: @ast::item, fld: &mut MacroExpander)
|
||||||
None => fld.cx.span_fatal(pth.span,
|
None => fld.cx.span_fatal(pth.span,
|
||||||
format!("macro undefined: '{}!'", extnamestr)),
|
format!("macro undefined: '{}!'", extnamestr)),
|
||||||
|
|
||||||
Some(&NormalTT(expander, span)) => {
|
Some(&NormalTT(ref expander, span)) => {
|
||||||
if it.ident.name != parse::token::special_idents::invalid.name {
|
if it.ident.name != parse::token::special_idents::invalid.name {
|
||||||
fld.cx.span_fatal(pth.span,
|
fld.cx.span_fatal(pth.span,
|
||||||
format!("macro {}! expects no ident argument, \
|
format!("macro {}! expects no ident argument, \
|
||||||
|
@ -321,7 +321,7 @@ pub fn expand_item_mac(it: @ast::item, fld: &mut MacroExpander)
|
||||||
let marked_ctxt = new_mark(fm,ctxt);
|
let marked_ctxt = new_mark(fm,ctxt);
|
||||||
expander.expand(fld.cx, it.span, marked_before, marked_ctxt)
|
expander.expand(fld.cx, it.span, marked_before, marked_ctxt)
|
||||||
}
|
}
|
||||||
Some(&IdentTT(expander, span)) => {
|
Some(&IdentTT(ref expander, span)) => {
|
||||||
if it.ident.name == parse::token::special_idents::invalid.name {
|
if it.ident.name == parse::token::special_idents::invalid.name {
|
||||||
fld.cx.span_fatal(pth.span,
|
fld.cx.span_fatal(pth.span,
|
||||||
format!("macro {}! expects an ident argument",
|
format!("macro {}! expects an ident argument",
|
||||||
|
@ -361,10 +361,10 @@ pub fn expand_item_mac(it: @ast::item, fld: &mut MacroExpander)
|
||||||
.flat_map(|i| fld.fold_item(i).move_iter())
|
.flat_map(|i| fld.fold_item(i).move_iter())
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
MRDef(ref mdef) => {
|
MRDef(MacroDef { name, ext }) => {
|
||||||
// yikes... no idea how to apply the mark to this. I'm afraid
|
// yikes... no idea how to apply the mark to this. I'm afraid
|
||||||
// we're going to have to wait-and-see on this one.
|
// we're going to have to wait-and-see on this one.
|
||||||
fld.extsbox.insert(intern(mdef.name), (*mdef).ext);
|
fld.extsbox.insert(intern(name), ext);
|
||||||
SmallVector::zero()
|
SmallVector::zero()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -392,12 +392,12 @@ pub fn expand_stmt(s: &Stmt, fld: &mut MacroExpander) -> SmallVector<@Stmt> {
|
||||||
}
|
}
|
||||||
let extname = &pth.segments[0].identifier;
|
let extname = &pth.segments[0].identifier;
|
||||||
let extnamestr = ident_to_str(extname);
|
let extnamestr = ident_to_str(extname);
|
||||||
let fully_expanded: SmallVector<@Stmt> = match fld.extsbox.find(&extname.name) {
|
let marked_after = match fld.extsbox.find(&extname.name) {
|
||||||
None => {
|
None => {
|
||||||
fld.cx.span_fatal(pth.span, format!("macro undefined: '{}'", extnamestr))
|
fld.cx.span_fatal(pth.span, format!("macro undefined: '{}'", extnamestr))
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(&NormalTT(expandfun, exp_span)) => {
|
Some(&NormalTT(ref expandfun, exp_span)) => {
|
||||||
fld.cx.bt_push(ExpnInfo {
|
fld.cx.bt_push(ExpnInfo {
|
||||||
call_site: s.span,
|
call_site: s.span,
|
||||||
callee: NameAndSpan {
|
callee: NameAndSpan {
|
||||||
|
@ -430,18 +430,8 @@ pub fn expand_stmt(s: &Stmt, fld: &mut MacroExpander) -> SmallVector<@Stmt> {
|
||||||
pth.span,
|
pth.span,
|
||||||
format!("non-stmt macro in stmt pos: {}", extnamestr))
|
format!("non-stmt macro in stmt pos: {}", extnamestr))
|
||||||
};
|
};
|
||||||
let marked_after = mark_stmt(expanded,fm);
|
|
||||||
|
|
||||||
// Keep going, outside-in.
|
mark_stmt(expanded,fm)
|
||||||
let fully_expanded = fld.fold_stmt(marked_after);
|
|
||||||
if fully_expanded.is_empty() {
|
|
||||||
fld.cx.span_fatal(pth.span,
|
|
||||||
"macro didn't expand to a statement");
|
|
||||||
}
|
|
||||||
fld.cx.bt_pop();
|
|
||||||
fully_expanded.move_iter()
|
|
||||||
.map(|s| @Spanned { span: s.span, node: s.node.clone() })
|
|
||||||
.collect()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
|
@ -451,6 +441,17 @@ pub fn expand_stmt(s: &Stmt, fld: &mut MacroExpander) -> SmallVector<@Stmt> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Keep going, outside-in.
|
||||||
|
let fully_expanded = fld.fold_stmt(marked_after);
|
||||||
|
if fully_expanded.is_empty() {
|
||||||
|
fld.cx.span_fatal(pth.span,
|
||||||
|
"macro didn't expand to a statement");
|
||||||
|
}
|
||||||
|
fld.cx.bt_pop();
|
||||||
|
let fully_expanded: SmallVector<@Stmt> = fully_expanded.move_iter()
|
||||||
|
.map(|s| @Spanned { span: s.span, node: s.node.clone() })
|
||||||
|
.collect();
|
||||||
|
|
||||||
fully_expanded.move_iter().map(|s| {
|
fully_expanded.move_iter().map(|s| {
|
||||||
match s.node {
|
match s.node {
|
||||||
StmtExpr(e, stmt_id) if semi => {
|
StmtExpr(e, stmt_id) if semi => {
|
||||||
|
@ -1109,10 +1110,8 @@ mod test {
|
||||||
use codemap::Spanned;
|
use codemap::Spanned;
|
||||||
use fold;
|
use fold;
|
||||||
use parse;
|
use parse;
|
||||||
use parse::token::{fresh_mark, gensym, intern, get_ident_interner, ident_to_str};
|
use parse::token::{fresh_mark, gensym, intern, ident_to_str};
|
||||||
use parse::token;
|
use parse::token;
|
||||||
use print::pprust;
|
|
||||||
use std;
|
|
||||||
use util::parser_testing::{string_to_crate, string_to_crate_and_sess};
|
use util::parser_testing::{string_to_crate, string_to_crate_and_sess};
|
||||||
use util::parser_testing::{string_to_pat, string_to_tts, strs_to_idents};
|
use util::parser_testing::{string_to_pat, string_to_tts, strs_to_idents};
|
||||||
use visit;
|
use visit;
|
||||||
|
|
|
@ -225,11 +225,11 @@ pub fn add_new_extension(cx: &mut ExtCtxt,
|
||||||
_ => cx.span_bug(sp, "wrong-structured rhs")
|
_ => cx.span_bug(sp, "wrong-structured rhs")
|
||||||
};
|
};
|
||||||
|
|
||||||
let exp = @MacroRulesSyntaxExpanderTTFun {
|
let exp = ~MacroRulesSyntaxExpanderTTFun {
|
||||||
name: name,
|
name: name,
|
||||||
lhses: lhses,
|
lhses: lhses,
|
||||||
rhses: rhses,
|
rhses: rhses,
|
||||||
} as @SyntaxExpanderTTTrait;
|
};
|
||||||
|
|
||||||
return MRDef(MacroDef {
|
return MRDef(MacroDef {
|
||||||
name: ident_to_str(&name),
|
name: ident_to_str(&name),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue