Add sequential property to AbstractInsnNode

master
Graham 5 years ago
parent 25a6953644
commit 7bb1218b42
  1. 3
      asm/src/main/java/dev/openrs2/asm/InsnListUtils.kt
  2. 24
      asm/src/main/java/dev/openrs2/asm/InsnNodeUtils.kt

@ -4,7 +4,6 @@ import org.objectweb.asm.tree.AbstractInsnNode
import org.objectweb.asm.tree.InsnList import org.objectweb.asm.tree.InsnList
private val ANY_INSN = { _: AbstractInsnNode -> true } private val ANY_INSN = { _: AbstractInsnNode -> true }
private val JUMP_OR_LABEL = listOf(AbstractInsnNode.LABEL, AbstractInsnNode.JUMP_INSN)
fun getExpression( fun getExpression(
last: AbstractInsnNode, last: AbstractInsnNode,
@ -27,7 +26,7 @@ fun getExpression(
} }
insn = insn.previous insn = insn.previous
} while (insn != null && insn.type !in JUMP_OR_LABEL && filter(insn)) } while (insn != null && insn.sequential && filter(insn))
return null return null
} }

@ -4,7 +4,11 @@ import org.objectweb.asm.Opcodes
import org.objectweb.asm.tree.AbstractInsnNode import org.objectweb.asm.tree.AbstractInsnNode
import org.objectweb.asm.tree.InsnNode import org.objectweb.asm.tree.InsnNode
import org.objectweb.asm.tree.IntInsnNode import org.objectweb.asm.tree.IntInsnNode
import org.objectweb.asm.tree.JumpInsnNode
import org.objectweb.asm.tree.LabelNode
import org.objectweb.asm.tree.LdcInsnNode import org.objectweb.asm.tree.LdcInsnNode
import org.objectweb.asm.tree.LookupSwitchInsnNode
import org.objectweb.asm.tree.TableSwitchInsnNode
import org.objectweb.asm.util.Textifier import org.objectweb.asm.util.Textifier
import org.objectweb.asm.util.TraceMethodVisitor import org.objectweb.asm.util.TraceMethodVisitor
import java.io.PrintWriter import java.io.PrintWriter
@ -184,6 +188,17 @@ private val IMPURE_OPCODES = setOf(
Opcodes.IFNONNULL Opcodes.IFNONNULL
) )
private val THROW_RETURN_OPCODES = listOf(
Opcodes.IRETURN,
Opcodes.LRETURN,
Opcodes.FRETURN,
Opcodes.DRETURN,
Opcodes.ARETURN,
Opcodes.RETURN,
Opcodes.RET,
Opcodes.ATHROW
)
val AbstractInsnNode.nextReal: AbstractInsnNode? val AbstractInsnNode.nextReal: AbstractInsnNode?
get() { get() {
var insn = next var insn = next
@ -249,6 +264,15 @@ val AbstractInsnNode.intConstant: Int?
} }
} }
val AbstractInsnNode.sequential: Boolean
get() = when (this) {
is LabelNode -> false
is JumpInsnNode -> false
is TableSwitchInsnNode -> false
is LookupSwitchInsnNode -> false
else -> opcode !in THROW_RETURN_OPCODES
}
val AbstractInsnNode.pure: Boolean val AbstractInsnNode.pure: Boolean
get() = when (opcode) { get() = when (opcode) {
in PURE_OPCODES -> true in PURE_OPCODES -> true

Loading…
Cancel
Save