Refactoring
This commit is contained in:
committed by
KonstantinAnisimov
parent
db50381bc9
commit
8690b00790
+180
-169
@@ -44,7 +44,9 @@ import org.jetbrains.kotlin.types.TypeSubstitutor
|
|||||||
import org.jetbrains.kotlin.types.Variance
|
import org.jetbrains.kotlin.types.Variance
|
||||||
import org.jetbrains.kotlin.types.typeUtil.makeNullable
|
import org.jetbrains.kotlin.types.typeUtil.makeNullable
|
||||||
|
|
||||||
internal class DeepCopyIrTreeWithDescriptors(val targetScope: ScopeWithIr, typeArgsMap: Map <TypeParameterDescriptor, KotlinType>?, val context: Context) {
|
internal class DeepCopyIrTreeWithDescriptors(val targetScope: ScopeWithIr,
|
||||||
|
typeArgsMap: Map <TypeParameterDescriptor, KotlinType>?,
|
||||||
|
val context: Context) {
|
||||||
|
|
||||||
private val descriptorSubstituteMap: MutableMap<DeclarationDescriptor, DeclarationDescriptor> = mutableMapOf()
|
private val descriptorSubstituteMap: MutableMap<DeclarationDescriptor, DeclarationDescriptor> = mutableMapOf()
|
||||||
private var typeSubstitutor = createTypeSubstitutor(typeArgsMap)
|
private var typeSubstitutor = createTypeSubstitutor(typeArgsMap)
|
||||||
@@ -70,10 +72,9 @@ internal class DeepCopyIrTreeWithDescriptors(val targetScope: ScopeWithIr, typeA
|
|||||||
override fun visitCall(expression: IrCall): IrExpression {
|
override fun visitCall(expression: IrCall): IrExpression {
|
||||||
val oldExpression = super.visitCall(expression) as IrCall
|
val oldExpression = super.visitCall(expression) as IrCall
|
||||||
|
|
||||||
return when (oldExpression) {
|
if (oldExpression is IrCallImpl)
|
||||||
is IrCallImpl -> copyIrCallImpl(oldExpression)
|
return copyIrCallImpl(oldExpression)
|
||||||
else -> oldExpression
|
return oldExpression
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,17 +83,16 @@ internal class DeepCopyIrTreeWithDescriptors(val targetScope: ScopeWithIr, typeA
|
|||||||
val newDescriptor = descriptorSubstituteMap.getOrDefault(oldDescriptor.original,
|
val newDescriptor = descriptorSubstituteMap.getOrDefault(oldDescriptor.original,
|
||||||
oldDescriptor) as FunctionDescriptor
|
oldDescriptor) as FunctionDescriptor
|
||||||
|
|
||||||
val oldSuperQualifier = oldExpression.superQualifier
|
val newSuperQualifier = oldExpression.superQualifier?.let { (descriptorSubstituteMap[it] ?: it) as ClassDescriptor }
|
||||||
val newSuperQualifier = oldSuperQualifier?.let { (descriptorSubstituteMap[it] ?: it) as ClassDescriptor }
|
|
||||||
|
|
||||||
val newExpression = IrCallImpl(
|
val newExpression = IrCallImpl(
|
||||||
oldExpression.startOffset,
|
startOffset = oldExpression.startOffset,
|
||||||
oldExpression.endOffset,
|
endOffset = oldExpression.endOffset,
|
||||||
substituteType(oldExpression.type)!!,
|
type = substituteType(oldExpression.type)!!,
|
||||||
newDescriptor,
|
descriptor = newDescriptor,
|
||||||
substituteTypeArguments(oldExpression.typeArguments),
|
typeArguments = substituteTypeArguments(oldExpression.typeArguments),
|
||||||
oldExpression.origin,
|
origin = oldExpression.origin,
|
||||||
newSuperQualifier
|
superQualifier = newSuperQualifier
|
||||||
).apply {
|
).apply {
|
||||||
oldExpression.descriptor.valueParameters.forEach {
|
oldExpression.descriptor.valueParameters.forEach {
|
||||||
val valueArgument = oldExpression.getValueArgument(it)
|
val valueArgument = oldExpression.getValueArgument(it)
|
||||||
@@ -109,23 +109,27 @@ internal class DeepCopyIrTreeWithDescriptors(val targetScope: ScopeWithIr, typeA
|
|||||||
|
|
||||||
inner class DescriptorCollector: IrElementVisitorVoidWithContext() {
|
inner class DescriptorCollector: IrElementVisitorVoidWithContext() {
|
||||||
|
|
||||||
|
override fun visitElement(element: IrElement) {
|
||||||
|
element.acceptChildren(this, null)
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------//
|
||||||
|
|
||||||
override fun visitClassNew(declaration: IrClass) {
|
override fun visitClassNew(declaration: IrClass) {
|
||||||
|
|
||||||
val oldDescriptor = declaration.descriptor
|
val oldDescriptor = declaration.descriptor
|
||||||
val newDescriptor = copyClassDescriptor(oldDescriptor)
|
val newDescriptor = copyClassDescriptor(oldDescriptor)
|
||||||
descriptorSubstituteMap[oldDescriptor] = newDescriptor
|
descriptorSubstituteMap[oldDescriptor] = newDescriptor
|
||||||
descriptorSubstituteMap[oldDescriptor.thisAsReceiverParameter] = newDescriptor.thisAsReceiverParameter
|
descriptorSubstituteMap[oldDescriptor.thisAsReceiverParameter] = newDescriptor.thisAsReceiverParameter
|
||||||
|
|
||||||
super.visitClassNew(declaration)
|
super.visitClassNew(declaration)
|
||||||
|
|
||||||
val constructors = oldDescriptor.constructors.map { oldConstructorDescriptor ->
|
val constructors = oldDescriptor.constructors.map { oldConstructorDescriptor ->
|
||||||
descriptorSubstituteMap[oldConstructorDescriptor] as ClassConstructorDescriptor
|
descriptorSubstituteMap[oldConstructorDescriptor] as ClassConstructorDescriptor
|
||||||
}.toSet()
|
}.toSet()
|
||||||
|
|
||||||
var primaryConstructor: ClassConstructorDescriptor? = null
|
|
||||||
val oldPrimaryConstructor = oldDescriptor.unsubstitutedPrimaryConstructor
|
val oldPrimaryConstructor = oldDescriptor.unsubstitutedPrimaryConstructor
|
||||||
if (oldPrimaryConstructor != null) {
|
val primaryConstructor = oldPrimaryConstructor?.let { descriptorSubstituteMap[it] as ClassConstructorDescriptor }
|
||||||
primaryConstructor = descriptorSubstituteMap[oldPrimaryConstructor] as ClassConstructorDescriptor
|
|
||||||
}
|
|
||||||
|
|
||||||
val contributedDescriptors = oldDescriptor.unsubstitutedMemberScope
|
val contributedDescriptors = oldDescriptor.unsubstitutedMemberScope
|
||||||
.getContributedDescriptors()
|
.getContributedDescriptors()
|
||||||
@@ -144,6 +148,7 @@ internal class DeepCopyIrTreeWithDescriptors(val targetScope: ScopeWithIr, typeA
|
|||||||
//---------------------------------------------------------------------//
|
//---------------------------------------------------------------------//
|
||||||
|
|
||||||
private fun copyPropertyOrField(oldDescriptor: PropertyDescriptor) {
|
private fun copyPropertyOrField(oldDescriptor: PropertyDescriptor) {
|
||||||
|
|
||||||
val newDescriptor = copyPropertyDescriptor(oldDescriptor)
|
val newDescriptor = copyPropertyDescriptor(oldDescriptor)
|
||||||
descriptorSubstituteMap[oldDescriptor] = newDescriptor
|
descriptorSubstituteMap[oldDescriptor] = newDescriptor
|
||||||
oldDescriptor.getter?.let {
|
oldDescriptor.getter?.let {
|
||||||
@@ -155,16 +160,20 @@ internal class DeepCopyIrTreeWithDescriptors(val targetScope: ScopeWithIr, typeA
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun visitPropertyNew(declaration: IrProperty) {
|
override fun visitPropertyNew(declaration: IrProperty) {
|
||||||
|
|
||||||
copyPropertyOrField(declaration.descriptor)
|
copyPropertyOrField(declaration.descriptor)
|
||||||
|
|
||||||
super.visitPropertyNew(declaration)
|
super.visitPropertyNew(declaration)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitFieldNew(declaration: IrField) {
|
override fun visitFieldNew(declaration: IrField) {
|
||||||
|
|
||||||
val oldDescriptor = declaration.descriptor
|
val oldDescriptor = declaration.descriptor
|
||||||
if (descriptorSubstituteMap[oldDescriptor] == null) {
|
if (descriptorSubstituteMap[oldDescriptor] == null) {
|
||||||
// A field without a property or a field of a delegated property.
|
// A field without a property or a field of a delegated property.
|
||||||
copyPropertyOrField(oldDescriptor)
|
copyPropertyOrField(oldDescriptor)
|
||||||
}
|
}
|
||||||
|
|
||||||
super.visitFieldNew(declaration)
|
super.visitFieldNew(declaration)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,6 +186,7 @@ internal class DeepCopyIrTreeWithDescriptors(val targetScope: ScopeWithIr, typeA
|
|||||||
val newDescriptor = copyFunctionDescriptor(oldDescriptor)
|
val newDescriptor = copyFunctionDescriptor(oldDescriptor)
|
||||||
descriptorSubstituteMap[oldDescriptor] = newDescriptor
|
descriptorSubstituteMap[oldDescriptor] = newDescriptor
|
||||||
}
|
}
|
||||||
|
|
||||||
super.visitFunctionNew(declaration)
|
super.visitFunctionNew(declaration)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,11 +201,12 @@ internal class DeepCopyIrTreeWithDescriptors(val targetScope: ScopeWithIr, typeA
|
|||||||
val containingDeclaration = (targetScope.scope.scopeOwner as? CallableDescriptor) ?: oldDescriptor
|
val containingDeclaration = (targetScope.scope.scopeOwner as? CallableDescriptor) ?: oldDescriptor
|
||||||
val newReturnType = substituteType(oldDescriptor.returnType)!!
|
val newReturnType = substituteType(oldDescriptor.returnType)!!
|
||||||
val newValueParameters = copyValueParameters(oldDescriptor.valueParameters, containingDeclaration)
|
val newValueParameters = copyValueParameters(oldDescriptor.valueParameters, containingDeclaration)
|
||||||
val newDescriptor = oldDescriptor.newCopyBuilder().apply {
|
val newDescriptor = oldDescriptor
|
||||||
setReturnType(newReturnType)
|
.newCopyBuilder()
|
||||||
setValueParameters(newValueParameters)
|
.setReturnType(newReturnType)
|
||||||
setOriginal(oldDescriptor.original)
|
.setValueParameters(newValueParameters)
|
||||||
}.build()
|
.setOriginal(oldDescriptor.original)
|
||||||
|
.build()
|
||||||
descriptorSubstituteMap[oldDescriptor] = newDescriptor!!
|
descriptorSubstituteMap[oldDescriptor] = newDescriptor!!
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,20 +219,15 @@ internal class DeepCopyIrTreeWithDescriptors(val targetScope: ScopeWithIr, typeA
|
|||||||
|
|
||||||
val oldDescriptor = declaration.descriptor
|
val oldDescriptor = declaration.descriptor
|
||||||
val newDescriptor = IrTemporaryVariableDescriptorImpl(
|
val newDescriptor = IrTemporaryVariableDescriptorImpl(
|
||||||
targetScope.scope.scopeOwner,
|
containingDeclaration = targetScope.scope.scopeOwner,
|
||||||
generateName(oldDescriptor.name),
|
name = generateName(oldDescriptor.name),
|
||||||
substituteType(oldDescriptor.type)!!,
|
outType = substituteType(oldDescriptor.type)!!,
|
||||||
oldDescriptor.isVar)
|
isMutable = oldDescriptor.isVar)
|
||||||
descriptorSubstituteMap[oldDescriptor] = newDescriptor
|
descriptorSubstituteMap[oldDescriptor] = newDescriptor
|
||||||
|
|
||||||
super.visitVariable(declaration)
|
super.visitVariable(declaration)
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------//
|
|
||||||
|
|
||||||
override fun visitElement(element: IrElement) {
|
|
||||||
element.acceptChildren(this, null)
|
|
||||||
}
|
|
||||||
|
|
||||||
//--- Copy descriptors ------------------------------------------------//
|
//--- Copy descriptors ------------------------------------------------//
|
||||||
|
|
||||||
private fun generateName(name: Name): Name {
|
private fun generateName(name: Name): Name {
|
||||||
@@ -239,7 +245,7 @@ internal class DeepCopyIrTreeWithDescriptors(val targetScope: ScopeWithIr, typeA
|
|||||||
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")
|
else -> TODO("Unsupported FunctionDescriptor subtype: $oldDescriptor")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -249,34 +255,33 @@ internal class DeepCopyIrTreeWithDescriptors(val targetScope: ScopeWithIr, typeA
|
|||||||
|
|
||||||
val newContainingDeclaration = parentScope?.let { descriptorSubstituteMap[it.scope.scopeOwner] } ?: targetScope.scope.scopeOwner
|
val newContainingDeclaration = parentScope?.let { descriptorSubstituteMap[it.scope.scopeOwner] } ?: targetScope.scope.scopeOwner
|
||||||
|
|
||||||
val newDescriptor = SimpleFunctionDescriptorImpl.create(
|
return SimpleFunctionDescriptorImpl.create(
|
||||||
newContainingDeclaration,
|
/* containingDeclaration = */ newContainingDeclaration,
|
||||||
oldDescriptor.annotations,
|
/* annotations = */ oldDescriptor.annotations,
|
||||||
generateName(oldDescriptor.name),
|
/* name = */ generateName(oldDescriptor.name),
|
||||||
CallableMemberDescriptor.Kind.SYNTHESIZED,
|
/* kind = */ oldDescriptor.kind,
|
||||||
oldDescriptor.source
|
/* source = */ oldDescriptor.source
|
||||||
).apply { isTailrec = oldDescriptor.isTailrec }
|
).apply {
|
||||||
|
|
||||||
val oldDispatchReceiverParameter = oldDescriptor.dispatchReceiverParameter
|
val oldDispatchReceiverParameter = oldDescriptor.dispatchReceiverParameter
|
||||||
val newDispatchReceiverParameter =
|
val newDispatchReceiverParameter = oldDispatchReceiverParameter?.let { descriptorSubstituteMap[it] as ReceiverParameterDescriptor }
|
||||||
if (oldDispatchReceiverParameter == null) null
|
val newTypeParameters = oldDescriptor.typeParameters // TODO substitute types
|
||||||
else descriptorSubstituteMap[oldDispatchReceiverParameter]
|
val newValueParameters = copyValueParameters(oldDescriptor.valueParameters, this)
|
||||||
val newTypeParameters = oldDescriptor.typeParameters // TODO substitute types
|
val newReceiverParameterType = substituteType(oldDescriptor.extensionReceiverParameter?.type)
|
||||||
val newValueParameters = copyValueParameters(oldDescriptor.valueParameters, newDescriptor)
|
val newReturnType = substituteType(oldDescriptor.returnType)
|
||||||
val receiverParameterType = substituteType(oldDescriptor.extensionReceiverParameter?.type)
|
|
||||||
val newReturnType = substituteType(oldDescriptor.returnType)
|
|
||||||
|
|
||||||
newDescriptor.initialize(
|
initialize(
|
||||||
receiverParameterType,
|
/* receiverParameterType = */ newReceiverParameterType,
|
||||||
newDispatchReceiverParameter as? ReceiverParameterDescriptor,
|
/* dispatchReceiverParameter = */ newDispatchReceiverParameter,
|
||||||
newTypeParameters,
|
/* typeParameters = */ newTypeParameters,
|
||||||
newValueParameters,
|
/* unsubstitutedValueParameters = */ newValueParameters,
|
||||||
newReturnType,
|
/* unsubstitutedReturnType = */ newReturnType,
|
||||||
oldDescriptor.modality,
|
/* modality = */ oldDescriptor.modality,
|
||||||
oldDescriptor.visibility
|
/* visibility = */ oldDescriptor.visibility
|
||||||
)
|
)
|
||||||
newDescriptor.overriddenDescriptors += oldDescriptor.overriddenDescriptors
|
isTailrec = oldDescriptor.isTailrec
|
||||||
return newDescriptor
|
overriddenDescriptors += oldDescriptor.overriddenDescriptors
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------//
|
//---------------------------------------------------------------------//
|
||||||
@@ -284,65 +289,66 @@ internal class DeepCopyIrTreeWithDescriptors(val targetScope: ScopeWithIr, typeA
|
|||||||
private fun copyConstructorDescriptor(oldDescriptor: ConstructorDescriptor) : FunctionDescriptor {
|
private fun copyConstructorDescriptor(oldDescriptor: ConstructorDescriptor) : FunctionDescriptor {
|
||||||
|
|
||||||
val containingDeclaration = parentScope?.let { descriptorSubstituteMap[it.scope.scopeOwner] } as ClassDescriptor
|
val containingDeclaration = parentScope?.let { descriptorSubstituteMap[it.scope.scopeOwner] } as ClassDescriptor
|
||||||
val newDescriptor = ClassConstructorDescriptorImpl.create(
|
return ClassConstructorDescriptorImpl.create(
|
||||||
containingDeclaration,
|
/* containingDeclaration = */ containingDeclaration,
|
||||||
oldDescriptor.annotations,
|
/* annotations = */ oldDescriptor.annotations,
|
||||||
oldDescriptor.isPrimary,
|
/* isPrimary = */ oldDescriptor.isPrimary,
|
||||||
oldDescriptor.source
|
/* source = */ oldDescriptor.source
|
||||||
)
|
).apply {
|
||||||
|
|
||||||
val newTypeParameters = oldDescriptor.typeParameters
|
val newTypeParameters = oldDescriptor.typeParameters
|
||||||
val newValueParameters = copyValueParameters(oldDescriptor.valueParameters, newDescriptor)
|
val newValueParameters = copyValueParameters(oldDescriptor.valueParameters, this)
|
||||||
val receiverParameterType = substituteType(oldDescriptor.dispatchReceiverParameter?.type)
|
val receiverParameterType = substituteType(oldDescriptor.dispatchReceiverParameter?.type)
|
||||||
val returnType = substituteType(oldDescriptor.returnType)
|
val returnType = substituteType(oldDescriptor.returnType)
|
||||||
assert(newTypeParameters.isEmpty())
|
assert(newTypeParameters.isEmpty())
|
||||||
|
|
||||||
newDescriptor.initialize(
|
initialize(
|
||||||
receiverParameterType,
|
/* receiverParameterType = */ receiverParameterType,
|
||||||
null, // TODO @Nullable ReceiverParameterDescriptor dispatchReceiverParameter,
|
/* dispatchReceiverParameter = */ null, // For constructor there is no explicit dispatch receiver.
|
||||||
newTypeParameters,
|
/* typeParameters = */ newTypeParameters,
|
||||||
newValueParameters,
|
/* unsubstitutedValueParameters = */ newValueParameters,
|
||||||
returnType,
|
/* unsubstitutedReturnType = */ returnType,
|
||||||
oldDescriptor.modality,
|
/* modality = */ oldDescriptor.modality,
|
||||||
oldDescriptor.visibility
|
/* visibility = */ oldDescriptor.visibility
|
||||||
)
|
)
|
||||||
return newDescriptor
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------//
|
//---------------------------------------------------------------------//
|
||||||
|
|
||||||
private fun copyPropertyDescriptor(oldDescriptor: PropertyDescriptor): PropertyDescriptor {
|
private fun copyPropertyDescriptor(oldDescriptor: PropertyDescriptor): PropertyDescriptor {
|
||||||
|
|
||||||
val memberOwner = currentClass?.let { descriptorSubstituteMap[it.scope.scopeOwner] } as ClassDescriptor
|
val memberOwner = currentClass?.let { descriptorSubstituteMap[it.scope.scopeOwner] } as ClassDescriptor
|
||||||
val newDescriptor = PropertyDescriptorImpl.create(
|
return PropertyDescriptorImpl.create(
|
||||||
memberOwner,
|
/* containingDeclaration = */ memberOwner,
|
||||||
oldDescriptor.annotations,
|
/* annotations = */ oldDescriptor.annotations,
|
||||||
oldDescriptor.modality,
|
/* modality = */ oldDescriptor.modality,
|
||||||
oldDescriptor.visibility,
|
/* visibility = */ oldDescriptor.visibility,
|
||||||
oldDescriptor.isVar,
|
/* isVar = */ oldDescriptor.isVar,
|
||||||
oldDescriptor.name,
|
/* name = */ oldDescriptor.name,
|
||||||
oldDescriptor.kind,
|
/* kind = */ oldDescriptor.kind,
|
||||||
oldDescriptor.source,
|
/* source = */ oldDescriptor.source,
|
||||||
oldDescriptor.isLateInit,
|
/* lateInit = */ oldDescriptor.isLateInit,
|
||||||
oldDescriptor.isConst,
|
/* isConst = */ oldDescriptor.isConst,
|
||||||
oldDescriptor.isHeader,
|
/* isHeader = */ oldDescriptor.isHeader,
|
||||||
oldDescriptor.isImpl,
|
/* isImpl = */ oldDescriptor.isImpl,
|
||||||
oldDescriptor.isExternal,
|
/* isExternal = */ oldDescriptor.isExternal,
|
||||||
oldDescriptor.isDelegated)
|
/* isDelegated = */ oldDescriptor.isDelegated
|
||||||
|
).apply {
|
||||||
|
|
||||||
newDescriptor.setType(
|
setType(
|
||||||
oldDescriptor.type,
|
/* outType = */ oldDescriptor.type,
|
||||||
oldDescriptor.typeParameters,
|
/* typeParameters = */ oldDescriptor.typeParameters,
|
||||||
memberOwner.thisAsReceiverParameter,
|
/* dispatchReceiverParameter = */ memberOwner.thisAsReceiverParameter,
|
||||||
oldDescriptor.extensionReceiverParameter?.type)
|
/* receiverType = */ oldDescriptor.extensionReceiverParameter?.type)
|
||||||
|
|
||||||
newDescriptor.initialize(
|
initialize(
|
||||||
oldDescriptor.getter?.let { copyPropertyGetterDescriptor(it, newDescriptor) },
|
/* getter = */ oldDescriptor.getter?.let { copyPropertyGetterDescriptor(it, this) },
|
||||||
oldDescriptor.setter?.let { copyPropertySetterDescriptor(it, newDescriptor) })
|
/* setter = */ oldDescriptor.setter?.let { copyPropertySetterDescriptor(it, this) })
|
||||||
|
|
||||||
newDescriptor.overriddenDescriptors += oldDescriptor.overriddenDescriptors
|
overriddenDescriptors += oldDescriptor.overriddenDescriptors
|
||||||
|
}
|
||||||
return newDescriptor
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------//
|
//---------------------------------------------------------------------//
|
||||||
@@ -351,16 +357,16 @@ internal class DeepCopyIrTreeWithDescriptors(val targetScope: ScopeWithIr, typeA
|
|||||||
: PropertyGetterDescriptorImpl {
|
: PropertyGetterDescriptorImpl {
|
||||||
|
|
||||||
return PropertyGetterDescriptorImpl(
|
return PropertyGetterDescriptorImpl(
|
||||||
newPropertyDescriptor,
|
/* correspondingProperty = */ newPropertyDescriptor,
|
||||||
oldDescriptor.annotations,
|
/* annotations = */ oldDescriptor.annotations,
|
||||||
oldDescriptor.modality,
|
/* modality = */ oldDescriptor.modality,
|
||||||
oldDescriptor.visibility,
|
/* visibility = */ oldDescriptor.visibility,
|
||||||
oldDescriptor.isDefault,
|
/* isDefault = */ oldDescriptor.isDefault,
|
||||||
oldDescriptor.isExternal,
|
/* isExternal = */ oldDescriptor.isExternal,
|
||||||
oldDescriptor.isInline,
|
/* isInline = */ oldDescriptor.isInline,
|
||||||
oldDescriptor.kind,
|
/* kind = */ oldDescriptor.kind,
|
||||||
null,
|
/* original = */ null,
|
||||||
oldDescriptor.source).apply {
|
/* source = */ oldDescriptor.source).apply {
|
||||||
initialize(oldDescriptor.returnType)
|
initialize(oldDescriptor.returnType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -371,16 +377,16 @@ internal class DeepCopyIrTreeWithDescriptors(val targetScope: ScopeWithIr, typeA
|
|||||||
: PropertySetterDescriptorImpl {
|
: PropertySetterDescriptorImpl {
|
||||||
|
|
||||||
return PropertySetterDescriptorImpl(
|
return PropertySetterDescriptorImpl(
|
||||||
newPropertyDescriptor,
|
/* correspondingProperty = */ newPropertyDescriptor,
|
||||||
oldDescriptor.annotations,
|
/* annotations = */ oldDescriptor.annotations,
|
||||||
oldDescriptor.modality,
|
/* modality = */ oldDescriptor.modality,
|
||||||
oldDescriptor.visibility,
|
/* visibility = */ oldDescriptor.visibility,
|
||||||
oldDescriptor.isDefault,
|
/* isDefault = */ oldDescriptor.isDefault,
|
||||||
oldDescriptor.isExternal,
|
/* isExternal = */ oldDescriptor.isExternal,
|
||||||
oldDescriptor.isInline,
|
/* isInline = */ oldDescriptor.isInline,
|
||||||
oldDescriptor.kind,
|
/* kind = */ oldDescriptor.kind,
|
||||||
null,
|
/* original = */ null,
|
||||||
oldDescriptor.source).apply {
|
/* source = */ oldDescriptor.source).apply {
|
||||||
initialize(copyValueParameters(oldDescriptor.valueParameters, this).single())
|
initialize(copyValueParameters(oldDescriptor.valueParameters, this).single())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -397,20 +403,20 @@ internal class DeepCopyIrTreeWithDescriptors(val targetScope: ScopeWithIr, typeA
|
|||||||
else
|
else
|
||||||
generateName(oldDescriptor.name)
|
generateName(oldDescriptor.name)
|
||||||
return ClassDescriptorImpl(
|
return ClassDescriptorImpl(
|
||||||
newContainingDeclaration,
|
/* containingDeclaration = */ newContainingDeclaration,
|
||||||
newName,
|
/* name = */ newName,
|
||||||
oldDescriptor.modality,
|
/* modality = */ oldDescriptor.modality,
|
||||||
oldDescriptor.kind,
|
/* kind = */ oldDescriptor.kind,
|
||||||
listOf(newSuperClass.defaultType),
|
/* supertypes = */ listOf(newSuperClass.defaultType),
|
||||||
oldDescriptor.source,
|
/* source = */ oldDescriptor.source,
|
||||||
oldDescriptor.isExternal
|
/* isExternal = */ oldDescriptor.isExternal
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------//
|
//-----------------------------------------------------------------------------//
|
||||||
|
|
||||||
inner class InlineCopyIr() : DeepCopyIrTree() {
|
inner class InlineCopyIr : DeepCopyIrTree() {
|
||||||
|
|
||||||
override fun mapClassDeclaration (descriptor: ClassDescriptor) = descriptorSubstituteMap.getOrDefault(descriptor, descriptor) as ClassDescriptor
|
override fun mapClassDeclaration (descriptor: ClassDescriptor) = descriptorSubstituteMap.getOrDefault(descriptor, descriptor) as ClassDescriptor
|
||||||
override fun mapTypeAliasDeclaration (descriptor: TypeAliasDescriptor) = descriptorSubstituteMap.getOrDefault(descriptor, descriptor) as TypeAliasDescriptor
|
override fun mapTypeAliasDeclaration (descriptor: TypeAliasDescriptor) = descriptorSubstituteMap.getOrDefault(descriptor, descriptor) as TypeAliasDescriptor
|
||||||
@@ -455,10 +461,11 @@ internal class DeepCopyIrTreeWithDescriptors(val targetScope: ScopeWithIr, typeA
|
|||||||
|
|
||||||
override fun visitFunction(declaration: IrFunction): IrFunction =
|
override fun visitFunction(declaration: IrFunction): IrFunction =
|
||||||
IrFunctionImpl(
|
IrFunctionImpl(
|
||||||
declaration.startOffset, declaration.endOffset,
|
startOffset = declaration.startOffset,
|
||||||
mapDeclarationOrigin(declaration.origin),
|
endOffset = declaration.endOffset,
|
||||||
mapFunctionDeclaration(declaration.descriptor),
|
origin = mapDeclarationOrigin(declaration.origin),
|
||||||
declaration.body?.transform(this, null)
|
descriptor = mapFunctionDeclaration(declaration.descriptor),
|
||||||
|
body = declaration.body?.transform(this, null)
|
||||||
).transformDefaults(declaration)
|
).transformDefaults(declaration)
|
||||||
|
|
||||||
//---------------------------------------------------------------------//
|
//---------------------------------------------------------------------//
|
||||||
@@ -477,11 +484,12 @@ internal class DeepCopyIrTreeWithDescriptors(val targetScope: ScopeWithIr, typeA
|
|||||||
|
|
||||||
override fun visitCallableReference(expression: IrCallableReference): IrCallableReference =
|
override fun visitCallableReference(expression: IrCallableReference): IrCallableReference =
|
||||||
IrCallableReferenceImpl(
|
IrCallableReferenceImpl(
|
||||||
expression.startOffset, expression.endOffset,
|
startOffset = expression.startOffset,
|
||||||
substituteType(expression.type)!!,
|
endOffset = expression.endOffset,
|
||||||
mapCallableReference(expression.descriptor),
|
type = substituteType(expression.type)!!,
|
||||||
expression.getTypeArgumentsMap(),
|
descriptor = mapCallableReference(expression.descriptor),
|
||||||
mapStatementOrigin(expression.origin)
|
typeArguments = expression.getTypeArgumentsMap(),
|
||||||
|
origin = mapStatementOrigin(expression.origin)
|
||||||
).transformValueArguments(expression)
|
).transformValueArguments(expression)
|
||||||
|
|
||||||
//---------------------------------------------------------------------//
|
//---------------------------------------------------------------------//
|
||||||
@@ -506,11 +514,12 @@ internal class DeepCopyIrTreeWithDescriptors(val targetScope: ScopeWithIr, typeA
|
|||||||
val typeOperand = substituteType(expression.typeOperand)!!
|
val typeOperand = substituteType(expression.typeOperand)!!
|
||||||
val returnType = getTypeOperatorReturnType(expression.operator, typeOperand)
|
val returnType = getTypeOperatorReturnType(expression.operator, typeOperand)
|
||||||
return IrTypeOperatorCallImpl(
|
return IrTypeOperatorCallImpl(
|
||||||
expression.startOffset, expression.endOffset,
|
startOffset = expression.startOffset,
|
||||||
returnType,
|
endOffset = expression.endOffset,
|
||||||
expression.operator,
|
type = returnType,
|
||||||
typeOperand,
|
operator = expression.operator,
|
||||||
expression.argument.transform(this, null)
|
typeOperand = typeOperand,
|
||||||
|
argument = expression.argument.transform(this, null)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -518,10 +527,11 @@ internal class DeepCopyIrTreeWithDescriptors(val targetScope: ScopeWithIr, typeA
|
|||||||
|
|
||||||
override fun visitReturn(expression: IrReturn): IrReturn =
|
override fun visitReturn(expression: IrReturn): IrReturn =
|
||||||
IrReturnImpl(
|
IrReturnImpl(
|
||||||
expression.startOffset, expression.endOffset,
|
startOffset = expression.startOffset,
|
||||||
substituteType(expression.type)!!,
|
endOffset = expression.endOffset,
|
||||||
mapReturnTarget(expression.returnTarget),
|
type = substituteType(expression.type)!!,
|
||||||
expression.value.transform(this, null)
|
returnTarget = mapReturnTarget(expression.returnTarget),
|
||||||
|
value = expression.value.transform(this, null)
|
||||||
)
|
)
|
||||||
|
|
||||||
//---------------------------------------------------------------------//
|
//---------------------------------------------------------------------//
|
||||||
@@ -529,11 +539,12 @@ internal class DeepCopyIrTreeWithDescriptors(val targetScope: ScopeWithIr, typeA
|
|||||||
override fun visitBlock(expression: IrBlock): IrBlock {
|
override fun visitBlock(expression: IrBlock): IrBlock {
|
||||||
return if (expression is IrInlineFunctionBody) {
|
return if (expression is IrInlineFunctionBody) {
|
||||||
IrInlineFunctionBody(
|
IrInlineFunctionBody(
|
||||||
expression.startOffset, expression.endOffset,
|
startOffset = expression.startOffset,
|
||||||
expression.type,
|
endOffset = expression.endOffset,
|
||||||
expression.descriptor,
|
type = expression.type,
|
||||||
mapStatementOrigin(expression.origin),
|
descriptor = expression.descriptor,
|
||||||
expression.statements.map { it.transform(this, null) }
|
origin = mapStatementOrigin(expression.origin),
|
||||||
|
statements = expression.statements.map { it.transform(this, null) }
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
super.visitBlock(expression)
|
super.visitBlock(expression)
|
||||||
@@ -547,17 +558,17 @@ internal class DeepCopyIrTreeWithDescriptors(val targetScope: ScopeWithIr, typeA
|
|||||||
|
|
||||||
return oldValueParameters.map { oldDescriptor ->
|
return oldValueParameters.map { oldDescriptor ->
|
||||||
val newDescriptor = ValueParameterDescriptorImpl(
|
val newDescriptor = ValueParameterDescriptorImpl(
|
||||||
containingDeclaration,
|
containingDeclaration = containingDeclaration,
|
||||||
oldDescriptor.original,
|
original = oldDescriptor.original,
|
||||||
oldDescriptor.index,
|
index = oldDescriptor.index,
|
||||||
oldDescriptor.annotations,
|
annotations = oldDescriptor.annotations,
|
||||||
oldDescriptor.name,
|
name = oldDescriptor.name,
|
||||||
substituteType(oldDescriptor.type)!!,
|
outType = substituteType(oldDescriptor.type)!!,
|
||||||
oldDescriptor.declaresDefaultValue(),
|
declaresDefaultValue = oldDescriptor.declaresDefaultValue(),
|
||||||
oldDescriptor.isCrossinline,
|
isCrossinline = oldDescriptor.isCrossinline,
|
||||||
oldDescriptor.isNoinline,
|
isNoinline = oldDescriptor.isNoinline,
|
||||||
substituteType(oldDescriptor.varargElementType),
|
varargElementType = substituteType(oldDescriptor.varargElementType),
|
||||||
oldDescriptor.source
|
source = oldDescriptor.source
|
||||||
)
|
)
|
||||||
descriptorSubstituteMap[oldDescriptor] = newDescriptor
|
descriptorSubstituteMap[oldDescriptor] = newDescriptor
|
||||||
newDescriptor
|
newDescriptor
|
||||||
|
|||||||
+8
-5
@@ -297,12 +297,15 @@ internal class FunctionInlining(val context: Context): IrElementTransformerVoidW
|
|||||||
return@forEach
|
return@forEach
|
||||||
}
|
}
|
||||||
|
|
||||||
val varName = currentScope!!.scope.scopeOwner.name.toString() + "_inline"
|
val currentScope = currentScope!!
|
||||||
val newVar = currentScope!!.scope.createTemporaryVariable(argument, varName, false) // Create new variable and init it with the parameter expression.
|
val varName = currentScope.scope.scopeOwner.name.toString() + "_inline"
|
||||||
statements.add(newVar) // Add initialization of the new variable in statement list.
|
val newVar = currentScope.scope.createTemporaryVariable(argument, varName, false) // Create new variable and init it with the parameter expression.
|
||||||
|
statements.add(newVar) // Add initialization of the new variable in statement list.
|
||||||
|
|
||||||
val getVal = IrGetValueImpl(0, 0, newVar.descriptor) // Create new IR element representing access the new variable.
|
val startOffset = currentScope.irElement.startOffset
|
||||||
parametersNew[parameter] = getVal // Parameter will be replaced with the new variable.
|
val endOffset = currentScope.irElement.endOffset
|
||||||
|
val getVal = IrGetValueImpl(startOffset, endOffset, newVar.descriptor) // Create new IR element representing access the new variable.
|
||||||
|
parametersNew[parameter] = getVal // Parameter will be replaced with the new variable.
|
||||||
}
|
}
|
||||||
return EvaluatedParameters(parametersNew, statements)
|
return EvaluatedParameters(parametersNew, statements)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user