Rework object and companion object interpretation

For now object value or fun can be interpreter only if they are
marked explicitly. Annotation for all object is restricted and if
whole class is marked with CompileTimeAnnotation this doesn't
mean that companion object is computable.
This commit is contained in:
Ivan Kylchik
2020-01-28 19:07:30 +03:00
parent 0ef34dcf53
commit 3ccf542b38
@@ -451,7 +451,16 @@ class IrInterpreter(irModule: IrModuleFragment) {
}
private fun interpretGetObjectValue(expression: IrGetObjectValue, data: Frame): Code {
data.pushReturnValue(Complex(expression.symbol.owner, mutableListOf()))
val objectState = Complex(expression.symbol.owner, mutableListOf())
val newFrame = data.copy().apply { addVar(Variable(expression.symbol.descriptor.thisAsReceiverParameter, objectState)) }
val constructor = expression.symbol.owner.declarations.single { it is IrConstructor } as IrConstructor
val constructorBody = constructor.body?.statements?.get(1) as? IrBlock
val irAnnotatedSetFields = constructorBody?.statements?.filterIsInstance<IrSetField>()
?.filter { it.symbol.owner.correspondingPropertySymbol!!.owner.hasAnnotation(compileTimeAnnotation) }
irAnnotatedSetFields?.forEach { irSetField -> irSetField.interpret(newFrame).also { if (it != Code.NEXT) return it } }
data.pushReturnValue(objectState)
return Code.NEXT
}