1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
use crate::semantics::*; use crate::*; #[derive(Clone)] pub struct Analysis { pub types: Types, pub navigator: Navigator, diagnostics_cache: Option<Vec<Diagnostic>>, } impl Analysis { pub fn new(modules: Arc<HashMap<URI, Arc<syntax::Tree>>>) -> Analysis { let navigator = Navigator::new(modules); let types = Types::new(navigator.clone()); Analysis { navigator, types, diagnostics_cache: None, } } pub fn check(&mut self) -> &Vec<Diagnostic> { if self.diagnostics_cache.is_none() { let mut diagnostics = vec![]; for checker in checkers::checkers().iter() { checker.check(self, &mut diagnostics); } self.diagnostics_cache = Some(diagnostics); } self.diagnostics_cache.as_ref().unwrap() } } impl<I: Iterator<Item = (URI, Arc<syntax::Tree>)>> From<I> for Analysis { fn from(iterator: I) -> Self { Self::new(Arc::new(iterator.collect())) } }