Skip to content

Commit 28f7c6a

Browse files
committed
Change bitvectors::relax_precond_block to use visit instead of walk
1 parent d552a0b commit 28f7c6a

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

src/comp/middle/tstate/bitvectors.rs

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import syntax::ast::*;
2-
import syntax::walk;
2+
import syntax::visit;
33
import std::ivec;
44
import std::option::*;
55
import aux::*;
@@ -25,6 +25,7 @@ import tstate::ann::clear_in_poststate;
2525
import tstate::ann::clear_in_prestate;
2626
import tstate::ann::clear_in_poststate_;
2727
import tritv::*;
28+
import util::common::*;
2829

2930
fn bit_num(fcx: &fn_ctxt, c: &tsconstr) -> uint {
3031
let d = tsconstr_to_def_id(c);
@@ -137,35 +138,38 @@ fn declare_var(fcx: &fn_ctxt, c: &tsconstr, pre: prestate) -> prestate {
137138
ret rslt;
138139
}
139140

140-
fn relax_precond_block_non_recursive(fcx: &fn_ctxt, i: node_id, b: &blk) {
141-
relax_precond(i as uint, block_precond(fcx.ccx, b));
141+
fn relax_precond_expr(e: &@expr, cx: &relax_ctxt,
142+
vt: &visit::vt[relax_ctxt]) {
143+
relax_precond(cx.i as uint, expr_precond(cx.fcx.ccx, e));
144+
visit::visit_expr(e, cx, vt);
142145
}
143146

144-
fn relax_precond_expr(fcx: &fn_ctxt, i: node_id, e: &@expr) {
145-
relax_precond(i as uint, expr_precond(fcx.ccx, e));
147+
fn relax_precond_stmt(s: &@stmt, cx: &relax_ctxt,
148+
vt: &visit::vt[relax_ctxt]) {
149+
relax_precond(cx.i as uint, stmt_precond(cx.fcx.ccx, *s));
150+
visit::visit_stmt(s, cx, vt);
146151
}
147152

148-
fn relax_precond_stmt(fcx: &fn_ctxt, i: node_id, s: &@stmt) {
149-
relax_precond(i as uint, stmt_precond(fcx.ccx, *s));
150-
}
151-
152-
fn relax_precond_block(fcx: &fn_ctxt, i: node_id, b: &blk) {
153-
relax_precond_block_non_recursive(fcx, i, b);
154-
// FIXME: should use visit instead
155-
// could at least generalize this pattern
156-
// (also seen in ck::check_states_against_conditions)
157-
let keepgoing: @mutable bool = @mutable true;
153+
type relax_ctxt = {fcx:fn_ctxt, i:node_id};
158154

159-
fn quit(keepgoing: @mutable bool, i: &@item) { *keepgoing = false; }
160-
fn kg(keepgoing: @mutable bool) -> bool { ret *keepgoing; }
155+
fn relax_precond_block_inner(b: &blk, cx: &relax_ctxt,
156+
vt: &visit::vt[relax_ctxt]) {
157+
relax_precond(cx.i as uint, block_precond(cx.fcx.ccx, b));
158+
visit::visit_block(b, cx, vt);
159+
}
161160

162-
let v =
163-
{visit_block_pre: bind relax_precond_block_non_recursive(fcx, i, _),
164-
visit_expr_pre: bind relax_precond_expr(fcx, i, _),
165-
visit_stmt_pre: bind relax_precond_stmt(fcx, i, _),
166-
visit_item_pre: bind quit(keepgoing, _),
167-
keep_going: bind kg(keepgoing) with walk::default_visitor()};
168-
walk::walk_block(v, b);
161+
fn relax_precond_block(fcx: &fn_ctxt, i: node_id, b:&blk) {
162+
let cx = {fcx: fcx, i: i};
163+
let visitor = visit::default_visitor[relax_ctxt]();
164+
visitor =
165+
@{visit_block: relax_precond_block_inner,
166+
visit_expr: relax_precond_expr,
167+
visit_stmt: relax_precond_stmt,
168+
visit_item: (fn (i: &@item, cx: &relax_ctxt,
169+
vt: &visit::vt[relax_ctxt]) {})
170+
with *visitor};
171+
let v1 = visit::mk_vt(visitor);
172+
v1.visit_block(b, cx, v1);
169173
}
170174

171175
fn gen_poststate(fcx: &fn_ctxt, id: node_id, c: &tsconstr) -> bool {

0 commit comments

Comments
 (0)