Files
kotlin-fork/compiler/testData/ir/irText/firProblems/DeepCopyIrTree.kt
T
Ivan Kylchik c7435ba760 Replace all occurrences of WITH_RUNTIME with WITH_STDLIB
We are going to deprecate `WITH_RUNTIME` directive. The main reason
behind this change is that `WITH_STDLIB` directive better describes
its meaning, specifically it will add kotlin stdlib to test's classpath.
2021-11-17 15:26:38 +03:00

45 lines
1.3 KiB
Kotlin
Vendored

// WITH_STDLIB
// FULL_JDK
interface IrType
interface TypeRemapper {
fun enterScope(irTypeParametersContainer: IrTypeParametersContainer)
fun remapType(type: IrType): IrType
fun leaveScope()
}
interface IrTypeParametersContainer : IrDeclaration, IrDeclarationParent {
var typeParameters: List<IrTypeParameter>
}
interface IrDeclaration
interface IrTypeParameter : IrDeclaration {
val superTypes: MutableList<IrType>
}
interface IrDeclarationParent
class DeepCopyIrTreeWithSymbols(private val typeRemapper: TypeRemapper) {
private fun copyTypeParameter(declaration: IrTypeParameter): IrTypeParameter = declaration
fun IrTypeParametersContainer.copyTypeParametersFrom(other: IrTypeParametersContainer) {
this.typeParameters = other.typeParameters.map {
copyTypeParameter(it)
}
typeRemapper.withinScope(this) {
for ((thisTypeParameter, otherTypeParameter) in this.typeParameters.zip(other.typeParameters)) {
otherTypeParameter.superTypes.mapTo(thisTypeParameter.superTypes) {
typeRemapper.remapType(it)
}
}
}
}
}
inline fun <T> TypeRemapper.withinScope(irTypeParametersContainer: IrTypeParametersContainer, fn: () -> T): T {
enterScope(irTypeParametersContainer)
val result = fn()
leaveScope()
return result
}