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
79 ModuleDeclaration,
81 InterfaceDeclaration,
83 StructDeclaration,
85 UnionDeclaration,
87 EnumDeclaration,
89 TypedefDeclaration,
91 ConstDeclaration,
93 ExceptionDeclaration,
95
96 SourceFile,
98 Include,
100 Pragma,
102 Error,
104 Eof,
106}
107
108impl ElementType for IdlElementType {
109 type Role = UniversalElementRole;
110
111 fn role(&self) -> Self::Role {
112 match self {
113 Self::SourceFile => UniversalElementRole::Root,
114 Self::ModuleDeclaration | Self::InterfaceDeclaration | Self::StructDeclaration | Self::UnionDeclaration | Self::EnumDeclaration | Self::TypedefDeclaration | Self::ConstDeclaration | Self::ExceptionDeclaration => {
115 UniversalElementRole::Definition
116 }
117 Self::Module | Self::Interface | Self::Struct | Self::Union | Self::Enum => UniversalElementRole::Container,
118 _ => UniversalElementRole::None,
119 }
120 }
121}
122
123impl From<crate::lexer::token_type::IdlTokenType> for IdlElementType {
124 fn from(token: crate::lexer::token_type::IdlTokenType) -> Self {
125 match token {
126 crate::lexer::token_type::IdlTokenType::Void => Self::Void,
127 crate::lexer::token_type::IdlTokenType::Boolean => Self::Boolean,
128 crate::lexer::token_type::IdlTokenType::Byte => Self::Byte,
129 crate::lexer::token_type::IdlTokenType::Octet => Self::Octet,
130 crate::lexer::token_type::IdlTokenType::Short => Self::Short,
131 crate::lexer::token_type::IdlTokenType::UnsignedShort => Self::UnsignedShort,
132 crate::lexer::token_type::IdlTokenType::Long => Self::Long,
133 crate::lexer::token_type::IdlTokenType::UnsignedLong => Self::UnsignedLong,
134 crate::lexer::token_type::IdlTokenType::LongLong => Self::LongLong,
135 crate::lexer::token_type::IdlTokenType::UnsignedLongLong => Self::UnsignedLongLong,
136 crate::lexer::token_type::IdlTokenType::Float => Self::Float,
137 crate::lexer::token_type::IdlTokenType::Double => Self::Double,
138 crate::lexer::token_type::IdlTokenType::LongDouble => Self::LongDouble,
139 crate::lexer::token_type::IdlTokenType::Char => Self::Char,
140 crate::lexer::token_type::IdlTokenType::WChar => Self::WChar,
141 crate::lexer::token_type::IdlTokenType::String => Self::String,
142 crate::lexer::token_type::IdlTokenType::WString => Self::WString,
143 crate::lexer::token_type::IdlTokenType::Any => Self::Any,
144 crate::lexer::token_type::IdlTokenType::Object => Self::Object,
145 crate::lexer::token_type::IdlTokenType::ValueBase => Self::ValueBase,
146 crate::lexer::token_type::IdlTokenType::Struct => Self::Struct,
147 crate::lexer::token_type::IdlTokenType::Union => Self::Union,
148 crate::lexer::token_type::IdlTokenType::Enum => Self::Enum,
149 crate::lexer::token_type::IdlTokenType::Interface => Self::Interface,
150 crate::lexer::token_type::IdlTokenType::Module => Self::Module,
151 crate::lexer::token_type::IdlTokenType::Exception => Self::Exception,
152 crate::lexer::token_type::IdlTokenType::Typedef => Self::Typedef,
153 crate::lexer::token_type::IdlTokenType::Sequence => Self::Sequence,
154 crate::lexer::token_type::IdlTokenType::Array => Self::Array,
155 crate::lexer::token_type::IdlTokenType::Fixed => Self::Fixed,
156 crate::lexer::token_type::IdlTokenType::Const => Self::Const,
157 crate::lexer::token_type::IdlTokenType::Attribute => Self::Attribute,
158 crate::lexer::token_type::IdlTokenType::Error => Self::Error,
159 crate::lexer::token_type::IdlTokenType::Eof => Self::Eof,
160 _ => Self::Error,
161 }
162 }
163}