Clone if/else arms before swapping them

This fixes a bug where some of the later transforms didn't run on the
swapped arms.
bzip2
Graham 5 years ago
parent ec53c74aaa
commit e202c4fcb9
  1. 12
      deob-ast/src/main/java/dev/openrs2/deob/ast/transform/IfElseTransformer.java

@ -20,13 +20,13 @@ public final class IfElseTransformer extends Transformer {
private static Statement getIf(Statement stmt) { private static Statement getIf(Statement stmt) {
if (stmt.isIfStmt()) { if (stmt.isIfStmt()) {
return stmt; return stmt.clone();
} else if (stmt.isBlockStmt()) { } else if (stmt.isBlockStmt()) {
NodeList<Statement> stmts = stmt.asBlockStmt().getStatements(); NodeList<Statement> stmts = stmt.asBlockStmt().getStatements();
if (stmts.size() == 1) { if (stmts.size() == 1) {
Statement head = stmts.get(0); Statement head = stmts.get(0);
if (head.isIfStmt()) { if (head.isIfStmt()) {
return head; return head.clone();
} }
} }
} }
@ -42,8 +42,8 @@ public final class IfElseTransformer extends Transformer {
var thenStmt = stmt.getThenStmt(); var thenStmt = stmt.getThenStmt();
if (isIf(thenStmt) && !isIf(elseStmt)) { if (isIf(thenStmt) && !isIf(elseStmt)) {
stmt.setCondition(ExprUtils.not(condition)); stmt.setCondition(ExprUtils.not(condition));
stmt.setThenStmt(elseStmt); stmt.setThenStmt(elseStmt.clone());
stmt.setElseStmt(thenStmt); stmt.setElseStmt(thenStmt.clone());
} else if (!isIf(thenStmt) && isIf(elseStmt)) { } else if (!isIf(thenStmt) && isIf(elseStmt)) {
/* /*
* Don't consider any more conditions for swapping the * Don't consider any more conditions for swapping the
@ -59,8 +59,8 @@ public final class IfElseTransformer extends Transformer {
*/ */
if (ExprUtils.isNot(condition)) { if (ExprUtils.isNot(condition)) {
stmt.setCondition(ExprUtils.not(condition)); stmt.setCondition(ExprUtils.not(condition));
stmt.setThenStmt(elseStmt); stmt.setThenStmt(elseStmt.clone());
stmt.setElseStmt(thenStmt); stmt.setElseStmt(thenStmt.clone());
} }
}); });
}); });

Loading…
Cancel
Save