zerodds_ast/facet/applied.rs
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 ZeroDDS Contributors
3//! Annotations applied to a node that have no typed field. Spec §4.1.
4//!
5//! The annotations the specifications define reach typed fields — an
6//! `@key` sets [`XTypesFacet::is_key`], not an entry here. This carries
7//! what a user declared with `@annotation`: a name, its arguments, and a
8//! reference to the declaration they belong to.
9//!
10//! Without it a user-defined annotation would have nowhere to land, and
11//! a backend regenerating IDL would silently emit a declaration the
12//! source never had.
13//!
14//! [`XTypesFacet::is_key`]: crate::facet::xtypes::XTypesFacet::is_key
15
16use crate::node::annotation::AnnotationDefNode;
17use crate::node::constant::ConstExprNode;
18use alloc::string::String;
19use alloc::vec::Vec;
20use zerodds_ast_core::{Id, Ref};
21
22/// One argument of an applied annotation.
23#[derive(Debug, Clone, PartialEq, Eq)]
24pub struct AppliedArgument {
25 /// The parameter name, when the source wrote `k = v`.
26 ///
27 /// Absent for the positional form `@ann(v)`, which names the
28 /// declaration's `value` member.
29 pub name: Option<String>,
30 /// The argument expression.
31 pub value: Id<ConstExprNode>,
32}
33
34/// One annotation applied to a node.
35#[derive(Debug, Clone, PartialEq, Eq)]
36pub struct AppliedAnnotation {
37 /// The name as written, without the `@`.
38 ///
39 /// Kept alongside the reference: the declaration may arrive after
40 /// the use, and a diagnostic has to name the annotation either way.
41 pub name: String,
42 /// The declaration this applies, once it is known.
43 pub definition: Ref<AnnotationDefNode>,
44 /// Arguments in the order they were written.
45 pub arguments: Vec<AppliedArgument>,
46}