Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change return type to UnaryType instead of UnaryOperationType #2124

Merged
merged 4 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions slither/slithir/operations/unary.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from slither.slithir.operations.lvalue import OperationWithLValue
from slither.slithir.utils.utils import is_valid_lvalue, is_valid_rvalue
from slither.slithir.exceptions import SlithIRError
from slither.core.expressions.unary_operation import UnaryOperationType
from slither.core.variables.local_variable import LocalVariable
from slither.slithir.variables.constant import Constant
from slither.slithir.variables.local_variable import LocalIRVariable
Expand Down Expand Up @@ -35,7 +34,7 @@ def __init__(
self,
result: Union[TemporaryVariableSSA, TemporaryVariable],
variable: Union[Constant, LocalIRVariable, LocalVariable],
operation_type: UnaryOperationType,
operation_type: UnaryType,
) -> None:
assert is_valid_rvalue(variable)
assert is_valid_lvalue(result)
Expand All @@ -53,7 +52,7 @@ def rvalue(self) -> Union[Constant, LocalVariable]:
return self._variable

@property
def type(self) -> UnaryOperationType:
def type(self) -> UnaryType:
return self._type

@property
Expand Down
10 changes: 9 additions & 1 deletion slither/visitors/slithir/expression_to_slithir.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
Member,
TypeConversion,
Unary,
UnaryType,
Unpack,
Return,
SolidityCall,
Expand Down Expand Up @@ -109,6 +110,13 @@ def set_val(expression: Expression, val: Any) -> None:
BinaryOperationType.OROR: BinaryType.OROR,
}


_unary_to_unary = {
UnaryOperationType.BANG: UnaryType.BANG,
UnaryOperationType.TILD: UnaryType.TILD,
}


_signed_to_unsigned = {
BinaryOperationType.DIVISION_SIGNED: BinaryType.DIVISION,
BinaryOperationType.MODULO_SIGNED: BinaryType.MODULO,
Expand Down Expand Up @@ -585,7 +593,7 @@ def _post_unary_operation(self, expression: UnaryOperation) -> None:
operation: Operation
if expression.type in [UnaryOperationType.BANG, UnaryOperationType.TILD]:
lvalue = TemporaryVariable(self._node)
operation = Unary(lvalue, value, expression.type)
operation = Unary(lvalue, value, _unary_to_unary[expression.type])
operation.set_expression(expression)
self._result.append(operation)
set_val(expression, lvalue)
Expand Down