@@ -22,7 +22,8 @@ use syntax::ast;
22
22
use syntax:: ast_map;
23
23
use syntax:: attr;
24
24
use syntax:: codemap:: span;
25
- use visit = syntax:: oldvisit;
25
+ use syntax:: visit;
26
+ use syntax:: visit:: Visitor ;
26
27
use util:: ppaux:: Repr ;
27
28
28
29
#[ deriving( Clone ) ]
@@ -31,44 +32,56 @@ struct Context {
31
32
safe_stack : bool
32
33
}
33
34
35
+ struct StackCheckVisitor ;
36
+
37
+ impl Visitor < Context > for StackCheckVisitor {
38
+ fn visit_item ( & mut self , i : @ast:: item , e : Context ) {
39
+ stack_check_item ( * self , i, e) ;
40
+ }
41
+ fn visit_fn ( & mut self , fk : & visit:: fn_kind , fd : & ast:: fn_decl ,
42
+ b : & ast:: Block , s : span , n : ast:: NodeId , e : Context ) {
43
+ stack_check_fn ( * self , fk, fd, b, s, n, e) ;
44
+ }
45
+ fn visit_expr ( & mut self , ex : @ast:: expr , e : Context ) {
46
+ stack_check_expr ( * self , ex, e) ;
47
+ }
48
+ }
49
+
34
50
pub fn stack_check_crate ( tcx : ty:: ctxt ,
35
51
crate : & ast:: Crate ) {
36
52
let new_cx = Context {
37
53
tcx : tcx,
38
54
safe_stack : false
39
55
} ;
40
- let visitor = visit:: mk_vt ( @visit:: Visitor {
41
- visit_item : stack_check_item,
42
- visit_fn : stack_check_fn,
43
- visit_expr : stack_check_expr,
44
- ..* visit:: default_visitor ( )
45
- } ) ;
46
- visit:: visit_crate ( crate , ( new_cx, visitor) ) ;
56
+ let mut visitor = StackCheckVisitor ;
57
+ visit:: walk_crate ( & mut visitor, crate , new_cx) ;
47
58
}
48
59
49
- fn stack_check_item ( item : @ast:: item ,
50
- ( in_cx, v) : ( Context , visit:: vt < Context > ) ) {
60
+ fn stack_check_item ( v : StackCheckVisitor ,
61
+ item : @ast:: item ,
62
+ in_cx : Context ) {
63
+ let mut v = v;
51
64
match item. node {
52
65
ast:: item_fn( _, ast:: extern_fn, _, _, _) => {
53
66
// an extern fn is already being called from C code...
54
67
let new_cx = Context { safe_stack : true , ..in_cx} ;
55
- visit:: visit_item ( item , ( new_cx , v ) ) ;
68
+ visit:: walk_item ( & mut v , item , new_cx ) ;
56
69
}
57
70
ast:: item_fn( * ) => {
58
71
let safe_stack = fixed_stack_segment ( item. attrs ) ;
59
72
let new_cx = Context { safe_stack : safe_stack, ..in_cx} ;
60
- visit:: visit_item ( item , ( new_cx , v ) ) ;
73
+ visit:: walk_item ( & mut v , item , new_cx ) ;
61
74
}
62
75
ast:: item_impl( _, _, _, ref methods) => {
63
76
// visit_method() would make this nicer
64
77
for & method in methods. iter ( ) {
65
78
let safe_stack = fixed_stack_segment ( method. attrs ) ;
66
79
let new_cx = Context { safe_stack : safe_stack, ..in_cx} ;
67
- visit:: visit_method_helper ( method , ( new_cx , v ) ) ;
80
+ visit:: walk_method_helper ( & mut v , method , new_cx ) ;
68
81
}
69
82
}
70
83
_ => {
71
- visit:: visit_item ( item , ( in_cx , v ) ) ;
84
+ visit:: walk_item ( & mut v , item , in_cx ) ;
72
85
}
73
86
}
74
87
@@ -77,12 +90,13 @@ fn stack_check_item(item: @ast::item,
77
90
}
78
91
}
79
92
80
- fn stack_check_fn < ' a > ( fk : & visit:: fn_kind ,
93
+ fn stack_check_fn < ' a > ( v : StackCheckVisitor ,
94
+ fk : & visit:: fn_kind ,
81
95
decl : & ast:: fn_decl ,
82
96
body : & ast:: Block ,
83
97
sp : span ,
84
98
id : ast:: NodeId ,
85
- ( in_cx, v ) : ( Context , visit :: vt < Context > ) ) {
99
+ in_cx : Context ) {
86
100
let safe_stack = match * fk {
87
101
visit:: fk_method( * ) | visit:: fk_item_fn( * ) => {
88
102
in_cx. safe_stack // see stack_check_item above
@@ -102,11 +116,13 @@ fn stack_check_fn<'a>(fk: &visit::fn_kind,
102
116
} ;
103
117
let new_cx = Context { safe_stack : safe_stack, ..in_cx} ;
104
118
debug ! ( "stack_check_fn(safe_stack=%b, id=%?)" , safe_stack, id) ;
105
- visit:: visit_fn ( fk, decl, body, sp, id, ( new_cx, v) ) ;
119
+ let mut v = v;
120
+ visit:: walk_fn ( & mut v, fk, decl, body, sp, id, new_cx) ;
106
121
}
107
122
108
- fn stack_check_expr < ' a > ( expr : @ast:: expr ,
109
- ( cx, v) : ( Context , visit:: vt < Context > ) ) {
123
+ fn stack_check_expr < ' a > ( v : StackCheckVisitor ,
124
+ expr : @ast:: expr ,
125
+ cx : Context ) {
110
126
debug ! ( "stack_check_expr(safe_stack=%b, expr=%s)" ,
111
127
cx. safe_stack, expr. repr( cx. tcx) ) ;
112
128
if !cx. safe_stack {
@@ -126,7 +142,8 @@ fn stack_check_expr<'a>(expr: @ast::expr,
126
142
_ => { }
127
143
}
128
144
}
129
- visit:: visit_expr ( expr, ( cx, v) ) ;
145
+ let mut v = v;
146
+ visit:: walk_expr ( & mut v, expr, cx) ;
130
147
}
131
148
132
149
fn call_to_extern_fn ( cx : Context , callee : @ast:: expr ) {
0 commit comments