IR metadata source: extract & use declaration name

This commit is contained in:
Mikhail Glukhikh
2020-06-08 14:17:14 +03:00
parent b2c78e490e
commit 5c6f40b34a
3 changed files with 27 additions and 5 deletions
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.ir.declarations.MetadataSource
import org.jetbrains.kotlin.name.Name
interface FirMetadataSource : MetadataSource {
@@ -23,6 +24,9 @@ interface FirMetadataSource : MetadataSource {
) : FirMetadataSource {
override val session: FirSession
get() = klass.session
override val name: Name?
get() = (klass as? FirRegularClass)?.name
}
class Function(
@@ -30,6 +34,13 @@ interface FirMetadataSource : MetadataSource {
) : FirMetadataSource {
override val session: FirSession
get() = function.session
override val name: Name?
get() = when (function) {
is FirSimpleFunction -> function.name
is FirConstructor -> Name.special("<init>")
else -> null
}
}
class Property(
@@ -469,7 +469,7 @@ internal class FunctionReferenceLowering(private val context: JvmBackendContext)
}
private val IrFunction.originalName: Name
get() = (metadata as? MetadataSource.Function)?.descriptor?.name ?: name
get() = metadata?.name ?: name
private fun JvmIrBuilder.generateSignature(target: IrFunctionSymbol): IrExpression =
irCall(backendContext.ir.symbols.signatureStringIntrinsic).apply {
@@ -9,13 +9,24 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.name.Name
interface MetadataSource {
open class Class(val descriptor: ClassDescriptor) : MetadataSource
val name: Name?
open class File(val descriptors: List<DeclarationDescriptor>) : MetadataSource
abstract class DescriptorBased<D : DeclarationDescriptor> internal constructor(val descriptor: D) : MetadataSource {
override val name: Name
get() = descriptor.name
}
open class Function(val descriptor: FunctionDescriptor) : MetadataSource
open class Class(descriptor: ClassDescriptor) : DescriptorBased<ClassDescriptor>(descriptor)
open class Property(val descriptor: PropertyDescriptor) : MetadataSource
open class File(val descriptors: List<DeclarationDescriptor>) : MetadataSource {
override val name: Name?
get() = null
}
open class Function(descriptor: FunctionDescriptor) : DescriptorBased<FunctionDescriptor>(descriptor)
open class Property(descriptor: PropertyDescriptor) : DescriptorBased<PropertyDescriptor>(descriptor)
}