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
use tblgen::record::Record;

#[derive(Debug, Clone, Copy)]
pub struct Type {
    optional: bool,
    variadic: bool,
    variadic_of_variadic: bool,
}

impl Type {
    pub fn new(record: Record) -> Self {
        Self {
            optional: record.subclass_of("Optional"),
            variadic: record.subclass_of("Variadic"),
            variadic_of_variadic: record.subclass_of("VariadicOfVariadic"),
        }
    }

    pub fn is_optional(&self) -> bool {
        self.optional
    }

    pub fn is_variadic(&self) -> bool {
        self.variadic
    }

    // TODO Support variadic-of-variadic.
    #[allow(unused)]
    pub fn is_variadic_of_variadic(&self) -> bool {
        self.variadic_of_variadic
    }

    pub fn is_unfixed(&self) -> bool {
        self.is_variadic() || self.is_optional()
    }
}