Cleanup: ExpectDependencyGenerator

This commit is contained in:
Mikhail Glukhikh
2020-05-28 09:21:00 +03:00
parent c9f2876368
commit 25b1059f74
@@ -13,10 +13,14 @@ import org.jetbrains.kotlin.resolve.multiplatform.findExpects
// Need to create unbound symbols for expects corresponding to actuals of the currently compiled module. // Need to create unbound symbols for expects corresponding to actuals of the currently compiled module.
// This is neccessary because there is no explicit links between expects and actuals // This is neccessary because there is no explicit links between expects and actuals
// neither in descriptors nor in IR. // neither in descriptors nor in IR.
fun referenceExpectsForUsedActuals(expectDescriptorToSymbol: MutableMap<DeclarationDescriptor, IrSymbol>, symbolTable: SymbolTable, irModule: IrModuleFragment) { fun referenceExpectsForUsedActuals(
expectDescriptorToSymbol: MutableMap<DeclarationDescriptor, IrSymbol>,
symbolTable: SymbolTable,
irModule: IrModuleFragment
) {
irModule.acceptVoid(object : IrElementVisitorVoid { irModule.acceptVoid(object : IrElementVisitorVoid {
private fun <T> T.forEachExpect(body: (DeclarationDescriptor) -> Unit) where T: IrDeclaration { private fun <T> T.forEachExpect(body: (DeclarationDescriptor) -> Unit) where T : IrDeclaration {
this.descriptor.findExpects().forEach { this.descriptor.findExpects().forEach {
body(it) body(it)
} }
@@ -27,11 +31,11 @@ fun referenceExpectsForUsedActuals(expectDescriptorToSymbol: MutableMap<Declarat
} }
override fun visitClass(declaration: IrClass) { override fun visitClass(declaration: IrClass) {
declaration.forEachExpect { declaration.forEachExpect { expectDescriptor ->
val symbol = symbolTable.referenceClass(it as ClassDescriptor) val symbol = symbolTable.referenceClass(expectDescriptor as ClassDescriptor)
expectDescriptorToSymbol.put(it, symbol); expectDescriptorToSymbol[expectDescriptor] = symbol
it.constructors.forEach { expectDescriptor.constructors.forEach {
expectDescriptorToSymbol.put(it, symbolTable.referenceConstructor(it as ClassConstructorDescriptor)) expectDescriptorToSymbol[it] = symbolTable.referenceConstructor(it as ClassConstructorDescriptor)
} }
} }
super.visitDeclaration(declaration) super.visitDeclaration(declaration)
@@ -39,8 +43,8 @@ fun referenceExpectsForUsedActuals(expectDescriptorToSymbol: MutableMap<Declarat
override fun visitSimpleFunction(declaration: IrSimpleFunction) { override fun visitSimpleFunction(declaration: IrSimpleFunction) {
declaration.forEachExpect { declaration.forEachExpect {
val symbol = symbolTable.referenceSimpleFunction(it as FunctionDescriptor); val symbol = symbolTable.referenceSimpleFunction(it as FunctionDescriptor)
expectDescriptorToSymbol.put(it, symbol); expectDescriptorToSymbol[it] = symbol
} }
super.visitDeclaration(declaration) super.visitDeclaration(declaration)
} }
@@ -48,7 +52,7 @@ fun referenceExpectsForUsedActuals(expectDescriptorToSymbol: MutableMap<Declarat
override fun visitConstructor(declaration: IrConstructor) { override fun visitConstructor(declaration: IrConstructor) {
declaration.forEachExpect { declaration.forEachExpect {
val symbol = symbolTable.referenceConstructor(it as ClassConstructorDescriptor) val symbol = symbolTable.referenceConstructor(it as ClassConstructorDescriptor)
expectDescriptorToSymbol.put(it, symbol); expectDescriptorToSymbol[it] = symbol
} }
super.visitDeclaration(declaration) super.visitDeclaration(declaration)
@@ -57,7 +61,7 @@ fun referenceExpectsForUsedActuals(expectDescriptorToSymbol: MutableMap<Declarat
override fun visitProperty(declaration: IrProperty) { override fun visitProperty(declaration: IrProperty) {
declaration.forEachExpect { declaration.forEachExpect {
val symbol = symbolTable.referenceProperty(it as PropertyDescriptor) val symbol = symbolTable.referenceProperty(it as PropertyDescriptor)
expectDescriptorToSymbol.put(it, symbol); expectDescriptorToSymbol[it] = symbol
} }
super.visitDeclaration(declaration) super.visitDeclaration(declaration)
} }
@@ -65,7 +69,7 @@ fun referenceExpectsForUsedActuals(expectDescriptorToSymbol: MutableMap<Declarat
override fun visitEnumEntry(declaration: IrEnumEntry) { override fun visitEnumEntry(declaration: IrEnumEntry) {
declaration.forEachExpect { declaration.forEachExpect {
val symbol = symbolTable.referenceEnumEntry(it as ClassDescriptor) val symbol = symbolTable.referenceEnumEntry(it as ClassDescriptor)
expectDescriptorToSymbol.put(it, symbol); expectDescriptorToSymbol[it] = symbol
} }
super.visitDeclaration(declaration) super.visitDeclaration(declaration)
@@ -77,7 +81,7 @@ fun referenceExpectsForUsedActuals(expectDescriptorToSymbol: MutableMap<Declarat
is ClassDescriptor -> symbolTable.referenceClass(it) is ClassDescriptor -> symbolTable.referenceClass(it)
else -> error("Unexpected expect for actual type alias: $it") else -> error("Unexpected expect for actual type alias: $it")
} }
expectDescriptorToSymbol.put(it, symbol); expectDescriptorToSymbol[it] = symbol
} }
super.visitDeclaration(declaration) super.visitDeclaration(declaration)