Skip to content

Commit 97576bd

Browse files
committed
Move some uses of walk to visit in trans.rs
1 parent e25e055 commit 97576bd

File tree

1 file changed

+46
-75
lines changed

1 file changed

+46
-75
lines changed

src/comp/middle/trans.rs

Lines changed: 46 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import back::abi;
3636
import back::upcall;
3737

3838
import middle::ty::pat_ty;
39+
import visit::vt;
3940

4041
import util::common;
4142
import util::common::istr;
@@ -7960,50 +7961,22 @@ fn decl_native_fn_and_pair(&@crate_ctxt ccx,
79607961
finish_fn(fcx, lltop);
79617962
}
79627963

7963-
type walk_ctxt = rec(mutable vec[str] path);
7964-
fn new_walk_ctxt() -> @walk_ctxt {
7965-
let vec[str] path = [];
7966-
ret @rec(mutable path=path);
7967-
}
7968-
7969-
fn enter_item(@walk_ctxt cx, &@ast::item item) {
7970-
alt (item.node) {
7971-
case (ast::item_fn(?name, _, _, _, _)) {
7972-
vec::push[str](cx.path, name);
7973-
}
7974-
case (ast::item_obj(?name, _, _, _, _)) {
7975-
vec::push[str](cx.path, name);
7976-
}
7977-
case (ast::item_mod(?name, _, _)) {
7978-
vec::push[str](cx.path, name);
7979-
}
7980-
case (_) { }
7981-
}
7982-
}
7983-
7984-
fn leave_item(@walk_ctxt cx, &@ast::item item) {
7964+
fn item_path(&@ast::item item) -> vec[str] {
79857965
alt (item.node) {
7986-
case (ast::item_fn(_, _, _, _, _)) {
7987-
vec::pop[str](cx.path);
7988-
}
7989-
case (ast::item_obj(_, _, _, _, _)) {
7990-
vec::pop[str](cx.path);
7991-
}
7992-
case (ast::item_mod(_, _, _)) {
7993-
vec::pop[str](cx.path);
7994-
}
7995-
case (_) { }
7966+
case (ast::item_fn(?name, _, _, _, _)) { ret [name]; }
7967+
case (ast::item_obj(?name, _, _, _, _)) { ret [name]; }
7968+
case (ast::item_mod(?name, _, _)) { ret [name]; }
7969+
case (_) { ret []; }
79967970
}
79977971
}
79987972

7999-
fn collect_native_item(&@crate_ctxt ccx, @walk_ctxt wcx,
8000-
&@ast::native_item i) {
7973+
fn collect_native_item(@crate_ctxt ccx, &@ast::native_item i,
7974+
&vec[str] pt, &vt[vec[str]] v) {
80017975
alt (i.node) {
80027976
case (ast::native_item_fn(?name, _, _, _, ?fid, ?ann)) {
80037977
ccx.native_items.insert(fid, i);
80047978
if (!ccx.obj_methods.contains_key(fid)) {
8005-
decl_native_fn_and_pair(ccx, i.span, wcx.path,
8006-
name, ann, fid);
7979+
decl_native_fn_and_pair(ccx, i.span, pt, name, ann, fid);
80077980
}
80087981
}
80097982
case (ast::native_item_ty(_, ?tid)) {
@@ -8012,9 +7985,9 @@ fn collect_native_item(&@crate_ctxt ccx, @walk_ctxt wcx,
80127985
}
80137986
}
80147987

8015-
fn collect_item_1(&@crate_ctxt ccx, @walk_ctxt wcx, &@ast::item i) {
8016-
enter_item(wcx, i);
8017-
7988+
fn collect_item_1(@crate_ctxt ccx, &@ast::item i,
7989+
&vec[str] pt, &vt[vec[str]] v) {
7990+
visit::visit_item(i, pt + item_path(i), v);
80187991
alt (i.node) {
80197992
case (ast::item_const(?name, _, _, ?cid, ?ann)) {
80207993
auto typ = node_ann_type(ccx, ann);
@@ -8041,19 +8014,20 @@ fn collect_item_1(&@crate_ctxt ccx, @walk_ctxt wcx, &@ast::item i) {
80418014
}
80428015
}
80438016

8044-
fn collect_item_2(&@crate_ctxt ccx, @walk_ctxt wcx, &@ast::item i) {
8045-
enter_item(wcx, i);
8046-
8017+
fn collect_item_2(&@crate_ctxt ccx, &@ast::item i,
8018+
&vec[str] pt, &vt[vec[str]] v) {
8019+
auto new_pt = pt + item_path(i);
8020+
visit::visit_item(i, new_pt, v);
80478021
alt (i.node) {
80488022
case (ast::item_fn(?name, ?f, ?tps, ?fid, ?ann)) {
80498023
ccx.items.insert(fid, i);
80508024
if (!ccx.obj_methods.contains_key(fid)) {
8051-
decl_fn_and_pair(ccx, i.span, wcx.path, "fn", tps, ann, fid);
8025+
decl_fn_and_pair(ccx, i.span, new_pt, "fn", tps, ann, fid);
80528026
}
80538027
}
80548028
case (ast::item_obj(?name, ?ob, ?tps, ?oid, ?ann)) {
80558029
ccx.items.insert(oid.ctor, i);
8056-
decl_fn_and_pair(ccx, i.span, wcx.path,
8030+
decl_fn_and_pair(ccx, i.span, new_pt,
80578031
"obj_ctor", tps, ann, oid.ctor);
80588032
for (@ast::method m in ob.methods) {
80598033
ccx.obj_methods.insert(m.node.id, ());
@@ -8064,29 +8038,28 @@ fn collect_item_2(&@crate_ctxt ccx, @walk_ctxt wcx, &@ast::item i) {
80648038
}
80658039

80668040
fn collect_items(&@crate_ctxt ccx, @ast::crate crate) {
8067-
auto wcx = new_walk_ctxt();
8068-
auto visitor0 = walk::default_visitor();
8069-
auto visitor1 = rec(visit_native_item_pre =
8070-
bind collect_native_item(ccx, wcx, _),
8071-
visit_item_pre = bind collect_item_1(ccx, wcx, _),
8072-
visit_item_post = bind leave_item(wcx, _)
8073-
with visitor0);
8074-
auto visitor2 = rec(visit_item_pre = bind collect_item_2(ccx, wcx, _),
8075-
visit_item_post = bind leave_item(wcx, _)
8076-
with visitor0);
8077-
walk::walk_crate(visitor1, *crate);
8078-
walk::walk_crate(visitor2, *crate);
8079-
}
8080-
8081-
fn collect_tag_ctor(&@crate_ctxt ccx, @walk_ctxt wcx, &@ast::item i) {
8082-
enter_item(wcx, i);
8041+
auto visitor0 = visit::default_visitor();
8042+
auto visitor1 = @rec(visit_native_item =
8043+
bind collect_native_item(ccx, _, _, _),
8044+
visit_item = bind collect_item_1(ccx, _, _, _)
8045+
with *visitor0);
8046+
auto visitor2 = @rec(visit_item = bind collect_item_2(ccx, _, _, _)
8047+
with *visitor0);
8048+
visit::visit_crate(*crate, [], visit::vtor(visitor1));
8049+
visit::visit_crate(*crate, [], visit::vtor(visitor2));
8050+
}
8051+
8052+
fn collect_tag_ctor(@crate_ctxt ccx, &@ast::item i,
8053+
&vec[str] pt, &vt[vec[str]] v) {
8054+
auto new_pt = pt + item_path(i);
8055+
visit::visit_item(i, new_pt, v);
80838056

80848057
alt (i.node) {
80858058
case (ast::item_tag(_, ?variants, ?tps, _, _)) {
80868059
for (ast::variant variant in variants) {
80878060
if (vec::len[ast::variant_arg](variant.node.args) != 0u) {
80888061
decl_fn_and_pair(ccx, i.span,
8089-
wcx.path + [variant.node.name],
8062+
new_pt + [variant.node.name],
80908063
"tag", tps, variant.node.ann,
80918064
variant.node.id);
80928065
}
@@ -8098,17 +8071,17 @@ fn collect_tag_ctor(&@crate_ctxt ccx, @walk_ctxt wcx, &@ast::item i) {
80988071
}
80998072

81008073
fn collect_tag_ctors(&@crate_ctxt ccx, @ast::crate crate) {
8101-
auto wcx = new_walk_ctxt();
8102-
auto visitor = rec(visit_item_pre = bind collect_tag_ctor(ccx, wcx, _),
8103-
visit_item_post = bind leave_item(wcx, _)
8104-
with walk::default_visitor());
8105-
walk::walk_crate(visitor, *crate);
8074+
auto visitor = @rec(visit_item = bind collect_tag_ctor(ccx, _, _, _)
8075+
with *visit::default_visitor());
8076+
visit::visit_crate(*crate, [], visit::vtor(visitor));
81068077
}
81078078

81088079
// The constant translation pass.
81098080

8110-
fn trans_constant(&@crate_ctxt ccx, @walk_ctxt wcx, &@ast::item it) {
8111-
enter_item(wcx, it);
8081+
fn trans_constant(@crate_ctxt ccx, &@ast::item it,
8082+
&vec[str] pt, &vt[vec[str]] v) {
8083+
auto new_pt = pt + item_path(it);
8084+
visit::visit_item(it, new_pt, v);
81128085

81138086
alt (it.node) {
81148087
case (ast::item_tag(?ident, ?variants, _, ?tag_id, _)) {
@@ -8119,7 +8092,7 @@ fn trans_constant(&@crate_ctxt ccx, @walk_ctxt wcx, &@ast::item it) {
81198092

81208093
auto discrim_val = C_int(i as int);
81218094

8122-
auto p = wcx.path + [ident, variant.node.name, "discrim"];
8095+
auto p = new_pt + [ident, variant.node.name, "discrim"];
81238096
auto s = mangle_exported_name(ccx, p, ty::mk_int(ccx.tcx));
81248097
auto discrim_gvar = llvm::LLVMAddGlobal(ccx.llmod, T_int(),
81258098
str::buf(s));
@@ -8139,7 +8112,7 @@ fn trans_constant(&@crate_ctxt ccx, @walk_ctxt wcx, &@ast::item it) {
81398112
// with consts.
81408113
auto v = C_int(1);
81418114
ccx.item_ids.insert(cid, v);
8142-
auto s = mangle_exported_name(ccx, wcx.path + [name],
8115+
auto s = mangle_exported_name(ccx, new_pt + [name],
81438116
node_ann_type(ccx, ann));
81448117
ccx.item_symbols.insert(cid, s);
81458118
}
@@ -8149,11 +8122,9 @@ fn trans_constant(&@crate_ctxt ccx, @walk_ctxt wcx, &@ast::item it) {
81498122
}
81508123

81518124
fn trans_constants(&@crate_ctxt ccx, @ast::crate crate) {
8152-
auto wcx = new_walk_ctxt();
8153-
auto visitor = rec(visit_item_pre = bind trans_constant(ccx, wcx, _),
8154-
visit_item_post = bind leave_item(wcx, _)
8155-
with walk::default_visitor());
8156-
walk::walk_crate(visitor, *crate);
8125+
auto visitor = @rec(visit_item = bind trans_constant(ccx, _, _, _)
8126+
with *visit::default_visitor());
8127+
visit::visit_crate(*crate, [], visit::vtor(visitor));
81578128
}
81588129

81598130

0 commit comments

Comments
 (0)