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