Open-source multiplayer game server compatible with the RuneScape client
https://www.openrs2.org/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.3 KiB
40 lines
1.3 KiB
package org.openrs2.deob.ast.transform
|
|
|
|
import com.github.javaparser.ast.CompilationUnit
|
|
import com.github.javaparser.ast.expr.UnaryExpr
|
|
import com.github.javaparser.ast.stmt.ExpressionStmt
|
|
import com.github.javaparser.ast.stmt.ForStmt
|
|
import org.openrs2.deob.ast.Library
|
|
import org.openrs2.deob.ast.LibraryGroup
|
|
import org.openrs2.deob.ast.util.walk
|
|
import javax.inject.Singleton
|
|
|
|
@Singleton
|
|
public class IncrementTransformer : Transformer() {
|
|
override fun transformUnit(group: LibraryGroup, library: Library, unit: CompilationUnit) {
|
|
unit.walk { stmt: ExpressionStmt ->
|
|
val expr = stmt.expression
|
|
if (expr !is UnaryExpr) {
|
|
return@walk
|
|
}
|
|
|
|
expr.operator = expr.operator.toPostfix()
|
|
}
|
|
|
|
unit.walk { stmt: ForStmt ->
|
|
for (expr in stmt.update) {
|
|
if (expr !is UnaryExpr) {
|
|
continue
|
|
}
|
|
|
|
expr.operator = expr.operator.toPostfix()
|
|
}
|
|
}
|
|
}
|
|
|
|
private fun UnaryExpr.Operator.toPostfix() = when (this) {
|
|
UnaryExpr.Operator.PREFIX_INCREMENT -> UnaryExpr.Operator.POSTFIX_INCREMENT
|
|
UnaryExpr.Operator.PREFIX_DECREMENT -> UnaryExpr.Operator.POSTFIX_DECREMENT
|
|
else -> this
|
|
}
|
|
}
|
|
|