IR: NullDescriptorsRemapper
This commit is contained in:
+1
-6
@@ -5,8 +5,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.common.lower.inline
|
||||
|
||||
import org.jetbrains.kotlin.ir.util.DescriptorsToIrRemapper
|
||||
import org.jetbrains.kotlin.ir.util.WrappedDescriptorPatcher
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent
|
||||
import org.jetbrains.kotlin.ir.declarations.IrTypeParametersContainer
|
||||
@@ -37,9 +35,6 @@ internal class DeepCopyIrTreeWithSymbolsForInliner(
|
||||
// Copy IR.
|
||||
val result = irElement.transform(copier, data = null)
|
||||
|
||||
// Bind newly created IR with wrapped descriptors.
|
||||
result.acceptVoid(WrappedDescriptorPatcher)
|
||||
|
||||
result.patchDeclarationParents(parent)
|
||||
return result
|
||||
}
|
||||
@@ -133,7 +128,7 @@ internal class DeepCopyIrTreeWithSymbolsForInliner(
|
||||
}
|
||||
}
|
||||
|
||||
private val symbolRemapper = SymbolRemapperImpl(DescriptorsToIrRemapper)
|
||||
private val symbolRemapper = SymbolRemapperImpl(NullDescriptorsRemapper)
|
||||
private val typeRemapper = InlinerTypeRemapper(symbolRemapper, typeArguments)
|
||||
private val copier = object : DeepCopyIrTreeWithSymbols(symbolRemapper, typeRemapper, InlinerSymbolRenamer()) {
|
||||
private fun IrType.remapTypeAndErase() = typeRemapper.remapTypeAndOptionallyErase(this, erase = true)
|
||||
|
||||
+1
-6
@@ -5,8 +5,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.ir.overrides
|
||||
|
||||
import org.jetbrains.kotlin.ir.util.DescriptorsToIrRemapper
|
||||
import org.jetbrains.kotlin.ir.util.WrappedDescriptorPatcher
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrTypeParametersContainer
|
||||
@@ -30,9 +28,6 @@ class DeepCopyIrTreeWithSymbolsForFakeOverrides(typeArguments: Map<IrTypeParamet
|
||||
// Copy IR.
|
||||
val result = irElement.transform(copier, data = null)
|
||||
|
||||
// Bind newly created IR with wrapped descriptors.
|
||||
result.acceptVoid(WrappedDescriptorPatcher)
|
||||
|
||||
result.patchDeclarationParents(parent)
|
||||
return result
|
||||
}
|
||||
@@ -92,7 +87,7 @@ class DeepCopyIrTreeWithSymbolsForFakeOverrides(typeArguments: Map<IrTypeParamet
|
||||
private val symbolRemapper =
|
||||
FakeOverrideSymbolRemapperImpl(
|
||||
typeArguments,
|
||||
DescriptorsToIrRemapper
|
||||
NullDescriptorsRemapper
|
||||
)
|
||||
private val copier = FakeOverrideCopier(
|
||||
symbolRemapper,
|
||||
|
||||
@@ -19,20 +19,20 @@ package org.jetbrains.kotlin.ir.util
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
|
||||
interface DescriptorsRemapper {
|
||||
fun remapDeclaredClass(descriptor: ClassDescriptor): ClassDescriptor = descriptor
|
||||
fun remapDeclaredScript(descriptor: ScriptDescriptor): ScriptDescriptor = descriptor
|
||||
fun remapDeclaredConstructor(descriptor: ClassConstructorDescriptor): ClassConstructorDescriptor = descriptor
|
||||
fun remapDeclaredEnumEntry(descriptor: ClassDescriptor): ClassDescriptor = descriptor
|
||||
fun remapDeclaredClass(descriptor: ClassDescriptor): ClassDescriptor? = descriptor
|
||||
fun remapDeclaredScript(descriptor: ScriptDescriptor): ScriptDescriptor? = descriptor
|
||||
fun remapDeclaredConstructor(descriptor: ClassConstructorDescriptor): ClassConstructorDescriptor? = descriptor
|
||||
fun remapDeclaredEnumEntry(descriptor: ClassDescriptor): ClassDescriptor? = descriptor
|
||||
fun remapDeclaredExternalPackageFragment(descriptor: PackageFragmentDescriptor): PackageFragmentDescriptor = descriptor
|
||||
fun remapDeclaredField(descriptor: PropertyDescriptor): PropertyDescriptor = descriptor
|
||||
fun remapDeclaredField(descriptor: PropertyDescriptor): PropertyDescriptor? = descriptor
|
||||
fun remapDeclaredFilePackageFragment(descriptor: PackageFragmentDescriptor): PackageFragmentDescriptor = descriptor
|
||||
fun remapDeclaredProperty(descriptor: PropertyDescriptor): PropertyDescriptor = descriptor
|
||||
fun remapDeclaredSimpleFunction(descriptor: FunctionDescriptor): FunctionDescriptor = descriptor
|
||||
fun remapDeclaredTypeParameter(descriptor: TypeParameterDescriptor): TypeParameterDescriptor = descriptor
|
||||
fun remapDeclaredValueParameter(descriptor: ParameterDescriptor): ParameterDescriptor = descriptor
|
||||
fun remapDeclaredVariable(descriptor: VariableDescriptor): VariableDescriptor = descriptor
|
||||
fun remapDeclaredLocalDelegatedProperty(descriptor: VariableDescriptorWithAccessors): VariableDescriptorWithAccessors = descriptor
|
||||
fun remapDeclaredTypeAlias(descriptor: TypeAliasDescriptor): TypeAliasDescriptor = descriptor
|
||||
fun remapDeclaredProperty(descriptor: PropertyDescriptor): PropertyDescriptor? = descriptor
|
||||
fun remapDeclaredSimpleFunction(descriptor: FunctionDescriptor): FunctionDescriptor? = descriptor
|
||||
fun remapDeclaredTypeParameter(descriptor: TypeParameterDescriptor): TypeParameterDescriptor? = descriptor
|
||||
fun remapDeclaredValueParameter(descriptor: ParameterDescriptor): ParameterDescriptor? = descriptor
|
||||
fun remapDeclaredVariable(descriptor: VariableDescriptor): VariableDescriptor? = descriptor
|
||||
fun remapDeclaredLocalDelegatedProperty(descriptor: VariableDescriptorWithAccessors): VariableDescriptorWithAccessors? = descriptor
|
||||
fun remapDeclaredTypeAlias(descriptor: TypeAliasDescriptor): TypeAliasDescriptor? = descriptor
|
||||
|
||||
object Default : DescriptorsRemapper
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.ir.util
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.descriptors.*
|
||||
import org.jetbrains.kotlin.ir.util.DescriptorsRemapper
|
||||
import org.jetbrains.kotlin.ir.util.parentAsClass
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
|
||||
|
||||
object DescriptorsToIrRemapper : DescriptorsRemapper {
|
||||
override fun remapDeclaredClass(descriptor: ClassDescriptor) =
|
||||
WrappedClassDescriptor()
|
||||
|
||||
override fun remapDeclaredConstructor(descriptor: ClassConstructorDescriptor) =
|
||||
WrappedClassConstructorDescriptor()
|
||||
|
||||
override fun remapDeclaredEnumEntry(descriptor: ClassDescriptor) =
|
||||
WrappedClassDescriptor()
|
||||
|
||||
override fun remapDeclaredField(descriptor: PropertyDescriptor) =
|
||||
WrappedFieldDescriptor()
|
||||
|
||||
override fun remapDeclaredSimpleFunction(descriptor: FunctionDescriptor) =
|
||||
when (descriptor) {
|
||||
is PropertyGetterDescriptor -> WrappedPropertyGetterDescriptor()
|
||||
is PropertySetterDescriptor -> WrappedPropertySetterDescriptor()
|
||||
else -> WrappedSimpleFunctionDescriptor()
|
||||
}
|
||||
|
||||
override fun remapDeclaredProperty(descriptor: PropertyDescriptor) =
|
||||
WrappedPropertyDescriptor()
|
||||
|
||||
override fun remapDeclaredTypeParameter(descriptor: TypeParameterDescriptor) =
|
||||
WrappedTypeParameterDescriptor()
|
||||
|
||||
override fun remapDeclaredVariable(descriptor: VariableDescriptor) =
|
||||
WrappedVariableDescriptor()
|
||||
|
||||
override fun remapDeclaredValueParameter(descriptor: ParameterDescriptor): ParameterDescriptor =
|
||||
if (descriptor is ReceiverParameterDescriptor)
|
||||
WrappedReceiverParameterDescriptor()
|
||||
else
|
||||
WrappedValueParameterDescriptor()
|
||||
}
|
||||
|
||||
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
||||
object WrappedDescriptorPatcher : IrElementVisitorVoid {
|
||||
override fun visitElement(element: IrElement) {
|
||||
element.acceptChildrenVoid(this)
|
||||
}
|
||||
|
||||
override fun visitClass(declaration: IrClass) {
|
||||
(declaration.descriptor as? WrappedClassDescriptor)?.bind(declaration)
|
||||
declaration.acceptChildrenVoid(this)
|
||||
}
|
||||
|
||||
override fun visitConstructor(declaration: IrConstructor) {
|
||||
(declaration.descriptor as? WrappedClassConstructorDescriptor)?.bind(declaration)
|
||||
declaration.acceptChildrenVoid(this)
|
||||
}
|
||||
|
||||
override fun visitEnumEntry(declaration: IrEnumEntry) {
|
||||
(declaration.descriptor as? WrappedClassDescriptor)?.bind(
|
||||
declaration.correspondingClass ?: declaration.parentAsClass
|
||||
)
|
||||
declaration.acceptChildrenVoid(this)
|
||||
}
|
||||
|
||||
override fun visitField(declaration: IrField) {
|
||||
(declaration.descriptor as? WrappedFieldDescriptor)?.bind(declaration)
|
||||
declaration.acceptChildrenVoid(this)
|
||||
}
|
||||
|
||||
override fun visitProperty(declaration: IrProperty) {
|
||||
(declaration.descriptor as? WrappedPropertyDescriptor)?.bind(declaration)
|
||||
declaration.acceptChildrenVoid(this)
|
||||
}
|
||||
|
||||
override fun visitFunction(declaration: IrFunction) {
|
||||
(declaration.descriptor as? WrappedSimpleFunctionDescriptor)?.bind(declaration as IrSimpleFunction)
|
||||
declaration.acceptChildrenVoid(this)
|
||||
}
|
||||
|
||||
override fun visitValueParameter(declaration: IrValueParameter) {
|
||||
(declaration.descriptor as? WrappedValueParameterDescriptor)?.bind(declaration)
|
||||
(declaration.descriptor as? WrappedReceiverParameterDescriptor)?.bind(declaration)
|
||||
declaration.acceptChildrenVoid(this)
|
||||
}
|
||||
|
||||
override fun visitTypeParameter(declaration: IrTypeParameter) {
|
||||
(declaration.descriptor as? WrappedTypeParameterDescriptor)?.bind(declaration)
|
||||
declaration.acceptChildrenVoid(this)
|
||||
}
|
||||
|
||||
override fun visitVariable(declaration: IrVariable) {
|
||||
(declaration.descriptor as? WrappedVariableDescriptor)?.bind(declaration)
|
||||
declaration.acceptChildrenVoid(this)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.ir.util
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
|
||||
object NullDescriptorsRemapper : DescriptorsRemapper {
|
||||
override fun remapDeclaredClass(descriptor: ClassDescriptor): ClassDescriptor? = null
|
||||
override fun remapDeclaredConstructor(descriptor: ClassConstructorDescriptor): ClassConstructorDescriptor? = null
|
||||
override fun remapDeclaredEnumEntry(descriptor: ClassDescriptor): ClassDescriptor? = null
|
||||
override fun remapDeclaredField(descriptor: PropertyDescriptor): PropertyDescriptor? = null
|
||||
override fun remapDeclaredSimpleFunction(descriptor: FunctionDescriptor): FunctionDescriptor? = null
|
||||
override fun remapDeclaredProperty(descriptor: PropertyDescriptor): PropertyDescriptor? = null
|
||||
override fun remapDeclaredTypeParameter(descriptor: TypeParameterDescriptor): TypeParameterDescriptor? = null
|
||||
override fun remapDeclaredVariable(descriptor: VariableDescriptor): VariableDescriptor? = null
|
||||
override fun remapDeclaredValueParameter(descriptor: ParameterDescriptor): ParameterDescriptor? = null
|
||||
}
|
||||
Reference in New Issue
Block a user