use visit;
use visit::Visitor;
-use std::gc::Gc;
-
enum Either<L,R> {
Left(L),
Right(R)
// be the root of the call stack. That's the most
// relevant span and it's the actual invocation of
// the macro.
- let mac_span = original_span(fld.cx);
+ let mac_span = fld.cx.original_span();
let opt_parsed = {
let expanded = expandfun.expand(fld.cx,
- mac_span.call_site,
+ mac_span,
marked_before.as_slice());
parse_thunk(expanded)
};
match fld.cx.syntax_env.find(&intern(mname.get())) {
Some(rc) => match *rc {
- ItemDecorator(ref dec) => {
+ Decorator(ref dec) => {
attr::mark_used(attr);
fld.cx.bt_push(ExpnInfo {
let mut items: SmallVector<P<ast::Item>> = SmallVector::zero();
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()));
+ decorator_items.extend(items.into_iter()
+ .flat_map(|item| expand_item(item, fld).into_iter()));
fld.cx.bt_pop();
}
// partition the attributes into ItemModifiers and others
let (modifiers, other_attrs) = it.attrs.partitioned(|attr| {
match fld.cx.syntax_env.find(&intern(attr.name().get())) {
- Some(rc) => match *rc { ItemModifier(_) => true, _ => false },
+ Some(rc) => match *rc { Modifier(_) => true, _ => false },
_ => false
}
});
match fld.cx.syntax_env.find(&intern(mname.get())) {
Some(rc) => match *rc {
- ItemModifier(ref mac) => {
+ Modifier(ref mac) => {
attr::mark_used(attr);
fld.cx.bt_push(ExpnInfo {
call_site: attr.span,
SmallVector::zero()
}
Right(Some(items)) => {
- items.move_iter()
+ items.into_iter()
.map(|i| mark_item(i, fm))
- .flat_map(|i| fld.fold_item(i).move_iter())
+ .flat_map(|i| fld.fold_item(i).into_iter())
.collect()
}
Right(None) => {
fld.cx.bt_pop();
if semi {
- fully_expanded.move_iter().map(|s| s.map(|Spanned {node, span}| {
+ fully_expanded.into_iter().map(|s| s.map(|Spanned {node, span}| {
Spanned {
node: match node {
StmtExpr(e, stmt_id) => StmtSemi(e, stmt_id),
// all of the pats must have the same set of bindings, so use the
// first one to extract them and generate new names:
let idents = pattern_bindings(&**expanded_pats.get(0));
- let new_renames = idents.move_iter().map(|id| (id, fresh_name(&id))).collect();
+ let new_renames = idents.into_iter().map(|id| (id, fresh_name(&id))).collect();
// apply the renaming, but only to the PatIdents:
let mut rename_pats_fld = PatIdentRenamer{renames:&new_renames};
let rewritten_pats = expanded_pats.move_map(|pat| rename_pats_fld.fold_pat(pat));
// expand the elements of a block.
pub fn expand_block_elts(b: P<Block>, fld: &mut MacroExpander) -> P<Block> {
b.map(|Block {id, view_items, stmts, expr, rules, span}| {
- let new_view_items = view_items.move_iter().map(|x| fld.fold_view_item(x)).collect();
- let new_stmts = stmts.move_iter().flat_map(|x| {
+ let new_view_items = view_items.into_iter().map(|x| fld.fold_view_item(x)).collect();
+ let new_stmts = stmts.into_iter().flat_map(|x| {
// perform all pending renames
let renamed_stmt = {
let pending_renames = &mut fld.cx.syntax_env.info().pending_renames;
rename_fld.fold_stmt(x).expect_one("rename_fold didn't return one value")
};
// expand macros in the statement
- fld.fold_stmt(renamed_stmt).move_iter()
+ fld.fold_stmt(renamed_stmt).into_iter()
}).collect();
let new_expr = expr.map(|x| {
let expr = {
let fm = fresh_mark();
let marked_before = mark_tts(tts.as_slice(), fm);
- let mac_span = original_span(fld.cx);
+ let mac_span = fld.cx.original_span();
let expanded = match expander.expand(fld.cx,
- mac_span.call_site,
+ mac_span,
marked_before.as_slice()).make_pat() {
Some(e) => e,
None => {
};
// expand again if necessary
- new_methods.move_iter().flat_map(|m| fld.fold_method(m).move_iter()).collect()
+ new_methods.into_iter().flat_map(|m| fld.fold_method(m).into_iter()).collect()
}
})
}
Span {
lo: sp.lo,
hi: sp.hi,
- expn_info: cx.backtrace(),
+ expn_id: cx.backtrace(),
}
}
cx: &mut cx,
};
- for ExportedMacros { crate_name, macros } in imported_macros.move_iter() {
+ for ExportedMacros { crate_name, macros } in imported_macros.into_iter() {
let name = format!("<{} macros>", token::get_ident(crate_name))
.into_string();
- for source in macros.move_iter() {
+ for source in macros.into_iter() {
let item = parse::parse_item_from_source_str(name.clone(),
source,
expander.cx.cfg(),
}
}
- for (name, extension) in user_exts.move_iter() {
+ for (name, extension) in user_exts.into_iter() {
expander.cx.syntax_env.insert(name, extension);
}
.expect_one("marking an item didn't return exactly one method")
}
-fn original_span(cx: &ExtCtxt) -> Gc<codemap::ExpnInfo> {
- let mut relevant_info = cx.backtrace();
- let mut einfo = relevant_info.unwrap();
- loop {
- match relevant_info {
- None => { break }
- Some(e) => {
- einfo = e;
- relevant_info = einfo.call_site.expn_info;
- }
- }
- }
- return einfo;
-}
-
/// Check that there are no macro invocations left in the AST:
pub fn check_for_macros(sess: &parse::ParseSess, krate: &ast::Crate) {
visit::walk_crate(&mut MacroExterminator{sess:sess}, krate);
use fold::Folder;
use parse;
use parse::token;
+ use ptr::P;
use util::parser_testing::{string_to_parser};
use util::parser_testing::{string_to_pat, string_to_crate, strs_to_idents};
use visit;
let attr1 = make_dummy_attr ("foo");
let attr2 = make_dummy_attr ("bar");
let escape_attr = make_dummy_attr ("macro_escape");
- let attrs1 = vec!(attr1, escape_attr, attr2);
+ let attrs1 = vec!(attr1.clone(), escape_attr, attr2.clone());
assert_eq!(contains_macro_escape(attrs1.as_slice()),true);
let attrs2 = vec!(attr1,attr2);
assert_eq!(contains_macro_escape(attrs2.as_slice()),false);