[interop] Move GenerationMode to StubIrContext
Knowing GenerationMode allows us to decide what elements of StubIr we want to emit. For example, it is required for enums, because a lot of information will be passed via annotations in metadata mode.
This commit is contained in:
committed by
Sergey Bogolepov
parent
88c962bfca
commit
ab82a02be8
+9
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
package org.jetbrains.kotlin.native.interop.gen
|
||||
|
||||
import org.jetbrains.kotlin.native.interop.gen.jvm.GenerationMode
|
||||
import org.jetbrains.kotlin.native.interop.gen.jvm.InteropConfiguration
|
||||
import org.jetbrains.kotlin.native.interop.gen.jvm.KotlinPlatform
|
||||
import org.jetbrains.kotlin.native.interop.indexer.*
|
||||
@@ -100,6 +101,13 @@ interface StubsBuildingContext {
|
||||
|
||||
val platform: KotlinPlatform
|
||||
|
||||
/**
|
||||
* In some cases StubIr should be different for metadata and sourcecode modes.
|
||||
* For example, it is impossible to represent call to superclass constructor in
|
||||
* metadata directly and arguments should be passed via annotations instead.
|
||||
*/
|
||||
val generationMode: GenerationMode
|
||||
|
||||
fun isStrictEnum(enumDef: EnumDef): Boolean
|
||||
|
||||
val macroConstantsByName: Map<String, MacroDef>
|
||||
@@ -132,6 +140,7 @@ class StubsBuildingContextImpl(
|
||||
|
||||
override val configuration: InteropConfiguration = stubIrContext.configuration
|
||||
override val platform: KotlinPlatform = stubIrContext.platform
|
||||
override val generationMode: GenerationMode = stubIrContext.generationMode
|
||||
val imports: Imports = stubIrContext.imports
|
||||
private val nativeIndex: NativeIndex = stubIrContext.nativeIndex
|
||||
|
||||
|
||||
+3
-3
@@ -18,6 +18,7 @@ class StubIrContext(
|
||||
val nativeIndex: NativeIndex,
|
||||
val imports: Imports,
|
||||
val platform: KotlinPlatform,
|
||||
val generationMode: GenerationMode,
|
||||
val libName: String
|
||||
) {
|
||||
val libraryForCStubs = configuration.library.copy(
|
||||
@@ -102,7 +103,6 @@ class StubIrDriver(
|
||||
private val options: DriverOptions
|
||||
) {
|
||||
data class DriverOptions(
|
||||
val mode: GenerationMode,
|
||||
val entryPoint: String?,
|
||||
val moduleName: String,
|
||||
val outCFile: File,
|
||||
@@ -116,7 +116,7 @@ class StubIrDriver(
|
||||
}
|
||||
|
||||
fun run(): Result {
|
||||
val (mode, entryPoint, moduleName, outCFile, outKtFile) = options
|
||||
val (entryPoint, moduleName, outCFile, outKtFile) = options
|
||||
|
||||
val builderResult = StubIrBuilder(context).build()
|
||||
val bridgeBuilderResult = StubIrBridgeBuilder(context, builderResult).build()
|
||||
@@ -125,7 +125,7 @@ class StubIrDriver(
|
||||
emitCFile(context, it, entryPoint, bridgeBuilderResult.nativeBridges)
|
||||
}
|
||||
|
||||
return when (mode) {
|
||||
return when (context.generationMode) {
|
||||
GenerationMode.SOURCE_CODE -> {
|
||||
emitSourceCode(outKtFile(), builderResult, bridgeBuilderResult)
|
||||
}
|
||||
|
||||
+2
-2
@@ -261,7 +261,7 @@ private fun processCLib(args: Array<String>, additionalArgs: Map<String, Any> =
|
||||
{}
|
||||
}
|
||||
|
||||
val stubIrContext = StubIrContext(logger, configuration, nativeIndex, imports, flavor, libName)
|
||||
val stubIrContext = StubIrContext(logger, configuration, nativeIndex, imports, flavor, mode, libName)
|
||||
val stubIrOutput = run {
|
||||
val outKtFileCreator = {
|
||||
val outKtFileName = fqParts.last() + ".kt"
|
||||
@@ -270,7 +270,7 @@ private fun processCLib(args: Array<String>, additionalArgs: Map<String, Any> =
|
||||
file.parentFile.mkdirs()
|
||||
file
|
||||
}
|
||||
val driverOptions = StubIrDriver.DriverOptions(mode, entryPoint, moduleName, File(outCFile.absolutePath), outKtFileCreator)
|
||||
val driverOptions = StubIrDriver.DriverOptions(entryPoint, moduleName, File(outCFile.absolutePath), outKtFileCreator)
|
||||
val stubIrDriver = StubIrDriver(stubIrContext, driverOptions)
|
||||
stubIrDriver.run()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user