[IR] Autogenerate IrFunctionWithLateBindingImpl

^KT-65773 In Progress
This commit is contained in:
Wojciech Litewka
2024-02-16 12:42:01 +01:00
committed by Space Team
parent d5b78c0cdc
commit d97681f2a9
2 changed files with 105 additions and 44 deletions
@@ -3,9 +3,15 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
// This file was generated automatically. See compiler/ir/ir.tree/tree-generator/ReadMe.md.
// DO NOT MODIFY IT MANUALLY.
@file:Suppress("DuplicatedCode", "unused")
package org.jetbrains.kotlin.ir.declarations.impl
import org.jetbrains.kotlin.descriptors.DescriptorVisibility
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.ir.IrImplementationDetail
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
@@ -23,28 +29,61 @@ class IrFunctionWithLateBindingImpl @IrImplementationDetail constructor(
override val startOffset: Int,
override val endOffset: Int,
override var origin: IrDeclarationOrigin,
override val factory: IrFactory,
override var name: Name,
override var visibility: DescriptorVisibility,
override var modality: Modality,
override var isInline: Boolean,
override var isExternal: Boolean,
override var visibility: DescriptorVisibility,
override var isInline: Boolean,
override var isExpect: Boolean,
override var modality: Modality,
override var isTailrec: Boolean,
override var isSuspend: Boolean,
override var isFakeOverride: Boolean,
override var isOperator: Boolean,
override var isInfix: Boolean,
override var isExpect: Boolean,
override var isFakeOverride: Boolean,
override val factory: IrFactory
) : IrFunctionWithLateBinding() {
override var annotations: List<IrConstructorCall> = emptyList()
private var _symbol: IrSimpleFunctionSymbol? = null
override lateinit var parent: IrDeclarationParent
override var typeParameters: List<IrTypeParameter> = emptyList()
override val containerSource: DeserializedContainerSource?
get() = null
override var metadata: MetadataSource? = null
@ObsoleteDescriptorBasedAPI
override val descriptor: FunctionDescriptor
get() = symbol.descriptor
override lateinit var returnType: IrType
override var dispatchReceiverParameter: IrValueParameter? = null
override var extensionReceiverParameter: IrValueParameter? = null
override var valueParameters: List<IrValueParameter> = emptyList()
override var contextReceiverParametersCount: Int = 0
override var body: IrBody? = null
override var attributeOwnerId: IrAttributeContainer = this
override var originalBeforeInline: IrAttributeContainer? = null
override val symbol: IrSimpleFunctionSymbol
get() = _symbol ?: error("$this has not acquired a symbol yet")
@ObsoleteDescriptorBasedAPI
override val descriptor
get() = _symbol?.descriptor ?: this.toIrBasedDescriptor()
override var overriddenSymbols: List<IrSimpleFunctionSymbol> = emptyList()
override var correspondingPropertySymbol: IrPropertySymbol? = null
override val isBound: Boolean
get() = _symbol != null
private var _symbol: IrSimpleFunctionSymbol? = null
override fun acquireSymbol(symbol: IrSimpleFunctionSymbol): IrFunctionWithLateBinding {
assert(_symbol == null) { "$this already has symbol _symbol" }
@@ -52,36 +91,4 @@ class IrFunctionWithLateBindingImpl @IrImplementationDetail constructor(
symbol.bind(this)
return this
}
override val isBound: Boolean
get() = _symbol != null
override val containerSource: DeserializedContainerSource?
get() = null
override lateinit var parent: IrDeclarationParent
override var annotations: List<IrConstructorCall> = emptyList()
override var typeParameters: List<IrTypeParameter> = emptyList()
override var dispatchReceiverParameter: IrValueParameter? = null
override var extensionReceiverParameter: IrValueParameter? = null
override var valueParameters: List<IrValueParameter> = emptyList()
override var contextReceiverParametersCount: Int = 0
override lateinit var returnType: IrType
override var body: IrBody? = null
override var metadata: MetadataSource? = null
override var overriddenSymbols: List<IrSimpleFunctionSymbol> = emptyList()
override var attributeOwnerId: IrAttributeContainer = this
override var originalBeforeInline: IrAttributeContainer? = null
override var correspondingPropertySymbol: IrPropertySymbol? = null
}
}
@@ -5,10 +5,20 @@
package org.jetbrains.kotlin.ir.generator
import org.jetbrains.kotlin.generators.tree.ArbitraryImportable
import org.jetbrains.kotlin.generators.tree.ClassRef
import org.jetbrains.kotlin.generators.tree.ImportCollector
import org.jetbrains.kotlin.generators.tree.StandardTypes
import org.jetbrains.kotlin.generators.tree.Visibility
import org.jetbrains.kotlin.generators.tree.printer.FunctionParameter
import org.jetbrains.kotlin.generators.tree.printer.VariableKind
import org.jetbrains.kotlin.generators.tree.printer.printFunctionWithBlockBody
import org.jetbrains.kotlin.generators.tree.printer.printPropertyDeclaration
import org.jetbrains.kotlin.ir.generator.config.AbstractIrTreeImplementationConfigurator
import org.jetbrains.kotlin.ir.generator.model.Element
import org.jetbrains.kotlin.ir.generator.model.Implementation
import org.jetbrains.kotlin.ir.generator.model.ListField
import org.jetbrains.kotlin.utils.SmartPrinter
object ImplementationConfigurator : AbstractIrTreeImplementationConfigurator() {
override fun configure(model: Model): Unit = with(IrTree) {
@@ -23,7 +33,12 @@ object ImplementationConfigurator : AbstractIrTreeImplementationConfigurator() {
isLateinit("returnType")
}
impl(functionWithLateBinding) {
implementation.doPrint = false
defaultEmptyList("valueParameters")
defaultNull("dispatchReceiverParameter", "extensionReceiverParameter", "body", "correspondingPropertySymbol")
default("contextReceiverParametersCount", "0")
isLateinit("returnType")
defaultNull("containerSource", withGetter = true)
configureDeclarationWithLateBindinig(simpleFunctionSymbolType)
}
impl(constructor) {
@@ -90,6 +105,45 @@ object ImplementationConfigurator : AbstractIrTreeImplementationConfigurator() {
}
}
private fun ImplementationContext.configureDeclarationWithLateBindinig(symbolType: ClassRef<*>) {
default("isBound") {
value = "_symbol != null"
withGetter = true
}
default("symbol") {
value = "_symbol ?: error(\"\$this has not acquired a symbol yet\")"
withGetter = true
}
additionalImports(ArbitraryImportable("org.jetbrains.kotlin.ir.descriptors", "toIrBasedDescriptor"))
default("descriptor") {
value = "_symbol?.descriptor ?: this.toIrBasedDescriptor()"
withGetter = true
}
implementation.generationCallback = {
println()
printPropertyDeclaration(
"_symbol",
symbolType.copy(nullable = true),
VariableKind.VAR,
visibility = Visibility.PRIVATE,
initializer = "null"
)
println()
println()
printFunctionWithBlockBody(
"acquireSymbol",
listOf(FunctionParameter("symbol", symbolType)),
implementation.element,
override = true,
) {
println("assert(_symbol == null) { \"\$this already has symbol _symbol\" }")
println("_symbol = symbol")
println("symbol.bind(this)")
println("return this")
}
}
}
override fun configureAllImplementations(model: Model) {
configureFieldInAllImplementations("parent") {
isLateinit("parent")