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
//! A visitor implementation for renaming subcomponents in a component reference.
//!
//! The `SubCompNamer` struct is used to modify the names of subcomponents within
//! a component reference in the intermediate representation (IR) of the code.
//! It operates by checking if the first part of the component reference matches
//! the specified component name (`comp`). If a match is found, the first part
//! of the reference is removed, and the next part is renamed by prefixing it
//! with the component name using dot notation.
//!
//! # Fields
//! - `comp`: The name of the component to match and use as a prefix for renaming.
//! - `is_operator_record`: If true, subscripts from the first part are moved to the
//! new flattened name (e.g., `u[1].re` -> `u.re[1]` for Complex arrays).
//!
//! # Example
//! Given a component reference like `comp.subcomp`, if `comp` is set to `"comp"`,
//! the visitor will transform it into `comp.subcomp` (flattened with dot separator).
//!
//! For operator records like Complex with `is_operator_record=true`:
//! Given `comp[1].subcomp`, it transforms to `comp.subcomp[1]`.
//!
//! # Trait Implementations
//! Implements the `Visitor` trait, specifically overriding the
//! `exit_component_reference` method to perform the renaming logic.
//!
//! # Method
//! - `exit_component_reference`: Modifies the `ComponentReference` node by
//! renaming its parts based on the specified component name.
use crateir;
use crateMutVisitor;