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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
use crate::spirv;

use super::{storage::Token, Constant, Decoration};

#[derive(Clone, Debug)]
pub struct StructMember {
    pub token: Token<Type>,
    pub decorations: Vec<Decoration>,
}

impl StructMember {
    pub fn new(ty: Token<Type>) -> Self {
        StructMember {
            token: ty,
            decorations: Vec::new(),
        }
    }
}

include!("autogen_types.rs");

impl PartialEq for Type {
    fn eq(&self, other: &Self) -> bool {
        use Type::*;
        match (self, other) {
            (Bool, Bool) => true,
            (
                Int {
                    width: sw,
                    signedness: ss,
                },
                Int {
                    width: ow,
                    signedness: os,
                },
            ) => sw == ow && ss == os,
            (Float { width: s }, Float { width: o }) => s == o,
            (
                Vector {
                    component_type: st,
                    component_count: sc,
                },
                Vector {
                    component_type: ot,
                    component_count: oc,
                },
            ) => st == ot && sc == oc,
            (
                Matrix {
                    column_type: st,
                    column_count: sc,
                },
                Matrix {
                    column_type: ot,
                    column_count: oc,
                },
            ) => st == ot && sc == oc,
            _ => false,
        }
    }
}

impl Type {
    pub fn is_numerical_type(&self) -> bool {
        matches!(self, Type::Int { .. } | Type::Float { .. })
    }

    pub fn is_scalar_type(&self) -> bool {
        match self {
            Type::Bool => true,
            _ => self.is_numerical_type(),
        }
    }

    pub fn is_aggregate_type(&self) -> bool {
        matches!(
            self,
            Type::Struct { .. } | Type::Array { .. } | Type::RuntimeArray { .. }
        )
    }

    pub fn is_composite_type(&self) -> bool {
        match self {
            Type::Vector { .. } | Type::Matrix { .. } => true,
            _ => self.is_aggregate_type(),
        }
    }
}