Skip to main content

xidl_parser/hir/
const_dcl.rs

1use super::*;
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Serialize, Deserialize, Clone)]
5pub struct ConstDcl {
6    pub annotations: Vec<Annotation>,
7    pub ty: ConstType,
8    pub ident: String,
9    pub value: ConstExpr,
10}
11
12#[derive(Debug, Serialize, Deserialize, Clone)]
13pub enum ConstType {
14    IntegerType(IntegerType),
15    FloatingPtType,
16    FixedPtConstType,
17    CharType,
18    WideCharType,
19    BooleanType,
20    OctetType,
21    StringType(StringType),
22    WideStringType(WideStringType),
23    ScopedName(ScopedName),
24    SequenceType(SequenceType),
25}
26
27impl From<crate::typed_ast::ConstDcl> for ConstDcl {
28    fn from(value: crate::typed_ast::ConstDcl) -> Self {
29        Self {
30            annotations: expand_annotations(value.annotations),
31            ty: value.ty.into(),
32            ident: value.ident.0,
33            value: value.value.into(),
34        }
35    }
36}
37
38impl From<crate::typed_ast::ConstType> for ConstType {
39    fn from(value: crate::typed_ast::ConstType) -> Self {
40        match value {
41            crate::typed_ast::ConstType::IntegerType(integer_type) => {
42                Self::IntegerType(integer_type.into())
43            }
44            crate::typed_ast::ConstType::FloatingPtType(_) => Self::FloatingPtType,
45            crate::typed_ast::ConstType::FixedPtConstType(_) => Self::FixedPtConstType,
46            crate::typed_ast::ConstType::CharType(_) => Self::CharType,
47            crate::typed_ast::ConstType::WideCharType(_) => Self::WideCharType,
48            crate::typed_ast::ConstType::BooleanType(_) => Self::BooleanType,
49            crate::typed_ast::ConstType::OctetType(_) => Self::OctetType,
50            crate::typed_ast::ConstType::StringType(string_type) => {
51                Self::StringType(string_type.into())
52            }
53            crate::typed_ast::ConstType::WideStringType(wide_string_type) => {
54                Self::WideStringType(wide_string_type.into())
55            }
56            crate::typed_ast::ConstType::ScopedName(scoped_name) => {
57                Self::ScopedName(scoped_name.into())
58            }
59            crate::typed_ast::ConstType::SequenceType(sequence_type) => {
60                Self::SequenceType(sequence_type.into())
61            }
62        }
63    }
64}