@@ -31,7 +31,9 @@ use syntax::ast;
31
31
use syntax:: ast_util:: id_range;
32
32
use syntax:: codemap:: span;
33
33
use syntax:: print:: pprust;
34
- use syntax:: oldvisit;
34
+ use syntax:: visit;
35
+ use syntax:: visit:: Visitor ;
36
+ use syntax:: ast:: { expr, fn_kind, fn_decl, Block , NodeId , stmt, pat, Local } ;
35
37
36
38
mod lifetime;
37
39
mod restrictions;
@@ -72,6 +74,30 @@ struct GatherLoanCtxt {
72
74
repeating_ids : ~[ ast:: NodeId ]
73
75
}
74
76
77
+ struct GatherLoanVisitor ;
78
+
79
+ impl visit:: Visitor < @mut GatherLoanCtxt > for GatherLoanVisitor {
80
+ fn visit_expr ( & mut self , ex: @expr, e : @mut GatherLoanCtxt ) {
81
+ gather_loans_in_expr ( self , ex, e) ;
82
+ }
83
+ fn visit_block ( & mut self , b : & Block , e : @mut GatherLoanCtxt ) {
84
+ gather_loans_in_block ( self , b, e) ;
85
+ }
86
+ fn visit_fn ( & mut self , fk : & fn_kind , fd : & fn_decl , b : & Block ,
87
+ s : span , n : NodeId , e : @mut GatherLoanCtxt ) {
88
+ gather_loans_in_fn ( self , fk, fd, b, s, n, e) ;
89
+ }
90
+ fn visit_stmt ( & mut self , s: @stmt, e : @mut GatherLoanCtxt ) {
91
+ add_stmt_to_map ( self , s, e) ;
92
+ }
93
+ fn visit_pat ( & mut self , p: @pat, e : @mut GatherLoanCtxt ) {
94
+ add_pat_to_id_range ( self , p, e) ;
95
+ }
96
+ fn visit_local ( & mut self , l : @Local , e : @mut GatherLoanCtxt ) {
97
+ gather_loans_in_local ( self , l, e) ;
98
+ }
99
+ }
100
+
75
101
pub fn gather_loans ( bccx : @BorrowckCtxt ,
76
102
decl : & ast:: fn_decl ,
77
103
body : & ast:: Block )
@@ -85,64 +111,57 @@ pub fn gather_loans(bccx: @BorrowckCtxt,
85
111
move_data : @mut MoveData :: new ( )
86
112
} ;
87
113
glcx. gather_fn_arg_patterns ( decl, body) ;
88
- let v = oldvisit:: mk_vt ( @oldvisit:: Visitor {
89
- visit_expr : gather_loans_in_expr,
90
- visit_block : gather_loans_in_block,
91
- visit_fn : gather_loans_in_fn,
92
- visit_stmt : add_stmt_to_map,
93
- visit_pat : add_pat_to_id_range,
94
- visit_local : gather_loans_in_local,
95
- .. * oldvisit:: default_visitor ( )
96
- } ) ;
97
- ( v. visit_block ) ( body, ( glcx, v) ) ;
114
+
115
+ let mut v = GatherLoanVisitor ;
116
+ v. visit_block ( body, glcx) ;
98
117
return ( glcx. id_range , glcx. all_loans , glcx. move_data ) ;
99
118
}
100
119
101
- fn add_pat_to_id_range ( p : @ast :: pat ,
102
- ( this , v ) : ( @ mut GatherLoanCtxt ,
103
- oldvisit :: vt < @mut GatherLoanCtxt > ) ) {
120
+ fn add_pat_to_id_range ( v : & mut GatherLoanVisitor ,
121
+ p : @ast :: pat ,
122
+ this : @mut GatherLoanCtxt ) {
104
123
// NB: This visitor function just adds the pat ids into the id
105
124
// range. We gather loans that occur in patterns using the
106
125
// `gather_pat()` method below. Eventually these two should be
107
126
// brought together.
108
127
this. id_range . add ( p. id ) ;
109
- oldvisit :: visit_pat ( p , ( this , v ) ) ;
128
+ visit :: walk_pat ( v , p , this ) ;
110
129
}
111
130
112
- fn gather_loans_in_fn ( fk : & oldvisit:: fn_kind ,
131
+ fn gather_loans_in_fn ( v : & mut GatherLoanVisitor ,
132
+ fk : & fn_kind ,
113
133
decl : & ast:: fn_decl ,
114
134
body : & ast:: Block ,
115
135
sp : span ,
116
136
id : ast:: NodeId ,
117
- ( this, v) : ( @mut GatherLoanCtxt ,
118
- oldvisit:: vt < @mut GatherLoanCtxt > ) ) {
137
+ this : @mut GatherLoanCtxt ) {
119
138
match fk {
120
139
// Do not visit items here, the outer loop in borrowck/mod
121
140
// will visit them for us in turn.
122
- & oldvisit :: fk_item_fn( * ) | & oldvisit :: fk_method( * ) => {
141
+ & visit :: fk_item_fn( * ) | & visit :: fk_method( * ) => {
123
142
return ;
124
143
}
125
144
126
145
// Visit closures as part of the containing item.
127
- & oldvisit :: fk_anon( * ) | & oldvisit :: fk_fn_block( * ) => {
146
+ & visit :: fk_anon( * ) | & visit :: fk_fn_block( * ) => {
128
147
this. push_repeating_id ( body. id ) ;
129
- oldvisit :: visit_fn ( fk, decl, body, sp, id, ( this, v ) ) ;
148
+ visit :: walk_fn ( v , fk, decl, body, sp, id, this) ;
130
149
this. pop_repeating_id ( body. id ) ;
131
150
this. gather_fn_arg_patterns ( decl, body) ;
132
151
}
133
152
}
134
153
}
135
154
136
- fn gather_loans_in_block ( blk : & ast :: Block ,
137
- ( this , vt ) : ( @ mut GatherLoanCtxt ,
138
- oldvisit :: vt < @mut GatherLoanCtxt > ) ) {
155
+ fn gather_loans_in_block ( v : & mut GatherLoanVisitor ,
156
+ blk : & ast :: Block ,
157
+ this : @mut GatherLoanCtxt ) {
139
158
this. id_range . add ( blk. id ) ;
140
- oldvisit :: visit_block ( blk , ( this , vt ) ) ;
159
+ visit :: walk_block ( v , blk , this ) ;
141
160
}
142
161
143
- fn gather_loans_in_local ( local : @ast :: Local ,
144
- ( this , vt ) : ( @ mut GatherLoanCtxt ,
145
- oldvisit :: vt < @mut GatherLoanCtxt > ) ) {
162
+ fn gather_loans_in_local( v : & mut GatherLoanVisitor ,
163
+ local : @ast :: Local ,
164
+ this : @mut GatherLoanCtxt ) {
146
165
match local. init {
147
166
None => {
148
167
// Variable declarations without initializers are considered "moves":
@@ -173,12 +192,13 @@ fn gather_loans_in_local(local: @ast::Local,
173
192
}
174
193
}
175
194
176
- oldvisit :: visit_local ( local , ( this , vt ) ) ;
195
+ visit :: walk_local ( v , local , this ) ;
177
196
}
178
197
179
- fn gather_loans_in_expr( ex: @ast:: expr,
180
- ( this, vt) : ( @mut GatherLoanCtxt ,
181
- oldvisit:: vt < @mut GatherLoanCtxt > ) ) {
198
+
199
+ fn gather_loans_in_expr( v: & mut GatherLoanVisitor ,
200
+ ex: @ast:: expr,
201
+ this: @mut GatherLoanCtxt ) {
182
202
let bccx = this. bccx;
183
203
let tcx = bccx. tcx;
184
204
@@ -218,7 +238,7 @@ fn gather_loans_in_expr(ex: @ast::expr,
218
238
// for the lifetime `scope_r` of the resulting ptr:
219
239
let scope_r = ty_region ( tcx, ex. span , ty:: expr_ty ( tcx, ex) ) ;
220
240
this. guarantee_valid ( ex. id , ex. span , base_cmt, mutbl, scope_r) ;
221
- oldvisit :: visit_expr ( ex , ( this , vt ) ) ;
241
+ visit :: walk_expr ( v , ex , this ) ;
222
242
}
223
243
224
244
ast:: expr_assign( l, _) | ast:: expr_assign_op( _, _, l, _) => {
@@ -235,7 +255,7 @@ fn gather_loans_in_expr(ex: @ast::expr,
235
255
// with moves etc, just ignore.
236
256
}
237
257
}
238
- oldvisit :: visit_expr ( ex , ( this , vt ) ) ;
258
+ visit :: walk_expr ( v , ex , this ) ;
239
259
}
240
260
241
261
ast:: expr_match( ex_v, ref arms) => {
@@ -245,7 +265,7 @@ fn gather_loans_in_expr(ex: @ast::expr,
245
265
this. gather_pat ( cmt, * pat, Some ( ( arm. body . id , ex. id ) ) ) ;
246
266
}
247
267
}
248
- oldvisit :: visit_expr ( ex , ( this , vt ) ) ;
268
+ visit :: walk_expr ( v , ex , this ) ;
249
269
}
250
270
251
271
ast:: expr_index( _, _, arg) |
@@ -259,36 +279,36 @@ fn gather_loans_in_expr(ex: @ast::expr,
259
279
let scope_r = ty:: re_scope ( ex. id ) ;
260
280
let arg_cmt = this. bccx . cat_expr ( arg) ;
261
281
this. guarantee_valid ( arg. id , arg. span , arg_cmt, m_imm, scope_r) ;
262
- oldvisit :: visit_expr ( ex , ( this , vt ) ) ;
282
+ visit :: walk_expr ( v , ex , this ) ;
263
283
}
264
284
265
285
// see explanation attached to the `root_ub` field:
266
286
ast:: expr_while( cond, ref body) => {
267
287
// during the condition, can only root for the condition
268
288
this. push_repeating_id ( cond. id ) ;
269
- ( vt . visit_expr ) ( cond, ( this, vt ) ) ;
289
+ v . visit_expr ( cond, this) ;
270
290
this. pop_repeating_id ( cond. id ) ;
271
291
272
292
// during body, can only root for the body
273
293
this. push_repeating_id ( body. id ) ;
274
- ( vt . visit_block ) ( body, ( this, vt ) ) ;
294
+ v . visit_block ( body, this) ;
275
295
this. pop_repeating_id ( body. id ) ;
276
296
}
277
297
278
298
// see explanation attached to the `root_ub` field:
279
299
ast:: expr_loop( ref body, _) => {
280
300
this. push_repeating_id ( body. id ) ;
281
- oldvisit :: visit_expr ( ex , ( this , vt ) ) ;
301
+ visit :: walk_expr ( v , ex , this ) ;
282
302
this. pop_repeating_id ( body. id ) ;
283
303
}
284
304
285
305
ast:: expr_fn_block( * ) => {
286
306
gather_moves:: gather_captures ( this. bccx , this. move_data , ex) ;
287
- oldvisit :: visit_expr ( ex , ( this , vt ) ) ;
307
+ visit :: walk_expr ( v , ex , this ) ;
288
308
}
289
309
290
310
_ => {
291
- oldvisit :: visit_expr ( ex , ( this , vt ) ) ;
311
+ visit :: walk_expr ( v , ex , this ) ;
292
312
}
293
313
}
294
314
}
@@ -770,14 +790,14 @@ impl GatherLoanCtxt {
770
790
771
791
// Setting up info that preserve needs.
772
792
// This is just the most convenient place to do it.
773
- fn add_stmt_to_map ( stmt : @ast :: stmt ,
774
- ( this , vt ) : ( @ mut GatherLoanCtxt ,
775
- oldvisit :: vt < @mut GatherLoanCtxt > ) ) {
793
+ fn add_stmt_to_map ( v : & mut GatherLoanVisitor ,
794
+ stmt : @ast :: stmt ,
795
+ this : @mut GatherLoanCtxt ) {
776
796
match stmt. node {
777
797
ast:: stmt_expr( _, id) | ast:: stmt_semi( _, id) => {
778
798
this. bccx . stmt_map . insert ( id) ;
779
799
}
780
800
_ => ( )
781
801
}
782
- oldvisit :: visit_stmt ( stmt , ( this , vt ) ) ;
802
+ visit :: walk_stmt ( v , stmt , this ) ;
783
803
}
0 commit comments