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

Remove Base._rename #568

Merged
merged 1 commit into from
Nov 5, 2024
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
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