FIR2IR: fix top-level parent settings thus fixing Cli.testFirHello
This commit is contained in:
+16
-2
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.fir.descriptors.FirModuleDescriptor
|
|||||||
import org.jetbrains.kotlin.fir.descriptors.FirPackageFragmentDescriptor
|
import org.jetbrains.kotlin.fir.descriptors.FirPackageFragmentDescriptor
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirVariable
|
import org.jetbrains.kotlin.fir.expressions.FirVariable
|
||||||
import org.jetbrains.kotlin.fir.render
|
import org.jetbrains.kotlin.fir.render
|
||||||
|
import org.jetbrains.kotlin.fir.resolve.FirProvider
|
||||||
import org.jetbrains.kotlin.fir.resolve.FirSymbolProvider
|
import org.jetbrains.kotlin.fir.resolve.FirSymbolProvider
|
||||||
import org.jetbrains.kotlin.fir.resolve.getOrPut
|
import org.jetbrains.kotlin.fir.resolve.getOrPut
|
||||||
import org.jetbrains.kotlin.fir.service
|
import org.jetbrains.kotlin.fir.service
|
||||||
@@ -44,8 +45,12 @@ class Fir2IrDeclarationStorage(
|
|||||||
) {
|
) {
|
||||||
private val firSymbolProvider = session.service<FirSymbolProvider>()
|
private val firSymbolProvider = session.service<FirSymbolProvider>()
|
||||||
|
|
||||||
|
private val firProvider = session.service<FirProvider>()
|
||||||
|
|
||||||
private val fragmentCache = mutableMapOf<FqName, IrExternalPackageFragment>()
|
private val fragmentCache = mutableMapOf<FqName, IrExternalPackageFragment>()
|
||||||
|
|
||||||
|
private val fileCache = mutableMapOf<FirFile, IrFile>()
|
||||||
|
|
||||||
private val classCache = mutableMapOf<FirRegularClass, IrClass>()
|
private val classCache = mutableMapOf<FirRegularClass, IrClass>()
|
||||||
|
|
||||||
private val typeParameterCache = mutableMapOf<FirTypeParameter, IrTypeParameter>()
|
private val typeParameterCache = mutableMapOf<FirTypeParameter, IrTypeParameter>()
|
||||||
@@ -62,6 +67,10 @@ class Fir2IrDeclarationStorage(
|
|||||||
|
|
||||||
private val unitType = session.builtinTypes.unitType.toIrType(session, this)
|
private val unitType = session.builtinTypes.unitType.toIrType(session, this)
|
||||||
|
|
||||||
|
fun registerFile(firFile: FirFile, irFile: IrFile) {
|
||||||
|
fileCache[firFile] = irFile
|
||||||
|
}
|
||||||
|
|
||||||
fun enterScope(descriptor: DeclarationDescriptor) {
|
fun enterScope(descriptor: DeclarationDescriptor) {
|
||||||
irSymbolTable.enterScope(descriptor)
|
irSymbolTable.enterScope(descriptor)
|
||||||
if (descriptor is WrappedSimpleFunctionDescriptor ||
|
if (descriptor is WrappedSimpleFunctionDescriptor ||
|
||||||
@@ -219,8 +228,13 @@ class Fir2IrDeclarationStorage(
|
|||||||
null
|
null
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val packageFqName = callableId.packageName
|
val containerFile = firProvider.getFirCallableContainerFile(firBasedSymbol)
|
||||||
getIrExternalPackageFragment(packageFqName)
|
if (containerFile != null) {
|
||||||
|
fileCache[containerFile]
|
||||||
|
} else {
|
||||||
|
val packageFqName = callableId.packageName
|
||||||
|
getIrExternalPackageFragment(packageFqName)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ import org.jetbrains.kotlin.fir.scopes.impl.FirClassSubstitutionScope
|
|||||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||||
import org.jetbrains.kotlin.fir.types.*
|
import org.jetbrains.kotlin.fir.types.*
|
||||||
import org.jetbrains.kotlin.fir.visitors.FirDefaultVisitor
|
import org.jetbrains.kotlin.fir.visitors.FirDefaultVisitor
|
||||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
|
||||||
import org.jetbrains.kotlin.ir.IrElement
|
import org.jetbrains.kotlin.ir.IrElement
|
||||||
import org.jetbrains.kotlin.ir.IrStatement
|
import org.jetbrains.kotlin.ir.IrStatement
|
||||||
import org.jetbrains.kotlin.ir.builders.*
|
import org.jetbrains.kotlin.ir.builders.*
|
||||||
@@ -142,6 +141,7 @@ class Fir2IrVisitor(
|
|||||||
sourceManager.getOrCreateFileEntry(file.psi as KtFile),
|
sourceManager.getOrCreateFileEntry(file.psi as KtFile),
|
||||||
moduleDescriptor.findPackageFragmentForFile(file)
|
moduleDescriptor.findPackageFragmentForFile(file)
|
||||||
).withParent {
|
).withParent {
|
||||||
|
declarationStorage.registerFile(file, this)
|
||||||
file.declarations.forEach {
|
file.declarations.forEach {
|
||||||
val irDeclaration = it.toIrDeclaration() ?: return@forEach
|
val irDeclaration = it.toIrDeclaration() ?: return@forEach
|
||||||
declarations += irDeclaration
|
declarations += irDeclaration
|
||||||
|
|||||||
Reference in New Issue
Block a user