[Interop][Linker] Simplify IrProviderForCEnumAndCStructStubs

This commit is contained in:
Sergey Bogolepov
2020-03-30 12:58:29 +07:00
committed by Sergey Bogolepov
parent 6c24e9091d
commit 0e9dbf3939
2 changed files with 9 additions and 18 deletions
@@ -245,12 +245,10 @@ internal val psiToIrPhase = konanUnitPhase(
if (this.stdlibModule in modulesWithoutDCE) { if (this.stdlibModule in modulesWithoutDCE) {
functionIrClassFactory.buildAllClasses() functionIrClassFactory.buildAllClasses()
} }
modulesWithoutDCE
.filter(ModuleDescriptor::isFromInteropLibrary)
.forEach(irProviderForCEnumsAndCStructs::buildAllEnumsAndStructsFrom)
module.acceptVoid(ManglerChecker(KonanManglerIr, Ir2DescriptorManglerAdapter(KonanManglerDesc))) module.acceptVoid(ManglerChecker(KonanManglerIr, Ir2DescriptorManglerAdapter(KonanManglerDesc)))
module.files += irProviderForCEnumsAndCStructs.outputFiles
irModule = module irModule = module
irModules = deserializer.modules.filterValues { llvmModuleSpecification.containsModule(it) } irModules = deserializer.modules.filterValues { llvmModuleSpecification.containsModule(it) }
ir.symbols = symbols ir.symbols = symbols
@@ -258,8 +256,6 @@ internal val psiToIrPhase = konanUnitPhase(
functionIrClassFactory.module = functionIrClassFactory.module =
(listOf(irModule!!) + deserializer.modules.values) (listOf(irModule!!) + deserializer.modules.values)
.single { it.descriptor.isKonanStdlib() } .single { it.descriptor.isKonanStdlib() }
irProviderForCEnumsAndCStructs.module = module
}, },
name = "Psi2Ir", name = "Psi2Ir",
description = "Psi to IR conversion", description = "Psi to IR conversion",
@@ -60,15 +60,12 @@ internal class IrProviderForCEnumAndCStructStubs(
private val cStructClassGenerator = private val cStructClassGenerator =
CStructVarClassGenerator(context, interopBuiltIns) CStructVarClassGenerator(context, interopBuiltIns)
var module: IrModuleFragment? = null /**
set(value) { * The final output of this provider is a list of files which contain IR declarations
if (value == null) * of enums and structs that should be generated.
error("Provide a valid non-null module") */
if (field != null) val outputFiles: List<IrFile>
error("Module has already been set") get() = filesMap.values.toList()
field = value
value.files += filesMap.values
}
fun canHandleSymbol(symbol: IrSymbol): Boolean { fun canHandleSymbol(symbol: IrSymbol): Boolean {
if (!symbol.isPublicApi) return false if (!symbol.isPublicApi) return false
@@ -116,9 +113,7 @@ internal class IrProviderForCEnumAndCStructStubs(
private fun irParentFor(descriptor: ClassDescriptor): IrDeclarationContainer { private fun irParentFor(descriptor: ClassDescriptor): IrDeclarationContainer {
val packageFragmentDescriptor = descriptor.findPackage() val packageFragmentDescriptor = descriptor.findPackage()
return filesMap.getOrPut(packageFragmentDescriptor) { return filesMap.getOrPut(packageFragmentDescriptor) {
IrFileImpl(NaiveSourceBasedFileEntryImpl(cTypeDefinitionsFileName), packageFragmentDescriptor).also { IrFileImpl(NaiveSourceBasedFileEntryImpl(cTypeDefinitionsFileName), packageFragmentDescriptor)
this@IrProviderForCEnumAndCStructStubs.module?.files?.add(it)
}
} }
} }