commonMain.co.touchlab.skie.phases.features.suspend.SuspendGenerator.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-compiler-linker-plugin-kgp_1.9.20 Show documentation
Show all versions of kotlin-compiler-linker-plugin-kgp_1.9.20 Show documentation
Kotlin compiler plugin that improves Swift interface of a Kotlin Multiplatform framework.
The newest version!
package co.touchlab.skie.phases.features.suspend
import co.touchlab.skie.configuration.SkieConfigurationFlag
import co.touchlab.skie.configuration.isSuspendInteropEnabled
import co.touchlab.skie.configuration.provider.descriptor.configuration
import co.touchlab.skie.kir.descriptor.DescriptorProvider
import co.touchlab.skie.kir.descriptor.allExposedMembers
import co.touchlab.skie.phases.FrontendIrPhase
import co.touchlab.skie.phases.descriptorProvider
import co.touchlab.skie.phases.util.StatefulKirPhase
import co.touchlab.skie.phases.util.StatefulSirPhase
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
object SuspendGenerator : FrontendIrPhase {
context(FrontendIrPhase.Context)
override fun isActive(): Boolean = SkieConfigurationFlag.Feature_CoroutinesInterop.isEnabled
context(FrontendIrPhase.Context)
override suspend fun execute() {
val kotlinDelegate = KotlinSuspendGeneratorDelegate(context)
val swiftDelegate = SwiftSuspendGeneratorDelegate(context)
descriptorProvider.allSupportedFunctions.forEach { function ->
val kotlinBridgingFunction = kotlinDelegate.generateKotlinBridgingFunction(function)
swiftDelegate.generateSwiftBridgingFunction(function, kotlinBridgingFunction)
}
}
context(FrontendIrPhase.Context)
private val DescriptorProvider.allSupportedFunctions: List
get() = this.allExposedMembers.filterIsInstance()
.filter { mapper.isBaseMethod(it) }
.filter { it.isSupported }
.filter { it.configuration.isSuspendInteropEnabled }
private val SimpleFunctionDescriptor.isSupported: Boolean
get() = this.isSuspend
object FlowMappingConfigurationPhase : StatefulKirPhase()
object KotlinBridgingFunctionVisibilityConfigurationInitPhase : StatefulKirPhase()
object KotlinBridgingFunctionVisibilityConfigurationFinalizePhase : StatefulSirPhase()
object SwiftBridgeGeneratorInitPhase : StatefulKirPhase()
object SwiftBridgeGeneratorFinalizePhase : StatefulSirPhase()
}