[KT-63275] Prepare SirAsSwiftSourcesPrinter for non-empty bodies
This commit is contained in:
committed by
Space Team
parent
30550a6da1
commit
d54877be87
+35
-16
@@ -10,8 +10,6 @@ import org.jetbrains.kotlin.sir.visitors.SirVisitorVoid
|
||||
import org.jetbrains.kotlin.utils.SmartPrinter
|
||||
import org.jetbrains.kotlin.utils.withIndent
|
||||
|
||||
private const val DEFAULT_INDENT: String = " "
|
||||
|
||||
public class SirAsSwiftSourcesPrinter(private val printer: SmartPrinter) : SirVisitorVoid() {
|
||||
|
||||
public constructor() : this(SmartPrinter(StringBuilder()))
|
||||
@@ -31,26 +29,43 @@ public class SirAsSwiftSourcesPrinter(private val printer: SmartPrinter) : SirVi
|
||||
}
|
||||
|
||||
override fun visitFunction(function: SirFunction): Unit = with(printer) {
|
||||
println(
|
||||
listOfNotNull(
|
||||
function.visibility.takeIf { it != SirVisibility.INTERNAL }?.let { "${it.swift} " },
|
||||
"func ",
|
||||
function.name.swiftIdentifier,
|
||||
function.parameters.takeIf { it.isNotEmpty() }
|
||||
?.joinToString(prefix = "(\n", postfix = "\n)", separator = ",\n") {
|
||||
it.swift.prependIndent(DEFAULT_INDENT)
|
||||
} ?: "()",
|
||||
" -> ",
|
||||
function.returnType.swift,
|
||||
" { fatalError() }",
|
||||
).joinToString(separator = ""),
|
||||
print(
|
||||
function.visibility.takeIf { it != SirVisibility.INTERNAL }?.let { "${it.swift} " } ?: "",
|
||||
"func ",
|
||||
function.name.swiftIdentifier,
|
||||
"("
|
||||
)
|
||||
if (function.parameters.isNotEmpty()) {
|
||||
println()
|
||||
withIndent {
|
||||
function.parameters.forEachIndexed { index, sirParameter ->
|
||||
print(sirParameter.swift)
|
||||
if (index != function.parameters.lastIndex) {
|
||||
println(",")
|
||||
} else {
|
||||
println()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
print(
|
||||
")",
|
||||
" -> ",
|
||||
function.returnType.swift,
|
||||
)
|
||||
println(" {")
|
||||
withIndent {
|
||||
printFunctionBody(function).forEach {
|
||||
println(it)
|
||||
}
|
||||
}
|
||||
println("}")
|
||||
}
|
||||
|
||||
override fun visitEnum(enum: SirEnum): Unit = with(printer) {
|
||||
println("enum ${enum.name.swiftIdentifier} {")
|
||||
withIndent {
|
||||
enum.acceptChildren(SirAsSwiftSourcesPrinter(printer))
|
||||
enum.acceptChildren(this@SirAsSwiftSourcesPrinter)
|
||||
}
|
||||
println("}")
|
||||
}
|
||||
@@ -62,6 +77,10 @@ public class SirAsSwiftSourcesPrinter(private val printer: SmartPrinter) : SirVi
|
||||
}
|
||||
}
|
||||
|
||||
private fun printFunctionBody(function: SirFunction): List<String> {
|
||||
return listOf("fatalError()")
|
||||
}
|
||||
|
||||
private val SirVisibility.swift
|
||||
get(): String = when (this) {
|
||||
SirVisibility.PRIVATE -> "private"
|
||||
|
||||
@@ -6,4 +6,6 @@ public func foo(
|
||||
arg5: Swift.Int64,
|
||||
arg6: Swift.Double,
|
||||
arg7: Swift.Float
|
||||
) -> Swift.Bool { fatalError() }
|
||||
) -> Swift.Bool {
|
||||
fatalError()
|
||||
}
|
||||
@@ -1 +1,3 @@
|
||||
public func foo() -> Swift.Bool { fatalError() }
|
||||
public func foo() -> Swift.Bool {
|
||||
fatalError()
|
||||
}
|
||||
@@ -1,3 +1,7 @@
|
||||
public func foo1() -> Swift.Bool { fatalError() }
|
||||
public func foo1() -> Swift.Bool {
|
||||
fatalError()
|
||||
}
|
||||
|
||||
public func foo2() -> Swift.Bool { fatalError() }
|
||||
public func foo2() -> Swift.Bool {
|
||||
fatalError()
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
public func foo(
|
||||
arg1: Swift.Int32
|
||||
) -> Swift.Bool { fatalError() }
|
||||
) -> Swift.Bool {
|
||||
fatalError()
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
public func foo(
|
||||
arg1: Swift.Int32,
|
||||
arg2: Swift.Double
|
||||
) -> Swift.Bool { fatalError() }
|
||||
) -> Swift.Bool {
|
||||
fatalError()
|
||||
}
|
||||
+9
-3
@@ -1,10 +1,16 @@
|
||||
enum namespace1 {
|
||||
enum main {
|
||||
public func foobar() -> Swift.Int32 { fatalError() }
|
||||
public func foobar() -> Swift.Int32 {
|
||||
fatalError()
|
||||
}
|
||||
}
|
||||
public func foo() -> Swift.Int32 {
|
||||
fatalError()
|
||||
}
|
||||
public func foo() -> Swift.Int32 { fatalError() }
|
||||
}
|
||||
|
||||
enum namespace2 {
|
||||
public func bar() -> Swift.Int32 { fatalError() }
|
||||
public func bar() -> Swift.Int32 {
|
||||
fatalError()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user