Mark most of classes and functions from interpreter package as internal
Main goal is to avoid ambiguity because some names, that are used by interpreter, can be found in other modules
This commit is contained in:
+4
-1
@@ -37,7 +37,10 @@ inline fun ExecutionResult.check(toCheckLabel: ReturnLabel = ReturnLabel.NEXT, r
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
fun ExecutionResult.implicitCastIfNeeded(expectedType: IrType, actualType: IrType, stack: Stack): ExecutionResult {
|
/**
|
||||||
|
* This method is analog of `checkcast` jvm bytecode operation. Throw exception whenever actual type is not a subtype of expected.
|
||||||
|
*/
|
||||||
|
internal fun ExecutionResult.implicitCastIfNeeded(expectedType: IrType, actualType: IrType, stack: Stack): ExecutionResult {
|
||||||
if (actualType.classifierOrNull !is IrTypeParameterSymbol) return this
|
if (actualType.classifierOrNull !is IrTypeParameterSymbol) return this
|
||||||
|
|
||||||
if (expectedType.classifierOrFail is IrTypeParameterSymbol) return this
|
if (expectedType.classifierOrFail is IrTypeParameterSymbol) return this
|
||||||
|
|||||||
+16
-24
@@ -23,23 +23,15 @@ import org.jetbrains.kotlin.name.FqName
|
|||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
|
|
||||||
fun IrFunction.getDispatchReceiver(): IrValueParameterSymbol? {
|
internal fun IrFunction.getDispatchReceiver(): IrValueParameterSymbol? = this.dispatchReceiverParameter?.symbol
|
||||||
return this.dispatchReceiverParameter?.symbol
|
|
||||||
}
|
|
||||||
|
|
||||||
fun IrFunction.getExtensionReceiver(): IrValueParameterSymbol? {
|
internal fun IrFunction.getExtensionReceiver(): IrValueParameterSymbol? = this.extensionReceiverParameter?.symbol
|
||||||
return this.extensionReceiverParameter?.symbol
|
|
||||||
}
|
|
||||||
|
|
||||||
fun IrFunction.getReceiver(): IrSymbol? {
|
internal fun IrFunction.getReceiver(): IrSymbol? = this.getDispatchReceiver() ?: this.getExtensionReceiver()
|
||||||
return this.getDispatchReceiver() ?: this.getExtensionReceiver()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun IrFunctionAccessExpression.getBody(): IrBody? {
|
internal fun IrFunctionAccessExpression.getBody(): IrBody? = this.symbol.owner.body
|
||||||
return this.symbol.owner.body
|
|
||||||
}
|
|
||||||
|
|
||||||
fun State.toIrExpression(expression: IrExpression): IrExpression {
|
internal fun State.toIrExpression(expression: IrExpression): IrExpression {
|
||||||
val start = expression.startOffset
|
val start = expression.startOffset
|
||||||
val end = expression.endOffset
|
val end = expression.endOffset
|
||||||
val type = expression.type.makeNotNull()
|
val type = expression.type.makeNotNull()
|
||||||
@@ -61,7 +53,7 @@ fun State.toIrExpression(expression: IrExpression): IrExpression {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Any?.toState(irType: IrType): State {
|
internal fun Any?.toState(irType: IrType): State {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
is State -> this
|
is State -> this
|
||||||
is Boolean, is Char, is Byte, is Short, is Int, is Long, is String, is Float, is Double, is Array<*>, is ByteArray,
|
is Boolean, is Char, is Byte, is Short, is Int, is Long, is String, is Float, is Double, is Array<*>, is ByteArray,
|
||||||
@@ -92,7 +84,7 @@ fun Any?.toIrConst(irType: IrType, startOffset: Int = UNDEFINED_OFFSET, endOffse
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T> IrConst<T>.toPrimitive(): Primitive<T> {
|
internal fun <T> IrConst<T>.toPrimitive(): Primitive<T> {
|
||||||
return Primitive(this.value, this.type)
|
return Primitive(this.value, this.type)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,13 +101,13 @@ fun IrAnnotationContainer.getAnnotation(annotation: FqName): IrConstructorCall {
|
|||||||
?: ((this as IrFunction).parent as IrClass).annotations.first { it.symbol.owner.parentAsClass.fqNameWhenAvailable == annotation }
|
?: ((this as IrFunction).parent as IrClass).annotations.first { it.symbol.owner.parentAsClass.fqNameWhenAvailable == annotation }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun IrAnnotationContainer.getEvaluateIntrinsicValue(): String? {
|
internal fun IrAnnotationContainer.getEvaluateIntrinsicValue(): String? {
|
||||||
if (this is IrClass && this.fqNameWhenAvailable?.startsWith(Name.identifier("java")) == true) return this.fqNameWhenAvailable?.asString()
|
if (this is IrClass && this.fqNameWhenAvailable?.startsWith(Name.identifier("java")) == true) return this.fqNameWhenAvailable?.asString()
|
||||||
if (!this.hasAnnotation(evaluateIntrinsicAnnotation)) return null
|
if (!this.hasAnnotation(evaluateIntrinsicAnnotation)) return null
|
||||||
return (this.getAnnotation(evaluateIntrinsicAnnotation).getValueArgument(0) as IrConst<*>).value.toString()
|
return (this.getAnnotation(evaluateIntrinsicAnnotation).getValueArgument(0) as IrConst<*>).value.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getPrimitiveClass(irType: IrType, asObject: Boolean = false): Class<*>? {
|
internal fun getPrimitiveClass(irType: IrType, asObject: Boolean = false): Class<*>? {
|
||||||
return when {
|
return when {
|
||||||
irType.isBoolean() -> if (asObject) Boolean::class.javaObjectType else Boolean::class.java
|
irType.isBoolean() -> if (asObject) Boolean::class.javaObjectType else Boolean::class.java
|
||||||
irType.isChar() -> if (asObject) Char::class.javaObjectType else Char::class.java
|
irType.isChar() -> if (asObject) Char::class.javaObjectType else Char::class.java
|
||||||
@@ -130,7 +122,7 @@ fun getPrimitiveClass(irType: IrType, asObject: Boolean = false): Class<*>? {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun IrFunction.getArgsForMethodInvocation(args: List<Variable>): List<Any?> {
|
internal fun IrFunction.getArgsForMethodInvocation(args: List<Variable>): List<Any?> {
|
||||||
val argsValues = args.map {
|
val argsValues = args.map {
|
||||||
when (val state = it.state) {
|
when (val state = it.state) {
|
||||||
is ExceptionState -> state.getThisAsCauseForException()
|
is ExceptionState -> state.getThisAsCauseForException()
|
||||||
@@ -157,7 +149,7 @@ fun IrFunction.getLastOverridden(): IrFunction {
|
|||||||
return generateSequence(listOf(this)) { it.firstOrNull()?.overriddenSymbols?.map { it.owner } }.flatten().last()
|
return generateSequence(listOf(this)) { it.firstOrNull()?.overriddenSymbols?.map { it.owner } }.flatten().last()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun List<Any?>.toPrimitiveStateArray(type: IrType): Primitive<*> {
|
internal fun List<Any?>.toPrimitiveStateArray(type: IrType): Primitive<*> {
|
||||||
return when {
|
return when {
|
||||||
type.isByteArray() -> Primitive(ByteArray(size) { i -> (this[i] as Number).toByte() }, type)
|
type.isByteArray() -> Primitive(ByteArray(size) { i -> (this[i] as Number).toByte() }, type)
|
||||||
type.isCharArray() -> Primitive(CharArray(size) { i -> this[i] as Char }, type)
|
type.isCharArray() -> Primitive(CharArray(size) { i -> this[i] as Char }, type)
|
||||||
@@ -178,7 +170,7 @@ fun IrFunctionAccessExpression.getVarargType(index: Int): IrType? {
|
|||||||
return this.getTypeArgument(typeParameter.index)
|
return this.getTypeArgument(typeParameter.index)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getTypeArguments(
|
internal fun getTypeArguments(
|
||||||
container: IrTypeParametersContainer, expression: IrFunctionAccessExpression, mapper: (IrTypeParameterSymbol) -> State
|
container: IrTypeParametersContainer, expression: IrFunctionAccessExpression, mapper: (IrTypeParameterSymbol) -> State
|
||||||
): List<Variable> {
|
): List<Variable> {
|
||||||
fun IrType.getState(): State {
|
fun IrType.getState(): State {
|
||||||
@@ -198,13 +190,13 @@ fun getTypeArguments(
|
|||||||
return typeArguments
|
return typeArguments
|
||||||
}
|
}
|
||||||
|
|
||||||
fun State?.extractNonLocalDeclarations(): List<Variable> {
|
internal fun State?.extractNonLocalDeclarations(): List<Variable> {
|
||||||
this ?: return listOf()
|
this ?: return listOf()
|
||||||
val state = this.takeIf { it !is Complex } ?: (this as Complex).getOriginal()
|
val state = this.takeIf { it !is Complex } ?: (this as Complex).getOriginal()
|
||||||
return state.fields.filter { it.symbol !is IrFieldSymbol }
|
return state.fields.filter { it.symbol !is IrFieldSymbol }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun State?.getCorrectReceiverByFunction(irFunction: IrFunction): State? {
|
internal fun State?.getCorrectReceiverByFunction(irFunction: IrFunction): State? {
|
||||||
if (this !is Complex) return this
|
if (this !is Complex) return this
|
||||||
|
|
||||||
val original: Complex? = this.getOriginal()
|
val original: Complex? = this.getOriginal()
|
||||||
@@ -212,7 +204,7 @@ fun State?.getCorrectReceiverByFunction(irFunction: IrFunction): State? {
|
|||||||
return generateSequence(original) { it.superClass }.firstOrNull { it.irClass.thisReceiver == other } ?: this
|
return generateSequence(original) { it.superClass }.firstOrNull { it.irClass.thisReceiver == other } ?: this
|
||||||
}
|
}
|
||||||
|
|
||||||
fun State.checkNullability(irType: IrType?): State {
|
internal fun State.checkNullability(irType: IrType?): State {
|
||||||
if (irType !is IrSimpleType) return this
|
if (irType !is IrSimpleType) return this
|
||||||
if (this.isNull() && !irType.hasQuestionMark) {
|
if (this.isNull() && !irType.hasQuestionMark) {
|
||||||
throw NullPointerException()
|
throw NullPointerException()
|
||||||
@@ -225,4 +217,4 @@ fun IrValueParameterSymbol.isNullable(): Boolean {
|
|||||||
return type.isNullable()
|
return type.isNullable()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun IrFunction.getCapitalizedFileName() = this.file.name.replace(".kt", "Kt").capitalize()
|
internal fun IrFunction.getCapitalizedFileName() = this.file.name.replace(".kt", "Kt").capitalize()
|
||||||
+1
-1
@@ -11,7 +11,7 @@ import org.jetbrains.kotlin.backend.common.interpreter.stack.Stack
|
|||||||
import org.jetbrains.kotlin.ir.IrElement
|
import org.jetbrains.kotlin.ir.IrElement
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||||
|
|
||||||
class IntrinsicEvaluator {
|
internal class IntrinsicEvaluator {
|
||||||
suspend fun evaluate(irFunction: IrFunction, stack: Stack, interpret: suspend IrElement.() -> ExecutionResult): ExecutionResult {
|
suspend fun evaluate(irFunction: IrFunction, stack: Stack, interpret: suspend IrElement.() -> ExecutionResult): ExecutionResult {
|
||||||
return when {
|
return when {
|
||||||
EmptyArray.equalTo(irFunction) -> EmptyArray.evaluate(irFunction, stack, interpret)
|
EmptyArray.equalTo(irFunction) -> EmptyArray.evaluate(irFunction, stack, interpret)
|
||||||
|
|||||||
+10
-10
@@ -17,12 +17,12 @@ import org.jetbrains.kotlin.ir.declarations.IrFunction
|
|||||||
import org.jetbrains.kotlin.ir.types.classOrNull
|
import org.jetbrains.kotlin.ir.types.classOrNull
|
||||||
import org.jetbrains.kotlin.ir.util.*
|
import org.jetbrains.kotlin.ir.util.*
|
||||||
|
|
||||||
sealed class IntrinsicBase {
|
internal sealed class IntrinsicBase {
|
||||||
abstract fun equalTo(irFunction: IrFunction): Boolean
|
abstract fun equalTo(irFunction: IrFunction): Boolean
|
||||||
abstract suspend fun evaluate(irFunction: IrFunction, stack: Stack, interpret: suspend IrElement.() -> ExecutionResult): ExecutionResult
|
abstract suspend fun evaluate(irFunction: IrFunction, stack: Stack, interpret: suspend IrElement.() -> ExecutionResult): ExecutionResult
|
||||||
}
|
}
|
||||||
|
|
||||||
object EmptyArray : IntrinsicBase() {
|
internal object EmptyArray : IntrinsicBase() {
|
||||||
override fun equalTo(irFunction: IrFunction): Boolean {
|
override fun equalTo(irFunction: IrFunction): Boolean {
|
||||||
val fqName = irFunction.fqNameWhenAvailable.toString()
|
val fqName = irFunction.fqNameWhenAvailable.toString()
|
||||||
return fqName in setOf("kotlin.emptyArray", "kotlin.ArrayIntrinsicsKt.emptyArray")
|
return fqName in setOf("kotlin.emptyArray", "kotlin.ArrayIntrinsicsKt.emptyArray")
|
||||||
@@ -37,7 +37,7 @@ object EmptyArray : IntrinsicBase() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object ArrayOf : IntrinsicBase() {
|
internal object ArrayOf : IntrinsicBase() {
|
||||||
override fun equalTo(irFunction: IrFunction): Boolean {
|
override fun equalTo(irFunction: IrFunction): Boolean {
|
||||||
val fqName = irFunction.fqNameWhenAvailable.toString()
|
val fqName = irFunction.fqNameWhenAvailable.toString()
|
||||||
return fqName == "kotlin.arrayOf"
|
return fqName == "kotlin.arrayOf"
|
||||||
@@ -53,7 +53,7 @@ object ArrayOf : IntrinsicBase() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object ArrayOfNulls : IntrinsicBase() {
|
internal object ArrayOfNulls : IntrinsicBase() {
|
||||||
override fun equalTo(irFunction: IrFunction): Boolean {
|
override fun equalTo(irFunction: IrFunction): Boolean {
|
||||||
val fqName = irFunction.fqNameWhenAvailable.toString()
|
val fqName = irFunction.fqNameWhenAvailable.toString()
|
||||||
return fqName == "kotlin.arrayOfNulls"
|
return fqName == "kotlin.arrayOfNulls"
|
||||||
@@ -70,7 +70,7 @@ object ArrayOfNulls : IntrinsicBase() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object EnumValues : IntrinsicBase() {
|
internal object EnumValues : IntrinsicBase() {
|
||||||
override fun equalTo(irFunction: IrFunction): Boolean {
|
override fun equalTo(irFunction: IrFunction): Boolean {
|
||||||
val fqName = irFunction.fqNameWhenAvailable.toString()
|
val fqName = irFunction.fqNameWhenAvailable.toString()
|
||||||
return (fqName == "kotlin.enumValues" || fqName.endsWith(".values")) && irFunction.valueParameters.isEmpty()
|
return (fqName == "kotlin.enumValues" || fqName.endsWith(".values")) && irFunction.valueParameters.isEmpty()
|
||||||
@@ -91,7 +91,7 @@ object EnumValues : IntrinsicBase() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object EnumValueOf : IntrinsicBase() {
|
internal object EnumValueOf : IntrinsicBase() {
|
||||||
override fun equalTo(irFunction: IrFunction): Boolean {
|
override fun equalTo(irFunction: IrFunction): Boolean {
|
||||||
val fqName = irFunction.fqNameWhenAvailable.toString()
|
val fqName = irFunction.fqNameWhenAvailable.toString()
|
||||||
return (fqName == "kotlin.enumValueOf" || fqName.endsWith(".valueOf")) && irFunction.valueParameters.size == 1
|
return (fqName == "kotlin.enumValueOf" || fqName.endsWith(".valueOf")) && irFunction.valueParameters.size == 1
|
||||||
@@ -113,7 +113,7 @@ object EnumValueOf : IntrinsicBase() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object RegexReplace : IntrinsicBase() {
|
internal object RegexReplace : IntrinsicBase() {
|
||||||
override fun equalTo(irFunction: IrFunction): Boolean {
|
override fun equalTo(irFunction: IrFunction): Boolean {
|
||||||
val fqName = irFunction.fqNameWhenAvailable.toString()
|
val fqName = irFunction.fqNameWhenAvailable.toString()
|
||||||
return fqName == "kotlin.text.Regex.replace" && irFunction.valueParameters.size == 2
|
return fqName == "kotlin.text.Regex.replace" && irFunction.valueParameters.size == 2
|
||||||
@@ -137,7 +137,7 @@ object RegexReplace : IntrinsicBase() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object EnumHashCode : IntrinsicBase() {
|
internal object EnumHashCode : IntrinsicBase() {
|
||||||
override fun equalTo(irFunction: IrFunction): Boolean {
|
override fun equalTo(irFunction: IrFunction): Boolean {
|
||||||
val fqName = irFunction.fqNameWhenAvailable.toString()
|
val fqName = irFunction.fqNameWhenAvailable.toString()
|
||||||
return fqName == "kotlin.Enum.hashCode"
|
return fqName == "kotlin.Enum.hashCode"
|
||||||
@@ -152,7 +152,7 @@ object EnumHashCode : IntrinsicBase() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object JsPrimitives : IntrinsicBase() {
|
internal object JsPrimitives : IntrinsicBase() {
|
||||||
override fun equalTo(irFunction: IrFunction): Boolean {
|
override fun equalTo(irFunction: IrFunction): Boolean {
|
||||||
val fqName = irFunction.fqNameWhenAvailable.toString()
|
val fqName = irFunction.fqNameWhenAvailable.toString()
|
||||||
return fqName == "kotlin.Long.<init>" || fqName == "kotlin.Char.<init>"
|
return fqName == "kotlin.Long.<init>" || fqName == "kotlin.Char.<init>"
|
||||||
@@ -176,7 +176,7 @@ object JsPrimitives : IntrinsicBase() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object ArrayConstructor : IntrinsicBase() {
|
internal object ArrayConstructor : IntrinsicBase() {
|
||||||
override fun equalTo(irFunction: IrFunction): Boolean {
|
override fun equalTo(irFunction: IrFunction): Boolean {
|
||||||
val fqName = irFunction.fqNameWhenAvailable.toString()
|
val fqName = irFunction.fqNameWhenAvailable.toString()
|
||||||
return fqName.matches("kotlin\\.(Byte|Char|Short|Int|Long|Float|Double|Boolean|)Array\\.<init>".toRegex())
|
return fqName.matches("kotlin\\.(Byte|Char|Short|Int|Long|Float|Double|Boolean|)Array\\.<init>".toRegex())
|
||||||
|
|||||||
+2
-2
@@ -9,7 +9,7 @@ import org.jetbrains.kotlin.backend.common.interpreter.state.State
|
|||||||
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
|
||||||
|
|
||||||
interface Frame {
|
internal interface Frame {
|
||||||
fun addVar(variable: Variable)
|
fun addVar(variable: Variable)
|
||||||
fun addAll(variables: List<Variable>)
|
fun addAll(variables: List<Variable>)
|
||||||
fun getVariable(symbol: IrSymbol): Variable?
|
fun getVariable(symbol: IrSymbol): Variable?
|
||||||
@@ -23,7 +23,7 @@ interface Frame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO replace exceptions with InterpreterException
|
// TODO replace exceptions with InterpreterException
|
||||||
class InterpreterFrame(
|
internal class InterpreterFrame(
|
||||||
private val pool: MutableList<Variable> = mutableListOf(),
|
private val pool: MutableList<Variable> = mutableListOf(),
|
||||||
private val typeArguments: List<Variable> = listOf()
|
private val typeArguments: List<Variable> = listOf()
|
||||||
) : Frame {
|
) : Frame {
|
||||||
|
|||||||
+2
-2
@@ -18,7 +18,7 @@ import org.jetbrains.kotlin.ir.util.fileEntry
|
|||||||
import org.jetbrains.kotlin.ir.util.fqNameWhenAvailable
|
import org.jetbrains.kotlin.ir.util.fqNameWhenAvailable
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult
|
import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult
|
||||||
|
|
||||||
interface Stack {
|
internal interface Stack {
|
||||||
suspend fun newFrame(
|
suspend fun newFrame(
|
||||||
asSubFrame: Boolean = false, initPool: List<Variable> = listOf(), block: suspend () -> ExecutionResult
|
asSubFrame: Boolean = false, initPool: List<Variable> = listOf(), block: suspend () -> ExecutionResult
|
||||||
): ExecutionResult
|
): ExecutionResult
|
||||||
@@ -39,7 +39,7 @@ interface Stack {
|
|||||||
fun peekReturnValue(): State
|
fun peekReturnValue(): State
|
||||||
}
|
}
|
||||||
|
|
||||||
class StackImpl : Stack {
|
internal class StackImpl : Stack {
|
||||||
private val frameList = mutableListOf(FrameContainer()) // first frame is default, it is easier to work when last() is not null
|
private val frameList = mutableListOf(FrameContainer()) // first frame is default, it is easier to work when last() is not null
|
||||||
private fun getCurrentFrame() = frameList.last()
|
private fun getCurrentFrame() = frameList.last()
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -8,4 +8,5 @@ package org.jetbrains.kotlin.backend.common.interpreter.stack
|
|||||||
import org.jetbrains.kotlin.backend.common.interpreter.state.State
|
import org.jetbrains.kotlin.backend.common.interpreter.state.State
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||||
|
|
||||||
data class Variable(val symbol: IrSymbol, var state: State)
|
// TODO maybe switch to typealias and use map instead of list
|
||||||
|
internal data class Variable(val symbol: IrSymbol, var state: State)
|
||||||
+1
-1
@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.ir.types.classOrNull
|
|||||||
import org.jetbrains.kotlin.ir.util.fqNameForIrSerialization
|
import org.jetbrains.kotlin.ir.util.fqNameForIrSerialization
|
||||||
import org.jetbrains.kotlin.ir.util.isInterface
|
import org.jetbrains.kotlin.ir.util.isInterface
|
||||||
|
|
||||||
class Common private constructor(
|
internal class Common private constructor(
|
||||||
override val irClass: IrClass, override val fields: MutableList<Variable>
|
override val irClass: IrClass, override val fields: MutableList<Variable>
|
||||||
) : Complex(irClass, fields) {
|
) : Complex(irClass, fields) {
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -18,7 +18,7 @@ import org.jetbrains.kotlin.ir.util.fqNameForIrSerialization
|
|||||||
import org.jetbrains.kotlin.ir.util.isInterface
|
import org.jetbrains.kotlin.ir.util.isInterface
|
||||||
import org.jetbrains.kotlin.ir.util.overrides
|
import org.jetbrains.kotlin.ir.util.overrides
|
||||||
|
|
||||||
abstract class Complex(override val irClass: IrClass, override val fields: MutableList<Variable>) : State {
|
internal abstract class Complex(override val irClass: IrClass, override val fields: MutableList<Variable>) : State {
|
||||||
var superClass: Complex? = null
|
var superClass: Complex? = null
|
||||||
var subClass: Complex? = null
|
var subClass: Complex? = null
|
||||||
val interfaces: MutableList<Complex> = mutableListOf() // filled lazily, as needed
|
val interfaces: MutableList<Complex> = mutableListOf() // filled lazily, as needed
|
||||||
|
|||||||
+1
-1
@@ -15,7 +15,7 @@ import org.jetbrains.kotlin.ir.util.isSubclassOf
|
|||||||
import org.jetbrains.kotlin.ir.util.nameForIrSerialization
|
import org.jetbrains.kotlin.ir.util.nameForIrSerialization
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
|
||||||
class ExceptionState private constructor(
|
internal class ExceptionState private constructor(
|
||||||
override val irClass: IrClass, override val fields: MutableList<Variable>, stackTrace: List<String>
|
override val irClass: IrClass, override val fields: MutableList<Variable>, stackTrace: List<String>
|
||||||
) : Complex(irClass, fields) {
|
) : Complex(irClass, fields) {
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -15,7 +15,7 @@ import org.jetbrains.kotlin.ir.util.nameForIrSerialization
|
|||||||
import org.jetbrains.kotlin.ir.util.render
|
import org.jetbrains.kotlin.ir.util.render
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
||||||
|
|
||||||
class Lambda(val irFunction: IrFunction, override val irClass: IrClass) : State {
|
internal class Lambda(val irFunction: IrFunction, override val irClass: IrClass) : State {
|
||||||
override val fields: MutableList<Variable> = mutableListOf()
|
override val fields: MutableList<Variable> = mutableListOf()
|
||||||
override val typeArguments: MutableList<Variable> = mutableListOf()
|
override val typeArguments: MutableList<Variable> = mutableListOf()
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -17,7 +17,7 @@ import org.jetbrains.kotlin.ir.types.IrType
|
|||||||
import org.jetbrains.kotlin.ir.types.classOrNull
|
import org.jetbrains.kotlin.ir.types.classOrNull
|
||||||
import org.jetbrains.kotlin.ir.util.isFakeOverride
|
import org.jetbrains.kotlin.ir.util.isFakeOverride
|
||||||
|
|
||||||
class Primitive<T>(var value: T, val type: IrType) : State {
|
internal class Primitive<T>(var value: T, val type: IrType) : State {
|
||||||
override val fields: MutableList<Variable> = mutableListOf()
|
override val fields: MutableList<Variable> = mutableListOf()
|
||||||
override val typeArguments: MutableList<Variable> = mutableListOf()
|
override val typeArguments: MutableList<Variable> = mutableListOf()
|
||||||
override val irClass: IrClass = type.classOrNull!!.owner
|
override val irClass: IrClass = type.classOrNull!!.owner
|
||||||
|
|||||||
+7
-7
@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
|||||||
import org.jetbrains.kotlin.ir.types.*
|
import org.jetbrains.kotlin.ir.types.*
|
||||||
import org.jetbrains.kotlin.ir.util.defaultType
|
import org.jetbrains.kotlin.ir.util.defaultType
|
||||||
|
|
||||||
interface State {
|
internal interface State {
|
||||||
val fields: MutableList<Variable>
|
val fields: MutableList<Variable>
|
||||||
val irClass: IrClass
|
val irClass: IrClass
|
||||||
val typeArguments: MutableList<Variable>
|
val typeArguments: MutableList<Variable>
|
||||||
@@ -36,15 +36,15 @@ interface State {
|
|||||||
fun getIrFunctionByIrCall(expression: IrCall): IrFunction?
|
fun getIrFunctionByIrCall(expression: IrCall): IrFunction?
|
||||||
}
|
}
|
||||||
|
|
||||||
fun State.isNull() = this is Primitive<*> && this.value == null
|
internal fun State.isNull() = this is Primitive<*> && this.value == null
|
||||||
|
|
||||||
fun State.asInt() = (this as Primitive<*>).value as Int
|
internal fun State.asInt() = (this as Primitive<*>).value as Int
|
||||||
fun State.asBoolean() = (this as Primitive<*>).value as Boolean
|
internal fun State.asBoolean() = (this as Primitive<*>).value as Boolean
|
||||||
fun State.asString() = (this as Primitive<*>).value.toString()
|
internal fun State.asString() = (this as Primitive<*>).value.toString()
|
||||||
|
|
||||||
fun State.asBooleanOrNull() = (this as? Primitive<*>)?.value as? Boolean
|
internal fun State.asBooleanOrNull() = (this as? Primitive<*>)?.value as? Boolean
|
||||||
|
|
||||||
fun State.isSubtypeOf(other: IrType): Boolean {
|
internal fun State.isSubtypeOf(other: IrType): Boolean {
|
||||||
if (this is Primitive<*> && this.value == null) return other.isNullable()
|
if (this is Primitive<*> && this.value == null) return other.isNullable()
|
||||||
|
|
||||||
if (this is Primitive<*> && this.type.isArray() && other.isArray()) {
|
if (this is Primitive<*> && this.type.isArray() && other.isArray()) {
|
||||||
|
|||||||
+1
-1
@@ -30,7 +30,7 @@ import java.lang.invoke.MethodHandle
|
|||||||
import java.lang.invoke.MethodHandles
|
import java.lang.invoke.MethodHandles
|
||||||
import java.lang.invoke.MethodType
|
import java.lang.invoke.MethodType
|
||||||
|
|
||||||
class Wrapper(val value: Any, override val irClass: IrClass) : Complex(irClass, mutableListOf()) {
|
internal class Wrapper(val value: Any, override val irClass: IrClass) : Complex(irClass, mutableListOf()) {
|
||||||
|
|
||||||
private val typeFqName = irClass.fqNameForIrSerialization.toUnsafe()
|
private val typeFqName = irClass.fqNameForIrSerialization.toUnsafe()
|
||||||
private val receiverClass = irClass.defaultType.getClass(true)
|
private val receiverClass = irClass.defaultType.getClass(true)
|
||||||
|
|||||||
Reference in New Issue
Block a user