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
/// Enum representing the different kinds of identifiers in the simplified representation.
#[derive(Debug, Clone, PartialEq)]
pub enum SrIdentifierKind {
    FunctionName,
    StaticFunctionName,
    TransitionName,
    ProcedureName,
    TemplateFunctionName,
    ExternalFunctionName,

    TypeName,
    ComponentName,
    Event,
    Namespace,
    BlockLabel,

    ContextResource,

    // Storage and reference
    VirtualRegister,
    VirtualRegisterIntermediate,
    Memory,
    State,

    // More info needed to derive kind
    Unknown,
}

/// Struct representing an identifier in the simplified representation.
#[derive(Debug, Clone, PartialEq)]
pub struct SrIdentifier {
    pub unresolved: String,
    pub resolved: Option<String>,
    pub type_reference: Option<String>,
    pub kind: SrIdentifierKind,
    pub is_definition: bool,
}

#[derive(Debug, Clone)]
pub struct SrType {
    pub main_type: String,
    pub sub_types: Vec<SrType>,
}

impl SrType {
    pub fn push_sub_type(&mut self, sub_type: SrType) {
        self.sub_types.push(sub_type);
    }
}

impl From<SrIdentifier> for SrType {
    fn from(value: SrIdentifier) -> Self {
        Self {
            main_type: value.unresolved,
            sub_types: vec![],
        }
    }
}

impl SrIdentifier {
    pub fn new(unresolved: String, kind: SrIdentifierKind) -> Self {
        Self {
            unresolved,
            resolved: None,
            type_reference: None,
            kind,
            is_definition: false,
        }
    }
}