[ObjCExport] AA: Enable generation of base declarations
^KT-65738 Fixed
This commit is contained in:
committed by
Space Team
parent
2ae2f09fee
commit
e53e94516f
+7
-1
@@ -21,5 +21,11 @@ data class KtObjCExportConfiguration(
|
|||||||
* - [org.jetbrains.kotlin.backend.konan.objcexport.ObjCExportNamingHelper.canBeSwiftOuter]
|
* - [org.jetbrains.kotlin.backend.konan.objcexport.ObjCExportNamingHelper.canBeSwiftOuter]
|
||||||
* - [org.jetbrains.kotlin.backend.konan.objcexport.ObjCExportNamingHelper.canBeSwiftInner]
|
* - [org.jetbrains.kotlin.backend.konan.objcexport.ObjCExportNamingHelper.canBeSwiftInner]
|
||||||
*/
|
*/
|
||||||
val objcGenerics: Boolean = true
|
val objcGenerics: Boolean = true,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flag to enable/disable the emission of 'base declarations'
|
||||||
|
* (see [org.jetbrains.kotlin.objcexport.objCBaseDeclarations]).
|
||||||
|
*/
|
||||||
|
val generateBaseDeclarationStubs: Boolean = true,
|
||||||
)
|
)
|
||||||
|
|||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.objcexport
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.backend.konan.objcexport.ObjCTopLevel
|
||||||
|
import org.jetbrains.kotlin.backend.konan.objcexport.objCBaseDeclarations
|
||||||
|
import org.jetbrains.kotlin.objcexport.analysisApiUtils.getDefaultSuperClassOrProtocolName
|
||||||
|
|
||||||
|
context(KtObjCExportSession)
|
||||||
|
internal fun objCBaseDeclarations(): List<ObjCTopLevel> {
|
||||||
|
return objCBaseDeclarations(
|
||||||
|
topLevelNamePrefix = configuration.frameworkName.orEmpty(),
|
||||||
|
objCNameOfAny = getDefaultSuperClassOrProtocolName(),
|
||||||
|
objCNameOfNumber = "Number".getObjCKotlinStdlibClassOrProtocolName(),
|
||||||
|
objCNameOfMutableMap = "MutableDictionary".getObjCKotlinStdlibClassOrProtocolName(),
|
||||||
|
objCNameOfMutableSet = "MutableSet".getObjCKotlinStdlibClassOrProtocolName(),
|
||||||
|
objCNameForNumberBox = { classId -> classId.shortClassName.asString().getObjCKotlinStdlibClassOrProtocolName() }
|
||||||
|
)
|
||||||
|
}
|
||||||
+4
@@ -127,6 +127,10 @@ fun translateToObjCHeader(files: List<KtFile>): ObjCHeader {
|
|||||||
classForwardDeclarations.add(errorForwardClass)
|
classForwardDeclarations.add(errorForwardClass)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (configuration.generateBaseDeclarationStubs) {
|
||||||
|
stubs.addAll(0, objCBaseDeclarations())
|
||||||
|
}
|
||||||
|
|
||||||
return ObjCHeader(
|
return ObjCHeader(
|
||||||
stubs = stubs,
|
stubs = stubs,
|
||||||
classForwardDeclarations = classForwardDeclarations,
|
classForwardDeclarations = classForwardDeclarations,
|
||||||
|
|||||||
+6
-1
@@ -7,6 +7,9 @@ package org.jetbrains.kotlin.objcexport.testUtils
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.backend.konan.objcexport.ObjCTopLevel
|
import org.jetbrains.kotlin.backend.konan.objcexport.ObjCTopLevel
|
||||||
import org.jetbrains.kotlin.backend.konan.tests.ObjCExportBaseDeclarationsTest
|
import org.jetbrains.kotlin.backend.konan.tests.ObjCExportBaseDeclarationsTest
|
||||||
|
import org.jetbrains.kotlin.objcexport.KtObjCExportConfiguration
|
||||||
|
import org.jetbrains.kotlin.objcexport.KtObjCExportSession
|
||||||
|
import org.jetbrains.kotlin.objcexport.objCBaseDeclarations
|
||||||
import org.junit.jupiter.api.extension.ExtensionContext
|
import org.junit.jupiter.api.extension.ExtensionContext
|
||||||
import org.junit.jupiter.api.extension.ParameterContext
|
import org.junit.jupiter.api.extension.ParameterContext
|
||||||
import org.junit.jupiter.api.extension.ParameterResolver
|
import org.junit.jupiter.api.extension.ParameterResolver
|
||||||
@@ -23,6 +26,8 @@ class AnalysisApiBaseDeclarationsGeneratorExtension : ParameterResolver {
|
|||||||
|
|
||||||
object AnalysisApiBaseDeclarationsGenerator : ObjCExportBaseDeclarationsTest.BaseDeclarationsGenerator {
|
object AnalysisApiBaseDeclarationsGenerator : ObjCExportBaseDeclarationsTest.BaseDeclarationsGenerator {
|
||||||
override fun invoke(topLevelPrefix: String): List<ObjCTopLevel> {
|
override fun invoke(topLevelPrefix: String): List<ObjCTopLevel> {
|
||||||
TODO("Analysis Api based 'base declaration generation' in not yet implemented")
|
return KtObjCExportSession(KtObjCExportConfiguration(topLevelPrefix)) {
|
||||||
|
objCBaseDeclarations()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+6
-1
@@ -32,7 +32,12 @@ object AnalysisApiHeaderGenerator : HeaderGenerator {
|
|||||||
val session = createStandaloneAnalysisApiSession(root.listFiles().orEmpty().filter { it.extension == "kt" })
|
val session = createStandaloneAnalysisApiSession(root.listFiles().orEmpty().filter { it.extension == "kt" })
|
||||||
val (module, files) = session.modulesWithFiles.entries.single()
|
val (module, files) = session.modulesWithFiles.entries.single()
|
||||||
return analyze(module) {
|
return analyze(module) {
|
||||||
KtObjCExportSession(KtObjCExportConfiguration(frameworkName = configuration.frameworkName)) {
|
KtObjCExportSession(
|
||||||
|
KtObjCExportConfiguration(
|
||||||
|
frameworkName = configuration.frameworkName,
|
||||||
|
generateBaseDeclarationStubs = configuration.generateBaseDeclarationStubs
|
||||||
|
)
|
||||||
|
) {
|
||||||
translateToObjCHeader(files.map { it as KtFile })
|
translateToObjCHeader(files.map { it as KtFile })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
@@ -45,6 +45,11 @@ class Fe10HeaderGeneratorExtension : ParameterResolver, AfterEachCallback {
|
|||||||
private class Fe10HeaderGeneratorImpl(private val disposable: Disposable) : HeaderGenerator {
|
private class Fe10HeaderGeneratorImpl(private val disposable: Disposable) : HeaderGenerator {
|
||||||
override fun generateHeaders(root: File, configuration: HeaderGenerator.Configuration): ObjCHeader {
|
override fun generateHeaders(root: File, configuration: HeaderGenerator.Configuration): ObjCHeader {
|
||||||
val headerGenerator = createObjCExportHeaderGenerator(disposable, root, configuration)
|
val headerGenerator = createObjCExportHeaderGenerator(disposable, root, configuration)
|
||||||
|
|
||||||
|
if (configuration.generateBaseDeclarationStubs) {
|
||||||
|
headerGenerator.translateBaseDeclarations()
|
||||||
|
}
|
||||||
|
|
||||||
headerGenerator.translateModuleDeclarations()
|
headerGenerator.translateModuleDeclarations()
|
||||||
return headerGenerator.buildHeader()
|
return headerGenerator.buildHeader()
|
||||||
}
|
}
|
||||||
|
|||||||
+6
@@ -12,6 +12,12 @@ interface HeaderGenerator {
|
|||||||
|
|
||||||
data class Configuration(
|
data class Configuration(
|
||||||
val frameworkName: String = "",
|
val frameworkName: String = "",
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base declaration stubs do not change and have dedicated tests.
|
||||||
|
* We do not generate them by default to keep test data easier to read.
|
||||||
|
*/
|
||||||
|
val generateBaseDeclarationStubs: Boolean = false,
|
||||||
)
|
)
|
||||||
|
|
||||||
fun generateHeaders(root: File, configuration: Configuration = Configuration()): ObjCHeader
|
fun generateHeaders(root: File, configuration: Configuration = Configuration()): ObjCHeader
|
||||||
|
|||||||
-3
@@ -7,7 +7,6 @@ package org.jetbrains.kotlin.backend.konan.tests
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.backend.konan.objcexport.ObjCTopLevel
|
import org.jetbrains.kotlin.backend.konan.objcexport.ObjCTopLevel
|
||||||
import org.jetbrains.kotlin.backend.konan.objcexport.StubRenderer
|
import org.jetbrains.kotlin.backend.konan.objcexport.StubRenderer
|
||||||
import org.jetbrains.kotlin.backend.konan.testUtils.TodoAnalysisApi
|
|
||||||
import org.jetbrains.kotlin.backend.konan.testUtils.baseDeclarationsDir
|
import org.jetbrains.kotlin.backend.konan.testUtils.baseDeclarationsDir
|
||||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
@@ -26,13 +25,11 @@ class ObjCExportBaseDeclarationsTest(
|
|||||||
) {
|
) {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TodoAnalysisApi
|
|
||||||
fun `test - noTopLevelPrefix`() {
|
fun `test - noTopLevelPrefix`() {
|
||||||
doTest(baseDeclarationsDir.resolve("!noTopLevelPrefix.h"), "")
|
doTest(baseDeclarationsDir.resolve("!noTopLevelPrefix.h"), "")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TodoAnalysisApi
|
|
||||||
fun `test - topLevelPrefix`() {
|
fun `test - topLevelPrefix`() {
|
||||||
doTest(baseDeclarationsDir.resolve("!topLevelPrefix.h"), "MyTopLevelPrefix")
|
doTest(baseDeclarationsDir.resolve("!topLevelPrefix.h"), "MyTopLevelPrefix")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user