1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use super::*;
mod display;
mod iters;

/// The flags kind
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum FlagKind {
    /// `enumerate`, exclusive encoding number
    Enumerate,
    /// `flags`, juxtapose encoding number
    Flags,
}

/// a number that encodes special semantics
///
/// `enumerate Bit(8bits): Trait { FlagA, FlagB }`
///
/// `flags Bit(8bits): Trait { FlagA, FlagB }`
#[derive(Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct FlagDeclaration {
    /// The kind of the flag statement
    pub kind: FlagKind,
    /// The annotations of this flag.
    pub annotations: AnnotationNode,
    /// The name of the flag.
    pub name: IdentifierNode,
    /// `flags Flag(8bits)`
    pub layout: Option<ExpressionKind>,
    /// `flags Flag: Trait`
    pub implements: Option<ExpressionKind>,
    /// `flags Flag { FlagA, FlagB }`
    pub body: Vec<FlagTerm>,
    /// The range of the node.
    pub span: Range<u32>,
}

/// Valid terms in the flags statement
#[derive(Clone, PartialEq, Eq, Hash, From)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum FlagTerm {
    /// `@macro`
    Macro(ProceduralNode),
    /// `Name = number`
    Encode(EncodeDeclaration),
    /// `method() { }`
    Method(MethodDeclaration),
}

/// `Name = 0x00`
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct EncodeDeclaration {
    /// The documentation for this field.
    pub annotations: AnnotationNode,
    /// The identifier of the field.
    pub name: IdentifierNode,
    /// The value of the field if exists.
    pub value: Option<ExpressionKind>,
    /// The range of the node.
    pub span: Range<u32>,
}