1use oak_core::{ElementType, UniversalElementRole};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6#[repr(u8)]
7pub enum IdlElementType {
8 Void,
10 Boolean,
12 Byte,
14 Octet,
16 Short,
18 UnsignedShort,
20 Long,
22 UnsignedLong,
24 LongLong,
26 UnsignedLongLong,
28 Float,
30 Double,
32 LongDouble,
34 Char,
36 WChar,
38 String,
40 WString,
42 Any,
44 Object,
46 ValueBase,
48
49 Struct,
51 Union,
53 Enum,
55 Interface,
57 Module,
59 Exception,
61 Typedef,
63 Sequence,
65 Array,
67 Fixed,
69
70 Attribute,
72 Operation,
74 Const,
76 ExceptionMember,
78 Field,
80 Param,
82
83 ModuleDeclaration,
85 InterfaceDeclaration,
87 StructDeclaration,
89 UnionDeclaration,
91 EnumDeclaration,
93 TypedefDeclaration,
95 ConstDeclaration,
97 ExceptionDeclaration,
99
100 SourceFile,
102 Include,
104 Pragma,
106 Error,
108 Eof,
110
111 Identifier,
113 StringLiteral,
115 NumberLiteral,
117 BooleanLiteral,
119 Readonly,
121 In,
123 Out,
125 Inout,
127}
128
129impl IdlElementType {
130 pub fn is_basic_type(&self) -> bool {
132 matches!(self,
133 Self::Void | Self::Boolean | Self::Byte | Self::Octet |
134 Self::Short | Self::UnsignedShort | Self::Long | Self::UnsignedLong |
135 Self::LongLong | Self::UnsignedLongLong | Self::Float | Self::Double |
136 Self::LongDouble | Self::Char | Self::WChar | Self::String |
137 Self::WString | Self::Any | Self::Object | Self::ValueBase
138 )
139 }
140}
141
142impl ElementType for IdlElementType {
143 type Role = UniversalElementRole;
144
145 fn role(&self) -> Self::Role {
146 match self {
147 Self::SourceFile => UniversalElementRole::Root,
148 Self::ModuleDeclaration | Self::InterfaceDeclaration | Self::StructDeclaration | Self::UnionDeclaration | Self::EnumDeclaration | Self::TypedefDeclaration | Self::ConstDeclaration | Self::ExceptionDeclaration => {
149 UniversalElementRole::Definition
150 }
151 Self::Module | Self::Interface | Self::Struct | Self::Union | Self::Enum => UniversalElementRole::Container,
152 _ => UniversalElementRole::None,
153 }
154 }
155}
156
157impl From<crate::lexer::token_type::IdlTokenType> for IdlElementType {
158 fn from(token: crate::lexer::token_type::IdlTokenType) -> Self {
159 match token {
160 crate::lexer::token_type::IdlTokenType::Void => Self::Void,
161 crate::lexer::token_type::IdlTokenType::Boolean => Self::Boolean,
162 crate::lexer::token_type::IdlTokenType::Byte => Self::Byte,
163 crate::lexer::token_type::IdlTokenType::Octet => Self::Octet,
164 crate::lexer::token_type::IdlTokenType::Short => Self::Short,
165 crate::lexer::token_type::IdlTokenType::UnsignedShort => Self::UnsignedShort,
166 crate::lexer::token_type::IdlTokenType::Long => Self::Long,
167 crate::lexer::token_type::IdlTokenType::UnsignedLong => Self::UnsignedLong,
168 crate::lexer::token_type::IdlTokenType::LongLong => Self::LongLong,
169 crate::lexer::token_type::IdlTokenType::UnsignedLongLong => Self::UnsignedLongLong,
170 crate::lexer::token_type::IdlTokenType::Float => Self::Float,
171 crate::lexer::token_type::IdlTokenType::Double => Self::Double,
172 crate::lexer::token_type::IdlTokenType::LongDouble => Self::LongDouble,
173 crate::lexer::token_type::IdlTokenType::Char => Self::Char,
174 crate::lexer::token_type::IdlTokenType::WChar => Self::WChar,
175 crate::lexer::token_type::IdlTokenType::String => Self::String,
176 crate::lexer::token_type::IdlTokenType::WString => Self::WString,
177 crate::lexer::token_type::IdlTokenType::Any => Self::Any,
178 crate::lexer::token_type::IdlTokenType::Object => Self::Object,
179 crate::lexer::token_type::IdlTokenType::ValueBase => Self::ValueBase,
180 crate::lexer::token_type::IdlTokenType::Struct => Self::Struct,
181 crate::lexer::token_type::IdlTokenType::Union => Self::Union,
182 crate::lexer::token_type::IdlTokenType::Enum => Self::Enum,
183 crate::lexer::token_type::IdlTokenType::Interface => Self::Interface,
184 crate::lexer::token_type::IdlTokenType::Module => Self::Module,
185 crate::lexer::token_type::IdlTokenType::Exception => Self::Exception,
186 crate::lexer::token_type::IdlTokenType::Typedef => Self::Typedef,
187 crate::lexer::token_type::IdlTokenType::Sequence => Self::Sequence,
188 crate::lexer::token_type::IdlTokenType::Array => Self::Array,
189 crate::lexer::token_type::IdlTokenType::Fixed => Self::Fixed,
190 crate::lexer::token_type::IdlTokenType::Const => Self::Const,
191 crate::lexer::token_type::IdlTokenType::Attribute => Self::Attribute,
192 crate::lexer::token_type::IdlTokenType::Readonly => Self::Readonly,
193 crate::lexer::token_type::IdlTokenType::In => Self::In,
194 crate::lexer::token_type::IdlTokenType::Out => Self::Out,
195 crate::lexer::token_type::IdlTokenType::Inout => Self::Inout,
196 crate::lexer::token_type::IdlTokenType::Identifier => Self::Identifier,
197 crate::lexer::token_type::IdlTokenType::StringLiteral => Self::StringLiteral,
198 crate::lexer::token_type::IdlTokenType::NumberLiteral => Self::NumberLiteral,
199 crate::lexer::token_type::IdlTokenType::BooleanLiteral => Self::BooleanLiteral,
200 crate::lexer::token_type::IdlTokenType::Error => Self::Error,
201 crate::lexer::token_type::IdlTokenType::Eof => Self::Eof,
202 _ => Self::Error,
203 }
204 }
205}