turn on explicitApi for SIR modules
Merge-request: KT-MR-13448 Merged-by: Artem Olkov <artem.olkov@jetbrains.com>
This commit is contained in:
@@ -4,6 +4,10 @@ plugins {
|
||||
|
||||
description = "Build Swift IR from Analysis API"
|
||||
|
||||
kotlin {
|
||||
explicitApi()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly(kotlinStdlib())
|
||||
|
||||
|
||||
+3
-3
@@ -17,11 +17,11 @@ import org.jetbrains.kotlin.sir.analysisapi.transformers.toForeignFunction
|
||||
/**
|
||||
* A root interface for classes that produce Swift IR elements.
|
||||
*/
|
||||
interface SirFactory {
|
||||
fun build(fromFile: KtFile): List<SirDeclaration>
|
||||
public interface SirFactory {
|
||||
public fun build(fromFile: KtFile): List<SirDeclaration>
|
||||
}
|
||||
|
||||
class SirGenerator : SirFactory {
|
||||
public class SirGenerator : SirFactory {
|
||||
override fun build(fromFile: KtFile): List<SirDeclaration> = analyze(fromFile) {
|
||||
val res = mutableListOf<SirForeignFunction>()
|
||||
fromFile.accept(Visitor(res))
|
||||
|
||||
@@ -4,6 +4,10 @@ plugins {
|
||||
|
||||
description = "SIR to Kotlin bindings generator"
|
||||
|
||||
kotlin {
|
||||
explicitApi()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly(kotlinStdlib())
|
||||
|
||||
|
||||
+21
-21
@@ -16,10 +16,10 @@ import org.jetbrains.kotlin.sir.bridge.impl.KotlinBridgePrinter
|
||||
* @param function SIR function we are generating bridge for
|
||||
* @param bridgeName C name of the bridge
|
||||
*/
|
||||
class BridgeRequest(
|
||||
val function: SirFunction,
|
||||
val bridgeName: String,
|
||||
val fqName: List<String>,
|
||||
public class BridgeRequest(
|
||||
public val function: SirFunction,
|
||||
public val bridgeName: String,
|
||||
public val fqName: List<String>,
|
||||
)
|
||||
|
||||
/**
|
||||
@@ -27,9 +27,9 @@ class BridgeRequest(
|
||||
* Abstracts away all nuances of Kotlin compiler ABI, making it possible
|
||||
* to call Kotlin code from other environments.
|
||||
*/
|
||||
class FunctionBridge(
|
||||
val kotlinFunctionBridge: KotlinFunctionBridge,
|
||||
val cDeclarationBridge: CFunctionBridge,
|
||||
public class FunctionBridge(
|
||||
public val kotlinFunctionBridge: KotlinFunctionBridge,
|
||||
public val cDeclarationBridge: CFunctionBridge,
|
||||
)
|
||||
|
||||
/**
|
||||
@@ -38,9 +38,9 @@ class FunctionBridge(
|
||||
* @param lines with function declaration.
|
||||
* @param headerDependencies required headers.
|
||||
*/
|
||||
class CFunctionBridge(
|
||||
val lines: List<String>,
|
||||
val headerDependencies: List<String>,
|
||||
public class CFunctionBridge(
|
||||
public val lines: List<String>,
|
||||
public val headerDependencies: List<String>,
|
||||
)
|
||||
|
||||
/**
|
||||
@@ -49,39 +49,39 @@ class CFunctionBridge(
|
||||
* @param lines definition of Kotlin bridge.
|
||||
* @param packageDependencies required packages to make sources compile.
|
||||
*/
|
||||
class KotlinFunctionBridge(
|
||||
val lines: List<String>,
|
||||
val packageDependencies: List<String>,
|
||||
public class KotlinFunctionBridge(
|
||||
public val lines: List<String>,
|
||||
public val packageDependencies: List<String>,
|
||||
)
|
||||
|
||||
/**
|
||||
* Generates [FunctionBridge] that binds SIR function to its Kotlin origin.
|
||||
*/
|
||||
interface BridgeGenerator {
|
||||
fun generate(request: BridgeRequest): FunctionBridge
|
||||
public interface BridgeGenerator {
|
||||
public fun generate(request: BridgeRequest): FunctionBridge
|
||||
}
|
||||
|
||||
/**
|
||||
* A common interface for classes that serialize [FunctionBridge] in some form.
|
||||
*/
|
||||
interface BridgePrinter {
|
||||
public interface BridgePrinter {
|
||||
/**
|
||||
* Populate printer with an additional [bridge].
|
||||
*/
|
||||
fun add(bridge: FunctionBridge)
|
||||
public fun add(bridge: FunctionBridge)
|
||||
|
||||
/**
|
||||
* Outputs the aggregated result.
|
||||
*/
|
||||
fun print(): Sequence<String>
|
||||
public fun print(): Sequence<String>
|
||||
}
|
||||
|
||||
fun createBridgeGenerator(): BridgeGenerator =
|
||||
public fun createBridgeGenerator(): BridgeGenerator =
|
||||
BridgeGeneratorImpl()
|
||||
|
||||
fun createCBridgePrinter(): BridgePrinter =
|
||||
public fun createCBridgePrinter(): BridgePrinter =
|
||||
CBridgePrinter()
|
||||
|
||||
fun createKotlinBridgePrinter(): BridgePrinter =
|
||||
public fun createKotlinBridgePrinter(): BridgePrinter =
|
||||
KotlinBridgePrinter()
|
||||
|
||||
|
||||
+2
-2
@@ -96,7 +96,7 @@ private fun bridgeParameter(parameter: SirParameter): BridgeParameter {
|
||||
)
|
||||
}
|
||||
|
||||
fun createBridgeParameterName(kotlinName: String): String {
|
||||
public fun createBridgeParameterName(kotlinName: String): String {
|
||||
// TODO: Post-process because C has stricter naming conventions.
|
||||
return kotlinName
|
||||
}
|
||||
@@ -111,7 +111,7 @@ internal data class CBridgeParameter(
|
||||
val type: CType,
|
||||
)
|
||||
|
||||
enum class CType(val repr: String) {
|
||||
public enum class CType(public val repr: String) {
|
||||
Bool("_Bool"),
|
||||
|
||||
Int8("int8_t"),
|
||||
|
||||
@@ -4,6 +4,10 @@ plugins {
|
||||
|
||||
description = "Infrastructure of transformations over SIR"
|
||||
|
||||
kotlin {
|
||||
explicitApi()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly(kotlinStdlib())
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import org.jetbrains.kotlin.sir.SirElement
|
||||
* Swift IR is supposed to be transformed by a series of passes.
|
||||
* This is a base interface that all such passes should implement.
|
||||
*/
|
||||
interface SirPass<out R, in T> {
|
||||
public interface SirPass<out R, in T> {
|
||||
|
||||
/**
|
||||
* Executes the pass over the given [SirElement].
|
||||
@@ -20,5 +20,5 @@ interface SirPass<out R, in T> {
|
||||
* @param data Additional data that is required to run the pass.
|
||||
* @return The result of the pass.
|
||||
*/
|
||||
fun run(element: SirElement, data: T): R
|
||||
public fun run(element: SirElement, data: T): R
|
||||
}
|
||||
+1
-1
@@ -22,7 +22,7 @@ import java.lang.IllegalStateException
|
||||
* or `element` does not contain origin of type `SirOrigin.KotlinEntity.Function`,
|
||||
* returns original element.
|
||||
*/
|
||||
class ForeignIntoSwiftFunctionTranslationPass : SirPass<SirElement, Unit> {
|
||||
public class ForeignIntoSwiftFunctionTranslationPass : SirPass<SirElement, Unit> {
|
||||
|
||||
private class Transformer : SirTransformer<Unit>() {
|
||||
override fun <E : SirElement> transformElement(element: E, data: Unit): E {
|
||||
|
||||
@@ -4,6 +4,10 @@ plugins {
|
||||
|
||||
description = "Printer for SIR"
|
||||
|
||||
kotlin {
|
||||
explicitApi()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly(kotlinStdlib())
|
||||
|
||||
|
||||
@@ -11,12 +11,12 @@ import org.jetbrains.kotlin.utils.SmartPrinter
|
||||
|
||||
private const val DEFAULT_INDENT: String = " "
|
||||
|
||||
class SirAsSwiftSourcesPrinter : SirVisitor<Unit, SmartPrinter>() {
|
||||
fun print(element: SirElement): String = buildString {
|
||||
public class SirAsSwiftSourcesPrinter : SirVisitor<Unit, SmartPrinter>() {
|
||||
public fun print(element: SirElement): String = buildString {
|
||||
element.accept(this@SirAsSwiftSourcesPrinter, SmartPrinter(this))
|
||||
}.trim()
|
||||
|
||||
override fun visitModule(module: SirModule, data: SmartPrinter) = with(data) {
|
||||
override fun visitModule(module: SirModule, data: SmartPrinter): Unit = with(data) {
|
||||
module.declarations.forEach {
|
||||
it.accept(this@SirAsSwiftSourcesPrinter, this)
|
||||
if (module.declarations.last() != it) {
|
||||
|
||||
Reference in New Issue
Block a user