Skip to content

libsyntax: ext cleanup #11168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 30, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/librustc/front/assign_node_ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 9 additions & 9 deletions src/librustc/front/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,25 @@ 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)
}
}

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)
Expand All @@ -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())
Expand All @@ -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))
Expand All @@ -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))
Expand Down Expand Up @@ -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())
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/front/std_inject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
51 changes: 25 additions & 26 deletions src/librustc/front/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -63,30 +63,30 @@ 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);
}
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 => {
Expand All @@ -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)
};
{
Expand All @@ -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| {
Expand All @@ -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)
Expand All @@ -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(~[]),
Expand All @@ -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",
Expand All @@ -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;
}

Expand All @@ -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 {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
;
Expand Down Expand Up @@ -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),
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/middle/astencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_, _) |
Expand Down Expand Up @@ -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: (),
};

Expand All @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions src/librustpkg/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);

Expand Down Expand Up @@ -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)
}
}
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Loading