@@ -15,27 +15,50 @@ use std::env;
1515use std:: fs:: { self , File } ;
1616use std:: path:: { Path , PathBuf } ;
1717
18- use syntax:: { ast, attr, visit} ;
18+ use syntax:: { attr, visit} ;
19+ use syntax:: ast:: { self , NodeId , DefId } ;
20+ use syntax:: parse:: token:: keywords;
1921use syntax:: codemap:: * ;
2022
23+ use self :: span_utils:: SpanUtils ;
24+
2125mod span_utils;
2226mod recorder;
2327
2428mod dump_csv;
2529
26- pub struct SaveContext < ' l > {
30+ pub struct SaveContext < ' l , ' tcx : ' l > {
2731 sess : & ' l Session ,
32+ analysis : & ' l ty:: CrateAnalysis < ' tcx > ,
33+ span_utils : SpanUtils < ' l > ,
2834}
2935
3036pub struct CrateData {
3137 pub name : String ,
3238 pub number : u32 ,
3339}
3440
35- impl < ' l > SaveContext < ' l > {
36- pub fn new < ' ll > ( sess : & ' ll Session ) -> SaveContext < ' ll > {
41+ pub enum Data {
42+ FunctionData ( FunctionData ) ,
43+ }
44+
45+ pub struct FunctionData {
46+ pub id : NodeId ,
47+ pub qualname : String ,
48+ pub declaration : Option < DefId > ,
49+ pub span : Span ,
50+ pub scope : NodeId ,
51+ }
52+
53+ impl < ' l , ' tcx : ' l > SaveContext < ' l , ' tcx > {
54+ pub fn new ( sess : & ' l Session ,
55+ analysis : & ' l ty:: CrateAnalysis < ' tcx > ,
56+ span_utils : SpanUtils < ' l > )
57+ -> SaveContext < ' l , ' tcx > {
3758 SaveContext {
38- sess : sess
59+ sess : sess,
60+ analysis : analysis,
61+ span_utils : span_utils,
3962 }
4063 }
4164
@@ -49,6 +72,30 @@ impl<'l> SaveContext<'l> {
4972
5073 result
5174 }
75+
76+ pub fn get_item_data ( & self , item : & ast:: Item ) -> Data {
77+ match item. node {
78+ ast:: Item_ :: ItemFn ( ..) => {
79+ let qualname = format ! ( "::{}" , self . analysis. ty_cx. map. path_to_string( item. id) ) ;
80+ let sub_span = self . span_utils . sub_span_after_keyword ( item. span , keywords:: Fn ) ;
81+
82+ Data :: FunctionData ( FunctionData {
83+ id : item. id ,
84+ qualname : qualname,
85+ declaration : None ,
86+ span : sub_span. unwrap ( ) ,
87+ scope : self . analysis . ty_cx . map . get_parent ( item. id ) ,
88+ } )
89+ }
90+ _ => {
91+ unimplemented ! ( ) ;
92+ }
93+ }
94+ }
95+
96+ pub fn get_data_for_id ( & self , id : & NodeId ) -> Data {
97+ unimplemented ! ( ) ;
98+ }
5299}
53100
54101#[ allow( deprecated) ]
0 commit comments