auto merge of #11168 : sfackler/rust/de-at-extctxt, r=alexcrichton
* Pass `&ExtCtxt` instead of `@ExtCtxt`. * Stop passing duplicate parameters around in `expand`. * Make `ast_fold` methods take `&mut self`. After these, it should be possible to remove the `@mut` boxes from `ExtCtxt` altogether, though #11167 is doing some of that so I'm holding off on that for now. This will probably conflict with that PR, so I'm guessing that one will have to be rebased on top of the other. r? @pcwalton
This commit is contained in:
commit
adc5eefa23
|
@ -18,14 +18,14 @@ struct NodeIdAssigner {
|
|||
}
|
||||
|
||||
impl ast_fold for NodeIdAssigner {
|
||||
fn new_id(&self, old_id: ast::NodeId) -> ast::NodeId {
|
||||
fn new_id(&mut self, old_id: ast::NodeId) -> ast::NodeId {
|
||||
assert_eq!(old_id, ast::DUMMY_NODE_ID);
|
||||
self.sess.next_node_id()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn assign_node_ids(sess: Session, crate: ast::Crate) -> ast::Crate {
|
||||
let fold = NodeIdAssigner {
|
||||
let mut fold = NodeIdAssigner {
|
||||
sess: sess,
|
||||
};
|
||||
fold.fold_crate(crate)
|
||||
|
|
|
@ -24,17 +24,17 @@ pub fn strip_unconfigured_items(crate: ast::Crate) -> ast::Crate {
|
|||
}
|
||||
|
||||
impl<'a> fold::ast_fold for Context<'a> {
|
||||
fn fold_mod(&self, module: &ast::_mod) -> ast::_mod {
|
||||
fn fold_mod(&mut self, module: &ast::_mod) -> ast::_mod {
|
||||
fold_mod(self, module)
|
||||
}
|
||||
fn fold_block(&self, block: ast::P<ast::Block>) -> ast::P<ast::Block> {
|
||||
fn fold_block(&mut self, block: ast::P<ast::Block>) -> ast::P<ast::Block> {
|
||||
fold_block(self, block)
|
||||
}
|
||||
fn fold_foreign_mod(&self, foreign_module: &ast::foreign_mod)
|
||||
fn fold_foreign_mod(&mut self, foreign_module: &ast::foreign_mod)
|
||||
-> ast::foreign_mod {
|
||||
fold_foreign_mod(self, foreign_module)
|
||||
}
|
||||
fn fold_item_underscore(&self, item: &ast::item_) -> ast::item_ {
|
||||
fn fold_item_underscore(&mut self, item: &ast::item_) -> ast::item_ {
|
||||
fold_item_underscore(self, item)
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ impl<'a> fold::ast_fold for Context<'a> {
|
|||
pub fn strip_items(crate: ast::Crate,
|
||||
in_cfg: |attrs: &[ast::Attribute]| -> bool)
|
||||
-> ast::Crate {
|
||||
let ctxt = Context {
|
||||
let mut ctxt = Context {
|
||||
in_cfg: in_cfg,
|
||||
};
|
||||
ctxt.fold_crate(crate)
|
||||
|
@ -57,7 +57,7 @@ fn filter_view_item<'r>(cx: &Context, view_item: &'r ast::view_item)
|
|||
}
|
||||
}
|
||||
|
||||
fn fold_mod(cx: &Context, m: &ast::_mod) -> ast::_mod {
|
||||
fn fold_mod(cx: &mut Context, m: &ast::_mod) -> ast::_mod {
|
||||
let filtered_items = m.items.iter()
|
||||
.filter(|&a| item_in_cfg(cx, *a))
|
||||
.flat_map(|&x| cx.fold_item(x).move_iter())
|
||||
|
@ -80,7 +80,7 @@ fn filter_foreign_item(cx: &Context, item: @ast::foreign_item)
|
|||
}
|
||||
}
|
||||
|
||||
fn fold_foreign_mod(cx: &Context, nm: &ast::foreign_mod) -> ast::foreign_mod {
|
||||
fn fold_foreign_mod(cx: &mut Context, nm: &ast::foreign_mod) -> ast::foreign_mod {
|
||||
let filtered_items = nm.items
|
||||
.iter()
|
||||
.filter_map(|a| filter_foreign_item(cx, *a))
|
||||
|
@ -95,7 +95,7 @@ fn fold_foreign_mod(cx: &Context, nm: &ast::foreign_mod) -> ast::foreign_mod {
|
|||
}
|
||||
}
|
||||
|
||||
fn fold_item_underscore(cx: &Context, item: &ast::item_) -> ast::item_ {
|
||||
fn fold_item_underscore(cx: &mut Context, item: &ast::item_) -> ast::item_ {
|
||||
let item = match *item {
|
||||
ast::item_impl(ref a, ref b, c, ref methods) => {
|
||||
let methods = methods.iter().filter(|m| method_in_cfg(cx, **m))
|
||||
|
@ -129,7 +129,7 @@ fn retain_stmt(cx: &Context, stmt: @ast::Stmt) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
fn fold_block(cx: &Context, b: ast::P<ast::Block>) -> ast::P<ast::Block> {
|
||||
fn fold_block(cx: &mut Context, b: ast::P<ast::Block>) -> ast::P<ast::Block> {
|
||||
let resulting_stmts = b.stmts.iter()
|
||||
.filter(|&a| retain_stmt(cx, *a))
|
||||
.flat_map(|&stmt| cx.fold_stmt(stmt).move_iter())
|
||||
|
|
|
@ -56,7 +56,7 @@ struct StandardLibraryInjector {
|
|||
}
|
||||
|
||||
impl fold::ast_fold for StandardLibraryInjector {
|
||||
fn fold_crate(&self, crate: ast::Crate) -> ast::Crate {
|
||||
fn fold_crate(&mut self, crate: ast::Crate) -> ast::Crate {
|
||||
let version = STD_VERSION.to_managed();
|
||||
let vers_item = attr::mk_name_value_item_str(@"vers", version);
|
||||
let mut vis = ~[ast::view_item {
|
||||
|
@ -108,7 +108,7 @@ impl fold::ast_fold for StandardLibraryInjector {
|
|||
}
|
||||
}
|
||||
|
||||
fn fold_item(&self, item: @ast::item) -> SmallVector<@ast::item> {
|
||||
fn fold_item(&mut self, item: @ast::item) -> SmallVector<@ast::item> {
|
||||
if !no_prelude(item.attrs) {
|
||||
// only recur if there wasn't `#[no_implicit_prelude];`
|
||||
// on this item, i.e. this means that the prelude is not
|
||||
|
@ -119,7 +119,7 @@ impl fold::ast_fold for StandardLibraryInjector {
|
|||
}
|
||||
}
|
||||
|
||||
fn fold_mod(&self, module: &ast::_mod) -> ast::_mod {
|
||||
fn fold_mod(&mut self, module: &ast::_mod) -> ast::_mod {
|
||||
let prelude_path = ast::Path {
|
||||
span: dummy_sp(),
|
||||
global: false,
|
||||
|
@ -158,7 +158,7 @@ impl fold::ast_fold for StandardLibraryInjector {
|
|||
}
|
||||
|
||||
fn inject_libstd_ref(sess: Session, crate: ast::Crate) -> ast::Crate {
|
||||
let fold = StandardLibraryInjector {
|
||||
let mut fold = StandardLibraryInjector {
|
||||
sess: sess,
|
||||
};
|
||||
fold.fold_crate(crate)
|
||||
|
|
|
@ -40,7 +40,7 @@ struct Test {
|
|||
struct TestCtxt {
|
||||
sess: session::Session,
|
||||
path: RefCell<~[ast::Ident]>,
|
||||
ext_cx: @ExtCtxt,
|
||||
ext_cx: ExtCtxt,
|
||||
testfns: RefCell<~[Test]>,
|
||||
is_extra: bool,
|
||||
config: ast::CrateConfig,
|
||||
|
@ -63,22 +63,22 @@ pub fn modify_for_testing(sess: session::Session,
|
|||
}
|
||||
|
||||
struct TestHarnessGenerator {
|
||||
cx: @TestCtxt,
|
||||
cx: TestCtxt,
|
||||
}
|
||||
|
||||
impl fold::ast_fold for TestHarnessGenerator {
|
||||
fn fold_crate(&self, c: ast::Crate) -> ast::Crate {
|
||||
fn fold_crate(&mut self, c: ast::Crate) -> ast::Crate {
|
||||
let folded = fold::noop_fold_crate(c, self);
|
||||
|
||||
// Add a special __test module to the crate that will contain code
|
||||
// generated for the test harness
|
||||
ast::Crate {
|
||||
module: add_test_module(self.cx, &folded.module),
|
||||
module: add_test_module(&self.cx, &folded.module),
|
||||
.. folded
|
||||
}
|
||||
}
|
||||
|
||||
fn fold_item(&self, i: @ast::item) -> SmallVector<@ast::item> {
|
||||
fn fold_item(&mut self, i: @ast::item) -> SmallVector<@ast::item> {
|
||||
{
|
||||
let mut path = self.cx.path.borrow_mut();
|
||||
path.get().push(i.ident);
|
||||
|
@ -86,7 +86,7 @@ impl fold::ast_fold for TestHarnessGenerator {
|
|||
debug!("current path: {}",
|
||||
ast_util::path_name_i(self.cx.path.get()));
|
||||
|
||||
if is_test_fn(self.cx, i) || is_bench_fn(i) {
|
||||
if is_test_fn(&self.cx, i) || is_bench_fn(i) {
|
||||
match i.node {
|
||||
ast::item_fn(_, purity, _, _, _)
|
||||
if purity == ast::unsafe_fn => {
|
||||
|
@ -101,7 +101,7 @@ impl fold::ast_fold for TestHarnessGenerator {
|
|||
span: i.span,
|
||||
path: self.cx.path.get(),
|
||||
bench: is_bench_fn(i),
|
||||
ignore: is_ignored(self.cx, i),
|
||||
ignore: is_ignored(&self.cx, i),
|
||||
should_fail: should_fail(i)
|
||||
};
|
||||
{
|
||||
|
@ -122,11 +122,11 @@ impl fold::ast_fold for TestHarnessGenerator {
|
|||
res
|
||||
}
|
||||
|
||||
fn fold_mod(&self, m: &ast::_mod) -> ast::_mod {
|
||||
fn fold_mod(&mut self, m: &ast::_mod) -> ast::_mod {
|
||||
// Remove any #[main] from the AST so it doesn't clash with
|
||||
// the one we're going to add. Only if compiling an executable.
|
||||
|
||||
fn nomain(cx: @TestCtxt, item: @ast::item) -> @ast::item {
|
||||
fn nomain(cx: &TestCtxt, item: @ast::item) -> @ast::item {
|
||||
if !cx.sess.building_library.get() {
|
||||
@ast::item {
|
||||
attrs: item.attrs.iter().filter_map(|attr| {
|
||||
|
@ -145,7 +145,7 @@ impl fold::ast_fold for TestHarnessGenerator {
|
|||
|
||||
let mod_nomain = ast::_mod {
|
||||
view_items: m.view_items.clone(),
|
||||
items: m.items.iter().map(|i| nomain(self.cx, *i)).collect(),
|
||||
items: m.items.iter().map(|i| nomain(&self.cx, *i)).collect(),
|
||||
};
|
||||
|
||||
fold::noop_fold_mod(&mod_nomain, self)
|
||||
|
@ -154,7 +154,7 @@ impl fold::ast_fold for TestHarnessGenerator {
|
|||
|
||||
fn generate_test_harness(sess: session::Session, crate: ast::Crate)
|
||||
-> ast::Crate {
|
||||
let cx: @TestCtxt = @TestCtxt {
|
||||
let mut cx: TestCtxt = TestCtxt {
|
||||
sess: sess,
|
||||
ext_cx: ExtCtxt::new(sess.parse_sess, sess.opts.cfg.clone()),
|
||||
path: RefCell::new(~[]),
|
||||
|
@ -163,8 +163,7 @@ fn generate_test_harness(sess: session::Session, crate: ast::Crate)
|
|||
config: crate.config.clone(),
|
||||
};
|
||||
|
||||
let ext_cx = cx.ext_cx;
|
||||
ext_cx.bt_push(ExpnInfo {
|
||||
cx.ext_cx.bt_push(ExpnInfo {
|
||||
call_site: dummy_sp(),
|
||||
callee: NameAndSpan {
|
||||
name: @"test",
|
||||
|
@ -173,11 +172,11 @@ fn generate_test_harness(sess: session::Session, crate: ast::Crate)
|
|||
}
|
||||
});
|
||||
|
||||
let fold = TestHarnessGenerator {
|
||||
let mut fold = TestHarnessGenerator {
|
||||
cx: cx
|
||||
};
|
||||
let res = fold.fold_crate(crate);
|
||||
ext_cx.bt_pop();
|
||||
fold.cx.ext_cx.bt_pop();
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -190,7 +189,7 @@ fn strip_test_functions(crate: ast::Crate) -> ast::Crate {
|
|||
})
|
||||
}
|
||||
|
||||
fn is_test_fn(cx: @TestCtxt, i: @ast::item) -> bool {
|
||||
fn is_test_fn(cx: &TestCtxt, i: @ast::item) -> bool {
|
||||
let has_test_attr = attr::contains_name(i.attrs, "test");
|
||||
|
||||
fn has_test_signature(i: @ast::item) -> bool {
|
||||
|
@ -243,7 +242,7 @@ fn is_bench_fn(i: @ast::item) -> bool {
|
|||
return has_bench_attr && has_test_signature(i);
|
||||
}
|
||||
|
||||
fn is_ignored(cx: @TestCtxt, i: @ast::item) -> bool {
|
||||
fn is_ignored(cx: &TestCtxt, i: @ast::item) -> bool {
|
||||
i.attrs.iter().any(|attr| {
|
||||
// check ignore(cfg(foo, bar))
|
||||
"ignore" == attr.name() && match attr.meta_item_list() {
|
||||
|
@ -313,7 +312,7 @@ fn mk_test_module(cx: &TestCtxt) -> @ast::item {
|
|||
|
||||
// The synthesized main function which will call the console test runner
|
||||
// with our list of tests
|
||||
let mainfn = (quote_item!(cx.ext_cx,
|
||||
let mainfn = (quote_item!(&cx.ext_cx,
|
||||
pub fn main() {
|
||||
#[main];
|
||||
extra::test::test_main_static(::std::os::args(), TESTS);
|
||||
|
@ -377,7 +376,7 @@ fn mk_tests(cx: &TestCtxt) -> @ast::item {
|
|||
// The vector of test_descs for this crate
|
||||
let test_descs = mk_test_descs(cx);
|
||||
|
||||
(quote_item!(cx.ext_cx,
|
||||
(quote_item!(&cx.ext_cx,
|
||||
pub static TESTS : &'static [self::extra::test::TestDescAndFn] =
|
||||
$test_descs
|
||||
;
|
||||
|
@ -438,24 +437,24 @@ fn mk_test_desc_and_fn_rec(cx: &TestCtxt, test: &Test) -> @ast::Expr {
|
|||
};
|
||||
|
||||
let t_expr = if test.bench {
|
||||
quote_expr!(cx.ext_cx, self::extra::test::StaticBenchFn($fn_expr) )
|
||||
quote_expr!(&cx.ext_cx, self::extra::test::StaticBenchFn($fn_expr) )
|
||||
} else {
|
||||
quote_expr!(cx.ext_cx, self::extra::test::StaticTestFn($fn_expr) )
|
||||
quote_expr!(&cx.ext_cx, self::extra::test::StaticTestFn($fn_expr) )
|
||||
};
|
||||
|
||||
let ignore_expr = if test.ignore {
|
||||
quote_expr!(cx.ext_cx, true )
|
||||
quote_expr!(&cx.ext_cx, true )
|
||||
} else {
|
||||
quote_expr!(cx.ext_cx, false )
|
||||
quote_expr!(&cx.ext_cx, false )
|
||||
};
|
||||
|
||||
let fail_expr = if test.should_fail {
|
||||
quote_expr!(cx.ext_cx, true )
|
||||
quote_expr!(&cx.ext_cx, true )
|
||||
} else {
|
||||
quote_expr!(cx.ext_cx, false )
|
||||
quote_expr!(&cx.ext_cx, false )
|
||||
};
|
||||
|
||||
let e = quote_expr!(cx.ext_cx,
|
||||
let e = quote_expr!(&cx.ext_cx,
|
||||
self::extra::test::TestDescAndFn {
|
||||
desc: self::extra::test::TestDesc {
|
||||
name: self::extra::test::StaticTestName($name_expr),
|
||||
|
|
|
@ -301,7 +301,7 @@ struct NestedItemsDropper {
|
|||
}
|
||||
|
||||
impl fold::ast_fold for NestedItemsDropper {
|
||||
fn fold_block(&self, blk: ast::P<ast::Block>) -> ast::P<ast::Block> {
|
||||
fn fold_block(&mut self, blk: ast::P<ast::Block>) -> ast::P<ast::Block> {
|
||||
let stmts_sans_items = blk.stmts.iter().filter_map(|stmt| {
|
||||
match stmt.node {
|
||||
ast::StmtExpr(_, _) | ast::StmtSemi(_, _) |
|
||||
|
@ -340,7 +340,7 @@ impl fold::ast_fold for NestedItemsDropper {
|
|||
// nested items, as otherwise it would get confused when translating
|
||||
// inlined items.
|
||||
fn simplify_ast(ii: &ast::inlined_item) -> ast::inlined_item {
|
||||
let fld = NestedItemsDropper {
|
||||
let mut fld = NestedItemsDropper {
|
||||
contents: (),
|
||||
};
|
||||
|
||||
|
@ -365,17 +365,17 @@ struct AstRenumberer {
|
|||
}
|
||||
|
||||
impl fold::ast_fold for AstRenumberer {
|
||||
fn new_id(&self, id: ast::NodeId) -> ast::NodeId {
|
||||
fn new_id(&mut self, id: ast::NodeId) -> ast::NodeId {
|
||||
self.xcx.tr_id(id)
|
||||
}
|
||||
fn new_span(&self, span: Span) -> Span {
|
||||
fn new_span(&mut self, span: Span) -> Span {
|
||||
self.xcx.tr_span(span)
|
||||
}
|
||||
}
|
||||
|
||||
fn renumber_ast(xcx: @ExtendedDecodeContext, ii: ast::inlined_item)
|
||||
-> ast::inlined_item {
|
||||
let fld = AstRenumberer {
|
||||
let mut fld = AstRenumberer {
|
||||
xcx: xcx,
|
||||
};
|
||||
match ii {
|
||||
|
|
|
@ -75,12 +75,12 @@ struct ListenerFn {
|
|||
|
||||
struct ReadyCtx {
|
||||
sess: session::Session,
|
||||
ext_cx: @ExtCtxt,
|
||||
ext_cx: ExtCtxt,
|
||||
path: ~[ast::Ident],
|
||||
fns: ~[ListenerFn]
|
||||
}
|
||||
|
||||
fn fold_mod(_ctx: @mut ReadyCtx, m: &ast::_mod, fold: &CrateSetup)
|
||||
fn fold_mod(_ctx: @mut ReadyCtx, m: &ast::_mod, fold: &mut CrateSetup)
|
||||
-> ast::_mod {
|
||||
fn strip_main(item: @ast::item) -> @ast::item {
|
||||
@ast::item {
|
||||
|
@ -101,7 +101,7 @@ fn fold_mod(_ctx: @mut ReadyCtx, m: &ast::_mod, fold: &CrateSetup)
|
|||
}, fold)
|
||||
}
|
||||
|
||||
fn fold_item(ctx: @mut ReadyCtx, item: @ast::item, fold: &CrateSetup)
|
||||
fn fold_item(ctx: @mut ReadyCtx, item: @ast::item, fold: &mut CrateSetup)
|
||||
-> SmallVector<@ast::item> {
|
||||
ctx.path.push(item.ident);
|
||||
|
||||
|
@ -145,10 +145,10 @@ struct CrateSetup {
|
|||
}
|
||||
|
||||
impl fold::ast_fold for CrateSetup {
|
||||
fn fold_item(&self, item: @ast::item) -> SmallVector<@ast::item> {
|
||||
fn fold_item(&mut self, item: @ast::item) -> SmallVector<@ast::item> {
|
||||
fold_item(self.ctx, item, self)
|
||||
}
|
||||
fn fold_mod(&self, module: &ast::_mod) -> ast::_mod {
|
||||
fn fold_mod(&mut self, module: &ast::_mod) -> ast::_mod {
|
||||
fold_mod(self.ctx, module, self)
|
||||
}
|
||||
}
|
||||
|
@ -162,7 +162,7 @@ pub fn ready_crate(sess: session::Session,
|
|||
path: ~[],
|
||||
fns: ~[]
|
||||
};
|
||||
let fold = CrateSetup {
|
||||
let mut fold = CrateSetup {
|
||||
ctx: ctx,
|
||||
};
|
||||
fold.fold_crate(crate)
|
||||
|
|
|
@ -37,7 +37,7 @@ fn next_state(s: State) -> Option<State> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn expand_asm(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
|
||||
pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
|
||||
-> base::MacResult {
|
||||
let p = parse::new_parser_from_tts(cx.parse_sess(),
|
||||
cx.cfg(),
|
||||
|
|
|
@ -35,11 +35,8 @@ pub struct MacroDef {
|
|||
ext: SyntaxExtension
|
||||
}
|
||||
|
||||
pub type ItemDecorator = extern "Rust" fn(@ExtCtxt,
|
||||
Span,
|
||||
@ast::MetaItem,
|
||||
~[@ast::item])
|
||||
-> ~[@ast::item];
|
||||
pub type ItemDecorator =
|
||||
fn(&ExtCtxt, Span, @ast::MetaItem, ~[@ast::item]) -> ~[@ast::item];
|
||||
|
||||
pub struct SyntaxExpanderTT {
|
||||
expander: SyntaxExpanderTTExpander,
|
||||
|
@ -48,7 +45,7 @@ pub struct SyntaxExpanderTT {
|
|||
|
||||
pub trait SyntaxExpanderTTTrait {
|
||||
fn expand(&self,
|
||||
ecx: @ExtCtxt,
|
||||
ecx: &mut ExtCtxt,
|
||||
span: Span,
|
||||
token_tree: &[ast::token_tree],
|
||||
context: ast::SyntaxContext)
|
||||
|
@ -56,10 +53,8 @@ pub trait SyntaxExpanderTTTrait {
|
|||
}
|
||||
|
||||
pub type SyntaxExpanderTTFunNoCtxt =
|
||||
extern "Rust" fn(ecx: @ExtCtxt,
|
||||
span: codemap::Span,
|
||||
token_tree: &[ast::token_tree])
|
||||
-> MacResult;
|
||||
fn(ecx: &mut ExtCtxt, span: codemap::Span, token_tree: &[ast::token_tree])
|
||||
-> MacResult;
|
||||
|
||||
enum SyntaxExpanderTTExpander {
|
||||
SyntaxExpanderTTExpanderWithoutContext(SyntaxExpanderTTFunNoCtxt),
|
||||
|
@ -67,7 +62,7 @@ enum SyntaxExpanderTTExpander {
|
|||
|
||||
impl SyntaxExpanderTTTrait for SyntaxExpanderTT {
|
||||
fn expand(&self,
|
||||
ecx: @ExtCtxt,
|
||||
ecx: &mut ExtCtxt,
|
||||
span: Span,
|
||||
token_tree: &[ast::token_tree],
|
||||
_: ast::SyntaxContext)
|
||||
|
@ -92,7 +87,7 @@ pub struct SyntaxExpanderTTItem {
|
|||
|
||||
pub trait SyntaxExpanderTTItemTrait {
|
||||
fn expand(&self,
|
||||
cx: @ExtCtxt,
|
||||
cx: &mut ExtCtxt,
|
||||
sp: Span,
|
||||
ident: ast::Ident,
|
||||
token_tree: ~[ast::token_tree],
|
||||
|
@ -102,7 +97,7 @@ pub trait SyntaxExpanderTTItemTrait {
|
|||
|
||||
impl SyntaxExpanderTTItemTrait for SyntaxExpanderTTItem {
|
||||
fn expand(&self,
|
||||
cx: @ExtCtxt,
|
||||
cx: &mut ExtCtxt,
|
||||
sp: Span,
|
||||
ident: ast::Ident,
|
||||
token_tree: ~[ast::token_tree],
|
||||
|
@ -119,16 +114,12 @@ impl SyntaxExpanderTTItemTrait for SyntaxExpanderTTItem {
|
|||
}
|
||||
}
|
||||
|
||||
pub type SyntaxExpanderTTItemFun = extern "Rust" fn(@ExtCtxt,
|
||||
Span,
|
||||
ast::Ident,
|
||||
~[ast::token_tree],
|
||||
ast::SyntaxContext)
|
||||
-> MacResult;
|
||||
pub type SyntaxExpanderTTItemFun =
|
||||
fn(&mut ExtCtxt, Span, ast::Ident, ~[ast::token_tree], ast::SyntaxContext)
|
||||
-> MacResult;
|
||||
|
||||
pub type SyntaxExpanderTTItemFunNoCtxt =
|
||||
extern "Rust" fn(@ExtCtxt, Span, ast::Ident, ~[ast::token_tree])
|
||||
-> MacResult;
|
||||
fn(&mut ExtCtxt, Span, ast::Ident, ~[ast::token_tree]) -> MacResult;
|
||||
|
||||
pub trait AnyMacro {
|
||||
fn make_expr(&self) -> @ast::Expr;
|
||||
|
@ -306,39 +297,38 @@ pub fn syntax_expander_table() -> SyntaxEnv {
|
|||
pub struct ExtCtxt {
|
||||
parse_sess: @mut parse::ParseSess,
|
||||
cfg: ast::CrateConfig,
|
||||
backtrace: @mut Option<@ExpnInfo>,
|
||||
backtrace: Option<@ExpnInfo>,
|
||||
|
||||
// These two @mut's should really not be here,
|
||||
// but the self types for CtxtRepr are all wrong
|
||||
// and there are bugs in the code for object
|
||||
// types that make this hard to get right at the
|
||||
// moment. - nmatsakis
|
||||
mod_path: @mut ~[ast::Ident],
|
||||
trace_mac: @mut bool
|
||||
mod_path: ~[ast::Ident],
|
||||
trace_mac: bool
|
||||
}
|
||||
|
||||
impl ExtCtxt {
|
||||
pub fn new(parse_sess: @mut parse::ParseSess, cfg: ast::CrateConfig)
|
||||
-> @ExtCtxt {
|
||||
@ExtCtxt {
|
||||
-> ExtCtxt {
|
||||
ExtCtxt {
|
||||
parse_sess: parse_sess,
|
||||
cfg: cfg,
|
||||
backtrace: @mut None,
|
||||
mod_path: @mut ~[],
|
||||
trace_mac: @mut false
|
||||
backtrace: None,
|
||||
mod_path: ~[],
|
||||
trace_mac: false
|
||||
}
|
||||
}
|
||||
|
||||
pub fn expand_expr(@self, mut e: @ast::Expr) -> @ast::Expr {
|
||||
pub fn expand_expr(&mut self, mut e: @ast::Expr) -> @ast::Expr {
|
||||
loop {
|
||||
match e.node {
|
||||
ast::ExprMac(..) => {
|
||||
let extsbox = @mut syntax_expander_table();
|
||||
let expander = expand::MacroExpander {
|
||||
extsbox: extsbox,
|
||||
let mut expander = expand::MacroExpander {
|
||||
extsbox: @mut syntax_expander_table(),
|
||||
cx: self,
|
||||
};
|
||||
e = expand::expand_expr(extsbox, self, e, &expander);
|
||||
e = expand::expand_expr(e, &mut expander);
|
||||
}
|
||||
_ => return e
|
||||
}
|
||||
|
@ -349,32 +339,32 @@ impl ExtCtxt {
|
|||
pub fn parse_sess(&self) -> @mut parse::ParseSess { self.parse_sess }
|
||||
pub fn cfg(&self) -> ast::CrateConfig { self.cfg.clone() }
|
||||
pub fn call_site(&self) -> Span {
|
||||
match *self.backtrace {
|
||||
match self.backtrace {
|
||||
Some(@ExpnInfo {call_site: cs, ..}) => cs,
|
||||
None => self.bug("missing top span")
|
||||
}
|
||||
}
|
||||
pub fn print_backtrace(&self) { }
|
||||
pub fn backtrace(&self) -> Option<@ExpnInfo> { *self.backtrace }
|
||||
pub fn mod_push(&self, i: ast::Ident) { self.mod_path.push(i); }
|
||||
pub fn mod_pop(&self) { self.mod_path.pop(); }
|
||||
pub fn mod_path(&self) -> ~[ast::Ident] { (*self.mod_path).clone() }
|
||||
pub fn bt_push(&self, ei: codemap::ExpnInfo) {
|
||||
pub fn backtrace(&self) -> Option<@ExpnInfo> { self.backtrace }
|
||||
pub fn mod_push(&mut self, i: ast::Ident) { self.mod_path.push(i); }
|
||||
pub fn mod_pop(&mut self) { self.mod_path.pop(); }
|
||||
pub fn mod_path(&self) -> ~[ast::Ident] { self.mod_path.clone() }
|
||||
pub fn bt_push(&mut self, ei: codemap::ExpnInfo) {
|
||||
match ei {
|
||||
ExpnInfo {call_site: cs, callee: ref callee} => {
|
||||
*self.backtrace =
|
||||
self.backtrace =
|
||||
Some(@ExpnInfo {
|
||||
call_site: Span {lo: cs.lo, hi: cs.hi,
|
||||
expn_info: *self.backtrace},
|
||||
expn_info: self.backtrace},
|
||||
callee: *callee});
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn bt_pop(&self) {
|
||||
match *self.backtrace {
|
||||
pub fn bt_pop(&mut self) {
|
||||
match self.backtrace {
|
||||
Some(@ExpnInfo {
|
||||
call_site: Span {expn_info: prev, ..}, ..}) => {
|
||||
*self.backtrace = prev
|
||||
self.backtrace = prev
|
||||
}
|
||||
_ => self.bug("tried to pop without a push")
|
||||
}
|
||||
|
@ -404,10 +394,10 @@ impl ExtCtxt {
|
|||
self.parse_sess.span_diagnostic.handler().bug(msg);
|
||||
}
|
||||
pub fn trace_macros(&self) -> bool {
|
||||
*self.trace_mac
|
||||
self.trace_mac
|
||||
}
|
||||
pub fn set_trace_macros(&self, x: bool) {
|
||||
*self.trace_mac = x
|
||||
pub fn set_trace_macros(&mut self, x: bool) {
|
||||
self.trace_mac = x
|
||||
}
|
||||
pub fn str_of(&self, id: ast::Ident) -> @str {
|
||||
ident_to_str(&id)
|
||||
|
@ -417,7 +407,7 @@ impl ExtCtxt {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn expr_to_str(cx: @ExtCtxt, expr: @ast::Expr, err_msg: &str) -> (@str, ast::StrStyle) {
|
||||
pub fn expr_to_str(cx: &ExtCtxt, expr: @ast::Expr, err_msg: &str) -> (@str, ast::StrStyle) {
|
||||
match expr.node {
|
||||
ast::ExprLit(l) => match l.node {
|
||||
ast::lit_str(s, style) => (s, style),
|
||||
|
@ -427,14 +417,14 @@ pub fn expr_to_str(cx: @ExtCtxt, expr: @ast::Expr, err_msg: &str) -> (@str, ast:
|
|||
}
|
||||
}
|
||||
|
||||
pub fn check_zero_tts(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree],
|
||||
pub fn check_zero_tts(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree],
|
||||
name: &str) {
|
||||
if tts.len() != 0 {
|
||||
cx.span_fatal(sp, format!("{} takes no arguments", name));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_single_str_from_tts(cx: @ExtCtxt,
|
||||
pub fn get_single_str_from_tts(cx: &ExtCtxt,
|
||||
sp: Span,
|
||||
tts: &[ast::token_tree],
|
||||
name: &str)
|
||||
|
@ -450,7 +440,7 @@ pub fn get_single_str_from_tts(cx: @ExtCtxt,
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_exprs_from_tts(cx: @ExtCtxt,
|
||||
pub fn get_exprs_from_tts(cx: &ExtCtxt,
|
||||
sp: Span,
|
||||
tts: &[ast::token_tree]) -> ~[@ast::Expr] {
|
||||
let p = parse::new_parser_from_tts(cx.parse_sess(),
|
||||
|
|
|
@ -15,7 +15,7 @@ use ast_util;
|
|||
use codemap::{Span, respan, dummy_sp};
|
||||
use ext::base::ExtCtxt;
|
||||
use ext::quote::rt::*;
|
||||
use fold;
|
||||
use fold::ast_fold;
|
||||
use opt_vec;
|
||||
use opt_vec::OptVec;
|
||||
|
||||
|
@ -236,7 +236,7 @@ pub trait AstBuilder {
|
|||
vis: ast::visibility, path: ~[ast::Ident]) -> ast::view_item;
|
||||
}
|
||||
|
||||
impl AstBuilder for @ExtCtxt {
|
||||
impl AstBuilder for ExtCtxt {
|
||||
fn path(&self, span: Span, strs: ~[ast::Ident]) -> ast::Path {
|
||||
self.path_all(span, false, strs, opt_vec::Empty, ~[])
|
||||
}
|
||||
|
@ -686,12 +686,12 @@ impl AstBuilder for @ExtCtxt {
|
|||
}
|
||||
fn lambda0(&self, _span: Span, blk: P<ast::Block>) -> @ast::Expr {
|
||||
let blk_e = self.expr(blk.span, ast::ExprBlock(blk));
|
||||
quote_expr!(*self, || $blk_e )
|
||||
quote_expr!(self, || $blk_e )
|
||||
}
|
||||
|
||||
fn lambda1(&self, _span: Span, blk: P<ast::Block>, ident: ast::Ident) -> @ast::Expr {
|
||||
let blk_e = self.expr(blk.span, ast::ExprBlock(blk));
|
||||
quote_expr!(*self, |$ident| $blk_e )
|
||||
quote_expr!(self, |$ident| $blk_e )
|
||||
}
|
||||
|
||||
fn lambda_expr(&self, span: Span, ids: ~[ast::Ident], expr: @ast::Expr) -> @ast::Expr {
|
||||
|
@ -903,12 +903,12 @@ impl AstBuilder for @ExtCtxt {
|
|||
}
|
||||
}
|
||||
|
||||
struct Duplicator {
|
||||
cx: @ExtCtxt,
|
||||
struct Duplicator<'a> {
|
||||
cx: &'a ExtCtxt,
|
||||
}
|
||||
|
||||
impl fold::ast_fold for Duplicator {
|
||||
fn new_id(&self, _: NodeId) -> NodeId {
|
||||
impl<'a> ast_fold for Duplicator<'a> {
|
||||
fn new_id(&mut self, _: NodeId) -> NodeId {
|
||||
ast::DUMMY_NODE_ID
|
||||
}
|
||||
}
|
||||
|
@ -920,14 +920,14 @@ pub trait Duplicate {
|
|||
// These functions just duplicate AST nodes.
|
||||
//
|
||||
|
||||
fn duplicate(&self, cx: @ExtCtxt) -> Self;
|
||||
fn duplicate(&self, cx: &ExtCtxt) -> Self;
|
||||
}
|
||||
|
||||
impl Duplicate for @ast::Expr {
|
||||
fn duplicate(&self, cx: @ExtCtxt) -> @ast::Expr {
|
||||
let folder = @Duplicator {
|
||||
fn duplicate(&self, cx: &ExtCtxt) -> @ast::Expr {
|
||||
let mut folder = Duplicator {
|
||||
cx: cx,
|
||||
} as @fold::ast_fold;
|
||||
};
|
||||
folder.fold_expr(*self)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ use ext::build::AstBuilder;
|
|||
|
||||
use std::char;
|
||||
|
||||
pub fn expand_syntax_ext(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult {
|
||||
pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult {
|
||||
// Gather all argument expressions
|
||||
let exprs = get_exprs_from_tts(cx, sp, tts);
|
||||
let mut bytes = ~[];
|
||||
|
|
|
@ -25,7 +25,7 @@ use parse;
|
|||
use parse::token;
|
||||
use parse::attr::parser_attr;
|
||||
|
||||
pub fn expand_cfg(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult {
|
||||
pub fn expand_cfg(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult {
|
||||
let p = parse::new_parser_from_tts(cx.parse_sess(), cx.cfg(), tts.to_owned());
|
||||
|
||||
let mut cfgs = ~[];
|
||||
|
|
|
@ -15,7 +15,7 @@ use codemap;
|
|||
use ext::base;
|
||||
use ext::build::AstBuilder;
|
||||
|
||||
pub fn expand_syntax_ext(cx: @base::ExtCtxt,
|
||||
pub fn expand_syntax_ext(cx: &mut base::ExtCtxt,
|
||||
sp: codemap::Span,
|
||||
tts: &[ast::token_tree]) -> base::MacResult {
|
||||
let es = base::get_exprs_from_tts(cx, sp, tts);
|
||||
|
|
|
@ -16,7 +16,7 @@ use opt_vec;
|
|||
use parse::token;
|
||||
use parse::token::{str_to_ident};
|
||||
|
||||
pub fn expand_syntax_ext(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
|
||||
pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
|
||||
-> base::MacResult {
|
||||
let mut res_str = ~"";
|
||||
for (i, e) in tts.iter().enumerate() {
|
||||
|
|
|
@ -14,7 +14,7 @@ use ext::base::ExtCtxt;
|
|||
use ext::build::AstBuilder;
|
||||
use ext::deriving::generic::*;
|
||||
|
||||
pub fn expand_deriving_clone(cx: @ExtCtxt,
|
||||
pub fn expand_deriving_clone(cx: &ExtCtxt,
|
||||
span: Span,
|
||||
mitem: @MetaItem,
|
||||
in_items: ~[@item])
|
||||
|
@ -42,7 +42,7 @@ pub fn expand_deriving_clone(cx: @ExtCtxt,
|
|||
trait_def.expand(mitem, in_items)
|
||||
}
|
||||
|
||||
pub fn expand_deriving_deep_clone(cx: @ExtCtxt,
|
||||
pub fn expand_deriving_deep_clone(cx: &ExtCtxt,
|
||||
span: Span,
|
||||
mitem: @MetaItem,
|
||||
in_items: ~[@item])
|
||||
|
@ -74,7 +74,7 @@ pub fn expand_deriving_deep_clone(cx: @ExtCtxt,
|
|||
|
||||
fn cs_clone(
|
||||
name: &str,
|
||||
cx: @ExtCtxt, span: Span,
|
||||
cx: &ExtCtxt, span: Span,
|
||||
substr: &Substructure) -> @Expr {
|
||||
let clone_ident = substr.method_ident;
|
||||
let ctor_ident;
|
||||
|
|
|
@ -14,17 +14,17 @@ use ext::base::ExtCtxt;
|
|||
use ext::build::AstBuilder;
|
||||
use ext::deriving::generic::*;
|
||||
|
||||
pub fn expand_deriving_eq(cx: @ExtCtxt,
|
||||
pub fn expand_deriving_eq(cx: &ExtCtxt,
|
||||
span: Span,
|
||||
mitem: @MetaItem,
|
||||
in_items: ~[@item]) -> ~[@item] {
|
||||
// structures are equal if all fields are equal, and non equal, if
|
||||
// any fields are not equal or if the enum variants are different
|
||||
fn cs_eq(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
|
||||
fn cs_eq(cx: &ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
|
||||
cs_and(|cx, span, _, _| cx.expr_bool(span, false),
|
||||
cx, span, substr)
|
||||
}
|
||||
fn cs_ne(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
|
||||
fn cs_ne(cx: &ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
|
||||
cs_or(|cx, span, _, _| cx.expr_bool(span, true),
|
||||
cx, span, substr)
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ use ext::base::ExtCtxt;
|
|||
use ext::build::AstBuilder;
|
||||
use ext::deriving::generic::*;
|
||||
|
||||
pub fn expand_deriving_ord(cx: @ExtCtxt,
|
||||
pub fn expand_deriving_ord(cx: &ExtCtxt,
|
||||
span: Span,
|
||||
mitem: @MetaItem,
|
||||
in_items: ~[@item]) -> ~[@item] {
|
||||
|
@ -51,7 +51,7 @@ pub fn expand_deriving_ord(cx: @ExtCtxt,
|
|||
}
|
||||
|
||||
/// Strict inequality.
|
||||
fn cs_op(less: bool, equal: bool, cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
|
||||
fn cs_op(less: bool, equal: bool, cx: &ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
|
||||
let op = if less {ast::BiLt} else {ast::BiGt};
|
||||
cs_fold(
|
||||
false, // need foldr,
|
||||
|
|
|
@ -14,11 +14,11 @@ use ext::base::ExtCtxt;
|
|||
use ext::build::AstBuilder;
|
||||
use ext::deriving::generic::*;
|
||||
|
||||
pub fn expand_deriving_totaleq(cx: @ExtCtxt,
|
||||
pub fn expand_deriving_totaleq(cx: &ExtCtxt,
|
||||
span: Span,
|
||||
mitem: @MetaItem,
|
||||
in_items: ~[@item]) -> ~[@item] {
|
||||
fn cs_equals(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
|
||||
fn cs_equals(cx: &ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
|
||||
cs_and(|cx, span, _, _| cx.expr_bool(span, false),
|
||||
cx, span, substr)
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ use ext::build::AstBuilder;
|
|||
use ext::deriving::generic::*;
|
||||
use std::cmp::{Ordering, Equal, Less, Greater};
|
||||
|
||||
pub fn expand_deriving_totalord(cx: @ExtCtxt,
|
||||
pub fn expand_deriving_totalord(cx: &ExtCtxt,
|
||||
span: Span,
|
||||
mitem: @MetaItem,
|
||||
in_items: ~[@item]) -> ~[@item] {
|
||||
|
@ -44,7 +44,7 @@ pub fn expand_deriving_totalord(cx: @ExtCtxt,
|
|||
}
|
||||
|
||||
|
||||
pub fn ordering_const(cx: @ExtCtxt, span: Span, cnst: Ordering) -> ast::Path {
|
||||
pub fn ordering_const(cx: &ExtCtxt, span: Span, cnst: Ordering) -> ast::Path {
|
||||
let cnst = match cnst {
|
||||
Less => "Less",
|
||||
Equal => "Equal",
|
||||
|
@ -56,7 +56,7 @@ pub fn ordering_const(cx: @ExtCtxt, span: Span, cnst: Ordering) -> ast::Path {
|
|||
cx.ident_of(cnst)])
|
||||
}
|
||||
|
||||
pub fn cs_cmp(cx: @ExtCtxt, span: Span,
|
||||
pub fn cs_cmp(cx: &ExtCtxt, span: Span,
|
||||
substr: &Substructure) -> @Expr {
|
||||
let test_id = cx.ident_of("__test");
|
||||
let equals_path = ordering_const(cx, span, Equal);
|
||||
|
|
|
@ -19,7 +19,7 @@ use ext::base::ExtCtxt;
|
|||
use ext::build::AstBuilder;
|
||||
use ext::deriving::generic::*;
|
||||
|
||||
pub fn expand_deriving_decodable(cx: @ExtCtxt,
|
||||
pub fn expand_deriving_decodable(cx: &ExtCtxt,
|
||||
span: Span,
|
||||
mitem: @MetaItem,
|
||||
in_items: ~[@item]) -> ~[@item] {
|
||||
|
@ -51,7 +51,7 @@ pub fn expand_deriving_decodable(cx: @ExtCtxt,
|
|||
trait_def.expand(mitem, in_items)
|
||||
}
|
||||
|
||||
fn decodable_substructure(cx: @ExtCtxt, span: Span,
|
||||
fn decodable_substructure(cx: &ExtCtxt, span: Span,
|
||||
substr: &Substructure) -> @Expr {
|
||||
let decoder = substr.nonself_args[0];
|
||||
let recurse = ~[cx.ident_of("extra"),
|
||||
|
@ -132,7 +132,7 @@ fn decodable_substructure(cx: @ExtCtxt, span: Span,
|
|||
/// Create a decoder for a single enum variant/struct:
|
||||
/// - `outer_pat_ident` is the name of this enum variant/struct
|
||||
/// - `getarg` should retrieve the `uint`-th field with name `@str`.
|
||||
fn decode_static_fields(cx: @ExtCtxt,
|
||||
fn decode_static_fields(cx: &ExtCtxt,
|
||||
outer_span: Span,
|
||||
outer_pat_ident: Ident,
|
||||
fields: &StaticFields,
|
||||
|
|
|
@ -14,7 +14,7 @@ use ext::base::ExtCtxt;
|
|||
use ext::build::AstBuilder;
|
||||
use ext::deriving::generic::*;
|
||||
|
||||
pub fn expand_deriving_default(cx: @ExtCtxt,
|
||||
pub fn expand_deriving_default(cx: &ExtCtxt,
|
||||
span: Span,
|
||||
mitem: @MetaItem,
|
||||
in_items: ~[@item])
|
||||
|
@ -41,7 +41,7 @@ pub fn expand_deriving_default(cx: @ExtCtxt,
|
|||
trait_def.expand(mitem, in_items)
|
||||
}
|
||||
|
||||
fn default_substructure(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
|
||||
fn default_substructure(cx: &ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
|
||||
let default_ident = ~[
|
||||
cx.ident_of("std"),
|
||||
cx.ident_of("default"),
|
||||
|
|
|
@ -81,7 +81,7 @@ use ext::base::ExtCtxt;
|
|||
use ext::build::AstBuilder;
|
||||
use ext::deriving::generic::*;
|
||||
|
||||
pub fn expand_deriving_encodable(cx: @ExtCtxt,
|
||||
pub fn expand_deriving_encodable(cx: &ExtCtxt,
|
||||
span: Span,
|
||||
mitem: @MetaItem,
|
||||
in_items: ~[@item]) -> ~[@item] {
|
||||
|
@ -113,7 +113,7 @@ pub fn expand_deriving_encodable(cx: @ExtCtxt,
|
|||
trait_def.expand(mitem, in_items)
|
||||
}
|
||||
|
||||
fn encodable_substructure(cx: @ExtCtxt, span: Span,
|
||||
fn encodable_substructure(cx: &ExtCtxt, span: Span,
|
||||
substr: &Substructure) -> @Expr {
|
||||
let encoder = substr.nonself_args[0];
|
||||
// throw an underscore in front to suppress unused variable warnings
|
||||
|
|
|
@ -190,7 +190,7 @@ mod ty;
|
|||
|
||||
pub struct TraitDef<'a> {
|
||||
/// The extension context
|
||||
cx: @ExtCtxt,
|
||||
cx: &'a ExtCtxt,
|
||||
/// The span for the current #[deriving(Foo)] header.
|
||||
span: Span,
|
||||
|
||||
|
@ -300,7 +300,7 @@ Combine the values of all the fields together. The last argument is
|
|||
all the fields of all the structures, see above for details.
|
||||
*/
|
||||
pub type CombineSubstructureFunc<'a> =
|
||||
'a |@ExtCtxt, Span, &Substructure| -> @Expr;
|
||||
'a |&ExtCtxt, Span, &Substructure| -> @Expr;
|
||||
|
||||
/**
|
||||
Deal with non-matching enum variants, the arguments are a list
|
||||
|
@ -308,7 +308,7 @@ representing each variant: (variant index, ast::variant instance,
|
|||
[variant fields]), and a list of the nonself args of the type
|
||||
*/
|
||||
pub type EnumNonMatchFunc<'a> =
|
||||
'a |@ExtCtxt,
|
||||
'a |&ExtCtxt,
|
||||
Span,
|
||||
&[(uint, P<ast::variant>, ~[(Span, Option<Ident>, @Expr)])],
|
||||
&[@Expr]|
|
||||
|
@ -1076,10 +1076,10 @@ Fold the fields. `use_foldl` controls whether this is done
|
|||
left-to-right (`true`) or right-to-left (`false`).
|
||||
*/
|
||||
pub fn cs_fold(use_foldl: bool,
|
||||
f: |@ExtCtxt, Span, @Expr, @Expr, &[@Expr]| -> @Expr,
|
||||
f: |&ExtCtxt, Span, @Expr, @Expr, &[@Expr]| -> @Expr,
|
||||
base: @Expr,
|
||||
enum_nonmatch_f: EnumNonMatchFunc,
|
||||
cx: @ExtCtxt,
|
||||
cx: &ExtCtxt,
|
||||
trait_span: Span,
|
||||
substructure: &Substructure)
|
||||
-> @Expr {
|
||||
|
@ -1115,9 +1115,9 @@ f(cx, span, ~[self_1.method(__arg_1_1, __arg_2_1),
|
|||
~~~
|
||||
*/
|
||||
#[inline]
|
||||
pub fn cs_same_method(f: |@ExtCtxt, Span, ~[@Expr]| -> @Expr,
|
||||
pub fn cs_same_method(f: |&ExtCtxt, Span, ~[@Expr]| -> @Expr,
|
||||
enum_nonmatch_f: EnumNonMatchFunc,
|
||||
cx: @ExtCtxt,
|
||||
cx: &ExtCtxt,
|
||||
trait_span: Span,
|
||||
substructure: &Substructure)
|
||||
-> @Expr {
|
||||
|
@ -1149,10 +1149,10 @@ fields. `use_foldl` controls whether this is done left-to-right
|
|||
*/
|
||||
#[inline]
|
||||
pub fn cs_same_method_fold(use_foldl: bool,
|
||||
f: |@ExtCtxt, Span, @Expr, @Expr| -> @Expr,
|
||||
f: |&ExtCtxt, Span, @Expr, @Expr| -> @Expr,
|
||||
base: @Expr,
|
||||
enum_nonmatch_f: EnumNonMatchFunc,
|
||||
cx: @ExtCtxt,
|
||||
cx: &ExtCtxt,
|
||||
trait_span: Span,
|
||||
substructure: &Substructure)
|
||||
-> @Expr {
|
||||
|
@ -1179,7 +1179,7 @@ on all the fields.
|
|||
#[inline]
|
||||
pub fn cs_binop(binop: ast::BinOp, base: @Expr,
|
||||
enum_nonmatch_f: EnumNonMatchFunc,
|
||||
cx: @ExtCtxt, trait_span: Span,
|
||||
cx: &ExtCtxt, trait_span: Span,
|
||||
substructure: &Substructure) -> @Expr {
|
||||
cs_same_method_fold(
|
||||
true, // foldl is good enough
|
||||
|
@ -1197,7 +1197,7 @@ pub fn cs_binop(binop: ast::BinOp, base: @Expr,
|
|||
/// cs_binop with binop == or
|
||||
#[inline]
|
||||
pub fn cs_or(enum_nonmatch_f: EnumNonMatchFunc,
|
||||
cx: @ExtCtxt, span: Span,
|
||||
cx: &ExtCtxt, span: Span,
|
||||
substructure: &Substructure) -> @Expr {
|
||||
cs_binop(ast::BiOr, cx.expr_bool(span, false),
|
||||
enum_nonmatch_f,
|
||||
|
@ -1207,7 +1207,7 @@ pub fn cs_or(enum_nonmatch_f: EnumNonMatchFunc,
|
|||
/// cs_binop with binop == and
|
||||
#[inline]
|
||||
pub fn cs_and(enum_nonmatch_f: EnumNonMatchFunc,
|
||||
cx: @ExtCtxt, span: Span,
|
||||
cx: &ExtCtxt, span: Span,
|
||||
substructure: &Substructure) -> @Expr {
|
||||
cs_binop(ast::BiAnd, cx.expr_bool(span, true),
|
||||
enum_nonmatch_f,
|
||||
|
|
|
@ -15,7 +15,7 @@ use ext::build::AstBuilder;
|
|||
use ext::deriving::generic::*;
|
||||
|
||||
|
||||
pub fn expand_deriving_iter_bytes(cx: @ExtCtxt,
|
||||
pub fn expand_deriving_iter_bytes(cx: &ExtCtxt,
|
||||
span: Span,
|
||||
mitem: @MetaItem,
|
||||
in_items: ~[@item]) -> ~[@item] {
|
||||
|
@ -45,7 +45,7 @@ pub fn expand_deriving_iter_bytes(cx: @ExtCtxt,
|
|||
trait_def.expand(mitem, in_items)
|
||||
}
|
||||
|
||||
fn iter_bytes_substructure(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
|
||||
fn iter_bytes_substructure(cx: &ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
|
||||
let (lsb0, f)= match substr.nonself_args {
|
||||
[l, f] => (l, f),
|
||||
_ => cx.span_bug(span, "Incorrect number of arguments in `deriving(IterBytes)`")
|
||||
|
|
|
@ -46,20 +46,20 @@ pub mod totalord;
|
|||
|
||||
pub mod generic;
|
||||
|
||||
pub type ExpandDerivingStructDefFn<'a> = 'a |@ExtCtxt,
|
||||
pub type ExpandDerivingStructDefFn<'a> = 'a |&ExtCtxt,
|
||||
Span,
|
||||
x: &struct_def,
|
||||
Ident,
|
||||
y: &Generics|
|
||||
-> @item;
|
||||
pub type ExpandDerivingEnumDefFn<'a> = 'a |@ExtCtxt,
|
||||
pub type ExpandDerivingEnumDefFn<'a> = 'a |&ExtCtxt,
|
||||
Span,
|
||||
x: &enum_def,
|
||||
Ident,
|
||||
y: &Generics|
|
||||
-> @item;
|
||||
|
||||
pub fn expand_meta_deriving(cx: @ExtCtxt,
|
||||
pub fn expand_meta_deriving(cx: &ExtCtxt,
|
||||
_span: Span,
|
||||
mitem: @MetaItem,
|
||||
in_items: ~[@item])
|
||||
|
|
|
@ -15,7 +15,7 @@ use ext::base::ExtCtxt;
|
|||
use ext::build::AstBuilder;
|
||||
use ext::deriving::generic::*;
|
||||
|
||||
pub fn expand_deriving_from_primitive(cx: @ExtCtxt,
|
||||
pub fn expand_deriving_from_primitive(cx: &ExtCtxt,
|
||||
span: Span,
|
||||
mitem: @MetaItem,
|
||||
in_items: ~[@item]) -> ~[@item] {
|
||||
|
@ -64,7 +64,7 @@ pub fn expand_deriving_from_primitive(cx: @ExtCtxt,
|
|||
trait_def.expand(mitem, in_items)
|
||||
}
|
||||
|
||||
fn cs_from(name: &str, cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
|
||||
fn cs_from(name: &str, cx: &ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
|
||||
let n = match substr.nonself_args {
|
||||
[n] => n,
|
||||
_ => cx.span_bug(span, "Incorrect number of arguments in `deriving(FromPrimitive)`")
|
||||
|
|
|
@ -16,7 +16,7 @@ use ext::build::{AstBuilder};
|
|||
use ext::deriving::generic::*;
|
||||
use opt_vec;
|
||||
|
||||
pub fn expand_deriving_rand(cx: @ExtCtxt,
|
||||
pub fn expand_deriving_rand(cx: &ExtCtxt,
|
||||
span: Span,
|
||||
mitem: @MetaItem,
|
||||
in_items: ~[@item])
|
||||
|
@ -50,7 +50,7 @@ pub fn expand_deriving_rand(cx: @ExtCtxt,
|
|||
trait_def.expand(mitem, in_items)
|
||||
}
|
||||
|
||||
fn rand_substructure(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
|
||||
fn rand_substructure(cx: &ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
|
||||
let rng = match substr.nonself_args {
|
||||
[rng] => ~[ rng ],
|
||||
_ => cx.bug("Incorrect number of arguments to `rand` in `deriving(Rand)`")
|
||||
|
@ -130,7 +130,7 @@ fn rand_substructure(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
|
|||
_ => cx.bug("Non-static method in `deriving(Rand)`")
|
||||
};
|
||||
|
||||
fn rand_thing(cx: @ExtCtxt,
|
||||
fn rand_thing(cx: &ExtCtxt,
|
||||
span: Span,
|
||||
ctor_ident: Ident,
|
||||
summary: &StaticFields,
|
||||
|
|
|
@ -15,7 +15,7 @@ use ext::base::ExtCtxt;
|
|||
use ext::build::AstBuilder;
|
||||
use ext::deriving::generic::*;
|
||||
|
||||
pub fn expand_deriving_to_str(cx: @ExtCtxt,
|
||||
pub fn expand_deriving_to_str(cx: &ExtCtxt,
|
||||
span: Span,
|
||||
mitem: @MetaItem,
|
||||
in_items: ~[@item])
|
||||
|
@ -47,7 +47,7 @@ pub fn expand_deriving_to_str(cx: @ExtCtxt,
|
|||
// doesn't invoke the to_str() method on each field. Hence we mirror
|
||||
// the logic of the repr_to_str() method, but with tweaks to call to_str()
|
||||
// on sub-fields.
|
||||
fn to_str_substructure(cx: @ExtCtxt, span: Span,
|
||||
fn to_str_substructure(cx: &ExtCtxt, span: Span,
|
||||
substr: &Substructure) -> @Expr {
|
||||
let to_str = cx.ident_of("to_str");
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ impl<'a> Path<'a> {
|
|||
}
|
||||
|
||||
pub fn to_ty(&self,
|
||||
cx: @ExtCtxt,
|
||||
cx: &ExtCtxt,
|
||||
span: Span,
|
||||
self_ty: Ident,
|
||||
self_generics: &Generics)
|
||||
|
@ -66,7 +66,7 @@ impl<'a> Path<'a> {
|
|||
cx.ty_path(self.to_path(cx, span, self_ty, self_generics), None)
|
||||
}
|
||||
pub fn to_path(&self,
|
||||
cx: @ExtCtxt,
|
||||
cx: &ExtCtxt,
|
||||
span: Span,
|
||||
self_ty: Ident,
|
||||
self_generics: &Generics)
|
||||
|
@ -110,14 +110,14 @@ pub fn nil_ty() -> Ty<'static> {
|
|||
Tuple(~[])
|
||||
}
|
||||
|
||||
fn mk_lifetime(cx: @ExtCtxt, span: Span, lt: &Option<&str>) -> Option<ast::Lifetime> {
|
||||
fn mk_lifetime(cx: &ExtCtxt, span: Span, lt: &Option<&str>) -> Option<ast::Lifetime> {
|
||||
match *lt {
|
||||
Some(ref s) => Some(cx.lifetime(span, cx.ident_of(*s))),
|
||||
None => None
|
||||
}
|
||||
}
|
||||
|
||||
fn mk_lifetimes(cx: @ExtCtxt, span: Span, lt: &Option<&str>) -> OptVec<ast::Lifetime> {
|
||||
fn mk_lifetimes(cx: &ExtCtxt, span: Span, lt: &Option<&str>) -> OptVec<ast::Lifetime> {
|
||||
match *lt {
|
||||
Some(ref s) => opt_vec::with(cx.lifetime(span, cx.ident_of(*s))),
|
||||
None => opt_vec::Empty
|
||||
|
@ -126,7 +126,7 @@ fn mk_lifetimes(cx: @ExtCtxt, span: Span, lt: &Option<&str>) -> OptVec<ast::Life
|
|||
|
||||
impl<'a> Ty<'a> {
|
||||
pub fn to_ty(&self,
|
||||
cx: @ExtCtxt,
|
||||
cx: &ExtCtxt,
|
||||
span: Span,
|
||||
self_ty: Ident,
|
||||
self_generics: &Generics)
|
||||
|
@ -164,7 +164,7 @@ impl<'a> Ty<'a> {
|
|||
}
|
||||
|
||||
pub fn to_path(&self,
|
||||
cx: @ExtCtxt,
|
||||
cx: &ExtCtxt,
|
||||
span: Span,
|
||||
self_ty: Ident,
|
||||
self_generics: &Generics)
|
||||
|
@ -189,7 +189,7 @@ impl<'a> Ty<'a> {
|
|||
}
|
||||
|
||||
|
||||
fn mk_ty_param(cx: @ExtCtxt, span: Span, name: &str, bounds: &[Path],
|
||||
fn mk_ty_param(cx: &ExtCtxt, span: Span, name: &str, bounds: &[Path],
|
||||
self_ident: Ident, self_generics: &Generics) -> ast::TyParam {
|
||||
let bounds = opt_vec::from(
|
||||
bounds.map(|b| {
|
||||
|
@ -219,7 +219,7 @@ impl<'a> LifetimeBounds<'a> {
|
|||
}
|
||||
}
|
||||
pub fn to_generics(&self,
|
||||
cx: @ExtCtxt,
|
||||
cx: &ExtCtxt,
|
||||
span: Span,
|
||||
self_ty: Ident,
|
||||
self_generics: &Generics)
|
||||
|
@ -239,7 +239,7 @@ impl<'a> LifetimeBounds<'a> {
|
|||
}
|
||||
|
||||
|
||||
pub fn get_explicit_self(cx: @ExtCtxt, span: Span, self_ptr: &Option<PtrTy>)
|
||||
pub fn get_explicit_self(cx: &ExtCtxt, span: Span, self_ptr: &Option<PtrTy>)
|
||||
-> (@Expr, ast::explicit_self) {
|
||||
let self_path = cx.expr_self(span);
|
||||
match *self_ptr {
|
||||
|
|
|
@ -14,7 +14,7 @@ use ext::base::ExtCtxt;
|
|||
use ext::build::AstBuilder;
|
||||
use ext::deriving::generic::*;
|
||||
|
||||
pub fn expand_deriving_zero(cx: @ExtCtxt,
|
||||
pub fn expand_deriving_zero(cx: &ExtCtxt,
|
||||
span: Span,
|
||||
mitem: @MetaItem,
|
||||
in_items: ~[@item])
|
||||
|
@ -57,7 +57,7 @@ pub fn expand_deriving_zero(cx: @ExtCtxt,
|
|||
trait_def.expand(mitem, in_items)
|
||||
}
|
||||
|
||||
fn zero_substructure(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
|
||||
fn zero_substructure(cx: &ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
|
||||
let zero_ident = ~[
|
||||
cx.ident_of("std"),
|
||||
cx.ident_of("num"),
|
||||
|
|
|
@ -22,7 +22,7 @@ use ext::build::AstBuilder;
|
|||
|
||||
use std::os;
|
||||
|
||||
pub fn expand_option_env(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
|
||||
pub fn expand_option_env(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
|
||||
-> base::MacResult {
|
||||
let var = get_single_str_from_tts(cx, sp, tts, "option_env!");
|
||||
|
||||
|
@ -33,7 +33,7 @@ pub fn expand_option_env(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
|
|||
MRExpr(e)
|
||||
}
|
||||
|
||||
pub fn expand_env(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
|
||||
pub fn expand_env(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
|
||||
-> base::MacResult {
|
||||
let exprs = get_exprs_from_tts(cx, sp, tts);
|
||||
|
||||
|
|
|
@ -31,11 +31,7 @@ use util::small_vector::SmallVector;
|
|||
|
||||
use std::vec;
|
||||
|
||||
pub fn expand_expr(extsbox: @mut SyntaxEnv,
|
||||
cx: @ExtCtxt,
|
||||
e: @ast::Expr,
|
||||
fld: &MacroExpander)
|
||||
-> @ast::Expr {
|
||||
pub fn expand_expr(e: @ast::Expr, fld: &mut MacroExpander) -> @ast::Expr {
|
||||
match e.node {
|
||||
// expr_mac should really be expr_ext or something; it's the
|
||||
// entry-point for all syntax extensions.
|
||||
|
@ -49,7 +45,7 @@ pub fn expand_expr(extsbox: @mut SyntaxEnv,
|
|||
// Token-tree macros:
|
||||
mac_invoc_tt(ref pth, ref tts, ctxt) => {
|
||||
if (pth.segments.len() > 1u) {
|
||||
cx.span_fatal(
|
||||
fld.cx.span_fatal(
|
||||
pth.span,
|
||||
format!("expected macro name without module \
|
||||
separators"));
|
||||
|
@ -57,14 +53,14 @@ pub fn expand_expr(extsbox: @mut SyntaxEnv,
|
|||
let extname = &pth.segments[0].identifier;
|
||||
let extnamestr = ident_to_str(extname);
|
||||
// leaving explicit deref here to highlight unbox op:
|
||||
match (*extsbox).find(&extname.name) {
|
||||
match (*fld.extsbox).find(&extname.name) {
|
||||
None => {
|
||||
cx.span_fatal(
|
||||
fld.cx.span_fatal(
|
||||
pth.span,
|
||||
format!("macro undefined: '{}'", extnamestr))
|
||||
}
|
||||
Some(@SE(NormalTT(expandfun, exp_span))) => {
|
||||
cx.bt_push(ExpnInfo {
|
||||
fld.cx.bt_push(ExpnInfo {
|
||||
call_site: e.span,
|
||||
callee: NameAndSpan {
|
||||
name: extnamestr,
|
||||
|
@ -81,17 +77,17 @@ pub fn expand_expr(extsbox: @mut SyntaxEnv,
|
|||
// 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(cx);
|
||||
let mac_span = original_span(fld.cx);
|
||||
|
||||
let expanded =
|
||||
match expandfun.expand(cx,
|
||||
match expandfun.expand(fld.cx,
|
||||
mac_span.call_site,
|
||||
marked_before,
|
||||
marked_ctxt) {
|
||||
MRExpr(e) => e,
|
||||
MRAny(any_macro) => any_macro.make_expr(),
|
||||
_ => {
|
||||
cx.span_fatal(
|
||||
fld.cx.span_fatal(
|
||||
pth.span,
|
||||
format!(
|
||||
"non-expr macro in expr pos: {}",
|
||||
|
@ -109,7 +105,7 @@ pub fn expand_expr(extsbox: @mut SyntaxEnv,
|
|||
// node here?
|
||||
let fully_expanded =
|
||||
fld.fold_expr(marked_after).node.clone();
|
||||
cx.bt_pop();
|
||||
fld.cx.bt_pop();
|
||||
|
||||
@ast::Expr {
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
|
@ -118,7 +114,7 @@ pub fn expand_expr(extsbox: @mut SyntaxEnv,
|
|||
}
|
||||
}
|
||||
_ => {
|
||||
cx.span_fatal(
|
||||
fld.cx.span_fatal(
|
||||
pth.span,
|
||||
format!("'{}' is not a tt-style macro", extnamestr)
|
||||
)
|
||||
|
@ -152,46 +148,47 @@ pub fn expand_expr(extsbox: @mut SyntaxEnv,
|
|||
// }
|
||||
|
||||
let local_ident = token::gensym_ident("i");
|
||||
let next_ident = cx.ident_of("next");
|
||||
let none_ident = cx.ident_of("None");
|
||||
let next_ident = fld.cx.ident_of("next");
|
||||
let none_ident = fld.cx.ident_of("None");
|
||||
|
||||
let local_path = cx.path_ident(span, local_ident);
|
||||
let some_path = cx.path_ident(span, cx.ident_of("Some"));
|
||||
let local_path = fld.cx.path_ident(span, local_ident);
|
||||
let some_path = fld.cx.path_ident(span, fld.cx.ident_of("Some"));
|
||||
|
||||
// `let i = &mut <src_expr>`
|
||||
let iter_decl_stmt = cx.stmt_let(span, false, local_ident,
|
||||
cx.expr_mut_addr_of(span, src_expr));
|
||||
let iter_decl_stmt = fld.cx.stmt_let(span, false, local_ident,
|
||||
fld.cx.expr_mut_addr_of(span, src_expr));
|
||||
|
||||
// `None => break ['<ident>];`
|
||||
let none_arm = {
|
||||
// FIXME #6993: this map goes away:
|
||||
let break_expr = cx.expr(span, ast::ExprBreak(opt_ident.map(|x| x.name)));
|
||||
let none_pat = cx.pat_ident(span, none_ident);
|
||||
cx.arm(span, ~[none_pat], break_expr)
|
||||
let break_expr = fld.cx.expr(span, ast::ExprBreak(opt_ident.map(|x| x.name)));
|
||||
let none_pat = fld.cx.pat_ident(span, none_ident);
|
||||
fld.cx.arm(span, ~[none_pat], break_expr)
|
||||
};
|
||||
|
||||
// `Some(<src_pat>) => <src_loop_block>`
|
||||
let some_arm =
|
||||
cx.arm(span,
|
||||
~[cx.pat_enum(span, some_path, ~[src_pat])],
|
||||
cx.expr_block(src_loop_block));
|
||||
fld.cx.arm(span,
|
||||
~[fld.cx.pat_enum(span, some_path, ~[src_pat])],
|
||||
fld.cx.expr_block(src_loop_block));
|
||||
|
||||
// `match i.next() { ... }`
|
||||
let match_expr = {
|
||||
let next_call_expr =
|
||||
cx.expr_method_call(span, cx.expr_path(local_path), next_ident, ~[]);
|
||||
fld.cx.expr_method_call(span, fld.cx.expr_path(local_path), next_ident, ~[]);
|
||||
|
||||
cx.expr_match(span, next_call_expr, ~[none_arm, some_arm])
|
||||
fld.cx.expr_match(span, next_call_expr, ~[none_arm, some_arm])
|
||||
};
|
||||
|
||||
// ['ident:] loop { ... }
|
||||
let loop_expr = cx.expr(span,
|
||||
ast::ExprLoop(cx.block_expr(match_expr), opt_ident));
|
||||
let loop_expr = fld.cx.expr(span,
|
||||
ast::ExprLoop(fld.cx.block_expr(match_expr),
|
||||
opt_ident));
|
||||
|
||||
// `{ let ... ; loop { ... } }`
|
||||
let block = cx.block(span,
|
||||
~[iter_decl_stmt],
|
||||
Some(loop_expr));
|
||||
let block = fld.cx.block(span,
|
||||
~[iter_decl_stmt],
|
||||
Some(loop_expr));
|
||||
|
||||
@ast::Expr {
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
|
@ -213,11 +210,7 @@ pub fn expand_expr(extsbox: @mut SyntaxEnv,
|
|||
//
|
||||
// NB: there is some redundancy between this and expand_item, below, and
|
||||
// they might benefit from some amount of semantic and language-UI merger.
|
||||
pub fn expand_mod_items(extsbox: @mut SyntaxEnv,
|
||||
cx: @ExtCtxt,
|
||||
module_: &ast::_mod,
|
||||
fld: &MacroExpander)
|
||||
-> ast::_mod {
|
||||
pub fn expand_mod_items(module_: &ast::_mod, fld: &mut MacroExpander) -> ast::_mod {
|
||||
// Fold the contents first:
|
||||
let module_ = noop_fold_mod(module_, fld);
|
||||
|
||||
|
@ -228,9 +221,9 @@ pub fn expand_mod_items(extsbox: @mut SyntaxEnv,
|
|||
item.attrs.rev_iter().fold(~[*item], |items, attr| {
|
||||
let mname = attr.name();
|
||||
|
||||
match (*extsbox).find(&intern(mname)) {
|
||||
match (*fld.extsbox).find(&intern(mname)) {
|
||||
Some(@SE(ItemDecorator(dec_fn))) => {
|
||||
cx.bt_push(ExpnInfo {
|
||||
fld.cx.bt_push(ExpnInfo {
|
||||
call_site: attr.span,
|
||||
callee: NameAndSpan {
|
||||
name: mname,
|
||||
|
@ -238,8 +231,8 @@ pub fn expand_mod_items(extsbox: @mut SyntaxEnv,
|
|||
span: None
|
||||
}
|
||||
});
|
||||
let r = dec_fn(cx, attr.span, attr.node.value, items);
|
||||
cx.bt_pop();
|
||||
let r = dec_fn(fld.cx, attr.span, attr.node.value, items);
|
||||
fld.cx.bt_pop();
|
||||
r
|
||||
},
|
||||
_ => items,
|
||||
|
@ -270,20 +263,17 @@ macro_rules! with_exts_frame (
|
|||
static special_block_name : &'static str = " block";
|
||||
|
||||
// When we enter a module, record it, for the sake of `module!`
|
||||
pub fn expand_item(extsbox: @mut SyntaxEnv,
|
||||
cx: @ExtCtxt,
|
||||
it: @ast::item,
|
||||
fld: &MacroExpander)
|
||||
pub fn expand_item(it: @ast::item, fld: &mut MacroExpander)
|
||||
-> SmallVector<@ast::item> {
|
||||
match it.node {
|
||||
ast::item_mac(..) => expand_item_mac(extsbox, cx, it, fld),
|
||||
ast::item_mac(..) => expand_item_mac(it, fld),
|
||||
ast::item_mod(_) | ast::item_foreign_mod(_) => {
|
||||
cx.mod_push(it.ident);
|
||||
fld.cx.mod_push(it.ident);
|
||||
let macro_escape = contains_macro_escape(it.attrs);
|
||||
let result = with_exts_frame!(extsbox,
|
||||
let result = with_exts_frame!(fld.extsbox,
|
||||
macro_escape,
|
||||
noop_fold_item(it, fld));
|
||||
cx.mod_pop();
|
||||
fld.cx.mod_pop();
|
||||
result
|
||||
},
|
||||
_ => noop_fold_item(it, fld)
|
||||
|
@ -297,10 +287,7 @@ pub fn contains_macro_escape(attrs: &[ast::Attribute]) -> bool {
|
|||
|
||||
// Support for item-position macro invocations, exactly the same
|
||||
// logic as for expression-position macro invocations.
|
||||
pub fn expand_item_mac(extsbox: @mut SyntaxEnv,
|
||||
cx: @ExtCtxt,
|
||||
it: @ast::item,
|
||||
fld: &MacroExpander)
|
||||
pub fn expand_item_mac(it: @ast::item, fld: &mut MacroExpander)
|
||||
-> SmallVector<@ast::item> {
|
||||
let (pth, tts, ctxt) = match it.node {
|
||||
item_mac(codemap::Spanned {
|
||||
|
@ -309,24 +296,24 @@ pub fn expand_item_mac(extsbox: @mut SyntaxEnv,
|
|||
}) => {
|
||||
(pth, (*tts).clone(), ctxt)
|
||||
}
|
||||
_ => cx.span_bug(it.span, "invalid item macro invocation")
|
||||
_ => fld.cx.span_bug(it.span, "invalid item macro invocation")
|
||||
};
|
||||
|
||||
let extname = &pth.segments[0].identifier;
|
||||
let extnamestr = ident_to_str(extname);
|
||||
let fm = fresh_mark();
|
||||
let expanded = match (*extsbox).find(&extname.name) {
|
||||
None => cx.span_fatal(pth.span,
|
||||
format!("macro undefined: '{}!'", extnamestr)),
|
||||
let expanded = match (*fld.extsbox).find(&extname.name) {
|
||||
None => fld.cx.span_fatal(pth.span,
|
||||
format!("macro undefined: '{}!'", extnamestr)),
|
||||
|
||||
Some(@SE(NormalTT(expander, span))) => {
|
||||
if it.ident.name != parse::token::special_idents::invalid.name {
|
||||
cx.span_fatal(pth.span,
|
||||
format!("macro {}! expects no ident argument, \
|
||||
given '{}'", extnamestr,
|
||||
ident_to_str(&it.ident)));
|
||||
fld.cx.span_fatal(pth.span,
|
||||
format!("macro {}! expects no ident argument, \
|
||||
given '{}'", extnamestr,
|
||||
ident_to_str(&it.ident)));
|
||||
}
|
||||
cx.bt_push(ExpnInfo {
|
||||
fld.cx.bt_push(ExpnInfo {
|
||||
call_site: it.span,
|
||||
callee: NameAndSpan {
|
||||
name: extnamestr,
|
||||
|
@ -337,15 +324,15 @@ pub fn expand_item_mac(extsbox: @mut SyntaxEnv,
|
|||
// mark before expansion:
|
||||
let marked_before = mark_tts(tts,fm);
|
||||
let marked_ctxt = new_mark(fm,ctxt);
|
||||
expander.expand(cx, it.span, marked_before, marked_ctxt)
|
||||
expander.expand(fld.cx, it.span, marked_before, marked_ctxt)
|
||||
}
|
||||
Some(@SE(IdentTT(expander, span))) => {
|
||||
if it.ident.name == parse::token::special_idents::invalid.name {
|
||||
cx.span_fatal(pth.span,
|
||||
format!("macro {}! expects an ident argument",
|
||||
extnamestr));
|
||||
fld.cx.span_fatal(pth.span,
|
||||
format!("macro {}! expects an ident argument",
|
||||
extnamestr));
|
||||
}
|
||||
cx.bt_push(ExpnInfo {
|
||||
fld.cx.bt_push(ExpnInfo {
|
||||
call_site: it.span,
|
||||
callee: NameAndSpan {
|
||||
name: extnamestr,
|
||||
|
@ -356,10 +343,11 @@ pub fn expand_item_mac(extsbox: @mut SyntaxEnv,
|
|||
// mark before expansion:
|
||||
let marked_tts = mark_tts(tts,fm);
|
||||
let marked_ctxt = new_mark(fm,ctxt);
|
||||
expander.expand(cx, it.span, it.ident, marked_tts, marked_ctxt)
|
||||
expander.expand(fld.cx, it.span, it.ident, marked_tts, marked_ctxt)
|
||||
}
|
||||
_ => cx.span_fatal(
|
||||
it.span, format!("{}! is not legal in item position", extnamestr))
|
||||
_ => fld.cx.span_fatal(it.span,
|
||||
format!("{}! is not legal in item position",
|
||||
extnamestr))
|
||||
};
|
||||
|
||||
let items = match expanded {
|
||||
|
@ -369,7 +357,8 @@ pub fn expand_item_mac(extsbox: @mut SyntaxEnv,
|
|||
.collect()
|
||||
}
|
||||
MRExpr(_) => {
|
||||
cx.span_fatal(pth.span, format!("expr macro in item position: {}", extnamestr))
|
||||
fld.cx.span_fatal(pth.span, format!("expr macro in item position: {}",
|
||||
extnamestr))
|
||||
}
|
||||
MRAny(any_macro) => {
|
||||
any_macro.make_items().move_iter()
|
||||
|
@ -380,11 +369,11 @@ pub fn expand_item_mac(extsbox: @mut SyntaxEnv,
|
|||
MRDef(ref mdef) => {
|
||||
// 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.
|
||||
insert_macro(*extsbox,intern(mdef.name), @SE((*mdef).ext));
|
||||
insert_macro(*fld.extsbox,intern(mdef.name), @SE((*mdef).ext));
|
||||
SmallVector::zero()
|
||||
}
|
||||
};
|
||||
cx.bt_pop();
|
||||
fld.cx.bt_pop();
|
||||
return items;
|
||||
}
|
||||
|
||||
|
@ -406,11 +395,7 @@ fn insert_macro(exts: SyntaxEnv, name: ast::Name, transformer: @Transformer) {
|
|||
}
|
||||
|
||||
// expand a stmt
|
||||
pub fn expand_stmt(extsbox: @mut SyntaxEnv,
|
||||
cx: @ExtCtxt,
|
||||
s: &Stmt,
|
||||
fld: &MacroExpander)
|
||||
-> SmallVector<@Stmt> {
|
||||
pub fn expand_stmt(s: &Stmt, fld: &mut MacroExpander) -> SmallVector<@Stmt> {
|
||||
// why the copying here and not in expand_expr?
|
||||
// looks like classic changed-in-only-one-place
|
||||
let (pth, tts, semi, ctxt) = match s.node {
|
||||
|
@ -421,21 +406,21 @@ pub fn expand_stmt(extsbox: @mut SyntaxEnv,
|
|||
}
|
||||
}
|
||||
}
|
||||
_ => return expand_non_macro_stmt(*extsbox, s, fld)
|
||||
_ => return expand_non_macro_stmt(s, fld)
|
||||
};
|
||||
if (pth.segments.len() > 1u) {
|
||||
cx.span_fatal(pth.span,
|
||||
"expected macro name without module separators");
|
||||
fld.cx.span_fatal(pth.span,
|
||||
"expected macro name without module separators");
|
||||
}
|
||||
let extname = &pth.segments[0].identifier;
|
||||
let extnamestr = ident_to_str(extname);
|
||||
let fully_expanded: SmallVector<@Stmt> = match (*extsbox).find(&extname.name) {
|
||||
let fully_expanded: SmallVector<@Stmt> = match (*fld.extsbox).find(&extname.name) {
|
||||
None => {
|
||||
cx.span_fatal(pth.span, format!("macro undefined: '{}'", extnamestr))
|
||||
fld.cx.span_fatal(pth.span, format!("macro undefined: '{}'", extnamestr))
|
||||
}
|
||||
|
||||
Some(@SE(NormalTT(expandfun, exp_span))) => {
|
||||
cx.bt_push(ExpnInfo {
|
||||
fld.cx.bt_push(ExpnInfo {
|
||||
call_site: s.span,
|
||||
callee: NameAndSpan {
|
||||
name: extnamestr,
|
||||
|
@ -450,9 +435,9 @@ pub fn expand_stmt(extsbox: @mut SyntaxEnv,
|
|||
|
||||
// See the comment in expand_expr for why we want the original span,
|
||||
// not the current mac.span.
|
||||
let mac_span = original_span(cx);
|
||||
let mac_span = original_span(fld.cx);
|
||||
|
||||
let expanded = match expandfun.expand(cx,
|
||||
let expanded = match expandfun.expand(fld.cx,
|
||||
mac_span.call_site,
|
||||
marked_tts,
|
||||
marked_ctxt) {
|
||||
|
@ -463,7 +448,7 @@ pub fn expand_stmt(extsbox: @mut SyntaxEnv,
|
|||
}
|
||||
}
|
||||
MRAny(any_macro) => any_macro.make_stmt(),
|
||||
_ => cx.span_fatal(
|
||||
_ => fld.cx.span_fatal(
|
||||
pth.span,
|
||||
format!("non-stmt macro in stmt pos: {}", extnamestr))
|
||||
};
|
||||
|
@ -472,18 +457,19 @@ pub fn expand_stmt(extsbox: @mut SyntaxEnv,
|
|||
// Keep going, outside-in.
|
||||
let fully_expanded = fld.fold_stmt(marked_after);
|
||||
if fully_expanded.is_empty() {
|
||||
cx.span_fatal(pth.span,
|
||||
fld.cx.span_fatal(pth.span,
|
||||
"macro didn't expand to a statement");
|
||||
}
|
||||
cx.bt_pop();
|
||||
fld.cx.bt_pop();
|
||||
fully_expanded.move_iter()
|
||||
.map(|s| @Spanned { span: s.span, node: s.node.clone() })
|
||||
.collect()
|
||||
}
|
||||
|
||||
_ => {
|
||||
cx.span_fatal(pth.span,
|
||||
format!("'{}' is not a tt-style macro", extnamestr))
|
||||
fld.cx.span_fatal(pth.span,
|
||||
format!("'{}' is not a tt-style macro",
|
||||
extnamestr))
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -502,7 +488,7 @@ pub fn expand_stmt(extsbox: @mut SyntaxEnv,
|
|||
|
||||
// expand a non-macro stmt. this is essentially the fallthrough for
|
||||
// expand_stmt, above.
|
||||
fn expand_non_macro_stmt(exts: SyntaxEnv, s: &Stmt, fld: &MacroExpander)
|
||||
fn expand_non_macro_stmt(s: &Stmt, fld: &mut MacroExpander)
|
||||
-> SmallVector<@Stmt> {
|
||||
// is it a let?
|
||||
match s.node {
|
||||
|
@ -511,7 +497,7 @@ fn expand_non_macro_stmt(exts: SyntaxEnv, s: &Stmt, fld: &MacroExpander)
|
|||
span: stmt_span
|
||||
},
|
||||
node_id) => {
|
||||
let block_info = get_block_info(exts);
|
||||
let block_info = get_block_info(*fld.extsbox);
|
||||
let pending_renames = block_info.pending_renames;
|
||||
|
||||
// take it apart:
|
||||
|
@ -536,7 +522,7 @@ fn expand_non_macro_stmt(exts: SyntaxEnv, s: &Stmt, fld: &MacroExpander)
|
|||
let new_name = fresh_name(ident);
|
||||
new_pending_renames.push((*ident,new_name));
|
||||
}
|
||||
let rename_fld = renames_to_fold(new_pending_renames);
|
||||
let mut rename_fld = renames_to_fold(new_pending_renames);
|
||||
// rewrite the pattern using the new names (the old ones
|
||||
// have already been applied):
|
||||
let rewritten_pat = rename_fld.fold_pat(expanded_pat);
|
||||
|
@ -624,22 +610,17 @@ pub fn new_name_finder(idents: ~[ast::Ident]) -> NewNameFinderContext {
|
|||
}
|
||||
|
||||
// expand a block. pushes a new exts_frame, then calls expand_block_elts
|
||||
pub fn expand_block(extsbox: @mut SyntaxEnv,
|
||||
_: @ExtCtxt,
|
||||
blk: &Block,
|
||||
fld: &MacroExpander)
|
||||
-> P<Block> {
|
||||
pub fn expand_block(blk: &Block, fld: &mut MacroExpander) -> P<Block> {
|
||||
// see note below about treatment of exts table
|
||||
with_exts_frame!(extsbox,false,
|
||||
expand_block_elts(*extsbox, blk, fld))
|
||||
with_exts_frame!(fld.extsbox,false,
|
||||
expand_block_elts(blk, fld))
|
||||
}
|
||||
|
||||
// expand the elements of a block.
|
||||
pub fn expand_block_elts(exts: SyntaxEnv, b: &Block, fld: &MacroExpander)
|
||||
-> P<Block> {
|
||||
let block_info = get_block_info(exts);
|
||||
pub fn expand_block_elts(b: &Block, fld: &mut MacroExpander) -> P<Block> {
|
||||
let block_info = get_block_info(*fld.extsbox);
|
||||
let pending_renames = block_info.pending_renames;
|
||||
let rename_fld = renames_to_fold(pending_renames);
|
||||
let mut rename_fld = renames_to_fold(pending_renames);
|
||||
let new_view_items = b.view_items.map(|x| fld.fold_view_item(x));
|
||||
let new_stmts = b.stmts.iter()
|
||||
.map(|x| rename_fld.fold_stmt(*x)
|
||||
|
@ -671,7 +652,7 @@ struct IdentRenamer {
|
|||
}
|
||||
|
||||
impl ast_fold for IdentRenamer {
|
||||
fn fold_ident(&self, id: ast::Ident) -> ast::Ident {
|
||||
fn fold_ident(&mut self, id: ast::Ident) -> ast::Ident {
|
||||
let new_ctxt = self.renames.iter().fold(id.ctxt, |ctxt, &(from, to)| {
|
||||
new_rename(from, to, ctxt)
|
||||
});
|
||||
|
@ -684,13 +665,13 @@ impl ast_fold for IdentRenamer {
|
|||
|
||||
// given a mutable list of renames, return a tree-folder that applies those
|
||||
// renames.
|
||||
pub fn renames_to_fold(renames: @mut ~[(ast::Ident,ast::Name)]) -> @ast_fold {
|
||||
@IdentRenamer {
|
||||
pub fn renames_to_fold(renames: @mut ~[(ast::Ident,ast::Name)]) -> IdentRenamer {
|
||||
IdentRenamer {
|
||||
renames: renames,
|
||||
} as @ast_fold
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_span(cx: @ExtCtxt, sp: Span) -> Span {
|
||||
pub fn new_span(cx: &ExtCtxt, sp: Span) -> Span {
|
||||
/* this discards information in the case of macro-defining macros */
|
||||
Span {
|
||||
lo: sp.lo,
|
||||
|
@ -917,7 +898,7 @@ struct Injector {
|
|||
}
|
||||
|
||||
impl ast_fold for Injector {
|
||||
fn fold_mod(&self, module: &ast::_mod) -> ast::_mod {
|
||||
fn fold_mod(&mut self, module: &ast::_mod) -> ast::_mod {
|
||||
// Just inject the standard macros at the start of the first module
|
||||
// in the crate: that is, at the start of the crate file itself.
|
||||
let items = vec::append(~[ self.sm ], module.items);
|
||||
|
@ -943,54 +924,39 @@ pub fn inject_std_macros(parse_sess: @mut parse::ParseSess,
|
|||
None => fail!("expected core macros to parse correctly")
|
||||
};
|
||||
|
||||
let injector = @Injector {
|
||||
let mut injector = Injector {
|
||||
sm: sm,
|
||||
} as @ast_fold;
|
||||
};
|
||||
injector.fold_crate(c)
|
||||
}
|
||||
|
||||
pub struct MacroExpander {
|
||||
pub struct MacroExpander<'a> {
|
||||
extsbox: @mut SyntaxEnv,
|
||||
cx: @ExtCtxt,
|
||||
cx: &'a mut ExtCtxt,
|
||||
}
|
||||
|
||||
impl ast_fold for MacroExpander {
|
||||
fn fold_expr(&self, expr: @ast::Expr) -> @ast::Expr {
|
||||
expand_expr(self.extsbox,
|
||||
self.cx,
|
||||
expr,
|
||||
self)
|
||||
impl<'a> ast_fold for MacroExpander<'a> {
|
||||
fn fold_expr(&mut self, expr: @ast::Expr) -> @ast::Expr {
|
||||
expand_expr(expr, self)
|
||||
}
|
||||
|
||||
fn fold_mod(&self, module: &ast::_mod) -> ast::_mod {
|
||||
expand_mod_items(self.extsbox,
|
||||
self.cx,
|
||||
module,
|
||||
self)
|
||||
fn fold_mod(&mut self, module: &ast::_mod) -> ast::_mod {
|
||||
expand_mod_items(module, self)
|
||||
}
|
||||
|
||||
fn fold_item(&self, item: @ast::item) -> SmallVector<@ast::item> {
|
||||
expand_item(self.extsbox,
|
||||
self.cx,
|
||||
item,
|
||||
self)
|
||||
fn fold_item(&mut self, item: @ast::item) -> SmallVector<@ast::item> {
|
||||
expand_item(item, self)
|
||||
}
|
||||
|
||||
fn fold_stmt(&self, stmt: &ast::Stmt) -> SmallVector<@ast::Stmt> {
|
||||
expand_stmt(self.extsbox,
|
||||
self.cx,
|
||||
stmt,
|
||||
self)
|
||||
fn fold_stmt(&mut self, stmt: &ast::Stmt) -> SmallVector<@ast::Stmt> {
|
||||
expand_stmt(stmt, self)
|
||||
}
|
||||
|
||||
fn fold_block(&self, block: P<Block>) -> P<Block> {
|
||||
expand_block(self.extsbox,
|
||||
self.cx,
|
||||
block,
|
||||
self)
|
||||
fn fold_block(&mut self, block: P<Block>) -> P<Block> {
|
||||
expand_block(block, self)
|
||||
}
|
||||
|
||||
fn new_span(&self, span: Span) -> Span {
|
||||
fn new_span(&mut self, span: Span) -> Span {
|
||||
new_span(self.cx, span)
|
||||
}
|
||||
}
|
||||
|
@ -1004,11 +970,11 @@ pub fn expand_crate(parse_sess: @mut parse::ParseSess,
|
|||
// exts table through the fold, but that would require updating
|
||||
// every method/element of AstFoldFns in fold.rs.
|
||||
let extsbox = syntax_expander_table();
|
||||
let cx = ExtCtxt::new(parse_sess, cfg.clone());
|
||||
let expander = @MacroExpander {
|
||||
let mut cx = ExtCtxt::new(parse_sess, cfg.clone());
|
||||
let mut expander = MacroExpander {
|
||||
extsbox: @mut extsbox,
|
||||
cx: cx,
|
||||
} as @ast_fold;
|
||||
cx: &mut cx,
|
||||
};
|
||||
|
||||
let ret = expander.fold_crate(c);
|
||||
parse_sess.span_diagnostic.handler().abort_if_errors();
|
||||
|
@ -1081,7 +1047,7 @@ pub struct ContextWrapper {
|
|||
}
|
||||
|
||||
impl ast_fold for ContextWrapper {
|
||||
fn fold_ident(&self, id: ast::Ident) -> ast::Ident {
|
||||
fn fold_ident(&mut self, id: ast::Ident) -> ast::Ident {
|
||||
let ast::Ident {
|
||||
name,
|
||||
ctxt
|
||||
|
@ -1091,7 +1057,7 @@ impl ast_fold for ContextWrapper {
|
|||
ctxt: self.context_function.f(ctxt),
|
||||
}
|
||||
}
|
||||
fn fold_mac(&self, m: &ast::mac) -> ast::mac {
|
||||
fn fold_mac(&mut self, m: &ast::mac) -> ast::mac {
|
||||
let macro = match m.node {
|
||||
mac_invoc_tt(ref path, ref tts, ctxt) => {
|
||||
mac_invoc_tt(self.fold_path(path),
|
||||
|
@ -1108,24 +1074,24 @@ impl ast_fold for ContextWrapper {
|
|||
|
||||
// given a function from ctxts to ctxts, produce
|
||||
// an ast_fold that applies that function to all ctxts:
|
||||
pub fn fun_to_ctxt_folder<T : 'static + CtxtFn>(cf: @T) -> @ContextWrapper {
|
||||
@ContextWrapper {
|
||||
pub fn fun_to_ctxt_folder<T : 'static + CtxtFn>(cf: @T) -> ContextWrapper {
|
||||
ContextWrapper {
|
||||
context_function: cf as @CtxtFn,
|
||||
}
|
||||
}
|
||||
|
||||
// just a convenience:
|
||||
pub fn new_mark_folder(m: Mrk) -> @ContextWrapper {
|
||||
pub fn new_mark_folder(m: Mrk) -> ContextWrapper {
|
||||
fun_to_ctxt_folder(@Marker{mark:m})
|
||||
}
|
||||
|
||||
pub fn new_rename_folder(from: ast::Ident, to: ast::Name) -> @ContextWrapper {
|
||||
pub fn new_rename_folder(from: ast::Ident, to: ast::Name) -> ContextWrapper {
|
||||
fun_to_ctxt_folder(@Renamer{from:from,to:to})
|
||||
}
|
||||
|
||||
// apply a given mark to the given token trees. Used prior to expansion of a macro.
|
||||
fn mark_tts(tts : &[token_tree], m : Mrk) -> ~[token_tree] {
|
||||
fold_tts(tts,new_mark_folder(m))
|
||||
fold_tts(tts, &mut new_mark_folder(m))
|
||||
}
|
||||
|
||||
// apply a given mark to the given expr. Used following the expansion of a macro.
|
||||
|
@ -1159,7 +1125,7 @@ pub fn mtwt_cancel_outer_mark(tts: &[ast::token_tree], ctxt: ast::SyntaxContext)
|
|||
mark_tts(tts,outer_mark)
|
||||
}
|
||||
|
||||
fn original_span(cx: @ExtCtxt) -> @codemap::ExpnInfo {
|
||||
fn original_span(cx: &ExtCtxt) -> @codemap::ExpnInfo {
|
||||
let mut relevant_info = cx.backtrace();
|
||||
let mut einfo = relevant_info.unwrap();
|
||||
loop {
|
||||
|
@ -1330,7 +1296,7 @@ mod test {
|
|||
let ident_str = @"x";
|
||||
let tts = string_to_tts(ident_str);
|
||||
let fm = fresh_mark();
|
||||
let marked_once = fold::fold_tts(tts,new_mark_folder(fm));
|
||||
let marked_once = fold::fold_tts(tts,&mut new_mark_folder(fm));
|
||||
assert_eq!(marked_once.len(),1);
|
||||
let marked_once_ctxt =
|
||||
match marked_once[0] {
|
||||
|
@ -1352,7 +1318,7 @@ mod test {
|
|||
let item_ast = string_to_crate(@"fn f() -> int { a }");
|
||||
let a_name = intern("a");
|
||||
let a2_name = gensym("a2");
|
||||
let renamer = new_rename_folder(ast::Ident{name:a_name,ctxt:EMPTY_CTXT},
|
||||
let mut renamer = new_rename_folder(ast::Ident{name:a_name,ctxt:EMPTY_CTXT},
|
||||
a2_name);
|
||||
let renamed_ast = renamer.fold_crate(item_ast.clone());
|
||||
let mut path_finder = new_path_finder(~[]);
|
||||
|
|
|
@ -15,7 +15,7 @@ use codemap::Span;
|
|||
use ext::base;
|
||||
use ext::build::AstBuilder;
|
||||
|
||||
pub fn expand_syntax_ext(ecx: @base::ExtCtxt, sp: Span,
|
||||
pub fn expand_syntax_ext(ecx: &mut base::ExtCtxt, sp: Span,
|
||||
_tts: &[ast::token_tree]) -> base::MacResult {
|
||||
ecx.span_err(sp, "`fmt!` is deprecated, use `format!` instead");
|
||||
ecx.parse_sess.span_diagnostic.span_note(sp,
|
||||
|
|
|
@ -28,8 +28,8 @@ enum ArgumentType {
|
|||
String,
|
||||
}
|
||||
|
||||
struct Context {
|
||||
ecx: @ExtCtxt,
|
||||
struct Context<'a> {
|
||||
ecx: &'a mut ExtCtxt,
|
||||
fmtsp: Span,
|
||||
|
||||
// Parsed argument expressions and the types that we've found so far for
|
||||
|
@ -50,7 +50,7 @@ struct Context {
|
|||
next_arg: uint,
|
||||
}
|
||||
|
||||
impl Context {
|
||||
impl<'a> Context<'a> {
|
||||
/// Parses the arguments from the given list of tokens, returning None if
|
||||
/// there's a parse error so we can continue parsing other format! expressions.
|
||||
fn parse_args(&mut self, sp: Span,
|
||||
|
@ -722,7 +722,7 @@ impl Context {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn expand_args(ecx: @ExtCtxt, sp: Span,
|
||||
pub fn expand_args(ecx: &mut ExtCtxt, sp: Span,
|
||||
tts: &[ast::token_tree]) -> base::MacResult {
|
||||
let mut cx = Context {
|
||||
ecx: ecx,
|
||||
|
@ -739,19 +739,20 @@ pub fn expand_args(ecx: @ExtCtxt, sp: Span,
|
|||
};
|
||||
let (extra, efmt) = match cx.parse_args(sp, tts) {
|
||||
(extra, Some(e)) => (extra, e),
|
||||
(_, None) => { return MRExpr(ecx.expr_uint(sp, 2)); }
|
||||
(_, None) => { return MRExpr(cx.ecx.expr_uint(sp, 2)); }
|
||||
};
|
||||
cx.fmtsp = efmt.span;
|
||||
// Be sure to recursively expand macros just in case the format string uses
|
||||
// a macro to build the format expression.
|
||||
let (fmt, _) = expr_to_str(ecx, ecx.expand_expr(efmt),
|
||||
let expr = cx.ecx.expand_expr(efmt);
|
||||
let (fmt, _) = expr_to_str(cx.ecx, expr,
|
||||
"format argument must be a string literal.");
|
||||
|
||||
let mut err = false;
|
||||
parse::parse_error::cond.trap(|m| {
|
||||
if !err {
|
||||
err = true;
|
||||
ecx.span_err(efmt.span, m);
|
||||
cx.ecx.span_err(efmt.span, m);
|
||||
}
|
||||
}).inside(|| {
|
||||
for piece in parse::Parser::new(fmt) {
|
||||
|
@ -767,12 +768,12 @@ pub fn expand_args(ecx: @ExtCtxt, sp: Span,
|
|||
// Make sure that all arguments were used and all arguments have types.
|
||||
for (i, ty) in cx.arg_types.iter().enumerate() {
|
||||
if ty.is_none() {
|
||||
ecx.span_err(cx.args[i].span, "argument never used");
|
||||
cx.ecx.span_err(cx.args[i].span, "argument never used");
|
||||
}
|
||||
}
|
||||
for (name, e) in cx.names.iter() {
|
||||
if !cx.name_types.contains_key(name) {
|
||||
ecx.span_err(e.span, "named argument never used");
|
||||
cx.ecx.span_err(e.span, "named argument never used");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ use ext::base;
|
|||
use print;
|
||||
use parse::token::{get_ident_interner};
|
||||
|
||||
pub fn expand_syntax_ext(cx: @ExtCtxt,
|
||||
pub fn expand_syntax_ext(cx: &mut ExtCtxt,
|
||||
sp: codemap::Span,
|
||||
tt: &[ast::token_tree])
|
||||
-> base::MacResult {
|
||||
|
|
|
@ -40,11 +40,11 @@ pub mod rt {
|
|||
pub use codemap::{BytePos, Span, dummy_spanned};
|
||||
|
||||
pub trait ToTokens {
|
||||
fn to_tokens(&self, _cx: @ExtCtxt) -> ~[token_tree];
|
||||
fn to_tokens(&self, _cx: &ExtCtxt) -> ~[token_tree];
|
||||
}
|
||||
|
||||
impl ToTokens for ~[token_tree] {
|
||||
fn to_tokens(&self, _cx: @ExtCtxt) -> ~[token_tree] {
|
||||
fn to_tokens(&self, _cx: &ExtCtxt) -> ~[token_tree] {
|
||||
(*self).clone()
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ pub mod rt {
|
|||
pub fn to_source() -> ~str;
|
||||
|
||||
// If you can make source, you can definitely make tokens.
|
||||
pub fn to_tokens(cx: @ExtCtxt) -> ~[token_tree] {
|
||||
pub fn to_tokens(cx: &ExtCtxt) -> ~[token_tree] {
|
||||
cx.parse_tts(self.to_source())
|
||||
}
|
||||
}
|
||||
|
@ -199,7 +199,7 @@ pub mod rt {
|
|||
macro_rules! impl_to_tokens(
|
||||
($t:ty) => (
|
||||
impl ToTokens for $t {
|
||||
fn to_tokens(&self, cx: @ExtCtxt) -> ~[token_tree] {
|
||||
fn to_tokens(&self, cx: &ExtCtxt) -> ~[token_tree] {
|
||||
cx.parse_tts(self.to_source())
|
||||
}
|
||||
}
|
||||
|
@ -209,7 +209,7 @@ pub mod rt {
|
|||
macro_rules! impl_to_tokens_self(
|
||||
($t:ty) => (
|
||||
impl<'a> ToTokens for $t {
|
||||
fn to_tokens(&self, cx: @ExtCtxt) -> ~[token_tree] {
|
||||
fn to_tokens(&self, cx: &ExtCtxt) -> ~[token_tree] {
|
||||
cx.parse_tts(self.to_source())
|
||||
}
|
||||
}
|
||||
|
@ -289,7 +289,7 @@ pub mod rt {
|
|||
|
||||
}
|
||||
|
||||
pub fn expand_quote_tokens(cx: @ExtCtxt,
|
||||
pub fn expand_quote_tokens(cx: &mut ExtCtxt,
|
||||
sp: Span,
|
||||
tts: &[ast::token_tree]) -> base::MacResult {
|
||||
let (cx_expr, expr) = expand_tts(cx, sp, tts);
|
||||
|
@ -297,14 +297,14 @@ pub fn expand_quote_tokens(cx: @ExtCtxt,
|
|||
base::MRExpr(expanded)
|
||||
}
|
||||
|
||||
pub fn expand_quote_expr(cx: @ExtCtxt,
|
||||
pub fn expand_quote_expr(cx: &mut ExtCtxt,
|
||||
sp: Span,
|
||||
tts: &[ast::token_tree]) -> base::MacResult {
|
||||
let expanded = expand_parse_call(cx, sp, "parse_expr", ~[], tts);
|
||||
base::MRExpr(expanded)
|
||||
}
|
||||
|
||||
pub fn expand_quote_item(cx: @ExtCtxt,
|
||||
pub fn expand_quote_item(cx: &mut ExtCtxt,
|
||||
sp: Span,
|
||||
tts: &[ast::token_tree]) -> base::MacResult {
|
||||
let e_attrs = cx.expr_vec_uniq(sp, ~[]);
|
||||
|
@ -313,7 +313,7 @@ pub fn expand_quote_item(cx: @ExtCtxt,
|
|||
base::MRExpr(expanded)
|
||||
}
|
||||
|
||||
pub fn expand_quote_pat(cx: @ExtCtxt,
|
||||
pub fn expand_quote_pat(cx: &mut ExtCtxt,
|
||||
sp: Span,
|
||||
tts: &[ast::token_tree]) -> base::MacResult {
|
||||
let e_refutable = cx.expr_lit(sp, ast::lit_bool(true));
|
||||
|
@ -322,7 +322,7 @@ pub fn expand_quote_pat(cx: @ExtCtxt,
|
|||
base::MRExpr(expanded)
|
||||
}
|
||||
|
||||
pub fn expand_quote_ty(cx: @ExtCtxt,
|
||||
pub fn expand_quote_ty(cx: &mut ExtCtxt,
|
||||
sp: Span,
|
||||
tts: &[ast::token_tree]) -> base::MacResult {
|
||||
let e_param_colons = cx.expr_lit(sp, ast::lit_bool(false));
|
||||
|
@ -331,7 +331,7 @@ pub fn expand_quote_ty(cx: @ExtCtxt,
|
|||
base::MRExpr(expanded)
|
||||
}
|
||||
|
||||
pub fn expand_quote_stmt(cx: @ExtCtxt,
|
||||
pub fn expand_quote_stmt(cx: &mut ExtCtxt,
|
||||
sp: Span,
|
||||
tts: &[ast::token_tree]) -> base::MacResult {
|
||||
let e_attrs = cx.expr_vec_uniq(sp, ~[]);
|
||||
|
@ -349,7 +349,7 @@ fn id_ext(str: &str) -> ast::Ident {
|
|||
}
|
||||
|
||||
// Lift an ident to the expr that evaluates to that ident.
|
||||
fn mk_ident(cx: @ExtCtxt, sp: Span, ident: ast::Ident) -> @ast::Expr {
|
||||
fn mk_ident(cx: &ExtCtxt, sp: Span, ident: ast::Ident) -> @ast::Expr {
|
||||
let e_str = cx.expr_str(sp, cx.str_of(ident));
|
||||
cx.expr_method_call(sp,
|
||||
cx.expr_ident(sp, id_ext("ext_cx")),
|
||||
|
@ -357,7 +357,7 @@ fn mk_ident(cx: @ExtCtxt, sp: Span, ident: ast::Ident) -> @ast::Expr {
|
|||
~[e_str])
|
||||
}
|
||||
|
||||
fn mk_binop(cx: @ExtCtxt, sp: Span, bop: token::binop) -> @ast::Expr {
|
||||
fn mk_binop(cx: &ExtCtxt, sp: Span, bop: token::binop) -> @ast::Expr {
|
||||
let name = match bop {
|
||||
PLUS => "PLUS",
|
||||
MINUS => "MINUS",
|
||||
|
@ -373,7 +373,7 @@ fn mk_binop(cx: @ExtCtxt, sp: Span, bop: token::binop) -> @ast::Expr {
|
|||
cx.expr_ident(sp, id_ext(name))
|
||||
}
|
||||
|
||||
fn mk_token(cx: @ExtCtxt, sp: Span, tok: &token::Token) -> @ast::Expr {
|
||||
fn mk_token(cx: &ExtCtxt, sp: Span, tok: &token::Token) -> @ast::Expr {
|
||||
|
||||
match *tok {
|
||||
BINOP(binop) => {
|
||||
|
@ -528,7 +528,7 @@ fn mk_token(cx: @ExtCtxt, sp: Span, tok: &token::Token) -> @ast::Expr {
|
|||
}
|
||||
|
||||
|
||||
fn mk_tt(cx: @ExtCtxt, sp: Span, tt: &ast::token_tree)
|
||||
fn mk_tt(cx: &ExtCtxt, sp: Span, tt: &ast::token_tree)
|
||||
-> ~[@ast::Stmt] {
|
||||
|
||||
match *tt {
|
||||
|
@ -570,7 +570,7 @@ fn mk_tt(cx: @ExtCtxt, sp: Span, tt: &ast::token_tree)
|
|||
}
|
||||
}
|
||||
|
||||
fn mk_tts(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
|
||||
fn mk_tts(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree])
|
||||
-> ~[@ast::Stmt] {
|
||||
let mut ss = ~[];
|
||||
for tt in tts.iter() {
|
||||
|
@ -579,7 +579,7 @@ fn mk_tts(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
|
|||
ss
|
||||
}
|
||||
|
||||
fn expand_tts(cx: @ExtCtxt,
|
||||
fn expand_tts(cx: &ExtCtxt,
|
||||
sp: Span,
|
||||
tts: &[ast::token_tree]) -> (@ast::Expr, @ast::Expr) {
|
||||
|
||||
|
@ -652,7 +652,7 @@ fn expand_tts(cx: @ExtCtxt,
|
|||
(cx_expr, block)
|
||||
}
|
||||
|
||||
fn expand_wrapper(cx: @ExtCtxt,
|
||||
fn expand_wrapper(cx: &ExtCtxt,
|
||||
sp: Span,
|
||||
cx_expr: @ast::Expr,
|
||||
expr: @ast::Expr) -> @ast::Expr {
|
||||
|
@ -667,7 +667,7 @@ fn expand_wrapper(cx: @ExtCtxt,
|
|||
cx.expr_block(cx.block_all(sp, uses, ~[stmt_let_ext_cx], Some(expr)))
|
||||
}
|
||||
|
||||
fn expand_parse_call(cx: @ExtCtxt,
|
||||
fn expand_parse_call(cx: &ExtCtxt,
|
||||
sp: Span,
|
||||
parse_method: &str,
|
||||
arg_exprs: ~[@ast::Expr],
|
||||
|
|
|
@ -28,7 +28,7 @@ use std::str;
|
|||
// a given file into the current one.
|
||||
|
||||
/* line!(): expands to the current line number */
|
||||
pub fn expand_line(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
|
||||
pub fn expand_line(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
|
||||
-> base::MacResult {
|
||||
base::check_zero_tts(cx, sp, tts, "line!");
|
||||
|
||||
|
@ -39,7 +39,7 @@ pub fn expand_line(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
|
|||
}
|
||||
|
||||
/* col!(): expands to the current column number */
|
||||
pub fn expand_col(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
|
||||
pub fn expand_col(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
|
||||
-> base::MacResult {
|
||||
base::check_zero_tts(cx, sp, tts, "col!");
|
||||
|
||||
|
@ -51,7 +51,7 @@ pub fn expand_col(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
|
|||
/* file!(): expands to the current filename */
|
||||
/* The filemap (`loc.file`) contains a bunch more information we could spit
|
||||
* out if we wanted. */
|
||||
pub fn expand_file(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
|
||||
pub fn expand_file(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
|
||||
-> base::MacResult {
|
||||
base::check_zero_tts(cx, sp, tts, "file!");
|
||||
|
||||
|
@ -61,13 +61,13 @@ pub fn expand_file(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
|
|||
base::MRExpr(cx.expr_str(topmost.call_site, filename))
|
||||
}
|
||||
|
||||
pub fn expand_stringify(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
|
||||
pub fn expand_stringify(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
|
||||
-> base::MacResult {
|
||||
let s = pprust::tts_to_str(tts, get_ident_interner());
|
||||
base::MRExpr(cx.expr_str(sp, s.to_managed()))
|
||||
}
|
||||
|
||||
pub fn expand_mod(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
|
||||
pub fn expand_mod(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
|
||||
-> base::MacResult {
|
||||
base::check_zero_tts(cx, sp, tts, "module_path!");
|
||||
base::MRExpr(cx.expr_str(sp,
|
||||
|
@ -77,7 +77,7 @@ pub fn expand_mod(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
|
|||
// include! : parse the given file as an expr
|
||||
// This is generally a bad idea because it's going to behave
|
||||
// unhygienically.
|
||||
pub fn expand_include(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
|
||||
pub fn expand_include(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
|
||||
-> base::MacResult {
|
||||
let file = get_single_str_from_tts(cx, sp, tts, "include!");
|
||||
// The file will be added to the code map by the parser
|
||||
|
@ -88,7 +88,7 @@ pub fn expand_include(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
|
|||
}
|
||||
|
||||
// include_str! : read the given file, insert it as a literal string expr
|
||||
pub fn expand_include_str(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
|
||||
pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
|
||||
-> base::MacResult {
|
||||
let file = get_single_str_from_tts(cx, sp, tts, "include_str!");
|
||||
let file = res_rel_file(cx, sp, &Path::new(file));
|
||||
|
@ -120,7 +120,7 @@ pub fn expand_include_str(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
|
|||
}
|
||||
}
|
||||
|
||||
pub fn expand_include_bin(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
|
||||
pub fn expand_include_bin(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
|
||||
-> base::MacResult
|
||||
{
|
||||
use std::at_vec;
|
||||
|
@ -167,7 +167,7 @@ fn topmost_expn_info(expn_info: @codemap::ExpnInfo) -> @codemap::ExpnInfo {
|
|||
|
||||
// resolve a file-system path to an absolute file-system path (if it
|
||||
// isn't already)
|
||||
fn res_rel_file(cx: @ExtCtxt, sp: codemap::Span, arg: &Path) -> Path {
|
||||
fn res_rel_file(cx: &mut ExtCtxt, sp: codemap::Span, arg: &Path) -> Path {
|
||||
// NB: relative paths are resolved relative to the compilation unit
|
||||
if !arg.is_absolute() {
|
||||
let mut cu = Path::new(cx.codemap().span_to_filename(sp));
|
||||
|
|
|
@ -16,7 +16,7 @@ use parse::lexer::{new_tt_reader, reader};
|
|||
use parse::parser::Parser;
|
||||
use parse::token::keywords;
|
||||
|
||||
pub fn expand_trace_macros(cx: @ExtCtxt,
|
||||
pub fn expand_trace_macros(cx: &mut ExtCtxt,
|
||||
sp: Span,
|
||||
tt: &[ast::token_tree])
|
||||
-> base::MacResult {
|
||||
|
|
|
@ -83,7 +83,7 @@ struct MacroRulesSyntaxExpanderTTFun {
|
|||
|
||||
impl SyntaxExpanderTTTrait for MacroRulesSyntaxExpanderTTFun {
|
||||
fn expand(&self,
|
||||
cx: @ExtCtxt,
|
||||
cx: &mut ExtCtxt,
|
||||
sp: Span,
|
||||
arg: &[ast::token_tree],
|
||||
_: ast::SyntaxContext)
|
||||
|
@ -93,7 +93,7 @@ impl SyntaxExpanderTTTrait for MacroRulesSyntaxExpanderTTFun {
|
|||
}
|
||||
|
||||
// Given `lhses` and `rhses`, this is the new macro we create
|
||||
fn generic_extension(cx: @ExtCtxt,
|
||||
fn generic_extension(cx: &ExtCtxt,
|
||||
sp: Span,
|
||||
name: Ident,
|
||||
arg: &[ast::token_tree],
|
||||
|
@ -168,7 +168,7 @@ fn generic_extension(cx: @ExtCtxt,
|
|||
// this procedure performs the expansion of the
|
||||
// macro_rules! macro. It parses the RHS and adds
|
||||
// an extension to the current context.
|
||||
pub fn add_new_extension(cx: @ExtCtxt,
|
||||
pub fn add_new_extension(cx: &mut ExtCtxt,
|
||||
sp: Span,
|
||||
name: Ident,
|
||||
arg: ~[ast::token_tree],
|
||||
|
|
|
@ -17,15 +17,15 @@ use util::small_vector::SmallVector;
|
|||
|
||||
// We may eventually want to be able to fold over type parameters, too.
|
||||
pub trait ast_fold {
|
||||
fn fold_crate(&self, c: Crate) -> Crate {
|
||||
fn fold_crate(&mut self, c: Crate) -> Crate {
|
||||
noop_fold_crate(c, self)
|
||||
}
|
||||
|
||||
fn fold_meta_items(&self, meta_items: &[@MetaItem]) -> ~[@MetaItem] {
|
||||
fn fold_meta_items(&mut self, meta_items: &[@MetaItem]) -> ~[@MetaItem] {
|
||||
meta_items.map(|x| fold_meta_item_(*x, self))
|
||||
}
|
||||
|
||||
fn fold_view_paths(&self, view_paths: &[@view_path]) -> ~[@view_path] {
|
||||
fn fold_view_paths(&mut self, view_paths: &[@view_path]) -> ~[@view_path] {
|
||||
view_paths.map(|view_path| {
|
||||
let inner_view_path = match view_path.node {
|
||||
view_path_simple(ref ident, ref path, node_id) => {
|
||||
|
@ -62,7 +62,7 @@ pub trait ast_fold {
|
|||
})
|
||||
}
|
||||
|
||||
fn fold_view_item(&self, vi: &view_item) -> view_item {
|
||||
fn fold_view_item(&mut self, vi: &view_item) -> view_item {
|
||||
let inner_view_item = match vi.node {
|
||||
view_item_extern_mod(ref ident,
|
||||
string,
|
||||
|
@ -85,7 +85,7 @@ pub trait ast_fold {
|
|||
}
|
||||
}
|
||||
|
||||
fn fold_foreign_item(&self, ni: @foreign_item) -> @foreign_item {
|
||||
fn fold_foreign_item(&mut self, ni: @foreign_item) -> @foreign_item {
|
||||
let fold_attribute = |x| fold_attribute_(x, self);
|
||||
|
||||
@ast::foreign_item {
|
||||
|
@ -114,11 +114,11 @@ pub trait ast_fold {
|
|||
}
|
||||
}
|
||||
|
||||
fn fold_item(&self, i: @item) -> SmallVector<@item> {
|
||||
fn fold_item(&mut self, i: @item) -> SmallVector<@item> {
|
||||
noop_fold_item(i, self)
|
||||
}
|
||||
|
||||
fn fold_struct_field(&self, sf: &struct_field) -> struct_field {
|
||||
fn fold_struct_field(&mut self, sf: &struct_field) -> struct_field {
|
||||
let fold_attribute = |x| fold_attribute_(x, self);
|
||||
|
||||
Spanned {
|
||||
|
@ -132,15 +132,15 @@ pub trait ast_fold {
|
|||
}
|
||||
}
|
||||
|
||||
fn fold_item_underscore(&self, i: &item_) -> item_ {
|
||||
fn fold_item_underscore(&mut self, i: &item_) -> item_ {
|
||||
noop_fold_item_underscore(i, self)
|
||||
}
|
||||
|
||||
fn fold_type_method(&self, m: &TypeMethod) -> TypeMethod {
|
||||
fn fold_type_method(&mut self, m: &TypeMethod) -> TypeMethod {
|
||||
noop_fold_type_method(m, self)
|
||||
}
|
||||
|
||||
fn fold_method(&self, m: @method) -> @method {
|
||||
fn fold_method(&mut self, m: @method) -> @method {
|
||||
@ast::method {
|
||||
ident: self.fold_ident(m.ident),
|
||||
attrs: m.attrs.map(|a| fold_attribute_(*a, self)),
|
||||
|
@ -156,15 +156,15 @@ pub trait ast_fold {
|
|||
}
|
||||
}
|
||||
|
||||
fn fold_block(&self, b: P<Block>) -> P<Block> {
|
||||
fn fold_block(&mut self, b: P<Block>) -> P<Block> {
|
||||
noop_fold_block(b, self)
|
||||
}
|
||||
|
||||
fn fold_stmt(&self, s: &Stmt) -> SmallVector<@Stmt> {
|
||||
fn fold_stmt(&mut self, s: &Stmt) -> SmallVector<@Stmt> {
|
||||
noop_fold_stmt(s, self)
|
||||
}
|
||||
|
||||
fn fold_arm(&self, a: &Arm) -> Arm {
|
||||
fn fold_arm(&mut self, a: &Arm) -> Arm {
|
||||
Arm {
|
||||
pats: a.pats.map(|x| self.fold_pat(*x)),
|
||||
guard: a.guard.map(|x| self.fold_expr(x)),
|
||||
|
@ -172,7 +172,7 @@ pub trait ast_fold {
|
|||
}
|
||||
}
|
||||
|
||||
fn fold_pat(&self, p: @Pat) -> @Pat {
|
||||
fn fold_pat(&mut self, p: @Pat) -> @Pat {
|
||||
let node = match p.node {
|
||||
PatWild => PatWild,
|
||||
PatWildMulti => PatWildMulti,
|
||||
|
@ -217,7 +217,7 @@ pub trait ast_fold {
|
|||
}
|
||||
}
|
||||
|
||||
fn fold_decl(&self, d: @Decl) -> SmallVector<@Decl> {
|
||||
fn fold_decl(&mut self, d: @Decl) -> SmallVector<@Decl> {
|
||||
let node = match d.node {
|
||||
DeclLocal(ref l) => SmallVector::one(DeclLocal(self.fold_local(*l))),
|
||||
DeclItem(it) => {
|
||||
|
@ -233,11 +233,11 @@ pub trait ast_fold {
|
|||
}).collect()
|
||||
}
|
||||
|
||||
fn fold_expr(&self, e: @Expr) -> @Expr {
|
||||
fn fold_expr(&mut self, e: @Expr) -> @Expr {
|
||||
noop_fold_expr(e, self)
|
||||
}
|
||||
|
||||
fn fold_ty(&self, t: P<Ty>) -> P<Ty> {
|
||||
fn fold_ty(&mut self, t: P<Ty>) -> P<Ty> {
|
||||
let node = match t.node {
|
||||
ty_nil | ty_bot | ty_infer => t.node.clone(),
|
||||
ty_box(ref mt) => ty_box(fold_mt(mt, self)),
|
||||
|
@ -284,11 +284,11 @@ pub trait ast_fold {
|
|||
})
|
||||
}
|
||||
|
||||
fn fold_mod(&self, m: &_mod) -> _mod {
|
||||
fn fold_mod(&mut self, m: &_mod) -> _mod {
|
||||
noop_fold_mod(m, self)
|
||||
}
|
||||
|
||||
fn fold_foreign_mod(&self, nm: &foreign_mod) -> foreign_mod {
|
||||
fn fold_foreign_mod(&mut self, nm: &foreign_mod) -> foreign_mod {
|
||||
ast::foreign_mod {
|
||||
abis: nm.abis,
|
||||
view_items: nm.view_items
|
||||
|
@ -302,7 +302,7 @@ pub trait ast_fold {
|
|||
}
|
||||
}
|
||||
|
||||
fn fold_variant(&self, v: &variant) -> P<variant> {
|
||||
fn fold_variant(&mut self, v: &variant) -> P<variant> {
|
||||
let kind;
|
||||
match v.node.kind {
|
||||
tuple_variant_kind(ref variant_args) => {
|
||||
|
@ -339,11 +339,11 @@ pub trait ast_fold {
|
|||
})
|
||||
}
|
||||
|
||||
fn fold_ident(&self, i: Ident) -> Ident {
|
||||
fn fold_ident(&mut self, i: Ident) -> Ident {
|
||||
i
|
||||
}
|
||||
|
||||
fn fold_path(&self, p: &Path) -> Path {
|
||||
fn fold_path(&mut self, p: &Path) -> Path {
|
||||
ast::Path {
|
||||
span: self.new_span(p.span),
|
||||
global: p.global,
|
||||
|
@ -355,7 +355,7 @@ pub trait ast_fold {
|
|||
}
|
||||
}
|
||||
|
||||
fn fold_local(&self, l: @Local) -> @Local {
|
||||
fn fold_local(&mut self, l: @Local) -> @Local {
|
||||
@Local {
|
||||
ty: self.fold_ty(l.ty),
|
||||
pat: self.fold_pat(l.pat),
|
||||
|
@ -365,7 +365,7 @@ pub trait ast_fold {
|
|||
}
|
||||
}
|
||||
|
||||
fn fold_mac(&self, macro: &mac) -> mac {
|
||||
fn fold_mac(&mut self, macro: &mac) -> mac {
|
||||
Spanned {
|
||||
node: match macro.node {
|
||||
mac_invoc_tt(ref p, ref tts, ctxt) => {
|
||||
|
@ -382,22 +382,22 @@ pub trait ast_fold {
|
|||
es.map(|x| f(*x))
|
||||
}
|
||||
|
||||
fn new_id(&self, i: NodeId) -> NodeId {
|
||||
fn new_id(&mut self, i: NodeId) -> NodeId {
|
||||
i
|
||||
}
|
||||
|
||||
fn new_span(&self, sp: Span) -> Span {
|
||||
fn new_span(&mut self, sp: Span) -> Span {
|
||||
sp
|
||||
}
|
||||
|
||||
fn fold_explicit_self(&self, es: &explicit_self) -> explicit_self {
|
||||
fn fold_explicit_self(&mut self, es: &explicit_self) -> explicit_self {
|
||||
Spanned {
|
||||
span: self.new_span(es.span),
|
||||
node: self.fold_explicit_self_(&es.node)
|
||||
}
|
||||
}
|
||||
|
||||
fn fold_explicit_self_(&self, es: &explicit_self_) -> explicit_self_ {
|
||||
fn fold_explicit_self_(&mut self, es: &explicit_self_) -> explicit_self_ {
|
||||
match *es {
|
||||
sty_static | sty_value(_) | sty_uniq(_) | sty_box(_) => {
|
||||
*es
|
||||
|
@ -412,7 +412,7 @@ pub trait ast_fold {
|
|||
/* some little folds that probably aren't useful to have in ast_fold itself*/
|
||||
|
||||
//used in noop_fold_item and noop_fold_crate and noop_fold_crate_directive
|
||||
fn fold_meta_item_<T:ast_fold>(mi: @MetaItem, fld: &T) -> @MetaItem {
|
||||
fn fold_meta_item_<T:ast_fold>(mi: @MetaItem, fld: &mut T) -> @MetaItem {
|
||||
@Spanned {
|
||||
node:
|
||||
match mi.node {
|
||||
|
@ -430,7 +430,7 @@ fn fold_meta_item_<T:ast_fold>(mi: @MetaItem, fld: &T) -> @MetaItem {
|
|||
}
|
||||
|
||||
//used in noop_fold_item and noop_fold_crate
|
||||
fn fold_attribute_<T:ast_fold>(at: Attribute, fld: &T) -> Attribute {
|
||||
fn fold_attribute_<T:ast_fold>(at: Attribute, fld: &mut T) -> Attribute {
|
||||
Spanned {
|
||||
span: fld.new_span(at.span),
|
||||
node: ast::Attribute_ {
|
||||
|
@ -442,7 +442,7 @@ fn fold_attribute_<T:ast_fold>(at: Attribute, fld: &T) -> Attribute {
|
|||
}
|
||||
|
||||
//used in noop_fold_foreign_item and noop_fold_fn_decl
|
||||
fn fold_arg_<T:ast_fold>(a: &arg, fld: &T) -> arg {
|
||||
fn fold_arg_<T:ast_fold>(a: &arg, fld: &mut T) -> arg {
|
||||
ast::arg {
|
||||
ty: fld.fold_ty(a.ty),
|
||||
pat: fld.fold_pat(a.pat),
|
||||
|
@ -452,7 +452,7 @@ fn fold_arg_<T:ast_fold>(a: &arg, fld: &T) -> arg {
|
|||
|
||||
// build a new vector of tts by appling the ast_fold's fold_ident to
|
||||
// all of the identifiers in the token trees.
|
||||
pub fn fold_tts<T:ast_fold>(tts: &[token_tree], fld: &T) -> ~[token_tree] {
|
||||
pub fn fold_tts<T:ast_fold>(tts: &[token_tree], fld: &mut T) -> ~[token_tree] {
|
||||
tts.map(|tt| {
|
||||
match *tt {
|
||||
tt_tok(span, ref tok) =>
|
||||
|
@ -470,7 +470,7 @@ pub fn fold_tts<T:ast_fold>(tts: &[token_tree], fld: &T) -> ~[token_tree] {
|
|||
}
|
||||
|
||||
// apply ident folder if it's an ident, otherwise leave it alone
|
||||
fn maybe_fold_ident<T:ast_fold>(t: &token::Token, fld: &T) -> token::Token {
|
||||
fn maybe_fold_ident<T:ast_fold>(t: &token::Token, fld: &mut T) -> token::Token {
|
||||
match *t {
|
||||
token::IDENT(id, followed_by_colons) => {
|
||||
token::IDENT(fld.fold_ident(id), followed_by_colons)
|
||||
|
@ -479,7 +479,7 @@ fn maybe_fold_ident<T:ast_fold>(t: &token::Token, fld: &T) -> token::Token {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn fold_fn_decl<T:ast_fold>(decl: &ast::fn_decl, fld: &T)
|
||||
pub fn fold_fn_decl<T:ast_fold>(decl: &ast::fn_decl, fld: &mut T)
|
||||
-> P<fn_decl> {
|
||||
P(fn_decl {
|
||||
inputs: decl.inputs.map(|x| fold_arg_(x, fld)), // bad copy
|
||||
|
@ -489,7 +489,7 @@ pub fn fold_fn_decl<T:ast_fold>(decl: &ast::fn_decl, fld: &T)
|
|||
})
|
||||
}
|
||||
|
||||
fn fold_ty_param_bound<T:ast_fold>(tpb: &TyParamBound, fld: &T)
|
||||
fn fold_ty_param_bound<T:ast_fold>(tpb: &TyParamBound, fld: &mut T)
|
||||
-> TyParamBound {
|
||||
match *tpb {
|
||||
TraitTyParamBound(ref ty) => TraitTyParamBound(fold_trait_ref(ty, fld)),
|
||||
|
@ -497,7 +497,7 @@ fn fold_ty_param_bound<T:ast_fold>(tpb: &TyParamBound, fld: &T)
|
|||
}
|
||||
}
|
||||
|
||||
pub fn fold_ty_param<T:ast_fold>(tp: &TyParam, fld: &T) -> TyParam {
|
||||
pub fn fold_ty_param<T:ast_fold>(tp: &TyParam, fld: &mut T) -> TyParam {
|
||||
TyParam {
|
||||
ident: tp.ident,
|
||||
id: fld.new_id(tp.id),
|
||||
|
@ -505,12 +505,12 @@ pub fn fold_ty_param<T:ast_fold>(tp: &TyParam, fld: &T) -> TyParam {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn fold_ty_params<T:ast_fold>(tps: &OptVec<TyParam>, fld: &T)
|
||||
pub fn fold_ty_params<T:ast_fold>(tps: &OptVec<TyParam>, fld: &mut T)
|
||||
-> OptVec<TyParam> {
|
||||
tps.map(|tp| fold_ty_param(tp, fld))
|
||||
}
|
||||
|
||||
pub fn fold_lifetime<T:ast_fold>(l: &Lifetime, fld: &T) -> Lifetime {
|
||||
pub fn fold_lifetime<T:ast_fold>(l: &Lifetime, fld: &mut T) -> Lifetime {
|
||||
Lifetime {
|
||||
id: fld.new_id(l.id),
|
||||
span: fld.new_span(l.span),
|
||||
|
@ -518,22 +518,22 @@ pub fn fold_lifetime<T:ast_fold>(l: &Lifetime, fld: &T) -> Lifetime {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn fold_lifetimes<T:ast_fold>(lts: &OptVec<Lifetime>, fld: &T)
|
||||
pub fn fold_lifetimes<T:ast_fold>(lts: &OptVec<Lifetime>, fld: &mut T)
|
||||
-> OptVec<Lifetime> {
|
||||
lts.map(|l| fold_lifetime(l, fld))
|
||||
}
|
||||
|
||||
pub fn fold_opt_lifetime<T:ast_fold>(o_lt: &Option<Lifetime>, fld: &T)
|
||||
pub fn fold_opt_lifetime<T:ast_fold>(o_lt: &Option<Lifetime>, fld: &mut T)
|
||||
-> Option<Lifetime> {
|
||||
o_lt.as_ref().map(|lt| fold_lifetime(lt, fld))
|
||||
}
|
||||
|
||||
pub fn fold_generics<T:ast_fold>(generics: &Generics, fld: &T) -> Generics {
|
||||
pub fn fold_generics<T:ast_fold>(generics: &Generics, fld: &mut T) -> Generics {
|
||||
Generics {ty_params: fold_ty_params(&generics.ty_params, fld),
|
||||
lifetimes: fold_lifetimes(&generics.lifetimes, fld)}
|
||||
}
|
||||
|
||||
fn fold_struct_def<T:ast_fold>(struct_def: @ast::struct_def, fld: &T)
|
||||
fn fold_struct_def<T:ast_fold>(struct_def: @ast::struct_def, fld: &mut T)
|
||||
-> @ast::struct_def {
|
||||
@ast::struct_def {
|
||||
fields: struct_def.fields.map(|f| fold_struct_field(f, fld)),
|
||||
|
@ -541,14 +541,14 @@ fn fold_struct_def<T:ast_fold>(struct_def: @ast::struct_def, fld: &T)
|
|||
}
|
||||
}
|
||||
|
||||
fn fold_trait_ref<T:ast_fold>(p: &trait_ref, fld: &T) -> trait_ref {
|
||||
fn fold_trait_ref<T:ast_fold>(p: &trait_ref, fld: &mut T) -> trait_ref {
|
||||
ast::trait_ref {
|
||||
path: fld.fold_path(&p.path),
|
||||
ref_id: fld.new_id(p.ref_id),
|
||||
}
|
||||
}
|
||||
|
||||
fn fold_struct_field<T:ast_fold>(f: &struct_field, fld: &T) -> struct_field {
|
||||
fn fold_struct_field<T:ast_fold>(f: &struct_field, fld: &mut T) -> struct_field {
|
||||
Spanned {
|
||||
node: ast::struct_field_ {
|
||||
kind: f.node.kind,
|
||||
|
@ -560,7 +560,7 @@ fn fold_struct_field<T:ast_fold>(f: &struct_field, fld: &T) -> struct_field {
|
|||
}
|
||||
}
|
||||
|
||||
fn fold_field_<T:ast_fold>(field: Field, folder: &T) -> Field {
|
||||
fn fold_field_<T:ast_fold>(field: Field, folder: &mut T) -> Field {
|
||||
ast::Field {
|
||||
ident: respan(field.ident.span, folder.fold_ident(field.ident.node)),
|
||||
expr: folder.fold_expr(field.expr),
|
||||
|
@ -568,14 +568,14 @@ fn fold_field_<T:ast_fold>(field: Field, folder: &T) -> Field {
|
|||
}
|
||||
}
|
||||
|
||||
fn fold_mt<T:ast_fold>(mt: &mt, folder: &T) -> mt {
|
||||
fn fold_mt<T:ast_fold>(mt: &mt, folder: &mut T) -> mt {
|
||||
mt {
|
||||
ty: folder.fold_ty(mt.ty),
|
||||
mutbl: mt.mutbl,
|
||||
}
|
||||
}
|
||||
|
||||
fn fold_opt_bounds<T:ast_fold>(b: &Option<OptVec<TyParamBound>>, folder: &T)
|
||||
fn fold_opt_bounds<T:ast_fold>(b: &Option<OptVec<TyParamBound>>, folder: &mut T)
|
||||
-> Option<OptVec<TyParamBound>> {
|
||||
b.as_ref().map(|bounds| {
|
||||
bounds.map(|bound| {
|
||||
|
@ -584,7 +584,7 @@ fn fold_opt_bounds<T:ast_fold>(b: &Option<OptVec<TyParamBound>>, folder: &T)
|
|||
})
|
||||
}
|
||||
|
||||
fn fold_variant_arg_<T:ast_fold>(va: &variant_arg, folder: &T)
|
||||
fn fold_variant_arg_<T:ast_fold>(va: &variant_arg, folder: &mut T)
|
||||
-> variant_arg {
|
||||
ast::variant_arg {
|
||||
ty: folder.fold_ty(va.ty),
|
||||
|
@ -592,7 +592,7 @@ fn fold_variant_arg_<T:ast_fold>(va: &variant_arg, folder: &T)
|
|||
}
|
||||
}
|
||||
|
||||
pub fn noop_fold_block<T:ast_fold>(b: P<Block>, folder: &T) -> P<Block> {
|
||||
pub fn noop_fold_block<T:ast_fold>(b: P<Block>, folder: &mut T) -> P<Block> {
|
||||
let view_items = b.view_items.map(|x| folder.fold_view_item(x));
|
||||
let stmts = b.stmts.iter().flat_map(|s| folder.fold_stmt(*s).move_iter()).collect();
|
||||
P(Block {
|
||||
|
@ -605,7 +605,7 @@ pub fn noop_fold_block<T:ast_fold>(b: P<Block>, folder: &T) -> P<Block> {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn noop_fold_item_underscore<T:ast_fold>(i: &item_, folder: &T) -> item_ {
|
||||
pub fn noop_fold_item_underscore<T:ast_fold>(i: &item_, folder: &mut T) -> item_ {
|
||||
match *i {
|
||||
item_static(t, m, e) => {
|
||||
item_static(folder.fold_ty(t), m, folder.fold_expr(e))
|
||||
|
@ -662,7 +662,7 @@ pub fn noop_fold_item_underscore<T:ast_fold>(i: &item_, folder: &T) -> item_ {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn noop_fold_type_method<T:ast_fold>(m: &TypeMethod, fld: &T)
|
||||
pub fn noop_fold_type_method<T:ast_fold>(m: &TypeMethod, fld: &mut T)
|
||||
-> TypeMethod {
|
||||
TypeMethod {
|
||||
ident: fld.fold_ident(m.ident),
|
||||
|
@ -676,7 +676,7 @@ pub fn noop_fold_type_method<T:ast_fold>(m: &TypeMethod, fld: &T)
|
|||
}
|
||||
}
|
||||
|
||||
pub fn noop_fold_mod<T:ast_fold>(m: &_mod, folder: &T) -> _mod {
|
||||
pub fn noop_fold_mod<T:ast_fold>(m: &_mod, folder: &mut T) -> _mod {
|
||||
ast::_mod {
|
||||
view_items: m.view_items
|
||||
.iter()
|
||||
|
@ -685,7 +685,7 @@ pub fn noop_fold_mod<T:ast_fold>(m: &_mod, folder: &T) -> _mod {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn noop_fold_crate<T:ast_fold>(c: Crate, folder: &T) -> Crate {
|
||||
pub fn noop_fold_crate<T:ast_fold>(c: Crate, folder: &mut T) -> Crate {
|
||||
let fold_meta_item = |x| fold_meta_item_(x, folder);
|
||||
let fold_attribute = |x| fold_attribute_(x, folder);
|
||||
|
||||
|
@ -697,7 +697,7 @@ pub fn noop_fold_crate<T:ast_fold>(c: Crate, folder: &T) -> Crate {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn noop_fold_item<T:ast_fold>(i: @ast::item, folder: &T)
|
||||
pub fn noop_fold_item<T:ast_fold>(i: @ast::item, folder: &mut T)
|
||||
-> SmallVector<@ast::item> {
|
||||
let fold_attribute = |x| fold_attribute_(x, folder);
|
||||
|
||||
|
@ -711,7 +711,7 @@ pub fn noop_fold_item<T:ast_fold>(i: @ast::item, folder: &T)
|
|||
})
|
||||
}
|
||||
|
||||
pub fn noop_fold_expr<T:ast_fold>(e: @ast::Expr, folder: &T) -> @ast::Expr {
|
||||
pub fn noop_fold_expr<T:ast_fold>(e: @ast::Expr, folder: &mut T) -> @ast::Expr {
|
||||
let fold_field = |x| fold_field_(x, folder);
|
||||
|
||||
let node = match e.node {
|
||||
|
@ -719,7 +719,7 @@ pub fn noop_fold_expr<T:ast_fold>(e: @ast::Expr, folder: &T) -> @ast::Expr {
|
|||
ExprVstore(folder.fold_expr(e), v)
|
||||
}
|
||||
ExprVec(ref exprs, mutt) => {
|
||||
ExprVec(folder.map_exprs(|x| folder.fold_expr(x), *exprs), mutt)
|
||||
ExprVec(exprs.map(|&x| folder.fold_expr(x)), mutt)
|
||||
}
|
||||
ExprRepeat(expr, count, mutt) => {
|
||||
ExprRepeat(folder.fold_expr(expr), folder.fold_expr(count), mutt)
|
||||
|
@ -727,7 +727,7 @@ pub fn noop_fold_expr<T:ast_fold>(e: @ast::Expr, folder: &T) -> @ast::Expr {
|
|||
ExprTup(ref elts) => ExprTup(elts.map(|x| folder.fold_expr(*x))),
|
||||
ExprCall(f, ref args, blk) => {
|
||||
ExprCall(folder.fold_expr(f),
|
||||
folder.map_exprs(|x| folder.fold_expr(x), *args),
|
||||
args.map(|&x| folder.fold_expr(x)),
|
||||
blk)
|
||||
}
|
||||
ExprMethodCall(callee_id, f, i, ref tps, ref args, blk) => {
|
||||
|
@ -736,7 +736,7 @@ pub fn noop_fold_expr<T:ast_fold>(e: @ast::Expr, folder: &T) -> @ast::Expr {
|
|||
folder.fold_expr(f),
|
||||
folder.fold_ident(i),
|
||||
tps.map(|&x| folder.fold_ty(x)),
|
||||
folder.map_exprs(|x| folder.fold_expr(x), *args),
|
||||
args.map(|&x| folder.fold_expr(x)),
|
||||
blk
|
||||
)
|
||||
}
|
||||
|
@ -837,7 +837,7 @@ pub fn noop_fold_expr<T:ast_fold>(e: @ast::Expr, folder: &T) -> @ast::Expr {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn noop_fold_stmt<T:ast_fold>(s: &Stmt, folder: &T) -> SmallVector<@Stmt> {
|
||||
pub fn noop_fold_stmt<T:ast_fold>(s: &Stmt, folder: &mut T) -> SmallVector<@Stmt> {
|
||||
let nodes = match s.node {
|
||||
StmtDecl(d, nid) => {
|
||||
folder.fold_decl(d).move_iter()
|
||||
|
@ -876,7 +876,7 @@ mod test {
|
|||
struct ToZzIdentFolder;
|
||||
|
||||
impl ast_fold for ToZzIdentFolder {
|
||||
fn fold_ident(&self, _: ast::Ident) -> ast::Ident {
|
||||
fn fold_ident(&mut self, _: ast::Ident) -> ast::Ident {
|
||||
token::str_to_ident("zz")
|
||||
}
|
||||
}
|
||||
|
@ -898,23 +898,23 @@ mod test {
|
|||
|
||||
// make sure idents get transformed everywhere
|
||||
#[test] fn ident_transformation () {
|
||||
let zz_fold = ToZzIdentFolder;
|
||||
let mut zz_fold = ToZzIdentFolder;
|
||||
let ast = string_to_crate(@"#[a] mod b {fn c (d : e, f : g) {h!(i,j,k);l;m}}");
|
||||
assert_pred!(matches_codepattern,
|
||||
"matches_codepattern",
|
||||
pprust::to_str(&zz_fold.fold_crate(ast),fake_print_crate,
|
||||
pprust::to_str(&mut zz_fold.fold_crate(ast),fake_print_crate,
|
||||
token::get_ident_interner()),
|
||||
~"#[a]mod zz{fn zz(zz:zz,zz:zz){zz!(zz,zz,zz);zz;zz}}");
|
||||
}
|
||||
|
||||
// even inside macro defs....
|
||||
#[test] fn ident_transformation_in_defs () {
|
||||
let zz_fold = ToZzIdentFolder;
|
||||
let mut zz_fold = ToZzIdentFolder;
|
||||
let ast = string_to_crate(@"macro_rules! a {(b $c:expr $(d $e:token)f+
|
||||
=> (g $(d $d $e)+))} ");
|
||||
assert_pred!(matches_codepattern,
|
||||
"matches_codepattern",
|
||||
pprust::to_str(&zz_fold.fold_crate(ast),fake_print_crate,
|
||||
pprust::to_str(&mut zz_fold.fold_crate(ast),fake_print_crate,
|
||||
token::get_ident_interner()),
|
||||
~"zz!zz((zz$zz:zz$(zz $zz:zz)zz+=>(zz$(zz$zz$zz)+)))");
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ extern mod syntax;
|
|||
|
||||
use syntax::ext::base::ExtCtxt;
|
||||
|
||||
fn syntax_extension(cx: @ExtCtxt) {
|
||||
fn syntax_extension(cx: &ExtCtxt) {
|
||||
let e_toks : ~[syntax::ast::token_tree] = quote_tokens!(cx, 1 + 2);
|
||||
let p_toks : ~[syntax::ast::token_tree] = quote_tokens!(cx, (x, 1 .. 4, *));
|
||||
|
||||
|
|
Loading…
Reference in New Issue