[FIR2IR] Introduce & use components storage
This commit is contained in:
+13
-20
@@ -6,7 +6,6 @@
|
||||
package org.jetbrains.kotlin.fir.backend
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.resolve.firProvider
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
|
||||
@@ -24,14 +23,12 @@ import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
import org.jetbrains.kotlin.ir.util.constructors
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
class Fir2IrClassifierStorage(
|
||||
session: FirSession,
|
||||
private val irSymbolTable: SymbolTable
|
||||
) {
|
||||
private val components: Fir2IrComponents
|
||||
) : Fir2IrComponents by components {
|
||||
private val firProvider = session.firProvider
|
||||
|
||||
private val classCache = mutableMapOf<FirRegularClass, IrClass>()
|
||||
@@ -44,10 +41,6 @@ class Fir2IrClassifierStorage(
|
||||
|
||||
private val localStorage = Fir2IrLocalStorage()
|
||||
|
||||
lateinit var typeConverter: Fir2IrTypeConverter
|
||||
|
||||
lateinit var declarationStorage: Fir2IrDeclarationStorage
|
||||
|
||||
private fun FirTypeRef.toIrType(typeContext: ConversionTypeContext = ConversionTypeContext.DEFAULT): IrType =
|
||||
with(typeConverter) { toIrType(typeContext) }
|
||||
|
||||
@@ -59,7 +52,7 @@ class Fir2IrClassifierStorage(
|
||||
endOffset: Int = this.endOffset
|
||||
): IrValueParameter {
|
||||
val receiverDescriptor = WrappedReceiverParameterDescriptor()
|
||||
return irSymbolTable.declareValueParameter(
|
||||
return symbolTable.declareValueParameter(
|
||||
startOffset, endOffset, thisOrigin, receiverDescriptor, thisType
|
||||
) { symbol ->
|
||||
IrValueParameterImpl(
|
||||
@@ -74,7 +67,7 @@ class Fir2IrClassifierStorage(
|
||||
}
|
||||
|
||||
private fun IrClass.setThisReceiver() {
|
||||
irSymbolTable.enterScope(descriptor)
|
||||
symbolTable.enterScope(descriptor)
|
||||
val typeArguments = this.typeParameters.map {
|
||||
IrSimpleTypeImpl(it.symbol, false, emptyList(), emptyList())
|
||||
}
|
||||
@@ -83,7 +76,7 @@ class Fir2IrClassifierStorage(
|
||||
thisType = IrSimpleTypeImpl(symbol, false, typeArguments, emptyList()),
|
||||
thisOrigin = IrDeclarationOrigin.INSTANCE_RECEIVER
|
||||
)
|
||||
irSymbolTable.leaveScope(descriptor)
|
||||
symbolTable.leaveScope(descriptor)
|
||||
}
|
||||
|
||||
internal fun preCacheTypeParameters(owner: FirTypeParametersOwner) {
|
||||
@@ -167,7 +160,7 @@ class Fir2IrClassifierStorage(
|
||||
regularClass.modality ?: Modality.FINAL
|
||||
}
|
||||
val irClass = regularClass.convertWithOffsets { startOffset, endOffset ->
|
||||
irSymbolTable.declareClass(startOffset, endOffset, origin, descriptor, modality, visibility) { symbol ->
|
||||
symbolTable.declareClass(startOffset, endOffset, origin, descriptor, modality, visibility) { symbol ->
|
||||
IrClassImpl(
|
||||
startOffset,
|
||||
endOffset,
|
||||
@@ -210,7 +203,7 @@ class Fir2IrClassifierStorage(
|
||||
val origin = IrDeclarationOrigin.DEFINED
|
||||
val modality = Modality.FINAL
|
||||
val result = anonymousObject.convertWithOffsets { startOffset, endOffset ->
|
||||
irSymbolTable.declareClass(startOffset, endOffset, origin, descriptor, modality, visibility) { symbol ->
|
||||
symbolTable.declareClass(startOffset, endOffset, origin, descriptor, modality, visibility) { symbol ->
|
||||
IrClassImpl(
|
||||
startOffset, endOffset, origin, symbol, name,
|
||||
// NB: for unknown reason, IR uses 'CLASS' kind for simple anonymous objects
|
||||
@@ -267,7 +260,7 @@ class Fir2IrClassifierStorage(
|
||||
val origin = IrDeclarationOrigin.DEFINED
|
||||
val irTypeParameter =
|
||||
convertWithOffsets { startOffset, endOffset ->
|
||||
irSymbolTable.declareGlobalTypeParameter(startOffset, endOffset, origin, descriptor) { symbol ->
|
||||
symbolTable.declareGlobalTypeParameter(startOffset, endOffset, origin, descriptor) { symbol ->
|
||||
IrTypeParameterImpl(
|
||||
startOffset, endOffset, origin, symbol,
|
||||
name, if (index < 0) 0 else index,
|
||||
@@ -304,7 +297,7 @@ class Fir2IrClassifierStorage(
|
||||
return enumEntry.convertWithOffsets { startOffset, endOffset ->
|
||||
val desc = WrappedEnumEntryDescriptor()
|
||||
declarationStorage.enterScope(desc)
|
||||
val result = irSymbolTable.declareEnumEntry(startOffset, endOffset, origin, desc) { symbol ->
|
||||
val result = symbolTable.declareEnumEntry(startOffset, endOffset, origin, desc) { symbol ->
|
||||
IrEnumEntryImpl(
|
||||
startOffset, endOffset, origin, symbol, enumEntry.name
|
||||
).apply {
|
||||
@@ -334,11 +327,11 @@ class Fir2IrClassifierStorage(
|
||||
|
||||
fun getIrClassSymbol(firClassSymbol: FirClassSymbol<*>): IrClassSymbol {
|
||||
val firClass = firClassSymbol.fir
|
||||
getCachedIrClass(firClass)?.let { return irSymbolTable.referenceClass(it.descriptor) }
|
||||
getCachedIrClass(firClass)?.let { return symbolTable.referenceClass(it.descriptor) }
|
||||
// TODO: remove all this code and change to unbound symbol creation
|
||||
val irClass = createIrClass(firClass)
|
||||
if (firClass is FirAnonymousObject || firClass is FirRegularClass && firClass.visibility == Visibilities.LOCAL) {
|
||||
return irSymbolTable.referenceClass(irClass.descriptor)
|
||||
return symbolTable.referenceClass(irClass.descriptor)
|
||||
}
|
||||
val classId = firClassSymbol.classId
|
||||
val parentId = classId.outerClassId
|
||||
@@ -350,7 +343,7 @@ class Fir2IrClassifierStorage(
|
||||
declarationStorage.addDeclarationsToExternalClass(firClass as FirRegularClass, irClass)
|
||||
}
|
||||
|
||||
return irSymbolTable.referenceClass(irClass.descriptor)
|
||||
return symbolTable.referenceClass(irClass.descriptor)
|
||||
}
|
||||
|
||||
fun getIrTypeParameterSymbol(
|
||||
@@ -359,6 +352,6 @@ class Fir2IrClassifierStorage(
|
||||
): IrTypeParameterSymbol {
|
||||
// TODO: use cached type parameter here
|
||||
val irTypeParameter = getIrTypeParameter(firTypeParameterSymbol.fir, typeContext = typeContext)
|
||||
return irSymbolTable.referenceTypeParameter(irTypeParameter.descriptor)
|
||||
return symbolTable.referenceTypeParameter(irTypeParameter.descriptor)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.fir.backend
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
|
||||
interface Fir2IrComponents {
|
||||
val session: FirSession
|
||||
val symbolTable: SymbolTable
|
||||
val irBuiltIns: IrBuiltIns
|
||||
val classifierStorage: Fir2IrClassifierStorage
|
||||
val declarationStorage: Fir2IrDeclarationStorage
|
||||
val typeConverter: Fir2IrTypeConverter
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.fir.backend
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
|
||||
class Fir2IrComponentsStorage(
|
||||
override val session: FirSession,
|
||||
override val symbolTable: SymbolTable,
|
||||
override val irBuiltIns: IrBuiltIns
|
||||
) : Fir2IrComponents {
|
||||
override lateinit var classifierStorage: Fir2IrClassifierStorage
|
||||
override lateinit var declarationStorage: Fir2IrDeclarationStorage
|
||||
override lateinit var typeConverter: Fir2IrTypeConverter
|
||||
}
|
||||
@@ -21,9 +21,8 @@ import org.jetbrains.kotlin.psi2ir.PsiSourceManager
|
||||
class Fir2IrConverter(
|
||||
private val moduleDescriptor: FirModuleDescriptor,
|
||||
private val sourceManager: PsiSourceManager,
|
||||
private val classifierStorage: Fir2IrClassifierStorage,
|
||||
private val declarationStorage: Fir2IrDeclarationStorage
|
||||
) {
|
||||
private val components: Fir2IrComponents
|
||||
) : Fir2IrComponents by components {
|
||||
|
||||
fun processLocalClassAndNestedClasses(regularClass: FirRegularClass, parent: IrDeclarationParent) {
|
||||
val irClass = registerClassAndNestedClasses(regularClass, parent)
|
||||
@@ -169,17 +168,17 @@ class Fir2IrConverter(
|
||||
typeTranslator.constantValueGenerator = constantValueGenerator
|
||||
val builtIns = IrBuiltIns(moduleDescriptor.builtIns, typeTranslator, signaturer, symbolTable)
|
||||
val sourceManager = PsiSourceManager()
|
||||
val declarationStorage = Fir2IrDeclarationStorage(session, symbolTable, moduleDescriptor)
|
||||
val classifierStorage = Fir2IrClassifierStorage(session, symbolTable)
|
||||
val typeConverter = Fir2IrTypeConverter(session, classifierStorage, builtIns)
|
||||
declarationStorage.typeConverter = typeConverter
|
||||
classifierStorage.typeConverter = typeConverter
|
||||
declarationStorage.classifierStorage = classifierStorage
|
||||
classifierStorage.declarationStorage = declarationStorage
|
||||
val components = Fir2IrComponentsStorage(session, symbolTable, builtIns)
|
||||
val declarationStorage = Fir2IrDeclarationStorage(components, moduleDescriptor)
|
||||
val classifierStorage = Fir2IrClassifierStorage(components)
|
||||
val typeConverter = Fir2IrTypeConverter(components)
|
||||
components.declarationStorage = declarationStorage
|
||||
components.classifierStorage = classifierStorage
|
||||
components.typeConverter = typeConverter
|
||||
typeConverter.initBuiltinTypes()
|
||||
val irFiles = mutableListOf<IrFile>()
|
||||
|
||||
val converter = Fir2IrConverter(moduleDescriptor, sourceManager, classifierStorage, declarationStorage)
|
||||
val converter = Fir2IrConverter(moduleDescriptor, sourceManager, components)
|
||||
for (firFile in firFiles) {
|
||||
converter.registerFileAndClasses(firFile)
|
||||
}
|
||||
@@ -190,9 +189,7 @@ class Fir2IrConverter(
|
||||
converter.processFileAndClassMembers(firFile)
|
||||
}
|
||||
|
||||
val fir2irVisitor = Fir2IrVisitor(
|
||||
session, symbolTable, classifierStorage, declarationStorage, converter, typeConverter, builtIns, fakeOverrideMode
|
||||
)
|
||||
val fir2irVisitor = Fir2IrVisitor(converter, components, fakeOverrideMode)
|
||||
for (firFile in firFiles) {
|
||||
val irFile = firFile.accept(fir2irVisitor, null) as IrFile
|
||||
val fileEntry = sourceManager.getOrCreateFileEntry(firFile.psi as KtFile)
|
||||
|
||||
+28
-35
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.fir.backend
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyGetter
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertySetter
|
||||
@@ -34,7 +33,6 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrErrorExpressionImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrExpressionBodyImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.*
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
@@ -43,10 +41,9 @@ import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
||||
import org.jetbrains.kotlin.psi.psiUtil.startOffsetSkippingComments
|
||||
|
||||
class Fir2IrDeclarationStorage(
|
||||
private val session: FirSession,
|
||||
private val irSymbolTable: SymbolTable,
|
||||
private val components: Fir2IrComponents,
|
||||
private val moduleDescriptor: FirModuleDescriptor
|
||||
) {
|
||||
) : Fir2IrComponents by components {
|
||||
private val firSymbolProvider = session.firSymbolProvider
|
||||
|
||||
private val firProvider = session.firProvider
|
||||
@@ -67,10 +64,6 @@ class Fir2IrDeclarationStorage(
|
||||
|
||||
private val localStorage = Fir2IrLocalStorage()
|
||||
|
||||
lateinit var typeConverter: Fir2IrTypeConverter
|
||||
|
||||
lateinit var classifierStorage: Fir2IrClassifierStorage
|
||||
|
||||
fun registerFile(firFile: FirFile, irFile: IrFile) {
|
||||
fileCache[firFile] = irFile
|
||||
}
|
||||
@@ -80,7 +73,7 @@ class Fir2IrDeclarationStorage(
|
||||
}
|
||||
|
||||
fun enterScope(descriptor: DeclarationDescriptor) {
|
||||
irSymbolTable.enterScope(descriptor)
|
||||
symbolTable.enterScope(descriptor)
|
||||
if (descriptor is WrappedSimpleFunctionDescriptor ||
|
||||
descriptor is WrappedClassConstructorDescriptor ||
|
||||
descriptor is WrappedPropertyDescriptor ||
|
||||
@@ -98,7 +91,7 @@ class Fir2IrDeclarationStorage(
|
||||
) {
|
||||
localStorage.leaveCallable()
|
||||
}
|
||||
irSymbolTable.leaveScope(descriptor)
|
||||
symbolTable.leaveScope(descriptor)
|
||||
}
|
||||
|
||||
private fun FirTypeRef.toIrType(typeContext: ConversionTypeContext = ConversionTypeContext.DEFAULT): IrType =
|
||||
@@ -110,7 +103,7 @@ class Fir2IrDeclarationStorage(
|
||||
private fun getIrExternalPackageFragment(fqName: FqName): IrExternalPackageFragment {
|
||||
return fragmentCache.getOrPut(fqName) {
|
||||
// TODO: module descriptor is wrong here
|
||||
return irSymbolTable.declareExternalPackageFragment(FirPackageFragmentDescriptor(fqName, moduleDescriptor))
|
||||
return symbolTable.declareExternalPackageFragment(FirPackageFragmentDescriptor(fqName, moduleDescriptor))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,7 +206,7 @@ class Fir2IrDeclarationStorage(
|
||||
val parent = this
|
||||
val descriptor = WrappedValueParameterDescriptor()
|
||||
valueParameters = listOf(
|
||||
irSymbolTable.declareValueParameter(
|
||||
symbolTable.declareValueParameter(
|
||||
startOffset, endOffset, origin, descriptor, type
|
||||
) { symbol ->
|
||||
IrValueParameterImpl(
|
||||
@@ -338,7 +331,7 @@ class Fir2IrDeclarationStorage(
|
||||
val visibility = simpleFunction?.visibility ?: Visibilities.LOCAL
|
||||
val created = function.convertWithOffsets { startOffset, endOffset ->
|
||||
enterScope(descriptor)
|
||||
val result = irSymbolTable.declareSimpleFunction(startOffset, endOffset, origin, descriptor) { symbol ->
|
||||
val result = symbolTable.declareSimpleFunction(startOffset, endOffset, origin, descriptor) { symbol ->
|
||||
IrFunctionImpl(
|
||||
startOffset, endOffset, updatedOrigin, symbol,
|
||||
name, visibility,
|
||||
@@ -378,7 +371,7 @@ class Fir2IrDeclarationStorage(
|
||||
irParent: IrClass
|
||||
): IrAnonymousInitializer {
|
||||
return anonymousInitializer.convertWithOffsets { startOffset, endOffset ->
|
||||
irSymbolTable.declareAnonymousInitializer(startOffset, endOffset, IrDeclarationOrigin.DEFINED, irParent.descriptor).apply {
|
||||
symbolTable.declareAnonymousInitializer(startOffset, endOffset, IrDeclarationOrigin.DEFINED, irParent.descriptor).apply {
|
||||
this.parent = irParent
|
||||
initializerCache[anonymousInitializer] = this
|
||||
}
|
||||
@@ -399,7 +392,7 @@ class Fir2IrDeclarationStorage(
|
||||
else -> constructor.visibility
|
||||
}
|
||||
val created = constructor.convertWithOffsets { startOffset, endOffset ->
|
||||
irSymbolTable.declareConstructor(startOffset, endOffset, origin, descriptor) { symbol ->
|
||||
symbolTable.declareConstructor(startOffset, endOffset, origin, descriptor) { symbol ->
|
||||
IrConstructorImpl(
|
||||
startOffset, endOffset, origin, symbol,
|
||||
Name.special("<init>"), visibility,
|
||||
@@ -433,7 +426,7 @@ class Fir2IrDeclarationStorage(
|
||||
WrappedFunctionDescriptorWithContainerSource(propertyDescriptor.containerSource)
|
||||
else WrappedSimpleFunctionDescriptor()
|
||||
val prefix = if (isSetter) "set" else "get"
|
||||
return irSymbolTable.declareSimpleFunction(
|
||||
return symbolTable.declareSimpleFunction(
|
||||
propertyAccessor?.psi?.startOffsetSkippingComments ?: startOffset,
|
||||
propertyAccessor?.psi?.endOffset ?: endOffset,
|
||||
origin, descriptor
|
||||
@@ -485,7 +478,7 @@ class Fir2IrDeclarationStorage(
|
||||
classifierStorage.preCacheTypeParameters(property)
|
||||
return property.convertWithOffsets { startOffset, endOffset ->
|
||||
enterScope(descriptor)
|
||||
val result = irSymbolTable.declareProperty(
|
||||
val result = symbolTable.declareProperty(
|
||||
startOffset, endOffset,
|
||||
origin, descriptor, property.delegate != null
|
||||
) { symbol ->
|
||||
@@ -542,7 +535,7 @@ class Fir2IrDeclarationStorage(
|
||||
val origin = IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB
|
||||
val type = field.returnTypeRef.toIrType()
|
||||
return field.convertWithOffsets { startOffset, endOffset ->
|
||||
irSymbolTable.declareField(
|
||||
symbolTable.declareField(
|
||||
startOffset, endOffset,
|
||||
origin, descriptor, type
|
||||
) { symbol ->
|
||||
@@ -571,7 +564,7 @@ class Fir2IrDeclarationStorage(
|
||||
val origin = IrDeclarationOrigin.DEFINED
|
||||
val type = valueParameter.returnTypeRef.toIrType()
|
||||
val irParameter = valueParameter.convertWithOffsets { startOffset, endOffset ->
|
||||
irSymbolTable.declareValueParameter(
|
||||
symbolTable.declareValueParameter(
|
||||
startOffset, endOffset, origin, descriptor, type
|
||||
) { symbol ->
|
||||
IrValueParameterImpl(
|
||||
@@ -614,7 +607,7 @@ class Fir2IrDeclarationStorage(
|
||||
isVar: Boolean, isConst: Boolean, isLateinit: Boolean
|
||||
): IrVariable {
|
||||
val descriptor = WrappedVariableDescriptor()
|
||||
return irSymbolTable.declareVariable(startOffset, endOffset, origin, descriptor, type) { symbol ->
|
||||
return symbolTable.declareVariable(startOffset, endOffset, origin, descriptor, type) { symbol ->
|
||||
IrVariableImpl(
|
||||
startOffset, endOffset, origin, symbol, name, type,
|
||||
isVar, isConst, isLateinit
|
||||
@@ -656,25 +649,25 @@ class Fir2IrDeclarationStorage(
|
||||
|
||||
fun getIrConstructorSymbol(firConstructorSymbol: FirConstructorSymbol): IrConstructorSymbol {
|
||||
val firConstructor = firConstructorSymbol.fir
|
||||
getCachedIrConstructor(firConstructor)?.let { return irSymbolTable.referenceConstructor(it.descriptor) }
|
||||
getCachedIrConstructor(firConstructor)?.let { return symbolTable.referenceConstructor(it.descriptor) }
|
||||
val irParent = findIrParent(firConstructor) as IrClass
|
||||
val parentOrigin = (irParent as? IrDeclaration)?.origin ?: IrDeclarationOrigin.DEFINED
|
||||
val irDeclaration = createIrConstructor(firConstructor, irParent, origin = parentOrigin).apply {
|
||||
setAndModifyParent(irParent)
|
||||
}
|
||||
return irSymbolTable.referenceConstructor(irDeclaration.descriptor)
|
||||
return symbolTable.referenceConstructor(irDeclaration.descriptor)
|
||||
}
|
||||
|
||||
fun getIrFunctionSymbol(firFunctionSymbol: FirFunctionSymbol<*>): IrFunctionSymbol {
|
||||
return when (val firDeclaration = firFunctionSymbol.fir) {
|
||||
is FirSimpleFunction, is FirAnonymousFunction -> {
|
||||
getCachedIrFunction(firDeclaration)?.let { return irSymbolTable.referenceSimpleFunction(it.descriptor) }
|
||||
getCachedIrFunction(firDeclaration)?.let { return symbolTable.referenceSimpleFunction(it.descriptor) }
|
||||
val irParent = findIrParent(firDeclaration)
|
||||
val parentOrigin = (irParent as? IrDeclaration)?.origin ?: IrDeclarationOrigin.DEFINED
|
||||
val irDeclaration = createIrFunction(firDeclaration, irParent, origin = parentOrigin).apply {
|
||||
setAndModifyParent(irParent)
|
||||
}
|
||||
irSymbolTable.referenceSimpleFunction(irDeclaration.descriptor)
|
||||
symbolTable.referenceSimpleFunction(irDeclaration.descriptor)
|
||||
}
|
||||
is FirConstructor -> {
|
||||
getIrConstructorSymbol(firDeclaration.symbol)
|
||||
@@ -686,20 +679,20 @@ class Fir2IrDeclarationStorage(
|
||||
fun getIrPropertyOrFieldSymbol(firVariableSymbol: FirVariableSymbol<*>): IrSymbol {
|
||||
return when (val fir = firVariableSymbol.fir) {
|
||||
is FirProperty -> {
|
||||
propertyCache[fir]?.let { return irSymbolTable.referenceProperty(it.descriptor) }
|
||||
propertyCache[fir]?.let { return symbolTable.referenceProperty(it.descriptor) }
|
||||
val irParent = findIrParent(fir)
|
||||
val parentOrigin = (irParent as? IrDeclaration)?.origin ?: IrDeclarationOrigin.DEFINED
|
||||
val irProperty = createIrProperty(fir, irParent, origin = parentOrigin).apply {
|
||||
setAndModifyParent(irParent)
|
||||
}
|
||||
irSymbolTable.referenceProperty(irProperty.descriptor)
|
||||
symbolTable.referenceProperty(irProperty.descriptor)
|
||||
}
|
||||
is FirField -> {
|
||||
fieldCache[fir]?.let { return irSymbolTable.referenceField(it.descriptor) }
|
||||
fieldCache[fir]?.let { return symbolTable.referenceField(it.descriptor) }
|
||||
val irField = createIrField(fir).apply {
|
||||
setAndModifyParent(findIrParent(fir))
|
||||
}
|
||||
irSymbolTable.referenceField(irField.descriptor)
|
||||
symbolTable.referenceField(irField.descriptor)
|
||||
}
|
||||
else -> throw IllegalArgumentException("Unexpected fir in property symbol: ${fir.render()}")
|
||||
}
|
||||
@@ -708,13 +701,13 @@ class Fir2IrDeclarationStorage(
|
||||
fun getIrBackingFieldSymbol(firVariableSymbol: FirVariableSymbol<*>): IrSymbol {
|
||||
return when (val fir = firVariableSymbol.fir) {
|
||||
is FirProperty -> {
|
||||
propertyCache[fir]?.let { return irSymbolTable.referenceField(it.backingField!!.descriptor) }
|
||||
propertyCache[fir]?.let { return symbolTable.referenceField(it.backingField!!.descriptor) }
|
||||
val irParent = findIrParent(fir)
|
||||
val parentOrigin = (irParent as? IrDeclaration)?.origin ?: IrDeclarationOrigin.DEFINED
|
||||
val irProperty = createIrProperty(fir, irParent, origin = parentOrigin).apply {
|
||||
setAndModifyParent(irParent)
|
||||
}
|
||||
irSymbolTable.referenceField(irProperty.backingField!!.descriptor)
|
||||
symbolTable.referenceField(irProperty.backingField!!.descriptor)
|
||||
}
|
||||
else -> {
|
||||
getIrVariableSymbol(fir)
|
||||
@@ -725,13 +718,13 @@ class Fir2IrDeclarationStorage(
|
||||
private fun getIrVariableSymbol(firVariable: FirVariable<*>): IrVariableSymbol {
|
||||
val irDeclaration = localStorage.getVariable(firVariable)
|
||||
?: throw IllegalArgumentException("Cannot find variable ${firVariable.render()} in local storage")
|
||||
return irSymbolTable.referenceVariable(irDeclaration.descriptor)
|
||||
return symbolTable.referenceVariable(irDeclaration.descriptor)
|
||||
}
|
||||
|
||||
fun getIrValueSymbol(firVariableSymbol: FirVariableSymbol<*>): IrSymbol {
|
||||
return when (val firDeclaration = firVariableSymbol.fir) {
|
||||
is FirEnumEntry -> {
|
||||
classifierStorage.getCachedIrEnumEntry(firDeclaration)?.let { return irSymbolTable.referenceEnumEntry(it.descriptor) }
|
||||
classifierStorage.getCachedIrEnumEntry(firDeclaration)?.let { return symbolTable.referenceEnumEntry(it.descriptor) }
|
||||
val containingFile = firProvider.getFirCallableContainerFile(firVariableSymbol)
|
||||
val parentClassSymbol = firVariableSymbol.callableId.classId?.let { firSymbolProvider.getClassLikeSymbolByFqName(it) }
|
||||
val irParentClass = (parentClassSymbol?.fir as? FirClass<*>)?.let { classifierStorage.getCachedIrClass(it) }
|
||||
@@ -740,13 +733,13 @@ class Fir2IrDeclarationStorage(
|
||||
irParent = irParentClass,
|
||||
origin = if (containingFile == null) IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB else IrDeclarationOrigin.DEFINED
|
||||
)
|
||||
irSymbolTable.referenceEnumEntry(irEnumEntry.descriptor)
|
||||
symbolTable.referenceEnumEntry(irEnumEntry.descriptor)
|
||||
}
|
||||
is FirValueParameter -> {
|
||||
val irDeclaration = localStorage.getParameter(firDeclaration)
|
||||
// catch parameter is FirValueParameter in FIR but IrVariable in IR
|
||||
?: return getIrVariableSymbol(firDeclaration)
|
||||
irSymbolTable.referenceValueParameter(irDeclaration.descriptor)
|
||||
symbolTable.referenceValueParameter(irDeclaration.descriptor)
|
||||
}
|
||||
else -> {
|
||||
getIrVariableSymbol(firDeclaration)
|
||||
|
||||
@@ -5,11 +5,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.backend
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.StandardClassIds
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.IrTypeArgument
|
||||
@@ -20,10 +18,8 @@ import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
class Fir2IrTypeConverter(
|
||||
private val session: FirSession,
|
||||
private val classifierStorage: Fir2IrClassifierStorage,
|
||||
private val irBuiltIns: IrBuiltIns
|
||||
) {
|
||||
private val components: Fir2IrComponents
|
||||
) : Fir2IrComponents by components {
|
||||
lateinit var nothingType: IrType
|
||||
lateinit var unitType: IrType
|
||||
lateinit var booleanType: IrType
|
||||
|
||||
@@ -33,7 +33,6 @@ import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
import org.jetbrains.kotlin.ir.builders.*
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFieldImpl
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.*
|
||||
import org.jetbrains.kotlin.ir.symbols.*
|
||||
@@ -45,15 +44,10 @@ import org.jetbrains.kotlin.psi.*
|
||||
import java.util.*
|
||||
|
||||
class Fir2IrVisitor(
|
||||
private val session: FirSession,
|
||||
private val symbolTable: SymbolTable,
|
||||
private val classifierStorage: Fir2IrClassifierStorage,
|
||||
private val declarationStorage: Fir2IrDeclarationStorage,
|
||||
private val converter: Fir2IrConverter,
|
||||
private val typeConverter: Fir2IrTypeConverter,
|
||||
override val irBuiltIns: IrBuiltIns,
|
||||
private val components: Fir2IrComponents,
|
||||
fakeOverrideMode: FakeOverrideMode
|
||||
) : FirDefaultVisitor<IrElement, Any?>(), IrGeneratorContextInterface {
|
||||
) : Fir2IrComponents by components, FirDefaultVisitor<IrElement, Any?>(), IrGeneratorContextInterface {
|
||||
companion object {
|
||||
private val NEGATED_OPERATIONS: Set<FirOperation> = EnumSet.of(FirOperation.NOT_EQ, FirOperation.NOT_IDENTITY)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user