forked from openrs2/openrs2
parent
ba66c47799
commit
38a3e752f9
@ -1,26 +0,0 @@ |
|||||||
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.ExprUtils; |
|
||||||
import dev.openrs2.deob.ast.util.NodeUtils; |
|
||||||
|
|
||||||
public final class NegativeLiteralTransformer extends Transformer { |
|
||||||
@Override |
|
||||||
public void transform(CompilationUnit unit) { |
|
||||||
NodeUtils.walk(unit, Node.TreeTraversal.POSTORDER, UnaryExpr.class, expr -> { |
|
||||||
var operand = expr.getExpression(); |
|
||||||
if (!ExprUtils.isIntegerOrLongLiteral(operand)) { |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
var op = expr.getOperator(); |
|
||||||
if (op == UnaryExpr.Operator.PLUS) { |
|
||||||
expr.replace(operand); |
|
||||||
} else if (op == UnaryExpr.Operator.MINUS) { |
|
||||||
expr.replace(ExprUtils.negate(operand)); |
|
||||||
} |
|
||||||
}); |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,28 @@ |
|||||||
|
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.ExprUtils |
||||||
|
import dev.openrs2.deob.ast.util.NodeUtils |
||||||
|
|
||||||
|
class NegativeLiteralTransformer : Transformer() { |
||||||
|
override fun transform(unit: CompilationUnit) { |
||||||
|
NodeUtils.walk(unit, Node.TreeTraversal.POSTORDER, UnaryExpr::class.java) { expr -> |
||||||
|
val operand = expr.expression |
||||||
|
if (!ExprUtils.isIntegerOrLongLiteral(operand)) { |
||||||
|
return@walk |
||||||
|
} |
||||||
|
|
||||||
|
@Suppress("NON_EXHAUSTIVE_WHEN") |
||||||
|
when (expr.operator) { |
||||||
|
UnaryExpr.Operator.PLUS -> { |
||||||
|
expr.replace(operand) |
||||||
|
} |
||||||
|
UnaryExpr.Operator.MINUS -> { |
||||||
|
expr.replace(ExprUtils.negate(operand)) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue