[IR] Move extension val property into Utils for interpreter

This commit is contained in:
Ivan Kylchik
2023-05-08 09:53:23 +02:00
committed by Space Team
parent 70560fc3eb
commit e5c45a4e51
7 changed files with 12 additions and 12 deletions
@@ -145,7 +145,7 @@ internal class DefaultCallInterceptor(override val interpreter: IrInterpreter) :
}
private fun calculateBuiltIns(irFunction: IrFunction, args: List<State>) {
val methodName = when (val property = (irFunction as? IrSimpleFunction)?.correspondingPropertySymbol) {
val methodName = when (val property = irFunction.property?.symbol) {
null -> irFunction.name.asString()
else -> property.owner.name.asString()
}
@@ -114,7 +114,7 @@ internal fun createTempClass(name: Name, origin: IrDeclarationOrigin = TEMP_CLAS
}
internal fun IrFunction.createGetField(): IrExpression {
val backingField = (this as IrSimpleFunction).correspondingPropertySymbol?.owner?.backingField!!
val backingField = this.property!!.backingField!!
val receiver = dispatchReceiverParameter ?: extensionReceiverParameter
return backingField.createGetField(receiver)
}
@@ -219,7 +219,7 @@ internal fun IrFieldAccessExpression.accessesTopLevelOrObjectField(): Boolean {
internal fun IrClass.getOriginalPropertyByName(name: String): IrProperty {
val property = this.properties.single { it.name.asString() == name }
return (property.getter!!.getLastOverridden() as IrSimpleFunction).correspondingPropertySymbol!!.owner
return property.getter!!.getLastOverridden().property!!
}
internal fun IrFunctionAccessExpression.getFunctionThatContainsDefaults(): IrFunction {
@@ -342,3 +342,7 @@ internal fun IrEnumEntry.toState(irBuiltIns: IrBuiltIns): Common {
return enumClassObject
}
internal val IrFunction.property: IrProperty?
get() = (this as? IrSimpleFunction)?.correspondingPropertySymbol?.owner
@@ -116,6 +116,3 @@ enum class EvaluationMode {
return (this.parent as? IrClass)?.isMarkedWith(annotation) ?: false
}
}
private val IrFunction.property: IrProperty?
get() = (this as? IrSimpleFunction)?.correspondingPropertySymbol?.owner
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.ir.expressions.IrCall
import org.jetbrains.kotlin.ir.expressions.IrCallableReference
import org.jetbrains.kotlin.ir.expressions.IrGetEnumValue
import org.jetbrains.kotlin.ir.expressions.IrStringConcatenation
import org.jetbrains.kotlin.ir.interpreter.property
import org.jetbrains.kotlin.ir.util.isSubclassOf
class IrInterpreterNameChecker : IrInterpreterChecker {
@@ -35,9 +36,7 @@ class IrInterpreterNameChecker : IrInterpreterChecker {
fun IrCall.isKCallableNameCall(irBuiltIns: IrBuiltIns): Boolean {
if (this.dispatchReceiver !is IrCallableReference<*>) return false
val directMember = this.symbol.owner.let {
(it as? IrSimpleFunction)?.correspondingPropertySymbol?.owner ?: it
}
val directMember = this.symbol.owner.let { it.property ?: it }
val irClass = directMember.parent as? IrClass ?: return false
if (!irClass.isSubclassOf(irBuiltIns.kCallableClass.owner)) return false
@@ -53,7 +52,7 @@ class IrInterpreterNameChecker : IrInterpreterChecker {
private fun IrCall.isEnumName(): Boolean {
val owner = this.symbol.owner
if (owner.extensionReceiverParameter != null || owner.valueParameters.isNotEmpty()) return false
val property = (owner as? IrSimpleFunction)?.correspondingPropertySymbol?.owner ?: return false
val property = owner.property ?: return false
return this.dispatchReceiver is IrGetEnumValue && property.name.asString() == "name"
}
}
@@ -171,7 +171,7 @@ internal object EnumIntrinsics : IntrinsicBase() {
val enumEntry = callStack.loadState(irFunction.dispatchReceiverParameter!!.symbol)
when (irFunction.name.asString()) {
"<get-name>", "<get-ordinal>" -> {
val symbol = (irFunction as IrSimpleFunction).correspondingPropertySymbol!!
val symbol = irFunction.property!!.symbol
callStack.pushState(enumEntry.getField(symbol)!!)
}
"compareTo" -> {
@@ -64,7 +64,7 @@ internal class Wrapper(val value: Any, override val irClass: IrClass, environmen
fun getMethod(irFunction: IrFunction): MethodHandle? {
// if function is actually a getter, then use "get${property.name.capitalize()}" as method name
val propertyName = (irFunction as? IrSimpleFunction)?.correspondingPropertySymbol?.owner?.name?.asString()
val propertyName = irFunction.property?.name?.asString()
val propertyCall = listOfNotNull(propertyName, "get${propertyName?.capitalizeAsciiOnly()}")
.firstOrNull { receiverClass.methods.any { method -> method.name == it } }