[FIR2IR] Search for ExtensionFunctionType constructor symbol using symbol provider
This commit is contained in:
committed by
teamcity
parent
119bc06435
commit
c3a03de557
@@ -6,6 +6,9 @@
|
||||
package org.jetbrains.kotlin.fir.backend
|
||||
|
||||
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
|
||||
import org.jetbrains.kotlin.fir.scopes.getDeclaredConstructors
|
||||
import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
|
||||
import org.jetbrains.kotlin.ir.declarations.IrConstructor
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrConstructorCallImpl
|
||||
@@ -17,45 +20,69 @@ import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance
|
||||
|
||||
class Fir2IrBuiltIns(
|
||||
private val components: Fir2IrComponents,
|
||||
private val provider: Fir2IrSpecialSymbolProvider?
|
||||
private val provider: Fir2IrSpecialSymbolProvider
|
||||
) : Fir2IrComponents by components {
|
||||
init {
|
||||
provider?.initComponents(components)
|
||||
provider.initComponents(components)
|
||||
}
|
||||
|
||||
private val enhancedNullabilityAnnotationSymbol by lazy {
|
||||
annotationSymbolById(StandardClassIds.Annotations.EnhancedNullability)
|
||||
// ---------------------- special annotations ----------------------
|
||||
|
||||
private val enhancedNullabilityAnnotationIrSymbol by lazy {
|
||||
specialAnnotationIrSymbolById(StandardClassIds.Annotations.EnhancedNullability)
|
||||
}
|
||||
|
||||
internal fun enhancedNullabilityAnnotationConstructorCall(): IrConstructorCall? =
|
||||
enhancedNullabilityAnnotationSymbol?.toConstructorCall()
|
||||
enhancedNullabilityAnnotationIrSymbol?.toConstructorCall()
|
||||
|
||||
private val flexibleNullabilityAnnotationSymbol by lazy {
|
||||
annotationSymbolById(StandardClassIds.Annotations.FlexibleNullability)
|
||||
specialAnnotationIrSymbolById(StandardClassIds.Annotations.FlexibleNullability)
|
||||
}
|
||||
|
||||
internal fun flexibleNullabilityAnnotationConstructorCall(): IrConstructorCall? =
|
||||
flexibleNullabilityAnnotationSymbol?.toConstructorCall()
|
||||
|
||||
private val extensionFunctionTypeAnnotationSymbol by lazy {
|
||||
annotationSymbolById(StandardClassIds.Annotations.ExtensionFunctionType)
|
||||
}
|
||||
|
||||
internal fun extensionFunctionTypeAnnotationConstructorCall(): IrConstructorCall? =
|
||||
extensionFunctionTypeAnnotationSymbol?.toConstructorCall()
|
||||
|
||||
private val rawTypeAnnotationSymbol by lazy {
|
||||
annotationSymbolById(StandardClassIds.Annotations.RawTypeAnnotation)
|
||||
specialAnnotationIrSymbolById(StandardClassIds.Annotations.RawTypeAnnotation)
|
||||
}
|
||||
|
||||
internal fun rawTypeAnnotationConstructorCall(): IrConstructorCall? =
|
||||
rawTypeAnnotationSymbol?.toConstructorCall()
|
||||
|
||||
private fun annotationSymbolById(id: ClassId): IrClassSymbol? =
|
||||
provider?.getClassSymbolById(id) ?: session.symbolProvider.getClassLikeSymbolByClassId(id)?.toSymbol(
|
||||
ConversionTypeContext.DEFAULT
|
||||
) as? IrClassSymbol
|
||||
// ---------------------- regular annotations ----------------------
|
||||
|
||||
private fun IrClassSymbol.toConstructorCall(): IrConstructorCallImpl =
|
||||
IrConstructorCallImpl.fromSymbolOwner(defaultType, owner.declarations.firstIsInstance<IrConstructor>().symbol)
|
||||
private val extensionFunctionTypeAnnotationFirSymbol by lazy {
|
||||
regularAnnotationFirSymbolById(StandardClassIds.Annotations.ExtensionFunctionType)
|
||||
}
|
||||
|
||||
private val extensionFunctionTypeAnnotationSymbol by lazy {
|
||||
extensionFunctionTypeAnnotationFirSymbol?.toSymbol(ConversionTypeContext.DEFAULT) as? IrClassSymbol
|
||||
}
|
||||
|
||||
internal fun extensionFunctionTypeAnnotationConstructorCall(): IrConstructorCall? =
|
||||
extensionFunctionTypeAnnotationSymbol?.toConstructorCall(extensionFunctionTypeAnnotationFirSymbol!!)
|
||||
|
||||
// ---------------------- utils ----------------------
|
||||
|
||||
private fun specialAnnotationIrSymbolById(classId: ClassId): IrClassSymbol? {
|
||||
return provider.getClassSymbolById(classId)
|
||||
}
|
||||
|
||||
private fun regularAnnotationFirSymbolById(id: ClassId): FirRegularClassSymbol? {
|
||||
return session.symbolProvider.getClassLikeSymbolByClassId(id) as? FirRegularClassSymbol
|
||||
}
|
||||
|
||||
private fun IrClassSymbol.toConstructorCall(firSymbol: FirRegularClassSymbol? = null): IrConstructorCallImpl? {
|
||||
val constructorSymbol = if (firSymbol == null) {
|
||||
owner.declarations.firstIsInstance<IrConstructor>().symbol
|
||||
} else {
|
||||
val firConstructorSymbol = firSymbol.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = true)
|
||||
.getDeclaredConstructors()
|
||||
.singleOrNull()
|
||||
?: return null
|
||||
|
||||
declarationStorage.getIrConstructorSymbol(firConstructorSymbol)
|
||||
}
|
||||
return IrConstructorCallImpl.fromSymbolOwner(defaultType, constructorSymbol)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -425,7 +425,7 @@ class Fir2IrConverter(
|
||||
irMangler: KotlinMangler.IrMangler,
|
||||
irFactory: IrFactory,
|
||||
visibilityConverter: Fir2IrVisibilityConverter,
|
||||
specialSymbolProvider: Fir2IrSpecialSymbolProvider?,
|
||||
specialSymbolProvider: Fir2IrSpecialSymbolProvider,
|
||||
irGenerationExtensions: Collection<IrGenerationExtension>
|
||||
): Fir2IrResult {
|
||||
val moduleDescriptor = FirModuleDescriptor(session)
|
||||
|
||||
Reference in New Issue
Block a user