13
13
//! The `Dump` trait can be used together with `DumpVisitor` in order to
14
14
//! retrieve the data from a crate.
15
15
16
+ use rustc:: hir;
16
17
use rustc:: hir:: def_id:: DefId ;
17
- use syntax:: ast:: { CrateNum , NodeId } ;
18
+ use syntax:: ast:: { self , CrateNum , NodeId } ;
18
19
use syntax_pos:: Span ;
19
20
20
21
pub struct CrateData {
@@ -76,6 +77,35 @@ pub enum Data {
76
77
VariableRefData ( VariableRefData ) ,
77
78
}
78
79
80
+ #[ derive( Eq , PartialEq , Clone , Copy , Debug , RustcEncodable ) ]
81
+ pub enum Visibility {
82
+ Public ,
83
+ Restricted ,
84
+ Inherited ,
85
+ }
86
+
87
+ impl < ' a > From < & ' a ast:: Visibility > for Visibility {
88
+ fn from ( v : & ' a ast:: Visibility ) -> Visibility {
89
+ match * v {
90
+ ast:: Visibility :: Public => Visibility :: Public ,
91
+ ast:: Visibility :: Crate ( _) => Visibility :: Restricted ,
92
+ ast:: Visibility :: Restricted { .. } => Visibility :: Restricted ,
93
+ ast:: Visibility :: Inherited => Visibility :: Inherited ,
94
+ }
95
+ }
96
+ }
97
+
98
+ impl < ' a > From < & ' a hir:: Visibility > for Visibility {
99
+ fn from ( v : & ' a hir:: Visibility ) -> Visibility {
100
+ match * v {
101
+ hir:: Visibility :: Public => Visibility :: Public ,
102
+ hir:: Visibility :: Crate => Visibility :: Restricted ,
103
+ hir:: Visibility :: Restricted { .. } => Visibility :: Restricted ,
104
+ hir:: Visibility :: Inherited => Visibility :: Inherited ,
105
+ }
106
+ }
107
+ }
108
+
79
109
/// Data for the prelude of a crate.
80
110
#[ derive( Debug , RustcEncodable ) ]
81
111
pub struct CratePreludeData {
@@ -103,7 +133,7 @@ pub struct EnumData {
103
133
pub span : Span ,
104
134
pub scope : NodeId ,
105
135
pub variants : Vec < NodeId > ,
106
-
136
+ pub visibility : Visibility ,
107
137
}
108
138
109
139
/// Data for extern crates.
@@ -135,6 +165,8 @@ pub struct FunctionData {
135
165
pub span : Span ,
136
166
pub scope : NodeId ,
137
167
pub value : String ,
168
+ pub visibility : Visibility ,
169
+ pub parent : Option < NodeId > ,
138
170
}
139
171
140
172
/// Data about a function call.
@@ -215,6 +247,7 @@ pub struct MethodData {
215
247
pub scope : NodeId ,
216
248
pub value : String ,
217
249
pub decl_id : Option < DefId > ,
250
+ pub visibility : Visibility ,
218
251
}
219
252
220
253
/// Data for modules.
@@ -227,6 +260,7 @@ pub struct ModData {
227
260
pub scope : NodeId ,
228
261
pub filename : String ,
229
262
pub items : Vec < NodeId > ,
263
+ pub visibility : Visibility ,
230
264
}
231
265
232
266
/// Data for a reference to a module.
@@ -248,6 +282,7 @@ pub struct StructData {
248
282
pub scope : NodeId ,
249
283
pub value : String ,
250
284
pub fields : Vec < NodeId > ,
285
+ pub visibility : Visibility ,
251
286
}
252
287
253
288
#[ derive( Debug , RustcEncodable ) ]
@@ -258,7 +293,8 @@ pub struct StructVariantData {
258
293
pub qualname : String ,
259
294
pub type_value : String ,
260
295
pub value : String ,
261
- pub scope : NodeId
296
+ pub scope : NodeId ,
297
+ pub parent : Option < NodeId > ,
262
298
}
263
299
264
300
#[ derive( Debug , RustcEncodable ) ]
@@ -270,6 +306,7 @@ pub struct TraitData {
270
306
pub scope : NodeId ,
271
307
pub value : String ,
272
308
pub items : Vec < NodeId > ,
309
+ pub visibility : Visibility ,
273
310
}
274
311
275
312
#[ derive( Debug , RustcEncodable ) ]
@@ -280,7 +317,8 @@ pub struct TupleVariantData {
280
317
pub qualname : String ,
281
318
pub type_value : String ,
282
319
pub value : String ,
283
- pub scope : NodeId
320
+ pub scope : NodeId ,
321
+ pub parent : Option < NodeId > ,
284
322
}
285
323
286
324
/// Data for a typedef.
@@ -291,6 +329,8 @@ pub struct TypeDefData {
291
329
pub span : Span ,
292
330
pub qualname : String ,
293
331
pub value : String ,
332
+ pub visibility : Visibility ,
333
+ pub parent : Option < NodeId > ,
294
334
}
295
335
296
336
/// Data for a reference to a type or trait.
@@ -308,15 +348,17 @@ pub struct UseData {
308
348
pub span : Span ,
309
349
pub name : String ,
310
350
pub mod_id : Option < DefId > ,
311
- pub scope : NodeId
351
+ pub scope : NodeId ,
352
+ pub visibility : Visibility ,
312
353
}
313
354
314
355
#[ derive( Debug , RustcEncodable ) ]
315
356
pub struct UseGlobData {
316
357
pub id : NodeId ,
317
358
pub span : Span ,
318
359
pub names : Vec < String > ,
319
- pub scope : NodeId
360
+ pub scope : NodeId ,
361
+ pub visibility : Visibility ,
320
362
}
321
363
322
364
/// Data for local and global variables (consts and statics).
@@ -328,8 +370,10 @@ pub struct VariableData {
328
370
pub qualname : String ,
329
371
pub span : Span ,
330
372
pub scope : NodeId ,
373
+ pub parent : Option < NodeId > ,
331
374
pub value : String ,
332
375
pub type_value : String ,
376
+ pub visibility : Visibility ,
333
377
}
334
378
335
379
#[ derive( Debug , RustcEncodable ) ]
0 commit comments