diff --git a/native/swift/sir-analysis-api/build.gradle.kts b/native/swift/sir-analysis-api/build.gradle.kts new file mode 100644 index 00000000000..00be91114c4 --- /dev/null +++ b/native/swift/sir-analysis-api/build.gradle.kts @@ -0,0 +1,20 @@ +plugins { + kotlin("jvm") +} + +description = "Build Swift IR from Analysis" + +dependencies { + compileOnly(kotlinStdlib()) + + api(project(":native:swift:sir")) + api(project(":analysis:analysis-api")) + + testImplementation(libs.junit4) + testImplementation(projectTests(":compiler:tests-common")) +} + +sourceSets { + "main" { projectDefault() } + "test" { projectDefault() } +} \ No newline at end of file diff --git a/native/swift/sir-analysis-api/src/org/jetbrains/kotlin/sir/analysisapi/SirGenerator.kt b/native/swift/sir-analysis-api/src/org/jetbrains/kotlin/sir/analysisapi/SirGenerator.kt new file mode 100644 index 00000000000..53e1f16564a --- /dev/null +++ b/native/swift/sir-analysis-api/src/org/jetbrains/kotlin/sir/analysisapi/SirGenerator.kt @@ -0,0 +1,15 @@ +/* + * Copyright 2010-2023 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.sir.analysisapi + +import org.jetbrains.kotlin.sir.SirElement + +/** + * A root interface for classes that produce Swift IR elements. + */ +interface SirFactory { + fun build(): SirElement +} \ No newline at end of file diff --git a/native/swift/sir-analysis-api/tests/org/jetbrains/kotlin/sir/analysisapi/FactoryTests.kt b/native/swift/sir-analysis-api/tests/org/jetbrains/kotlin/sir/analysisapi/FactoryTests.kt new file mode 100644 index 00000000000..7934cbcdf31 --- /dev/null +++ b/native/swift/sir-analysis-api/tests/org/jetbrains/kotlin/sir/analysisapi/FactoryTests.kt @@ -0,0 +1,28 @@ +/* + * Copyright 2010-2023 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.sir.analysisapi + +import org.jetbrains.kotlin.sir.SirElement +import org.junit.Test +import kotlin.test.assertEquals + +class FactoryTests { + @Test + fun smoke() { + val expectedString = "Element from factory" + val myFactory = object : SirFactory { + override fun build(): SirElement { + return object : SirElement { + override fun toString(): String { + return expectedString + } + } + } + } + val element = myFactory.build() + assertEquals(expectedString, element.toString()) + } +} \ No newline at end of file diff --git a/native/swift/sir-passes/build.gradle.kts b/native/swift/sir-passes/build.gradle.kts new file mode 100644 index 00000000000..315b1fbd941 --- /dev/null +++ b/native/swift/sir-passes/build.gradle.kts @@ -0,0 +1,19 @@ +plugins { + kotlin("jvm") +} + +description = "Infrastructure of transformations over SIR" + +dependencies { + compileOnly(kotlinStdlib()) + + api(project(":native:swift:sir")) + + testImplementation(libs.junit4) + testImplementation(projectTests(":compiler:tests-common")) +} + +sourceSets { + "main" { projectDefault() } + "test" { projectDefault() } +} \ No newline at end of file diff --git a/native/swift/sir-passes/src/org/jetbrains/sir/passes/SirPass.kt b/native/swift/sir-passes/src/org/jetbrains/sir/passes/SirPass.kt new file mode 100644 index 00000000000..5e045800190 --- /dev/null +++ b/native/swift/sir-passes/src/org/jetbrains/sir/passes/SirPass.kt @@ -0,0 +1,24 @@ +/* + * Copyright 2010-2023 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.sir.passes + +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 { + + /** + * Executes the pass over the given [SirElement]. + * + * @param element SIR element to be processed. + * @param data Additional data that is required to run the pass. + * @return The result of the pass. + */ + fun run(element: SirElement, data: T): R +} \ No newline at end of file diff --git a/native/swift/sir-passes/tests/org/jetbrains/kotlin/sir/passes/SirPassTests.kt b/native/swift/sir-passes/tests/org/jetbrains/kotlin/sir/passes/SirPassTests.kt new file mode 100644 index 00000000000..484d7d60688 --- /dev/null +++ b/native/swift/sir-passes/tests/org/jetbrains/kotlin/sir/passes/SirPassTests.kt @@ -0,0 +1,30 @@ +/* + * Copyright 2010-2023 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.sir.passes + +import org.jetbrains.kotlin.sir.SirElement +import org.jetbrains.sir.passes.SirPass +import org.junit.Test +import kotlin.test.assertEquals + +class SirPassTests { + @Test + fun smoke() { + val elementDescription = "mySirElement" + val mySirElement = object : SirElement { + override fun toString(): String { + return elementDescription + } + } + val myPass = object : SirPass { + override fun run(element: SirElement, data: Unit): String { + return element.toString() + } + } + val result = myPass.run(mySirElement, Unit) + assertEquals(elementDescription, result) + } +} \ No newline at end of file diff --git a/native/swift/sir/build.gradle.kts b/native/swift/sir/build.gradle.kts new file mode 100644 index 00000000000..ba80eb032a1 --- /dev/null +++ b/native/swift/sir/build.gradle.kts @@ -0,0 +1,17 @@ +plugins { + kotlin("jvm") +} + +description = "Swift Intermediate Representation" + +dependencies { + compileOnly(kotlinStdlib()) + + testImplementation(libs.junit4) + testImplementation(projectTests(":compiler:tests-common")) +} + +sourceSets { + "main" { projectDefault() } + "test" { projectDefault() } +} \ No newline at end of file diff --git a/native/swift/sir/src/org/jetbrains/kotlin/sir/SirElement.kt b/native/swift/sir/src/org/jetbrains/kotlin/sir/SirElement.kt new file mode 100644 index 00000000000..b98c9148d7d --- /dev/null +++ b/native/swift/sir/src/org/jetbrains/kotlin/sir/SirElement.kt @@ -0,0 +1,12 @@ +/* + * Copyright 2010-2023 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.sir + +/** + * A marker interface that denotes Swift IR elements. + */ +interface SirElement { +} \ No newline at end of file diff --git a/native/swift/sir/tests/org/jetbrains/kotlin/sir/SirTest.kt b/native/swift/sir/tests/org/jetbrains/kotlin/sir/SirTest.kt new file mode 100644 index 00000000000..2868b552b7f --- /dev/null +++ b/native/swift/sir/tests/org/jetbrains/kotlin/sir/SirTest.kt @@ -0,0 +1,23 @@ +/* + * Copyright 2010-2023 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.sir + +import org.junit.Test +import kotlin.test.assertTrue + +class SirTest { + + // TODO: Just a fake test to validate that everything is working. Feel free to delete. + @Test + fun exampleTest() { + val fakeElement = produceSwiftElement() + assertTrue(fakeElement is SirElement) + } + + private fun produceSwiftElement(): Any { + return object : SirElement {} + } +} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 9989808cd75..595fd4fbe20 100644 --- a/settings.gradle +++ b/settings.gradle @@ -397,6 +397,11 @@ include ":plugins:compose-compiler-plugin:compiler", ":plugins:compose-compiler-plugin:compiler-daemon", ":plugins:compose-compiler-plugin:compiler-daemon:integration-tests" +// Swift Export modules +include ":native:swift:sir", + ":native:swift:sir-passes", + ":native:swift:sir-analysis-api" + void intellij(String imlPath) { File imlFile = new File("${rootDir}/intellij/community/plugins/kotlin/${imlPath}") imlFile = imlFile.exists() ? imlFile : new File("${rootDir}/intellij/plugins/kotlin/${imlPath}")