Skip to content

Support multi-way And/Or conditions #3

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
40 changes: 39 additions & 1 deletion decompiler/decompiler/constraint_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,45 @@ def visit(self, expression):
return value

def visit_BoolRef(self, expr):
if expr.num_args() == 2:
if expr.num_args() > 2 and expr.decl().name() in ('and', 'or'):
# Not sure if we need to do DeMorgan's or something here, so bail out
if self._in_not:
raise NotImplementedError()
operation = f"{expr.decl()!s}"
visited = [self.visit(expr.arg(i)) for i in range(expr.num_args())]

tokens = []
tokens.append(
InstructionTextToken(
InstructionTextTokenType.TextToken,
"("
)
)
for idx, item in enumerate(visited):
if idx != 0:
tokens.append(InstructionTextToken(
InstructionTextTokenType.TextToken,
f" {operation} "
))
tokens.append(InstructionTextToken(
InstructionTextTokenType.TextToken,
"("
))
tokens.extend(item)
tokens.append(InstructionTextToken(
InstructionTextTokenType.TextToken,
")"
))
tokens.append(
InstructionTextToken(
InstructionTextTokenType.TextToken,
")"
)
)

return tokens

elif expr.num_args() == 2:
if self._in_not:
operation = negations.get(f"{expr.decl()!s}")
if operation is None:
Expand Down