KT-64932: add support for no-package top level functions

Merge-request: KT-MR-13879
Merged-by: Artem Olkov <artem.olkov@jetbrains.com>
This commit is contained in:
Artem Olkov
2024-01-16 10:58:51 +00:00
committed by Space Team
parent 672c945895
commit baa0748375
6 changed files with 26 additions and 1 deletions
@@ -166,9 +166,14 @@ class SwiftExportExtension(
override fun visitFunction(function: SirFunction) {
val fqName = (function.origin as? SirKotlinOrigin.Function)?.fqName
?: return
val fqNameForBridge = if (fqName.count() == 1) {
listOf("__root__", fqName.first()) // todo: should be changed with correct mangling KT-64970
} else {
fqName
}
val bridgeRequest = BridgeRequest(
function,
fqName.joinToString("_"),
fqNameForBridge.joinToString("_"),
fqName
)
requests += bridgeRequest
+3
View File
@@ -0,0 +1,3 @@
#include <stdint.h>
int32_t __root___meaningOfLife();
+7
View File
@@ -0,0 +1,7 @@
import kotlin.native.internal.ExportedBridge
@ExportedBridge("__root___meaningOfLife")
public fun __root___meaningOfLife(): Int {
val result = meaningOfLife()
return result
}
+3
View File
@@ -0,0 +1,3 @@
public func meaningOfLife() -> Swift.Int32 {
return __root___meaningOfLife()
}
+1
View File
@@ -0,0 +1 @@
fun meaningOfLife(): Int = 420
@@ -25,6 +25,12 @@ public class SwiftExportCompilerPluginTest extends AbstractSwiftExportContextTes
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("plugins/swift-export/testData"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile(".*\\.golden\\.kt$"), TargetBackend.JVM, false);
}
@Test
@TestMetadata("no_package.kt")
public void testNo_package() throws Exception {
runTest("plugins/swift-export/testData/no_package.kt");
}
@Test
@TestMetadata("simple.kt")
public void testSimple() throws Exception {