From b642bb17c65470a9bb399e45afd6df6a6e85566a Mon Sep 17 00:00:00 2001 From: Graham Date: Thu, 6 Aug 2020 22:57:32 +0100 Subject: [PATCH] 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 --- .../openrs2/deob/ast/transform/AddSubTransformer.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/AddSubTransformer.kt b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/AddSubTransformer.kt index 19f2f21aae..2ee4dc2642 100644 --- a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/AddSubTransformer.kt +++ b/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.Expression 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.UnaryExpr import dev.openrs2.deob.ast.Library @@ -48,6 +49,15 @@ class AddSubTransformer : Transformer() { 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 })