|
1 | 1 | use std::collections::BTreeMap;
|
2 | 2 | use std::mem;
|
3 | 3 |
|
4 |
| -use crate::availability::Availability; |
5 |
| -use crate::config::{ClassData, Config}; |
| 4 | +use crate::config::Config; |
6 | 5 | use crate::file::File;
|
7 | 6 | use crate::id::ItemIdentifier;
|
8 | 7 | use crate::method::Method;
|
9 | 8 | use crate::output::Output;
|
10 | 9 | use crate::stmt::Stmt;
|
11 | 10 |
|
12 |
| -#[derive(Debug, PartialEq, Clone)] |
13 |
| -struct MethodCache { |
14 |
| - availability: Availability, |
15 |
| - methods: Vec<Method>, |
16 |
| - category: ItemIdentifier<Option<String>>, |
17 |
| -} |
18 |
| - |
19 |
| -#[derive(Debug, PartialEq, Clone, Default)] |
20 |
| -struct ClassCache { |
21 |
| - /// Methods that should be duplicated onto any subclass. |
22 |
| - to_emit: Vec<MethodCache>, |
23 |
| - // We don't need availability here, since a superclass' availability |
24 |
| - // should always be greater than the subclass'. |
25 |
| -} |
26 |
| - |
27 |
| -impl ClassCache { |
28 |
| - fn all_methods_data(&self) -> impl Iterator<Item = (bool, &str)> { |
29 |
| - self.to_emit |
30 |
| - .iter() |
31 |
| - .flat_map(|cache| cache.methods.iter().map(|m| m.id())) |
32 |
| - } |
33 |
| -} |
34 |
| - |
35 | 11 | /// A helper struct for doing global analysis on the output.
|
36 | 12 | #[derive(Debug, PartialEq, Clone)]
|
37 | 13 | pub struct Cache<'a> {
|
38 |
| - classes: BTreeMap<ItemIdentifier, ClassCache>, |
39 | 14 | config: &'a Config,
|
40 | 15 | }
|
41 | 16 |
|
42 | 17 | impl<'a> Cache<'a> {
|
43 |
| - pub fn new(output: &Output, config: &'a Config) -> Self { |
44 |
| - let mut classes: BTreeMap<_, ClassCache> = BTreeMap::new(); |
45 |
| - |
46 |
| - for (name, library) in &output.libraries { |
47 |
| - let _span = debug_span!("library", name).entered(); |
48 |
| - for (name, file) in &library.files { |
49 |
| - let _span = debug_span!("file", name).entered(); |
50 |
| - for stmt in &file.stmts { |
51 |
| - if let Some((cls, method_cache)) = Self::cache_stmt(stmt) { |
52 |
| - let cache = classes.entry(cls.clone()).or_default(); |
53 |
| - cache.to_emit.push(method_cache); |
54 |
| - } |
55 |
| - } |
56 |
| - } |
57 |
| - } |
58 |
| - |
59 |
| - Self { classes, config } |
60 |
| - } |
61 |
| - |
62 |
| - fn cache_stmt(stmt: &Stmt) -> Option<(&ItemIdentifier, MethodCache)> { |
63 |
| - if let Stmt::Methods { |
64 |
| - cls, |
65 |
| - generics: _, |
66 |
| - category, |
67 |
| - availability, |
68 |
| - superclasses: _, |
69 |
| - methods, |
70 |
| - description, |
71 |
| - } = stmt |
72 |
| - { |
73 |
| - let _span = debug_span!("Stmt::Methods", ?cls).entered(); |
74 |
| - let methods: Vec<Method> = methods |
75 |
| - .iter() |
76 |
| - .filter(|method| method.emit_on_subclasses()) |
77 |
| - .cloned() |
78 |
| - .collect(); |
79 |
| - if methods.is_empty() { |
80 |
| - return None; |
81 |
| - } |
82 |
| - if description.is_some() { |
83 |
| - warn!(description, "description was set"); |
84 |
| - } |
85 |
| - let category = category.clone().with_new_path(cls); |
86 |
| - Some(( |
87 |
| - cls, |
88 |
| - MethodCache { |
89 |
| - availability: availability.clone(), |
90 |
| - methods, |
91 |
| - category, |
92 |
| - }, |
93 |
| - )) |
94 |
| - } else { |
95 |
| - None |
96 |
| - } |
| 18 | + pub fn new(_output: &Output, config: &'a Config) -> Self { |
| 19 | + Self { config } |
97 | 20 | }
|
98 | 21 |
|
99 | 22 | pub fn update(&self, output: &mut Output) {
|
@@ -145,70 +68,6 @@ impl<'a> Cache<'a> {
|
145 | 68 | }
|
146 | 69 | }
|
147 | 70 |
|
148 |
| - let mut new_stmts = Vec::new(); |
149 |
| - for stmt in &mut file.stmts { |
150 |
| - #[allow(clippy::single_match)] // There will be others |
151 |
| - match stmt { |
152 |
| - Stmt::ClassDecl { |
153 |
| - id, |
154 |
| - generics, |
155 |
| - superclasses, |
156 |
| - .. |
157 |
| - } => { |
158 |
| - let _span = debug_span!("Stmt::ClassDecl", ?id).entered(); |
159 |
| - let data = self.config.class_data.get(&id.name); |
160 |
| - |
161 |
| - // Used for duplicate checking (sometimes the subclass |
162 |
| - // defines the same method that the superclass did). |
163 |
| - let mut seen_methods: Vec<_> = self |
164 |
| - .classes |
165 |
| - .get(id) |
166 |
| - .map(|cache| cache.all_methods_data()) |
167 |
| - .into_iter() |
168 |
| - .flatten() |
169 |
| - .collect(); |
170 |
| - |
171 |
| - for (superclass, _) in &*superclasses { |
172 |
| - if let Some(cache) = self.classes.get(superclass) { |
173 |
| - new_stmts.extend(cache.to_emit.iter().filter_map(|cache| { |
174 |
| - let methods: Vec<_> = cache |
175 |
| - .methods |
176 |
| - .iter() |
177 |
| - .filter(|method| !seen_methods.contains(&method.id())) |
178 |
| - .filter_map(|method| { |
179 |
| - method.clone().update(ClassData::get_method_data( |
180 |
| - data, |
181 |
| - &method.fn_name, |
182 |
| - )) |
183 |
| - }) |
184 |
| - .collect(); |
185 |
| - if methods.is_empty() { |
186 |
| - return None; |
187 |
| - } |
188 |
| - |
189 |
| - Some(Stmt::Methods { |
190 |
| - cls: id.clone(), |
191 |
| - generics: generics.clone(), |
192 |
| - category: cache.category.clone(), |
193 |
| - availability: cache.availability.clone(), |
194 |
| - superclasses: superclasses.clone(), |
195 |
| - methods, |
196 |
| - description: Some(format!( |
197 |
| - "Methods declared on superclass `{}`", |
198 |
| - superclass.name |
199 |
| - )), |
200 |
| - }) |
201 |
| - })); |
202 |
| - |
203 |
| - seen_methods.extend(cache.all_methods_data()); |
204 |
| - } |
205 |
| - } |
206 |
| - } |
207 |
| - _ => {} |
208 |
| - } |
209 |
| - } |
210 |
| - file.stmts.extend(new_stmts); |
211 |
| - |
212 | 71 | // Fix up a few typedef + enum declarations
|
213 | 72 | let mut iter = mem::take(&mut file.stmts).into_iter().peekable();
|
214 | 73 | while let Some(stmt) = iter.next() {
|
|
0 commit comments