Removed descriptors usage from IR copier
This commit is contained in:
+2
-1
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.descriptors.VariableDescriptor
|
|||||||
import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor
|
import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor
|
||||||
import org.jetbrains.kotlin.ir.IrElement
|
import org.jetbrains.kotlin.ir.IrElement
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrLoop
|
import org.jetbrains.kotlin.ir.expressions.IrLoop
|
||||||
|
import org.jetbrains.kotlin.ir.util.DeepCopyIrTreeWithSymbols
|
||||||
import org.jetbrains.kotlin.ir.util.DeepCopySymbolRemapper
|
import org.jetbrains.kotlin.ir.util.DeepCopySymbolRemapper
|
||||||
import org.jetbrains.kotlin.ir.util.DeepCopyTypeRemapper
|
import org.jetbrains.kotlin.ir.util.DeepCopyTypeRemapper
|
||||||
import org.jetbrains.kotlin.ir.util.DescriptorsRemapper
|
import org.jetbrains.kotlin.ir.util.DescriptorsRemapper
|
||||||
@@ -45,7 +46,7 @@ fun <T : IrElement> T.deepCopyWithVariables(): T {
|
|||||||
val typesRemapper = DeepCopyTypeRemapper(symbolsRemapper)
|
val typesRemapper = DeepCopyTypeRemapper(symbolsRemapper)
|
||||||
|
|
||||||
return this.transform(
|
return this.transform(
|
||||||
object : DeepCopyIrTreeWithReturnableBlockSymbols(symbolsRemapper, typesRemapper) {
|
object : DeepCopyIrTreeWithSymbols(symbolsRemapper, typesRemapper) {
|
||||||
override fun getNonTransformedLoop(irLoop: IrLoop): IrLoop {
|
override fun getNonTransformedLoop(irLoop: IrLoop): IrLoop {
|
||||||
return irLoop
|
return irLoop
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,68 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2017 JetBrains s.r.o.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.backend.common
|
|
||||||
|
|
||||||
import org.jetbrains.kotlin.ir.IrElement
|
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrBlock
|
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrReturn
|
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrReturnableBlock
|
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.IrReturnImpl
|
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.IrReturnableBlockImpl
|
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrReturnableBlockSymbol
|
|
||||||
import org.jetbrains.kotlin.ir.util.DeepCopyIrTreeWithSymbols
|
|
||||||
import org.jetbrains.kotlin.ir.util.SymbolRemapper
|
|
||||||
import org.jetbrains.kotlin.ir.util.TypeRemapper
|
|
||||||
|
|
||||||
open class DeepCopyIrTreeWithReturnableBlockSymbols(
|
|
||||||
symbolRemapper: SymbolRemapper,
|
|
||||||
typeRemapper: TypeRemapper
|
|
||||||
) : DeepCopyIrTreeWithSymbols(symbolRemapper, typeRemapper) {
|
|
||||||
|
|
||||||
private inline fun <reified T : IrElement> T.transform() =
|
|
||||||
transform(this@DeepCopyIrTreeWithReturnableBlockSymbols, null) as T
|
|
||||||
|
|
||||||
private val transformedReturnableBlocks = mutableMapOf<IrReturnableBlock, IrReturnableBlock>()
|
|
||||||
|
|
||||||
override fun visitBlock(expression: IrBlock): IrBlock = if (expression is IrReturnableBlock) {
|
|
||||||
IrReturnableBlockImpl(
|
|
||||||
expression.startOffset, expression.endOffset,
|
|
||||||
expression.type,
|
|
||||||
expression.descriptor,
|
|
||||||
expression.origin,
|
|
||||||
expression.sourceFileName
|
|
||||||
).also {
|
|
||||||
transformedReturnableBlocks.put(expression, it)
|
|
||||||
it.statements.addAll(expression.statements.map { it.transform() })
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
super.visitBlock(expression)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun visitReturn(expression: IrReturn): IrReturn {
|
|
||||||
val returnTargetSymbol = expression.returnTargetSymbol
|
|
||||||
return if (returnTargetSymbol is IrReturnableBlockSymbol) {
|
|
||||||
IrReturnImpl(
|
|
||||||
expression.startOffset, expression.endOffset,
|
|
||||||
expression.type,
|
|
||||||
transformedReturnableBlocks.getOrElse(returnTargetSymbol.owner) { returnTargetSymbol.owner }.symbol,
|
|
||||||
expression.value.transform()
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
super.visitReturn(expression)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+43
-2
@@ -19,6 +19,7 @@ import org.jetbrains.kotlin.resolve.scopes.LazyScopeAdapter
|
|||||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||||
import org.jetbrains.kotlin.resolve.scopes.TypeIntersectionScope
|
import org.jetbrains.kotlin.resolve.scopes.TypeIntersectionScope
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExtensionReceiver
|
import org.jetbrains.kotlin.resolve.scopes.receivers.ExtensionReceiver
|
||||||
|
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||||
import org.jetbrains.kotlin.storage.StorageManager
|
import org.jetbrains.kotlin.storage.StorageManager
|
||||||
import org.jetbrains.kotlin.types.*
|
import org.jetbrains.kotlin.types.*
|
||||||
@@ -130,6 +131,43 @@ open class WrappedValueParameterDescriptor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open class WrappedReceiverParameterDescriptor(
|
||||||
|
annotations: Annotations = Annotations.EMPTY,
|
||||||
|
sourceElement: SourceElement = SourceElement.NO_SOURCE
|
||||||
|
) : ReceiverParameterDescriptor, WrappedCallableDescriptor<IrValueParameter>(annotations, sourceElement) {
|
||||||
|
|
||||||
|
override fun getValue(): ReceiverValue {
|
||||||
|
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getContainingDeclaration(): DeclarationDescriptor =
|
||||||
|
(owner.parent as? IrFunction)?.descriptor ?: (owner.parent as IrClass).descriptor
|
||||||
|
|
||||||
|
override fun getType() = owner.type.toKotlinType()
|
||||||
|
override fun getName() = owner.name
|
||||||
|
|
||||||
|
override fun copy(newOwner: DeclarationDescriptor) = object : WrappedReceiverParameterDescriptor() {
|
||||||
|
override fun getContainingDeclaration() = newOwner
|
||||||
|
}.also { it.bind(owner) }
|
||||||
|
|
||||||
|
override fun getOverriddenDescriptors(): Collection<ValueParameterDescriptor> = emptyList()
|
||||||
|
|
||||||
|
override fun getOriginal() = this
|
||||||
|
|
||||||
|
override fun substitute(substitutor: TypeSubstitutor): ReceiverParameterDescriptor {
|
||||||
|
TODO("")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getReturnType(): KotlinType? = owner.type.toKotlinType()
|
||||||
|
|
||||||
|
override fun <R : Any?, D : Any?> accept(visitor: DeclarationDescriptorVisitor<R, D>?, data: D) =
|
||||||
|
visitor!!.visitReceiverParameterDescriptor(this, data)!!
|
||||||
|
|
||||||
|
override fun acceptVoid(visitor: DeclarationDescriptorVisitor<Void, Void>?) {
|
||||||
|
visitor!!.visitReceiverParameterDescriptor(this, null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
open class WrappedTypeParameterDescriptor(
|
open class WrappedTypeParameterDescriptor(
|
||||||
annotations: Annotations = Annotations.EMPTY,
|
annotations: Annotations = Annotations.EMPTY,
|
||||||
sourceElement: SourceElement = SourceElement.NO_SOURCE
|
sourceElement: SourceElement = SourceElement.NO_SOURCE
|
||||||
@@ -223,6 +261,7 @@ open class WrappedVariableDescriptor(
|
|||||||
|
|
||||||
override fun <R, D> accept(visitor: DeclarationDescriptorVisitor<R, D>?, data: D): R =
|
override fun <R, D> accept(visitor: DeclarationDescriptorVisitor<R, D>?, data: D): R =
|
||||||
visitor!!.visitVariableDescriptor(this, data)
|
visitor!!.visitVariableDescriptor(this, data)
|
||||||
|
|
||||||
override fun acceptVoid(visitor: DeclarationDescriptorVisitor<Void, Void>?) {
|
override fun acceptVoid(visitor: DeclarationDescriptorVisitor<Void, Void>?) {
|
||||||
visitor!!.visitVariableDescriptor(this, null)
|
visitor!!.visitVariableDescriptor(this, null)
|
||||||
}
|
}
|
||||||
@@ -255,6 +294,7 @@ open class WrappedSimpleFunctionDescriptor(
|
|||||||
.asSequence()
|
.asSequence()
|
||||||
.mapNotNull { it.descriptor as? ValueParameterDescriptor }
|
.mapNotNull { it.descriptor as? ValueParameterDescriptor }
|
||||||
.toMutableList()
|
.toMutableList()
|
||||||
|
|
||||||
override fun isExternal() = owner.isExternal
|
override fun isExternal() = owner.isExternal
|
||||||
override fun isSuspend() = owner.isSuspend
|
override fun isSuspend() = owner.isSuspend
|
||||||
override fun isTailrec() = owner.isTailrec
|
override fun isTailrec() = owner.isTailrec
|
||||||
@@ -321,6 +361,7 @@ open class WrappedClassConstructorDescriptor(
|
|||||||
override fun getDispatchReceiverParameter() = owner.dispatchReceiverParameter?.run {
|
override fun getDispatchReceiverParameter() = owner.dispatchReceiverParameter?.run {
|
||||||
(containingDeclaration.containingDeclaration as ClassDescriptor).thisAsReceiverParameter
|
(containingDeclaration.containingDeclaration as ClassDescriptor).thisAsReceiverParameter
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getTypeParameters() = owner.typeParameters.map { it.descriptor }
|
override fun getTypeParameters() = owner.typeParameters.map { it.descriptor }
|
||||||
override fun getValueParameters() = owner.valueParameters.asSequence()
|
override fun getValueParameters() = owner.valueParameters.asSequence()
|
||||||
.mapNotNull { it.descriptor as? ValueParameterDescriptor }
|
.mapNotNull { it.descriptor as? ValueParameterDescriptor }
|
||||||
@@ -409,9 +450,9 @@ open class WrappedClassDescriptor(
|
|||||||
) : ClassDescriptor, WrappedDeclarationDescriptor<IrClass>(annotations) {
|
) : ClassDescriptor, WrappedDeclarationDescriptor<IrClass>(annotations) {
|
||||||
override fun getName() = owner.name
|
override fun getName() = owner.name
|
||||||
|
|
||||||
override fun getMemberScope(typeArguments: MutableList<out TypeProjection>)= MemberScope.Empty
|
override fun getMemberScope(typeArguments: MutableList<out TypeProjection>) = MemberScope.Empty
|
||||||
|
|
||||||
override fun getMemberScope(typeSubstitution: TypeSubstitution)= MemberScope.Empty
|
override fun getMemberScope(typeSubstitution: TypeSubstitution) = MemberScope.Empty
|
||||||
|
|
||||||
override fun getUnsubstitutedMemberScope() = MemberScope.Empty
|
override fun getUnsubstitutedMemberScope() = MemberScope.Empty
|
||||||
|
|
||||||
|
|||||||
@@ -35,13 +35,14 @@ class IrCallImpl(
|
|||||||
override val symbol: IrFunctionSymbol,
|
override val symbol: IrFunctionSymbol,
|
||||||
override val descriptor: FunctionDescriptor,
|
override val descriptor: FunctionDescriptor,
|
||||||
typeArgumentsCount: Int,
|
typeArgumentsCount: Int,
|
||||||
|
valueArgumentsCount: Int,
|
||||||
origin: IrStatementOrigin? = null,
|
origin: IrStatementOrigin? = null,
|
||||||
override val superQualifierSymbol: IrClassSymbol? = null
|
override val superQualifierSymbol: IrClassSymbol? = null
|
||||||
) :
|
) :
|
||||||
IrCallWithIndexedArgumentsBase(
|
IrCallWithIndexedArgumentsBase(
|
||||||
startOffset, endOffset, type,
|
startOffset, endOffset, type,
|
||||||
typeArgumentsCount,
|
typeArgumentsCount,
|
||||||
symbol.descriptor.valueParameters.size,
|
valueArgumentsCount,
|
||||||
origin
|
origin
|
||||||
),
|
),
|
||||||
IrCall {
|
IrCall {
|
||||||
@@ -54,7 +55,20 @@ class IrCallImpl(
|
|||||||
descriptor: FunctionDescriptor,
|
descriptor: FunctionDescriptor,
|
||||||
origin: IrStatementOrigin? = null,
|
origin: IrStatementOrigin? = null,
|
||||||
superQualifierSymbol: IrClassSymbol? = null
|
superQualifierSymbol: IrClassSymbol? = null
|
||||||
) : this(startOffset, endOffset, type, symbol, descriptor, descriptor.typeParametersCount, origin, superQualifierSymbol)
|
) : this(startOffset, endOffset, type, symbol, descriptor, descriptor.typeParametersCount,
|
||||||
|
descriptor.valueParameters.size, origin, superQualifierSymbol)
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
startOffset: Int,
|
||||||
|
endOffset: Int,
|
||||||
|
type: IrType,
|
||||||
|
symbol: IrFunctionSymbol,
|
||||||
|
descriptor: FunctionDescriptor,
|
||||||
|
typeArgumentsCount: Int,
|
||||||
|
origin: IrStatementOrigin? = null,
|
||||||
|
superQualifierSymbol: IrClassSymbol? = null
|
||||||
|
) : this(startOffset, endOffset, type, symbol, descriptor, typeArgumentsCount,
|
||||||
|
descriptor.valueParameters.size, origin, superQualifierSymbol)
|
||||||
|
|
||||||
@Deprecated("Creates unbound symbols")
|
@Deprecated("Creates unbound symbols")
|
||||||
constructor(
|
constructor(
|
||||||
@@ -71,6 +85,7 @@ class IrCallImpl(
|
|||||||
createFunctionSymbol(descriptor),
|
createFunctionSymbol(descriptor),
|
||||||
descriptor,
|
descriptor,
|
||||||
typeArgumentsCount,
|
typeArgumentsCount,
|
||||||
|
descriptor.valueParameters.size,
|
||||||
origin,
|
origin,
|
||||||
createClassSymbolOrNull(superQualifierDescriptor)
|
createClassSymbolOrNull(superQualifierDescriptor)
|
||||||
)
|
)
|
||||||
|
|||||||
+15
-4
@@ -30,14 +30,15 @@ class IrDelegatingConstructorCallImpl(
|
|||||||
type: IrType,
|
type: IrType,
|
||||||
override val symbol: IrConstructorSymbol,
|
override val symbol: IrConstructorSymbol,
|
||||||
override val descriptor: ClassConstructorDescriptor,
|
override val descriptor: ClassConstructorDescriptor,
|
||||||
typeArgumentsCount: Int
|
typeArgumentsCount: Int,
|
||||||
|
valueArgumentsCount: Int
|
||||||
) :
|
) :
|
||||||
IrCallWithIndexedArgumentsBase(
|
IrCallWithIndexedArgumentsBase(
|
||||||
startOffset,
|
startOffset,
|
||||||
endOffset,
|
endOffset,
|
||||||
type,
|
type,
|
||||||
typeArgumentsCount = typeArgumentsCount,
|
typeArgumentsCount = typeArgumentsCount,
|
||||||
valueArgumentsCount = symbol.descriptor.valueParameters.size
|
valueArgumentsCount = valueArgumentsCount
|
||||||
),
|
),
|
||||||
IrDelegatingConstructorCall {
|
IrDelegatingConstructorCall {
|
||||||
|
|
||||||
@@ -47,7 +48,16 @@ class IrDelegatingConstructorCallImpl(
|
|||||||
type: IrType,
|
type: IrType,
|
||||||
symbol: IrConstructorSymbol,
|
symbol: IrConstructorSymbol,
|
||||||
descriptor: ClassConstructorDescriptor
|
descriptor: ClassConstructorDescriptor
|
||||||
) : this(startOffset, endOffset, type, symbol, descriptor, descriptor.typeParametersCount)
|
) : this(startOffset, endOffset, type, symbol, descriptor, descriptor.typeParametersCount, descriptor.valueParameters.size)
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
startOffset: Int,
|
||||||
|
endOffset: Int,
|
||||||
|
type: IrType,
|
||||||
|
symbol: IrConstructorSymbol,
|
||||||
|
descriptor: ClassConstructorDescriptor,
|
||||||
|
typeArgumentsCount: Int
|
||||||
|
) : this(startOffset, endOffset, type, symbol, descriptor, typeArgumentsCount, descriptor.valueParameters.size)
|
||||||
|
|
||||||
@Deprecated("Creates unbound symbol")
|
@Deprecated("Creates unbound symbol")
|
||||||
constructor(
|
constructor(
|
||||||
@@ -60,7 +70,8 @@ class IrDelegatingConstructorCallImpl(
|
|||||||
startOffset, endOffset, type,
|
startOffset, endOffset, type,
|
||||||
IrConstructorSymbolImpl(descriptor.original),
|
IrConstructorSymbolImpl(descriptor.original),
|
||||||
descriptor,
|
descriptor,
|
||||||
typeArgumentsCount
|
typeArgumentsCount,
|
||||||
|
descriptor.valueParameters.size
|
||||||
)
|
)
|
||||||
|
|
||||||
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R {
|
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R {
|
||||||
|
|||||||
+13
-4
@@ -29,14 +29,15 @@ class IrEnumConstructorCallImpl(
|
|||||||
endOffset: Int,
|
endOffset: Int,
|
||||||
type: IrType,
|
type: IrType,
|
||||||
override val symbol: IrConstructorSymbol,
|
override val symbol: IrConstructorSymbol,
|
||||||
typeArgumentsCount: Int
|
typeArgumentsCount: Int,
|
||||||
|
valueArgumentsCount: Int
|
||||||
) :
|
) :
|
||||||
IrCallWithIndexedArgumentsBase(
|
IrCallWithIndexedArgumentsBase(
|
||||||
startOffset,
|
startOffset,
|
||||||
endOffset,
|
endOffset,
|
||||||
type,
|
type,
|
||||||
typeArgumentsCount = typeArgumentsCount,
|
typeArgumentsCount = typeArgumentsCount,
|
||||||
valueArgumentsCount = symbol.descriptor.valueParameters.size
|
valueArgumentsCount = valueArgumentsCount
|
||||||
),
|
),
|
||||||
IrEnumConstructorCall {
|
IrEnumConstructorCall {
|
||||||
|
|
||||||
@@ -45,7 +46,15 @@ class IrEnumConstructorCallImpl(
|
|||||||
endOffset: Int,
|
endOffset: Int,
|
||||||
type: IrType,
|
type: IrType,
|
||||||
symbol: IrConstructorSymbol
|
symbol: IrConstructorSymbol
|
||||||
) : this(startOffset, endOffset, type, symbol, symbol.descriptor.typeParametersCount)
|
) : this(startOffset, endOffset, type, symbol, symbol.descriptor.typeParametersCount, symbol.descriptor.valueParameters.size)
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
startOffset: Int,
|
||||||
|
endOffset: Int,
|
||||||
|
type: IrType,
|
||||||
|
symbol: IrConstructorSymbol,
|
||||||
|
typeArgumentsCount: Int
|
||||||
|
) : this(startOffset, endOffset, type, symbol, typeArgumentsCount, symbol.descriptor.valueParameters.size)
|
||||||
|
|
||||||
@Deprecated("Creates unbound symbols")
|
@Deprecated("Creates unbound symbols")
|
||||||
constructor(
|
constructor(
|
||||||
@@ -54,7 +63,7 @@ class IrEnumConstructorCallImpl(
|
|||||||
type: IrType,
|
type: IrType,
|
||||||
descriptor: ClassConstructorDescriptor,
|
descriptor: ClassConstructorDescriptor,
|
||||||
typeArgumentsCount: Int
|
typeArgumentsCount: Int
|
||||||
) : this(startOffset, endOffset, type, IrConstructorSymbolImpl(descriptor), typeArgumentsCount)
|
) : this(startOffset, endOffset, type, IrConstructorSymbolImpl(descriptor), typeArgumentsCount, descriptor.valueParameters.size)
|
||||||
|
|
||||||
override val descriptor: ClassConstructorDescriptor get() = symbol.descriptor
|
override val descriptor: ClassConstructorDescriptor get() = symbol.descriptor
|
||||||
|
|
||||||
|
|||||||
+14
-2
@@ -31,6 +31,7 @@ class IrFunctionReferenceImpl(
|
|||||||
override val symbol: IrFunctionSymbol,
|
override val symbol: IrFunctionSymbol,
|
||||||
override val descriptor: FunctionDescriptor,
|
override val descriptor: FunctionDescriptor,
|
||||||
typeArgumentsCount: Int,
|
typeArgumentsCount: Int,
|
||||||
|
valueArgumentsCount: Int,
|
||||||
origin: IrStatementOrigin? = null
|
origin: IrStatementOrigin? = null
|
||||||
) :
|
) :
|
||||||
IrCallWithIndexedArgumentsBase(
|
IrCallWithIndexedArgumentsBase(
|
||||||
@@ -38,11 +39,21 @@ class IrFunctionReferenceImpl(
|
|||||||
endOffset,
|
endOffset,
|
||||||
type,
|
type,
|
||||||
typeArgumentsCount,
|
typeArgumentsCount,
|
||||||
symbol.descriptor.valueParameters.size,
|
valueArgumentsCount,
|
||||||
origin
|
origin
|
||||||
),
|
),
|
||||||
IrFunctionReference {
|
IrFunctionReference {
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
startOffset: Int,
|
||||||
|
endOffset: Int,
|
||||||
|
type: IrType,
|
||||||
|
symbol: IrFunctionSymbol,
|
||||||
|
descriptor: FunctionDescriptor,
|
||||||
|
typeArgumentsCount: Int,
|
||||||
|
origin: IrStatementOrigin? = null
|
||||||
|
): this(startOffset, endOffset, type, symbol, descriptor, typeArgumentsCount, descriptor.valueParameters.size, origin)
|
||||||
|
|
||||||
@Deprecated("Creates unbound symbol")
|
@Deprecated("Creates unbound symbol")
|
||||||
constructor(
|
constructor(
|
||||||
startOffset: Int,
|
startOffset: Int,
|
||||||
@@ -51,7 +62,8 @@ class IrFunctionReferenceImpl(
|
|||||||
descriptor: FunctionDescriptor,
|
descriptor: FunctionDescriptor,
|
||||||
typeArgumentsCount: Int,
|
typeArgumentsCount: Int,
|
||||||
origin: IrStatementOrigin? = null
|
origin: IrStatementOrigin? = null
|
||||||
) : this(startOffset, endOffset, type, createFunctionSymbol(descriptor.original), descriptor, typeArgumentsCount, origin)
|
) : this(startOffset, endOffset, type, createFunctionSymbol(descriptor.original), descriptor,
|
||||||
|
typeArgumentsCount, descriptor.valueParameters.size, origin)
|
||||||
|
|
||||||
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
|
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
|
||||||
visitor.visitFunctionReference(this, data)
|
visitor.visitFunctionReference(this, data)
|
||||||
|
|||||||
+100
-29
@@ -27,6 +27,8 @@ import org.jetbrains.kotlin.ir.symbols.impl.IrAnonymousInitializerSymbolImpl
|
|||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
||||||
import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
||||||
|
import org.jetbrains.kotlin.name.FqName
|
||||||
|
import org.jetbrains.kotlin.name.Name
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
inline fun <reified T : IrElement> T.deepCopyWithSymbols(initialParent: IrDeclarationParent? = null): T {
|
inline fun <reified T : IrElement> T.deepCopyWithSymbols(initialParent: IrDeclarationParent? = null): T {
|
||||||
@@ -36,10 +38,24 @@ inline fun <reified T : IrElement> T.deepCopyWithSymbols(initialParent: IrDeclar
|
|||||||
return transform(DeepCopyIrTreeWithSymbols(symbolRemapper, typeRemapper), null).patchDeclarationParents(initialParent) as T
|
return transform(DeepCopyIrTreeWithSymbols(symbolRemapper, typeRemapper), null).patchDeclarationParents(initialParent) as T
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface SymbolRenamer {
|
||||||
|
fun getClassName(symbol: IrClassSymbol): Name = symbol.owner.name
|
||||||
|
fun getFunctionName(symbol: IrSimpleFunctionSymbol): Name = symbol.owner.name
|
||||||
|
fun getFieldName(symbol: IrFieldSymbol): Name = symbol.owner.name
|
||||||
|
fun getFileName(symbol: IrFileSymbol): FqName = symbol.owner.fqName
|
||||||
|
fun getExternalPackageFragmentName(symbol: IrExternalPackageFragmentSymbol): FqName = symbol.owner.fqName
|
||||||
|
fun getEnumEntryName(symbol: IrEnumEntrySymbol): Name = symbol.owner.name
|
||||||
|
fun getVariableName(symbol: IrVariableSymbol): Name = symbol.owner.name
|
||||||
|
fun getTypeParameterName(symbol: IrTypeParameterSymbol): Name = symbol.owner.name
|
||||||
|
fun getValueParameterName(symbol: IrValueParameterSymbol): Name = symbol.owner.name
|
||||||
|
|
||||||
|
object DEFAULT : SymbolRenamer
|
||||||
|
}
|
||||||
|
|
||||||
open class DeepCopyIrTreeWithSymbols(
|
open class DeepCopyIrTreeWithSymbols(
|
||||||
private val symbolRemapper: SymbolRemapper,
|
private val symbolRemapper: SymbolRemapper,
|
||||||
private val typeRemapper: TypeRemapper
|
private val typeRemapper: TypeRemapper,
|
||||||
|
private val symbolRenamer: SymbolRenamer = SymbolRenamer.DEFAULT
|
||||||
) : IrElementTransformerVoid() {
|
) : IrElementTransformerVoid() {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@@ -78,7 +94,8 @@ open class DeepCopyIrTreeWithSymbols(
|
|||||||
|
|
||||||
override fun visitExternalPackageFragment(declaration: IrExternalPackageFragment, data: Nothing?): IrExternalPackageFragment =
|
override fun visitExternalPackageFragment(declaration: IrExternalPackageFragment, data: Nothing?): IrExternalPackageFragment =
|
||||||
IrExternalPackageFragmentImpl(
|
IrExternalPackageFragmentImpl(
|
||||||
symbolRemapper.getDeclaredExternalPackageFragment(declaration.symbol)
|
symbolRemapper.getDeclaredExternalPackageFragment(declaration.symbol),
|
||||||
|
symbolRenamer.getExternalPackageFragmentName(declaration.symbol)
|
||||||
).apply {
|
).apply {
|
||||||
declaration.transformDeclarationsTo(this)
|
declaration.transformDeclarationsTo(this)
|
||||||
}
|
}
|
||||||
@@ -86,7 +103,8 @@ open class DeepCopyIrTreeWithSymbols(
|
|||||||
override fun visitFile(declaration: IrFile): IrFile =
|
override fun visitFile(declaration: IrFile): IrFile =
|
||||||
IrFileImpl(
|
IrFileImpl(
|
||||||
declaration.fileEntry,
|
declaration.fileEntry,
|
||||||
symbolRemapper.getDeclaredFile(declaration.symbol)
|
symbolRemapper.getDeclaredFile(declaration.symbol),
|
||||||
|
symbolRenamer.getFileName(declaration.symbol)
|
||||||
).apply {
|
).apply {
|
||||||
transformAnnotations(declaration)
|
transformAnnotations(declaration)
|
||||||
fileAnnotations.addAll(declaration.fileAnnotations)
|
fileAnnotations.addAll(declaration.fileAnnotations)
|
||||||
@@ -100,7 +118,16 @@ open class DeepCopyIrTreeWithSymbols(
|
|||||||
IrClassImpl(
|
IrClassImpl(
|
||||||
declaration.startOffset, declaration.endOffset,
|
declaration.startOffset, declaration.endOffset,
|
||||||
mapDeclarationOrigin(declaration.origin),
|
mapDeclarationOrigin(declaration.origin),
|
||||||
symbolRemapper.getDeclaredClass(declaration.symbol)
|
symbolRemapper.getDeclaredClass(declaration.symbol),
|
||||||
|
symbolRenamer.getClassName(declaration.symbol),
|
||||||
|
declaration.kind,
|
||||||
|
declaration.visibility,
|
||||||
|
declaration.modality,
|
||||||
|
declaration.isCompanion,
|
||||||
|
declaration.isInner,
|
||||||
|
declaration.isData,
|
||||||
|
declaration.isExternal,
|
||||||
|
declaration.isInline
|
||||||
).apply {
|
).apply {
|
||||||
transformAnnotations(declaration)
|
transformAnnotations(declaration)
|
||||||
copyTypeParametersFrom(declaration)
|
copyTypeParametersFrom(declaration)
|
||||||
@@ -124,7 +151,14 @@ open class DeepCopyIrTreeWithSymbols(
|
|||||||
IrFunctionImpl(
|
IrFunctionImpl(
|
||||||
declaration.startOffset, declaration.endOffset,
|
declaration.startOffset, declaration.endOffset,
|
||||||
mapDeclarationOrigin(declaration.origin),
|
mapDeclarationOrigin(declaration.origin),
|
||||||
symbolRemapper.getDeclaredFunction(declaration.symbol)
|
symbolRemapper.getDeclaredFunction(declaration.symbol),
|
||||||
|
symbolRenamer.getFunctionName(declaration.symbol),
|
||||||
|
declaration.visibility,
|
||||||
|
declaration.modality,
|
||||||
|
declaration.isInline,
|
||||||
|
declaration.isExternal,
|
||||||
|
declaration.isTailrec,
|
||||||
|
declaration.isSuspend
|
||||||
).apply {
|
).apply {
|
||||||
declaration.overriddenSymbols.mapTo(overriddenSymbols) {
|
declaration.overriddenSymbols.mapTo(overriddenSymbols) {
|
||||||
symbolRemapper.getReferencedFunction(it) as IrSimpleFunctionSymbol
|
symbolRemapper.getReferencedFunction(it) as IrSimpleFunctionSymbol
|
||||||
@@ -136,7 +170,12 @@ open class DeepCopyIrTreeWithSymbols(
|
|||||||
IrConstructorImpl(
|
IrConstructorImpl(
|
||||||
declaration.startOffset, declaration.endOffset,
|
declaration.startOffset, declaration.endOffset,
|
||||||
mapDeclarationOrigin(declaration.origin),
|
mapDeclarationOrigin(declaration.origin),
|
||||||
symbolRemapper.getDeclaredConstructor(declaration.symbol)
|
symbolRemapper.getDeclaredConstructor(declaration.symbol),
|
||||||
|
declaration.name,
|
||||||
|
declaration.visibility,
|
||||||
|
declaration.isInline,
|
||||||
|
declaration.isExternal,
|
||||||
|
declaration.isPrimary
|
||||||
).apply {
|
).apply {
|
||||||
transformFunctionChildren(declaration)
|
transformFunctionChildren(declaration)
|
||||||
}
|
}
|
||||||
@@ -163,7 +202,7 @@ open class DeepCopyIrTreeWithSymbols(
|
|||||||
declaration.startOffset, declaration.endOffset,
|
declaration.startOffset, declaration.endOffset,
|
||||||
mapDeclarationOrigin(declaration.origin),
|
mapDeclarationOrigin(declaration.origin),
|
||||||
declaration.isDelegated,
|
declaration.isDelegated,
|
||||||
declaration.descriptor,
|
declaration.descriptor, // TODO
|
||||||
declaration.backingField?.transform(),
|
declaration.backingField?.transform(),
|
||||||
declaration.getter?.transform(),
|
declaration.getter?.transform(),
|
||||||
declaration.setter?.transform()
|
declaration.setter?.transform()
|
||||||
@@ -176,7 +215,12 @@ open class DeepCopyIrTreeWithSymbols(
|
|||||||
declaration.startOffset, declaration.endOffset,
|
declaration.startOffset, declaration.endOffset,
|
||||||
mapDeclarationOrigin(declaration.origin),
|
mapDeclarationOrigin(declaration.origin),
|
||||||
symbolRemapper.getDeclaredField(declaration.symbol),
|
symbolRemapper.getDeclaredField(declaration.symbol),
|
||||||
declaration.type.remapType()
|
symbolRenamer.getFieldName(declaration.symbol),
|
||||||
|
declaration.type.remapType(),
|
||||||
|
declaration.visibility,
|
||||||
|
declaration.isFinal,
|
||||||
|
declaration.isExternal,
|
||||||
|
declaration.isStatic
|
||||||
).apply {
|
).apply {
|
||||||
transformAnnotations(declaration)
|
transformAnnotations(declaration)
|
||||||
declaration.overriddenSymbols.mapTo(overriddenSymbols) {
|
declaration.overriddenSymbols.mapTo(overriddenSymbols) {
|
||||||
@@ -189,7 +233,7 @@ open class DeepCopyIrTreeWithSymbols(
|
|||||||
IrLocalDelegatedPropertyImpl(
|
IrLocalDelegatedPropertyImpl(
|
||||||
declaration.startOffset, declaration.endOffset,
|
declaration.startOffset, declaration.endOffset,
|
||||||
mapDeclarationOrigin(declaration.origin),
|
mapDeclarationOrigin(declaration.origin),
|
||||||
declaration.descriptor,
|
declaration.descriptor, // TODO
|
||||||
declaration.type.remapType(),
|
declaration.type.remapType(),
|
||||||
declaration.delegate.transform(),
|
declaration.delegate.transform(),
|
||||||
declaration.getter.transform(),
|
declaration.getter.transform(),
|
||||||
@@ -202,7 +246,8 @@ open class DeepCopyIrTreeWithSymbols(
|
|||||||
IrEnumEntryImpl(
|
IrEnumEntryImpl(
|
||||||
declaration.startOffset, declaration.endOffset,
|
declaration.startOffset, declaration.endOffset,
|
||||||
mapDeclarationOrigin(declaration.origin),
|
mapDeclarationOrigin(declaration.origin),
|
||||||
symbolRemapper.getDeclaredEnumEntry(declaration.symbol)
|
symbolRemapper.getDeclaredEnumEntry(declaration.symbol),
|
||||||
|
symbolRenamer.getEnumEntryName(declaration.symbol)
|
||||||
).apply {
|
).apply {
|
||||||
transformAnnotations(declaration)
|
transformAnnotations(declaration)
|
||||||
correspondingClass = declaration.correspondingClass?.transform()
|
correspondingClass = declaration.correspondingClass?.transform()
|
||||||
@@ -223,7 +268,11 @@ open class DeepCopyIrTreeWithSymbols(
|
|||||||
declaration.startOffset, declaration.endOffset,
|
declaration.startOffset, declaration.endOffset,
|
||||||
mapDeclarationOrigin(declaration.origin),
|
mapDeclarationOrigin(declaration.origin),
|
||||||
symbolRemapper.getDeclaredVariable(declaration.symbol),
|
symbolRemapper.getDeclaredVariable(declaration.symbol),
|
||||||
declaration.type.remapType()
|
symbolRenamer.getVariableName(declaration.symbol),
|
||||||
|
declaration.type.remapType(),
|
||||||
|
declaration.isVar,
|
||||||
|
declaration.isConst,
|
||||||
|
declaration.isLateinit
|
||||||
).apply {
|
).apply {
|
||||||
transformAnnotations(declaration)
|
transformAnnotations(declaration)
|
||||||
initializer = declaration.initializer?.transform()
|
initializer = declaration.initializer?.transform()
|
||||||
@@ -239,7 +288,11 @@ open class DeepCopyIrTreeWithSymbols(
|
|||||||
IrTypeParameterImpl(
|
IrTypeParameterImpl(
|
||||||
declaration.startOffset, declaration.endOffset,
|
declaration.startOffset, declaration.endOffset,
|
||||||
mapDeclarationOrigin(declaration.origin),
|
mapDeclarationOrigin(declaration.origin),
|
||||||
symbolRemapper.getDeclaredTypeParameter(declaration.symbol)
|
symbolRemapper.getDeclaredTypeParameter(declaration.symbol),
|
||||||
|
symbolRenamer.getTypeParameterName(declaration.symbol),
|
||||||
|
declaration.index,
|
||||||
|
declaration.isReified,
|
||||||
|
declaration.variance
|
||||||
).apply {
|
).apply {
|
||||||
transformAnnotations(declaration)
|
transformAnnotations(declaration)
|
||||||
}
|
}
|
||||||
@@ -263,8 +316,12 @@ open class DeepCopyIrTreeWithSymbols(
|
|||||||
declaration.startOffset, declaration.endOffset,
|
declaration.startOffset, declaration.endOffset,
|
||||||
mapDeclarationOrigin(declaration.origin),
|
mapDeclarationOrigin(declaration.origin),
|
||||||
symbolRemapper.getDeclaredValueParameter(declaration.symbol),
|
symbolRemapper.getDeclaredValueParameter(declaration.symbol),
|
||||||
|
symbolRenamer.getValueParameterName(declaration.symbol),
|
||||||
|
declaration.index,
|
||||||
declaration.type.remapType(),
|
declaration.type.remapType(),
|
||||||
declaration.varargElementType?.remapType()
|
declaration.varargElementType?.remapType(),
|
||||||
|
declaration.isCrossinline,
|
||||||
|
declaration.isNoinline
|
||||||
).apply {
|
).apply {
|
||||||
transformAnnotations(declaration)
|
transformAnnotations(declaration)
|
||||||
defaultValue = declaration.defaultValue?.transform()
|
defaultValue = declaration.defaultValue?.transform()
|
||||||
@@ -305,12 +362,22 @@ open class DeepCopyIrTreeWithSymbols(
|
|||||||
)
|
)
|
||||||
|
|
||||||
override fun visitBlock(expression: IrBlock): IrBlock =
|
override fun visitBlock(expression: IrBlock): IrBlock =
|
||||||
IrBlockImpl(
|
if (expression is IrReturnableBlock)
|
||||||
expression.startOffset, expression.endOffset,
|
IrReturnableBlockImpl(
|
||||||
expression.type.remapType(),
|
expression.startOffset, expression.endOffset,
|
||||||
mapStatementOrigin(expression.origin),
|
expression.type.remapType(),
|
||||||
expression.statements.map { it.transform() }
|
symbolRemapper.getReferencedReturnableBlock(expression.symbol),
|
||||||
)
|
mapStatementOrigin(expression.origin),
|
||||||
|
expression.statements.map { it.transform() },
|
||||||
|
expression.sourceFileName
|
||||||
|
)
|
||||||
|
else
|
||||||
|
IrBlockImpl(
|
||||||
|
expression.startOffset, expression.endOffset,
|
||||||
|
expression.type.remapType(),
|
||||||
|
mapStatementOrigin(expression.origin),
|
||||||
|
expression.statements.map { it.transform() }
|
||||||
|
)
|
||||||
|
|
||||||
override fun visitComposite(expression: IrComposite): IrComposite =
|
override fun visitComposite(expression: IrComposite): IrComposite =
|
||||||
IrCompositeImpl(
|
IrCompositeImpl(
|
||||||
@@ -408,8 +475,9 @@ open class DeepCopyIrTreeWithSymbols(
|
|||||||
expression.startOffset, expression.endOffset,
|
expression.startOffset, expression.endOffset,
|
||||||
expression.type.remapType(),
|
expression.type.remapType(),
|
||||||
newCallee,
|
newCallee,
|
||||||
expression.descriptor, // TODO substitute referenced descriptor
|
newCallee.descriptor,
|
||||||
expression.typeArgumentsCount,
|
expression.typeArgumentsCount,
|
||||||
|
expression.valueArgumentsCount,
|
||||||
mapStatementOrigin(expression.origin),
|
mapStatementOrigin(expression.origin),
|
||||||
symbolRemapper.getReferencedClassOrNull(expression.superQualifierSymbol)
|
symbolRemapper.getReferencedClassOrNull(expression.superQualifierSymbol)
|
||||||
).apply {
|
).apply {
|
||||||
@@ -426,8 +494,8 @@ open class DeepCopyIrTreeWithSymbols(
|
|||||||
|
|
||||||
private fun <T : IrMemberAccessExpression> T.transformValueArguments(original: T) {
|
private fun <T : IrMemberAccessExpression> T.transformValueArguments(original: T) {
|
||||||
transformReceiverArguments(original)
|
transformReceiverArguments(original)
|
||||||
mapValueParameters { valueParameter ->
|
for (i in 0 until original.valueArgumentsCount) {
|
||||||
original.getValueArgument(valueParameter)?.transform()
|
putValueArgument(i, original.getValueArgument(i)?.transform())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -437,7 +505,7 @@ open class DeepCopyIrTreeWithSymbols(
|
|||||||
expression.startOffset, expression.endOffset,
|
expression.startOffset, expression.endOffset,
|
||||||
expression.type.remapType(),
|
expression.type.remapType(),
|
||||||
newConstructor,
|
newConstructor,
|
||||||
expression.descriptor,
|
newConstructor.descriptor,
|
||||||
expression.typeArgumentsCount
|
expression.typeArgumentsCount
|
||||||
).apply {
|
).apply {
|
||||||
copyRemappedTypeArgumentsFrom(expression)
|
copyRemappedTypeArgumentsFrom(expression)
|
||||||
@@ -465,18 +533,21 @@ open class DeepCopyIrTreeWithSymbols(
|
|||||||
expression.argument.transform()
|
expression.argument.transform()
|
||||||
)
|
)
|
||||||
|
|
||||||
override fun visitFunctionReference(expression: IrFunctionReference): IrFunctionReference =
|
override fun visitFunctionReference(expression: IrFunctionReference): IrFunctionReference {
|
||||||
IrFunctionReferenceImpl(
|
val symbol = symbolRemapper.getReferencedFunction(expression.symbol)
|
||||||
|
return IrFunctionReferenceImpl(
|
||||||
expression.startOffset, expression.endOffset,
|
expression.startOffset, expression.endOffset,
|
||||||
expression.type.remapType(),
|
expression.type.remapType(),
|
||||||
symbolRemapper.getReferencedFunction(expression.symbol),
|
symbol,
|
||||||
expression.descriptor, // TODO substitute referenced descriptor
|
symbol.descriptor,
|
||||||
expression.typeArgumentsCount,
|
expression.typeArgumentsCount,
|
||||||
|
expression.valueArgumentsCount,
|
||||||
mapStatementOrigin(expression.origin)
|
mapStatementOrigin(expression.origin)
|
||||||
).apply {
|
).apply {
|
||||||
copyRemappedTypeArgumentsFrom(expression)
|
copyRemappedTypeArgumentsFrom(expression)
|
||||||
transformValueArguments(expression)
|
transformValueArguments(expression)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun visitPropertyReference(expression: IrPropertyReference): IrPropertyReference =
|
override fun visitPropertyReference(expression: IrPropertyReference): IrPropertyReference =
|
||||||
IrPropertyReferenceImpl(
|
IrPropertyReferenceImpl(
|
||||||
@@ -509,7 +580,7 @@ open class DeepCopyIrTreeWithSymbols(
|
|||||||
expression.startOffset, expression.endOffset,
|
expression.startOffset, expression.endOffset,
|
||||||
expression.type.remapType(),
|
expression.type.remapType(),
|
||||||
symbolRemapper.getReferencedClassifier(expression.symbol),
|
symbolRemapper.getReferencedClassifier(expression.symbol),
|
||||||
expression.classType
|
expression.classType.remapType()
|
||||||
)
|
)
|
||||||
|
|
||||||
override fun visitInstanceInitializerCall(expression: IrInstanceInitializerCall): IrInstanceInitializerCall =
|
override fun visitInstanceInitializerCall(expression: IrInstanceInitializerCall): IrInstanceInitializerCall =
|
||||||
@@ -524,7 +595,7 @@ open class DeepCopyIrTreeWithSymbols(
|
|||||||
expression.startOffset, expression.endOffset,
|
expression.startOffset, expression.endOffset,
|
||||||
expression.type.remapType(),
|
expression.type.remapType(),
|
||||||
expression.operator,
|
expression.operator,
|
||||||
expression.typeOperand,
|
expression.typeOperand.remapType(),
|
||||||
symbolRemapper.getReferencedClassifier(expression.typeOperandClassifier),
|
symbolRemapper.getReferencedClassifier(expression.typeOperandClassifier),
|
||||||
expression.argument.transform()
|
expression.argument.transform()
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user