Convert createLong to an extension method on Long

Signed-off-by: Graham <gpe@openrs2.dev>
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 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))

@ -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()
}
}

@ -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 {

Loading…
Cancel
Save