[KT-63275] Add a nullable body property to SIR functions
This commit is contained in:
committed by
Space Team
parent
d54877be87
commit
5dd1d7c9c1
+3
-1
@@ -5,8 +5,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.sir.passes.mocks
|
||||
|
||||
import org.jetbrains.kotlin.sir.SirFunctionBody
|
||||
import org.jetbrains.kotlin.sir.*
|
||||
import org.jetbrains.kotlin.sir.util.SirSwiftModule
|
||||
import org.jetbrains.kotlin.sir.visitors.SirTransformer
|
||||
import org.jetbrains.kotlin.sir.visitors.SirVisitor
|
||||
|
||||
@@ -20,4 +20,6 @@ class MockSirFunction(
|
||||
) : SirFunction() {
|
||||
override fun <R, D> acceptChildren(visitor: SirVisitor<R, D>, data: D) = Unit
|
||||
override fun <D> transformChildren(transformer: SirTransformer<D>, data: D) = Unit
|
||||
|
||||
override var body: SirFunctionBody? = null
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ abstract class SirFunction : SirElementBase(), SirCallable {
|
||||
abstract val name: String
|
||||
abstract val parameters: List<SirParameter>
|
||||
abstract val returnType: SirType
|
||||
abstract var body: SirFunctionBody?
|
||||
|
||||
override fun <R, D> accept(visitor: SirVisitor<R, D>, data: D): R =
|
||||
visitor.visitFunction(this, data)
|
||||
|
||||
@@ -21,6 +21,7 @@ class SirFunctionBuilder {
|
||||
lateinit var name: String
|
||||
val parameters: MutableList<SirParameter> = mutableListOf()
|
||||
lateinit var returnType: SirType
|
||||
var body: SirFunctionBody? = null
|
||||
|
||||
fun build(): SirFunction {
|
||||
return SirFunctionImpl(
|
||||
@@ -29,8 +30,10 @@ class SirFunctionBuilder {
|
||||
name,
|
||||
parameters,
|
||||
returnType,
|
||||
body,
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
@@ -52,5 +55,6 @@ inline fun buildFunctionCopy(original: SirFunction, init: SirFunctionBuilder.()
|
||||
copyBuilder.name = original.name
|
||||
copyBuilder.parameters.addAll(original.parameters)
|
||||
copyBuilder.returnType = original.returnType
|
||||
copyBuilder.body = original.body
|
||||
return copyBuilder.apply(init).build()
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ internal class SirFunctionImpl(
|
||||
override val name: String,
|
||||
override val parameters: MutableList<SirParameter>,
|
||||
override val returnType: SirType,
|
||||
override var body: SirFunctionBody?,
|
||||
) : SirFunction() {
|
||||
override lateinit var parent: SirDeclarationParent
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
/*
|
||||
* Copyright 2010-2024 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
|
||||
|
||||
class SirFunctionBody {
|
||||
}
|
||||
+1
@@ -84,6 +84,7 @@ object SwiftIrTree : AbstractSwiftIrTreeBuilder() {
|
||||
+field("name", string)
|
||||
+listField("parameters", parameterType)
|
||||
+field("returnType", typeType)
|
||||
+field("body", functionBodyType, nullable = true, mutable = true)
|
||||
}
|
||||
|
||||
val foreignFunction by element {
|
||||
|
||||
@@ -14,6 +14,7 @@ val originType = type(BASE_PACKAGE, "SirOrigin", TypeKind.Class)
|
||||
val parameterType = type(BASE_PACKAGE, "SirParameter", TypeKind.Class)
|
||||
val typeType = type(BASE_PACKAGE, "SirType", TypeKind.Class)
|
||||
val enumCaseType = type(BASE_PACKAGE, "SirEnumCase", TypeKind.Class)
|
||||
val functionBodyType = type(BASE_PACKAGE, "SirFunctionBody", TypeKind.Class)
|
||||
|
||||
private const val VISITORS_PACKAGE = "$BASE_PACKAGE.visitors"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user