Using LabelNode instead of bare Label

This commit is contained in:
Andrey Breslav
2013-10-06 12:32:38 +04:00
parent 8aad18e849
commit 21e0dabf87
2 changed files with 7 additions and 7 deletions
+5 -5
View File
@@ -13,7 +13,7 @@ import org.objectweb.asm.tree.MultiANewArrayInsnNode
import org.objectweb.asm.tree.TypeInsnNode
import org.objectweb.asm.tree.JumpInsnNode
import org.objectweb.asm.tree.IincInsnNode
import org.objectweb.asm.Label
import org.objectweb.asm.tree.LabelNode
class UnsupportedByteCodeException(message: String) : RuntimeException(message)
@@ -39,7 +39,7 @@ trait Eval {
}
trait Control {
fun jump(label: Label)
fun jump(label: LabelNode)
fun returnValue(value: Value)
fun throwException(value: Value)
@@ -103,7 +103,7 @@ class SingleInstructionInterpreter(private val eval: Eval, private val control:
else -> throw UnsupportedByteCodeException("Illegal LDC constant " + cst)
}
}
JSR -> LabelValue((insn as JumpInsnNode).label.getLabel())
JSR -> LabelValue((insn as JumpInsnNode).label)
GETSTATIC -> eval.getStaticField((insn as FieldInsnNode).desc)
NEW -> eval.newInstance(Type.getType((insn as TypeInsnNode).desc))
else -> throw UnsupportedByteCodeException("$insn")
@@ -141,7 +141,7 @@ class SingleInstructionInterpreter(private val eval: Eval, private val control:
F2D -> double(value.float.toDouble())
IFEQ, IFNE, IFLT, IFGE, IFGT, IFLE, IFNULL, IFNONNULL -> {
val label = (insn as JumpInsnNode).label.getLabel()
val label = (insn as JumpInsnNode).label
when (insn.getOpcode()) {
IFEQ -> if (value.int == 0) control.jump(label)
IFNE -> if (value.int != 0) control.jump(label)
@@ -290,7 +290,7 @@ class SingleInstructionInterpreter(private val eval: Eval, private val control:
}
IF_ICMPEQ, IF_ICMPNE, IF_ICMPLT, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ACMPEQ, IF_ACMPNE -> {
val label = (insn as JumpInsnNode).label.getLabel()
val label = (insn as JumpInsnNode).label
when (insn.getOpcode()) {
IF_ICMPEQ -> if (value1.int == value2.int) control.jump(label)
IF_ICMPNE -> if (value1.int != value2.int) control.jump(label)
+2 -2
View File
@@ -1,7 +1,7 @@
package org.jetbrains.eval4j
import org.objectweb.asm.Type
import org.objectweb.asm.Label
import org.objectweb.asm.tree.LabelNode
trait Value : org.objectweb.asm.tree.analysis.Value {
val asmType: Type
@@ -31,7 +31,7 @@ class FloatValue(val value: Float): AbstractValue(Type.FLOAT_TYPE)
class DoubleValue(val value: Double): AbstractValue(Type.DOUBLE_TYPE)
class ObjectValue(val value: Any?, asmType: Type): AbstractValue(asmType)
class LabelValue(val value: Label): AbstractValue(Type.VOID_TYPE)
class LabelValue(val value: LabelNode): AbstractValue(Type.VOID_TYPE)
fun boolean(v: Boolean) = IntValue(if (v) 1 else 0, Type.BOOLEAN_TYPE)
fun byte(v: Byte) = IntValue(v.toInt(), Type.BYTE_TYPE)