Skip to content

Commit

Permalink
Fix UnaryOp size.
Browse files Browse the repository at this point in the history
  • Loading branch information
ltfish committed Dec 11, 2024
1 parent a61add9 commit 7459e1d
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions ailment/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,12 +462,19 @@ class UnaryOp(Op):
)

def __init__(
self, idx: int | None, op: str, operand: Expression, variable=None, variable_offset: int | None = None, **kwargs
self,
idx: int | None,
op: str,
operand: Expression,
variable=None,
variable_offset: int | None = None,
bits=None,
**kwargs,
):
super().__init__(idx, (operand.depth if isinstance(operand, Expression) else 0) + 1, op, **kwargs)

self.operand = operand
self.bits = operand.bits
self.bits = operand.bits if bits is None else bits
self.variable = variable
self.variable_offset = variable_offset

Expand Down Expand Up @@ -506,7 +513,7 @@ def replace(self, old_expr, new_expr):
r, replaced_operand = self.operand.replace(old_expr, new_expr)

if r:
return True, UnaryOp(self.idx, self.op, replaced_operand, **self.tags)
return True, UnaryOp(self.idx, self.op, replaced_operand, bits=self.bits, **self.tags)
else:
return False, self

Expand All @@ -520,7 +527,13 @@ def size(self):

def copy(self) -> UnaryOp:
return UnaryOp(
self.idx, self.op, self.operand, variable=self.variable, variable_offset=self.variable_offset, **self.tags
self.idx,
self.op,
self.operand,
variable=self.variable,
variable_offset=self.variable_offset,
bits=self.bits,
**self.tags,
)

def has_atom(self, atom, identity=True):
Expand Down

0 comments on commit 7459e1d

Please sign in to comment.