rapx/analysis/core/alias_analysis/default/
value.rs

1use crate::analysis::core::alias_analysis::default::types::TyKind;
2use rustc_data_structures::fx::FxHashMap;
3
4#[derive(Debug, Clone)]
5pub struct Value {
6    pub index: usize, // node index; this could be the field of a value.
7    pub local: usize, // This is the real local; The range of index is generally larger than local.
8    pub need_drop: bool,
9    pub may_drop: bool,
10    pub kind: TyKind,
11    pub father: usize,
12    pub field_id: usize, // the field id of its father node.
13    pub birth: isize,
14    pub fields: FxHashMap<usize, usize>,
15}
16
17impl Value {
18    pub fn new(index: usize, local: usize, need_drop: bool, may_drop: bool) -> Self {
19        Value {
20            index,
21            local,
22            need_drop,
23            father: local,
24            field_id: usize::MAX,
25            birth: 0,
26            may_drop,
27            kind: TyKind::Adt,
28            fields: FxHashMap::default(),
29        }
30    }
31
32    pub fn drop(&mut self) {
33        self.birth = -1;
34    }
35
36    pub fn is_alive(&self) -> bool {
37        self.birth > -1
38    }
39
40    pub fn is_tuple(&self) -> bool {
41        self.kind == TyKind::Tuple
42    }
43
44    pub fn is_ptr(&self) -> bool {
45        self.kind == TyKind::RawPtr || self.kind == TyKind::Ref
46    }
47
48    pub fn is_ref(&self) -> bool {
49        self.kind == TyKind::Ref
50    }
51
52    pub fn is_corner_case(&self) -> bool {
53        self.kind == TyKind::CornerCase
54    }
55}