Skip to main content

libsurfer/
variable_meta.rs

1use crate::wave_container::VariableMeta;
2#[local_impl::local_impl]
3impl VariableMetaExt for VariableMeta {
4    /// Check if the variable type name indicates signed integer type
5    fn has_signed_integer_type_name(&self) -> bool {
6        match_variable_type_name(self.variable_type_name.as_ref(), SIGNED_INTEGER_TYPE_NAMES)
7    }
8
9    /// Check if the variable type name indicates signed fixed-point type
10    fn has_signed_fixedpoint_type_name(&self) -> bool {
11        match_variable_type_name(
12            self.variable_type_name.as_ref(),
13            SIGNED_FIXEDPOINT_TYPE_NAMES,
14        )
15    }
16
17    /// Check if the variable type name indicates unsigned integer type
18    fn has_unsigned_integer_type_name(&self) -> bool {
19        match_variable_type_name(
20            self.variable_type_name.as_ref(),
21            UNSIGNED_INTEGER_TYPE_NAMES,
22        )
23    }
24
25    /// Check if the variable type name indicates unsigned fixed-point type
26    fn has_unsigned_fixedpoint_type_name(&self) -> bool {
27        match_variable_type_name(
28            self.variable_type_name.as_ref(),
29            UNSIGNED_FIXEDPOINT_TYPE_NAMES,
30        )
31    }
32}
33
34/// Helper to case insensitive match of variable type names against a list of candidates
35fn match_variable_type_name(
36    variable_type_name: Option<&String>,
37    candidates: &'static [&'static str],
38) -> bool {
39    variable_type_name
40        .is_some_and(|type_name| candidates.iter().any(|c| type_name.eq_ignore_ascii_case(c)))
41}
42
43/// Type names that should default to signed integer conversion
44/// - `ieee.numeric_std.signed`
45static SIGNED_INTEGER_TYPE_NAMES: &[&str] = &["unresolved_signed", "signed"];
46
47/// Type names that should default to signed fixed-point conversion
48/// - `ieee.fixed_pkg.sfixed`
49static SIGNED_FIXEDPOINT_TYPE_NAMES: &[&str] = &["unresolved_sfixed", "sfixed"];
50
51/// Type names that should default to unsigned integer conversion
52/// - `ieee.numeric_std.unsigned`
53static UNSIGNED_INTEGER_TYPE_NAMES: &[&str] = &["unresolved_unsigned", "unsigned"];
54
55/// Type names that should default to unsigned fixed-point conversion
56/// - `ieee.fixed_pkg.ufixed`
57static UNSIGNED_FIXEDPOINT_TYPE_NAMES: &[&str] = &["unresolved_ufixed", "ufixed"];