[KT-63275] Implement trivial bodies in SIR functions
This commit is contained in:
committed by
Space Team
parent
5dd1d7c9c1
commit
cb19e291a3
@@ -78,7 +78,7 @@ public class SirAsSwiftSourcesPrinter(private val printer: SmartPrinter) : SirVi
|
||||
}
|
||||
|
||||
private fun printFunctionBody(function: SirFunction): List<String> {
|
||||
return listOf("fatalError()")
|
||||
return function.body?.statements ?: listOf("fatalError()")
|
||||
}
|
||||
|
||||
private val SirVisibility.swift
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
public func foo(
|
||||
arg1: Swift.Int32
|
||||
) -> Swift.Bool {
|
||||
return foo_wrapped(arg1)
|
||||
}
|
||||
+28
@@ -191,6 +191,34 @@ class SirAsSwiftSourcesPrinterTests {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should print non-empty bodies`() {
|
||||
|
||||
val module = buildModule {
|
||||
name = "Test"
|
||||
declarations.add(
|
||||
buildFunction {
|
||||
origin = SirOrigin.Unknown
|
||||
visibility = SirVisibility.PUBLIC
|
||||
name = "foo"
|
||||
parameters.add(
|
||||
SirParameter(
|
||||
argumentName = "arg1",
|
||||
type = SirNominalType(SirSwiftModule.int32)
|
||||
)
|
||||
)
|
||||
returnType = SirNominalType(SirSwiftModule.bool)
|
||||
body = SirFunctionBody(listOf("return foo_wrapped(arg1)"))
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
runTest(
|
||||
module,
|
||||
"testData/non_empty_body"
|
||||
)
|
||||
}
|
||||
|
||||
private fun runTest(module: SirModule, goldenDataFile: String) {
|
||||
val expectedSwiftSrc = File(KtTestUtil.getHomeDirectory()).resolve("$goldenDataFile.golden.swift")
|
||||
|
||||
|
||||
@@ -5,5 +5,10 @@
|
||||
|
||||
package org.jetbrains.kotlin.sir
|
||||
|
||||
class SirFunctionBody {
|
||||
}
|
||||
/**
|
||||
* A body of a SIR function.
|
||||
*
|
||||
* For now, it is just a list of statements. This is sufficient as bodies are pretty trivial.
|
||||
* In the future, it may become more complicated as bridging logic becomes more sophisticated.
|
||||
*/
|
||||
class SirFunctionBody(val statements: List<String>)
|
||||
Reference in New Issue
Block a user