IrTypes: make old DeepCopy compile
Lots of TODOs, should figure out proper type mapping strategy (or simply drop this frankenstein code, finally).
This commit is contained in:
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.ir.expressions.*
|
|||||||
import org.jetbrains.kotlin.ir.expressions.impl.*
|
import org.jetbrains.kotlin.ir.expressions.impl.*
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.*
|
import org.jetbrains.kotlin.ir.symbols.impl.*
|
||||||
|
import org.jetbrains.kotlin.ir.types.classifierOrFail
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
||||||
|
|
||||||
inline fun <reified T : IrElement> T.deepCopyOld(): T =
|
inline fun <reified T : IrElement> T.deepCopyOld(): T =
|
||||||
@@ -95,7 +96,8 @@ open class DeepCopyIrTree : IrElementTransformerVoid() {
|
|||||||
declaration.declarations.map { it.transform() }
|
declaration.declarations.map { it.transform() }
|
||||||
).apply {
|
).apply {
|
||||||
transformAnnotations(declaration)
|
transformAnnotations(declaration)
|
||||||
thisReceiver = declaration.thisReceiver?.withDescriptor(descriptor.thisAsReceiverParameter)
|
thisReceiver = declaration.thisReceiver?.replaceDescriptor(descriptor.thisAsReceiverParameter)
|
||||||
|
|
||||||
transformTypeParameters(declaration, descriptor.declaredTypeParameters)
|
transformTypeParameters(declaration, descriptor.declaredTypeParameters)
|
||||||
|
|
||||||
descriptor.typeConstructor.supertypes.forEachIndexed { index, supertype ->
|
descriptor.typeConstructor.supertypes.forEachIndexed { index, supertype ->
|
||||||
@@ -112,9 +114,6 @@ open class DeepCopyIrTree : IrElementTransformerVoid() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun IrValueParameter.withDescriptor(newDescriptor: ParameterDescriptor) =
|
|
||||||
IrValueParameterImpl(startOffset, endOffset, origin, newDescriptor, defaultValue?.transform())
|
|
||||||
|
|
||||||
override fun visitTypeAlias(declaration: IrTypeAlias): IrTypeAlias =
|
override fun visitTypeAlias(declaration: IrTypeAlias): IrTypeAlias =
|
||||||
IrTypeAliasImpl(
|
IrTypeAliasImpl(
|
||||||
declaration.startOffset, declaration.endOffset,
|
declaration.startOffset, declaration.endOffset,
|
||||||
@@ -129,6 +128,7 @@ open class DeepCopyIrTree : IrElementTransformerVoid() {
|
|||||||
declaration.startOffset, declaration.endOffset,
|
declaration.startOffset, declaration.endOffset,
|
||||||
mapDeclarationOrigin(declaration.origin),
|
mapDeclarationOrigin(declaration.origin),
|
||||||
mapFunctionDeclaration(declaration.descriptor),
|
mapFunctionDeclaration(declaration.descriptor),
|
||||||
|
declaration.returnType, // TODO
|
||||||
declaration.body?.transform()
|
declaration.body?.transform()
|
||||||
).transformParameters(declaration).apply {
|
).transformParameters(declaration).apply {
|
||||||
transformAnnotations(declaration)
|
transformAnnotations(declaration)
|
||||||
@@ -146,6 +146,7 @@ open class DeepCopyIrTree : IrElementTransformerVoid() {
|
|||||||
declaration.startOffset, declaration.endOffset,
|
declaration.startOffset, declaration.endOffset,
|
||||||
mapDeclarationOrigin(declaration.origin),
|
mapDeclarationOrigin(declaration.origin),
|
||||||
mapConstructorDeclaration(declaration.descriptor),
|
mapConstructorDeclaration(declaration.descriptor),
|
||||||
|
declaration.returnType,
|
||||||
declaration.body?.transform()
|
declaration.body?.transform()
|
||||||
).transformParameters(declaration).apply {
|
).transformParameters(declaration).apply {
|
||||||
transformAnnotations(declaration)
|
transformAnnotations(declaration)
|
||||||
@@ -175,19 +176,18 @@ open class DeepCopyIrTree : IrElementTransformerVoid() {
|
|||||||
|
|
||||||
protected fun <T : IrFunction> T.transformValueParameters(original: T) =
|
protected fun <T : IrFunction> T.transformValueParameters(original: T) =
|
||||||
apply {
|
apply {
|
||||||
dispatchReceiverParameter = original.dispatchReceiverParameter?.let {
|
dispatchReceiverParameter =
|
||||||
copyValueParameter(it, descriptor.dispatchReceiverParameter ?: throw AssertionError("No dispatch receiver in $descriptor"))
|
original.dispatchReceiverParameter?.replaceDescriptor(
|
||||||
}
|
descriptor.dispatchReceiverParameter ?: throw AssertionError("No dispatch receiver in $descriptor")
|
||||||
|
)
|
||||||
|
|
||||||
extensionReceiverParameter = original.extensionReceiverParameter?.let {
|
extensionReceiverParameter =
|
||||||
copyValueParameter(
|
original.extensionReceiverParameter?.replaceDescriptor(
|
||||||
it,
|
descriptor.extensionReceiverParameter ?: throw AssertionError("No extension receiver in $descriptor")
|
||||||
descriptor.extensionReceiverParameter ?: throw AssertionError("No extension receiver in $descriptor")
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
original.valueParameters.mapIndexedTo(valueParameters) { i, originalValueParameter ->
|
original.valueParameters.mapIndexedTo(valueParameters) { i, originalValueParameter ->
|
||||||
copyValueParameter(originalValueParameter, descriptor.valueParameters[i])
|
originalValueParameter.replaceDescriptor(descriptor.valueParameters[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,11 +202,12 @@ open class DeepCopyIrTree : IrElementTransformerVoid() {
|
|||||||
IrTypeParameterImpl(
|
IrTypeParameterImpl(
|
||||||
originalTypeParameter.startOffset, originalTypeParameter.endOffset,
|
originalTypeParameter.startOffset, originalTypeParameter.endOffset,
|
||||||
mapDeclarationOrigin(originalTypeParameter.origin),
|
mapDeclarationOrigin(originalTypeParameter.origin),
|
||||||
newTypeParameterDescriptor
|
newTypeParameterDescriptor,
|
||||||
|
originalTypeParameter.upperBounds // TODO
|
||||||
).apply {
|
).apply {
|
||||||
transformAnnotations(originalTypeParameter)
|
transformAnnotations(originalTypeParameter)
|
||||||
for (i in upperBounds.indices) {
|
for (i in upperBounds.indices) {
|
||||||
val upperBoundClassifier = upperBounds[i].constructor.declarationDescriptor ?: continue
|
val upperBoundClassifier = upperBounds[i].classifierOrFail.descriptor // TODO
|
||||||
val oldSuperClassifierSymbol = originalTypeParameter.superClassifiers[i]
|
val oldSuperClassifierSymbol = originalTypeParameter.superClassifiers[i]
|
||||||
val newSuperClassifierSymbol =
|
val newSuperClassifierSymbol =
|
||||||
if (upperBoundClassifier == oldSuperClassifierSymbol.descriptor)
|
if (upperBoundClassifier == oldSuperClassifierSymbol.descriptor)
|
||||||
@@ -224,17 +225,19 @@ open class DeepCopyIrTree : IrElementTransformerVoid() {
|
|||||||
else -> throw IllegalArgumentException("Unexpected classifier descriptor: $classifier")
|
else -> throw IllegalArgumentException("Unexpected classifier descriptor: $classifier")
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun copyValueParameter(
|
protected fun copyValueParameter(valueParameter: IrValueParameter, newDescriptor: ParameterDescriptor) =
|
||||||
originalValueParameter: IrValueParameter,
|
valueParameter.replaceDescriptor(newDescriptor)
|
||||||
newParameterDescriptor: ParameterDescriptor
|
|
||||||
): IrValueParameterImpl =
|
protected fun IrValueParameter.replaceDescriptor(newDescriptor: ParameterDescriptor) =
|
||||||
IrValueParameterImpl(
|
IrValueParameterImpl(
|
||||||
originalValueParameter.startOffset, originalValueParameter.endOffset,
|
startOffset, endOffset,
|
||||||
mapDeclarationOrigin(originalValueParameter.origin),
|
mapDeclarationOrigin(origin),
|
||||||
newParameterDescriptor,
|
newDescriptor,
|
||||||
originalValueParameter.defaultValue?.transform()
|
type, // TODO
|
||||||
|
varargElementType, // TODO
|
||||||
|
defaultValue?.transform()
|
||||||
).apply {
|
).apply {
|
||||||
transformAnnotations(originalValueParameter)
|
transformAnnotations(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO visitTypeParameter
|
// TODO visitTypeParameter
|
||||||
@@ -246,6 +249,7 @@ open class DeepCopyIrTree : IrElementTransformerVoid() {
|
|||||||
mapDeclarationOrigin(declaration.origin),
|
mapDeclarationOrigin(declaration.origin),
|
||||||
declaration.isDelegated,
|
declaration.isDelegated,
|
||||||
mapPropertyDeclaration(declaration.descriptor),
|
mapPropertyDeclaration(declaration.descriptor),
|
||||||
|
declaration.type, // TODO
|
||||||
declaration.backingField?.transform(),
|
declaration.backingField?.transform(),
|
||||||
declaration.getter?.transform(),
|
declaration.getter?.transform(),
|
||||||
declaration.setter?.transform()
|
declaration.setter?.transform()
|
||||||
@@ -258,6 +262,7 @@ open class DeepCopyIrTree : IrElementTransformerVoid() {
|
|||||||
declaration.startOffset, declaration.endOffset,
|
declaration.startOffset, declaration.endOffset,
|
||||||
mapDeclarationOrigin(declaration.origin),
|
mapDeclarationOrigin(declaration.origin),
|
||||||
mapPropertyDeclaration(declaration.descriptor),
|
mapPropertyDeclaration(declaration.descriptor),
|
||||||
|
declaration.type, // TODO
|
||||||
declaration.initializer?.transform()
|
declaration.initializer?.transform()
|
||||||
).apply {
|
).apply {
|
||||||
transformAnnotations(declaration)
|
transformAnnotations(declaration)
|
||||||
@@ -268,6 +273,7 @@ open class DeepCopyIrTree : IrElementTransformerVoid() {
|
|||||||
declaration.startOffset, declaration.endOffset,
|
declaration.startOffset, declaration.endOffset,
|
||||||
mapDeclarationOrigin(declaration.origin),
|
mapDeclarationOrigin(declaration.origin),
|
||||||
mapLocalPropertyDeclaration(declaration.descriptor),
|
mapLocalPropertyDeclaration(declaration.descriptor),
|
||||||
|
declaration.type, // TODO
|
||||||
declaration.delegate.transform(),
|
declaration.delegate.transform(),
|
||||||
declaration.getter.transform(),
|
declaration.getter.transform(),
|
||||||
declaration.setter?.transform()
|
declaration.setter?.transform()
|
||||||
@@ -299,6 +305,7 @@ open class DeepCopyIrTree : IrElementTransformerVoid() {
|
|||||||
declaration.startOffset, declaration.endOffset,
|
declaration.startOffset, declaration.endOffset,
|
||||||
mapDeclarationOrigin(declaration.origin),
|
mapDeclarationOrigin(declaration.origin),
|
||||||
mapVariableDeclaration(declaration.descriptor),
|
mapVariableDeclaration(declaration.descriptor),
|
||||||
|
declaration.type, // TODO
|
||||||
declaration.initializer?.transform()
|
declaration.initializer?.transform()
|
||||||
).apply {
|
).apply {
|
||||||
transformAnnotations(declaration)
|
transformAnnotations(declaration)
|
||||||
@@ -378,6 +385,7 @@ open class DeepCopyIrTree : IrElementTransformerVoid() {
|
|||||||
override fun visitGetValue(expression: IrGetValue): IrGetValue =
|
override fun visitGetValue(expression: IrGetValue): IrGetValue =
|
||||||
IrGetValueImpl(
|
IrGetValueImpl(
|
||||||
expression.startOffset, expression.endOffset,
|
expression.startOffset, expression.endOffset,
|
||||||
|
expression.type, // TODO
|
||||||
mapValueReference(expression.descriptor),
|
mapValueReference(expression.descriptor),
|
||||||
mapStatementOrigin(expression.origin)
|
mapStatementOrigin(expression.origin)
|
||||||
)
|
)
|
||||||
@@ -385,6 +393,7 @@ open class DeepCopyIrTree : IrElementTransformerVoid() {
|
|||||||
override fun visitSetVariable(expression: IrSetVariable): IrSetVariable =
|
override fun visitSetVariable(expression: IrSetVariable): IrSetVariable =
|
||||||
IrSetVariableImpl(
|
IrSetVariableImpl(
|
||||||
expression.startOffset, expression.endOffset,
|
expression.startOffset, expression.endOffset,
|
||||||
|
expression.type, // TODO
|
||||||
mapVariableReference(expression.descriptor),
|
mapVariableReference(expression.descriptor),
|
||||||
expression.value.transform(),
|
expression.value.transform(),
|
||||||
mapStatementOrigin(expression.origin)
|
mapStatementOrigin(expression.origin)
|
||||||
@@ -395,6 +404,7 @@ open class DeepCopyIrTree : IrElementTransformerVoid() {
|
|||||||
expression.startOffset, expression.endOffset,
|
expression.startOffset, expression.endOffset,
|
||||||
mapPropertyReference(expression.descriptor),
|
mapPropertyReference(expression.descriptor),
|
||||||
expression.receiver?.transform(),
|
expression.receiver?.transform(),
|
||||||
|
expression.type, // TODO
|
||||||
mapStatementOrigin(expression.origin),
|
mapStatementOrigin(expression.origin),
|
||||||
mapSuperQualifier(expression.superQualifier)
|
mapSuperQualifier(expression.superQualifier)
|
||||||
)
|
)
|
||||||
@@ -405,6 +415,7 @@ open class DeepCopyIrTree : IrElementTransformerVoid() {
|
|||||||
mapPropertyReference(expression.descriptor),
|
mapPropertyReference(expression.descriptor),
|
||||||
expression.receiver?.transform(),
|
expression.receiver?.transform(),
|
||||||
expression.value.transform(),
|
expression.value.transform(),
|
||||||
|
expression.type, // TODO
|
||||||
mapStatementOrigin(expression.origin),
|
mapStatementOrigin(expression.origin),
|
||||||
mapSuperQualifier(expression.superQualifier)
|
mapSuperQualifier(expression.superQualifier)
|
||||||
)
|
)
|
||||||
@@ -449,6 +460,7 @@ open class DeepCopyIrTree : IrElementTransformerVoid() {
|
|||||||
val newCallee = mapDelegatedConstructorCallee(expression.descriptor)
|
val newCallee = mapDelegatedConstructorCallee(expression.descriptor)
|
||||||
return IrDelegatingConstructorCallImpl(
|
return IrDelegatingConstructorCallImpl(
|
||||||
expression.startOffset, expression.endOffset,
|
expression.startOffset, expression.endOffset,
|
||||||
|
expression.type, // TODO
|
||||||
newCallee,
|
newCallee,
|
||||||
expression.typeArgumentsCount
|
expression.typeArgumentsCount
|
||||||
).apply {
|
).apply {
|
||||||
@@ -462,6 +474,7 @@ open class DeepCopyIrTree : IrElementTransformerVoid() {
|
|||||||
val newConstructor = mapEnumConstructorCallee(oldConstructor)
|
val newConstructor = mapEnumConstructorCallee(oldConstructor)
|
||||||
return IrEnumConstructorCallImpl(
|
return IrEnumConstructorCallImpl(
|
||||||
expression.startOffset, expression.endOffset,
|
expression.startOffset, expression.endOffset,
|
||||||
|
expression.type, // TODO
|
||||||
newConstructor,
|
newConstructor,
|
||||||
expression.typeArgumentsCount
|
expression.typeArgumentsCount
|
||||||
).apply {
|
).apply {
|
||||||
@@ -532,7 +545,8 @@ open class DeepCopyIrTree : IrElementTransformerVoid() {
|
|||||||
override fun visitInstanceInitializerCall(expression: IrInstanceInitializerCall): IrInstanceInitializerCall =
|
override fun visitInstanceInitializerCall(expression: IrInstanceInitializerCall): IrInstanceInitializerCall =
|
||||||
IrInstanceInitializerCallImpl(
|
IrInstanceInitializerCallImpl(
|
||||||
expression.startOffset, expression.endOffset,
|
expression.startOffset, expression.endOffset,
|
||||||
mapClassReference(expression.classDescriptor)
|
mapClassReference(expression.classDescriptor),
|
||||||
|
expression.type // TODO
|
||||||
)
|
)
|
||||||
|
|
||||||
override fun visitTypeOperator(expression: IrTypeOperatorCall): IrTypeOperatorCall =
|
override fun visitTypeOperator(expression: IrTypeOperatorCall): IrTypeOperatorCall =
|
||||||
|
|||||||
Reference in New Issue
Block a user