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
|
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
|
if (this !is ReceiverParameterDescriptor || other !is ReceiverParameterDescriptor) return false
|
||||||
return when {
|
return when {
|
||||||
this.value is ImplicitClassReceiver && other.value is ImplicitClassReceiver -> this.value.type.isSubtypeOf(other.value.type)
|
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
|
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
|
package org.jetbrains.kotlin.backend.common.interpreter.stack
|
||||||
|
|
||||||
import org.jetbrains.kotlin.backend.common.interpreter.hasSameNameAs
|
import org.jetbrains.kotlin.backend.common.interpreter.equalTo
|
||||||
import org.jetbrains.kotlin.backend.common.interpreter.isSubtypeOf
|
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor
|
import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@@ -39,9 +38,8 @@ class InterpreterFrame(val pool: MutableList<Variable> = mutableListOf()) : Fram
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getVariableState(variableDescriptor: DeclarationDescriptor): State {
|
override fun getVariableState(variableDescriptor: DeclarationDescriptor): State {
|
||||||
return pool.firstOrNull {
|
return pool.firstOrNull { it.descriptor.equalTo(variableDescriptor) }?.state
|
||||||
it.descriptor.isSubtypeOf(variableDescriptor) || it.descriptor.hasSameNameAs(variableDescriptor) || it.descriptor == variableDescriptor
|
?: throw NoSuchElementException("Frame pool doesn't contains variable with descriptor $variableDescriptor")
|
||||||
}?.state ?: throw NoSuchElementException("Frame pool doesn't contains variable with descriptor $variableDescriptor")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getAll(): List<Variable> {
|
override fun getAll(): List<Variable> {
|
||||||
|
|||||||
+2
-5
@@ -5,8 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.backend.common.interpreter.stack
|
package org.jetbrains.kotlin.backend.common.interpreter.stack
|
||||||
|
|
||||||
import org.jetbrains.kotlin.backend.common.interpreter.hasSameNameAs
|
import org.jetbrains.kotlin.backend.common.interpreter.equalTo
|
||||||
import org.jetbrains.kotlin.backend.common.interpreter.isSubtypeOf
|
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
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? {
|
override fun getState(descriptor: DeclarationDescriptor): State? {
|
||||||
return values.firstOrNull {
|
return values.firstOrNull { it.descriptor.equalTo(descriptor) }?.state
|
||||||
it.descriptor.isSubtypeOf(descriptor) || it.descriptor.hasSameNameAs(descriptor) || it.descriptor == descriptor
|
|
||||||
}?.state
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setState(newVar: Variable) {
|
override fun setState(newVar: Variable) {
|
||||||
|
|||||||
Reference in New Issue
Block a user