Change the way of getting name and ordinal for enum entry in interpreter
For now IrProperty doesn't have corresponding overridden symbol, so it must be taken from getter.
This commit is contained in:
committed by
TeamCityServer
parent
f815f63fc5
commit
334d518aba
@@ -211,6 +211,11 @@ internal fun IrFieldAccessExpression.accessesTopLevelOrObjectField(): Boolean {
|
||||
return this.receiver == null || (this.receiver?.type?.classifierOrNull?.owner as? IrClass)?.isObject == true
|
||||
}
|
||||
|
||||
internal fun IrClass.getOriginalPropertyByName(name: String): IrProperty {
|
||||
val property = this.declarations.single { it.nameForIrSerialization.asString() == name } as IrProperty
|
||||
return (property.getter!!.getLastOverridden() as IrSimpleFunction).correspondingPropertySymbol!!.owner
|
||||
}
|
||||
|
||||
internal fun IrFunctionAccessExpression.getFunctionThatContainsDefaults(): IrFunction {
|
||||
val irFunction = this.symbol.owner
|
||||
fun IrValueParameter.lookup(): IrFunction? {
|
||||
|
||||
+4
-9
@@ -20,7 +20,6 @@ import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.ir.types.impl.buildSimpleType
|
||||
import org.jetbrains.kotlin.ir.types.impl.makeTypeProjection
|
||||
import org.jetbrains.kotlin.ir.util.fqNameWhenAvailable
|
||||
import org.jetbrains.kotlin.ir.util.resolveFakeOverride
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import java.util.*
|
||||
|
||||
@@ -168,11 +167,9 @@ internal object EnumIntrinsics : IntrinsicBase() {
|
||||
callStack.pushState(enumEntry.getField(symbol)!!)
|
||||
}
|
||||
"compareTo" -> {
|
||||
val ordinal = enumEntry.irClass.declarations.filterIsInstance<IrProperty>()
|
||||
.first { it.name.asString() == "ordinal" }
|
||||
.resolveFakeOverride()!!
|
||||
val ordinalSymbol = enumEntry.irClass.getOriginalPropertyByName("ordinal").symbol
|
||||
val other = callStack.getState(irFunction.valueParameters.single().symbol)
|
||||
val compareTo = enumEntry.getField(ordinal.symbol)!!.asInt().compareTo(other.getField(ordinal.symbol)!!.asInt())
|
||||
val compareTo = enumEntry.getField(ordinalSymbol)!!.asInt().compareTo(other.getField(ordinalSymbol)!!.asInt())
|
||||
callStack.pushState(compareTo.toState(irFunction.returnType))
|
||||
}
|
||||
// TODO "clone" -> throw exception
|
||||
@@ -182,10 +179,8 @@ internal object EnumIntrinsics : IntrinsicBase() {
|
||||
}
|
||||
"hashCode" -> callStack.pushState(enumEntry.hashCode().toState(irFunction.returnType))
|
||||
"toString" -> {
|
||||
val name = enumEntry.irClass.declarations.filterIsInstance<IrProperty>()
|
||||
.first { it.name.asString() == "name" }
|
||||
.resolveFakeOverride()!!
|
||||
callStack.pushState(enumEntry.getField(name.symbol)!!)
|
||||
val nameSymbol = enumEntry.irClass.getOriginalPropertyByName("name").symbol
|
||||
callStack.pushState(enumEntry.getField(nameSymbol)!!)
|
||||
}
|
||||
"values" -> EnumValues.evaluate(irFunction, environment)
|
||||
"valueOf" -> EnumValueOf.evaluate(irFunction, environment)
|
||||
|
||||
+5
-13
@@ -6,13 +6,10 @@
|
||||
package org.jetbrains.kotlin.ir.interpreter.state
|
||||
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrProperty
|
||||
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
|
||||
import org.jetbrains.kotlin.ir.interpreter.getLastOverridden
|
||||
import org.jetbrains.kotlin.ir.interpreter.getOriginalPropertyByName
|
||||
import org.jetbrains.kotlin.ir.interpreter.stack.Variable
|
||||
import org.jetbrains.kotlin.ir.interpreter.toState
|
||||
import org.jetbrains.kotlin.ir.util.isSubclassOf
|
||||
import org.jetbrains.kotlin.ir.util.nameForIrSerialization
|
||||
import kotlin.math.min
|
||||
|
||||
internal class ExceptionState private constructor(
|
||||
@@ -29,8 +26,8 @@ internal class ExceptionState private constructor(
|
||||
|
||||
private lateinit var exceptionFqName: String
|
||||
private val exceptionHierarchy = mutableListOf<String>()
|
||||
private val messageProperty = irClass.getPropertyByName("message")
|
||||
private val causeProperty = irClass.getPropertyByName("cause")
|
||||
private val messageProperty = irClass.getOriginalPropertyByName("message")
|
||||
private val causeProperty = irClass.getOriginalPropertyByName("cause")
|
||||
|
||||
private val stackTrace: List<String> = stackTrace.reversed()
|
||||
|
||||
@@ -103,14 +100,9 @@ internal class ExceptionState private constructor(
|
||||
override fun toString(): String = message?.let { "$exceptionFqName: $it" } ?: exceptionFqName
|
||||
|
||||
companion object {
|
||||
private fun IrClass.getPropertyByName(name: String): IrProperty {
|
||||
val property = this.declarations.single { it.nameForIrSerialization.asString() == name } as IrProperty
|
||||
return (property.getter!!.getLastOverridden() as IrSimpleFunction).correspondingPropertySymbol!!.owner
|
||||
}
|
||||
|
||||
private fun evaluateFields(exception: Throwable, irClass: IrClass, stackTrace: List<String>): MutableList<Variable> {
|
||||
val messageProperty = irClass.getPropertyByName("message")
|
||||
val causeProperty = irClass.getPropertyByName("cause")
|
||||
val messageProperty = irClass.getOriginalPropertyByName("message")
|
||||
val causeProperty = irClass.getOriginalPropertyByName("cause")
|
||||
|
||||
val messageVar = Variable(messageProperty.symbol, exception.message.toState(messageProperty.getter!!.returnType))
|
||||
val causeVar = exception.cause?.let {
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
import kotlin.*
|
||||
import kotlin.collections.*
|
||||
|
||||
|
||||
Reference in New Issue
Block a user