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
use crate::{constant::Constant, context::Context, irtype::Type};
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
pub struct Pointer(pub generational_arena::Index);
#[doc(hidden)]
#[derive(Clone)]
pub struct PointerContent {
pub ty: Type,
pub is_mutable: bool,
pub initializer: Option<Constant>,
}
impl Pointer {
pub fn new(
context: &mut Context,
ty: Type,
is_mutable: bool,
initializer: Option<Constant>,
) -> Self {
let content = PointerContent {
ty,
is_mutable,
initializer,
};
Pointer(context.pointers.insert(content))
}
pub fn get_type<'a>(&self, context: &'a Context) -> &'a Type {
&context.pointers[self.0].ty
}
pub fn is_struct_ptr(&self, context: &Context) -> bool {
matches!(&context.pointers[self.0].ty, Type::Struct(_))
}
}