Move literals to the RHS of an add/sub expression

The BinaryExprTransformer deals with this to an extent. However, it
requires multiple passes to do so. Adding support to AddSubTransformer
allows it to be done in a single pass.

Signed-off-by: Graham <gpe@openrs2.dev>
Graham 4 years ago
parent c4df34102a
commit b642bb17c6
  1. 10
      deob-ast/src/main/java/dev/openrs2/deob/ast/transform/AddSubTransformer.kt

@ -4,6 +4,7 @@ import com.github.javaparser.ast.CompilationUnit
import com.github.javaparser.ast.expr.BinaryExpr import com.github.javaparser.ast.expr.BinaryExpr
import com.github.javaparser.ast.expr.Expression import com.github.javaparser.ast.expr.Expression
import com.github.javaparser.ast.expr.IntegerLiteralExpr import com.github.javaparser.ast.expr.IntegerLiteralExpr
import com.github.javaparser.ast.expr.LiteralExpr
import com.github.javaparser.ast.expr.LongLiteralExpr import com.github.javaparser.ast.expr.LongLiteralExpr
import com.github.javaparser.ast.expr.UnaryExpr import com.github.javaparser.ast.expr.UnaryExpr
import dev.openrs2.deob.ast.Library import dev.openrs2.deob.ast.Library
@ -48,6 +49,15 @@ class AddSubTransformer : Transformer() {
return@Comparator -1 return@Comparator -1
} }
// push literals to the right
val aLiteral = a is LiteralExpr
val bLiteral = b is LiteralExpr
if (aLiteral && !bLiteral) {
return@Comparator 1
} else if (!aLiteral && bLiteral) {
return@Comparator -1
}
return@Comparator 0 return@Comparator 0
}) })

Loading…
Cancel
Save