[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
|
package org.jetbrains.kotlin.fir.backend
|
||||||
|
|
||||||
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
|
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.declarations.IrConstructor
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.IrConstructorCallImpl
|
import org.jetbrains.kotlin.ir.expressions.impl.IrConstructorCallImpl
|
||||||
@@ -17,45 +20,69 @@ import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance
|
|||||||
|
|
||||||
class Fir2IrBuiltIns(
|
class Fir2IrBuiltIns(
|
||||||
private val components: Fir2IrComponents,
|
private val components: Fir2IrComponents,
|
||||||
private val provider: Fir2IrSpecialSymbolProvider?
|
private val provider: Fir2IrSpecialSymbolProvider
|
||||||
) : Fir2IrComponents by components {
|
) : Fir2IrComponents by components {
|
||||||
init {
|
init {
|
||||||
provider?.initComponents(components)
|
provider.initComponents(components)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val enhancedNullabilityAnnotationSymbol by lazy {
|
// ---------------------- special annotations ----------------------
|
||||||
annotationSymbolById(StandardClassIds.Annotations.EnhancedNullability)
|
|
||||||
|
private val enhancedNullabilityAnnotationIrSymbol by lazy {
|
||||||
|
specialAnnotationIrSymbolById(StandardClassIds.Annotations.EnhancedNullability)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun enhancedNullabilityAnnotationConstructorCall(): IrConstructorCall? =
|
internal fun enhancedNullabilityAnnotationConstructorCall(): IrConstructorCall? =
|
||||||
enhancedNullabilityAnnotationSymbol?.toConstructorCall()
|
enhancedNullabilityAnnotationIrSymbol?.toConstructorCall()
|
||||||
|
|
||||||
private val flexibleNullabilityAnnotationSymbol by lazy {
|
private val flexibleNullabilityAnnotationSymbol by lazy {
|
||||||
annotationSymbolById(StandardClassIds.Annotations.FlexibleNullability)
|
specialAnnotationIrSymbolById(StandardClassIds.Annotations.FlexibleNullability)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun flexibleNullabilityAnnotationConstructorCall(): IrConstructorCall? =
|
internal fun flexibleNullabilityAnnotationConstructorCall(): IrConstructorCall? =
|
||||||
flexibleNullabilityAnnotationSymbol?.toConstructorCall()
|
flexibleNullabilityAnnotationSymbol?.toConstructorCall()
|
||||||
|
|
||||||
private val extensionFunctionTypeAnnotationSymbol by lazy {
|
|
||||||
annotationSymbolById(StandardClassIds.Annotations.ExtensionFunctionType)
|
|
||||||
}
|
|
||||||
|
|
||||||
internal fun extensionFunctionTypeAnnotationConstructorCall(): IrConstructorCall? =
|
|
||||||
extensionFunctionTypeAnnotationSymbol?.toConstructorCall()
|
|
||||||
|
|
||||||
private val rawTypeAnnotationSymbol by lazy {
|
private val rawTypeAnnotationSymbol by lazy {
|
||||||
annotationSymbolById(StandardClassIds.Annotations.RawTypeAnnotation)
|
specialAnnotationIrSymbolById(StandardClassIds.Annotations.RawTypeAnnotation)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun rawTypeAnnotationConstructorCall(): IrConstructorCall? =
|
internal fun rawTypeAnnotationConstructorCall(): IrConstructorCall? =
|
||||||
rawTypeAnnotationSymbol?.toConstructorCall()
|
rawTypeAnnotationSymbol?.toConstructorCall()
|
||||||
|
|
||||||
private fun annotationSymbolById(id: ClassId): IrClassSymbol? =
|
// ---------------------- regular annotations ----------------------
|
||||||
provider?.getClassSymbolById(id) ?: session.symbolProvider.getClassLikeSymbolByClassId(id)?.toSymbol(
|
|
||||||
ConversionTypeContext.DEFAULT
|
|
||||||
) as? IrClassSymbol
|
|
||||||
|
|
||||||
private fun IrClassSymbol.toConstructorCall(): IrConstructorCallImpl =
|
private val extensionFunctionTypeAnnotationFirSymbol by lazy {
|
||||||
IrConstructorCallImpl.fromSymbolOwner(defaultType, owner.declarations.firstIsInstance<IrConstructor>().symbol)
|
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,
|
irMangler: KotlinMangler.IrMangler,
|
||||||
irFactory: IrFactory,
|
irFactory: IrFactory,
|
||||||
visibilityConverter: Fir2IrVisibilityConverter,
|
visibilityConverter: Fir2IrVisibilityConverter,
|
||||||
specialSymbolProvider: Fir2IrSpecialSymbolProvider?,
|
specialSymbolProvider: Fir2IrSpecialSymbolProvider,
|
||||||
irGenerationExtensions: Collection<IrGenerationExtension>
|
irGenerationExtensions: Collection<IrGenerationExtension>
|
||||||
): Fir2IrResult {
|
): Fir2IrResult {
|
||||||
val moduleDescriptor = FirModuleDescriptor(session)
|
val moduleDescriptor = FirModuleDescriptor(session)
|
||||||
|
|||||||
Reference in New Issue
Block a user