Use original DeepCopyIrTree algorithm in visitCall
This commit is contained in:
committed by
KonstantinAnisimov
parent
fa86ef5399
commit
42955526bf
+49
-43
@@ -60,19 +60,6 @@ internal class DeepCopyIrTreeWithDescriptors(val targetDescriptor: DeclarationDe
|
|||||||
|
|
||||||
//-------------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
|
|
||||||
val descriptorSubstitutorForExternalScope = object : IrElementTransformerVoid() {
|
|
||||||
|
|
||||||
override fun visitCall(expression: IrCall): IrExpression {
|
|
||||||
val oldExpression = super.visitCall(expression) as IrCall
|
|
||||||
|
|
||||||
if (oldExpression is IrCallImpl)
|
|
||||||
return copyIrCallImpl(oldExpression)
|
|
||||||
return oldExpression
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------//
|
|
||||||
|
|
||||||
inner class DescriptorCollector: IrElementVisitorVoid {
|
inner class DescriptorCollector: IrElementVisitorVoid {
|
||||||
|
|
||||||
override fun visitElement(element: IrElement) {
|
override fun visitElement(element: IrElement) {
|
||||||
@@ -194,8 +181,8 @@ internal class DeepCopyIrTreeWithDescriptors(val targetDescriptor: DeclarationDe
|
|||||||
private fun copyFunctionDescriptor(oldDescriptor: CallableDescriptor): CallableDescriptor {
|
private fun copyFunctionDescriptor(oldDescriptor: CallableDescriptor): CallableDescriptor {
|
||||||
|
|
||||||
return when (oldDescriptor) {
|
return when (oldDescriptor) {
|
||||||
is ConstructorDescriptor -> copyConstructorDescriptor(oldDescriptor)
|
is ConstructorDescriptor -> copyConstructorDescriptor(oldDescriptor)
|
||||||
is SimpleFunctionDescriptor -> copySimpleFunctionDescriptor(oldDescriptor)
|
is SimpleFunctionDescriptor -> copySimpleFunctionDescriptor(oldDescriptor)
|
||||||
else -> TODO("Unsupported FunctionDescriptor subtype: $oldDescriptor")
|
else -> TODO("Unsupported FunctionDescriptor subtype: $oldDescriptor")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -417,10 +404,16 @@ internal class DeepCopyIrTreeWithDescriptors(val targetDescriptor: DeclarationDe
|
|||||||
//--- Visits ----------------------------------------------------------//
|
//--- Visits ----------------------------------------------------------//
|
||||||
|
|
||||||
override fun visitCall(expression: IrCall): IrCall {
|
override fun visitCall(expression: IrCall): IrCall {
|
||||||
val oldExpression = super.visitCall(expression)
|
if (expression !is IrCallImpl) return super.visitCall(expression)
|
||||||
if (oldExpression !is IrCallImpl) return oldExpression // TODO what other kinds of call can we meet?
|
return IrCallImpl(
|
||||||
|
startOffset = expression.startOffset,
|
||||||
return copyIrCallImpl(oldExpression)
|
endOffset = expression.endOffset,
|
||||||
|
type = substituteType(expression.type)!!,
|
||||||
|
descriptor = mapCallee(expression.descriptor),
|
||||||
|
typeArguments = substituteTypeArguments(expression.getTypeArgumentsMap()),
|
||||||
|
origin = expression.origin,
|
||||||
|
superQualifier = mapSuperQualifier(expression.superQualifier)
|
||||||
|
).transformValueArguments(expression)
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------//
|
//---------------------------------------------------------------------//
|
||||||
@@ -542,6 +535,43 @@ internal class DeepCopyIrTreeWithDescriptors(val targetDescriptor: DeclarationDe
|
|||||||
|
|
||||||
//-------------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
|
|
||||||
|
private fun substituteType(oldType: KotlinType?): KotlinType? {
|
||||||
|
if (typeSubstitutor == null) return oldType
|
||||||
|
if (oldType == null) return oldType
|
||||||
|
return typeSubstitutor!!.substitute(oldType, Variance.INVARIANT) ?: oldType
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------//
|
||||||
|
|
||||||
|
private fun substituteTypeArguments(oldTypeArguments: Map <TypeParameterDescriptor, KotlinType>?): Map <TypeParameterDescriptor, KotlinType>? {
|
||||||
|
|
||||||
|
if (oldTypeArguments == null) return null
|
||||||
|
if (typeSubstitutor == null) return oldTypeArguments
|
||||||
|
|
||||||
|
val newTypeArguments = oldTypeArguments.entries.associate {
|
||||||
|
val typeParameterDescriptor = it.key
|
||||||
|
val oldTypeArgument = it.value
|
||||||
|
val newTypeArgument = substituteType(oldTypeArgument)!!
|
||||||
|
typeParameterDescriptor to newTypeArgument
|
||||||
|
}
|
||||||
|
return newTypeArguments
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------//
|
||||||
|
|
||||||
|
val descriptorSubstitutorForExternalScope = object : IrElementTransformerVoid() {
|
||||||
|
|
||||||
|
override fun visitCall(expression: IrCall): IrExpression {
|
||||||
|
val oldExpression = super.visitCall(expression) as IrCall
|
||||||
|
|
||||||
|
if (oldExpression is IrCallImpl)
|
||||||
|
return copyIrCallImpl(oldExpression)
|
||||||
|
return oldExpression
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------//
|
||||||
|
|
||||||
private fun copyIrCallImpl(oldExpression: IrCallImpl): IrCallImpl {
|
private fun copyIrCallImpl(oldExpression: IrCallImpl): IrCallImpl {
|
||||||
|
|
||||||
val oldDescriptor = oldExpression.descriptor
|
val oldDescriptor = oldExpression.descriptor
|
||||||
@@ -569,30 +599,6 @@ internal class DeepCopyIrTreeWithDescriptors(val targetDescriptor: DeclarationDe
|
|||||||
|
|
||||||
return newExpression
|
return newExpression
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------//
|
|
||||||
|
|
||||||
private fun substituteType(oldType: KotlinType?): KotlinType? {
|
|
||||||
if (typeSubstitutor == null) return oldType
|
|
||||||
if (oldType == null) return oldType
|
|
||||||
return typeSubstitutor!!.substitute(oldType, Variance.INVARIANT) ?: oldType
|
|
||||||
}
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------//
|
|
||||||
|
|
||||||
private fun substituteTypeArguments(oldTypeArguments: Map <TypeParameterDescriptor, KotlinType>?): Map <TypeParameterDescriptor, KotlinType>? {
|
|
||||||
|
|
||||||
if (oldTypeArguments == null) return null
|
|
||||||
if (typeSubstitutor == null) return oldTypeArguments
|
|
||||||
|
|
||||||
val newTypeArguments = oldTypeArguments.entries.associate {
|
|
||||||
val typeParameterDescriptor = it.key
|
|
||||||
val oldTypeArgument = it.value
|
|
||||||
val newTypeArgument = substituteType(oldTypeArgument)!!
|
|
||||||
typeParameterDescriptor to newTypeArgument
|
|
||||||
}
|
|
||||||
return newTypeArguments
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user