Convert createLong to an extension method on Long

Signed-off-by: Graham <gpe@openrs2.dev>
bzip2
Graham 5 years ago
parent cf3474c016
commit 9de55399f5
  1. 4
      deob-ast/src/main/java/dev/openrs2/deob/ast/transform/BitMaskTransformer.kt
  2. 4
      deob-ast/src/main/java/dev/openrs2/deob/ast/transform/ComplementTransformer.kt
  3. 8
      deob-ast/src/main/java/dev/openrs2/deob/ast/util/ExprUtils.kt

@ -5,8 +5,8 @@ import com.github.javaparser.ast.expr.BinaryExpr
import com.github.javaparser.ast.expr.IntegerLiteralExpr import com.github.javaparser.ast.expr.IntegerLiteralExpr
import dev.openrs2.deob.ast.util.checkedAsInt import dev.openrs2.deob.ast.util.checkedAsInt
import dev.openrs2.deob.ast.util.checkedAsLong 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.isIntegerOrLongLiteral
import dev.openrs2.deob.ast.util.toLongLiteralExpr
import dev.openrs2.deob.ast.util.walk import dev.openrs2.deob.ast.util.walk
class BitMaskTransformer : Transformer() { class BitMaskTransformer : Transformer() {
@ -52,7 +52,7 @@ class BitMaskTransformer : Transformer() {
else -> error("Invalid shiftOp") else -> error("Invalid shiftOp")
} }
maskExpr = createLong(mask) maskExpr = mask.toLongLiteralExpr()
} }
expr.replace(BinaryExpr(BinaryExpr(argExpr.clone(), shamtExpr.clone(), shiftOp), maskExpr, bitwiseOp)) expr.replace(BinaryExpr(BinaryExpr(argExpr.clone(), shamtExpr.clone(), shiftOp), maskExpr, bitwiseOp))

@ -7,8 +7,8 @@ import com.github.javaparser.ast.expr.IntegerLiteralExpr
import com.github.javaparser.ast.expr.UnaryExpr import com.github.javaparser.ast.expr.UnaryExpr
import dev.openrs2.deob.ast.util.checkedAsInt import dev.openrs2.deob.ast.util.checkedAsInt
import dev.openrs2.deob.ast.util.checkedAsLong 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.isIntegerOrLongLiteral
import dev.openrs2.deob.ast.util.toLongLiteralExpr
import dev.openrs2.deob.ast.util.walk import dev.openrs2.deob.ast.util.walk
class ComplementTransformer : Transformer() { class ComplementTransformer : Transformer() {
@ -55,7 +55,7 @@ class ComplementTransformer : Transformer() {
return when { return when {
isUnaryExpr -> asUnaryExpr().expression isUnaryExpr -> asUnaryExpr().expression
isIntegerLiteralExpr -> IntegerLiteralExpr(asIntegerLiteralExpr().checkedAsInt().inv().toString()) isIntegerLiteralExpr -> IntegerLiteralExpr(asIntegerLiteralExpr().checkedAsInt().inv().toString())
isLongLiteralExpr -> createLong(asLongLiteralExpr().checkedAsLong().inv()) isLongLiteralExpr -> asLongLiteralExpr().checkedAsLong().inv().toLongLiteralExpr()
else -> throw IllegalArgumentException() else -> throw IllegalArgumentException()
} }
} }

@ -27,8 +27,8 @@ fun Expression.isIntegerOrLongLiteral(): Boolean {
return isIntegerLiteralExpr || isLongLiteralExpr return isIntegerLiteralExpr || isLongLiteralExpr
} }
fun createLong(value: Long): LongLiteralExpr { fun Long.toLongLiteralExpr(): LongLiteralExpr {
return LongLiteralExpr(value.toString() + "L") return LongLiteralExpr(this.toString() + "L")
} }
fun Expression.negate(): Expression { fun Expression.negate(): Expression {
@ -42,8 +42,8 @@ fun Expression.negate(): Expression {
} }
} else if (isLongLiteralExpr) { } else if (isLongLiteralExpr) {
when (val n = asLongLiteralExpr().asNumber()) { when (val n = asLongLiteralExpr().asNumber()) {
LongLiteralExpr.MAX_63_BIT_UNSIGNED_VALUE_AS_BIG_INTEGER -> createLong(Long.MIN_VALUE) LongLiteralExpr.MAX_63_BIT_UNSIGNED_VALUE_AS_BIG_INTEGER -> Long.MIN_VALUE.toLongLiteralExpr()
is Long -> createLong(-n) is Long -> (-n).toLongLiteralExpr()
else -> error("Invalid LongLiteralExpr type") else -> error("Invalid LongLiteralExpr type")
} }
} else { } else {

Loading…
Cancel
Save