[FIR2IR] Use specific symbols for enum entries
This commit is contained in:
+14
-5
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.fir.declarations.*
|
|||||||
import org.jetbrains.kotlin.fir.resolve.firProvider
|
import org.jetbrains.kotlin.fir.resolve.firProvider
|
||||||
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.Fir2IrClassSymbol
|
import org.jetbrains.kotlin.fir.symbols.Fir2IrClassSymbol
|
||||||
|
import org.jetbrains.kotlin.fir.symbols.Fir2IrEnumEntrySymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.StandardClassIds
|
import org.jetbrains.kotlin.fir.symbols.StandardClassIds
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.ConeClassLikeLookupTagImpl
|
import org.jetbrains.kotlin.fir.symbols.impl.ConeClassLikeLookupTagImpl
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
|
||||||
@@ -23,6 +24,7 @@ import org.jetbrains.kotlin.ir.descriptors.*
|
|||||||
import org.jetbrains.kotlin.ir.expressions.impl.IrEnumConstructorCallImpl
|
import org.jetbrains.kotlin.ir.expressions.impl.IrEnumConstructorCallImpl
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.IrExpressionBodyImpl
|
import org.jetbrains.kotlin.ir.expressions.impl.IrExpressionBodyImpl
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||||
|
import org.jetbrains.kotlin.ir.symbols.IrEnumEntrySymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl
|
import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl
|
||||||
@@ -322,19 +324,26 @@ class Fir2IrClassifierStorage(
|
|||||||
|
|
||||||
fun getCachedIrEnumEntry(enumEntry: FirEnumEntry): IrEnumEntry? = enumEntryCache[enumEntry]
|
fun getCachedIrEnumEntry(enumEntry: FirEnumEntry): IrEnumEntry? = enumEntryCache[enumEntry]
|
||||||
|
|
||||||
|
private fun declareIrEnumEntry(signature: IdSignature?, factory: (IrEnumEntrySymbol) -> IrEnumEntry): IrEnumEntry {
|
||||||
|
if (signature == null) {
|
||||||
|
val descriptor = WrappedEnumEntryDescriptor()
|
||||||
|
return symbolTable.declareEnumEntry(0, 0, IrDeclarationOrigin.DEFINED, descriptor, factory).apply { descriptor.bind(this) }
|
||||||
|
}
|
||||||
|
return symbolTable.declareEnumEntry(signature, { Fir2IrEnumEntrySymbol(signature) }, factory)
|
||||||
|
}
|
||||||
|
|
||||||
fun createIrEnumEntry(
|
fun createIrEnumEntry(
|
||||||
enumEntry: FirEnumEntry,
|
enumEntry: FirEnumEntry,
|
||||||
irParent: IrClass?,
|
irParent: IrClass?,
|
||||||
origin: IrDeclarationOrigin = IrDeclarationOrigin.DEFINED
|
origin: IrDeclarationOrigin = IrDeclarationOrigin.DEFINED
|
||||||
): IrEnumEntry {
|
): IrEnumEntry {
|
||||||
return enumEntry.convertWithOffsets { startOffset, endOffset ->
|
return enumEntry.convertWithOffsets { startOffset, endOffset ->
|
||||||
val desc = WrappedEnumEntryDescriptor()
|
val signature = signatureComposer.composeSignature(enumEntry)
|
||||||
declarationStorage.enterScope(desc)
|
val result = declareIrEnumEntry(signature) { symbol ->
|
||||||
val result = symbolTable.declareEnumEntry(startOffset, endOffset, origin, desc) { symbol ->
|
|
||||||
IrEnumEntryImpl(
|
IrEnumEntryImpl(
|
||||||
startOffset, endOffset, origin, symbol, enumEntry.name
|
startOffset, endOffset, origin, symbol, enumEntry.name
|
||||||
).apply {
|
).apply {
|
||||||
desc.bind(this)
|
declarationStorage.enterScope(descriptor)
|
||||||
val irType = enumEntry.returnTypeRef.toIrType()
|
val irType = enumEntry.returnTypeRef.toIrType()
|
||||||
if (irParent != null) {
|
if (irParent != null) {
|
||||||
this.parent = irParent
|
this.parent = irParent
|
||||||
@@ -350,9 +359,9 @@ class Fir2IrClassifierStorage(
|
|||||||
IrEnumConstructorCallImpl(startOffset, endOffset, irType, irParent.constructors.first().symbol)
|
IrEnumConstructorCallImpl(startOffset, endOffset, irType, irParent.constructors.first().symbol)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
declarationStorage.leaveScope(descriptor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
declarationStorage.leaveScope(desc)
|
|
||||||
enumEntryCache[enumEntry] = result
|
enumEntryCache[enumEntry] = result
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|||||||
+4
@@ -49,6 +49,10 @@ class FirBasedSignatureComposer(private val mangler: FirMangler) : Fir2IrSignatu
|
|||||||
hashId = mangler.run { property.signatureMangle }
|
hashId = mangler.run { property.signatureMangle }
|
||||||
setExpected(property.isExpect)
|
setExpected(property.isExpect)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun visitEnumEntry(enumEntry: FirEnumEntry) {
|
||||||
|
setExpected(enumEntry.isExpect)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val CallableId.relativeCallableName: FqName
|
private val CallableId.relativeCallableName: FqName
|
||||||
|
|||||||
@@ -515,6 +515,12 @@ open class SymbolTable(
|
|||||||
factory
|
factory
|
||||||
)
|
)
|
||||||
|
|
||||||
|
fun declareEnumEntry(
|
||||||
|
sig: IdSignature,
|
||||||
|
symbolFactory: () -> IrEnumEntrySymbol,
|
||||||
|
enumEntryFactory: (IrEnumEntrySymbol) -> IrEnumEntry
|
||||||
|
): IrEnumEntry = enumEntrySymbolTable.declare(sig, symbolFactory, enumEntryFactory)
|
||||||
|
|
||||||
fun declareEnumEntryIfNotExists(descriptor: ClassDescriptor, factory: (IrEnumEntrySymbol) -> IrEnumEntry): IrEnumEntry {
|
fun declareEnumEntryIfNotExists(descriptor: ClassDescriptor, factory: (IrEnumEntrySymbol) -> IrEnumEntry): IrEnumEntry {
|
||||||
return enumEntrySymbolTable.declareIfNotExists(descriptor, { createEnumEntrySymbol(descriptor) }, factory)
|
return enumEntrySymbolTable.declareIfNotExists(descriptor, { createEnumEntrySymbol(descriptor) }, factory)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user