Skip to content

Commit 501af66

Browse files
committed
Improve PossibleValueSet.__eq__
1 parent 06ee9fe commit 501af66

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

python/variable.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,11 +365,19 @@ def __contains__(self, other):
365365
return NotImplemented
366366

367367
def __eq__(self, other):
368+
# Allow comparing some value types to an int
368369
if self.type in [RegisterValueType.ConstantValue, RegisterValueType.ConstantPointerValue
369370
] and isinstance(other, int):
370371
return self.value == other
372+
373+
# Otherwise just allow comparing to other PossibleValueSet instances
371374
if not isinstance(other, self.__class__):
372375
return NotImplemented
376+
377+
# If the PVS type isn't the same, they're not equal
378+
if self.type != other.type:
379+
return False
380+
373381
if self.type in [RegisterValueType.ConstantValue, RegisterValueType.ConstantPointerValue]:
374382
return self.value == other.value
375383
elif self.type == RegisterValueType.StackFrameOffset:
@@ -380,10 +388,9 @@ def __eq__(self, other):
380388
return self.ranges == other.ranges
381389
elif self.type in [RegisterValueType.InSetOfValues, RegisterValueType.NotInSetOfValues]:
382390
return self.values == other.values
383-
elif self.type == RegisterValueType.UndeterminedValue and hasattr(other, '_type'):
384-
return self.type == other.type
385-
else:
386-
return self == other
391+
elif self.type == RegisterValueType.UndeterminedValue:
392+
return True # UndeterminedValue is always equal to itself
393+
return NotImplemented
387394

388395
def __ne__(self, other):
389396
if not isinstance(other, self.__class__):

0 commit comments

Comments
 (0)