Skip to content

Commit

Permalink
Remove Base._rename (#568)
Browse files Browse the repository at this point in the history
  • Loading branch information
twizmwazin authored Nov 5, 2024
1 parent 8c9cfac commit 7b71286
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
22 changes: 10 additions & 12 deletions claripy/ast/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,16 +506,6 @@ def identical(self, other: Self, strict=False) -> bool:
and self.annotations == other.annotations
)

#
# Collapsing and simplification
#

def _rename(self, new_name: str) -> Self:
if self.op not in {"BVS", "BoolS", "FPS"}:
raise ClaripyOperationError("rename is only supported on leaf nodes")
new_args = (new_name,) + self.args[1:]
return self.make_like(self.op, new_args, length=self.length, variables=frozenset((new_name,)))

#
# Annotations
#
Expand Down Expand Up @@ -895,9 +885,17 @@ def canonicalize(self, var_map=None, counter=None) -> Self:
var_map = {} if var_map is None else var_map

for v in self.leaf_asts():
if v.hash() not in var_map and v.op in {"BVS", "BoolS", "FPS"}:
if v.hash() not in var_map and v.is_leaf():
new_name = "canonical_%d" % next(counter)
var_map[v.hash()] = v._rename(new_name)
match v.op:
case "BVS":
var_map[v.hash()] = claripy.BVS(new_name, v.length, explicit_name=True)
case "BoolS":
var_map[v.hash()] = claripy.BoolS(new_name, explicit_name=True)
case "FPS":
var_map[v.hash()] = claripy.FPS(new_name, v.args[1], explicit_name=True)
case "StringS":
var_map[v.hash()] = claripy.StringS(new_name, explicit_name=True)

return var_map, counter, claripy.replace_dict(self, var_map)

Expand Down
5 changes: 0 additions & 5 deletions tests/test_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,11 +366,6 @@ def test_depth_repr(self):
"<BV32 LShR(LShR(LShR(LShR(LShR(<...>, <...>), 0xa), 0xa), 0xa), 0xa)>",
)

def test_rename(self):
x1 = claripy.BVS("x", 32)
x2 = x1._rename("y")
assert x2.variables == frozenset(("y",))

def test_canonical(self):
x1 = claripy.BVS("x", 32)
b1 = claripy.BoolS("b")
Expand Down

0 comments on commit 7b71286

Please sign in to comment.