-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore.rs
More file actions
80 lines (71 loc) · 2.33 KB
/
Copy pathcore.rs
File metadata and controls
80 lines (71 loc) · 2.33 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use crate::analyser::index_identifier::IdentifierIndex;
use crate::diagnostics::diagnose::Diagnose;
use crate::diagnostics::kinds::DiagnosticKind;
use crate::diagnostics::reporter::Reporter;
use crate::parser::Meta;
use tucana::shared::{DefinitionDataType, FlowType, RuntimeFunctionDefinition};
#[derive(Clone)]
pub struct AnalysableDataType {
pub original_definition: Meta,
pub definition_data_type: DefinitionDataType,
pub id: i16,
}
#[derive(Clone)]
pub struct AnalysableFlowType {
pub original_definition: Meta,
pub flow_type: FlowType,
pub id: i16,
}
#[derive(Clone)]
pub struct AnalysableFunction {
pub original_definition: Meta,
pub function: RuntimeFunctionDefinition,
pub id: i16,
}
pub struct Analyser {
pub reporter: Reporter,
pub(crate) index: IdentifierIndex,
pub data_types: Vec<AnalysableDataType>,
pub flow_types: Vec<AnalysableFlowType>,
pub functions: Vec<AnalysableFunction>,
}
impl Analyser {
pub fn new(path: &str) -> Self {
super::loader::load_from_path(path)
}
pub fn report(&mut self, will_exit: bool) {
// Run analysis passes
for dt in self.data_types.clone() {
self.analyse_data_type(&dt);
}
for ft in self.flow_types.clone() {
self.analyse_flow_type(&ft);
}
for f in self.functions.clone() {
self.analyse_runtime_function(&f);
}
self.reporter.print(will_exit);
}
pub fn data_type_identifier_exists(&self, identifier: &str, except_id: Option<i16>) -> bool {
self.index.has_data_type(identifier, except_id)
}
pub fn generic_key_in_target(&self, key: &str, target: &str) -> bool {
let norm_target = target.to_ascii_lowercase();
self.data_types.iter().any(|dt| {
dt.definition_data_type
.identifier
.eq_ignore_ascii_case(&norm_target)
&& dt
.definition_data_type
.generic_keys
.contains(&key.to_string())
})
}
pub fn null_field(&mut self, name: String, adt: &AnalysableDataType) {
self.reporter.add(Diagnose::new(
adt.definition_data_type.identifier.clone(),
adt.original_definition.clone(),
DiagnosticKind::NullField { field_name: name },
));
}
}