rtlola_hir/
type_check.rs

1mod pacing_ast_climber;
2mod pacing_types;
3mod rtltc;
4mod value_ast_climber;
5mod value_types;
6
7use rtlola_reporting::RtLolaError;
8use uom::si::rational64::Frequency as UOM_Frequency;
9
10pub use self::pacing_types::ActivationCondition;
11use crate::hir::{Expression, Hir};
12use crate::modes::{HirMode, Typed};
13use crate::type_check::rtltc::LolaTypeChecker;
14
15/// Checks all types of in the [Hir] and returns a [Typed] struct, containing all type information.
16/// In case of a type error a string with sparse error description is returned and the [Handler] emits
17/// detailed error information.
18pub(crate) fn type_check<M>(hir: &Hir<M>) -> Result<Typed, RtLolaError>
19where
20    M: HirMode + 'static,
21{
22    let mut tyc = LolaTypeChecker::new(hir);
23    tyc.check()
24}
25
26/// The external definition of a pacing type.
27#[derive(Debug, Clone, PartialEq, Eq)]
28pub enum ConcretePacingType {
29    /// The stream / expression can be evaluated whenever the activation condition is satisfied.
30    Event(ActivationCondition),
31    /// The stream / expression can be evaluated with a fixed global frequency.
32    FixedGlobalPeriodic(UOM_Frequency),
33    /// The stream / expression can be evaluated with a fixed local frequency.
34    FixedLocalPeriodic(UOM_Frequency),
35    /// The stream / expression can be evaluated with any frequency.
36    AnyPeriodic,
37    /// The stream / expression can always be evaluated.
38    Constant,
39}
40
41impl ConcretePacingType {
42    /// Returns true if the type is fixed-periodic
43    pub fn is_periodic(&self) -> bool {
44        matches!(
45            self,
46            ConcretePacingType::FixedLocalPeriodic(_) | ConcretePacingType::FixedGlobalPeriodic(_)
47        )
48    }
49
50    /// Returns true if the type is event-based
51    pub fn is_event_based(&self) -> bool {
52        matches!(self, ConcretePacingType::Event(_))
53    }
54
55    /// Returns true if the type is constant
56    pub fn is_constant(&self) -> bool {
57        matches!(self, ConcretePacingType::Constant)
58    }
59}
60
61/// The external definition for a value type.
62#[derive(Debug, Clone, Eq, PartialEq, Hash)]
63pub enum ConcreteValueType {
64    /// Bool e.g. true, false
65    Bool,
66    /// 8-bit signed integer
67    Integer8,
68    /// 16-bit signed integer
69    Integer16,
70    /// 32-bit signed integer
71    Integer32,
72    /// 64-bit signed integer
73    Integer64,
74    /// 128-bit signed integer
75    Integer128,
76    /// 256-bit signed integer
77    Integer256,
78    /// 8-bit unsigned integer
79    UInteger8,
80    /// 16-bit unsigned integer
81    UInteger16,
82    /// 32-bit unsigned integer
83    UInteger32,
84    /// 64-bit unsigned integer
85    UInteger64,
86    /// 128-bit unsigned integer
87    UInteger128,
88    /// 256-bit unsigned integer
89    UInteger256,
90    /// 32-bit floating point value
91    Float32,
92    /// 64-bit floating point value
93    Float64,
94    /// A 64-bit signed fixed-point number with 32-bits fractional part
95    Fixed64_32,
96    /// A 32-bit signed fixed-point number with 16-bits fractional part
97    Fixed32_16,
98    /// A 16-bit signed fixed-point number with 8-bits fractional part
99    Fixed16_8,
100    /// A 64-bit unsigned fixed-point number with 32-bits fractional part
101    UFixed64_32,
102    /// A 32-bit unsigned fixed-point number with 16-bits fractional part
103    UFixed32_16,
104    /// A 16-bit unsigned fixed-point number with 8-bits fractional part
105    UFixed16_8,
106    /// A tuple type of arbitrary but fixed length: (Int8, Float32, Bool)
107    Tuple(Vec<ConcreteValueType>),
108    /// String value: "Hello"
109    TString,
110    /// Byte value, used for string index access and regex matches
111    Byte,
112    /// Optional value for partial functions like [Offset](crate::hir::Offset)
113    Option(Box<ConcreteValueType>),
114}
115
116/// The external definition of the stream pacing.
117#[derive(Debug, Clone)]
118pub struct ConcreteStreamPacing {
119    /// The pacing of the stream expression.
120    pub eval_pacing: ConcretePacingType,
121    /// The filter expression
122    pub eval_condition: Expression,
123    /// The pacing of the spawn expression
124    pub spawn_pacing: ConcretePacingType,
125    /// The spawn condition expression
126    pub spawn_condition: Expression,
127    /// The pacing of the close expression.
128    pub close_pacing: ConcretePacingType,
129    /// The close expression
130    pub close_condition: Expression,
131}
132
133/// The external definition of the stream type.
134#[derive(Debug, Clone)]
135pub struct StreamType {
136    /// The [ConcreteValueType] of the stream and his expression, e.g. Bool.
137    pub value_ty: ConcreteValueType,
138    /// The [ConcretePacingType] of the stream, e.g. 5Hz.
139    pub eval_pacing: ConcretePacingType,
140    /// The filter type given by the filter expression.
141    /// The stream only has to be evaluated if this boolean expression evaluates to true.
142    pub eval_condition: Expression,
143    /// The pacing of the spawn expression.
144    pub spawn_pacing: ConcretePacingType,
145    /// The spawn condition of the stream. The spawn expression only has to be evaluated if this expression evaluates to true.
146    pub spawn_condition: Expression,
147    /// The pacing of the close condition.
148    pub close_pacing: ConcretePacingType,
149    /// The stream can be closed and does not have to be evaluated if this boolean expression returns true.
150    pub close_condition: Expression,
151}