use crate::facet::Facets;
use crate::node::AnyId;
use crate::node::exception::ExceptionNode;
use crate::node::module::ModuleNode;
use crate::node::type_::{Completeness, TypeNode};
use alloc::string::String;
use alloc::vec::Vec;
use zerodds_ast_core::{Id, NodeId, Ref};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum InterfaceKind {
Interface,
Local,
Abstract,
Component,
Home,
Connector,
PortType,
}
impl InterfaceKind {
pub const ALL: [Self; 7] = [
Self::Interface,
Self::Local,
Self::Abstract,
Self::Component,
Self::Home,
Self::Connector,
Self::PortType,
];
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::Interface => "interface",
Self::Local => "local interface",
Self::Abstract => "abstract interface",
Self::Component => "component",
Self::Home => "home",
Self::Connector => "connector",
Self::PortType => "porttype",
}
}
#[must_use]
pub const fn is_component_model(self) -> bool {
matches!(
self,
Self::Component | Self::Home | Self::Connector | Self::PortType
)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct InterfaceNode {
pub node_id: NodeId,
pub name: String,
pub module: Id<ModuleNode>,
pub kind: InterfaceKind,
pub bases: Vec<Ref<InterfaceNode>>,
pub operations: Vec<Id<OperationNode>>,
pub attributes: Vec<Id<AttributeNode>>,
pub completeness: Completeness,
pub facets: Facets,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ParamDirection {
In,
Out,
InOut,
}
impl ParamDirection {
pub const ALL: [Self; 3] = [Self::In, Self::Out, Self::InOut];
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::In => "in",
Self::Out => "out",
Self::InOut => "inout",
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct OperationNode {
pub node_id: NodeId,
pub name: String,
pub return_type: Option<Ref<TypeNode>>,
pub params: Vec<Id<ParamNode>>,
pub raises: Vec<Ref<ExceptionNode>>,
pub oneway: bool,
pub contexts: Vec<String>,
pub parent: AnyId,
pub facets: Facets,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParamNode {
pub node_id: NodeId,
pub name: String,
pub direction: ParamDirection,
pub type_: Ref<TypeNode>,
pub parent: Id<OperationNode>,
pub facets: Facets,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AttributeNode {
pub node_id: NodeId,
pub name: String,
pub type_: Ref<TypeNode>,
pub readonly: bool,
pub get_raises: Vec<Ref<ExceptionNode>>,
pub set_raises: Vec<Ref<ExceptionNode>>,
pub parent: Id<InterfaceNode>,
pub facets: Facets,
}