Skip to main content

oxilean_kernel/abstract_interp/
signdomain_traits.rs

1//! # SignDomain - Trait Implementations
2//!
3//! This module contains trait implementations for `SignDomain`.
4//!
5//! ## Implemented Traits
6//!
7//! - `AbstractDomain`
8//!
9//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)
10
11use super::functions::AbstractDomain;
12use super::types::SignDomain;
13
14impl AbstractDomain for SignDomain {
15    fn join(&self, other: &Self) -> Self {
16        use SignDomain::*;
17        if self == other {
18            return *self;
19        }
20        match (self, other) {
21            (Bottom, x) | (x, Bottom) => *x,
22            (Top, _) | (_, Top) => Top,
23            (Neg, Zero) | (Zero, Neg) => NonPos,
24            (Pos, Zero) | (Zero, Pos) => NonNeg,
25            (Neg, Pos) | (Pos, Neg) => Nonzero,
26            (Neg, NonPos) | (NonPos, Neg) => NonPos,
27            (Pos, NonNeg) | (NonNeg, Pos) => NonNeg,
28            (Zero, Nonzero) | (Nonzero, Zero) => Top,
29            (NonPos, Pos) | (Pos, NonPos) => Top,
30            (NonNeg, Neg) | (Neg, NonNeg) => Top,
31            (NonPos, NonNeg) | (NonNeg, NonPos) => Top,
32            (NonPos, Nonzero) | (Nonzero, NonPos) => Top,
33            (NonNeg, Nonzero) | (Nonzero, NonNeg) => Top,
34            (Zero, NonPos) | (NonPos, Zero) => NonPos,
35            (Zero, NonNeg) | (NonNeg, Zero) => NonNeg,
36            _ => Top,
37        }
38    }
39    fn meet(&self, other: &Self) -> Self {
40        use SignDomain::*;
41        if self == other {
42            return *self;
43        }
44        match (self, other) {
45            (Top, x) | (x, Top) => *x,
46            (Bottom, _) | (_, Bottom) => Bottom,
47            (NonNeg, NonPos) | (NonPos, NonNeg) => Zero,
48            (NonNeg, Nonzero) | (Nonzero, NonNeg) => Pos,
49            (NonPos, Nonzero) | (Nonzero, NonPos) => Neg,
50            (NonNeg, Neg) | (Neg, NonNeg) => Bottom,
51            (NonPos, Pos) | (Pos, NonPos) => Bottom,
52            (Nonzero, Zero) | (Zero, Nonzero) => Bottom,
53            (NonNeg, Pos) | (Pos, NonNeg) => Pos,
54            (NonNeg, Zero) | (Zero, NonNeg) => Zero,
55            (NonPos, Neg) | (Neg, NonPos) => Neg,
56            (NonPos, Zero) | (Zero, NonPos) => Zero,
57            _ => Bottom,
58        }
59    }
60    fn is_bottom(&self) -> bool {
61        matches!(self, SignDomain::Bottom)
62    }
63    fn is_top(&self) -> bool {
64        matches!(self, SignDomain::Top)
65    }
66    fn leq(&self, other: &Self) -> bool {
67        self.join(other) == *other
68    }
69}