org.jetbrains.kotlin.ir.interpreter.state.Primitive.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-compiler-embeddable Show documentation
Show all versions of kotlin-compiler-embeddable Show documentation
the Kotlin compiler embeddable
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.ir.interpreter.state
import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.declarations.IrFunction
import org.jetbrains.kotlin.ir.expressions.IrCall
import org.jetbrains.kotlin.ir.interpreter.getFirstNonInterfaceOverridden
import org.jetbrains.kotlin.ir.interpreter.stack.Fields
import org.jetbrains.kotlin.ir.symbols.IrSymbol
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.types.classOrNull
import org.jetbrains.kotlin.ir.util.defaultType
internal class Primitive(val value: Any?, val type: IrType) : State {
override val fields: Fields = mutableMapOf()
override val irClass: IrClass = type.classOrNull!!.owner
override fun getField(symbol: IrSymbol): State? = null
override fun getIrFunctionByIrCall(expression: IrCall): IrFunction {
val owner = expression.symbol.owner
return if (owner.isFakeOverride) owner.getFirstNonInterfaceOverridden() else owner
}
override fun toString(): String {
return "Primitive(value=$value, type=${irClass.defaultType})"
}
companion object {
fun nullStateOfType(irType: IrType): Primitive {
return Primitive(null, irType)
}
}
}