Don't swap for loop conditions where both sides have a side effect

bzip2
Graham 5 years ago
parent d8c3f4e31c
commit 2e1db9f0b1
  1. 5
      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.Node
import com.github.javaparser.ast.expr.BinaryExpr import com.github.javaparser.ast.expr.BinaryExpr
import com.github.javaparser.ast.stmt.ForStmt import com.github.javaparser.ast.stmt.ForStmt
import dev.openrs2.deob.ast.util.hasSideEffects
import dev.openrs2.deob.ast.util.walk import dev.openrs2.deob.ast.util.walk
class ForLoopConditionTransformer : Transformer() { class ForLoopConditionTransformer : Transformer() {
@ -15,6 +16,10 @@ class ForLoopConditionTransformer : Transformer() {
} }
val expr = compare.asBinaryExpr() val expr = compare.asBinaryExpr()
if (expr.left.hasSideEffects() && expr.right.hasSideEffects()) {
return@ifPresent
}
val flipped = when (expr.operator) { val flipped = when (expr.operator) {
BinaryExpr.Operator.GREATER -> BinaryExpr.Operator.LESS BinaryExpr.Operator.GREATER -> BinaryExpr.Operator.LESS
BinaryExpr.Operator.GREATER_EQUALS -> BinaryExpr.Operator.LESS_EQUALS BinaryExpr.Operator.GREATER_EQUALS -> BinaryExpr.Operator.LESS_EQUALS

Loading…
Cancel
Save