Skip to main content

zerodds_ast/node/
module.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 ZeroDDS Contributors
3//! Modules. Spec §3.1.
4
5use crate::facet::Facets;
6use crate::node::AnyId;
7use alloc::string::String;
8use alloc::vec::Vec;
9use zerodds_ast_core::{Id, NodeId};
10
11/// A namespace. Spec §3.1.
12///
13/// Reopening a module in a second translation unit merges into the same
14/// node rather than creating a second one; see
15/// [`crate::Ast::ensure_module`]. That is the structural resolution of
16/// the per-file fragmentation that previously needed an opt-in dedup
17/// pass on multi-input builds.
18#[derive(Debug, Clone, PartialEq, Eq)]
19pub struct ModuleNode {
20    /// Stable identity.
21    pub node_id: NodeId,
22    /// Simple name. Empty for the root module.
23    pub name: String,
24    /// Enclosing module; `None` only for the root.
25    pub parent: Option<Id<ModuleNode>>,
26    /// Everything declared directly inside, in declaration order.
27    pub children: Vec<AnyId>,
28    /// Per-source information. A module reopened across files records
29    /// the first origin; the rest live in the changeset history.
30    /// Spec §4.7.
31    pub facets: Facets,
32}
33
34impl ModuleNode {
35    /// Whether this is the anonymous global scope.
36    #[must_use]
37    pub const fn is_root(&self) -> bool {
38        self.parent.is_none()
39    }
40}