From eb2841dda83b6eb5bea0b70ada039b7e2a69d622 Mon Sep 17 00:00:00 2001 From: Jordan Wiens Date: Mon, 7 Dec 2020 21:52:07 -0500 Subject: initial support for contains operator on possible value sets --- python/function.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'python') diff --git a/python/function.py b/python/function.py index fbcb09fb..e98f7191 100644 --- a/python/function.py +++ b/python/function.py @@ -268,6 +268,11 @@ class ValueRange(object): return NotImplemented return self.start == other.start and self.end == other.end and self.step == other.step + def __contains__(self, other): + if not isinstance(other, numbers.Integral): + return NotImplemented + return other in range(self._start, self._end, self._step) + @property def start(self): """ """ @@ -379,6 +384,27 @@ class PossibleValueSet(object): return "" return "" + def __contains__(self, other): + if self.type in [RegisterValueType.ConstantValue, RegisterValueType.ConstantPointerValue] and isinstance(other, numbers.Integral): + return self.value == other + if self.type in [RegisterValueType.ConstantValue, RegisterValueType.ConstantPointerValue] and hasattr(other, "value"): + return self.value == other.value + if not isinstance(other, numbers.Integral): + return NotImplemented + #Initial implementation only checks numbers, no set logic + if self.type == RegisterValueType.StackFrameOffset: + return NotImplemented + if self.type in [RegisterValueType.SignedRangeValue, RegisterValueType.UnsignedRangeValue]: + for rng in self.ranges: + if other in rng: + return True + return False + if self.type == RegisterValueType.InSetOfValues: + return other in self.values + if self.type == RegisterValueType.NotInSetOfValues: + return not other in self.values + return NotImplemented + def __eq__(self, other): if self.type in [RegisterValueType.ConstantValue, RegisterValueType.ConstantPointerValue] and isinstance(other, numbers.Integral): return self.value == other -- cgit v1.3.1