Support basic interpretation of IrGetClass
This commit is contained in:
committed by
TeamCityServer
parent
6fe8dd1254
commit
cf20e64c61
+6
@@ -694,6 +694,12 @@ public class IrInterpreterAfterFir2IrTestGenerated extends AbstractIrInterpreter
|
|||||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/ir/interpreter/reference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/ir/interpreter/reference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("getClass.kt")
|
||||||
|
public void testGetClass() throws Exception {
|
||||||
|
runTest("compiler/testData/ir/interpreter/reference/getClass.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("propertyReference.kt")
|
@TestMetadata("propertyReference.kt")
|
||||||
public void testPropertyReference() throws Exception {
|
public void testPropertyReference() throws Exception {
|
||||||
|
|||||||
+6
@@ -694,6 +694,12 @@ public class IrInterpreterAfterPsi2IrTestGenerated extends AbstractIrInterpreter
|
|||||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/ir/interpreter/reference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/ir/interpreter/reference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("getClass.kt")
|
||||||
|
public void testGetClass() throws Exception {
|
||||||
|
runTest("compiler/testData/ir/interpreter/reference/getClass.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("propertyReference.kt")
|
@TestMetadata("propertyReference.kt")
|
||||||
public void testPropertyReference() throws Exception {
|
public void testPropertyReference() throws Exception {
|
||||||
|
|||||||
+6
@@ -68,6 +68,7 @@ internal fun unfoldInstruction(element: IrElement?, environment: IrInterpreterEn
|
|||||||
is IrFunctionReference -> unfoldFunctionReference(element, callStack)
|
is IrFunctionReference -> unfoldFunctionReference(element, callStack)
|
||||||
is IrPropertyReference -> unfoldPropertyReference(element, callStack)
|
is IrPropertyReference -> unfoldPropertyReference(element, callStack)
|
||||||
is IrClassReference -> unfoldClassReference(element, callStack)
|
is IrClassReference -> unfoldClassReference(element, callStack)
|
||||||
|
is IrGetClass -> unfoldGetClass(element, callStack)
|
||||||
is IrComposite -> unfoldComposite(element, callStack)
|
is IrComposite -> unfoldComposite(element, callStack)
|
||||||
|
|
||||||
else -> TODO("${element.javaClass} not supported")
|
else -> TODO("${element.javaClass} not supported")
|
||||||
@@ -401,4 +402,9 @@ private fun unfoldPropertyReference(propertyReference: IrPropertyReference, call
|
|||||||
|
|
||||||
private fun unfoldClassReference(classReference: IrClassReference, callStack: CallStack) {
|
private fun unfoldClassReference(classReference: IrClassReference, callStack: CallStack) {
|
||||||
callStack.addInstruction(SimpleInstruction(classReference))
|
callStack.addInstruction(SimpleInstruction(classReference))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun unfoldGetClass(element: IrGetClass, callStack: CallStack) {
|
||||||
|
callStack.addInstruction(SimpleInstruction(element))
|
||||||
|
callStack.addInstruction(CompoundInstruction(element.argument))
|
||||||
}
|
}
|
||||||
@@ -132,6 +132,7 @@ class IrInterpreter private constructor(
|
|||||||
is IrFunctionReference -> interpretFunctionReference(element)
|
is IrFunctionReference -> interpretFunctionReference(element)
|
||||||
is IrPropertyReference -> interpretPropertyReference(element)
|
is IrPropertyReference -> interpretPropertyReference(element)
|
||||||
is IrClassReference -> interpretClassReference(element)
|
is IrClassReference -> interpretClassReference(element)
|
||||||
|
is IrGetClass -> interpretGetClass(element)
|
||||||
else -> TODO("${element.javaClass} not supported for interpretation")
|
else -> TODO("${element.javaClass} not supported for interpretation")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -616,4 +617,9 @@ class IrInterpreter private constructor(
|
|||||||
else -> callStack.pushState(KClassState(classReference))
|
else -> callStack.pushState(KClassState(classReference))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun interpretGetClass(expression: IrGetClass) {
|
||||||
|
val irClass = callStack.popState().irClass
|
||||||
|
callStack.pushState(KClassState(irClass, expression.type.classOrNull!!.owner))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import kotlin.*
|
||||||
|
|
||||||
|
fun test(a: Any) = when (a::class) {
|
||||||
|
String::class -> "String"
|
||||||
|
Int::class -> "Int"
|
||||||
|
Boolean::class -> "Boolean"
|
||||||
|
else -> "Else"
|
||||||
|
}
|
||||||
|
|
||||||
|
const val a = <!EVALUATED: `String`!>test("")<!>
|
||||||
|
const val b = <!EVALUATED: `Int`!>test(1)<!>
|
||||||
|
const val c = <!EVALUATED: `Boolean`!>test(true)<!>
|
||||||
|
const val d = <!EVALUATED: `Else`!>test(2.0)<!>
|
||||||
Reference in New Issue
Block a user