[FIR2IR] Add enum entries to Fir2IrLazyClass for enums
This commit is contained in:
committed by
Space
parent
7390d8cd54
commit
4db579e128
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.fir.backend
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.fir.containingClass
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.*
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnonymousObjectExpression
|
||||
@@ -462,6 +463,43 @@ class Fir2IrClassifierStorage(
|
||||
else
|
||||
symbolTable.declareEnumEntry(signature, { Fir2IrEnumEntrySymbol(signature) }, factory)
|
||||
|
||||
fun getIrEnumEntry(
|
||||
enumEntry: FirEnumEntry,
|
||||
irParent: IrClass?,
|
||||
predefinedOrigin: IrDeclarationOrigin? = null,
|
||||
forceTopLevelPrivate: Boolean = false,
|
||||
): IrEnumEntry {
|
||||
getCachedIrEnumEntry(enumEntry)?.let { return it }
|
||||
val containingFile = firProvider.getFirCallableContainerFile(enumEntry.symbol)
|
||||
val irParentClass = irParent ?: enumEntry.containingClass()?.let { findIrClass(it) }
|
||||
|
||||
@Suppress("NAME_SHADOWING")
|
||||
val predefinedOrigin = predefinedOrigin ?: if (containingFile != null) {
|
||||
IrDeclarationOrigin.DEFINED
|
||||
} else {
|
||||
irParentClass?.origin ?: IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB
|
||||
}
|
||||
return createIrEnumEntry(
|
||||
enumEntry,
|
||||
irParent = irParentClass,
|
||||
predefinedOrigin = predefinedOrigin,
|
||||
forceTopLevelPrivate
|
||||
)
|
||||
}
|
||||
|
||||
fun findIrClass(lookupTag: ConeClassLikeLookupTag): IrClass? {
|
||||
return if (lookupTag.classId.isLocal) {
|
||||
getCachedLocalClass(lookupTag)
|
||||
} else {
|
||||
val firSymbol = lookupTag.toSymbol(session)
|
||||
if (firSymbol is FirClassSymbol) {
|
||||
getIrClassSymbol(firSymbol).owner
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun createIrEnumEntry(
|
||||
enumEntry: FirEnumEntry,
|
||||
irParent: IrClass?,
|
||||
|
||||
+2
-14
@@ -236,18 +236,6 @@ class Fir2IrDeclarationStorage(
|
||||
}
|
||||
}
|
||||
|
||||
private fun findIrClass(lookupTag: ConeClassLikeLookupTag): IrClass? =
|
||||
if (lookupTag.classId.isLocal) {
|
||||
classifierStorage.getCachedLocalClass(lookupTag)
|
||||
} else {
|
||||
val firSymbol = lookupTag.toSymbol(session)
|
||||
if (firSymbol is FirClassSymbol) {
|
||||
classifierStorage.getIrClassSymbol(firSymbol).owner
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
internal fun findIrParent(
|
||||
packageFqName: FqName,
|
||||
parentLookupTag: ConeClassLikeLookupTag?,
|
||||
@@ -255,7 +243,7 @@ class Fir2IrDeclarationStorage(
|
||||
firOrigin: FirDeclarationOrigin
|
||||
): IrDeclarationParent? {
|
||||
return if (parentLookupTag != null) {
|
||||
findIrClass(parentLookupTag)
|
||||
classifierStorage.findIrClass(parentLookupTag)
|
||||
} else {
|
||||
val containerFile = when (firBasedSymbol) {
|
||||
is FirCallableSymbol -> firProvider.getFirCallableContainerFile(firBasedSymbol)
|
||||
@@ -1573,7 +1561,7 @@ class Fir2IrDeclarationStorage(
|
||||
is FirEnumEntry -> {
|
||||
classifierStorage.getCachedIrEnumEntry(firDeclaration)?.let { return it.symbol }
|
||||
val containingFile = firProvider.getFirCallableContainerFile(firVariableSymbol)
|
||||
val irParentClass = firDeclaration.containingClass()?.let { findIrClass(it) }
|
||||
val irParentClass = firDeclaration.containingClass()?.let { classifierStorage.findIrClass(it) }
|
||||
classifierStorage.createIrEnumEntry(
|
||||
firDeclaration,
|
||||
irParent = irParentClass,
|
||||
|
||||
@@ -169,7 +169,7 @@ class FirIrProvider(val fir2IrComponents: Fir2IrComponents) : IrProvider {
|
||||
(firDeclaration as FirRegularClass).symbol,
|
||||
forceTopLevelPrivate = isTopLevelPrivate
|
||||
).owner
|
||||
SymbolKind.ENUM_ENTRY_SYMBOL -> classifierStorage.createIrEnumEntry(
|
||||
SymbolKind.ENUM_ENTRY_SYMBOL -> classifierStorage.getIrEnumEntry(
|
||||
firDeclaration as FirEnumEntry, parent as IrClass, forceTopLevelPrivate = isTopLevelPrivate
|
||||
)
|
||||
SymbolKind.CONSTRUCTOR_SYMBOL -> {
|
||||
|
||||
@@ -169,14 +169,25 @@ class Fir2IrLazyClass(
|
||||
// Handle generated methods for enum classes (values(), valueOf(String)).
|
||||
if (fir.classKind == ClassKind.ENUM_CLASS) {
|
||||
for (declaration in fir.declarations) {
|
||||
if (declaration !is FirSimpleFunction || !declaration.isStatic || !shouldBuildStub(declaration)) continue
|
||||
// TODO we also come here for all deserialized / enhanced static enum members (with declaration.source == null).
|
||||
// For such members we currently can't tell whether they are compiler-generated methods or not.
|
||||
// Note: we must drop declarations from Java here to avoid FirJavaTypeRefs inside
|
||||
if (declaration.source == null && declaration.origin !is FirDeclarationOrigin.Java ||
|
||||
declaration.source?.kind == KtFakeSourceElementKind.EnumGeneratedDeclaration
|
||||
) {
|
||||
result += declarationStorage.getIrFunctionSymbol(declaration.symbol, forceTopLevelPrivate = isTopLevelPrivate).owner
|
||||
if (declaration !is FirCallableDeclaration || !declaration.isStatic || !shouldBuildStub(declaration)) continue
|
||||
|
||||
when (declaration) {
|
||||
is FirSimpleFunction -> {
|
||||
// TODO we also come here for all deserialized / enhanced static enum members (with declaration.source == null).
|
||||
// For such members we currently can't tell whether they are compiler-generated methods or not.
|
||||
// Note: we must drop declarations from Java here to avoid FirJavaTypeRefs inside
|
||||
if (declaration.source == null && declaration.origin !is FirDeclarationOrigin.Java ||
|
||||
declaration.source?.kind == KtFakeSourceElementKind.EnumGeneratedDeclaration
|
||||
) {
|
||||
result += declarationStorage.getIrFunctionSymbol(declaration.symbol, forceTopLevelPrivate = isTopLevelPrivate).owner
|
||||
}
|
||||
}
|
||||
|
||||
is FirEnumEntry -> {
|
||||
result += declarationStorage.getIrValueSymbol(declaration.symbol).owner as IrDeclaration
|
||||
}
|
||||
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user