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