Implement equalTo function for descriptors
This commit is contained in:
+6
-2
@@ -117,7 +117,11 @@ fun IrFunctionAccessExpression.getBody(): IrBody? {
|
||||
return this.symbol.owner.body
|
||||
}
|
||||
|
||||
fun DeclarationDescriptor.isSubtypeOf(other: DeclarationDescriptor): Boolean {
|
||||
fun DeclarationDescriptor.equalTo(other: DeclarationDescriptor): Boolean {
|
||||
return this.isSubtypeOf(other) || this.hasSameNameAs(other) || this == other
|
||||
}
|
||||
|
||||
private fun DeclarationDescriptor.isSubtypeOf(other: DeclarationDescriptor): Boolean {
|
||||
if (this !is ReceiverParameterDescriptor || other !is ReceiverParameterDescriptor) return false
|
||||
return when {
|
||||
this.value is ImplicitClassReceiver && other.value is ImplicitClassReceiver -> this.value.type.isSubtypeOf(other.value.type)
|
||||
@@ -126,7 +130,7 @@ fun DeclarationDescriptor.isSubtypeOf(other: DeclarationDescriptor): Boolean {
|
||||
}
|
||||
}
|
||||
|
||||
fun DeclarationDescriptor.hasSameNameAs(other: DeclarationDescriptor): Boolean {
|
||||
private fun DeclarationDescriptor.hasSameNameAs(other: DeclarationDescriptor): Boolean {
|
||||
return this is ValueParameterDescriptor && other is ValueParameterDescriptor && this.name == other.name
|
||||
}
|
||||
|
||||
|
||||
+3
-5
@@ -5,8 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.common.interpreter.stack
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.interpreter.hasSameNameAs
|
||||
import org.jetbrains.kotlin.backend.common.interpreter.isSubtypeOf
|
||||
import org.jetbrains.kotlin.backend.common.interpreter.equalTo
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor
|
||||
import java.util.*
|
||||
@@ -39,9 +38,8 @@ class InterpreterFrame(val pool: MutableList<Variable> = mutableListOf()) : Fram
|
||||
}
|
||||
|
||||
override fun getVariableState(variableDescriptor: DeclarationDescriptor): State {
|
||||
return pool.firstOrNull {
|
||||
it.descriptor.isSubtypeOf(variableDescriptor) || it.descriptor.hasSameNameAs(variableDescriptor) || it.descriptor == variableDescriptor
|
||||
}?.state ?: throw NoSuchElementException("Frame pool doesn't contains variable with descriptor $variableDescriptor")
|
||||
return pool.firstOrNull { it.descriptor.equalTo(variableDescriptor) }?.state
|
||||
?: throw NoSuchElementException("Frame pool doesn't contains variable with descriptor $variableDescriptor")
|
||||
}
|
||||
|
||||
override fun getAll(): List<Variable> {
|
||||
|
||||
+2
-5
@@ -5,8 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.common.interpreter.stack
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.interpreter.hasSameNameAs
|
||||
import org.jetbrains.kotlin.backend.common.interpreter.isSubtypeOf
|
||||
import org.jetbrains.kotlin.backend.common.interpreter.equalTo
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||
@@ -62,9 +61,7 @@ class Complex(private var classOfObject: IrClass, private val values: MutableLis
|
||||
}
|
||||
|
||||
override fun getState(descriptor: DeclarationDescriptor): State? {
|
||||
return values.firstOrNull {
|
||||
it.descriptor.isSubtypeOf(descriptor) || it.descriptor.hasSameNameAs(descriptor) || it.descriptor == descriptor
|
||||
}?.state
|
||||
return values.firstOrNull { it.descriptor.equalTo(descriptor) }?.state
|
||||
}
|
||||
|
||||
override fun setState(newVar: Variable) {
|
||||
|
||||
Reference in New Issue
Block a user