diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/NameProvider.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/NameProvider.kt new file mode 100644 index 00000000000..1a8ef49dbbe --- /dev/null +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/NameProvider.kt @@ -0,0 +1,17 @@ +/* + * 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.DeclarationDescriptor +import org.jetbrains.kotlin.name.Name + +interface NameProvider { + fun nameForDeclaration(descriptor: DeclarationDescriptor): Name + + object DEFAULT : NameProvider { + override fun nameForDeclaration(descriptor: DeclarationDescriptor): Name = descriptor.name + } +} \ No newline at end of file diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/SymbolTable.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/SymbolTable.kt index a50629e95de..59ad7648f9c 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/SymbolTable.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/SymbolTable.kt @@ -30,6 +30,7 @@ import org.jetbrains.kotlin.ir.symbols.* import org.jetbrains.kotlin.ir.symbols.impl.* import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.kotlin.ir.types.impl.IrUninitializedType +import org.jetbrains.kotlin.resolve.descriptorUtil.isEffectivelyExternal import org.jetbrains.kotlin.serialization.deserialization.descriptors.DescriptorWithContainerSource interface IrProvider { @@ -86,7 +87,7 @@ interface ReferenceSymbolTable { fun leaveScope(owner: DeclarationDescriptor) } -open class SymbolTable(val signaturer: IdSignatureComposer) : ReferenceSymbolTable { +open class SymbolTable(val signaturer: IdSignatureComposer, val nameProvider: NameProvider = NameProvider.DEFAULT) : ReferenceSymbolTable { @Suppress("LeakingThis") val lazyWrapper = IrLazySymbolTable(this) @@ -164,7 +165,8 @@ open class SymbolTable(val signaturer: IdSignatureComposer) : ReferenceSymbolTab } } - private open inner class FlatSymbolTable> : SymbolTableBase() { + private open inner class FlatSymbolTable> : + SymbolTableBase() { val descriptorToSymbol = linkedMapOf() val idSigToSymbol = linkedMapOf() @@ -353,7 +355,7 @@ open class SymbolTable(val signaturer: IdSignatureComposer) : ReferenceSymbolTab fun declareScript( descriptor: ScriptDescriptor, scriptFactory: (IrScriptSymbol) -> IrScript = { symbol: IrScriptSymbol -> - IrScriptImpl(symbol, descriptor.name) + IrScriptImpl(symbol, nameProvider.nameForDeclaration(descriptor)) } ): IrScript { return scriptSymbolTable.declare( @@ -371,7 +373,18 @@ open class SymbolTable(val signaturer: IdSignatureComposer) : ReferenceSymbolTab startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, descriptor: ClassDescriptor, modality: Modality = descriptor.modality, visibility: Visibility = descriptor.visibility, classFactory: (IrClassSymbol) -> IrClass = { - IrClassImpl(startOffset, endOffset, origin, it, modality, visibility).apply { metadata = MetadataSource.Class(it.descriptor) } + IrClassImpl( + startOffset, endOffset, origin, it, + nameProvider.nameForDeclaration(descriptor), descriptor.kind, + visibility, modality, + isCompanion = descriptor.isCompanionObject, + isInner = descriptor.isInner, + isData = descriptor.isData, + isExternal = descriptor.isExternal, + isInline = descriptor.isInline, + isExpect = descriptor.isExpect, + isFun = descriptor.isFun + ).apply { metadata = MetadataSource.Class(it.descriptor) } } ): IrClass { return classSymbolTable.declare( @@ -414,7 +427,16 @@ open class SymbolTable(val signaturer: IdSignatureComposer) : ReferenceSymbolTab origin: IrDeclarationOrigin, descriptor: ClassConstructorDescriptor, constructorFactory: (IrConstructorSymbol) -> IrConstructor = { - IrConstructorImpl(startOffset, endOffset, origin, it, IrUninitializedType).apply { + IrConstructorImpl( + startOffset, endOffset, origin, it, + nameProvider.nameForDeclaration(descriptor), + descriptor.visibility, + returnType = IrUninitializedType, + isInline = descriptor.isInline, + isExternal = descriptor.isEffectivelyExternal(), + isPrimary = descriptor.isPrimary, + isExpect = descriptor.isExpect + ).apply { metadata = MetadataSource.Function(it.descriptor) } } @@ -457,7 +479,9 @@ open class SymbolTable(val signaturer: IdSignatureComposer) : ReferenceSymbolTab fun declareEnumEntry( startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, descriptor: ClassDescriptor, - factory: (IrEnumEntrySymbol) -> IrEnumEntry = { IrEnumEntryImpl(startOffset, endOffset, origin, it) } + factory: (IrEnumEntrySymbol) -> IrEnumEntry = { + IrEnumEntryImpl(startOffset, endOffset, origin, it, nameProvider.nameForDeclaration(descriptor)) + } ): IrEnumEntry = enumEntrySymbolTable.declare( descriptor, @@ -502,7 +526,15 @@ open class SymbolTable(val signaturer: IdSignatureComposer) : ReferenceSymbolTab type: IrType, visibility: Visibility? = null, fieldFactory: (IrFieldSymbol) -> IrField = { - IrFieldImpl(startOffset, endOffset, origin, it, type, visibility ?: it.descriptor.visibility).apply { + IrFieldImpl( + startOffset, endOffset, origin, it, + nameProvider.nameForDeclaration(descriptor), + type, visibility ?: it.descriptor.visibility, + isFinal = !descriptor.isVar, + isExternal = descriptor.isExternal, + isStatic = descriptor.dispatchReceiverParameter == null, + isFakeOverride = origin == IrDeclarationOrigin.FAKE_OVERRIDE + ).apply { metadata = MetadataSource.Property(it.descriptor) } } @@ -563,7 +595,10 @@ open class SymbolTable(val signaturer: IdSignatureComposer) : ReferenceSymbolTab descriptor: PropertyDescriptor, @Suppress("DEPRECATION") isDelegated: Boolean = descriptor.isDelegated, propertyFactory: (IrPropertySymbol) -> IrProperty = { symbol -> - IrPropertyImpl(startOffset, endOffset, origin, symbol, isDelegated = isDelegated).apply { + IrPropertyImpl( + startOffset, endOffset, origin, symbol, isDelegated = isDelegated, + name = nameProvider.nameForDeclaration(descriptor) + ).apply { metadata = MetadataSource.Property(symbol.descriptor) } } @@ -640,7 +675,20 @@ open class SymbolTable(val signaturer: IdSignatureComposer) : ReferenceSymbolTab origin: IrDeclarationOrigin, descriptor: FunctionDescriptor, functionFactory: (IrSimpleFunctionSymbol) -> IrSimpleFunction = { - IrFunctionImpl(startOffset, endOffset, origin, it, IrUninitializedType).apply { + IrFunctionImpl( + startOffset, endOffset, origin, it, + nameProvider.nameForDeclaration(descriptor), + returnType = IrUninitializedType, + visibility = descriptor.visibility, + modality = descriptor.modality, + isInline = descriptor.isInline, + isExternal = descriptor.isExternal, + isTailrec = descriptor.isTailrec, + isSuspend = descriptor.isSuspend, + isOperator = descriptor.isOperator, + isExpect = descriptor.isExpect, + isFakeOverride = origin == IrDeclarationOrigin.FAKE_OVERRIDE + ).apply { metadata = MetadataSource.Function(it.descriptor) } } @@ -690,7 +738,13 @@ open class SymbolTable(val signaturer: IdSignatureComposer) : ReferenceSymbolTab endOffset: Int, origin: IrDeclarationOrigin, descriptor: TypeParameterDescriptor, - typeParameterFactory: (IrTypeParameterSymbol) -> IrTypeParameter = { IrTypeParameterImpl(startOffset, endOffset, origin, it) } + typeParameterFactory: (IrTypeParameterSymbol) -> IrTypeParameter = { + IrTypeParameterImpl( + startOffset, endOffset, origin, it, + nameProvider.nameForDeclaration(descriptor), + descriptor.index, descriptor.isReified, descriptor.variance + ) + } ): IrTypeParameter = globalTypeParameterSymbolTable.declare( descriptor, @@ -712,7 +766,13 @@ open class SymbolTable(val signaturer: IdSignatureComposer) : ReferenceSymbolTab endOffset: Int, origin: IrDeclarationOrigin, descriptor: TypeParameterDescriptor, - typeParameterFactory: (IrTypeParameterSymbol) -> IrTypeParameter = { IrTypeParameterImpl(startOffset, endOffset, origin, it) } + typeParameterFactory: (IrTypeParameterSymbol) -> IrTypeParameter = { + IrTypeParameterImpl( + startOffset, endOffset, origin, it, + nameProvider.nameForDeclaration(descriptor), + descriptor.index, descriptor.isReified, descriptor.variance + ) + } ): IrTypeParameter = scopedTypeParameterSymbolTable.declare( descriptor, @@ -739,7 +799,15 @@ open class SymbolTable(val signaturer: IdSignatureComposer) : ReferenceSymbolTab type: IrType, varargElementType: IrType? = null, valueParameterFactory: (IrValueParameterSymbol) -> IrValueParameter = { - IrValueParameterImpl(startOffset, endOffset, origin, it, type, varargElementType) + val valueParameterDescriptor = descriptor as? ValueParameterDescriptor + IrValueParameterImpl( + startOffset, endOffset, origin, it, + nameProvider.nameForDeclaration(descriptor), + valueParameterDescriptor?.index ?: -1, + type, varargElementType, + isCrossinline = valueParameterDescriptor?.isCrossinline ?: false, + isNoinline = valueParameterDescriptor?.isNoinline ?: false + ) } ): IrValueParameter = valueParameterSymbolTable.declareLocal( @@ -775,7 +843,14 @@ open class SymbolTable(val signaturer: IdSignatureComposer) : ReferenceSymbolTab descriptor: VariableDescriptor, type: IrType, variableFactory: (IrVariableSymbol) -> IrVariable = { - IrVariableImpl(startOffset, endOffset, origin, it, type) + IrVariableImpl( + startOffset, endOffset, origin, it, + nameProvider.nameForDeclaration(descriptor), + type, + isVar = descriptor.isVar, + isConst = descriptor.isConst, + isLateinit = descriptor.isLateInit + ) } ): IrVariable = @@ -810,7 +885,11 @@ open class SymbolTable(val signaturer: IdSignatureComposer) : ReferenceSymbolTab localDelegatedPropertySymbolTable.declareLocal( descriptor, { IrLocalDelegatedPropertySymbolImpl(descriptor) }, - { IrLocalDelegatedPropertyImpl(startOffset, endOffset, origin, it, type) } + { + IrLocalDelegatedPropertyImpl( + startOffset, endOffset, origin, it, nameProvider.nameForDeclaration(descriptor), type, descriptor.isVar + ) + } ) fun referenceLocalDelegatedProperty(descriptor: VariableDescriptorWithAccessors) =