]> git.lizzy.rs Git - rust.git/blob - src/librustc_save_analysis/dumper.rs
Remove unchecked inline attribute, remove unused functions, make chache mod private...
[rust.git] / src / librustc_save_analysis / dumper.rs
1 use rls_data::config::Config;
2 use rls_data::{self, Analysis, CompilationOptions, CratePreludeData, Def, DefKind, Impl, Import,
3                MacroRef, Ref, RefKind, Relation};
4 use rls_span::{Column, Row};
5
6 #[derive(Debug)]
7 pub struct Access {
8     pub reachable: bool,
9     pub public: bool,
10 }
11
12 pub struct Dumper {
13     result: Analysis,
14     config: Config,
15 }
16
17 impl Dumper {
18     pub fn new(config: Config) -> Dumper {
19         Dumper {
20             config: config.clone(),
21             result: Analysis::new(config),
22         }
23     }
24
25     pub fn analysis(&self) -> &Analysis {
26         &self.result
27     }
28 }
29
30 impl Dumper {
31     pub fn crate_prelude(&mut self, data: CratePreludeData) {
32         self.result.prelude = Some(data)
33     }
34
35     pub fn compilation_opts(&mut self, data: CompilationOptions) {
36         self.result.compilation = Some(data);
37     }
38
39     pub fn _macro_use(&mut self, data: MacroRef) {
40         if self.config.pub_only || self.config.reachable_only {
41             return;
42         }
43         self.result.macro_refs.push(data);
44     }
45
46     pub fn import(&mut self, access: &Access, import: Import) {
47         if !access.public && self.config.pub_only
48             || !access.reachable && self.config.reachable_only {
49             return;
50         }
51         self.result.imports.push(import);
52     }
53
54     pub fn dump_ref(&mut self, data: Ref) {
55         if self.config.pub_only || self.config.reachable_only {
56             return;
57         }
58         self.result.refs.push(data);
59     }
60
61     pub fn dump_def(&mut self, access: &Access, mut data: Def) {
62         if !access.public && self.config.pub_only
63             || !access.reachable && self.config.reachable_only {
64             return;
65         }
66         if data.kind == DefKind::Mod && data.span.file_name.to_str().unwrap() != data.value {
67             // If the module is an out-of-line definition, then we'll make the
68             // definition the first character in the module's file and turn
69             // the declaration into a reference to it.
70             let rf = Ref {
71                 kind: RefKind::Mod,
72                 span: data.span,
73                 ref_id: data.id,
74             };
75             self.result.refs.push(rf);
76             data.span = rls_data::SpanData {
77                 file_name: data.value.clone().into(),
78                 byte_start: 0,
79                 byte_end: 0,
80                 line_start: Row::new_one_indexed(1),
81                 line_end: Row::new_one_indexed(1),
82                 column_start: Column::new_one_indexed(1),
83                 column_end: Column::new_one_indexed(1),
84             }
85         }
86         self.result.defs.push(data);
87     }
88
89     pub fn dump_relation(&mut self, data: Relation) {
90         self.result.relations.push(data);
91     }
92
93     pub fn dump_impl(&mut self, data: Impl) {
94         self.result.impls.push(data);
95     }
96 }