Skip to main content

luaur_analysis/records/
node.rs

1//! Faithful port of `Luau::detail::Node` (`Analysis/src/TopoSortStatements.cpp:78`).
2//!
3//! ```cpp
4//! struct Node : Arcs
5//! {
6//!     std::optional<Identifier> name;
7//!     AstStat* element;
8//!
9//!     Node(const std::optional<Identifier>& name, AstStat* el)
10//!         : name(name), element(el) {}
11//! };
12//! ```
13//!
14//! C++ `Node` publicly inherits `Arcs`, so `node->provides` / `node->depends`
15//! name the base's sets directly. Rust has no struct inheritance, so the two
16//! `Arcs` fields are flattened into `Node` (the only observable use of the base
17//! is `node->provides` / `node->depends`). A separate [`Arcs`](super::arcs::Arcs)
18//! value is still used by `drain` to build a filtered copy of the connectivity.
19
20use crate::records::identifier::Identifier;
21use alloc::collections::BTreeSet;
22use luaur_ast::records::ast_stat::AstStat;
23
24#[derive(Debug, Clone)]
25pub struct Node {
26    // Flattened `Arcs` base (`struct Node : Arcs`).
27    pub(crate) provides: BTreeSet<*mut Node>,
28    pub(crate) depends: BTreeSet<*mut Node>,
29
30    pub(crate) name: Option<Identifier>,
31    pub(crate) element: *mut AstStat,
32}
33
34impl Node {
35    /// `Node(const std::optional<Identifier>& name, AstStat* el)`.
36    pub fn new(name: Option<Identifier>, el: *mut AstStat) -> Self {
37        Self {
38            provides: BTreeSet::new(),
39            depends: BTreeSet::new(),
40            name,
41            element: el,
42        }
43    }
44}