From 2e1db9f0b1e60652b5b1c9700918f9830211bc7e Mon Sep 17 00:00:00 2001 From: Graham Date: Wed, 29 Jan 2020 22:37:58 +0000 Subject: [PATCH] Don't swap for loop conditions where both sides have a side effect --- .../deob/ast/transform/ForLoopConditionTransformer.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/ForLoopConditionTransformer.kt b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/ForLoopConditionTransformer.kt index 51fd3338..1cfb2f62 100644 --- a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/ForLoopConditionTransformer.kt +++ b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/ForLoopConditionTransformer.kt @@ -4,6 +4,7 @@ import com.github.javaparser.ast.CompilationUnit import com.github.javaparser.ast.Node import com.github.javaparser.ast.expr.BinaryExpr import com.github.javaparser.ast.stmt.ForStmt +import dev.openrs2.deob.ast.util.hasSideEffects import dev.openrs2.deob.ast.util.walk class ForLoopConditionTransformer : Transformer() { @@ -15,6 +16,10 @@ class ForLoopConditionTransformer : Transformer() { } val expr = compare.asBinaryExpr() + if (expr.left.hasSideEffects() && expr.right.hasSideEffects()) { + return@ifPresent + } + val flipped = when (expr.operator) { BinaryExpr.Operator.GREATER -> BinaryExpr.Operator.LESS BinaryExpr.Operator.GREATER_EQUALS -> BinaryExpr.Operator.LESS_EQUALS