From 9de55399f5bbd4e326c8bea474ae039c41379da7 Mon Sep 17 00:00:00 2001 From: Graham Date: Sat, 2 May 2020 23:51:21 +0100 Subject: [PATCH] Convert createLong to an extension method on Long Signed-off-by: Graham --- .../dev/openrs2/deob/ast/transform/BitMaskTransformer.kt | 4 ++-- .../openrs2/deob/ast/transform/ComplementTransformer.kt | 4 ++-- .../src/main/java/dev/openrs2/deob/ast/util/ExprUtils.kt | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/BitMaskTransformer.kt b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/BitMaskTransformer.kt index 09c6de8832..0da3ae86aa 100644 --- a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/BitMaskTransformer.kt +++ b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/BitMaskTransformer.kt @@ -5,8 +5,8 @@ import com.github.javaparser.ast.expr.BinaryExpr import com.github.javaparser.ast.expr.IntegerLiteralExpr import dev.openrs2.deob.ast.util.checkedAsInt import dev.openrs2.deob.ast.util.checkedAsLong -import dev.openrs2.deob.ast.util.createLong import dev.openrs2.deob.ast.util.isIntegerOrLongLiteral +import dev.openrs2.deob.ast.util.toLongLiteralExpr import dev.openrs2.deob.ast.util.walk class BitMaskTransformer : Transformer() { @@ -52,7 +52,7 @@ class BitMaskTransformer : Transformer() { else -> error("Invalid shiftOp") } - maskExpr = createLong(mask) + maskExpr = mask.toLongLiteralExpr() } expr.replace(BinaryExpr(BinaryExpr(argExpr.clone(), shamtExpr.clone(), shiftOp), maskExpr, bitwiseOp)) diff --git a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/ComplementTransformer.kt b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/ComplementTransformer.kt index b3ef7f7857..2d54fa1f69 100644 --- a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/ComplementTransformer.kt +++ b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/ComplementTransformer.kt @@ -7,8 +7,8 @@ import com.github.javaparser.ast.expr.IntegerLiteralExpr import com.github.javaparser.ast.expr.UnaryExpr import dev.openrs2.deob.ast.util.checkedAsInt import dev.openrs2.deob.ast.util.checkedAsLong -import dev.openrs2.deob.ast.util.createLong import dev.openrs2.deob.ast.util.isIntegerOrLongLiteral +import dev.openrs2.deob.ast.util.toLongLiteralExpr import dev.openrs2.deob.ast.util.walk class ComplementTransformer : Transformer() { @@ -55,7 +55,7 @@ class ComplementTransformer : Transformer() { return when { isUnaryExpr -> asUnaryExpr().expression isIntegerLiteralExpr -> IntegerLiteralExpr(asIntegerLiteralExpr().checkedAsInt().inv().toString()) - isLongLiteralExpr -> createLong(asLongLiteralExpr().checkedAsLong().inv()) + isLongLiteralExpr -> asLongLiteralExpr().checkedAsLong().inv().toLongLiteralExpr() else -> throw IllegalArgumentException() } } diff --git a/deob-ast/src/main/java/dev/openrs2/deob/ast/util/ExprUtils.kt b/deob-ast/src/main/java/dev/openrs2/deob/ast/util/ExprUtils.kt index 2017170938..7087940efa 100644 --- a/deob-ast/src/main/java/dev/openrs2/deob/ast/util/ExprUtils.kt +++ b/deob-ast/src/main/java/dev/openrs2/deob/ast/util/ExprUtils.kt @@ -27,8 +27,8 @@ fun Expression.isIntegerOrLongLiteral(): Boolean { return isIntegerLiteralExpr || isLongLiteralExpr } -fun createLong(value: Long): LongLiteralExpr { - return LongLiteralExpr(value.toString() + "L") +fun Long.toLongLiteralExpr(): LongLiteralExpr { + return LongLiteralExpr(this.toString() + "L") } fun Expression.negate(): Expression { @@ -42,8 +42,8 @@ fun Expression.negate(): Expression { } } else if (isLongLiteralExpr) { when (val n = asLongLiteralExpr().asNumber()) { - LongLiteralExpr.MAX_63_BIT_UNSIGNED_VALUE_AS_BIG_INTEGER -> createLong(Long.MIN_VALUE) - is Long -> createLong(-n) + LongLiteralExpr.MAX_63_BIT_UNSIGNED_VALUE_AS_BIG_INTEGER -> Long.MIN_VALUE.toLongLiteralExpr() + is Long -> (-n).toLongLiteralExpr() else -> error("Invalid LongLiteralExpr type") } } else {