eval4j: cleanup 'public', property access syntax

This commit is contained in:
Dmitry Jemerov
2016-01-07 18:03:29 +01:00
parent 3870bd04b8
commit 951a313331
6 changed files with 38 additions and 38 deletions
+18 -18
View File
@@ -25,25 +25,25 @@ import org.jetbrains.org.objectweb.asm.tree.analysis.Interpreter
class UnsupportedByteCodeException(message: String) : RuntimeException(message)
public interface Eval {
public fun loadClass(classType: Type): Value
public fun loadString(str: String): Value
public fun newInstance(classType: Type): Value
public fun isInstanceOf(value: Value, targetType: Type): Boolean
interface Eval {
fun loadClass(classType: Type): Value
fun loadString(str: String): Value
fun newInstance(classType: Type): Value
fun isInstanceOf(value: Value, targetType: Type): Boolean
public fun newArray(arrayType: Type, size: Int): Value
public fun newMultiDimensionalArray(arrayType: Type, dimensionSizes: List<Int>): Value
public fun getArrayLength(array: Value): Value
public fun getArrayElement(array: Value, index: Value): Value
public fun setArrayElement(array: Value, index: Value, newValue: Value)
fun newArray(arrayType: Type, size: Int): Value
fun newMultiDimensionalArray(arrayType: Type, dimensionSizes: List<Int>): Value
fun getArrayLength(array: Value): Value
fun getArrayElement(array: Value, index: Value): Value
fun setArrayElement(array: Value, index: Value, newValue: Value)
public fun getStaticField(fieldDesc: FieldDescription): Value
public fun setStaticField(fieldDesc: FieldDescription, newValue: Value)
public fun invokeStaticMethod(methodDesc: MethodDescription, arguments: List<Value>): Value
fun getStaticField(fieldDesc: FieldDescription): Value
fun setStaticField(fieldDesc: FieldDescription, newValue: Value)
fun invokeStaticMethod(methodDesc: MethodDescription, arguments: List<Value>): Value
public fun getField(instance: Value, fieldDesc: FieldDescription): Value
public fun setField(instance: Value, fieldDesc: FieldDescription, newValue: Value)
public fun invokeMethod(instance: Value, methodDesc: MethodDescription, arguments: List<Value>, invokespecial: Boolean = false): Value
fun getField(instance: Value, fieldDesc: FieldDescription): Value
fun setField(instance: Value, fieldDesc: FieldDescription, newValue: Value)
fun invokeMethod(instance: Value, methodDesc: MethodDescription, arguments: List<Value>, invokespecial: Boolean = false): Value
}
class SingleInstructionInterpreter(private val eval: Eval) : Interpreter<Value>(ASM5) {
@@ -203,7 +203,7 @@ class SingleInstructionInterpreter(private val eval: Eval) : Interpreter<Value>(
}
}
public fun checkUnaryCondition(value: Value, opcode: Int): Boolean {
fun checkUnaryCondition(value: Value, opcode: Int): Boolean {
return when (opcode) {
IFEQ -> value.int == 0
IFNE -> value.int != 0
@@ -312,7 +312,7 @@ class SingleInstructionInterpreter(private val eval: Eval) : Interpreter<Value>(
}
}
public fun checkBinaryCondition(value1: Value, value2: Value, opcode: Int): Boolean {
fun checkBinaryCondition(value1: Value, value2: Value, opcode: Int): Boolean {
return when (opcode) {
IF_ICMPEQ -> value1.int == value2.int
IF_ICMPNE -> value1.int != value2.int
@@ -24,29 +24,29 @@ import org.jetbrains.org.objectweb.asm.tree.analysis.Frame
import org.jetbrains.org.objectweb.asm.util.Printer
import java.util.*
public interface InterpreterResult {
interface InterpreterResult {
override fun toString(): String
}
public class ExceptionThrown(public val exception: ObjectValue, public val kind: ExceptionKind): InterpreterResult {
class ExceptionThrown(val exception: ObjectValue, val kind: ExceptionKind): InterpreterResult {
override fun toString(): String = "Thrown $exception: $kind"
public enum class ExceptionKind {
enum class ExceptionKind {
FROM_EVALUATED_CODE,
FROM_EVALUATOR,
BROKEN_CODE
}
}
public data class ValueReturned(public val result: Value): InterpreterResult {
data class ValueReturned(val result: Value): InterpreterResult {
override fun toString(): String = "Returned $result"
}
public class AbnormalTermination(public val message: String): InterpreterResult {
class AbnormalTermination(val message: String): InterpreterResult {
override fun toString(): String = "Terminated abnormally: $message"
}
public interface InterpretationEventHandler {
interface InterpretationEventHandler {
object NONE : InterpretationEventHandler {
override fun instructionProcessed(insn: AbstractInsnNode): InterpreterResult? = null
override fun exceptionThrown(currentState: Frame<Value>, currentInsn: AbstractInsnNode, exception: Value): InterpreterResult? = null
@@ -71,7 +71,7 @@ class ThrownFromEvaluatedCodeException(val exception: ObjectValue): RuntimeExcep
override fun toString(): String = "Thrown from evaluated code: $exception"
}
public fun interpreterLoop(
fun interpreterLoop(
m: MethodNode,
initialState: Frame<Value>,
eval: Eval,
@@ -28,7 +28,7 @@ val CLASS = Type.getType(Class::class.java)
val OBJECT = Type.getType(Any::class.java)
val BOOTSTRAP_CLASS_DESCRIPTORS = setOf("Ljava/lang/String;", "Ljava/lang/ClassLoader;", "Ljava/lang/Class;")
public class JDIEval(
class JDIEval(
private val vm: VirtualMachine,
private val defaultClassLoader: ClassLoaderReference?,
private val thread: ThreadReference,
@@ -251,7 +251,7 @@ public class JDIEval(
mayThrow { obj.setValue(field, jdiValue) }
}
public fun unboxType(boxedValue: Value, type: Type): Value {
fun unboxType(boxedValue: Value, type: Type): Value {
val method = when (type) {
Type.INT_TYPE -> MethodDescription("java/lang/Integer", "intValue", "()I", false)
Type.BOOLEAN_TYPE -> MethodDescription("java/lang/Boolean", "booleanValue", "()Z", false)
@@ -266,7 +266,7 @@ public class JDIEval(
return invokeMethod(boxedValue, method, listOf(), true)
}
public fun boxType(value: Value): Value {
fun boxType(value: Value): Value {
val method = when (value.asmType) {
Type.INT_TYPE -> MethodDescription("java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false)
Type.BYTE_TYPE -> MethodDescription("java/lang/Byte", "valueOf", "(B)Ljava/lang/Byte;", false)
@@ -36,7 +36,7 @@ import com.sun.jdi.Type as jdi_Type
import com.sun.jdi.Value as jdi_Value
import com.sun.jdi.VoidValue as jdi_VoidValue
public fun makeInitialFrame(methodNode: MethodNode, arguments: List<Value>): Frame<Value> {
fun makeInitialFrame(methodNode: MethodNode, arguments: List<Value>): Frame<Value> {
val isStatic = (methodNode.access and ACC_STATIC) != 0
val params = Type.getArgumentTypes(methodNode.desc)
@@ -64,14 +64,14 @@ public fun makeInitialFrame(methodNode: MethodNode, arguments: List<Value>): Fra
class JDIFailureException(message: String?, cause: Throwable? = null): RuntimeException(message, cause)
public fun jdi_ObjectReference?.asValue(): ObjectValue {
fun jdi_ObjectReference?.asValue(): ObjectValue {
return when (this) {
null -> NULL_VALUE
else -> ObjectValue(this, type().asType())
}
}
public fun jdi_Value?.asValue(): Value {
fun jdi_Value?.asValue(): Value {
return when (this) {
null -> NULL_VALUE
is jdi_VoidValue -> VOID_VALUE
@@ -96,7 +96,7 @@ val Value.jdiObj: jdi_ObjectReference?
val Value.jdiClass: ClassObjectReference?
get() = this.jdiObj as ClassObjectReference?
public fun Value.asJdiValue(vm: VirtualMachine, expectedType: Type): jdi_Value? {
fun Value.asJdiValue(vm: VirtualMachine, expectedType: Type): jdi_Value? {
return when (this) {
NULL_VALUE -> null
VOID_VALUE -> vm.mirrorOfVoid()
+1 -1
View File
@@ -74,7 +74,7 @@ val MethodDescription.parameterTypes: List<Type>
get() = Type.getArgumentTypes(desc).toList()
public class FieldDescription(
class FieldDescription(
ownerInternalName: String,
name: String,
desc: String,
+5 -5
View File
@@ -19,9 +19,9 @@ package org.jetbrains.eval4j
import org.jetbrains.org.objectweb.asm.Type
import org.jetbrains.org.objectweb.asm.tree.LabelNode
public interface Value : org.jetbrains.org.objectweb.asm.tree.analysis.Value {
public val asmType: Type
public val valid: Boolean
interface Value : org.jetbrains.org.objectweb.asm.tree.analysis.Value {
val asmType: Type
val valid: Boolean
override fun getSize(): Int = asmType.size
override fun toString(): String
@@ -57,7 +57,7 @@ abstract class AbstractValueBase<V>(
override val asmType: Type
) : Value {
override val valid = true
public abstract val value: V
abstract val value: V
override fun toString() = "$value: $asmType"
@@ -81,7 +81,7 @@ class IntValue(value: Int, asmType: Type): AbstractValue<Int>(value, asmType)
class LongValue(value: Long): AbstractValue<Long>(value, Type.LONG_TYPE)
class FloatValue(value: Float): AbstractValue<Float>(value, Type.FLOAT_TYPE)
class DoubleValue(value: Double): AbstractValue<Double>(value, Type.DOUBLE_TYPE)
public open class ObjectValue(value: Any?, asmType: Type): AbstractValue<Any?>(value, asmType)
open class ObjectValue(value: Any?, asmType: Type): AbstractValue<Any?>(value, asmType)
class NewObjectValue(asmType: Type): ObjectValue(null, asmType) {
override var value: Any? = null
get(): Any? {