@@ -16,6 +16,7 @@ use middle::lang_items;
16
16
use middle:: ty;
17
17
use middle:: def_id:: { DefId , DefIndex } ;
18
18
19
+ use std:: any:: Any ;
19
20
use std:: rc:: Rc ;
20
21
use syntax:: ast;
21
22
use syntax:: attr;
@@ -24,9 +25,18 @@ use rustc_front::hir;
24
25
pub use metadata:: csearch:: FoundAst ;
25
26
pub use metadata:: cstore:: LinkagePreference ;
26
27
pub use metadata:: decoder:: DecodeInlinedItem ;
28
+ pub use metadata:: decoder:: DefLike ;
27
29
pub use metadata:: inline:: InlinedItem ;
28
30
29
- pub trait CrateStore < ' tcx > {
31
+ pub use self :: DefLike :: { DlDef , DlField , DlImpl } ;
32
+
33
+ pub struct ChildItem {
34
+ pub def : DefLike ,
35
+ pub name : ast:: Name ,
36
+ pub vis : hir:: Visibility
37
+ }
38
+
39
+ pub trait CrateStore < ' tcx > : Any {
30
40
// item info
31
41
fn stability ( & self , def : DefId ) -> Option < attr:: Stability > ;
32
42
fn closure_kind ( & self , tcx : & ty:: ctxt < ' tcx > , def_id : DefId )
@@ -75,17 +85,24 @@ pub trait CrateStore<'tcx> {
75
85
fn is_const_fn ( & self , did : DefId ) -> bool ;
76
86
fn is_defaulted_trait ( & self , did : DefId ) -> bool ;
77
87
fn is_impl ( & self , did : DefId ) -> bool ;
88
+ fn is_static_method ( & self , did : DefId ) -> bool ;
78
89
79
90
// metadata
80
91
fn dylib_dependency_formats ( & self , cnum : ast:: CrateNum )
81
- -> Vec < ( ast:: CrateNum , cstore :: LinkagePreference ) > ;
92
+ -> Vec < ( ast:: CrateNum , LinkagePreference ) > ;
82
93
fn lang_items ( & self , cnum : ast:: CrateNum ) -> Vec < ( DefIndex , usize ) > ;
83
- fn missing_lang_items ( & self , cnum : ast:: CrateNum )
84
- -> Vec < lang_items:: LangItem > ;
94
+ fn missing_lang_items ( & self , cnum : ast:: CrateNum ) -> Vec < lang_items:: LangItem > ;
85
95
fn is_staged_api ( & self , cnum : ast:: CrateNum ) -> bool ;
96
+ fn plugin_registrar_fn ( & self , cnum : ast:: CrateNum ) -> Option < DefId > ;
86
97
87
- // misc.
98
+ // resolve
88
99
fn def_path ( & self , def : DefId ) -> ast_map:: DefPath ;
100
+ fn tuple_struct_definition_if_ctor ( & self , did : DefId ) -> Option < DefId > ;
101
+ fn struct_field_names ( & self , def : DefId ) -> Vec < ast:: Name > ;
102
+ fn item_children ( & self , did : DefId ) -> Vec < ChildItem > ;
103
+ fn crate_top_level_items ( & self , cnum : ast:: CrateNum ) -> Vec < ChildItem > ;
104
+
105
+ // misc.
89
106
fn maybe_get_item_ast ( & ' tcx self , tcx : & ty:: ctxt < ' tcx > , def : DefId )
90
107
-> FoundAst < ' tcx > ;
91
108
}
@@ -278,8 +295,13 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
278
295
decoder:: is_impl ( & * cdata, did. index )
279
296
}
280
297
298
+ fn is_static_method ( & self , def : DefId ) -> bool {
299
+ let cdata = self . get_crate_data ( def. krate ) ;
300
+ decoder:: is_static_method ( & * cdata, def. index )
301
+ }
302
+
281
303
fn dylib_dependency_formats ( & self , cnum : ast:: CrateNum )
282
- -> Vec < ( ast:: CrateNum , cstore :: LinkagePreference ) >
304
+ -> Vec < ( ast:: CrateNum , LinkagePreference ) >
283
305
{
284
306
let cdata = self . get_crate_data ( cnum) ;
285
307
decoder:: get_dylib_dependency_formats ( & cdata)
@@ -307,13 +329,66 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
307
329
self . get_crate_data ( cnum) . staged_api
308
330
}
309
331
310
- fn def_path ( & self , def : DefId ) -> ast_map:: DefPath {
332
+ fn plugin_registrar_fn ( & self , cnum : ast:: CrateNum ) -> Option < DefId >
333
+ {
334
+ let cdata = self . get_crate_data ( cnum) ;
335
+ decoder:: get_plugin_registrar_fn ( cdata. data ( ) ) . map ( |index| DefId {
336
+ krate : cnum,
337
+ index : index
338
+ } )
339
+ }
340
+
341
+ fn def_path ( & self , def : DefId ) -> ast_map:: DefPath
342
+ {
311
343
let cdata = self . get_crate_data ( def. krate ) ;
312
344
let path = decoder:: def_path ( & * cdata, def. index ) ;
313
345
let local_path = cdata. local_def_path ( ) ;
314
346
local_path. into_iter ( ) . chain ( path) . collect ( )
315
347
}
316
348
349
+ fn tuple_struct_definition_if_ctor ( & self , did : DefId ) -> Option < DefId >
350
+ {
351
+ let cdata = self . get_crate_data ( did. krate ) ;
352
+ decoder:: get_tuple_struct_definition_if_ctor ( & * cdata, did. index )
353
+ }
354
+
355
+ fn struct_field_names ( & self , def : DefId ) -> Vec < ast:: Name >
356
+ {
357
+ let cdata = self . get_crate_data ( def. krate ) ;
358
+ decoder:: get_struct_field_names ( & self . intr , & * cdata, def. index )
359
+ }
360
+
361
+ fn item_children ( & self , def_id : DefId ) -> Vec < ChildItem >
362
+ {
363
+ let mut result = vec ! [ ] ;
364
+ let crate_data = self . get_crate_data ( def_id. krate ) ;
365
+ let get_crate_data = |cnum| self . get_crate_data ( cnum) ;
366
+ decoder:: each_child_of_item (
367
+ self . intr . clone ( ) , & * crate_data,
368
+ def_id. index , get_crate_data,
369
+ |def, name, vis| result. push ( ChildItem {
370
+ def : def,
371
+ name : name,
372
+ vis : vis
373
+ } ) ) ;
374
+ result
375
+ }
376
+
377
+ fn crate_top_level_items ( & self , cnum : ast:: CrateNum ) -> Vec < ChildItem >
378
+ {
379
+ let mut result = vec ! [ ] ;
380
+ let crate_data = self . get_crate_data ( cnum) ;
381
+ let get_crate_data = |cnum| self . get_crate_data ( cnum) ;
382
+ decoder:: each_top_level_item_of_crate (
383
+ self . intr . clone ( ) , & * crate_data, get_crate_data,
384
+ |def, name, vis| result. push ( ChildItem {
385
+ def : def,
386
+ name : name,
387
+ vis : vis
388
+ } ) ) ;
389
+ result
390
+ }
391
+
317
392
fn maybe_get_item_ast ( & ' tcx self , tcx : & ty:: ctxt < ' tcx > , def : DefId )
318
393
-> FoundAst < ' tcx >
319
394
{
0 commit comments