libsyntax: progress on making syntax::visit vecs_implicitly_copyable-free

This commit is contained in:
Erick Tryzelaar 2013-02-17 22:20:36 -08:00
parent 9ac5262bdf
commit f14409c528
41 changed files with 1060 additions and 921 deletions

View file

@ -134,7 +134,7 @@ pub pure fn safe_to_use_expr(e: ast::expr, tm: test_mode) -> bool {
pub fn safe_to_steal_ty(t: @ast::Ty, tm: test_mode) -> bool { pub fn safe_to_steal_ty(t: @ast::Ty, tm: test_mode) -> bool {
// Restrictions happen to be the same. // Restrictions happen to be the same.
safe_to_replace_ty(t.node, tm) safe_to_replace_ty(&t.node, tm)
} }
// Not type-parameterized: https://github.com/mozilla/rust/issues/898 (FIXED) // Not type-parameterized: https://github.com/mozilla/rust/issues/898 (FIXED)
@ -175,8 +175,8 @@ pub fn steal(crate: ast::crate, tm: test_mode) -> StolenStuff {
} }
pub fn safe_to_replace_expr(e: ast::expr_, _tm: test_mode) -> bool { pub fn safe_to_replace_expr(e: &ast::expr_, _tm: test_mode) -> bool {
match e { match *e {
// https://github.com/mozilla/rust/issues/652 // https://github.com/mozilla/rust/issues/652
ast::expr_if(*) => { false } ast::expr_if(*) => { false }
ast::expr_block(_) => { false } ast::expr_block(_) => { false }
@ -188,8 +188,8 @@ pub fn safe_to_replace_expr(e: ast::expr_, _tm: test_mode) -> bool {
} }
} }
pub fn safe_to_replace_ty(t: ast::ty_, _tm: test_mode) -> bool { pub fn safe_to_replace_ty(t: &ast::ty_, _tm: test_mode) -> bool {
match t { match *t {
ast::ty_infer => { false } // always implicit, always top level ast::ty_infer => { false } // always implicit, always top level
ast::ty_bot => { false } // in source, can only appear ast::ty_bot => { false } // in source, can only appear
// as the out type of a function // as the out type of a function
@ -204,7 +204,7 @@ pub fn replace_expr_in_crate(crate: ast::crate, i: uint,
ast::crate { ast::crate {
let j: @mut uint = @mut 0u; let j: @mut uint = @mut 0u;
fn fold_expr_rep(j_: @mut uint, i_: uint, newexpr_: ast::expr_, fn fold_expr_rep(j_: @mut uint, i_: uint, newexpr_: ast::expr_,
original: ast::expr_, fld: fold::ast_fold, original: &ast::expr_, fld: fold::ast_fold,
tm_: test_mode) -> tm_: test_mode) ->
ast::expr_ { ast::expr_ {
*j_ += 1u; *j_ += 1u;
@ -221,7 +221,7 @@ pub fn replace_expr_in_crate(crate: ast::crate, i: uint,
.. *fold::default_ast_fold() .. *fold::default_ast_fold()
}; };
let af = fold::make_fold(afp); let af = fold::make_fold(afp);
let crate2: @ast::crate = @af.fold_crate(crate); let crate2: @ast::crate = @af.fold_crate(&crate);
*crate2 *crate2
} }
@ -231,7 +231,7 @@ pub fn replace_ty_in_crate(crate: ast::crate, i: uint, newty: ast::Ty,
tm: test_mode) -> ast::crate { tm: test_mode) -> ast::crate {
let j: @mut uint = @mut 0u; let j: @mut uint = @mut 0u;
fn fold_ty_rep(j_: @mut uint, i_: uint, newty_: ast::ty_, fn fold_ty_rep(j_: @mut uint, i_: uint, newty_: ast::ty_,
original: ast::ty_, fld: fold::ast_fold, original: &ast::ty_, fld: fold::ast_fold,
tm_: test_mode) -> tm_: test_mode) ->
ast::ty_ { ast::ty_ {
*j_ += 1u; *j_ += 1u;
@ -244,7 +244,7 @@ pub fn replace_ty_in_crate(crate: ast::crate, i: uint, newty: ast::Ty,
.. *fold::default_ast_fold() .. *fold::default_ast_fold()
}; };
let af = fold::make_fold(afp); let af = fold::make_fold(afp);
let crate2: @ast::crate = @af.fold_crate(crate); let crate2: @ast::crate = @af.fold_crate(&crate);
*crate2 *crate2
} }

View file

@ -396,7 +396,7 @@ pub fn pretty_print_input(sess: Session, +cfg: ast::crate_cfg, input: input,
pprust::node_block(s, ref blk) => { pprust::node_block(s, ref blk) => {
pp::space(s.s); pp::space(s.s);
pprust::synth_comment( pprust::synth_comment(
s, ~"block " + int::to_str((*blk).node.id)); s, ~"block " + int::to_str(blk.node.id));
} }
pprust::node_expr(s, expr) => { pprust::node_expr(s, expr) => {
pp::space(s.s); pp::space(s.s);

View file

@ -45,7 +45,7 @@ pub fn strip_items(crate: @ast::crate, in_cfg: in_cfg_pred)
.. *fold::default_ast_fold()}; .. *fold::default_ast_fold()};
let fold = fold::make_fold(precursor); let fold = fold::make_fold(precursor);
let res = @fold.fold_crate(*crate); let res = @fold.fold_crate(&*crate);
return res; return res;
} }
@ -63,7 +63,7 @@ fn filter_view_item(cx: @Context, &&view_item: @ast::view_item
} }
} }
fn fold_mod(cx: @Context, m: ast::_mod, fld: fold::ast_fold) -> ast::_mod { fn fold_mod(cx: @Context, m: &ast::_mod, fld: fold::ast_fold) -> ast::_mod {
let filtered_items = let filtered_items =
m.items.filter_mapped(|a| filter_item(cx, *a)); m.items.filter_mapped(|a| filter_item(cx, *a));
let filtered_view_items = let filtered_view_items =
@ -83,7 +83,7 @@ fn filter_foreign_item(cx: @Context, &&item: @ast::foreign_item) ->
fn fold_foreign_mod( fn fold_foreign_mod(
cx: @Context, cx: @Context,
nm: ast::foreign_mod, nm: &ast::foreign_mod,
fld: fold::ast_fold fld: fold::ast_fold
) -> ast::foreign_mod { ) -> ast::foreign_mod {
let filtered_items = let filtered_items =
@ -98,21 +98,21 @@ fn fold_foreign_mod(
} }
} }
fn fold_item_underscore(cx: @Context, +item: ast::item_, fn fold_item_underscore(cx: @Context, item: &ast::item_,
fld: fold::ast_fold) -> ast::item_ { fld: fold::ast_fold) -> ast::item_ {
let item = match item { let item = match *item {
ast::item_impl(a, b, c, methods) => { ast::item_impl(ref a, b, c, ref methods) => {
let methods = methods.filtered(|m| method_in_cfg(cx, *m) ); let methods = methods.filtered(|m| method_in_cfg(cx, *m) );
ast::item_impl(a, b, c, methods) ast::item_impl(/*bad*/ copy *a, b, c, methods)
} }
ast::item_trait(ref a, ref b, ref methods) => { ast::item_trait(ref a, ref b, ref methods) => {
let methods = methods.filtered(|m| trait_method_in_cfg(cx, m) ); let methods = methods.filtered(|m| trait_method_in_cfg(cx, m) );
ast::item_trait(/*bad*/copy *a, /*bad*/copy *b, methods) ast::item_trait(/*bad*/copy *a, /*bad*/copy *b, methods)
} }
item => item ref item => /*bad*/ copy *item
}; };
fold::noop_fold_item_underscore(item, fld) fold::noop_fold_item_underscore(&item, fld)
} }
fn filter_stmt(cx: @Context, &&stmt: @ast::stmt) -> fn filter_stmt(cx: @Context, &&stmt: @ast::stmt) ->
@ -134,7 +134,7 @@ fn filter_stmt(cx: @Context, &&stmt: @ast::stmt) ->
fn fold_block( fn fold_block(
cx: @Context, cx: @Context,
b: ast::blk_, b: &ast::blk_,
fld: fold::ast_fold fld: fold::ast_fold
) -> ast::blk_ { ) -> ast::blk_ {
let filtered_stmts = let filtered_stmts =

View file

@ -66,10 +66,13 @@ fn inject_libcore_ref(sess: Session,
view_items: vis, view_items: vis,
../*bad*/copy crate.module ../*bad*/copy crate.module
}; };
new_module = fld.fold_mod(new_module); new_module = fld.fold_mod(&new_module);
// FIXME #2543: Bad copy. // FIXME #2543: Bad copy.
let new_crate = ast::crate_ { module: new_module, ..copy crate }; let new_crate = ast::crate_ {
module: new_module,
..copy *crate
};
(new_crate, span) (new_crate, span)
}, },
fold_mod: |module, fld| { fold_mod: |module, fld| {
@ -95,12 +98,15 @@ fn inject_libcore_ref(sess: Session,
let vis = vec::append(~[vi2], module.view_items); let vis = vec::append(~[vi2], module.view_items);
// FIXME #2543: Bad copy. // FIXME #2543: Bad copy.
let new_module = ast::_mod { view_items: vis, ..copy module }; let new_module = ast::_mod {
fold::noop_fold_mod(new_module, fld) view_items: vis,
..copy *module
};
fold::noop_fold_mod(&new_module, fld)
}, },
..*fold::default_ast_fold() ..*fold::default_ast_fold()
}; };
let fold = fold::make_fold(precursor); let fold = fold::make_fold(precursor);
@fold.fold_crate(*crate) @fold.fold_crate(crate)
} }

View file

@ -91,7 +91,7 @@ fn generate_test_harness(sess: session::Session,
fold_mod: |a,b| fold_mod(cx, a, b),.. *fold::default_ast_fold()}; fold_mod: |a,b| fold_mod(cx, a, b),.. *fold::default_ast_fold()};
let fold = fold::make_fold(precursor); let fold = fold::make_fold(precursor);
let res = @fold.fold_crate(*crate); let res = @fold.fold_crate(&*crate);
cx.ext_cx.bt_pop(); cx.ext_cx.bt_pop();
return res; return res;
} }
@ -106,7 +106,7 @@ fn strip_test_functions(crate: @ast::crate) -> @ast::crate {
} }
fn fold_mod(cx: @mut TestCtxt, fn fold_mod(cx: @mut TestCtxt,
m: ast::_mod, m: &ast::_mod,
fld: fold::ast_fold) fld: fold::ast_fold)
-> ast::_mod { -> ast::_mod {
// Remove any #[main] from the AST so it doesn't clash with // Remove any #[main] from the AST so it doesn't clash with
@ -125,19 +125,21 @@ fn fold_mod(cx: @mut TestCtxt,
items: vec::map(m.items, |i| nomain(cx, *i)), items: vec::map(m.items, |i| nomain(cx, *i)),
}; };
fold::noop_fold_mod(mod_nomain, fld) fold::noop_fold_mod(&mod_nomain, fld)
} }
fn fold_crate(cx: @mut TestCtxt, fn fold_crate(cx: @mut TestCtxt,
c: ast::crate_, c: &ast::crate_,
fld: fold::ast_fold) fld: fold::ast_fold)
-> ast::crate_ { -> ast::crate_ {
let folded = fold::noop_fold_crate(c, fld); let folded = fold::noop_fold_crate(c, fld);
// Add a special __test module to the crate that will contain code // Add a special __test module to the crate that will contain code
// generated for the test harness // generated for the test harness
ast::crate_ { module: add_test_module(cx, /*bad*/copy folded.module), ast::crate_ {
.. folded } module: add_test_module(cx, &folded.module),
.. folded
}
} }
@ -238,11 +240,11 @@ fn should_fail(i: @ast::item) -> bool {
vec::len(attr::find_attrs_by_name(i.attrs, ~"should_fail")) > 0u vec::len(attr::find_attrs_by_name(i.attrs, ~"should_fail")) > 0u
} }
fn add_test_module(cx: &TestCtxt, +m: ast::_mod) -> ast::_mod { fn add_test_module(cx: &TestCtxt, m: &ast::_mod) -> ast::_mod {
let testmod = mk_test_module(cx); let testmod = mk_test_module(cx);
ast::_mod { ast::_mod {
items: vec::append_one(/*bad*/copy m.items, testmod), items: vec::append_one(/*bad*/copy m.items, testmod),
.. m .. /*bad*/ copy *m
} }
} }

View file

@ -323,7 +323,7 @@ fn encode_path(ecx: @EncodeContext, ebml_w: writer::Encoder,
} }
fn encode_info_for_mod(ecx: @EncodeContext, ebml_w: writer::Encoder, fn encode_info_for_mod(ecx: @EncodeContext, ebml_w: writer::Encoder,
md: _mod, id: node_id, path: &[ast_map::path_elt], md: &_mod, id: node_id, path: &[ast_map::path_elt],
name: ident) { name: ident) {
ebml_w.start_tag(tag_items_data_item); ebml_w.start_tag(tag_items_data_item);
encode_def_id(ebml_w, local_def(id)); encode_def_id(ebml_w, local_def(id));
@ -621,7 +621,7 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: writer::Encoder,
} }
ebml_w.end_tag(); ebml_w.end_tag();
} }
item_mod(m) => { item_mod(ref m) => {
add_to_index(); add_to_index();
encode_info_for_mod(ecx, ebml_w, m, item.id, path, item.ident); encode_info_for_mod(ecx, ebml_w, m, item.id, path, item.ident);
} }
@ -856,8 +856,8 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: writer::Encoder,
// method info, we output static methods with type signatures as // method info, we output static methods with type signatures as
// written. Here, we output the *real* type signatures. I feel like // written. Here, we output the *real* type signatures. I feel like
// maybe we should only ever handle the real type signatures. // maybe we should only ever handle the real type signatures.
for vec::each((*ms)) |m| { for ms.each |m| {
let ty_m = ast_util::trait_method_to_ty_method(*m); let ty_m = ast_util::trait_method_to_ty_method(m);
if ty_m.self_ty.node != ast::sty_static { loop; } if ty_m.self_ty.node != ast::sty_static { loop; }
index.push(entry { val: ty_m.id, pos: ebml_w.writer.tell() }); index.push(entry { val: ty_m.id, pos: ebml_w.writer.tell() });
@ -927,7 +927,7 @@ fn encode_info_for_items(ecx: @EncodeContext, ebml_w: writer::Encoder,
let index = @mut ~[]; let index = @mut ~[];
ebml_w.start_tag(tag_items_data); ebml_w.start_tag(tag_items_data);
index.push(entry { val: crate_node_id, pos: ebml_w.writer.tell() }); index.push(entry { val: crate_node_id, pos: ebml_w.writer.tell() });
encode_info_for_mod(ecx, ebml_w, crate.node.module, encode_info_for_mod(ecx, ebml_w, &crate.node.module,
crate_node_id, ~[], crate_node_id, ~[],
syntax::parse::token::special_idents::invalid); syntax::parse::token::special_idents::invalid);
visit::visit_crate(*crate, (), visit::mk_vt(@visit::Visitor { visit::visit_crate(*crate, (), visit::mk_vt(@visit::Visitor {

View file

@ -298,7 +298,7 @@ fn encode_ast(ebml_w: writer::Encoder, item: ast::inlined_item) {
// nested items, as otherwise it would get confused when translating // nested items, as otherwise it would get confused when translating
// inlined items. // inlined items.
fn simplify_ast(ii: ast::inlined_item) -> ast::inlined_item { fn simplify_ast(ii: ast::inlined_item) -> ast::inlined_item {
fn drop_nested_items(blk: ast::blk_, fld: fold::ast_fold) -> ast::blk_ { fn drop_nested_items(blk: &ast::blk_, fld: fold::ast_fold) -> ast::blk_ {
let stmts_sans_items = do blk.stmts.filtered |stmt| { let stmts_sans_items = do blk.stmts.filtered |stmt| {
match stmt.node { match stmt.node {
ast::stmt_expr(_, _) | ast::stmt_semi(_, _) | ast::stmt_expr(_, _) | ast::stmt_semi(_, _) |
@ -317,7 +317,7 @@ fn simplify_ast(ii: ast::inlined_item) -> ast::inlined_item {
id: blk.id, id: blk.id,
rules: blk.rules rules: blk.rules
}; };
fold::noop_fold_block(blk_sans_items, fld) fold::noop_fold_block(&blk_sans_items, fld)
} }
let fld = fold::make_fold(@fold::AstFoldFns { let fld = fold::make_fold(@fold::AstFoldFns {
@ -336,7 +336,7 @@ fn simplify_ast(ii: ast::inlined_item) -> ast::inlined_item {
ast::ii_foreign(fld.fold_foreign_item(i)) ast::ii_foreign(fld.fold_foreign_item(i))
} }
ast::ii_dtor(ref dtor, nm, ref tps, parent_id) => { ast::ii_dtor(ref dtor, nm, ref tps, parent_id) => {
let dtor_body = fld.fold_block((*dtor).node.body); let dtor_body = fld.fold_block(&dtor.node.body);
ast::ii_dtor( ast::ii_dtor(
codemap::spanned { codemap::spanned {
node: ast::struct_dtor_ { body: dtor_body, node: ast::struct_dtor_ { body: dtor_body,
@ -372,7 +372,7 @@ fn renumber_ast(xcx: @ExtendedDecodeContext, ii: ast::inlined_item)
ast::ii_foreign(fld.fold_foreign_item(i)) ast::ii_foreign(fld.fold_foreign_item(i))
} }
ast::ii_dtor(ref dtor, nm, ref tps, parent_id) => { ast::ii_dtor(ref dtor, nm, ref tps, parent_id) => {
let dtor_body = fld.fold_block((*dtor).node.body); let dtor_body = fld.fold_block(&dtor.node.body);
let dtor_attrs = fld.fold_attributes(/*bad*/copy (*dtor).node.attrs); let dtor_attrs = fld.fold_attributes(/*bad*/copy (*dtor).node.attrs);
let new_params = fold::fold_ty_params(/*bad*/copy *tps, fld); let new_params = fold::fold_ty_params(/*bad*/copy *tps, fld);
let dtor_id = fld.new_id((*dtor).node.id); let dtor_id = fld.new_id((*dtor).node.id);

View file

@ -580,8 +580,8 @@ impl CheckLoanCtxt {
} }
fn check_loans_in_fn(fk: &visit::fn_kind, fn check_loans_in_fn(fk: &visit::fn_kind,
decl: ast::fn_decl, decl: &ast::fn_decl,
body: ast::blk, body: &ast::blk,
sp: span, sp: span,
id: ast::node_id, id: ast::node_id,
&&self: @mut CheckLoanCtxt, &&self: @mut CheckLoanCtxt,
@ -753,7 +753,7 @@ fn check_loans_in_expr(expr: @ast::expr,
visit::visit_expr(expr, self, vt); visit::visit_expr(expr, self, vt);
} }
fn check_loans_in_block(blk: ast::blk, fn check_loans_in_block(blk: &ast::blk,
&&self: @mut CheckLoanCtxt, &&self: @mut CheckLoanCtxt,
vt: visit::vt<@mut CheckLoanCtxt>) { vt: visit::vt<@mut CheckLoanCtxt>) {
do save_and_restore_managed(self.declared_purity) { do save_and_restore_managed(self.declared_purity) {

View file

@ -96,8 +96,8 @@ pub fn gather_loans(bccx: @BorrowckCtxt, crate: @ast::crate) -> ReqMaps {
} }
fn req_loans_in_fn(fk: &visit::fn_kind, fn req_loans_in_fn(fk: &visit::fn_kind,
decl: ast::fn_decl, decl: &ast::fn_decl,
body: ast::blk, body: &ast::blk,
sp: span, sp: span,
id: ast::node_id, id: ast::node_id,
&&self: @mut GatherLoanCtxt, &&self: @mut GatherLoanCtxt,
@ -269,13 +269,13 @@ fn req_loans_in_expr(ex: @ast::expr,
(vt.visit_expr)(cond, self, vt); (vt.visit_expr)(cond, self, vt);
// during body, can only root for the body // during body, can only root for the body
self.root_ub = (*body).node.id; self.root_ub = body.node.id;
(vt.visit_block)((*body), self, vt); (vt.visit_block)(body, self, vt);
} }
// see explanation attached to the `root_ub` field: // see explanation attached to the `root_ub` field:
ast::expr_loop(ref body, _) => { ast::expr_loop(ref body, _) => {
self.root_ub = (*body).node.id; self.root_ub = body.node.id;
visit::visit_expr(ex, self, vt); visit::visit_expr(ex, self, vt);
} }

View file

@ -33,10 +33,10 @@ pub fn check_crate(tcx: ty::ctxt, crate: @crate) {
match e.node { match e.node {
expr_while(e, ref b) => { expr_while(e, ref b) => {
(v.visit_expr)(e, cx, v); (v.visit_expr)(e, cx, v);
(v.visit_block)((*b), Context { in_loop: true,.. cx }, v); (v.visit_block)(b, Context { in_loop: true,.. cx }, v);
} }
expr_loop(ref b, _) => { expr_loop(ref b, _) => {
(v.visit_block)((*b), Context { in_loop: true,.. cx }, v); (v.visit_block)(b, Context { in_loop: true,.. cx }, v);
} }
expr_fn(*) => { expr_fn(*) => {
visit::visit_expr(e, Context { visit::visit_expr(e, Context {
@ -45,7 +45,7 @@ pub fn check_crate(tcx: ty::ctxt, crate: @crate) {
}, v); }, v);
} }
expr_fn_block(_, ref b) => { expr_fn_block(_, ref b) => {
(v.visit_block)((*b), Context { (v.visit_block)(b, Context {
in_loop: false, in_loop: false,
can_ret: false can_ret: false
}, v); }, v);
@ -53,10 +53,10 @@ pub fn check_crate(tcx: ty::ctxt, crate: @crate) {
expr_loop_body(@expr {node: expr_fn_block(_, ref b), _}) => { expr_loop_body(@expr {node: expr_fn_block(_, ref b), _}) => {
let sigil = ty::ty_closure_sigil(ty::expr_ty(tcx, e)); let sigil = ty::ty_closure_sigil(ty::expr_ty(tcx, e));
let blk = (sigil == BorrowedSigil); let blk = (sigil == BorrowedSigil);
(v.visit_block)((*b), Context { (v.visit_block)(b, Context {
in_loop: true, in_loop: true,
can_ret: blk can_ret: blk
}, v); }, v);
} }
expr_break(_) => { expr_break(_) => {
if !cx.in_loop { if !cx.in_loop {

View file

@ -670,8 +670,8 @@ pub fn check_local(cx: @MatchCheckCtxt,
pub fn check_fn(cx: @MatchCheckCtxt, pub fn check_fn(cx: @MatchCheckCtxt,
kind: &visit::fn_kind, kind: &visit::fn_kind,
decl: fn_decl, decl: &fn_decl,
body: blk, body: &blk,
sp: span, sp: span,
id: node_id, id: node_id,
&&s: (), &&s: (),

View file

@ -39,7 +39,7 @@ pub type freevar_map = HashMap<ast::node_id, freevar_info>;
// Since we want to be able to collect upvars in some arbitrary piece // Since we want to be able to collect upvars in some arbitrary piece
// of the AST, we take a walker function that we invoke with a visitor // of the AST, we take a walker function that we invoke with a visitor
// in order to start the search. // in order to start the search.
fn collect_freevars(def_map: resolve::DefMap, blk: ast::blk) fn collect_freevars(def_map: resolve::DefMap, blk: &ast::blk)
-> freevar_info { -> freevar_info {
let seen = HashMap(); let seen = HashMap();
let refs = @mut ~[]; let refs = @mut ~[];
@ -100,8 +100,8 @@ pub fn annotate_freevars(def_map: resolve::DefMap, crate: @ast::crate) ->
freevar_map { freevar_map {
let freevars = HashMap(); let freevars = HashMap();
let walk_fn = fn@(_fk: &visit::fn_kind, _decl: ast::fn_decl, let walk_fn = fn@(_fk: &visit::fn_kind, _decl: &ast::fn_decl,
blk: ast::blk, _sp: span, nid: ast::node_id) { blk: &ast::blk, _sp: span, nid: ast::node_id) {
let vars = collect_freevars(def_map, blk); let vars = collect_freevars(def_map, blk);
freevars.insert(nid, vars); freevars.insert(nid, vars);
}; };

View file

@ -153,8 +153,14 @@ fn with_appropriate_checker(cx: Context, id: node_id, b: fn(check_fn)) {
// Check that the free variables used in a shared/sendable closure conform // Check that the free variables used in a shared/sendable closure conform
// to the copy/move kind bounds. Then recursively check the function body. // to the copy/move kind bounds. Then recursively check the function body.
fn check_fn(fk: &visit::fn_kind, decl: fn_decl, body: blk, sp: span, fn check_fn(
fn_id: node_id, cx: Context, v: visit::vt<Context>) { fk: &visit::fn_kind,
decl: &fn_decl,
body: &blk,
sp: span,
fn_id: node_id,
cx: Context,
v: visit::vt<Context>) {
// Check kinds on free variables: // Check kinds on free variables:
do with_appropriate_checker(cx, fn_id) |chk| { do with_appropriate_checker(cx, fn_id) |chk| {
@ -166,7 +172,7 @@ fn check_fn(fk: &visit::fn_kind, decl: fn_decl, body: blk, sp: span,
visit::visit_fn(fk, decl, body, sp, fn_id, cx, v); visit::visit_fn(fk, decl, body, sp, fn_id, cx, v);
} }
fn check_arm(a: arm, cx: Context, v: visit::vt<Context>) { fn check_arm(a: &arm, cx: Context, v: visit::vt<Context>) {
for vec::each(a.pats) |p| { for vec::each(a.pats) |p| {
do pat_util::pat_bindings(cx.tcx.def_map, *p) |mode, id, span, _pth| { do pat_util::pat_bindings(cx.tcx.def_map, *p) |mode, id, span, _pth| {
if mode == bind_by_copy { if mode == bind_by_copy {

View file

@ -726,7 +726,7 @@ fn check_item_structural_records(cx: ty::ctxt, it: @ast::item) {
fn check_item_ctypes(cx: ty::ctxt, it: @ast::item) { fn check_item_ctypes(cx: ty::ctxt, it: @ast::item) {
fn check_foreign_fn(cx: ty::ctxt, fn_id: ast::node_id, fn check_foreign_fn(cx: ty::ctxt, fn_id: ast::node_id,
decl: ast::fn_decl) { decl: &ast::fn_decl) {
let tys = vec::map(decl.inputs, |a| a.ty ); let tys = vec::map(decl.inputs, |a| a.ty );
for vec::each(vec::append_one(tys, decl.output)) |ty| { for vec::each(vec::append_one(tys, decl.output)) |ty| {
match ty.node { match ty.node {
@ -760,7 +760,7 @@ fn check_item_ctypes(cx: ty::ctxt, it: @ast::item) {
either::Right(ast::foreign_abi_rust_intrinsic) => { either::Right(ast::foreign_abi_rust_intrinsic) => {
for nmod.items.each |ni| { for nmod.items.each |ni| {
match /*bad*/copy ni.node { match /*bad*/copy ni.node {
ast::foreign_item_fn(decl, _, _) => { ast::foreign_item_fn(ref decl, _, _) => {
check_foreign_fn(cx, it.id, decl); check_foreign_fn(cx, it.id, decl);
} }
// FIXME #4622: Not implemented. // FIXME #4622: Not implemented.
@ -923,8 +923,8 @@ fn check_item_non_camel_case_types(cx: ty::ctxt, it: @ast::item) {
} }
} }
fn check_fn(tcx: ty::ctxt, fk: &visit::fn_kind, decl: ast::fn_decl, fn check_fn(tcx: ty::ctxt, fk: &visit::fn_kind, decl: &ast::fn_decl,
_body: ast::blk, span: span, id: ast::node_id) { _body: &ast::blk, span: span, id: ast::node_id) {
debug!("lint check_fn fk=%? id=%?", fk, id); debug!("lint check_fn fk=%? id=%?", fk, id);
// don't complain about blocks, since they tend to get their modes // don't complain about blocks, since they tend to get their modes
@ -938,7 +938,7 @@ fn check_fn(tcx: ty::ctxt, fk: &visit::fn_kind, decl: ast::fn_decl,
check_fn_deprecated_modes(tcx, fn_ty, decl, span, id); check_fn_deprecated_modes(tcx, fn_ty, decl, span, id);
} }
fn check_fn_deprecated_modes(tcx: ty::ctxt, fn_ty: ty::t, decl: ast::fn_decl, fn check_fn_deprecated_modes(tcx: ty::ctxt, fn_ty: ty::t, decl: &ast::fn_decl,
span: span, id: ast::node_id) { span: span, id: ast::node_id) {
match ty::get(fn_ty).sty { match ty::get(fn_ty).sty {
ty::ty_closure(ty::ClosureTy {sig: ref sig, _}) | ty::ty_closure(ty::ClosureTy {sig: ref sig, _}) |
@ -990,7 +990,7 @@ fn check_fn_deprecated_modes(tcx: ty::ctxt, fn_ty: ty::t, decl: ast::fn_decl,
ast::ty_closure(@ast::TyClosure{decl: ref d, _}) | ast::ty_closure(@ast::TyClosure{decl: ref d, _}) |
ast::ty_bare_fn(@ast::TyBareFn{decl: ref d, _})=>{ ast::ty_bare_fn(@ast::TyBareFn{decl: ref d, _})=>{
check_fn_deprecated_modes(tcx, arg_ty.ty, check_fn_deprecated_modes(tcx, arg_ty.ty,
*d, span, id); d, span, id);
} }
ast::ty_path(*) => { ast::ty_path(*) => {
// This is probably a typedef, so we can't // This is probably a typedef, so we can't
@ -1026,7 +1026,7 @@ fn check_item_deprecated_modes(tcx: ty::ctxt, it: @ast::item) {
ast::ty_bare_fn(@ast::TyBareFn {decl: ref decl, _}) => { ast::ty_bare_fn(@ast::TyBareFn {decl: ref decl, _}) => {
let fn_ty = ty::node_id_to_type(tcx, it.id); let fn_ty = ty::node_id_to_type(tcx, it.id);
check_fn_deprecated_modes( check_fn_deprecated_modes(
tcx, fn_ty, *decl, ty.span, it.id) tcx, fn_ty, decl, ty.span, it.id)
} }
_ => () _ => ()
} }

View file

@ -436,8 +436,8 @@ impl IrMaps {
} }
fn visit_fn(fk: &visit::fn_kind, fn visit_fn(fk: &visit::fn_kind,
decl: fn_decl, decl: &fn_decl,
body: blk, body: &blk,
sp: span, sp: span,
id: node_id, id: node_id,
&&self: @mut IrMaps, &&self: @mut IrMaps,
@ -540,7 +540,7 @@ fn visit_local(local: @local, &&self: @mut IrMaps, vt: vt<@mut IrMaps>) {
visit::visit_local(local, self, vt); visit::visit_local(local, self, vt);
} }
fn visit_arm(arm: arm, &&self: @mut IrMaps, vt: vt<@mut IrMaps>) { fn visit_arm(arm: &arm, &&self: @mut IrMaps, vt: vt<@mut IrMaps>) {
let def_map = self.tcx.def_map; let def_map = self.tcx.def_map;
for arm.pats.each |pat| { for arm.pats.each |pat| {
do pat_util::pat_bindings(def_map, *pat) |bm, p_id, sp, path| { do pat_util::pat_bindings(def_map, *pat) |bm, p_id, sp, path| {
@ -979,7 +979,7 @@ impl Liveness {
// _______________________________________________________________________ // _______________________________________________________________________
fn compute(&self, decl: fn_decl, body: blk) -> LiveNode { fn compute(&self, decl: &fn_decl, body: &blk) -> LiveNode {
// if there is a `break` or `again` at the top level, then it's // if there is a `break` or `again` at the top level, then it's
// effectively a return---this only occurs in `for` loops, // effectively a return---this only occurs in `for` loops,
// where the body is really a closure. // where the body is really a closure.
@ -1004,7 +1004,7 @@ impl Liveness {
entry_ln entry_ln
} }
fn propagate_through_fn_block(&self, decl: fn_decl, blk: blk) fn propagate_through_fn_block(&self, decl: &fn_decl, blk: &blk)
-> LiveNode { -> LiveNode {
// inputs passed by & mode should be considered live on exit: // inputs passed by & mode should be considered live on exit:
for decl.inputs.each |arg| { for decl.inputs.each |arg| {
@ -1038,7 +1038,7 @@ impl Liveness {
self.propagate_through_block(blk, self.s.fallthrough_ln) self.propagate_through_block(blk, self.s.fallthrough_ln)
} }
fn propagate_through_block(&self, blk: blk, succ: LiveNode) -> LiveNode { fn propagate_through_block(&self, blk: &blk, succ: LiveNode) -> LiveNode {
let succ = self.propagate_through_opt_expr(blk.node.expr, succ); let succ = self.propagate_through_opt_expr(blk.node.expr, succ);
do blk.node.stmts.foldr(succ) |stmt, succ| { do blk.node.stmts.foldr(succ) |stmt, succ| {
self.propagate_through_stmt(*stmt, succ) self.propagate_through_stmt(*stmt, succ)
@ -1134,7 +1134,7 @@ impl Liveness {
The next-node for a break is the successor of the entire The next-node for a break is the successor of the entire
loop. The next-node for a continue is the top of this loop. loop. The next-node for a continue is the top of this loop.
*/ */
self.with_loop_nodes((*blk).node.id, succ, self.with_loop_nodes(blk.node.id, succ,
self.live_node(expr.id, expr.span), || { self.live_node(expr.id, expr.span), || {
// the construction of a closure itself is not important, // the construction of a closure itself is not important,
@ -1164,7 +1164,7 @@ impl Liveness {
// ( succ ) // ( succ )
// //
let else_ln = self.propagate_through_opt_expr(els, succ); let else_ln = self.propagate_through_opt_expr(els, succ);
let then_ln = self.propagate_through_block((*then), succ); let then_ln = self.propagate_through_block(then, succ);
let ln = self.live_node(expr.id, expr.span); let ln = self.live_node(expr.id, expr.span);
self.init_from_succ(ln, else_ln); self.init_from_succ(ln, else_ln);
self.merge_from_succ(ln, then_ln, false); self.merge_from_succ(ln, then_ln, false);
@ -1172,13 +1172,13 @@ impl Liveness {
} }
expr_while(cond, ref blk) => { expr_while(cond, ref blk) => {
self.propagate_through_loop(expr, Some(cond), (*blk), succ) self.propagate_through_loop(expr, Some(cond), blk, succ)
} }
// Note that labels have been resolved, so we don't need to look // Note that labels have been resolved, so we don't need to look
// at the label ident // at the label ident
expr_loop(ref blk, _) => { expr_loop(ref blk, _) => {
self.propagate_through_loop(expr, None, (*blk), succ) self.propagate_through_loop(expr, None, blk, succ)
} }
expr_match(e, ref arms) => { expr_match(e, ref arms) => {
@ -1199,9 +1199,9 @@ impl Liveness {
let ln = self.live_node(expr.id, expr.span); let ln = self.live_node(expr.id, expr.span);
self.init_empty(ln, succ); self.init_empty(ln, succ);
let mut first_merge = true; let mut first_merge = true;
for (*arms).each |arm| { for arms.each |arm| {
let body_succ = let body_succ =
self.propagate_through_block(arm.body, succ); self.propagate_through_block(&arm.body, succ);
let guard_succ = let guard_succ =
self.propagate_through_opt_expr(arm.guard, body_succ); self.propagate_through_opt_expr(arm.guard, body_succ);
let arm_succ = let arm_succ =
@ -1362,7 +1362,7 @@ impl Liveness {
} }
expr_block(ref blk) => { expr_block(ref blk) => {
self.propagate_through_block((*blk), succ) self.propagate_through_block(blk, succ)
} }
expr_mac(*) => { expr_mac(*) => {
@ -1463,7 +1463,7 @@ impl Liveness {
fn propagate_through_loop(&self, expr: @expr, fn propagate_through_loop(&self, expr: @expr,
cond: Option<@expr>, cond: Option<@expr>,
body: blk, body: &blk,
succ: LiveNode) -> LiveNode { succ: LiveNode) -> LiveNode {
/* /*
@ -1568,7 +1568,7 @@ fn check_local(local: @local, &&self: @Liveness, vt: vt<@Liveness>) {
visit::visit_local(local, self, vt); visit::visit_local(local, self, vt);
} }
fn check_arm(arm: arm, &&self: @Liveness, vt: vt<@Liveness>) { fn check_arm(arm: &arm, &&self: @Liveness, vt: vt<@Liveness>) {
do self.arm_pats_bindings(arm.pats) |ln, var, sp| { do self.arm_pats_bindings(arm.pats) |ln, var, sp| {
self.warn_about_unused(sp, ln, var); self.warn_about_unused(sp, ln, var);
} }
@ -1639,8 +1639,8 @@ fn check_expr(expr: @expr, &&self: @Liveness, vt: vt<@Liveness>) {
} }
} }
fn check_fn(_fk: &visit::fn_kind, _decl: fn_decl, fn check_fn(_fk: &visit::fn_kind, _decl: &fn_decl,
_body: blk, _sp: span, _id: node_id, _body: &blk, _sp: span, _id: node_id,
&&_self: @Liveness, _v: vt<@Liveness>) { &&_self: @Liveness, _v: vt<@Liveness>) {
// do not check contents of nested fns // do not check contents of nested fns
} }
@ -1885,7 +1885,7 @@ impl @Liveness {
if name[0] == ('_' as u8) { None } else { Some(name) } if name[0] == ('_' as u8) { None } else { Some(name) }
} }
fn warn_about_unused_args(&self, decl: fn_decl, entry_ln: LiveNode) { fn warn_about_unused_args(&self, decl: &fn_decl, entry_ln: LiveNode) {
for decl.inputs.each |arg| { for decl.inputs.each |arg| {
do pat_util::pat_bindings(self.tcx.def_map, arg.pat) do pat_util::pat_bindings(self.tcx.def_map, arg.pat)
|_bm, p_id, sp, _n| { |_bm, p_id, sp, _n| {

View file

@ -221,7 +221,7 @@ pub fn record_parent(cx: ctxt, child_id: ast::node_id) {
} }
} }
pub fn resolve_block(blk: ast::blk, cx: ctxt, visitor: visit::vt<ctxt>) { pub fn resolve_block(blk: &ast::blk, cx: ctxt, visitor: visit::vt<ctxt>) {
// Record the parent of this block. // Record the parent of this block.
record_parent(cx, blk.node.id); record_parent(cx, blk.node.id);
@ -230,7 +230,7 @@ pub fn resolve_block(blk: ast::blk, cx: ctxt, visitor: visit::vt<ctxt>) {
visit::visit_block(blk, new_cx, visitor); visit::visit_block(blk, new_cx, visitor);
} }
pub fn resolve_arm(arm: ast::arm, cx: ctxt, visitor: visit::vt<ctxt>) { pub fn resolve_arm(arm: &ast::arm, cx: ctxt, visitor: visit::vt<ctxt>) {
visit::visit_arm(arm, cx, visitor); visit::visit_arm(arm, cx, visitor);
} }
@ -317,8 +317,8 @@ pub fn resolve_item(item: @ast::item, cx: ctxt, visitor: visit::vt<ctxt>) {
} }
pub fn resolve_fn(fk: &visit::fn_kind, pub fn resolve_fn(fk: &visit::fn_kind,
decl: ast::fn_decl, decl: &ast::fn_decl,
body: ast::blk, body: &ast::blk,
sp: span, sp: span,
id: ast::node_id, id: ast::node_id,
cx: ctxt, cx: ctxt,
@ -608,8 +608,8 @@ pub fn determine_rp_in_item(item: @ast::item,
} }
pub fn determine_rp_in_fn(fk: &visit::fn_kind, pub fn determine_rp_in_fn(fk: &visit::fn_kind,
decl: ast::fn_decl, decl: &ast::fn_decl,
body: ast::blk, body: &ast::blk,
_: span, _: span,
_: ast::node_id, _: ast::node_id,
&&cx: @mut DetermineRpCtxt, &&cx: @mut DetermineRpCtxt,
@ -626,7 +626,7 @@ pub fn determine_rp_in_fn(fk: &visit::fn_kind,
} }
} }
pub fn determine_rp_in_ty_method(ty_m: ast::ty_method, pub fn determine_rp_in_ty_method(ty_m: &ast::ty_method,
&&cx: @mut DetermineRpCtxt, &&cx: @mut DetermineRpCtxt,
visitor: visit::vt<@mut DetermineRpCtxt>) { visitor: visit::vt<@mut DetermineRpCtxt>) {
do cx.with(cx.item_id, false) { do cx.with(cx.item_id, false) {

View file

@ -1027,7 +1027,7 @@ pub impl Resolver {
} }
} }
fn block_needs_anonymous_module(@mut self, block: blk) -> bool { fn block_needs_anonymous_module(@mut self, block: &blk) -> bool {
// If the block has view items, we need an anonymous module. // If the block has view items, we need an anonymous module.
if block.node.view_items.len() > 0 { if block.node.view_items.len() > 0 {
return true; return true;
@ -1276,7 +1276,7 @@ pub impl Resolver {
// methods, so check that first. // methods, so check that first.
let mut has_static_methods = false; let mut has_static_methods = false;
for (*methods).each |method| { for (*methods).each |method| {
let ty_m = trait_method_to_ty_method(*method); let ty_m = trait_method_to_ty_method(method);
match ty_m.self_ty.node { match ty_m.self_ty.node {
sty_static => { sty_static => {
has_static_methods = true; has_static_methods = true;
@ -1304,7 +1304,7 @@ pub impl Resolver {
// Add the names of all the methods to the trait info. // Add the names of all the methods to the trait info.
let method_names = @HashMap(); let method_names = @HashMap();
for (*methods).each |method| { for (*methods).each |method| {
let ty_m = trait_method_to_ty_method(*method); let ty_m = trait_method_to_ty_method(method);
let ident = ty_m.ident; let ident = ty_m.ident;
// Add it to the trait info if not static, // Add it to the trait info if not static,
@ -1534,7 +1534,7 @@ pub impl Resolver {
} }
fn build_reduced_graph_for_block(@mut self, fn build_reduced_graph_for_block(@mut self,
block: blk, block: &blk,
parent: ReducedGraphParent, parent: ReducedGraphParent,
&&visitor: vt<ReducedGraphParent>) { &&visitor: vt<ReducedGraphParent>) {
let mut new_parent; let mut new_parent;
@ -3788,7 +3788,7 @@ pub impl Resolver {
item.id, item.id,
0, 0,
OpaqueFunctionRibKind), OpaqueFunctionRibKind),
(*block), block,
NoSelfBinding, NoSelfBinding,
visitor); visitor);
} }
@ -3866,7 +3866,7 @@ pub impl Resolver {
rib_kind: RibKind, rib_kind: RibKind,
optional_declaration: Option<@fn_decl>, optional_declaration: Option<@fn_decl>,
type_parameters: TypeParameters, type_parameters: TypeParameters,
block: blk, block: &blk,
self_binding: SelfBinding, self_binding: SelfBinding,
visitor: ResolveVisitor) { visitor: ResolveVisitor) {
// Create a value rib for the function. // Create a value rib for the function.
@ -3982,7 +3982,7 @@ pub impl Resolver {
self.resolve_function(NormalRibKind, self.resolve_function(NormalRibKind,
None, None,
NoTypeParameters, NoTypeParameters,
(*destructor).node.body, &destructor.node.body,
HasSelfBinding HasSelfBinding
((*destructor).node.self_id, ((*destructor).node.self_id,
true), true),
@ -4015,7 +4015,7 @@ pub impl Resolver {
self.resolve_function(rib_kind, self.resolve_function(rib_kind,
Some(@/*bad*/copy method.decl), Some(@/*bad*/copy method.decl),
type_parameters, type_parameters,
method.body, &method.body,
self_binding, self_binding,
visitor); visitor);
} }
@ -4140,7 +4140,7 @@ pub impl Resolver {
return result; return result;
} }
fn check_consistent_bindings(@mut self, arm: arm) { fn check_consistent_bindings(@mut self, arm: &arm) {
if arm.pats.len() == 0 { return; } if arm.pats.len() == 0 { return; }
let map_0 = self.binding_mode_map(arm.pats[0]); let map_0 = self.binding_mode_map(arm.pats[0]);
for arm.pats.eachi() |i, p| { for arm.pats.eachi() |i, p| {
@ -4179,7 +4179,7 @@ pub impl Resolver {
} }
} }
fn resolve_arm(@mut self, arm: arm, visitor: ResolveVisitor) { fn resolve_arm(@mut self, arm: &arm, visitor: ResolveVisitor) {
(*self.value_ribs).push(@Rib(NormalRibKind)); (*self.value_ribs).push(@Rib(NormalRibKind));
let bindings_list = HashMap(); let bindings_list = HashMap();
@ -4193,12 +4193,12 @@ pub impl Resolver {
self.check_consistent_bindings(arm); self.check_consistent_bindings(arm);
visit_expr_opt(arm.guard, (), visitor); visit_expr_opt(arm.guard, (), visitor);
self.resolve_block(arm.body, visitor); self.resolve_block(&arm.body, visitor);
(*self.value_ribs).pop(); (*self.value_ribs).pop();
} }
fn resolve_block(@mut self, block: blk, visitor: ResolveVisitor) { fn resolve_block(@mut self, block: &blk, visitor: ResolveVisitor) {
debug!("(resolving block) entering block"); debug!("(resolving block) entering block");
(*self.value_ribs).push(@Rib(NormalRibKind)); (*self.value_ribs).push(@Rib(NormalRibKind));
@ -4910,7 +4910,7 @@ pub impl Resolver {
self.resolve_function(FunctionRibKind(expr.id, block.node.id), self.resolve_function(FunctionRibKind(expr.id, block.node.id),
Some(@/*bad*/copy *fn_decl), Some(@/*bad*/copy *fn_decl),
NoTypeParameters, NoTypeParameters,
(*block), block,
NoSelfBinding, NoSelfBinding,
visitor); visitor);
} }

View file

@ -2093,7 +2093,7 @@ pub fn trans_item(ccx: @CrateContext, item: ast::item) {
vec::append(/*bad*/copy *path, ~[path_name(item.ident)]), vec::append(/*bad*/copy *path, ~[path_name(item.ident)]),
decl, body, llfndecl, no_self, None, item.id, None); decl, body, llfndecl, no_self, None, item.id, None);
} else { } else {
for vec::each((*body).node.stmts) |stmt| { for body.node.stmts.each |stmt| {
match stmt.node { match stmt.node {
ast::stmt_decl(@codemap::spanned { node: ast::decl_item(i), ast::stmt_decl(@codemap::spanned { node: ast::decl_item(i),
_ }, _) => { _ }, _) => {
@ -2108,7 +2108,7 @@ pub fn trans_item(ccx: @CrateContext, item: ast::item) {
meth::trans_impl(ccx, /*bad*/copy *path, item.ident, ms, tps, None, meth::trans_impl(ccx, /*bad*/copy *path, item.ident, ms, tps, None,
item.id); item.id);
} }
ast::item_mod(m) => { ast::item_mod(ref m) => {
trans_mod(ccx, m); trans_mod(ccx, m);
} }
ast::item_enum(ref enum_definition, ref tps) => { ast::item_enum(ref enum_definition, ref tps) => {
@ -2121,11 +2121,10 @@ pub fn trans_item(ccx: @CrateContext, item: ast::item) {
} }
} }
ast::item_const(_, expr) => consts::trans_const(ccx, expr, item.id), ast::item_const(_, expr) => consts::trans_const(ccx, expr, item.id),
ast::item_foreign_mod(foreign_mod) => { ast::item_foreign_mod(ref foreign_mod) => {
let abi = match attr::foreign_abi(item.attrs) { let abi = match attr::foreign_abi(item.attrs) {
either::Right(abi_) => abi_, Right(abi_) => abi_,
either::Left(ref msg) => ccx.sess.span_fatal(item.span, Left(ref msg) => ccx.sess.span_fatal(item.span, /*bad*/copy *msg)
/*bad*/copy *msg)
}; };
foreign::trans_foreign_mod(ccx, foreign_mod, abi); foreign::trans_foreign_mod(ccx, foreign_mod, abi);
} }
@ -2165,9 +2164,9 @@ pub fn trans_struct_def(ccx: @CrateContext, struct_def: @ast::struct_def,
// separate modules in the compiled program. That's because modules exist // separate modules in the compiled program. That's because modules exist
// only as a convenience for humans working with the code, to organize names // only as a convenience for humans working with the code, to organize names
// and control visibility. // and control visibility.
pub fn trans_mod(ccx: @CrateContext, m: ast::_mod) { pub fn trans_mod(ccx: @CrateContext, m: &ast::_mod) {
let _icx = ccx.insn_ctxt("trans_mod"); let _icx = ccx.insn_ctxt("trans_mod");
for vec::each(m.items) |item| { for m.items.each |item| {
trans_item(ccx, **item); trans_item(ccx, **item);
} }
} }
@ -3130,7 +3129,7 @@ pub fn trans_crate(sess: session::Session,
{ {
let _icx = ccx.insn_ctxt("text"); let _icx = ccx.insn_ctxt("text");
trans_mod(ccx, crate.node.module); trans_mod(ccx, &crate.node.module);
} }
decl_gc_metadata(ccx, llmod_id); decl_gc_metadata(ccx, llmod_id);

View file

@ -390,7 +390,7 @@ pub fn trans_rtcall_or_lang_call_with_type_params(bcx: block,
ArgVals(args), dest, DontAutorefArg); ArgVals(args), dest, DontAutorefArg);
} }
pub fn body_contains_ret(body: ast::blk) -> bool { pub fn body_contains_ret(body: &ast::blk) -> bool {
let cx = @mut false; let cx = @mut false;
visit::visit_block(body, cx, visit::mk_vt(@visit::Visitor { visit::visit_block(body, cx, visit::mk_vt(@visit::Visitor {
visit_item: |_i, _cx, _v| { }, visit_item: |_i, _cx, _v| { },
@ -424,7 +424,7 @@ pub fn trans_call_inner(
ast::expr_loop_body(@ast::expr { ast::expr_loop_body(@ast::expr {
node: ast::expr_fn_block(_, ref body), node: ast::expr_fn_block(_, ref body),
_ _
}) => body_contains_ret((*body)), }) => body_contains_ret(body),
_ => false _ => false
} }
} }

View file

@ -202,7 +202,7 @@ fn build_wrap_fn_(ccx: @CrateContext,
// function itself is unnecessary). We used to do this, in fact, and will // function itself is unnecessary). We used to do this, in fact, and will
// perhaps do so in the future. // perhaps do so in the future.
pub fn trans_foreign_mod(ccx: @CrateContext, pub fn trans_foreign_mod(ccx: @CrateContext,
foreign_mod: ast::foreign_mod, foreign_mod: &ast::foreign_mod,
abi: ast::foreign_abi) { abi: ast::foreign_abi) {
let _icx = ccx.insn_ctxt("foreign::trans_foreign_mod"); let _icx = ccx.insn_ctxt("foreign::trans_foreign_mod");

View file

@ -310,7 +310,7 @@ pub fn trans_static_method_callee(bcx: block,
let mname = if method_id.crate == ast::local_crate { let mname = if method_id.crate == ast::local_crate {
match bcx.tcx().items.get(&method_id.node) { match bcx.tcx().items.get(&method_id.node) {
ast_map::node_trait_method(trait_method, _, _) => { ast_map::node_trait_method(trait_method, _, _) => {
ast_util::trait_method_to_ty_method(*trait_method).ident ast_util::trait_method_to_ty_method(trait_method).ident
} }
_ => fail!(~"callee is not a trait method") _ => fail!(~"callee is not a trait method")
} }

View file

@ -109,7 +109,7 @@ fn traverse_public_item(cx: ctx, item: @item) {
item_fn(_, _, ref tps, ref blk) => { item_fn(_, _, ref tps, ref blk) => {
if tps.len() > 0u || if tps.len() > 0u ||
attr::find_inline_attr(item.attrs) != attr::ia_none { attr::find_inline_attr(item.attrs) != attr::ia_none {
traverse_inline_body(cx, (*blk)); traverse_inline_body(cx, blk);
} }
} }
item_impl(tps, _, _, ms) => { item_impl(tps, _, _, ms) => {
@ -117,7 +117,7 @@ fn traverse_public_item(cx: ctx, item: @item) {
if tps.len() > 0u || m.tps.len() > 0u || if tps.len() > 0u || m.tps.len() > 0u ||
attr::find_inline_attr(m.attrs) != attr::ia_none { attr::find_inline_attr(m.attrs) != attr::ia_none {
cx.rmap.insert(m.id, ()); cx.rmap.insert(m.id, ());
traverse_inline_body(cx, m.body); traverse_inline_body(cx, &m.body);
} }
} }
} }
@ -129,7 +129,7 @@ fn traverse_public_item(cx: ctx, item: @item) {
cx.rmap.insert(dtor.node.id, ()); cx.rmap.insert(dtor.node.id, ());
if tps.len() > 0u || attr::find_inline_attr(dtor.node.attrs) if tps.len() > 0u || attr::find_inline_attr(dtor.node.attrs)
!= attr::ia_none { != attr::ia_none {
traverse_inline_body(cx, dtor.node.body); traverse_inline_body(cx, &dtor.node.body);
} }
} }
} }
@ -168,7 +168,7 @@ fn traverse_ty(ty: @Ty, cx: ctx, v: visit::vt<ctx>) {
} }
} }
fn traverse_inline_body(cx: ctx, body: blk) { fn traverse_inline_body(cx: ctx, body: &blk) {
fn traverse_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) { fn traverse_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) {
match e.node { match e.node {
expr_path(_) => { expr_path(_) => {
@ -217,7 +217,7 @@ fn traverse_inline_body(cx: ctx, body: blk) {
fn traverse_item(i: @item, cx: ctx, _v: visit::vt<ctx>) { fn traverse_item(i: @item, cx: ctx, _v: visit::vt<ctx>) {
traverse_public_item(cx, i); traverse_public_item(cx, i);
} }
visit::visit_block(body, cx, visit::mk_vt(@visit::Visitor { visit::visit_block(body, cx, visit::mk_vt(@visit::Visitor {
visit_expr: traverse_expr, visit_expr: traverse_expr,
visit_item: traverse_item, visit_item: traverse_item,
..*visit::default_visitor() ..*visit::default_visitor()

View file

@ -103,7 +103,7 @@ pub fn type_uses_for(ccx: @CrateContext, fn_id: def_id, n_tps: uint)
ast_map::node_item(@ast::item { node: item_fn(_, _, _, ref body), ast_map::node_item(@ast::item { node: item_fn(_, _, _, ref body),
_ }, _) | _ }, _) |
ast_map::node_method(@ast::method {body: ref body, _}, _, _) => { ast_map::node_method(@ast::method {body: ref body, _}, _, _) => {
handle_body(cx, (*body)); handle_body(cx, body);
} }
ast_map::node_trait_method(*) => { ast_map::node_trait_method(*) => {
// This will be a static trait method. For now, we just assume // This will be a static trait method. For now, we just assume
@ -159,8 +159,8 @@ pub fn type_uses_for(ccx: @CrateContext, fn_id: def_id, n_tps: uint)
for uint::range(0u, n_tps) |n| { cx.uses[n] |= flags;} for uint::range(0u, n_tps) |n| { cx.uses[n] |= flags;}
} }
} }
ast_map::node_dtor(_, dtor, _, _) => { ast_map::node_dtor(_, ref dtor, _, _) => {
handle_body(cx, dtor.node.body); handle_body(cx, &dtor.node.body);
} }
ast_map::node_struct_ctor(*) => { ast_map::node_struct_ctor(*) => {
// Similarly to node_variant, this monomorphized function just uses // Similarly to node_variant, this monomorphized function just uses
@ -359,7 +359,7 @@ pub fn mark_for_expr(cx: Context, e: @expr) {
} }
} }
pub fn handle_body(cx: Context, body: blk) { pub fn handle_body(cx: Context, body: &blk) {
let v = visit::mk_vt(@visit::Visitor { let v = visit::mk_vt(@visit::Visitor {
visit_expr: |e, cx, v| { visit_expr: |e, cx, v| {
visit::visit_expr(e, cx, v); visit::visit_expr(e, cx, v);

View file

@ -3850,7 +3850,7 @@ pub fn item_path(cx: ctxt, id: ast::def_id) -> ast_map::path {
ast_map::path_name(method.ident)) ast_map::path_name(method.ident))
} }
ast_map::node_trait_method(trait_method, _, path) => { ast_map::node_trait_method(trait_method, _, path) => {
let method = ast_util::trait_method_to_ty_method(*trait_method); let method = ast_util::trait_method_to_ty_method(&*trait_method);
vec::append_one(/*bad*/copy *path, vec::append_one(/*bad*/copy *path,
ast_map::path_name(method.ident)) ast_map::path_name(method.ident))
} }

View file

@ -332,14 +332,14 @@ pub fn ast_ty_to_ty<AC:AstConv,RS:region_scope + Copy + Durable>(
}; };
ty::mk_rec(tcx, flds) ty::mk_rec(tcx, flds)
} }
ast::ty_bare_fn(bf) => { ast::ty_bare_fn(ref bf) => {
ty::mk_bare_fn(tcx, ty_of_bare_fn(self, rscope, bf.purity, ty::mk_bare_fn(tcx, ty_of_bare_fn(self, rscope, bf.purity,
bf.abi, bf.decl)) bf.abi, &bf.decl))
} }
ast::ty_closure(f) => { ast::ty_closure(ref f) => {
let fn_decl = ty_of_closure(self, rscope, f.sigil, let fn_decl = ty_of_closure(self, rscope, f.sigil,
f.purity, f.onceness, f.purity, f.onceness,
f.region, f.decl, None, f.region, &f.decl, None,
ast_ty.span); ast_ty.span);
ty::mk_closure(tcx, fn_decl) ty::mk_closure(tcx, fn_decl)
} }
@ -473,7 +473,7 @@ pub fn ty_of_bare_fn<AC:AstConv,RS:region_scope + Copy + Durable>(
rscope: RS, rscope: RS,
purity: ast::purity, purity: ast::purity,
abi: ast::Abi, abi: ast::Abi,
decl: ast::fn_decl) decl: &ast::fn_decl)
-> ty::BareFnTy { -> ty::BareFnTy {
debug!("ty_of_fn_decl"); debug!("ty_of_fn_decl");
@ -501,7 +501,7 @@ pub fn ty_of_closure<AC:AstConv,RS:region_scope + Copy + Durable>(
purity: ast::purity, purity: ast::purity,
onceness: ast::Onceness, onceness: ast::Onceness,
opt_region: Option<@ast::region>, opt_region: Option<@ast::region>,
decl: ast::fn_decl, decl: &ast::fn_decl,
expected_tys: Option<ty::FnSig>, expected_tys: Option<ty::FnSig>,
span: span) span: span)
-> ty::ClosureTy { -> ty::ClosureTy {

View file

@ -58,7 +58,7 @@ pub fn check_match(fcx: @mut FnCtxt,
Some(e) => { check_expr_has_type(fcx, e, ty::mk_bool(tcx)); }, Some(e) => { check_expr_has_type(fcx, e, ty::mk_bool(tcx)); },
None => () None => ()
} }
if !check_block(fcx, arm.body) { arm_non_bot = true; } if !check_block(fcx, &arm.body) { arm_non_bot = true; }
let bty = fcx.node_ty(arm.body.node.id); let bty = fcx.node_ty(arm.body.node.id);
demand::suptype(fcx, arm.body.span, result_ty, bty); demand::suptype(fcx, arm.body.span, result_ty, bty);
} }

View file

@ -244,7 +244,7 @@ pub fn check_item_types(ccx: @mut CrateCtxt, crate: @ast::crate) {
pub fn check_bare_fn(ccx: @mut CrateCtxt, pub fn check_bare_fn(ccx: @mut CrateCtxt,
decl: &ast::fn_decl, decl: &ast::fn_decl,
body: ast::blk, body: &ast::blk,
id: ast::node_id, id: ast::node_id,
self_info: Option<SelfInfo>) { self_info: Option<SelfInfo>) {
let fty = ty::node_id_to_type(ccx.tcx, id); let fty = ty::node_id_to_type(ccx.tcx, id);
@ -264,7 +264,7 @@ pub fn check_fn(ccx: @mut CrateCtxt,
sigil: Option<ast::Sigil>, sigil: Option<ast::Sigil>,
fn_sig: &ty::FnSig, fn_sig: &ty::FnSig,
decl: &ast::fn_decl, decl: &ast::fn_decl,
body: ast::blk, body: &ast::blk,
fn_kind: FnKind, fn_kind: FnKind,
old_fcx: Option<@mut FnCtxt>) { old_fcx: Option<@mut FnCtxt>) {
let tcx = ccx.tcx; let tcx = ccx.tcx;
@ -381,7 +381,7 @@ pub fn check_fn(ccx: @mut CrateCtxt,
fn gather_locals(fcx: @mut FnCtxt, fn gather_locals(fcx: @mut FnCtxt,
decl: &ast::fn_decl, decl: &ast::fn_decl,
body: ast::blk, body: &ast::blk,
arg_tys: &[ty::t], arg_tys: &[ty::t],
self_info: Option<SelfInfo>) { self_info: Option<SelfInfo>) {
let tcx = fcx.ccx.tcx; let tcx = fcx.ccx.tcx;
@ -459,7 +459,7 @@ pub fn check_fn(ccx: @mut CrateCtxt,
visit::visit_pat(p, e, v); visit::visit_pat(p, e, v);
}; };
let visit_block = fn@(b: ast::blk, &&e: (), v: visit::vt<()>) { let visit_block = fn@(b: &ast::blk, &&e: (), v: visit::vt<()>) {
// non-obvious: the `blk` variable maps to region lb, so // non-obvious: the `blk` variable maps to region lb, so
// we have to keep this up-to-date. This // we have to keep this up-to-date. This
// is... unfortunate. It'd be nice to not need this. // is... unfortunate. It'd be nice to not need this.
@ -469,8 +469,8 @@ pub fn check_fn(ccx: @mut CrateCtxt,
}; };
// Don't descend into fns and items // Don't descend into fns and items
fn visit_fn(_fk: &visit::fn_kind, _decl: ast::fn_decl, fn visit_fn(_fk: &visit::fn_kind, _decl: &ast::fn_decl,
_body: ast::blk, _sp: span, _body: &ast::blk, _sp: span,
_id: ast::node_id, &&_t: (), _v: visit::vt<()>) { _id: ast::node_id, &&_t: (), _v: visit::vt<()>) {
} }
fn visit_item(_i: @ast::item, &&_e: (), _v: visit::vt<()>) { } fn visit_item(_i: @ast::item, &&_e: (), _v: visit::vt<()>) { }
@ -497,7 +497,13 @@ pub fn check_method(ccx: @mut CrateCtxt,
def_id: self_impl_def_id, def_id: self_impl_def_id,
explicit_self: method.self_ty explicit_self: method.self_ty
}; };
check_bare_fn(ccx, &method.decl, method.body, method.id, Some(self_info)); check_bare_fn(
ccx,
&method.decl,
&method.body,
method.id,
Some(self_info)
);
} }
pub fn check_no_duplicate_fields(tcx: ty::ctxt, pub fn check_no_duplicate_fields(tcx: ty::ctxt,
@ -541,9 +547,13 @@ pub fn check_struct(ccx: @mut CrateCtxt,
}; };
// typecheck the dtor // typecheck the dtor
let dtor_dec = ast_util::dtor_dec(); let dtor_dec = ast_util::dtor_dec();
check_bare_fn(ccx, &dtor_dec, check_bare_fn(
dtor.node.body, dtor.node.id, ccx,
Some(class_t)); &dtor_dec,
&dtor.node.body,
dtor.node.id,
Some(class_t)
);
}; };
// Check that the class is instantiable // Check that the class is instantiable
@ -565,7 +575,7 @@ pub fn check_item(ccx: @mut CrateCtxt, it: @ast::item) {
it.id); it.id);
} }
ast::item_fn(ref decl, _, _, ref body) => { ast::item_fn(ref decl, _, _, ref body) => {
check_bare_fn(ccx, decl, (*body), it.id, None); check_bare_fn(ccx, decl, body, it.id, None);
} }
ast::item_impl(_, _, ty, ms) => { ast::item_impl(_, _, ty, ms) => {
let rp = ccx.tcx.region_paramd_items.find(&it.id); let rp = ccx.tcx.region_paramd_items.find(&it.id);
@ -1397,7 +1407,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
fn check_for(fcx: @mut FnCtxt, fn check_for(fcx: @mut FnCtxt,
local: @ast::local, local: @ast::local,
element_ty: ty::t, element_ty: ty::t,
body: ast::blk, body: &ast::blk,
node_id: ast::node_id) node_id: ast::node_id)
-> bool { -> bool {
let local_ty = fcx.local_ty(local.span, local.node.id); let local_ty = fcx.local_ty(local.span, local.node.id);
@ -1411,7 +1421,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
// A generic function for checking the then and else in an if // A generic function for checking the then and else in an if
// or if-check // or if-check
fn check_then_else(fcx: @mut FnCtxt, fn check_then_else(fcx: @mut FnCtxt,
thn: ast::blk, thn: &ast::blk,
elsopt: Option<@ast::expr>, elsopt: Option<@ast::expr>,
id: ast::node_id, id: ast::node_id,
_sp: span) _sp: span)
@ -1609,7 +1619,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
expr: @ast::expr, expr: @ast::expr,
ast_sigil_opt: Option<ast::Sigil>, ast_sigil_opt: Option<ast::Sigil>,
decl: &ast::fn_decl, decl: &ast::fn_decl,
body: ast::blk, body: &ast::blk,
fn_kind: FnKind, fn_kind: FnKind,
expected: Option<ty::t>) { expected: Option<ty::t>) {
let tcx = fcx.ccx.tcx; let tcx = fcx.ccx.tcx;
@ -1653,7 +1663,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
let mut fn_ty = astconv::ty_of_closure( let mut fn_ty = astconv::ty_of_closure(
fcx, fcx, fcx, fcx,
sigil, purity, expected_onceness, sigil, purity, expected_onceness,
None, *decl, expected_tys, expr.span); None, decl, expected_tys, expr.span);
let fty = ty::mk_closure(tcx, copy fn_ty); let fty = ty::mk_closure(tcx, copy fn_ty);
@ -2094,7 +2104,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
// message because of the indirect_ret_ty. // message because of the indirect_ret_ty.
let fn_kind = if err_happened {Vanilla} else {ForLoop}; let fn_kind = if err_happened {Vanilla} else {ForLoop};
check_expr_fn(fcx, loop_body, None, check_expr_fn(fcx, loop_body, None,
decl, *body, fn_kind, Some(inner_ty)); decl, body, fn_kind, Some(inner_ty));
demand::suptype(fcx, loop_body.span, demand::suptype(fcx, loop_body.span,
inner_ty, fcx.expr_ty(loop_body)); inner_ty, fcx.expr_ty(loop_body));
} }
@ -2341,28 +2351,28 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
} }
ast::expr_if(cond, ref thn, elsopt) => { ast::expr_if(cond, ref thn, elsopt) => {
bot = check_expr_has_type(fcx, cond, ty::mk_bool(tcx)); bot = check_expr_has_type(fcx, cond, ty::mk_bool(tcx));
bot |= check_then_else(fcx, *thn, elsopt, id, expr.span); bot |= check_then_else(fcx, thn, elsopt, id, expr.span);
} }
ast::expr_while(cond, ref body) => { ast::expr_while(cond, ref body) => {
bot = check_expr_has_type(fcx, cond, ty::mk_bool(tcx)); bot = check_expr_has_type(fcx, cond, ty::mk_bool(tcx));
check_block_no_value(fcx, (*body)); check_block_no_value(fcx, body);
fcx.write_ty(id, ty::mk_nil(tcx)); fcx.write_ty(id, ty::mk_nil(tcx));
} }
ast::expr_loop(ref body, _) => { ast::expr_loop(ref body, _) => {
check_block_no_value(fcx, (*body)); check_block_no_value(fcx, body);
fcx.write_ty(id, ty::mk_nil(tcx)); fcx.write_ty(id, ty::mk_nil(tcx));
bot = !may_break(tcx, expr.id, (*body)); bot = !may_break(tcx, expr.id, body);
} }
ast::expr_match(discrim, ref arms) => { ast::expr_match(discrim, ref arms) => {
bot = _match::check_match(fcx, expr, discrim, (/*bad*/copy *arms)); bot = _match::check_match(fcx, expr, discrim, (/*bad*/copy *arms));
} }
ast::expr_fn(sigil, ref decl, ref body, _) => { ast::expr_fn(sigil, ref decl, ref body, _) => {
check_expr_fn(fcx, expr, Some(sigil), check_expr_fn(fcx, expr, Some(sigil),
decl, (*body), Vanilla, expected); decl, body, Vanilla, expected);
} }
ast::expr_fn_block(ref decl, ref body) => { ast::expr_fn_block(ref decl, ref body) => {
check_expr_fn(fcx, expr, None, check_expr_fn(fcx, expr, None,
decl, (*body), Vanilla, expected); decl, body, Vanilla, expected);
} }
ast::expr_loop_body(loop_body) => { ast::expr_loop_body(loop_body) => {
check_loop_body(fcx, expr, expected, loop_body); check_loop_body(fcx, expr, expected, loop_body);
@ -2392,7 +2402,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
match b.node { match b.node {
ast::expr_fn_block(ref decl, ref body) => { ast::expr_fn_block(ref decl, ref body) => {
check_expr_fn(fcx, b, None, check_expr_fn(fcx, b, None,
decl, *body, DoBlock, Some(inner_ty)); decl, body, DoBlock, Some(inner_ty));
demand::suptype(fcx, b.span, inner_ty, fcx.expr_ty(b)); demand::suptype(fcx, b.span, inner_ty, fcx.expr_ty(b));
} }
// argh // argh
@ -2402,7 +2412,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
} }
ast::expr_block(ref b) => { ast::expr_block(ref b) => {
// If this is an unchecked block, turn off purity-checking // If this is an unchecked block, turn off purity-checking
bot = check_block_with_expected(fcx, *b, expected); bot = check_block_with_expected(fcx, b, expected);
let typ = let typ =
match b.node.expr { match b.node.expr {
Some(expr) => fcx.expr_ty(expr), Some(expr) => fcx.expr_ty(expr),
@ -2692,7 +2702,7 @@ pub fn check_stmt(fcx: @mut FnCtxt, stmt: @ast::stmt) -> bool {
return bot; return bot;
} }
pub fn check_block_no_value(fcx: @mut FnCtxt, blk: ast::blk) -> bool { pub fn check_block_no_value(fcx: @mut FnCtxt, blk: &ast::blk) -> bool {
let bot = check_block(fcx, blk); let bot = check_block(fcx, blk);
if !bot { if !bot {
let blkty = fcx.node_ty(blk.node.id); let blkty = fcx.node_ty(blk.node.id);
@ -2702,12 +2712,12 @@ pub fn check_block_no_value(fcx: @mut FnCtxt, blk: ast::blk) -> bool {
return bot; return bot;
} }
pub fn check_block(fcx0: @mut FnCtxt, blk: ast::blk) -> bool { pub fn check_block(fcx0: @mut FnCtxt, blk: &ast::blk) -> bool {
check_block_with_expected(fcx0, blk, None) check_block_with_expected(fcx0, blk, None)
} }
pub fn check_block_with_expected(fcx0: @mut FnCtxt, pub fn check_block_with_expected(fcx0: @mut FnCtxt,
blk: ast::blk, blk: &ast::blk,
expected: Option<ty::t>) expected: Option<ty::t>)
-> bool { -> bool {
let fcx = match blk.node.rules { let fcx = match blk.node.rules {
@ -3102,7 +3112,7 @@ pub fn ast_expr_vstore_to_vstore(fcx: @mut FnCtxt,
} }
// Returns true if b contains a break that can exit from b // Returns true if b contains a break that can exit from b
pub fn may_break(cx: ty::ctxt, id: ast::node_id, b: ast::blk) -> bool { pub fn may_break(cx: ty::ctxt, id: ast::node_id, b: &ast::blk) -> bool {
// First: is there an unlabeled break immediately // First: is there an unlabeled break immediately
// inside the loop? // inside the loop?
(loop_query(b, |e| { (loop_query(b, |e| {

View file

@ -125,7 +125,7 @@ pub fn regionck_expr(fcx: @mut FnCtxt, e: @ast::expr) {
fcx.infcx().resolve_regions(); fcx.infcx().resolve_regions();
} }
pub fn regionck_fn(fcx: @mut FnCtxt, blk: ast::blk) { pub fn regionck_fn(fcx: @mut FnCtxt, blk: &ast::blk) {
let rcx = @mut Rcx { fcx: fcx, errors_reported: 0 }; let rcx = @mut Rcx { fcx: fcx, errors_reported: 0 };
let v = regionck_visitor(); let v = regionck_visitor();
(v.visit_block)(blk, rcx, v); (v.visit_block)(blk, rcx, v);
@ -176,7 +176,7 @@ pub fn visit_local(l: @ast::local, &&rcx: @mut Rcx, v: rvt) {
} }
} }
pub fn visit_block(b: ast::blk, &&rcx: @mut Rcx, v: rvt) { pub fn visit_block(b: &ast::blk, &&rcx: @mut Rcx, v: rvt) {
visit::visit_block(b, rcx, v); visit::visit_block(b, rcx, v);
} }

View file

@ -731,7 +731,7 @@ pub fn resolve_expr(ex: @ast::expr,
// Detect points where a trait-bounded type parameter is // Detect points where a trait-bounded type parameter is
// instantiated, resolve the impls for the parameters. // instantiated, resolve the impls for the parameters.
pub fn resolve_in_block(fcx: @mut FnCtxt, bl: ast::blk) { pub fn resolve_in_block(fcx: @mut FnCtxt, bl: &ast::blk) {
visit::visit_block(bl, fcx, visit::mk_vt(@visit::Visitor { visit::visit_block(bl, fcx, visit::mk_vt(@visit::Visitor {
visit_expr: resolve_expr, visit_expr: resolve_expr,
visit_item: |_,_,_| {}, visit_item: |_,_,_| {},

View file

@ -200,7 +200,7 @@ fn visit_expr(e: @ast::expr, &&wbcx: @mut WbCtxt, v: wb_vt) {
} }
visit::visit_expr(e, wbcx, v); visit::visit_expr(e, wbcx, v);
} }
fn visit_block(b: ast::blk, &&wbcx: @mut WbCtxt, v: wb_vt) { fn visit_block(b: &ast::blk, &&wbcx: @mut WbCtxt, v: wb_vt) {
if !wbcx.success { return; } if !wbcx.success { return; }
resolve_type_vars_for_node(wbcx, b.span, b.node.id); resolve_type_vars_for_node(wbcx, b.span, b.node.id);
visit::visit_block(b, wbcx, v); visit::visit_block(b, wbcx, v);
@ -260,7 +260,7 @@ pub fn resolve_type_vars_in_expr(fcx: @mut FnCtxt, e: @ast::expr) -> bool {
pub fn resolve_type_vars_in_fn(fcx: @mut FnCtxt, pub fn resolve_type_vars_in_fn(fcx: @mut FnCtxt,
decl: &ast::fn_decl, decl: &ast::fn_decl,
blk: ast::blk, blk: &ast::blk,
self_info: Option<SelfInfo>) -> bool { self_info: Option<SelfInfo>) -> bool {
let wbcx = @mut WbCtxt { fcx: fcx, success: true }; let wbcx = @mut WbCtxt { fcx: fcx, success: true };
let visit = mk_visitor(); let visit = mk_visitor();

View file

@ -228,7 +228,7 @@ pub fn ensure_trait_methods(ccx: @mut CrateCtxt,
} }
fn make_static_method_ty(ccx: @mut CrateCtxt, fn make_static_method_ty(ccx: @mut CrateCtxt,
am: ast::ty_method, am: &ast::ty_method,
rp: Option<ty::region_variance>, rp: Option<ty::region_variance>,
m: ty::method, m: ty::method,
// Take this as an argument b/c we may check // Take this as an argument b/c we may check
@ -289,10 +289,11 @@ pub fn ensure_trait_methods(ccx: @mut CrateCtxt,
} }
let trait_bounds = ty_param_bounds(ccx, *params); let trait_bounds = ty_param_bounds(ccx, *params);
let ty_m = trait_method_to_ty_method(*m); let ty_m = trait_method_to_ty_method(m);
let method_ty = ty_of_ty_method(ccx, ty_m, region_paramd, def_id); let method_ty = ty_of_ty_method(ccx, &ty_m, region_paramd,
def_id);
if ty_m.self_ty.node == ast::sty_static { if ty_m.self_ty.node == ast::sty_static {
make_static_method_ty(ccx, ty_m, region_paramd, make_static_method_ty(ccx, &ty_m, region_paramd,
method_ty, trait_ty, method_ty, trait_ty,
trait_bounds); trait_bounds);
} }
@ -689,7 +690,7 @@ pub fn convert_struct(ccx: @mut CrateCtxt,
astconv::ty_of_bare_fn( astconv::ty_of_bare_fn(
ccx, type_rscope(rp), ccx, type_rscope(rp),
ast::impure_fn, ast::RustAbi, ast::impure_fn, ast::RustAbi,
ast_util::dtor_dec())); &ast_util::dtor_dec()));
write_ty_to_tcx(tcx, dtor.node.id, t_dtor); write_ty_to_tcx(tcx, dtor.node.id, t_dtor);
tcx.tcache.insert(local_def(dtor.node.id), tcx.tcache.insert(local_def(dtor.node.id),
ty_param_bounds_and_ty { ty_param_bounds_and_ty {
@ -748,7 +749,7 @@ pub fn ty_of_method(ccx: @mut CrateCtxt,
ident: m.ident, ident: m.ident,
tps: ty_param_bounds(ccx, m.tps), tps: ty_param_bounds(ccx, m.tps),
fty: astconv::ty_of_bare_fn(ccx, type_rscope(rp), m.purity, fty: astconv::ty_of_bare_fn(ccx, type_rscope(rp), m.purity,
ast::RustAbi, m.decl), ast::RustAbi, &m.decl),
self_ty: m.self_ty.node, self_ty: m.self_ty.node,
vis: m.vis, vis: m.vis,
def_id: local_def(m.id) def_id: local_def(m.id)
@ -756,14 +757,14 @@ pub fn ty_of_method(ccx: @mut CrateCtxt,
} }
pub fn ty_of_ty_method(self: @mut CrateCtxt, pub fn ty_of_ty_method(self: @mut CrateCtxt,
m: ast::ty_method, m: &ast::ty_method,
rp: Option<ty::region_variance>, rp: Option<ty::region_variance>,
id: ast::def_id) -> ty::method { id: ast::def_id) -> ty::method {
ty::method { ty::method {
ident: m.ident, ident: m.ident,
tps: ty_param_bounds(self, m.tps), tps: ty_param_bounds(self, m.tps),
fty: astconv::ty_of_bare_fn(self, type_rscope(rp), m.purity, fty: astconv::ty_of_bare_fn(self, type_rscope(rp), m.purity,
ast::RustAbi, m.decl), ast::RustAbi, &m.decl),
// assume public, because this is only invoked on trait methods // assume public, because this is only invoked on trait methods
self_ty: m.self_ty.node, self_ty: m.self_ty.node,
vis: ast::public, vis: ast::public,
@ -819,7 +820,7 @@ pub fn ty_of_item(ccx: @mut CrateCtxt, it: @ast::item)
ast::item_fn(decl, purity, tps, _) => { ast::item_fn(decl, purity, tps, _) => {
let bounds = ty_param_bounds(ccx, tps); let bounds = ty_param_bounds(ccx, tps);
let tofd = astconv::ty_of_bare_fn(ccx, empty_rscope, purity, let tofd = astconv::ty_of_bare_fn(ccx, empty_rscope, purity,
ast::RustAbi, decl); ast::RustAbi, &decl);
let tpt = ty_param_bounds_and_ty { let tpt = ty_param_bounds_and_ty {
bounds: bounds, bounds: bounds,
region_param: None, region_param: None,
@ -903,17 +904,17 @@ pub fn ty_of_item(ccx: @mut CrateCtxt, it: @ast::item)
pub fn ty_of_foreign_item(ccx: @mut CrateCtxt, it: @ast::foreign_item) pub fn ty_of_foreign_item(ccx: @mut CrateCtxt, it: @ast::foreign_item)
-> ty::ty_param_bounds_and_ty { -> ty::ty_param_bounds_and_ty {
match /*bad*/copy it.node { match /*bad*/copy it.node {
ast::foreign_item_fn(fn_decl, _, params) => { ast::foreign_item_fn(ref fn_decl, _, ref params) => {
return ty_of_foreign_fn_decl(ccx, fn_decl, params, local_def(it.id)); ty_of_foreign_fn_decl(ccx, fn_decl, *params, local_def(it.id))
} }
ast::foreign_item_const(t) => { ast::foreign_item_const(t) => {
let rb = in_binding_rscope(empty_rscope); let rb = in_binding_rscope(empty_rscope);
return ty::ty_param_bounds_and_ty { ty::ty_param_bounds_and_ty {
bounds: @~[], bounds: @~[],
region_param: None, region_param: None,
ty: ast_ty_to_ty(ccx, rb, t) ty: ast_ty_to_ty(ccx, rb, t)
}; }
} }
} }
} }
@ -958,7 +959,7 @@ pub fn compute_bounds(ccx: @mut CrateCtxt,
} }
pub fn ty_param_bounds(ccx: @mut CrateCtxt, pub fn ty_param_bounds(ccx: @mut CrateCtxt,
params: ~[ast::ty_param]) params: &[ast::ty_param])
-> @~[ty::param_bounds] { -> @~[ty::param_bounds] {
@do params.map |param| { @do params.map |param| {
match ccx.tcx.ty_param_bounds.find(&param.id) { match ccx.tcx.ty_param_bounds.find(&param.id) {
@ -973,8 +974,8 @@ pub fn ty_param_bounds(ccx: @mut CrateCtxt,
} }
pub fn ty_of_foreign_fn_decl(ccx: @mut CrateCtxt, pub fn ty_of_foreign_fn_decl(ccx: @mut CrateCtxt,
decl: ast::fn_decl, decl: &ast::fn_decl,
+ty_params: ~[ast::ty_param], ty_params: &[ast::ty_param],
def_id: ast::def_id) def_id: ast::def_id)
-> ty::ty_param_bounds_and_ty { -> ty::ty_param_bounds_and_ty {
let bounds = ty_param_bounds(ccx, ty_params); let bounds = ty_param_bounds(ccx, ty_params);

View file

@ -56,7 +56,7 @@ pub fn field_exprs(fields: ~[ast::field]) -> ~[@ast::expr] {
// Takes a predicate p, returns true iff p is true for any subexpressions // Takes a predicate p, returns true iff p is true for any subexpressions
// of b -- skipping any inner loops (loop, while, loop_body) // of b -- skipping any inner loops (loop, while, loop_body)
pub fn loop_query(b: ast::blk, p: fn@(ast::expr_) -> bool) -> bool { pub fn loop_query(b: &ast::blk, p: fn@(ast::expr_) -> bool) -> bool {
let rs = @mut false; let rs = @mut false;
let visit_expr: @fn(@ast::expr, let visit_expr: @fn(@ast::expr,
&&flag: @mut bool, &&flag: @mut bool,
@ -79,7 +79,7 @@ pub fn loop_query(b: ast::blk, p: fn@(ast::expr_) -> bool) -> bool {
// Takes a predicate p, returns true iff p is true for any subexpressions // Takes a predicate p, returns true iff p is true for any subexpressions
// of b -- skipping any inner loops (loop, while, loop_body) // of b -- skipping any inner loops (loop, while, loop_body)
pub fn block_query(b: ast::blk, p: fn@(@ast::expr) -> bool) -> bool { pub fn block_query(b: &ast::blk, p: fn@(@ast::expr) -> bool) -> bool {
let rs = @mut false; let rs = @mut false;
let visit_expr: @fn(@ast::expr, let visit_expr: @fn(@ast::expr,
&&flag: @mut bool, &&flag: @mut bool,

View file

@ -70,7 +70,7 @@ pub fn explain_region_and_span(cx: ctxt, region: ty::Region)
re_scope(node_id) => { re_scope(node_id) => {
match cx.items.find(&node_id) { match cx.items.find(&node_id) {
Some(ast_map::node_block(ref blk)) => { Some(ast_map::node_block(ref blk)) => {
explain_span(cx, "block", (*blk).span) explain_span(cx, "block", blk.span)
} }
Some(ast_map::node_expr(expr)) => { Some(ast_map::node_expr(expr)) => {
match expr.node { match expr.node {
@ -108,7 +108,7 @@ pub fn explain_region_and_span(cx: ctxt, region: ty::Region)
match cx.items.find(&id) { match cx.items.find(&id) {
Some(ast_map::node_block(ref blk)) => { Some(ast_map::node_block(ref blk)) => {
let (msg, opt_span) = explain_span(cx, "block", (*blk).span); let (msg, opt_span) = explain_span(cx, "block", blk.span);
(fmt!("%s %s", prefix, msg), opt_span) (fmt!("%s %s", prefix, msg), opt_span)
} }
Some(_) | None => { Some(_) | None => {
@ -159,7 +159,7 @@ pub fn re_scope_id_to_str(cx: ctxt, node_id: ast::node_id) -> ~str {
match cx.items.find(&node_id) { match cx.items.find(&node_id) {
Some(ast_map::node_block(ref blk)) => { Some(ast_map::node_block(ref blk)) => {
fmt!("<block at %s>", fmt!("<block at %s>",
cx.sess.codemap.span_to_str((*blk).span)) cx.sess.codemap.span_to_str(blk.span))
} }
Some(ast_map::node_expr(expr)) => { Some(ast_map::node_expr(expr)) => {
match expr.node { match expr.node {

View file

@ -76,7 +76,7 @@ struct ReadyCtx {
fns: ~[ListenerFn] fns: ~[ListenerFn]
} }
fn fold_mod(_ctx: @mut ReadyCtx, m: ast::_mod, fn fold_mod(_ctx: @mut ReadyCtx, m: &ast::_mod,
fold: fold::ast_fold) -> ast::_mod { fold: fold::ast_fold) -> ast::_mod {
fn strip_main(item: @ast::item) -> @ast::item { fn strip_main(item: @ast::item) -> @ast::item {
@ast::item { @ast::item {
@ -87,11 +87,11 @@ fn fold_mod(_ctx: @mut ReadyCtx, m: ast::_mod,
} }
} }
fold::noop_fold_mod(ast::_mod { fold::noop_fold_mod(&ast::_mod {
items: do vec::map(m.items) |item| { items: do m.items.map |item| {
strip_main(*item) strip_main(*item)
}, },
.. m .. copy *m
}, fold) }, fold)
} }
@ -199,7 +199,7 @@ pub fn ready_crate(sess: session::Session,
let fold = fold::make_fold(precursor); let fold = fold::make_fold(precursor);
@fold.fold_crate(*crate) @fold.fold_crate(crate)
} }
pub fn parse_vers(vers: ~str) -> result::Result<semver::Version, ~str> { pub fn parse_vers(vers: ~str) -> result::Result<semver::Version, ~str> {

View file

@ -186,8 +186,8 @@ pub fn map_decoded_item(diag: span_handler,
pub fn map_fn( pub fn map_fn(
fk: &visit::fn_kind, fk: &visit::fn_kind,
decl: fn_decl, decl: &fn_decl,
body: blk, body: &blk,
sp: codemap::span, sp: codemap::span,
id: node_id, id: node_id,
&&cx: @mut Ctx, &&cx: @mut Ctx,
@ -205,7 +205,7 @@ pub fn map_fn(
id: id, id: id,
attrs: /* FIXME (#2543) */ vec::from_slice(*attrs), attrs: /* FIXME (#2543) */ vec::from_slice(*attrs),
self_id: self_id, self_id: self_id,
body: /* FIXME (#2543) */ copy body, body: /* FIXME (#2543) */ copy *body,
}, },
span: sp, span: sp,
}; };
@ -222,8 +222,8 @@ pub fn map_fn(
visit::visit_fn(fk, decl, body, sp, id, cx, v); visit::visit_fn(fk, decl, body, sp, id, cx, v);
} }
pub fn map_block(b: blk, &&cx: @mut Ctx, v: visit::vt<@mut Ctx>) { pub fn map_block(b: &blk, &&cx: @mut Ctx, v: visit::vt<@mut Ctx>) {
cx.map.insert(b.node.id, node_block(/* FIXME (#2543) */ copy b)); cx.map.insert(b.node.id, node_block(/* FIXME (#2543) */ copy *b));
visit::visit_block(b, cx, v); visit::visit_block(b, cx, v);
} }
@ -244,7 +244,7 @@ pub fn map_local(loc: @local, &&cx: @mut Ctx, v: visit::vt<@mut Ctx>) {
visit::visit_local(loc, cx, v); visit::visit_local(loc, cx, v);
} }
pub fn map_arm(arm: arm, &&cx: @mut Ctx, v: visit::vt<@mut Ctx>) { pub fn map_arm(arm: &arm, &&cx: @mut Ctx, v: visit::vt<@mut Ctx>) {
number_pat(cx, arm.pats[0]); number_pat(cx, arm.pats[0]);
visit::visit_arm(arm, cx, v); visit::visit_arm(arm, cx, v);
} }
@ -308,7 +308,7 @@ pub fn map_item(i: @item, &&cx: @mut Ctx, v: visit::vt<@mut Ctx>) {
cx.map.insert(p.ref_id, node_item(i, item_path)); cx.map.insert(p.ref_id, node_item(i, item_path));
} }
for methods.each |tm| { for methods.each |tm| {
let id = ast_util::trait_method_to_ty_method(*tm).id; let id = ast_util::trait_method_to_ty_method(tm).id;
let d_id = ast_util::local_def(i.id); let d_id = ast_util::local_def(i.id);
cx.map.insert(id, node_trait_method(@*tm, d_id, item_path)); cx.map.insert(id, node_trait_method(@*tm, d_id, item_path));
} }
@ -387,14 +387,14 @@ pub fn node_id_to_str(map: map, id: node_id, itr: @ident_interner) -> ~str {
fmt!("method %s in %s (id=%?)", fmt!("method %s in %s (id=%?)",
*itr.get(m.ident), path_to_str(*path, itr), id) *itr.get(m.ident), path_to_str(*path, itr), id)
} }
Some(node_trait_method(tm, _, path)) => { Some(node_trait_method(ref tm, _, path)) => {
let m = ast_util::trait_method_to_ty_method(*tm); let m = ast_util::trait_method_to_ty_method(&**tm);
fmt!("method %s in %s (id=%?)", fmt!("method %s in %s (id=%?)",
*itr.get(m.ident), path_to_str(*path, itr), id) *itr.get(m.ident), path_to_str(*path, itr), id)
} }
Some(node_variant(ref variant, _, path)) => { Some(node_variant(ref variant, _, path)) => {
fmt!("variant %s in %s (id=%?)", fmt!("variant %s in %s (id=%?)",
*itr.get((*variant).node.name), path_to_str(*path, itr), id) *itr.get(variant.node.name), path_to_str(*path, itr), id)
} }
Some(node_expr(expr)) => { Some(node_expr(expr)) => {
fmt!("expr %s (id=%?)", pprust::expr_to_str(expr, itr), id) fmt!("expr %s (id=%?)", pprust::expr_to_str(expr, itr), id)

View file

@ -260,9 +260,9 @@ pub fn public_methods(ms: ~[@method]) -> ~[@method] {
// extract a ty_method from a trait_method. if the trait_method is // extract a ty_method from a trait_method. if the trait_method is
// a default, pull out the useful fields to make a ty_method // a default, pull out the useful fields to make a ty_method
pub fn trait_method_to_ty_method(method: trait_method) -> ty_method { pub fn trait_method_to_ty_method(method: &trait_method) -> ty_method {
match method { match *method {
required(ref m) => (*m), required(ref m) => copy *m,
provided(ref m) => { provided(ref m) => {
ty_method { ty_method {
ident: m.ident, ident: m.ident,
@ -278,7 +278,7 @@ pub fn trait_method_to_ty_method(method: trait_method) -> ty_method {
} }
} }
pub fn split_trait_methods(trait_methods: ~[trait_method]) pub fn split_trait_methods(trait_methods: &[trait_method])
-> (~[ty_method], ~[@method]) { -> (~[ty_method], ~[@method]) {
let mut reqd = ~[], provd = ~[]; let mut reqd = ~[], provd = ~[];
for trait_methods.each |trt_method| { for trait_methods.each |trt_method| {
@ -425,7 +425,7 @@ pub fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> {
vfn(l.node.id); vfn(l.node.id);
}, },
visit_block: fn@(b: blk) { visit_block: fn@(b: &blk) {
vfn(b.node.id); vfn(b.node.id);
}, },
@ -433,7 +433,7 @@ pub fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> {
vfn(ast_util::stmt_id(*s)); vfn(ast_util::stmt_id(*s));
}, },
visit_arm: fn@(_a: arm) { }, visit_arm: fn@(_a: &arm) { },
visit_pat: fn@(p: @pat) { visit_pat: fn@(p: @pat) {
vfn(p.id) vfn(p.id)
@ -463,8 +463,8 @@ pub fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> {
} }
}, },
visit_fn: fn@(fk: &visit::fn_kind, d: ast::fn_decl, visit_fn: fn@(fk: &visit::fn_kind, d: &ast::fn_decl,
_b: ast::blk, _sp: span, id: ast::node_id) { _b: &ast::blk, _sp: span, id: ast::node_id) {
vfn(id); vfn(id);
match *fk { match *fk {
@ -491,10 +491,10 @@ pub fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> {
} }
}, },
visit_ty_method: fn@(_ty_m: ty_method) { visit_ty_method: fn@(_ty_m: &ty_method) {
}, },
visit_trait_method: fn@(_ty_m: trait_method) { visit_trait_method: fn@(_ty_m: &trait_method) {
}, },
visit_struct_def: fn@(_sd: @struct_def, _id: ident, _tps: &[ty_param], visit_struct_def: fn@(_sd: @struct_def, _id: ident, _tps: &[ty_param],

View file

@ -183,28 +183,28 @@ pub fn contains(haystack: &[@ast::meta_item],
} }
fn eq(a: @ast::meta_item, b: @ast::meta_item) -> bool { fn eq(a: @ast::meta_item, b: @ast::meta_item) -> bool {
return match a.node { match a.node {
ast::meta_word(ref na) => match b.node { ast::meta_word(ref na) => match b.node {
ast::meta_word(ref nb) => (*na) == (*nb), ast::meta_word(ref nb) => (*na) == (*nb),
_ => false _ => false
}, },
ast::meta_name_value(ref na, va) => match b.node { ast::meta_name_value(ref na, va) => match b.node {
ast::meta_name_value(ref nb, vb) => { ast::meta_name_value(ref nb, vb) => {
(*na) == (*nb) && va.node == vb.node (*na) == (*nb) && va.node == vb.node
} }
_ => false _ => false
}, },
ast::meta_list(ref na, misa) => match b.node { ast::meta_list(ref na, ref misa) => match b.node {
ast::meta_list(ref nb, misb) => { ast::meta_list(ref nb, ref misb) => {
if na != nb { return false; } if na != nb { return false; }
for misa.each |&mi| { for misa.each |mi| {
if !contains(misb, mi) { return false; } if !misb.contains(mi) { return false; }
} }
true true
} }
_ => false _ => false
}
} }
}
} }
pub fn contains_name(metas: &[@ast::meta_item], name: &str) -> bool { pub fn contains_name(metas: &[@ast::meta_item], name: &str) -> bool {
@ -260,21 +260,23 @@ pub fn last_meta_item_list_by_name(items: ~[@ast::meta_item], name: &str)
/* Higher-level applications */ /* Higher-level applications */
pub fn sort_meta_items(+items: ~[@ast::meta_item]) -> ~[@ast::meta_item] { pub fn sort_meta_items(items: &[@ast::meta_item]) -> ~[@ast::meta_item] {
// This is sort of stupid here, converting to a vec of mutables and back // This is sort of stupid here, converting to a vec of mutables and back
let mut v = items; let mut v = vec::from_slice(items);
do std::sort::quick_sort(v) |ma, mb| { do std::sort::quick_sort(v) |ma, mb| {
get_meta_item_name(*ma) <= get_meta_item_name(*mb) get_meta_item_name(*ma) <= get_meta_item_name(*mb)
} }
// There doesn't seem to be a more optimal way to do this // There doesn't seem to be a more optimal way to do this
do v.map |&m| { do v.map |m| {
match m.node { match m.node {
ast::meta_list(n, mis) => @spanned { ast::meta_list(n, ref mis) => {
node: ast::meta_list(n, sort_meta_items(mis)), @spanned {
.. *m node: ast::meta_list(n, sort_meta_items(*mis)),
}, .. /*bad*/ copy **m
_ => m }
}
_ => /*bad*/ copy *m
} }
} }
} }

View file

@ -24,63 +24,71 @@ use core::vec;
use std::oldmap::HashMap; use std::oldmap::HashMap;
pub fn expand_expr(exts: SyntaxExtensions, cx: ext_ctxt, pub fn expand_expr(exts: SyntaxExtensions, cx: ext_ctxt,
e: expr_, s: span, fld: ast_fold, e: &expr_, s: span, fld: ast_fold,
orig: fn@(expr_, span, ast_fold) -> (expr_, span)) orig: fn@(&expr_, span, ast_fold) -> (expr_, span))
-> (expr_, span) { -> (expr_, span) {
return match e { match *e {
// expr_mac should really be expr_ext or something; it's the // expr_mac should really be expr_ext or something; it's the
// entry-point for all syntax extensions. // entry-point for all syntax extensions.
expr_mac(ref mac) => { expr_mac(ref mac) => {
match (*mac).node { match (*mac).node {
// Token-tree macros, these will be the only case when we're
// Token-tree macros, these will be the only case when we're // finished transitioning.
// finished transitioning. mac_invoc_tt(pth, ref tts) => {
mac_invoc_tt(pth, ref tts) => { assert (vec::len(pth.idents) == 1u);
assert (vec::len(pth.idents) == 1u); /* using idents and token::special_idents would make the
/* using idents and token::special_idents would make the the macro names be hygienic */
the macro names be hygienic */ let extname = cx.parse_sess().interner.get(pth.idents[0]);
let extname = cx.parse_sess().interner.get(pth.idents[0]); match exts.find(&extname) {
match exts.find(&extname) { None => {
None => { cx.span_fatal(
cx.span_fatal(pth.span, pth.span,
fmt!("macro undefined: '%s'", *extname)) fmt!("macro undefined: '%s'", *extname))
}
Some(NormalTT(SyntaxExpanderTT{expander: exp,
span: exp_sp})) => {
cx.bt_push(ExpandedFrom(CallInfo{
call_site: s,
callee: NameAndSpan {
name: *extname, span: exp_sp
} }
})); Some(NormalTT(SyntaxExpanderTT{
expander: exp,
span: exp_sp
})) => {
cx.bt_push(ExpandedFrom(CallInfo {
call_site: s,
callee: NameAndSpan {
name: *extname,
span: exp_sp,
},
}));
let expanded = match exp(cx, (*mac).span, (*tts)) { let expanded = match exp(cx, mac.span, *tts) {
MRExpr(e) => e, MRExpr(e) => e,
MRAny(expr_maker,_,_) => expr_maker(), MRAny(expr_maker,_,_) => expr_maker(),
_ => cx.span_fatal( _ => {
pth.span, fmt!("non-expr macro in expr pos: %s", cx.span_fatal(
*extname)) pth.span,
}; fmt!(
"non-expr macro in expr pos: %s",
*extname
)
)
}
};
//keep going, outside-in //keep going, outside-in
let fully_expanded = fld.fold_expr(expanded).node; let fully_expanded = fld.fold_expr(expanded).node;
cx.bt_pop(); cx.bt_pop();
(fully_expanded, s)
}
_ => {
cx.span_fatal(pth.span,
fmt!("'%s' is not a tt-style macro",
*extname))
}
(fully_expanded, s)
}
_ => {
cx.span_fatal(
pth.span,
fmt!("'%s' is not a tt-style macro", *extname)
)
}
}
} }
}
} }
} }
_ => orig(e, s, fld) _ => orig(e, s, fld)
}; }
} }
// This is a secondary mechanism for invoking syntax extensions on items: // This is a secondary mechanism for invoking syntax extensions on items:
@ -93,8 +101,8 @@ pub fn expand_expr(exts: SyntaxExtensions, cx: ext_ctxt,
// NB: there is some redundancy between this and expand_item, below, and // NB: there is some redundancy between this and expand_item, below, and
// they might benefit from some amount of semantic and language-UI merger. // they might benefit from some amount of semantic and language-UI merger.
pub fn expand_mod_items(exts: SyntaxExtensions, cx: ext_ctxt, pub fn expand_mod_items(exts: SyntaxExtensions, cx: ext_ctxt,
module_: ast::_mod, fld: ast_fold, module_: &ast::_mod, fld: ast_fold,
orig: fn@(ast::_mod, ast_fold) -> ast::_mod) orig: fn@(&ast::_mod, ast_fold) -> ast::_mod)
-> ast::_mod { -> ast::_mod {
// Fold the contents first: // Fold the contents first:
let module_ = orig(module_, fld); let module_ = orig(module_, fld);
@ -130,8 +138,8 @@ pub fn expand_mod_items(exts: SyntaxExtensions, cx: ext_ctxt,
// When we enter a module, record it, for the sake of `module!` // When we enter a module, record it, for the sake of `module!`
pub fn expand_item(exts: SyntaxExtensions, pub fn expand_item(exts: SyntaxExtensions,
cx: ext_ctxt, &&it: @ast::item, fld: ast_fold, cx: ext_ctxt, it: @ast::item, fld: ast_fold,
orig: fn@(&&v: @ast::item, ast_fold) -> Option<@ast::item>) orig: fn@(@ast::item, ast_fold) -> Option<@ast::item>)
-> Option<@ast::item> { -> Option<@ast::item> {
let is_mod = match it.node { let is_mod = match it.node {
ast::item_mod(_) | ast::item_foreign_mod(_) => true, ast::item_mod(_) | ast::item_foreign_mod(_) => true,
@ -223,13 +231,13 @@ pub fn expand_item_mac(exts: SyntaxExtensions,
} }
pub fn expand_stmt(exts: SyntaxExtensions, cx: ext_ctxt, pub fn expand_stmt(exts: SyntaxExtensions, cx: ext_ctxt,
&& s: stmt_, sp: span, fld: ast_fold, s: &stmt_, sp: span, fld: ast_fold,
orig: fn@(&&s: stmt_, span, ast_fold) -> (stmt_, span)) orig: fn@(s: &stmt_, span, ast_fold) -> (stmt_, span))
-> (stmt_, span) { -> (stmt_, span) {
let (mac, pth, tts, semi) = match s { let (mac, pth, tts, semi) = match *s {
stmt_mac(ref mac, semi) => { stmt_mac(ref mac, semi) => {
match (*mac).node { match mac.node {
mac_invoc_tt(pth, ref tts) => ((*mac), pth, (*tts), semi) mac_invoc_tt(pth, ref tts) => ((*mac), pth, (*tts), semi)
} }
} }
@ -361,8 +369,7 @@ pub fn expand_crate(parse_sess: @mut parse::ParseSess,
// as it registers all the core macros as expanders. // as it registers all the core macros as expanders.
f.fold_expr(cm); f.fold_expr(cm);
let res = @f.fold_crate(*c); @f.fold_crate(&*c)
return res;
} }
// Local Variables: // Local Variables:
// mode: rust // mode: rust

File diff suppressed because it is too large Load diff

View file

@ -38,8 +38,8 @@ use core::u64;
use core::vec; use core::vec;
// The @ps is stored here to prevent recursive type. // The @ps is stored here to prevent recursive type.
pub enum ann_node { pub enum ann_node/& {
node_block(@ps, ast::blk), node_block(@ps, &ast::blk),
node_item(@ps, @ast::item), node_item(@ps, @ast::item),
node_expr(@ps, @ast::expr), node_expr(@ps, @ast::expr),
node_pat(@ps, @ast::pat), node_pat(@ps, @ast::pat),
@ -183,7 +183,7 @@ pub fn fun_to_str(decl: ast::fn_decl, name: ast::ident,
} }
} }
pub fn block_to_str(blk: ast::blk, intr: @ident_interner) -> ~str { pub fn block_to_str(blk: &ast::blk, intr: @ident_interner) -> ~str {
do io::with_str_writer |wr| { do io::with_str_writer |wr| {
let s = rust_printer(wr, intr); let s = rust_printer(wr, intr);
// containing cbox, will be closed by print-block at } // containing cbox, will be closed by print-block at }
@ -510,7 +510,7 @@ pub fn print_item(s: @ps, &&item: @ast::item) {
item.vis item.vis
); );
word(s.s, ~" "); word(s.s, ~" ");
print_block_with_attrs(s, (*body), item.attrs); print_block_with_attrs(s, body, item.attrs);
} }
ast::item_mod(_mod) => { ast::item_mod(_mod) => {
head(s, visibility_qualified(item.vis, ~"mod")); head(s, visibility_qualified(item.vis, ~"mod"));
@ -607,8 +607,8 @@ pub fn print_item(s: @ps, &&item: @ast::item) {
} }
word(s.s, ~" "); word(s.s, ~" ");
bopen(s); bopen(s);
for (*methods).each |meth| { for methods.each |meth| {
print_trait_method(s, *meth); print_trait_method(s, meth);
} }
bclose(s, item.span); bclose(s, item.span);
} }
@ -741,7 +741,7 @@ pub fn print_struct(s: @ps,
maybe_print_comment(s, dtor.span.lo); maybe_print_comment(s, dtor.span.lo);
print_outer_attributes(s, dtor.node.attrs); print_outer_attributes(s, dtor.node.attrs);
head(s, ~"drop"); head(s, ~"drop");
print_block(s, dtor.node.body); print_block(s, &dtor.node.body);
} }
for struct_def.fields.each |field| { for struct_def.fields.each |field| {
@ -839,7 +839,7 @@ pub fn print_variant(s: @ps, v: ast::variant) {
} }
} }
pub fn print_ty_method(s: @ps, m: ast::ty_method) { pub fn print_ty_method(s: @ps, m: &ast::ty_method) {
hardbreak_if_not_bol(s); hardbreak_if_not_bol(s);
maybe_print_comment(s, m.span.lo); maybe_print_comment(s, m.span.lo);
print_outer_attributes(s, m.attrs); print_outer_attributes(s, m.attrs);
@ -849,10 +849,10 @@ pub fn print_ty_method(s: @ps, m: ast::ty_method) {
word(s.s, ~";"); word(s.s, ~";");
} }
pub fn print_trait_method(s: @ps, m: ast::trait_method) { pub fn print_trait_method(s: @ps, m: &ast::trait_method) {
match m { match *m {
required(ref ty_m) => print_ty_method(s, (*ty_m)), required(ref ty_m) => print_ty_method(s, ty_m),
provided(m) => print_method(s, m) provided(m) => print_method(s, m)
} }
} }
@ -864,7 +864,7 @@ pub fn print_method(s: @ps, meth: @ast::method) {
meth.ident, meth.tps, Some(meth.self_ty.node), meth.ident, meth.tps, Some(meth.self_ty.node),
meth.vis); meth.vis);
word(s.s, ~" "); word(s.s, ~" ");
print_block_with_attrs(s, meth.body, meth.attrs); print_block_with_attrs(s, &meth.body, meth.attrs);
} }
pub fn print_outer_attributes(s: @ps, attrs: ~[ast::attribute]) { pub fn print_outer_attributes(s: @ps, attrs: ~[ast::attribute]) {
@ -935,22 +935,22 @@ pub fn print_stmt(s: @ps, st: ast::stmt) {
maybe_print_trailing_comment(s, st.span, None); maybe_print_trailing_comment(s, st.span, None);
} }
pub fn print_block(s: @ps, blk: ast::blk) { pub fn print_block(s: @ps, blk: &ast::blk) {
print_possibly_embedded_block(s, blk, block_normal, indent_unit); print_possibly_embedded_block(s, blk, block_normal, indent_unit);
} }
pub fn print_block_unclosed(s: @ps, blk: ast::blk) { pub fn print_block_unclosed(s: @ps, blk: &ast::blk) {
print_possibly_embedded_block_(s, blk, block_normal, indent_unit, ~[], print_possibly_embedded_block_(s, blk, block_normal, indent_unit, ~[],
false); false);
} }
pub fn print_block_unclosed_indent(s: @ps, blk: ast::blk, indented: uint) { pub fn print_block_unclosed_indent(s: @ps, blk: &ast::blk, indented: uint) {
print_possibly_embedded_block_(s, blk, block_normal, indented, ~[], print_possibly_embedded_block_(s, blk, block_normal, indented, ~[],
false); false);
} }
pub fn print_block_with_attrs(s: @ps, pub fn print_block_with_attrs(s: @ps,
blk: ast::blk, blk: &ast::blk,
attrs: ~[ast::attribute]) { attrs: ~[ast::attribute]) {
print_possibly_embedded_block_(s, blk, block_normal, indent_unit, attrs, print_possibly_embedded_block_(s, blk, block_normal, indent_unit, attrs,
true); true);
@ -959,7 +959,7 @@ pub fn print_block_with_attrs(s: @ps,
pub enum embed_type { block_block_fn, block_normal, } pub enum embed_type { block_block_fn, block_normal, }
pub fn print_possibly_embedded_block(s: @ps, pub fn print_possibly_embedded_block(s: @ps,
blk: ast::blk, blk: &ast::blk,
embedded: embed_type, embedded: embed_type,
indented: uint) { indented: uint) {
print_possibly_embedded_block_( print_possibly_embedded_block_(
@ -967,7 +967,7 @@ pub fn print_possibly_embedded_block(s: @ps,
} }
pub fn print_possibly_embedded_block_(s: @ps, pub fn print_possibly_embedded_block_(s: @ps,
blk: ast::blk, blk: &ast::blk,
embedded: embed_type, embedded: embed_type,
indented: uint, indented: uint,
attrs: ~[ast::attribute], attrs: ~[ast::attribute],
@ -1002,7 +1002,7 @@ pub fn print_possibly_embedded_block_(s: @ps,
(s.ann.post)(ann_node); (s.ann.post)(ann_node);
} }
pub fn print_if(s: @ps, test: @ast::expr, blk: ast::blk, pub fn print_if(s: @ps, test: @ast::expr, blk: &ast::blk,
elseopt: Option<@ast::expr>, chk: bool) { elseopt: Option<@ast::expr>, chk: bool) {
head(s, ~"if"); head(s, ~"if");
if chk { word_nbsp(s, ~"check"); } if chk { word_nbsp(s, ~"check"); }
@ -1020,7 +1020,7 @@ pub fn print_if(s: @ps, test: @ast::expr, blk: ast::blk,
word(s.s, ~" else if "); word(s.s, ~" else if ");
print_expr(s, i); print_expr(s, i);
space(s.s); space(s.s);
print_block(s, (*t)); print_block(s, t);
do_else(s, e); do_else(s, e);
} }
// "final else" // "final else"
@ -1028,7 +1028,7 @@ pub fn print_if(s: @ps, test: @ast::expr, blk: ast::blk,
cbox(s, indent_unit - 1u); cbox(s, indent_unit - 1u);
ibox(s, 0u); ibox(s, 0u);
word(s.s, ~" else "); word(s.s, ~" else ");
print_block(s, (*b)); print_block(s, b);
} }
// BLEAH, constraints would be great here // BLEAH, constraints would be great here
_ => { _ => {
@ -1263,13 +1263,13 @@ pub fn print_expr(s: @ps, &&expr: @ast::expr) {
print_type_ex(s, ty, true); print_type_ex(s, ty, true);
} }
ast::expr_if(test, ref blk, elseopt) => { ast::expr_if(test, ref blk, elseopt) => {
print_if(s, test, (*blk), elseopt, false); print_if(s, test, blk, elseopt, false);
} }
ast::expr_while(test, ref blk) => { ast::expr_while(test, ref blk) => {
head(s, ~"while"); head(s, ~"while");
print_expr(s, test); print_expr(s, test);
space(s.s); space(s.s);
print_block(s, (*blk)); print_block(s, blk);
} }
ast::expr_loop(ref blk, opt_ident) => { ast::expr_loop(ref blk, opt_ident) => {
head(s, ~"loop"); head(s, ~"loop");
@ -1278,7 +1278,7 @@ pub fn print_expr(s: @ps, &&expr: @ast::expr) {
print_ident(s, *ident); print_ident(s, *ident);
word_space(s, ~":"); word_space(s, ~":");
}); });
print_block(s, (*blk)); print_block(s, blk);
} }
ast::expr_match(expr, ref arms) => { ast::expr_match(expr, ref arms) => {
cbox(s, match_indent_unit); cbox(s, match_indent_unit);
@ -1323,7 +1323,7 @@ pub fn print_expr(s: @ps, &&expr: @ast::expr) {
ast::expr_block(ref blk) => { ast::expr_block(ref blk) => {
// the block will close the pattern's ibox // the block will close the pattern's ibox
print_block_unclosed_indent( print_block_unclosed_indent(
s, (*blk), match_indent_unit); s, blk, match_indent_unit);
} }
_ => { _ => {
end(s); // close the ibox for the pattern end(s); // close the ibox for the pattern
@ -1340,7 +1340,7 @@ pub fn print_expr(s: @ps, &&expr: @ast::expr) {
} }
} else { } else {
// the block will close the pattern's ibox // the block will close the pattern's ibox
print_block_unclosed_indent(s, arm.body, match_indent_unit); print_block_unclosed_indent(s, &arm.body, match_indent_unit);
} }
} }
bclose_(s, expr.span, match_indent_unit); bclose_(s, expr.span, match_indent_unit);
@ -1354,7 +1354,7 @@ pub fn print_expr(s: @ps, &&expr: @ast::expr) {
Some(sigil), ast::inherited); Some(sigil), ast::inherited);
print_fn_args_and_ret(s, /* FIXME (#2543) */ copy *decl, None); print_fn_args_and_ret(s, /* FIXME (#2543) */ copy *decl, None);
space(s.s); space(s.s);
print_block(s, (*body)); print_block(s, body);
} }
ast::expr_fn_block(ref decl, ref body) => { ast::expr_fn_block(ref decl, ref body) => {
// in do/for blocks we don't want to show an empty // in do/for blocks we don't want to show an empty
@ -1365,16 +1365,16 @@ pub fn print_expr(s: @ps, &&expr: @ast::expr) {
print_fn_block_args(s, /* FIXME (#2543) */ copy *decl); print_fn_block_args(s, /* FIXME (#2543) */ copy *decl);
space(s.s); space(s.s);
// } // }
assert (*body).node.stmts.is_empty(); assert body.node.stmts.is_empty();
assert (*body).node.expr.is_some(); assert body.node.expr.is_some();
// we extract the block, so as not to create another set of boxes // we extract the block, so as not to create another set of boxes
match (*body).node.expr.get().node { match body.node.expr.get().node {
ast::expr_block(ref blk) => { ast::expr_block(ref blk) => {
print_block_unclosed(s, (*blk)); print_block_unclosed(s, blk);
} }
_ => { _ => {
// this is a bare expression // this is a bare expression
print_expr(s, (*body).node.expr.get()); print_expr(s, body.node.expr.get());
end(s); // need to close a box end(s); // need to close a box
} }
} }
@ -1394,7 +1394,7 @@ pub fn print_expr(s: @ps, &&expr: @ast::expr) {
cbox(s, indent_unit); cbox(s, indent_unit);
// head-box, will be closed by print-block after { // head-box, will be closed by print-block after {
ibox(s, 0u); ibox(s, 0u);
print_block(s, (*blk)); print_block(s, blk);
} }
ast::expr_copy(e) => { word_space(s, ~"copy"); print_expr(s, e); } ast::expr_copy(e) => { word_space(s, ~"copy"); print_expr(s, e); }
ast::expr_assign(lhs, rhs) => { ast::expr_assign(lhs, rhs) => {

View file

@ -67,18 +67,18 @@ pub struct Visitor<E> {
visit_foreign_item: fn@(@foreign_item, E, vt<E>), visit_foreign_item: fn@(@foreign_item, E, vt<E>),
visit_item: fn@(@item, E, vt<E>), visit_item: fn@(@item, E, vt<E>),
visit_local: fn@(@local, E, vt<E>), visit_local: fn@(@local, E, vt<E>),
visit_block: fn@(ast::blk, E, vt<E>), visit_block: fn@(&blk, E, vt<E>),
visit_stmt: fn@(@stmt, E, vt<E>), visit_stmt: fn@(@stmt, E, vt<E>),
visit_arm: fn@(arm, E, vt<E>), visit_arm: fn@(&arm, E, vt<E>),
visit_pat: fn@(@pat, E, vt<E>), visit_pat: fn@(@pat, E, vt<E>),
visit_decl: fn@(@decl, E, vt<E>), visit_decl: fn@(@decl, E, vt<E>),
visit_expr: fn@(@expr, E, vt<E>), visit_expr: fn@(@expr, E, vt<E>),
visit_expr_post: fn@(@expr, E, vt<E>), visit_expr_post: fn@(@expr, E, vt<E>),
visit_ty: fn@(@Ty, E, vt<E>), visit_ty: fn@(@Ty, E, vt<E>),
visit_ty_params: fn@(&[ty_param], E, vt<E>), visit_ty_params: fn@(&[ty_param], E, vt<E>),
visit_fn: fn@(&fn_kind, fn_decl, blk, span, node_id, E, vt<E>), visit_fn: fn@(&fn_kind, &fn_decl, &blk, span, node_id, E, vt<E>),
visit_ty_method: fn@(ty_method, E, vt<E>), visit_ty_method: fn@(&ty_method, E, vt<E>),
visit_trait_method: fn@(trait_method, E, vt<E>), visit_trait_method: fn@(&trait_method, E, vt<E>),
visit_struct_def: fn@(@struct_def, ident, &[ty_param], node_id, E, visit_struct_def: fn@(@struct_def, ident, &[ty_param], node_id, E,
vt<E>), vt<E>),
visit_struct_field: fn@(@struct_field, E, vt<E>), visit_struct_field: fn@(@struct_field, E, vt<E>),
@ -146,8 +146,8 @@ pub fn visit_item<E>(i: @item, e: E, v: vt<E>) {
*tps, *tps,
purity purity
), ),
/* FIXME (#2543) */ copy *decl, decl,
*body, body,
i.span, i.span,
i.id, i.id,
e, e,
@ -190,7 +190,7 @@ pub fn visit_item<E>(i: @item, e: E, v: vt<E>) {
(v.visit_ty_params)(*tps, e, v); (v.visit_ty_params)(*tps, e, v);
for traits.each |p| { visit_path(p.path, e, v); } for traits.each |p| { visit_path(p.path, e, v); }
for (*methods).each |m| { for (*methods).each |m| {
(v.visit_trait_method)(*m, e, v); (v.visit_trait_method)(m, e, v);
} }
} }
item_mac(ref m) => visit_mac((*m), e, v) item_mac(ref m) => visit_mac((*m), e, v)
@ -198,12 +198,12 @@ pub fn visit_item<E>(i: @item, e: E, v: vt<E>) {
} }
pub fn visit_enum_def<E>(enum_definition: ast::enum_def, pub fn visit_enum_def<E>(enum_definition: ast::enum_def,
tps: ~[ast::ty_param], tps: &[ast::ty_param],
e: E, e: E,
v: vt<E>) { v: vt<E>) {
for enum_definition.variants.each |vr| { for enum_definition.variants.each |vr| {
match vr.node.kind { match vr.node.kind {
tuple_variant_kind(variant_args) => { tuple_variant_kind(ref variant_args) => {
for variant_args.each |va| { (v.visit_ty)(va.ty, e, v); } for variant_args.each |va| { (v.visit_ty)(va.ty, e, v); }
} }
struct_variant_kind(struct_def) => { struct_variant_kind(struct_def) => {
@ -223,30 +223,31 @@ pub fn skip_ty<E>(_t: @Ty, _e: E, _v: vt<E>) {}
pub fn visit_ty<E>(t: @Ty, e: E, v: vt<E>) { pub fn visit_ty<E>(t: @Ty, e: E, v: vt<E>) {
match t.node { match t.node {
ty_box(mt) | ty_uniq(mt) | ty_box(mt) | ty_uniq(mt) |
ty_vec(mt) | ty_ptr(mt) | ty_rptr(_, mt) => { ty_vec(mt) | ty_ptr(mt) | ty_rptr(_, mt) => {
(v.visit_ty)(mt.ty, e, v); (v.visit_ty)(mt.ty, e, v);
} },
ty_rec(ref flds) => for (*flds).each |f| { ty_rec(ref flds) => {
(v.visit_ty)(f.node.mt.ty, e, v); for flds.each |f| {
}, (v.visit_ty)(f.node.mt.ty, e, v);
ty_tup(ts) => for ts.each |tt| { }
(v.visit_ty)(*tt, e, v); },
}, ty_tup(ref ts) => {
ty_closure(f) => { for ts.each |tt| {
for f.decl.inputs.each |a| { (v.visit_ty)(a.ty, e, v); } (v.visit_ty)(*tt, e, v);
(v.visit_ty)(f.decl.output, e, v); }
} },
ty_bare_fn(f) => { ty_closure(ref f) => {
for f.decl.inputs.each |a| { (v.visit_ty)(a.ty, e, v); } for f.decl.inputs.each |a| { (v.visit_ty)(a.ty, e, v); }
(v.visit_ty)(f.decl.output, e, v); (v.visit_ty)(f.decl.output, e, v);
} },
ty_path(p, _) => visit_path(p, e, v), ty_bare_fn(ref f) => {
ty_fixed_length_vec(mt, _) => (v.visit_ty)(mt.ty, e, v), for f.decl.inputs.each |a| { (v.visit_ty)(a.ty, e, v); }
ty_nil | (v.visit_ty)(f.decl.output, e, v);
ty_bot | },
ty_mac(_) | ty_path(p, _) => visit_path(p, e, v),
ty_infer => () ty_fixed_length_vec(ref mt, _) => (v.visit_ty)(mt.ty, e, v),
ty_nil | ty_bot | ty_mac(_) | ty_infer => ()
} }
} }
@ -256,49 +257,55 @@ pub fn visit_path<E>(p: @path, e: E, v: vt<E>) {
pub fn visit_pat<E>(p: @pat, e: E, v: vt<E>) { pub fn visit_pat<E>(p: @pat, e: E, v: vt<E>) {
match p.node { match p.node {
pat_enum(path, children) => { pat_enum(path, ref children) => {
visit_path(path, e, v); visit_path(path, e, v);
do option::iter(&children) |children| { do children.iter |children| {
for children.each |child| { (v.visit_pat)(*child, e, v); }} for children.each |child| { (v.visit_pat)(*child, e, v); }
} }
pat_rec(fields, _) => for fields.each |f| {
(v.visit_pat)(f.pat, e, v)
},
pat_struct(path, fields, _) => {
visit_path(path, e, v);
for fields.each |f| {
(v.visit_pat)(f.pat, e, v);
} }
} pat_rec(ref fields, _) => {
pat_tup(elts) => for elts.each |elt| { for fields.each |f| {
(v.visit_pat)(*elt, e, v) (v.visit_pat)(f.pat, e, v)
}, }
pat_box(inner) | pat_uniq(inner) | pat_region(inner) => },
(v.visit_pat)(inner, e, v), pat_struct(path, ref fields, _) => {
pat_ident(_, path, inner) => { visit_path(path, e, v);
visit_path(path, e, v); for fields.each |f| {
do option::iter(&inner) |subpat| { (v.visit_pat)(*subpat, e, v)}; (v.visit_pat)(f.pat, e, v);
} }
pat_lit(ex) => (v.visit_expr)(ex, e, v),
pat_range(e1, e2) => {
(v.visit_expr)(e1, e, v);
(v.visit_expr)(e2, e, v);
}
pat_wild => (),
pat_vec(elts, tail) => {
for elts.each |elt| {
(v.visit_pat)(*elt, e, v);
} }
do option::iter(&tail) |tail| { pat_tup(ref elts) => {
(v.visit_pat)(*tail, e, v); for elts.each |elt| {
(v.visit_pat)(*elt, e, v)
}
},
pat_box(inner) | pat_uniq(inner) | pat_region(inner) => {
(v.visit_pat)(inner, e, v)
},
pat_ident(_, path, ref inner) => {
visit_path(path, e, v);
do inner.iter |subpat| { (v.visit_pat)(*subpat, e, v) }
}
pat_lit(ex) => (v.visit_expr)(ex, e, v),
pat_range(e1, e2) => {
(v.visit_expr)(e1, e, v);
(v.visit_expr)(e2, e, v);
}
pat_wild => (),
pat_vec(ref elts, ref tail) => {
for elts.each |elt| {
(v.visit_pat)(*elt, e, v);
}
do tail.iter |tail| {
(v.visit_pat)(*tail, e, v);
}
} }
}
} }
} }
pub fn visit_foreign_item<E>(ni: @foreign_item, e: E, v: vt<E>) { pub fn visit_foreign_item<E>(ni: @foreign_item, e: E, v: vt<E>) {
match ni.node { match ni.node {
foreign_item_fn(fd, _, ref tps) => { foreign_item_fn(ref fd, _, ref tps) => {
(v.visit_ty_params)(*tps, e, v); (v.visit_ty_params)(*tps, e, v);
visit_fn_decl(fd, e, v); visit_fn_decl(fd, e, v);
} }
@ -323,7 +330,7 @@ pub fn visit_ty_params<E>(tps: &[ty_param], e: E, v: vt<E>) {
} }
} }
pub fn visit_fn_decl<E>(fd: fn_decl, e: E, v: vt<E>) { pub fn visit_fn_decl<E>(fd: &fn_decl, e: E, v: vt<E>) {
for fd.inputs.each |a| { for fd.inputs.each |a| {
(v.visit_pat)(a.pat, e, v); (v.visit_pat)(a.pat, e, v);
(v.visit_ty)(a.ty, e, v); (v.visit_ty)(a.ty, e, v);
@ -342,8 +349,8 @@ pub fn visit_method_helper<E>(m: &method, e: E, v: vt<E>) {
m.tps, m.tps,
m m
), ),
m.decl, &m.decl,
m.body, &m.body,
m.span, m.span,
m.id, m.id,
e, e,
@ -360,8 +367,8 @@ pub fn visit_struct_dtor_helper<E>(dtor: struct_dtor, tps: &[ty_param],
dtor.node.self_id, dtor.node.self_id,
parent_id parent_id
), ),
ast_util::dtor_dec(), &ast_util::dtor_dec(),
dtor.node.body, &dtor.node.body,
dtor.span, dtor.span,
dtor.node.id, dtor.node.id,
e, e,
@ -370,22 +377,22 @@ pub fn visit_struct_dtor_helper<E>(dtor: struct_dtor, tps: &[ty_param],
} }
pub fn visit_fn<E>(fk: &fn_kind, decl: fn_decl, body: blk, _sp: span, pub fn visit_fn<E>(fk: &fn_kind, decl: &fn_decl, body: &blk, _sp: span,
_id: node_id, e: E, v: vt<E>) { _id: node_id, e: E, v: vt<E>) {
visit_fn_decl(decl, e, v); visit_fn_decl(decl, e, v);
(v.visit_ty_params)(tps_of_fn(fk), e, v); (v.visit_ty_params)(tps_of_fn(fk), e, v);
(v.visit_block)(body, e, v); (v.visit_block)(body, e, v);
} }
pub fn visit_ty_method<E>(m: ty_method, e: E, v: vt<E>) { pub fn visit_ty_method<E>(m: &ty_method, e: E, v: vt<E>) {
for m.decl.inputs.each |a| { (v.visit_ty)(a.ty, e, v); } for m.decl.inputs.each |a| { (v.visit_ty)(a.ty, e, v); }
(v.visit_ty_params)(m.tps, e, v); (v.visit_ty_params)(m.tps, e, v);
(v.visit_ty)(m.decl.output, e, v); (v.visit_ty)(m.decl.output, e, v);
} }
pub fn visit_trait_method<E>(m: trait_method, e: E, v: vt<E>) { pub fn visit_trait_method<E>(m: &trait_method, e: E, v: vt<E>) {
match m { match *m {
required(ref ty_m) => (v.visit_ty_method)((*ty_m), e, v), required(ref ty_m) => (v.visit_ty_method)(ty_m, e, v),
provided(m) => visit_method_helper(m, e, v) provided(m) => visit_method_helper(m, e, v)
} }
} }
@ -408,7 +415,7 @@ pub fn visit_struct_method<E>(m: @method, e: E, v: vt<E>) {
visit_method_helper(m, e, v); visit_method_helper(m, e, v);
} }
pub fn visit_block<E>(b: ast::blk, e: E, v: vt<E>) { pub fn visit_block<E>(b: &blk, e: E, v: vt<E>) {
for b.node.view_items.each |vi| { for b.node.view_items.each |vi| {
(v.visit_view_item)(*vi, e, v); (v.visit_view_item)(*vi, e, v);
} }
@ -429,10 +436,12 @@ pub fn visit_stmt<E>(s: @stmt, e: E, v: vt<E>) {
pub fn visit_decl<E>(d: @decl, e: E, v: vt<E>) { pub fn visit_decl<E>(d: @decl, e: E, v: vt<E>) {
match d.node { match d.node {
decl_local(locs) => for locs.each |loc| { decl_local(ref locs) => {
(v.visit_local)(*loc, e, v) for locs.each |loc| {
}, (v.visit_local)(*loc, e, v)
decl_item(it) => (v.visit_item)(it, e, v) }
},
decl_item(it) => (v.visit_item)(it, e, v)
} }
} }
@ -440,7 +449,7 @@ pub fn visit_expr_opt<E>(eo: Option<@expr>, e: E, v: vt<E>) {
match eo { None => (), Some(ex) => (v.visit_expr)(ex, e, v) } match eo { None => (), Some(ex) => (v.visit_expr)(ex, e, v) }
} }
pub fn visit_exprs<E>(exprs: ~[@expr], e: E, v: vt<E>) { pub fn visit_exprs<E>(exprs: &[@expr], e: E, v: vt<E>) {
for exprs.each |ex| { (v.visit_expr)(*ex, e, v); } for exprs.each |ex| { (v.visit_expr)(*ex, e, v); }
} }
@ -450,112 +459,121 @@ pub fn visit_mac<E>(_m: mac, _e: E, _v: vt<E>) {
pub fn visit_expr<E>(ex: @expr, e: E, v: vt<E>) { pub fn visit_expr<E>(ex: @expr, e: E, v: vt<E>) {
match ex.node { match ex.node {
expr_vstore(x, _) => (v.visit_expr)(x, e, v), expr_vstore(x, _) => (v.visit_expr)(x, e, v),
expr_vec(es, _) => visit_exprs(es, e, v), expr_vec(ref es, _) => visit_exprs(*es, e, v),
expr_repeat(element, count, _) => { expr_repeat(element, count, _) => {
(v.visit_expr)(element, e, v); (v.visit_expr)(element, e, v);
(v.visit_expr)(count, e, v); (v.visit_expr)(count, e, v);
} }
expr_rec(ref flds, base) => { expr_rec(ref flds, base) => {
for (*flds).each |f| { (v.visit_expr)(f.node.expr, e, v); } for flds.each |f| { (v.visit_expr)(f.node.expr, e, v); }
visit_expr_opt(base, e, v); visit_expr_opt(base, e, v);
} }
expr_struct(p, ref flds, base) => { expr_struct(p, ref flds, base) => {
visit_path(p, e, v); visit_path(p, e, v);
for (*flds).each |f| { (v.visit_expr)(f.node.expr, e, v); } for flds.each |f| { (v.visit_expr)(f.node.expr, e, v); }
visit_expr_opt(base, e, v); visit_expr_opt(base, e, v);
} }
expr_tup(elts) => for elts.each |el| { (v.visit_expr)(*el, e, v); }, expr_tup(ref elts) => {
expr_call(callee, args, _) => { for elts.each |el| { (v.visit_expr)(*el, e, v) }
visit_exprs(args, e, v); }
(v.visit_expr)(callee, e, v); expr_call(callee, ref args, _) => {
} visit_exprs(*args, e, v);
expr_method_call(callee, _, tys, args, _) => { (v.visit_expr)(callee, e, v);
visit_exprs(args, e, v); }
for tys.each |tp| { (v.visit_ty)(*tp, e, v); } expr_method_call(callee, _, ref tys, ref args, _) => {
(v.visit_expr)(callee, e, v); visit_exprs(*args, e, v);
} for tys.each |tp| { (v.visit_ty)(*tp, e, v); }
expr_binary(_, a, b) => { (v.visit_expr)(callee, e, v);
(v.visit_expr)(a, e, v); (v.visit_expr)(b, e, v); }
} expr_binary(_, a, b) => {
expr_addr_of(_, x) | expr_unary(_, x) | (v.visit_expr)(a, e, v);
expr_loop_body(x) | expr_do_body(x) | (v.visit_expr)(b, e, v);
expr_assert(x) => (v.visit_expr)(x, e, v), }
expr_lit(_) => (), expr_addr_of(_, x) | expr_unary(_, x) |
expr_cast(x, t) => { (v.visit_expr)(x, e, v); (v.visit_ty)(t, e, v); } expr_loop_body(x) | expr_do_body(x) |
expr_if(x, ref b, eo) => { expr_assert(x) => (v.visit_expr)(x, e, v),
(v.visit_expr)(x, e, v); expr_lit(_) => (),
(v.visit_block)((*b), e, v); expr_cast(x, t) => {
visit_expr_opt(eo, e, v); (v.visit_expr)(x, e, v);
} (v.visit_ty)(t, e, v);
expr_while(x, ref b) => { }
(v.visit_expr)(x, e, v); expr_if(x, ref b, eo) => {
(v.visit_block)((*b), e, v); (v.visit_expr)(x, e, v);
} (v.visit_block)(b, e, v);
expr_loop(ref b, _) => (v.visit_block)((*b), e, v), visit_expr_opt(eo, e, v);
expr_match(x, ref arms) => { }
(v.visit_expr)(x, e, v); expr_while(x, ref b) => {
for (*arms).each |a| { (v.visit_arm)(*a, e, v); } (v.visit_expr)(x, e, v);
} (v.visit_block)(b, e, v);
expr_fn(proto, ref decl, ref body, _) => { }
(v.visit_fn)( expr_loop(ref b, _) => (v.visit_block)(b, e, v),
&fk_anon(proto), expr_match(x, ref arms) => {
/* FIXME (#2543) */ copy *decl, (v.visit_expr)(x, e, v);
*body, for arms.each |a| { (v.visit_arm)(a, e, v); }
ex.span, }
ex.id, expr_fn(proto, ref decl, ref body, _) => {
e, (v.visit_fn)(
v &fk_anon(proto),
); decl,
} body,
expr_fn_block(ref decl, ref body) => { ex.span,
(v.visit_fn)( ex.id,
&fk_fn_block, e,
/* FIXME (#2543) */ copy *decl, v
*body, );
ex.span, }
ex.id, expr_fn_block(ref decl, ref body) => {
e, (v.visit_fn)(
v &fk_fn_block,
); decl,
} body,
expr_block(ref b) => (v.visit_block)((*b), e, v), ex.span,
expr_assign(a, b) => { ex.id,
(v.visit_expr)(b, e, v); e,
(v.visit_expr)(a, e, v); v
} );
expr_copy(a) => (v.visit_expr)(a, e, v), }
expr_swap(a, b) => { (v.visit_expr)(a, e, v); (v.visit_expr)(b, e, v); } expr_block(ref b) => (v.visit_block)(b, e, v),
expr_assign_op(_, a, b) => { expr_assign(a, b) => {
(v.visit_expr)(b, e, v); (v.visit_expr)(b, e, v);
(v.visit_expr)(a, e, v); (v.visit_expr)(a, e, v);
} }
expr_field(x, _, tys) => { expr_copy(a) => (v.visit_expr)(a, e, v),
(v.visit_expr)(x, e, v); expr_swap(a, b) => {
for tys.each |tp| { (v.visit_ty)(*tp, e, v); } (v.visit_expr)(a, e, v);
} (v.visit_expr)(b, e, v);
expr_index(a, b) => { }
(v.visit_expr)(a, e, v); expr_assign_op(_, a, b) => {
(v.visit_expr)(b, e, v); (v.visit_expr)(b, e, v);
} (v.visit_expr)(a, e, v);
expr_path(p) => visit_path(p, e, v), }
expr_break(_) => (), expr_field(x, _, ref tys) => {
expr_again(_) => (), (v.visit_expr)(x, e, v);
expr_ret(eo) => visit_expr_opt(eo, e, v), for tys.each |tp| { (v.visit_ty)(*tp, e, v); }
expr_log(_, lv, x) => { }
(v.visit_expr)(lv, e, v); expr_index(a, b) => {
(v.visit_expr)(x, e, v); (v.visit_expr)(a, e, v);
} (v.visit_expr)(b, e, v);
expr_mac(ref mac) => visit_mac((*mac), e, v), }
expr_paren(x) => (v.visit_expr)(x, e, v), expr_path(p) => visit_path(p, e, v),
expr_break(_) => (),
expr_again(_) => (),
expr_ret(eo) => visit_expr_opt(eo, e, v),
expr_log(_, lv, x) => {
(v.visit_expr)(lv, e, v);
(v.visit_expr)(x, e, v);
}
expr_mac(ref mac) => visit_mac((*mac), e, v),
expr_paren(x) => (v.visit_expr)(x, e, v),
} }
(v.visit_expr_post)(ex, e, v); (v.visit_expr_post)(ex, e, v);
} }
pub fn visit_arm<E>(a: arm, e: E, v: vt<E>) { pub fn visit_arm<E>(a: &arm, e: E, v: vt<E>) {
for a.pats.each |p| { (v.visit_pat)(*p, e, v); } for a.pats.each |p| { (v.visit_pat)(*p, e, v); }
visit_expr_opt(a.guard, e, v); visit_expr_opt(a.guard, e, v);
(v.visit_block)(a.body, e, v); (v.visit_block)(&a.body, e, v);
} }
// Simpler, non-context passing interface. Always walks the whole tree, simply // Simpler, non-context passing interface. Always walks the whole tree, simply
@ -567,18 +585,18 @@ pub struct SimpleVisitor {
visit_foreign_item: fn@(@foreign_item), visit_foreign_item: fn@(@foreign_item),
visit_item: fn@(@item), visit_item: fn@(@item),
visit_local: fn@(@local), visit_local: fn@(@local),
visit_block: fn@(ast::blk), visit_block: fn@(&blk),
visit_stmt: fn@(@stmt), visit_stmt: fn@(@stmt),
visit_arm: fn@(arm), visit_arm: fn@(&arm),
visit_pat: fn@(@pat), visit_pat: fn@(@pat),
visit_decl: fn@(@decl), visit_decl: fn@(@decl),
visit_expr: fn@(@expr), visit_expr: fn@(@expr),
visit_expr_post: fn@(@expr), visit_expr_post: fn@(@expr),
visit_ty: fn@(@Ty), visit_ty: fn@(@Ty),
visit_ty_params: fn@(&[ty_param]), visit_ty_params: fn@(&[ty_param]),
visit_fn: fn@(&fn_kind, fn_decl, blk, span, node_id), visit_fn: fn@(&fn_kind, &fn_decl, &blk, span, node_id),
visit_ty_method: fn@(ty_method), visit_ty_method: fn@(&ty_method),
visit_trait_method: fn@(trait_method), visit_trait_method: fn@(&trait_method),
visit_struct_def: fn@(@struct_def, ident, &[ty_param], node_id), visit_struct_def: fn@(@struct_def, ident, &[ty_param], node_id),
visit_struct_field: fn@(@struct_field), visit_struct_field: fn@(@struct_field),
visit_struct_method: fn@(@method) visit_struct_method: fn@(@method)
@ -604,10 +622,10 @@ pub fn default_simple_visitor() -> @SimpleVisitor {
visit_expr_post: |_e| { }, visit_expr_post: |_e| { },
visit_ty: simple_ignore_ty, visit_ty: simple_ignore_ty,
visit_ty_params: fn@(_ps: &[ty_param]) { }, visit_ty_params: fn@(_ps: &[ty_param]) { },
visit_fn: fn@(_fk: &fn_kind, _d: fn_decl, _b: blk, _sp: span, visit_fn: fn@(_fk: &fn_kind, _d: &fn_decl, _b: &blk, _sp: span,
_id: node_id) { }, _id: node_id) { },
visit_ty_method: fn@(_m: ty_method) { }, visit_ty_method: fn@(_m: &ty_method) { },
visit_trait_method: fn@(_m: trait_method) { }, visit_trait_method: fn@(_m: &trait_method) { },
visit_struct_def: fn@(_sd: @struct_def, _nm: ident, visit_struct_def: fn@(_sd: @struct_def, _nm: ident,
_tps: &[ty_param], _id: node_id) { }, _tps: &[ty_param], _id: node_id) { },
visit_struct_field: fn@(_f: @struct_field) { }, visit_struct_field: fn@(_f: @struct_field) { },
@ -644,7 +662,7 @@ pub fn mk_simple_visitor(v: simple_visitor) -> vt<()> {
f(l); f(l);
visit_local(l, e, v); visit_local(l, e, v);
} }
fn v_block(f: fn@(ast::blk), bl: ast::blk, &&e: (), v: vt<()>) { fn v_block(f: fn@(&blk), bl: &blk, &&e: (), v: vt<()>) {
f(bl); f(bl);
visit_block(bl, e, v); visit_block(bl, e, v);
} }
@ -652,7 +670,7 @@ pub fn mk_simple_visitor(v: simple_visitor) -> vt<()> {
f(st); f(st);
visit_stmt(st, e, v); visit_stmt(st, e, v);
} }
fn v_arm(f: fn@(arm), a: arm, &&e: (), v: vt<()>) { fn v_arm(f: fn@(&arm), a: &arm, &&e: (), v: vt<()>) {
f(a); f(a);
visit_arm(a, e, v); visit_arm(a, e, v);
} }
@ -675,11 +693,11 @@ pub fn mk_simple_visitor(v: simple_visitor) -> vt<()> {
f(ty); f(ty);
visit_ty(ty, e, v); visit_ty(ty, e, v);
} }
fn v_ty_method(f: fn@(ty_method), ty: ty_method, &&e: (), v: vt<()>) { fn v_ty_method(f: fn@(&ty_method), ty: &ty_method, &&e: (), v: vt<()>) {
f(ty); f(ty);
visit_ty_method(ty, e, v); visit_ty_method(ty, e, v);
} }
fn v_trait_method(f: fn@(trait_method), m: trait_method, &&e: (), fn v_trait_method(f: fn@(&trait_method), m: &trait_method, &&e: (),
v: vt<()>) { v: vt<()>) {
f(m); f(m);
visit_trait_method(m, e, v); visit_trait_method(m, e, v);
@ -697,9 +715,16 @@ pub fn mk_simple_visitor(v: simple_visitor) -> vt<()> {
f(ps); f(ps);
visit_ty_params(ps, e, v); visit_ty_params(ps, e, v);
} }
fn v_fn(f: fn@(&fn_kind, fn_decl, blk, span, node_id), fn v_fn(
fk: &fn_kind, decl: fn_decl, body: blk, sp: span, f: fn@(&fn_kind, &fn_decl, &blk, span, node_id),
id: node_id, &&e: (), v: vt<()>) { fk: &fn_kind,
decl: &fn_decl,
body: &blk,
sp: span,
id: node_id,
&&e: (),
v: vt<()>
) {
f(fk, decl, body, sp, id); f(fk, decl, body, sp, id);
visit_fn(fk, decl, body, sp, id, e, v); visit_fn(fk, decl, body, sp, id, e, v);
} }