From 4ceb988246649a04cf1c0823f38227af4fe58445 Mon Sep 17 00:00:00 2001 From: Vladimir Ivanov Date: Fri, 7 Feb 2020 16:53:41 +0300 Subject: [PATCH] Skip C overloads (#3821) --- .../jetbrains/kotlin/native/interop/gen/StubIrBuilder.kt | 7 ++++++- .../kotlin/native/interop/gen/StubIrElementBuilders.kt | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/StubIrBuilder.kt b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/StubIrBuilder.kt index 4d25a0102b7..f8c6a29d40c 100644 --- a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/StubIrBuilder.kt +++ b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/StubIrBuilder.kt @@ -123,6 +123,8 @@ interface StubsBuildingContext { fun getKotlinClassFor(objCClassOrProtocol: ObjCClassOrProtocol, isMeta: Boolean = false): Classifier fun getKotlinClassForPointed(structDecl: StructDecl): Classifier + + fun isOverloading(func: FunctionDecl): Boolean } /** @@ -146,6 +148,9 @@ class StubsBuildingContextImpl( private var theCounter = 0 + private val uniqFunctions = mutableSetOf() + override fun isOverloading(func: FunctionDecl) = !uniqFunctions.add(func.name) // TODO: params & return type. + override fun generateNextUniqueId(prefix: String) = prefix + pkgName.replace('.', '_') + theCounter++ @@ -358,7 +363,7 @@ class StubIrBuilder(private val context: StubIrContext) { private fun generateStubsForFunction(func: FunctionDecl) { try { - addStubs(FunctionStubBuilder(buildingContext, func).build()) + addStubs(FunctionStubBuilder(buildingContext, func, skipOverloads = true).build()) } catch (e: Throwable) { context.log("Warning: cannot generate stubs for function ${func.name}") } diff --git a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/StubIrElementBuilders.kt b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/StubIrElementBuilders.kt index 55a6687f51f..82771b0fa83 100644 --- a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/StubIrElementBuilders.kt +++ b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/StubIrElementBuilders.kt @@ -454,8 +454,10 @@ internal class EnumStubBuilder( internal class FunctionStubBuilder( override val context: StubsBuildingContext, - private val func: FunctionDecl + private val func: FunctionDecl, + private val skipOverloads: Boolean = false ) : StubElementBuilder { + override fun build(): List { val platform = context.platform val parameters = mutableListOf() @@ -508,6 +510,8 @@ internal class FunctionStubBuilder( context.mirror(func.returnType).argType }.toStubIrType() + if (skipOverloads && context.isOverloading(func)) + return emptyList() val annotations: List val mustBeExternal: Boolean