copy_map: std::map::new_int_hash(),
ref_map: std::map::new_int_hash(),
mutable silent: false};
- let v = @{visit_fn_body: bind visit_fn_body(cx, _, _, _, _, _, _, _),
+ let v = @{visit_fn: bind visit_fn(cx, _, _, _, _, _, _, _, _),
visit_expr: bind visit_expr(cx, _, _, _),
visit_block: bind visit_block(cx, _, _, _)
with *visit::default_visitor::<scope>()};
ret (cx.copy_map, cx.ref_map);
}
-fn visit_fn_body(cx: @ctx, decl: ast::fn_decl, body: ast::blk,
- sp: span, _name: ast::fn_ident,
- id: ast::node_id, sc: scope, v: vt<scope>) {
+fn visit_fn(cx: @ctx, decl: ast::fn_decl, _ts: [ast::ty_param],
+ body: ast::blk, sp: span, _name: ast::fn_ident,
+ id: ast::node_id, sc: scope, v: vt<scope>) {
visit::visit_fn_decl(decl, sc, v);
let fty = ty::node_id_to_type(cx.tcx, id);
let args = ty::ty_fn_args(cx.tcx, fty);
(@{visit_item: bind map_item(cx, _),
visit_native_item: bind map_native_item(cx, _),
visit_expr: bind map_expr(cx, _),
- visit_fn_body: bind map_fn_body(cx, _, _, _, _, _),
+ visit_fn: bind map_fn(cx, _, _, _, _, _, _),
visit_local: bind map_local(cx, _),
visit_arm: bind map_arm(cx, _)
with *visit::default_simple_visitor()});
ret cx.map;
}
-fn map_fn_body(cx: ctx, decl: fn_decl, _body: blk,
- _sp: codemap::span, _n: fn_ident, _id: node_id) {
+fn map_fn(cx: ctx, decl: fn_decl, _tps: [ty_param], _body: blk,
+ _sp: codemap::span, _n: fn_ident, _id: node_id) {
for a in decl.inputs {
cx.map.insert(a.id, node_arg(a, cx.local_id));
cx.local_id += 1u;
freevar_map {
let freevars = new_int_hash();
- let walk_fn_body = lambda (_decl: ast::fn_decl, blk: ast::blk,
- _sp: span, _nm: ast::fn_ident,
- nid: ast::node_id) {
+ let walk_fn = lambda (_decl: ast::fn_decl, _tps: [ast::ty_param],
+ blk: ast::blk, _sp: span, _nm: ast::fn_ident,
+ nid: ast::node_id) {
let vars = collect_freevars(def_map, blk);
freevars.insert(nid, vars);
};
let visitor =
- visit::mk_simple_visitor(@{visit_fn_body: walk_fn_body
+ visit::mk_simple_visitor(@{visit_fn: walk_fn
with *visit::default_simple_visitor()});
visit::visit_crate(*crate, (), visitor);
let visit = visit::mk_vt(@{
visit_expr: check_expr,
visit_stmt: check_stmt,
- visit_fn_body: check_fn_body
+ visit_fn: check_fn
with *visit::default_visitor()
});
visit::visit_crate(*crate, ctx, visit);
// Check that the free variables used in a shared/sendable closure conform
// to the copy/move kind bounds. Then recursively check the function body.
-fn check_fn_body(decl: fn_decl, body: blk, sp: span, i: fn_ident, id: node_id,
- cx: ctx, v: visit::vt<ctx>) {
+fn check_fn(decl: fn_decl, tps: [ty_param], body: blk, sp: span,
+ i: fn_ident, id: node_id, cx: ctx, v: visit::vt<ctx>) {
// n.b.: This could be the body of either a fn decl or a fn expr. In the
// former case, the prototype will be proto_bare and no check occurs. In
}
}
- visit::visit_fn_body(decl, body, sp, i, id, cx, v);
+ visit::visit_fn(decl, tps, body, sp, i, id, cx, v);
}
fn check_fn_cap_clause(cx: ctx,
fn find_last_uses(c: @crate, def_map: resolve::def_map,
ref_map: alias::ref_map, tcx: ty::ctxt) -> last_uses {
let v = visit::mk_vt(@{visit_expr: visit_expr,
- visit_fn_body: visit_fn_body
+ visit_fn: visit_fn
with *visit::default_visitor()});
let cx = {last_uses: std::map::new_int_hash(),
def_map: def_map,
}
}
-fn visit_fn_body(decl: fn_decl, body: blk,
- sp: span, nm: fn_ident, id: node_id,
- cx: ctx, v: visit::vt<ctx>) {
+fn visit_fn(decl: fn_decl, tps: [ty_param], body: blk,
+ sp: span, nm: fn_ident, id: node_id,
+ cx: ctx, v: visit::vt<ctx>) {
let fty = ty::node_id_to_type(cx.tcx, id);
let proto = ty::ty_fn_proto(cx.tcx, fty);
if proto == proto_block {
visit_block(func, cx, {||
- visit::visit_fn_body(decl, body, sp, nm, id, cx, v);
+ visit::visit_fn(decl, tps, body, sp, nm, id, cx, v);
});
} else {
let old = nil;
cx.blocks <-> old;
- visit::visit_fn_body(decl, body, sp, nm, id, cx, v);
+ visit::visit_fn(decl, tps, body, sp, nm, id, cx, v);
cx.blocks <-> old;
leave_fn(cx);
}
visit_expr: bind walk_expr(e, _, _, _),
visit_ty: bind walk_ty(e, _, _, _),
visit_constr: bind walk_constr(e, _, _, _, _, _),
- visit_fn_proto:
- bind visit_fn_proto_with_scope(e, _, _, _, _, _, _, _, _)
+ visit_fn: bind visit_fn_with_scope(e, _, _, _, _, _, _, _, _)
with *visit::default_visitor()};
visit::visit_crate(*c, cons(scope_crate, @nil), visit::mk_vt(v));
e.used_imports.track = false;
alt ifce { some(ty) { v.visit_ty(ty, sc, v); } _ {} }
v.visit_ty(sty, sc, v);
for m in methods {
- v.visit_fn_proto(m.decl, tps + m.tps, m.body, m.span,
- some(m.ident), m.id, sc, v);
+ v.visit_fn(m.decl, tps + m.tps, m.body, m.span,
+ some(m.ident), m.id, sc, v);
}
}
_ { visit::visit_item(i, sc, v); }
visit::visit_native_item(ni, cons(scope_native_item(ni), @sc), v);
}
-fn visit_fn_proto_with_scope(e: @env, decl: ast::fn_decl, tp: [ast::ty_param],
- body: ast::blk, sp: span, name: fn_ident,
- id: node_id, sc: scopes, v: vt<scopes>) {
+fn visit_fn_with_scope(e: @env, decl: ast::fn_decl, tp: [ast::ty_param],
+ body: ast::blk, sp: span, name: fn_ident,
+ id: node_id, sc: scopes, v: vt<scopes>) {
// is this a main fn declaration?
alt name {
some(nm) {
_ { scope_fn_expr(decl, id, tp) }
};
- visit::visit_fn_proto(decl, tp, body, sp, name, id, cons(scope, @sc), v);
+ visit::visit_fn(decl, tp, body, sp, name, id, cons(scope, @sc), v);
}
fn visit_block_with_scope(b: ast::blk, sc: scopes, v: vt<scopes>) {
init_vecs(ccx, node_id_vec, num_constraints);
}
-fn annotate_in_fn_body(ccx: crate_ctxt, _decl: fn_decl, body: blk,
- _sp: span, _n: fn_ident, id: node_id) {
+fn annotate_in_fn(ccx: crate_ctxt, _decl: fn_decl, _ts: [ty_param], body: blk,
+ _sp: span, _n: fn_ident, id: node_id) {
let f_info = get_fn_info(ccx, id);
visit_fn(ccx, num_constraints(f_info), body);
}
fn annotate_crate(ccx: crate_ctxt, crate: crate) {
let do_ann =
visit::mk_simple_visitor(
- @{visit_fn_body: bind annotate_in_fn_body(ccx, _, _, _, _, _)
+ @{visit_fn: bind annotate_in_fn(ccx, _, _, _, _, _, _)
with *visit::default_simple_visitor()});
visit::visit_crate(crate, (), do_ann);
}
}
// default function visitor
-fn do_nothing<T>(_decl: fn_decl, _body: blk,
+fn do_nothing<T>(_decl: fn_decl, _ts: [ty_param], _body: blk,
_sp: span, _i: fn_ident, _id: node_id,
_t: T, _v: visit::vt<T>) {
}
visit_stmt: relax_precond_stmt,
visit_item:
fn (_i: @item, _cx: relax_ctxt, _vt: visit::vt<relax_ctxt>) { },
- visit_fn_body: bind do_nothing(_, _, _, _, _, _, _)
+ visit_fn: bind do_nothing(_, _, _, _, _, _, _, _)
with *visitor};
let v1 = visit::mk_vt(visitor);
v1.visit_block(b, cx, v1);
let visitor = visit::mk_vt(
@{visit_stmt: check_states_stmt,
visit_expr: check_states_expr,
- visit_fn_body: bind do_nothing::<fn_ctxt>(_, _, _, _, _, _, _)
+ visit_fn: bind do_nothing::<fn_ctxt>(_, _, _, _, _, _, _, _)
with *visit::default_visitor::<fn_ctxt>()});
- visit::visit_fn_body(f_decl, f_body, sp, nm, id, fcx, visitor);
+ visit::visit_fn(f_decl, [], f_body, sp, nm, id, fcx, visitor);
/* Check that the return value is initialized */
let post = aux::block_poststate(fcx.ccx, f_body);
check_states_against_conditions(fcx, f_decl, f_body, sp, nm, id);
}
-fn fn_states(f_decl: ast::fn_decl, f_body: ast::blk,
+fn fn_states(f_decl: ast::fn_decl, tps: [ast::ty_param], f_body: ast::blk,
sp: span, i: ast::fn_ident, id: node_id,
ccx: crate_ctxt, v: visit::vt<crate_ctxt>) {
- visit::visit_fn_body(f_decl, f_body, sp, i, id, ccx, v);
+ visit::visit_fn(f_decl, tps, f_body, sp, i, id, ccx, v);
/* Look up the var-to-bit-num map for this function */
assert (ccx.fm.contains_key(id));
/* Compute the pre and postcondition for every subexpression */
let vtor = visit::default_visitor::<crate_ctxt>();
- vtor = @{visit_fn_body: fn_pre_post with *vtor};
+ vtor = @{visit_fn: fn_pre_post with *vtor};
visit::visit_crate(*crate, ccx, visit::mk_vt(vtor));
/* Check the pre- and postcondition against the pre- and poststate
for every expression */
let vtor = visit::default_visitor::<crate_ctxt>();
- vtor = @{visit_fn_body: fn_states with *vtor};
+ vtor = @{visit_fn: fn_states with *vtor};
visit::visit_crate(*crate, ccx, visit::mk_vt(vtor));
}
//
fn find_locals(tcx: ty::ctxt,
f_decl: fn_decl,
+ tps: [ty_param],
f_body: blk,
sp: span,
n: fn_ident,
visitor =
@{visit_local: collect_local,
visit_expr: collect_pred,
- visit_fn_body: bind do_nothing(_, _, _, _, _, _, _)
+ visit_fn: bind do_nothing(_, _, _, _, _, _, _, _)
with *visitor};
- visit::visit_fn_body(f_decl, f_body, sp,
- n, id, cx, visit::mk_vt(visitor));
+ visit::visit_fn(f_decl, tps, f_body, sp,
+ n, id, cx, visit::mk_vt(visitor));
ret cx;
}
to a bit number in the precondition/postcondition vectors */
fn mk_fn_info(ccx: crate_ctxt,
f_decl: fn_decl,
+ tps: [ty_param],
f_body: blk,
f_sp: span,
f_name: fn_ident,
let res_map = @new_def_hash::<constraint>();
let next: uint = 0u;
- let cx: ctxt = find_locals(ccx.tcx, f_decl, f_body, f_sp, f_name, id);
+ let cx: ctxt = find_locals(ccx.tcx, f_decl, tps, f_body, f_sp,
+ f_name, id);
/* now we have to add bit nums for both the constraints
and the variables... */
to bit number) */
fn mk_f_to_fn_info(ccx: crate_ctxt, c: @crate) {
let visitor =
- visit::mk_simple_visitor(@{visit_fn_body:
- bind mk_fn_info(ccx, _, _, _, _, _)
+ visit::mk_simple_visitor(@{visit_fn:
+ bind mk_fn_info(ccx, _, _, _, _, _, _)
with *visit::default_simple_visitor()});
visit::visit_crate(*c, (), visitor);
}
}
}
-fn fn_pre_post(decl: fn_decl, body: blk, sp: span,
+fn fn_pre_post(decl: fn_decl, tps: [ty_param], body: blk, sp: span,
i: fn_ident, id: node_id,
ccx: crate_ctxt, v: visit::vt<crate_ctxt>) {
- visit::visit_fn_body(decl, body, sp, i, id, ccx, v);
+ visit::visit_fn(decl, tps, body, sp, i, id, ccx, v);
assert (ccx.fm.contains_key(id));
let fcx =
{enclosing: ccx.fm.get(id),
};
// Don't descend into fns and items
- fn visit_fn_body<T>(_decl: ast::fn_decl, _body: ast::blk,
- _sp: span, _nm: ast::fn_ident, _id: ast::node_id,
- _t: T, _v: visit::vt<T>) {
+ fn visit_fn<T>(_decl: ast::fn_decl, _ts: [ast::ty_param], _body: ast::blk,
+ _sp: span, _nm: ast::fn_ident, _id: ast::node_id,
+ _t: T, _v: visit::vt<T>) {
}
fn visit_item<E>(_i: @ast::item, _e: E, _v: visit::vt<E>) { }
let visit =
@{visit_local: visit_local,
visit_pat: visit_pat,
- visit_fn_body: bind visit_fn_body(_, _, _, _, _, _, _),
+ visit_fn: bind visit_fn(_, _, _, _, _, _, _, _),
visit_item: bind visit_item(_, _, _)
with *visit::default_visitor()};
visit_expr: fn@(@expr, E, vt<E>),
visit_ty: fn@(@ty, E, vt<E>),
visit_constr: fn@(@path, span, node_id, E, vt<E>),
-
- // A function with a fully specified prototype:
- visit_fn_proto: fn@(fn_decl, [ty_param], blk, span, fn_ident, node_id,
- E, vt<E>),
-
- // Invoked by both visit_fn_proto above.
- // Intended to be a common flow point for all fn decls in AST.
- visit_fn_body: fn@(fn_decl, blk, span, fn_ident, node_id, E, vt<E>)};
+ visit_fn: fn@(fn_decl, [ty_param], blk, span, fn_ident, node_id,
+ E, vt<E>)};
fn default_visitor<E>() -> visitor<E> {
ret @{visit_mod: bind visit_mod::<E>(_, _, _, _),
visit_expr: bind visit_expr::<E>(_, _, _),
visit_ty: bind skip_ty::<E>(_, _, _),
visit_constr: bind visit_constr::<E>(_, _, _, _, _),
- visit_fn_proto: bind visit_fn_proto::<E>(_, _, _, _, _, _, _, _),
- visit_fn_body: bind visit_fn_body::<E>(_, _, _, _, _, _, _)};
+ visit_fn: bind visit_fn::<E>(_, _, _, _, _, _, _, _)};
}
fn visit_crate<E>(c: crate, e: E, v: vt<E>) {
alt i.node {
item_const(t, ex) { v.visit_ty(t, e, v); v.visit_expr(ex, e, v); }
item_fn(decl, tp, body) {
- v.visit_fn_proto(decl, tp, body, i.span, some(i.ident), i.id, e, v);
+ v.visit_fn(decl, tp, body, i.span, some(i.ident), i.id, e, v);
}
item_mod(m) { v.visit_mod(m, i.span, e, v); }
item_native_mod(nm) {
}
item_ty(t, _) { v.visit_ty(t, e, v); }
item_res(decl, tps, body, dtor_id, _) {
- v.visit_fn_proto(decl, tps, body, i.span, some(i.ident), dtor_id,
- e, v);
+ v.visit_fn(decl, tps, body, i.span, some(i.ident), dtor_id,
+ e, v);
}
item_tag(variants, _) {
for vr: variant in variants {
item_obj(ob, _, _) {
for f: obj_field in ob.fields { v.visit_ty(f.ty, e, v); }
for m: @method in ob.methods {
- v.visit_fn_proto(m.decl, m.tps, m.body, m.span,
- some(m.ident), m.id, e, v);
+ v.visit_fn(m.decl, m.tps, m.body, m.span,
+ some(m.ident), m.id, e, v);
}
}
item_impl(_, ifce, ty, methods) {
alt ifce { some(ty) { v.visit_ty(ty, e, v); } _ {} }
v.visit_ty(ty, e, v);
for m in methods {
- v.visit_fn_proto(m.decl, m.tps, m.body, m.span,
- some(m.ident), m.id, e, v);
+ v.visit_fn(m.decl, m.tps, m.body, m.span,
+ some(m.ident), m.id, e, v);
}
}
item_iface(_, methods) {
v.visit_ty(fd.output, e, v);
}
-fn visit_fn_proto<E>(decl: fn_decl, _tp: [ty_param], body: blk, sp: span,
- i: fn_ident, id: node_id, e: E, v: vt<E>) {
- v.visit_fn_body(decl, body, sp, i, id, e, v);
-}
-
-fn visit_fn_body<E>(decl: fn_decl, body: blk, _sp: span,
- _name: fn_ident, _id: node_id,
- e: E, v: vt<E>) {
+fn visit_fn<E>(decl: fn_decl, _tp: [ty_param], body: blk, _sp: span,
+ _i: fn_ident, _id: node_id, e: E, v: vt<E>) {
visit_fn_decl(decl, e, v);
v.visit_block(body, e, v);
}
for a: arm in arms { v.visit_arm(a, e, v); }
}
expr_fn(decl, body, _) {
- v.visit_fn_proto(decl, [], body, ex.span, none, ex.id, e, v);
+ v.visit_fn(decl, [], body, ex.span, none, ex.id, e, v);
}
expr_fn_block(decl, body) {
- v.visit_fn_proto(decl, [], body, ex.span, none, ex.id, e, v);
+ v.visit_fn(decl, [], body, ex.span, none, ex.id, e, v);
}
expr_block(b) { v.visit_block(b, e, v); }
expr_assign(a, b) { v.visit_expr(b, e, v); v.visit_expr(a, e, v); }
some(ex) { v.visit_expr(ex, e, v); }
}
for m: @method in anon_obj.methods {
- v.visit_fn_proto(m.decl, m.tps, m.body, m.span,
- some(m.ident), m.id, e, v);
+ v.visit_fn(m.decl, m.tps, m.body, m.span,
+ some(m.ident), m.id, e, v);
}
}
expr_mac(mac) { visit_mac(mac, e, v); }
visit_expr: fn@(@expr),
visit_ty: fn@(@ty),
visit_constr: fn@(@path, span, node_id),
- visit_fn_proto: fn@(fn_decl, [ty_param], blk, span, fn_ident, node_id),
- visit_fn_body: fn@(fn_decl, blk, span, fn_ident, node_id)};
+ visit_fn: fn@(fn_decl, [ty_param], blk, span, fn_ident, node_id)};
fn simple_ignore_ty(_t: @ty) {}
visit_expr: fn(_e: @expr) { },
visit_ty: simple_ignore_ty,
visit_constr: fn(_p: @path, _sp: span, _id: node_id) { },
- visit_fn_proto:
- fn(_d: fn_decl, _tps: [ty_param], _b: blk, _sp: span,
- _ident: fn_ident, _id: node_id) { },
- visit_fn_body:
- fn(_f: fn_decl, _b: blk, _sp: span,
- _nm: fn_ident, _node_id: node_id) { }
+ visit_fn: fn(_d: fn_decl, _tps: [ty_param], _b: blk, _sp: span,
+ _ident: fn_ident, _id: node_id) { }
};
}
decl: fn_decl, tps: [ty_param], body: blk, sp: span,
ident: fn_ident, id: node_id, &&e: (), v: vt<()>) {
f(decl, tps, body, sp, ident, id);
- visit_fn_proto(decl, tps, body, sp, ident, id, e, v);
- }
- fn v_fn_body(f: fn@(fn_decl, blk, span, fn_ident, node_id),
- fn_decl: fn_decl, blk: blk,
- sp: span, name: fn_ident, node_id: node_id,
- &&e: (), v: vt<()>) {
- f(fn_decl, blk, sp, name, node_id);
- visit_fn_body(fn_decl, blk, sp, name, node_id, e, v);
+ visit_fn(decl, tps, body, sp, ident, id, e, v);
}
let visit_ty = if v.visit_ty == simple_ignore_ty {
bind skip_ty(_, _, _)
visit_expr: bind v_expr(v.visit_expr, _, _, _),
visit_ty: visit_ty,
visit_constr: bind v_constr(v.visit_constr, _, _, _, _, _),
- visit_fn_proto:
- bind v_fn(v.visit_fn_proto, _, _, _, _, _, _, _, _),
- visit_fn_body:
- bind v_fn_body(v.visit_fn_body, _, _, _, _, _, _, _),
+ visit_fn: bind v_fn(v.visit_fn, _, _, _, _, _, _, _, _)
});
}