|
|
@ -1,10 +1,15 @@ |
|
|
|
package dev.openrs2.deob.ast.util |
|
|
|
package dev.openrs2.deob.ast.util |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.github.javaparser.ast.expr.ArrayAccessExpr |
|
|
|
import com.github.javaparser.ast.expr.BinaryExpr |
|
|
|
import com.github.javaparser.ast.expr.BinaryExpr |
|
|
|
import com.github.javaparser.ast.expr.BooleanLiteralExpr |
|
|
|
import com.github.javaparser.ast.expr.BooleanLiteralExpr |
|
|
|
import com.github.javaparser.ast.expr.Expression |
|
|
|
import com.github.javaparser.ast.expr.Expression |
|
|
|
|
|
|
|
import com.github.javaparser.ast.expr.FieldAccessExpr |
|
|
|
import com.github.javaparser.ast.expr.IntegerLiteralExpr |
|
|
|
import com.github.javaparser.ast.expr.IntegerLiteralExpr |
|
|
|
|
|
|
|
import com.github.javaparser.ast.expr.LiteralExpr |
|
|
|
import com.github.javaparser.ast.expr.LongLiteralExpr |
|
|
|
import com.github.javaparser.ast.expr.LongLiteralExpr |
|
|
|
|
|
|
|
import com.github.javaparser.ast.expr.NameExpr |
|
|
|
|
|
|
|
import com.github.javaparser.ast.expr.ThisExpr |
|
|
|
import com.github.javaparser.ast.expr.UnaryExpr |
|
|
|
import com.github.javaparser.ast.expr.UnaryExpr |
|
|
|
|
|
|
|
|
|
|
|
fun IntegerLiteralExpr.checkedAsInt(): Int { |
|
|
|
fun IntegerLiteralExpr.checkedAsInt(): Int { |
|
|
@ -116,23 +121,15 @@ fun Expression.countNots(): Int { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun Expression.hasSideEffects(): Boolean { |
|
|
|
fun Expression.hasSideEffects(): Boolean { |
|
|
|
if (isLiteralExpr || isNameExpr || isThisExpr) { |
|
|
|
return when (this) { |
|
|
|
return false |
|
|
|
is LiteralExpr, is NameExpr, is ThisExpr -> false |
|
|
|
} else if (isUnaryExpr) { |
|
|
|
is UnaryExpr -> expression.hasSideEffects() |
|
|
|
return asUnaryExpr().expression.hasSideEffects() |
|
|
|
is BinaryExpr -> left.hasSideEffects() || right.hasSideEffects() |
|
|
|
} else if (isBinaryExpr) { |
|
|
|
is ArrayAccessExpr -> name.hasSideEffects() || index.hasSideEffects() |
|
|
|
val binary = asBinaryExpr() |
|
|
|
is FieldAccessExpr -> scope.hasSideEffects() |
|
|
|
return binary.left.hasSideEffects() || binary.right.hasSideEffects() |
|
|
|
|
|
|
|
} else if (isArrayAccessExpr) { |
|
|
|
|
|
|
|
val access = asArrayAccessExpr() |
|
|
|
|
|
|
|
return access.name.hasSideEffects() || access.index.hasSideEffects() |
|
|
|
|
|
|
|
} else if (isFieldAccessExpr) { |
|
|
|
|
|
|
|
val access = asFieldAccessExpr() |
|
|
|
|
|
|
|
return access.scope.hasSideEffects() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO(gpe): more cases |
|
|
|
// TODO(gpe): more cases |
|
|
|
return true |
|
|
|
else -> true |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun BinaryExpr.Operator.flip(): BinaryExpr.Operator? { |
|
|
|
fun BinaryExpr.Operator.flip(): BinaryExpr.Operator? { |
|
|
|