Struct cwe_checker_lib::abstract_domain::Interval
source · pub struct Interval {
pub start: Bitvector,
pub end: Bitvector,
pub stride: u64,
}
Expand description
A strided interval of values with a fixed byte size.
The interval bounds are interpreted as signed integers,
i.e. self.start
is not allowed to be greater than self.end
as signed integers.
The values represented by the interval are start, start + stride, start + 2*stride, ... , end
.
The following invariants have to hold for a correct interval instance:
end - start % stride == 0
- if
start == end
, then the stride should always be set to zero.
Fields§
§start: Bitvector
The start of the interval. The bound is included in the represented interval.
end: Bitvector
The end of the interval. The bound is included in the represented interval.
stride: u64
The stride.
Implementations§
source§impl Interval
impl Interval
sourcepub fn new(start: Bitvector, end: Bitvector, stride: u64) -> Interval
pub fn new(start: Bitvector, end: Bitvector, stride: u64) -> Interval
Construct a new interval.
Both start
and end
of the interval are inclusive,
i.e. contained in the represented interval.
The function automatically rounds down end
(if necessary)
so that it is contained in the same residue class as the start value modulo the stride.
If the stride is 0 then end
will be set to start
.
sourcepub fn is_top(&self) -> bool
pub fn is_top(&self) -> bool
Returns true if all values representable by bitvectors of the corresponding length are contained in the interval.
sourcepub fn signed_merge(&self, other: &Interval) -> Interval
pub fn signed_merge(&self, other: &Interval) -> Interval
Merge two intervals interpreting both as intervals of signed integers.
sourcepub fn signed_intersect(&self, other: &Interval) -> Result<Interval, Error>
pub fn signed_intersect(&self, other: &Interval) -> Result<Interval, Error>
Compute the intersection of two intervals as intervals of signed integers. Return an error if the intersection is empty.
sourcepub fn adjust_end_to_value_in_stride(&mut self)
pub fn adjust_end_to_value_in_stride(&mut self)
Round down self.end
to the nearest value such that self.end - self.start
is again divisible by the stride.
If afterwards self.start == self.end
holds then set the stride to 0.
sourcepub fn adjust_start_to_value_in_stride(&mut self)
pub fn adjust_start_to_value_in_stride(&mut self)
Round up self.start
to the nearest value such that self.end - self.start
is again divisible by the stride.
If afterwards self.start == self.end
holds then set the stride to 0.
sourcepub fn adjust_to_stride_and_remainder(
self,
stride: u64,
remainder: u64
) -> Result<Self, Error>
pub fn adjust_to_stride_and_remainder( self, stride: u64, remainder: u64 ) -> Result<Self, Error>
Change the given interval such that it only contains values with the given remainder modulo the given stride. This may round up the start of the interval and may round down the end of the interval. If the resulting interval is empty then an error is returned. This function ignores and replaces the previous stride of the interval.
For intervals with bytesize greater than 8 this function just returns the unmodified interval.
sourcepub fn zero_extend(self, width: ByteSize) -> Interval
pub fn zero_extend(self, width: ByteSize) -> Interval
Compute the interval represented if the byte size of the value is zero-extended.
sourcepub fn subpiece_higher(self, low_byte: ByteSize) -> Self
pub fn subpiece_higher(self, low_byte: ByteSize) -> Self
Truncate the bitvectors in the interval
by removing the least significant bytes lower than the low_byte
from them.
sourcepub fn subpiece_lower(self, size: ByteSize) -> Self
pub fn subpiece_lower(self, size: ByteSize) -> Self
Truncate the bitvectors in the interval to size
,
i.e. the most significant bytes (higher than size
) are removed from all values.
sourcepub fn subpiece(self, low_byte: ByteSize, size: ByteSize) -> Self
pub fn subpiece(self, low_byte: ByteSize, size: ByteSize) -> Self
Take a subpiece of the bitvectors.
sourcepub fn piece(&self, other: &Interval) -> Self
pub fn piece(&self, other: &Interval) -> Self
Piece two intervals together, where self
contains the most signifcant bytes
and other
contains the least significant bytes of the resulting values.
sourcepub fn int_2_comp(self) -> Self
pub fn int_2_comp(self) -> Self
Take the 2’s complement of values in the interval.
sourcepub fn bitwise_not(self) -> Self
pub fn bitwise_not(self) -> Self
Compute the bitwise negation of values in the interval. Only exact if there is exactly one value in the interval.
sourcepub fn add(&self, rhs: &Interval) -> Interval
pub fn add(&self, rhs: &Interval) -> Interval
Compute the interval of possible results
if one adds a value from self
to a value from rhs
.
sourcepub fn sub(&self, rhs: &Interval) -> Interval
pub fn sub(&self, rhs: &Interval) -> Interval
Compute the interval of possible results
if one subtracts a value in rhs
from a value in self
.
sourcepub fn signed_mul(&self, rhs: &Interval) -> Interval
pub fn signed_mul(&self, rhs: &Interval) -> Interval
Compute the interval of possible results
if one multiplies a value in self
with a value in rhs
.
Trait Implementations§
source§impl<'de> Deserialize<'de> for Interval
impl<'de> Deserialize<'de> for Interval
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl From<Interval> for IntervalDomain
impl From<Interval> for IntervalDomain
source§fn from(interval: Interval) -> IntervalDomain
fn from(interval: Interval) -> IntervalDomain
Generate an interval domain without widening hints.
source§impl PartialEq for Interval
impl PartialEq for Interval
impl Eq for Interval
impl StructuralEq for Interval
impl StructuralPartialEq for Interval
Auto Trait Implementations§
impl RefUnwindSafe for Interval
impl Send for Interval
impl Sync for Interval
impl Unpin for Interval
impl UnwindSafe for Interval
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.