8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
+ use middle:: def_id:: DefId ;
11
12
use middle:: ty:: Region ;
12
13
use mir:: repr:: * ;
13
14
use rustc_data_structures:: tuple_slice:: TupleSlice ;
15
+ use syntax:: codemap:: Span ;
14
16
15
17
pub trait Visitor < ' tcx > {
16
18
// Override these, and call `self.super_xxx` to revert back to the
@@ -56,6 +58,18 @@ pub trait Visitor<'tcx> {
56
58
self . super_constant ( constant) ;
57
59
}
58
60
61
+ fn visit_literal ( & mut self , literal : & Literal < ' tcx > ) {
62
+ self . super_literal ( literal) ;
63
+ }
64
+
65
+ fn visit_def_id ( & mut self , def_id : DefId ) {
66
+ self . super_def_id ( def_id) ;
67
+ }
68
+
69
+ fn visit_span ( & mut self , span : Span ) {
70
+ self . super_span ( span) ;
71
+ }
72
+
59
73
// The `super_xxx` methods comprise the default behavior and are
60
74
// not meant to be overidden.
61
75
@@ -74,6 +88,8 @@ pub trait Visitor<'tcx> {
74
88
}
75
89
76
90
fn super_statement ( & mut self , block : BasicBlock , statement : & Statement < ' tcx > ) {
91
+ self . visit_span ( statement. span ) ;
92
+
77
93
match statement. kind {
78
94
StatementKind :: Assign ( ref lvalue, ref rvalue) => {
79
95
self . visit_assign ( block, lvalue, rvalue) ;
@@ -218,7 +234,26 @@ pub trait Visitor<'tcx> {
218
234
fn super_branch ( & mut self , _source : BasicBlock , _target : BasicBlock ) {
219
235
}
220
236
221
- fn super_constant ( & mut self , _constant : & Constant < ' tcx > ) {
237
+ fn super_constant ( & mut self , constant : & Constant < ' tcx > ) {
238
+ self . visit_span ( constant. span ) ;
239
+ self . visit_literal ( & constant. literal ) ;
240
+ }
241
+
242
+ fn super_literal ( & mut self , literal : & Literal < ' tcx > ) {
243
+ match * literal {
244
+ Literal :: Item { def_id, .. } => {
245
+ self . visit_def_id ( def_id) ;
246
+ } ,
247
+ Literal :: Value { .. } => {
248
+ // Nothing to do
249
+ }
250
+ }
251
+ }
252
+
253
+ fn super_def_id ( & mut self , _def_id : DefId ) {
254
+ }
255
+
256
+ fn super_span ( & mut self , _span : Span ) {
222
257
}
223
258
}
224
259
0 commit comments