Skip to main content

zerodds_ast/node/
interface.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 ZeroDDS Contributors
3//! Interfaces, operations, parameters and attributes. Spec §3.4.
4
5use crate::facet::Facets;
6use crate::node::AnyId;
7use crate::node::exception::ExceptionNode;
8use crate::node::module::ModuleNode;
9use crate::node::type_::{Completeness, TypeNode};
10use alloc::string::String;
11use alloc::vec::Vec;
12use zerodds_ast_core::{Id, NodeId, Ref};
13
14/// Which interface form this is. Spec §3.4.
15///
16/// `Component`, `Home`, `Connector` and `PortType` are CCM forms; their
17/// role detail lives in `CorbaFacet` rather than in more core kinds.
18#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19pub enum InterfaceKind {
20    /// `interface`
21    Interface,
22    /// `local interface`
23    Local,
24    /// `abstract interface`
25    Abstract,
26    /// `component`
27    Component,
28    /// `home`
29    Home,
30    /// `connector`
31    Connector,
32    /// `porttype`
33    PortType,
34}
35
36impl InterfaceKind {
37    /// Every form of spec §3.4.
38    pub const ALL: [Self; 7] = [
39        Self::Interface,
40        Self::Local,
41        Self::Abstract,
42        Self::Component,
43        Self::Home,
44        Self::Connector,
45        Self::PortType,
46    ];
47
48    /// Source spelling.
49    #[must_use]
50    pub const fn as_str(self) -> &'static str {
51        match self {
52            Self::Interface => "interface",
53            Self::Local => "local interface",
54            Self::Abstract => "abstract interface",
55            Self::Component => "component",
56            Self::Home => "home",
57            Self::Connector => "connector",
58            Self::PortType => "porttype",
59        }
60    }
61
62    /// Whether this form belongs to the CORBA component model rather
63    /// than to plain IDL interfaces.
64    #[must_use]
65    pub const fn is_component_model(self) -> bool {
66        matches!(
67            self,
68            Self::Component | Self::Home | Self::Connector | Self::PortType
69        )
70    }
71}
72
73/// An interface or component form. Spec §3.4.
74#[derive(Debug, Clone, PartialEq, Eq)]
75pub struct InterfaceNode {
76    /// Stable identity.
77    pub node_id: NodeId,
78    /// Simple name.
79    pub name: String,
80    /// Enclosing module.
81    pub module: Id<ModuleNode>,
82    /// Which form.
83    pub kind: InterfaceKind,
84    /// Base interfaces, in declaration order.
85    ///
86    /// The order matters: CORBA multiple inheritance resolves operation
87    /// lookup along it.
88    pub bases: Vec<Ref<InterfaceNode>>,
89    /// Operations in declaration order.
90    pub operations: Vec<Id<OperationNode>>,
91    /// Attributes in declaration order.
92    pub attributes: Vec<Id<AttributeNode>>,
93    /// Whether the body has arrived.
94    pub completeness: Completeness,
95    /// Per-source information. Spec §4.
96    pub facets: Facets,
97}
98
99/// Parameter passing direction. Spec §3.4.
100#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
101pub enum ParamDirection {
102    /// `in`
103    In,
104    /// `out`
105    Out,
106    /// `inout`
107    InOut,
108}
109
110impl ParamDirection {
111    /// Every direction IDL defines.
112    pub const ALL: [Self; 3] = [Self::In, Self::Out, Self::InOut];
113
114    /// Source spelling.
115    #[must_use]
116    pub const fn as_str(self) -> &'static str {
117        match self {
118            Self::In => "in",
119            Self::Out => "out",
120            Self::InOut => "inout",
121        }
122    }
123}
124
125/// An operation. Spec §3.4.
126#[derive(Debug, Clone, PartialEq, Eq)]
127pub struct OperationNode {
128    /// Stable identity.
129    pub node_id: NodeId,
130    /// Simple name.
131    pub name: String,
132    /// Return type, absent for a `void` operation.
133    ///
134    /// `void` is the absence of a return, not a data type: giving it a
135    /// type node would put a value with no representation into the
136    /// layout and profile tables. IDL 4.2 §7.4.3.5.
137    pub return_type: Option<Ref<TypeNode>>,
138    /// Parameters in declaration order.
139    pub params: Vec<Id<ParamNode>>,
140    /// Exceptions this operation may raise.
141    pub raises: Vec<Ref<ExceptionNode>>,
142    /// Whether the operation is `oneway`.
143    pub oneway: bool,
144    /// `context` identifiers, in declaration order.
145    pub contexts: Vec<String>,
146    /// The interface or valuetype this operation belongs to.
147    pub parent: AnyId,
148    /// Per-source information. Spec §4.
149    pub facets: Facets,
150}
151
152/// An operation parameter. Spec §3.4.
153#[derive(Debug, Clone, PartialEq, Eq)]
154pub struct ParamNode {
155    /// Stable identity.
156    pub node_id: NodeId,
157    /// Simple name.
158    pub name: String,
159    /// Passing direction.
160    pub direction: ParamDirection,
161    /// Declared type.
162    pub type_: Ref<TypeNode>,
163    /// The operation this parameter belongs to.
164    pub parent: Id<OperationNode>,
165    /// Per-source information. Spec §4.
166    pub facets: Facets,
167}
168
169/// An interface attribute. Spec §3.4.
170#[derive(Debug, Clone, PartialEq, Eq)]
171pub struct AttributeNode {
172    /// Stable identity.
173    pub node_id: NodeId,
174    /// Simple name.
175    pub name: String,
176    /// Declared type.
177    pub type_: Ref<TypeNode>,
178    /// Whether the attribute is `readonly`.
179    pub readonly: bool,
180    /// Exceptions the getter may raise.
181    pub get_raises: Vec<Ref<ExceptionNode>>,
182    /// Exceptions the setter may raise. A `readonly` attribute with a
183    /// non-empty setter list is representable here and rejected by
184    /// profile validation, not by the model. Spec §8.2.
185    pub set_raises: Vec<Ref<ExceptionNode>>,
186    /// The interface this attribute belongs to.
187    pub parent: Id<InterfaceNode>,
188    /// Per-source information. Spec §4.
189    pub facets: Facets,
190}