@@ -15,27 +15,50 @@ use std::env;
15
15
use std:: fs:: { self , File } ;
16
16
use std:: path:: { Path , PathBuf } ;
17
17
18
- use syntax:: { ast, attr, visit} ;
18
+ use syntax:: { attr, visit} ;
19
+ use syntax:: ast:: { self , NodeId , DefId } ;
20
+ use syntax:: parse:: token:: keywords;
19
21
use syntax:: codemap:: * ;
20
22
23
+ use self :: span_utils:: SpanUtils ;
24
+
21
25
mod span_utils;
22
26
mod recorder;
23
27
24
28
mod dump_csv;
25
29
26
- pub struct SaveContext < ' l > {
30
+ pub struct SaveContext < ' l , ' tcx : ' l > {
27
31
sess : & ' l Session ,
32
+ analysis : & ' l ty:: CrateAnalysis < ' tcx > ,
33
+ span_utils : SpanUtils < ' l > ,
28
34
}
29
35
30
36
pub struct CrateData {
31
37
pub name : String ,
32
38
pub number : u32 ,
33
39
}
34
40
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 > {
37
58
SaveContext {
38
- sess : sess
59
+ sess : sess,
60
+ analysis : analysis,
61
+ span_utils : span_utils,
39
62
}
40
63
}
41
64
@@ -49,6 +72,30 @@ impl<'l> SaveContext<'l> {
49
72
50
73
result
51
74
}
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
+ }
52
99
}
53
100
54
101
#[ allow( deprecated) ]
0 commit comments