Minor: reformat DeepCopyIrTreeWithDescriptors.kt

This commit is contained in:
Dmitry Petrov
2019-04-12 12:12:15 +03:00
parent bf2ab99b61
commit 8a95da4a95
@@ -14,16 +14,17 @@ import org.jetbrains.kotlin.ir.symbols.*
import org.jetbrains.kotlin.ir.types.* import org.jetbrains.kotlin.ir.types.*
import org.jetbrains.kotlin.ir.types.impl.buildSimpleType import org.jetbrains.kotlin.ir.types.impl.buildSimpleType
import org.jetbrains.kotlin.ir.types.impl.makeTypeProjection import org.jetbrains.kotlin.ir.types.impl.makeTypeProjection
import org.jetbrains.kotlin.ir.types.impl.toBuilder
import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
import org.jetbrains.kotlin.ir.visitors.acceptVoid import org.jetbrains.kotlin.ir.visitors.acceptVoid
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
internal class DeepCopyIrTreeWithSymbolsForInliner(val context: Context, internal class DeepCopyIrTreeWithSymbolsForInliner(
val typeArguments: Map<IrTypeParameterSymbol, IrType?>?, val context: Context,
val parent: IrDeclarationParent?) { val typeArguments: Map<IrTypeParameterSymbol, IrType?>?,
val parent: IrDeclarationParent?
) {
fun copy(irElement: IrElement): IrElement { fun copy(irElement: IrElement): IrElement {
// Create new symbols. // Create new symbols.
@@ -36,7 +37,7 @@ internal class DeepCopyIrTreeWithSymbolsForInliner(val context: Context,
val result = irElement.transform(copier, data = null) val result = irElement.transform(copier, data = null)
// Bind newly created IR with wrapped descriptors. // Bind newly created IR with wrapped descriptors.
result.acceptVoid(object: IrElementVisitorVoid { result.acceptVoid(object : IrElementVisitorVoid {
override fun visitElement(element: IrElement) { override fun visitElement(element: IrElement) {
element.acceptChildrenVoid(this) element.acceptChildrenVoid(this)
} }
@@ -53,7 +54,8 @@ internal class DeepCopyIrTreeWithSymbolsForInliner(val context: Context,
override fun visitEnumEntry(declaration: IrEnumEntry) { override fun visitEnumEntry(declaration: IrEnumEntry) {
(declaration.descriptor as WrappedClassDescriptor).bind( (declaration.descriptor as WrappedClassDescriptor).bind(
declaration.correspondingClass ?: declaration.parentAsClass) declaration.correspondingClass ?: declaration.parentAsClass
)
declaration.acceptChildrenVoid(this) declaration.acceptChildrenVoid(this)
} }
@@ -108,45 +110,47 @@ internal class DeepCopyIrTreeWithSymbolsForInliner(val context: Context,
private inner class DescriptorsToIrRemapper : DescriptorsRemapper { private inner class DescriptorsToIrRemapper : DescriptorsRemapper {
override fun remapDeclaredClass(descriptor: ClassDescriptor) = override fun remapDeclaredClass(descriptor: ClassDescriptor) =
WrappedClassDescriptor(descriptor.annotations, descriptor.source) WrappedClassDescriptor(descriptor.annotations, descriptor.source)
override fun remapDeclaredConstructor(descriptor: ClassConstructorDescriptor) = override fun remapDeclaredConstructor(descriptor: ClassConstructorDescriptor) =
WrappedClassConstructorDescriptor(descriptor.annotations, descriptor.source) WrappedClassConstructorDescriptor(descriptor.annotations, descriptor.source)
override fun remapDeclaredEnumEntry(descriptor: ClassDescriptor) = override fun remapDeclaredEnumEntry(descriptor: ClassDescriptor) =
WrappedClassDescriptor(descriptor.annotations, descriptor.source) WrappedClassDescriptor(descriptor.annotations, descriptor.source)
override fun remapDeclaredField(descriptor: PropertyDescriptor) = override fun remapDeclaredField(descriptor: PropertyDescriptor) =
WrappedFieldDescriptor(descriptor.annotations, descriptor.source) WrappedFieldDescriptor(descriptor.annotations, descriptor.source)
override fun remapDeclaredSimpleFunction(descriptor: FunctionDescriptor) = override fun remapDeclaredSimpleFunction(descriptor: FunctionDescriptor) =
WrappedSimpleFunctionDescriptor(descriptor.annotations, descriptor.source) WrappedSimpleFunctionDescriptor(descriptor.annotations, descriptor.source)
override fun remapDeclaredTypeParameter(descriptor: TypeParameterDescriptor) = override fun remapDeclaredTypeParameter(descriptor: TypeParameterDescriptor) =
WrappedTypeParameterDescriptor(descriptor.annotations, descriptor.source) WrappedTypeParameterDescriptor(descriptor.annotations, descriptor.source)
override fun remapDeclaredVariable(descriptor: VariableDescriptor) = override fun remapDeclaredVariable(descriptor: VariableDescriptor) =
WrappedVariableDescriptor(descriptor.annotations, descriptor.source) WrappedVariableDescriptor(descriptor.annotations, descriptor.source)
override fun remapDeclaredValueParameter(descriptor: ParameterDescriptor): ParameterDescriptor = override fun remapDeclaredValueParameter(descriptor: ParameterDescriptor): ParameterDescriptor =
if (descriptor is ReceiverParameterDescriptor) if (descriptor is ReceiverParameterDescriptor)
WrappedReceiverParameterDescriptor(descriptor.annotations, descriptor.source) WrappedReceiverParameterDescriptor(descriptor.annotations, descriptor.source)
else else
WrappedValueParameterDescriptor(descriptor.annotations, descriptor.source) WrappedValueParameterDescriptor(descriptor.annotations, descriptor.source)
} }
private inner class InlinerTypeRemapper(val symbolRemapper: SymbolRemapper, private inner class InlinerTypeRemapper(
val typeArguments: Map<IrTypeParameterSymbol, IrType?>?) : TypeRemapper { val symbolRemapper: SymbolRemapper,
val typeArguments: Map<IrTypeParameterSymbol, IrType?>?
) : TypeRemapper {
override fun enterScope(irTypeParametersContainer: IrTypeParametersContainer) { } override fun enterScope(irTypeParametersContainer: IrTypeParametersContainer) {}
override fun leaveScope() { } override fun leaveScope() {}
private fun remapTypeArguments(arguments: List<IrTypeArgument>) = private fun remapTypeArguments(arguments: List<IrTypeArgument>) =
arguments.map { argument -> arguments.map { argument ->
(argument as? IrTypeProjection)?.let { makeTypeProjection(remapType(it.type), it.variance) } (argument as? IrTypeProjection)?.let { makeTypeProjection(remapType(it.type), it.variance) }
?: argument ?: argument
} }
override fun remapType(type: IrType): IrType { override fun remapType(type: IrType): IrType {
if (type !is IrSimpleType) return type if (type !is IrSimpleType) return type