FIR2IR: register file first and convert declarations second
This allows to find parent declaration from another file correctly
This commit is contained in:
@@ -35,10 +35,13 @@ object Fir2IrConverter {
|
|||||||
typeTranslator.constantValueGenerator = constantValueGenerator
|
typeTranslator.constantValueGenerator = constantValueGenerator
|
||||||
val builtIns = IrBuiltIns(moduleDescriptor.builtIns, typeTranslator, signaturer, symbolTable)
|
val builtIns = IrBuiltIns(moduleDescriptor.builtIns, typeTranslator, signaturer, symbolTable)
|
||||||
val sourceManager = PsiSourceManager()
|
val sourceManager = PsiSourceManager()
|
||||||
val fir2irTransformer = Fir2IrVisitor(session, moduleDescriptor, symbolTable, sourceManager, builtIns, fakeOverrideMode)
|
val fir2irVisitor = Fir2IrVisitor(session, moduleDescriptor, symbolTable, sourceManager, builtIns, fakeOverrideMode)
|
||||||
val irFiles = mutableListOf<IrFile>()
|
val irFiles = mutableListOf<IrFile>()
|
||||||
for (firFile in firFiles) {
|
for (firFile in firFiles) {
|
||||||
val irFile = firFile.accept(fir2irTransformer, null) as IrFile
|
fir2irVisitor.registerFile(firFile)
|
||||||
|
}
|
||||||
|
for (firFile in firFiles) {
|
||||||
|
val irFile = firFile.accept(fir2irVisitor, null) as IrFile
|
||||||
val fileEntry = sourceManager.getOrCreateFileEntry(firFile.psi as KtFile)
|
val fileEntry = sourceManager.getOrCreateFileEntry(firFile.psi as KtFile)
|
||||||
sourceManager.putFileEntry(irFile, fileEntry)
|
sourceManager.putFileEntry(irFile, fileEntry)
|
||||||
irFiles += irFile
|
irFiles += irFile
|
||||||
|
|||||||
+5
-1
@@ -80,6 +80,10 @@ class Fir2IrDeclarationStorage(
|
|||||||
fileCache[firFile] = irFile
|
fileCache[firFile] = irFile
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getIrFile(firFile: FirFile): IrFile {
|
||||||
|
return fileCache[firFile]!!
|
||||||
|
}
|
||||||
|
|
||||||
fun enterScope(descriptor: DeclarationDescriptor) {
|
fun enterScope(descriptor: DeclarationDescriptor) {
|
||||||
irSymbolTable.enterScope(descriptor)
|
irSymbolTable.enterScope(descriptor)
|
||||||
if (descriptor is WrappedSimpleFunctionDescriptor ||
|
if (descriptor is WrappedSimpleFunctionDescriptor ||
|
||||||
@@ -525,7 +529,7 @@ class Fir2IrDeclarationStorage(
|
|||||||
|
|
||||||
fun getIrFunction(
|
fun getIrFunction(
|
||||||
function: FirSimpleFunction,
|
function: FirSimpleFunction,
|
||||||
irParent: IrDeclarationParent? = null,
|
irParent: IrDeclarationParent?,
|
||||||
shouldLeaveScope: Boolean = false,
|
shouldLeaveScope: Boolean = false,
|
||||||
origin: IrDeclarationOrigin = IrDeclarationOrigin.DEFINED
|
origin: IrDeclarationOrigin = IrDeclarationOrigin.DEFINED
|
||||||
): IrSimpleFunction {
|
): IrSimpleFunction {
|
||||||
|
|||||||
@@ -87,14 +87,16 @@ class Fir2IrVisitor(
|
|||||||
TODO("Should not be here: ${element.render()}")
|
TODO("Should not be here: ${element.render()}")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun registerFile(file: FirFile) {
|
||||||
|
val irFile = IrFileImpl(
|
||||||
|
sourceManager.getOrCreateFileEntry(file.psi as KtFile),
|
||||||
|
moduleDescriptor.getPackage(file.packageFqName).fragments.first()
|
||||||
|
)
|
||||||
|
declarationStorage.registerFile(file, irFile)
|
||||||
|
}
|
||||||
|
|
||||||
override fun visitFile(file: FirFile, data: Any?): IrFile {
|
override fun visitFile(file: FirFile, data: Any?): IrFile {
|
||||||
return conversionScope.withParent(
|
return conversionScope.withParent(declarationStorage.getIrFile(file)) {
|
||||||
IrFileImpl(
|
|
||||||
sourceManager.getOrCreateFileEntry(file.psi as KtFile),
|
|
||||||
moduleDescriptor.getPackage(file.packageFqName).fragments.first()
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
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