Cleanup: ExpectDependencyGenerator
This commit is contained in:
+17
-13
@@ -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.
|
||||
// This is neccessary because there is no explicit links between expects and actuals
|
||||
// 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 {
|
||||
|
||||
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 {
|
||||
body(it)
|
||||
}
|
||||
@@ -27,11 +31,11 @@ fun referenceExpectsForUsedActuals(expectDescriptorToSymbol: MutableMap<Declarat
|
||||
}
|
||||
|
||||
override fun visitClass(declaration: IrClass) {
|
||||
declaration.forEachExpect {
|
||||
val symbol = symbolTable.referenceClass(it as ClassDescriptor)
|
||||
expectDescriptorToSymbol.put(it, symbol);
|
||||
it.constructors.forEach {
|
||||
expectDescriptorToSymbol.put(it, symbolTable.referenceConstructor(it as ClassConstructorDescriptor))
|
||||
declaration.forEachExpect { expectDescriptor ->
|
||||
val symbol = symbolTable.referenceClass(expectDescriptor as ClassDescriptor)
|
||||
expectDescriptorToSymbol[expectDescriptor] = symbol
|
||||
expectDescriptor.constructors.forEach {
|
||||
expectDescriptorToSymbol[it] = symbolTable.referenceConstructor(it as ClassConstructorDescriptor)
|
||||
}
|
||||
}
|
||||
super.visitDeclaration(declaration)
|
||||
@@ -39,8 +43,8 @@ fun referenceExpectsForUsedActuals(expectDescriptorToSymbol: MutableMap<Declarat
|
||||
|
||||
override fun visitSimpleFunction(declaration: IrSimpleFunction) {
|
||||
declaration.forEachExpect {
|
||||
val symbol = symbolTable.referenceSimpleFunction(it as FunctionDescriptor);
|
||||
expectDescriptorToSymbol.put(it, symbol);
|
||||
val symbol = symbolTable.referenceSimpleFunction(it as FunctionDescriptor)
|
||||
expectDescriptorToSymbol[it] = symbol
|
||||
}
|
||||
super.visitDeclaration(declaration)
|
||||
}
|
||||
@@ -48,7 +52,7 @@ fun referenceExpectsForUsedActuals(expectDescriptorToSymbol: MutableMap<Declarat
|
||||
override fun visitConstructor(declaration: IrConstructor) {
|
||||
declaration.forEachExpect {
|
||||
val symbol = symbolTable.referenceConstructor(it as ClassConstructorDescriptor)
|
||||
expectDescriptorToSymbol.put(it, symbol);
|
||||
expectDescriptorToSymbol[it] = symbol
|
||||
|
||||
}
|
||||
super.visitDeclaration(declaration)
|
||||
@@ -57,7 +61,7 @@ fun referenceExpectsForUsedActuals(expectDescriptorToSymbol: MutableMap<Declarat
|
||||
override fun visitProperty(declaration: IrProperty) {
|
||||
declaration.forEachExpect {
|
||||
val symbol = symbolTable.referenceProperty(it as PropertyDescriptor)
|
||||
expectDescriptorToSymbol.put(it, symbol);
|
||||
expectDescriptorToSymbol[it] = symbol
|
||||
}
|
||||
super.visitDeclaration(declaration)
|
||||
}
|
||||
@@ -65,7 +69,7 @@ fun referenceExpectsForUsedActuals(expectDescriptorToSymbol: MutableMap<Declarat
|
||||
override fun visitEnumEntry(declaration: IrEnumEntry) {
|
||||
declaration.forEachExpect {
|
||||
val symbol = symbolTable.referenceEnumEntry(it as ClassDescriptor)
|
||||
expectDescriptorToSymbol.put(it, symbol);
|
||||
expectDescriptorToSymbol[it] = symbol
|
||||
|
||||
}
|
||||
super.visitDeclaration(declaration)
|
||||
@@ -77,7 +81,7 @@ fun referenceExpectsForUsedActuals(expectDescriptorToSymbol: MutableMap<Declarat
|
||||
is ClassDescriptor -> symbolTable.referenceClass(it)
|
||||
else -> error("Unexpected expect for actual type alias: $it")
|
||||
}
|
||||
expectDescriptorToSymbol.put(it, symbol);
|
||||
expectDescriptorToSymbol[it] = symbol
|
||||
|
||||
}
|
||||
super.visitDeclaration(declaration)
|
||||
|
||||
Reference in New Issue
Block a user