Remove traversal argument from walk extension method

bzip2
Graham 5 years ago
parent 54aec42f90
commit 5487a74eb8
  1. 3
      deob-ast/src/main/java/dev/openrs2/deob/ast/transform/AddSubTransformer.kt
  2. 3
      deob-ast/src/main/java/dev/openrs2/deob/ast/transform/BinaryExprOrderTransformer.kt
  3. 3
      deob-ast/src/main/java/dev/openrs2/deob/ast/transform/BitMaskTransformer.kt
  4. 3
      deob-ast/src/main/java/dev/openrs2/deob/ast/transform/ComplementTransformer.kt
  5. 3
      deob-ast/src/main/java/dev/openrs2/deob/ast/transform/EncloseTransformer.kt
  6. 3
      deob-ast/src/main/java/dev/openrs2/deob/ast/transform/ForLoopConditionTransformer.kt
  7. 3
      deob-ast/src/main/java/dev/openrs2/deob/ast/transform/IdentityTransformer.kt
  8. 7
      deob-ast/src/main/java/dev/openrs2/deob/ast/transform/IfElseTransformer.kt
  9. 5
      deob-ast/src/main/java/dev/openrs2/deob/ast/transform/IncrementTransformer.kt
  10. 3
      deob-ast/src/main/java/dev/openrs2/deob/ast/transform/NegativeLiteralTransformer.kt
  11. 3
      deob-ast/src/main/java/dev/openrs2/deob/ast/transform/NewInstanceTransformer.kt
  12. 3
      deob-ast/src/main/java/dev/openrs2/deob/ast/transform/TernaryTransformer.kt
  13. 3
      deob-ast/src/main/java/dev/openrs2/deob/ast/transform/UnencloseTransformer.kt
  14. 3
      deob-ast/src/main/java/dev/openrs2/deob/ast/transform/ValueOfTransformer.kt
  15. 5
      deob-ast/src/main/java/dev/openrs2/deob/ast/util/NodeUtils.kt

@ -1,7 +1,6 @@
package dev.openrs2.deob.ast.transform
import com.github.javaparser.ast.CompilationUnit
import com.github.javaparser.ast.Node
import com.github.javaparser.ast.expr.BinaryExpr
import com.github.javaparser.ast.expr.Expression
import com.github.javaparser.ast.expr.UnaryExpr
@ -12,7 +11,7 @@ import dev.openrs2.deob.ast.util.walk
class AddSubTransformer : Transformer() {
override fun transform(unit: CompilationUnit) {
unit.walk(Node.TreeTraversal.POSTORDER) { expr: BinaryExpr ->
unit.walk { expr: BinaryExpr ->
val op = expr.operator
val left = expr.left
val right = expr.right

@ -1,14 +1,13 @@
package dev.openrs2.deob.ast.transform
import com.github.javaparser.ast.CompilationUnit
import com.github.javaparser.ast.Node
import com.github.javaparser.ast.expr.BinaryExpr
import dev.openrs2.deob.ast.util.isString
import dev.openrs2.deob.ast.util.walk
class BinaryExprOrderTransformer : Transformer() {
override fun transform(unit: CompilationUnit) {
unit.walk(Node.TreeTraversal.POSTORDER) { expr: BinaryExpr ->
unit.walk { expr: BinaryExpr ->
val op = flip(expr.operator) ?: return@walk
val type = expr.calculateResolvedType()

@ -1,7 +1,6 @@
package dev.openrs2.deob.ast.transform
import com.github.javaparser.ast.CompilationUnit
import com.github.javaparser.ast.Node
import com.github.javaparser.ast.expr.BinaryExpr
import com.github.javaparser.ast.expr.IntegerLiteralExpr
import dev.openrs2.deob.ast.util.createLong
@ -10,7 +9,7 @@ import dev.openrs2.deob.ast.util.walk
class BitMaskTransformer : Transformer() {
override fun transform(unit: CompilationUnit) {
unit.walk(Node.TreeTraversal.POSTORDER) { expr: BinaryExpr ->
unit.walk { expr: BinaryExpr ->
val shiftOp = expr.operator
val left = expr.left
val shamtExpr = expr.right

@ -1,7 +1,6 @@
package dev.openrs2.deob.ast.transform
import com.github.javaparser.ast.CompilationUnit
import com.github.javaparser.ast.Node
import com.github.javaparser.ast.expr.BinaryExpr
import com.github.javaparser.ast.expr.Expression
import com.github.javaparser.ast.expr.IntegerLiteralExpr
@ -12,7 +11,7 @@ import dev.openrs2.deob.ast.util.walk
class ComplementTransformer : Transformer() {
override fun transform(unit: CompilationUnit) {
unit.walk(Node.TreeTraversal.POSTORDER) { expr: BinaryExpr ->
unit.walk { expr: BinaryExpr ->
val op = complement(expr.operator) ?: return@walk
val left = expr.left

@ -1,7 +1,6 @@
package dev.openrs2.deob.ast.transform
import com.github.javaparser.ast.CompilationUnit
import com.github.javaparser.ast.Node
import com.github.javaparser.ast.expr.BinaryExpr
import com.github.javaparser.ast.expr.EnclosedExpr
import com.github.javaparser.ast.expr.Expression
@ -73,7 +72,7 @@ class EncloseTransformer : Transformer() {
}
override fun transform(unit: CompilationUnit) {
unit.walk(Node.TreeTraversal.POSTORDER) { expr: Expression ->
unit.walk { expr: Expression ->
when {
expr.isArrayAccessExpr -> {
val accessExpr = expr.asArrayAccessExpr()

@ -1,7 +1,6 @@
package dev.openrs2.deob.ast.transform
import com.github.javaparser.ast.CompilationUnit
import com.github.javaparser.ast.Node
import com.github.javaparser.ast.expr.BinaryExpr
import com.github.javaparser.ast.stmt.ForStmt
import dev.openrs2.deob.ast.util.hasSideEffects
@ -9,7 +8,7 @@ import dev.openrs2.deob.ast.util.walk
class ForLoopConditionTransformer : Transformer() {
override fun transform(unit: CompilationUnit) {
unit.walk(Node.TreeTraversal.POSTORDER) { stmt: ForStmt ->
unit.walk { stmt: ForStmt ->
stmt.compare.ifPresent { compare ->
if (!compare.isBinaryExpr) {
return@ifPresent

@ -1,7 +1,6 @@
package dev.openrs2.deob.ast.transform
import com.github.javaparser.ast.CompilationUnit
import com.github.javaparser.ast.Node
import com.github.javaparser.ast.expr.BinaryExpr
import com.github.javaparser.ast.expr.Expression
import com.github.javaparser.ast.expr.UnaryExpr
@ -9,7 +8,7 @@ import dev.openrs2.deob.ast.util.walk
class IdentityTransformer : Transformer() {
override fun transform(unit: CompilationUnit) {
unit.walk(Node.TreeTraversal.POSTORDER) { expr: BinaryExpr ->
unit.walk { expr: BinaryExpr ->
@Suppress("NON_EXHAUSTIVE_WHEN")
when (expr.operator) {
BinaryExpr.Operator.PLUS -> {

@ -1,7 +1,6 @@
package dev.openrs2.deob.ast.transform
import com.github.javaparser.ast.CompilationUnit
import com.github.javaparser.ast.Node
import com.github.javaparser.ast.stmt.BlockStmt
import com.github.javaparser.ast.stmt.IfStmt
import com.github.javaparser.ast.stmt.Statement
@ -11,7 +10,7 @@ import dev.openrs2.deob.ast.util.walk
class IfElseTransformer : Transformer() {
override fun transform(unit: CompilationUnit) {
unit.walk(Node.TreeTraversal.POSTORDER) { stmt: IfStmt ->
unit.walk { stmt: IfStmt ->
stmt.elseStmt.ifPresent { elseStmt: Statement ->
val condition = stmt.condition
val thenStmt = stmt.thenStmt
@ -44,7 +43,7 @@ class IfElseTransformer : Transformer() {
}
}
unit.walk(Node.TreeTraversal.POSTORDER) { stmt: IfStmt ->
unit.walk { stmt: IfStmt ->
stmt.elseStmt.ifPresent { elseStmt ->
if (isIf(elseStmt)) {
stmt.setElseStmt(getIf(elseStmt))
@ -74,7 +73,7 @@ class IfElseTransformer : Transformer() {
* throw ...;
* }
*/
unit.walk(Node.TreeTraversal.POSTORDER) { stmt: IfStmt ->
unit.walk { stmt: IfStmt ->
stmt.elseStmt.ifPresent { elseStmt ->
// match
if (!elseStmt.isBlockStmt) {

@ -1,7 +1,6 @@
package dev.openrs2.deob.ast.transform
import com.github.javaparser.ast.CompilationUnit
import com.github.javaparser.ast.Node
import com.github.javaparser.ast.expr.UnaryExpr
import com.github.javaparser.ast.stmt.ExpressionStmt
import com.github.javaparser.ast.stmt.ForStmt
@ -9,7 +8,7 @@ import dev.openrs2.deob.ast.util.walk
class IncrementTransformer : Transformer() {
override fun transform(unit: CompilationUnit) {
unit.walk(Node.TreeTraversal.POSTORDER) { stmt: ExpressionStmt ->
unit.walk { stmt: ExpressionStmt ->
if (!stmt.expression.isUnaryExpr) {
return@walk
}
@ -18,7 +17,7 @@ class IncrementTransformer : Transformer() {
unaryExpr.operator = prefixToPostfix(unaryExpr.operator)
}
unit.walk(Node.TreeTraversal.POSTORDER) { stmt: ForStmt ->
unit.walk { stmt: ForStmt ->
for (expr in stmt.update) {
if (!expr.isUnaryExpr) {
continue

@ -1,7 +1,6 @@
package dev.openrs2.deob.ast.transform
import com.github.javaparser.ast.CompilationUnit
import com.github.javaparser.ast.Node
import com.github.javaparser.ast.expr.UnaryExpr
import dev.openrs2.deob.ast.util.isIntegerOrLongLiteral
import dev.openrs2.deob.ast.util.negate
@ -9,7 +8,7 @@ import dev.openrs2.deob.ast.util.walk
class NegativeLiteralTransformer : Transformer() {
override fun transform(unit: CompilationUnit) {
unit.walk(Node.TreeTraversal.POSTORDER) { expr: UnaryExpr ->
unit.walk { expr: UnaryExpr ->
val operand = expr.expression
if (!operand.isIntegerOrLongLiteral()) {
return@walk

@ -1,13 +1,12 @@
package dev.openrs2.deob.ast.transform
import com.github.javaparser.ast.CompilationUnit
import com.github.javaparser.ast.Node
import com.github.javaparser.ast.expr.MethodCallExpr
import dev.openrs2.deob.ast.util.walk
class NewInstanceTransformer : Transformer() {
override fun transform(unit: CompilationUnit) {
unit.walk(Node.TreeTraversal.POSTORDER) { expr: MethodCallExpr ->
unit.walk { expr: MethodCallExpr ->
if (expr.nameAsString != "newInstance") {
return@walk
}

@ -1,7 +1,6 @@
package dev.openrs2.deob.ast.transform
import com.github.javaparser.ast.CompilationUnit
import com.github.javaparser.ast.Node
import com.github.javaparser.ast.expr.ConditionalExpr
import dev.openrs2.deob.ast.util.countNots
import dev.openrs2.deob.ast.util.not
@ -9,7 +8,7 @@ import dev.openrs2.deob.ast.util.walk
class TernaryTransformer : Transformer() {
override fun transform(unit: CompilationUnit) {
unit.walk(Node.TreeTraversal.POSTORDER) { expr: ConditionalExpr ->
unit.walk { expr: ConditionalExpr ->
val condition = expr.condition
val notCondition = condition.not()
if (notCondition.countNots() >= condition.countNots()) {

@ -1,13 +1,12 @@
package dev.openrs2.deob.ast.transform
import com.github.javaparser.ast.CompilationUnit
import com.github.javaparser.ast.Node
import com.github.javaparser.ast.expr.EnclosedExpr
import dev.openrs2.deob.ast.util.walk
class UnencloseTransformer : Transformer() {
override fun transform(unit: CompilationUnit) {
unit.walk(Node.TreeTraversal.POSTORDER) { expr: EnclosedExpr ->
unit.walk { expr: EnclosedExpr ->
expr.replace(expr.inner.clone())
}
}

@ -1,7 +1,6 @@
package dev.openrs2.deob.ast.transform
import com.github.javaparser.ast.CompilationUnit
import com.github.javaparser.ast.Node
import com.github.javaparser.ast.expr.MethodCallExpr
import com.github.javaparser.ast.expr.ObjectCreationExpr
import com.github.javaparser.ast.expr.TypeExpr
@ -9,7 +8,7 @@ import dev.openrs2.deob.ast.util.walk
class ValueOfTransformer : Transformer() {
override fun transform(unit: CompilationUnit) {
unit.walk(Node.TreeTraversal.POSTORDER) { expr: ObjectCreationExpr ->
unit.walk { expr: ObjectCreationExpr ->
if (expr.type.isBoxedType) {
expr.replace(MethodCallExpr(TypeExpr(expr.type), "valueOf", expr.arguments))
}

@ -1,10 +1,9 @@
package dev.openrs2.deob.ast.util
import com.github.javaparser.ast.Node
import com.github.javaparser.ast.Node.TreeTraversal
inline fun <reified T : Node> Node.walk(traversal: TreeTraversal, crossinline consumer: (T) -> Unit) {
this.walk(traversal) {
inline fun <reified T : Node> Node.walk(crossinline consumer: (T) -> Unit) {
this.walk(Node.TreeTraversal.POSTORDER) {
if (it is T) {
consumer(it)
}

Loading…
Cancel
Save