ezno_checker/
type_mappings.rs1use crate::{
2 features::variables::VariableWithValue,
3 types::{TypeId, TypeStore},
4 GeneralContext, RangeMap, VariableId,
5};
6use source_map::{SourceId, SpanWithSource};
7use std::{collections::HashMap, path::PathBuf};
8
9#[derive(Default, Debug)]
15pub struct TypeMappings {
16 pub expressions_to_instances: RangeMap<Instance>,
18 pub variables_to_constraints: VariablesToTypes,
21 pub properties_to_types: RangeMap<TypeId>,
23 pub types_to_types: RangeMap<TypeId>,
25 pub import_statements_to_pointing_path: RangeMap<PathBuf>,
26
27 pub var_aliases: HashMap<u32, VariableId>,
29
30 pub variable_restrictions: HashMap<(SourceId, u32), (TypeId, SpanWithSource)>,
32 pub special_expressions: RangeMap<SpecialExpressions>,
34}
35
36#[derive(Debug)]
37pub enum SpecialExpressions {
38 CompileOut,
39 Marker,
40}
41
42#[derive(Default, Debug)]
43pub struct VariablesToTypes(pub(crate) HashMap<VariableId, TypeId>);
44
45impl TypeMappings {
47 #[must_use]
48 pub fn print_type_mappings(
49 &self,
50 _source: &str,
51 _env: &GeneralContext,
52 _types: &TypeStore,
53 ) -> String {
54 todo!()
55 }
66}
67
68#[derive(Clone, Debug)]
71pub enum Instance {
72 LValue(VariableWithValue),
73 RValue(TypeId),
74 GValue(TypeId),
76}
77
78impl Instance {
79 #[must_use]
80 pub fn get_variable_id(&self) -> Option<VariableId> {
81 match self {
82 Self::LValue(variable) => Some(variable.0.get_id()),
83 Self::RValue(_) | Self::GValue(_) => None,
84 }
85 }
86
87 #[must_use]
88 pub fn get_value(self) -> TypeId {
89 match self {
90 Instance::LValue(l) => l.1,
91 Instance::GValue(value) | Instance::RValue(value) => value,
92 }
93 }
94
95 #[must_use]
96 pub fn get_value_on_ref(&self) -> TypeId {
97 match self {
98 Instance::LValue(l) => l.1,
99 Instance::GValue(value) | Instance::RValue(value) => *value,
100 }
101 }
102}