From e202c4fcb9d945e632dc65b21cc3d7375f1d8da6 Mon Sep 17 00:00:00 2001 From: Graham Date: Sat, 24 Aug 2019 21:06:18 +0100 Subject: [PATCH] Clone if/else arms before swapping them This fixes a bug where some of the later transforms didn't run on the swapped arms. --- .../deob/ast/transform/IfElseTransformer.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/IfElseTransformer.java b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/IfElseTransformer.java index 9c6e651d..4c673402 100644 --- a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/IfElseTransformer.java +++ b/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) { if (stmt.isIfStmt()) { - return stmt; + return stmt.clone(); } else if (stmt.isBlockStmt()) { NodeList stmts = stmt.asBlockStmt().getStatements(); if (stmts.size() == 1) { Statement head = stmts.get(0); if (head.isIfStmt()) { - return head; + return head.clone(); } } } @@ -42,8 +42,8 @@ public final class IfElseTransformer extends Transformer { var thenStmt = stmt.getThenStmt(); if (isIf(thenStmt) && !isIf(elseStmt)) { stmt.setCondition(ExprUtils.not(condition)); - stmt.setThenStmt(elseStmt); - stmt.setElseStmt(thenStmt); + stmt.setThenStmt(elseStmt.clone()); + stmt.setElseStmt(thenStmt.clone()); } else if (!isIf(thenStmt) && isIf(elseStmt)) { /* * Don't consider any more conditions for swapping the @@ -59,8 +59,8 @@ public final class IfElseTransformer extends Transformer { */ if (ExprUtils.isNot(condition)) { stmt.setCondition(ExprUtils.not(condition)); - stmt.setThenStmt(elseStmt); - stmt.setElseStmt(thenStmt); + stmt.setThenStmt(elseStmt.clone()); + stmt.setElseStmt(thenStmt.clone()); } }); });