1
1
import syntax:: ast:: * ;
2
- import syntax:: walk ;
2
+ import syntax:: visit ;
3
3
import std:: ivec;
4
4
import std:: option:: * ;
5
5
import aux:: * ;
@@ -25,6 +25,7 @@ import tstate::ann::clear_in_poststate;
25
25
import tstate:: ann:: clear_in_prestate;
26
26
import tstate:: ann:: clear_in_poststate_;
27
27
import tritv:: * ;
28
+ import util:: common:: * ;
28
29
29
30
fn bit_num ( fcx : & fn_ctxt , c : & tsconstr ) -> uint {
30
31
let d = tsconstr_to_def_id ( c) ;
@@ -137,35 +138,38 @@ fn declare_var(fcx: &fn_ctxt, c: &tsconstr, pre: prestate) -> prestate {
137
138
ret rslt;
138
139
}
139
140
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) ;
142
145
}
143
146
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) ;
146
151
}
147
152
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 } ;
158
154
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
+ }
161
160
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) ;
169
173
}
170
174
171
175
fn gen_poststate ( fcx : & fn_ctxt , id : node_id , c : & tsconstr ) -> bool {
0 commit comments