org.jetbrains.kotlin.fir.lazy.AbstractFir2IrLazyFunction.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-compiler-embeddable Show documentation
Show all versions of kotlin-compiler-embeddable Show documentation
the Kotlin compiler embeddable
/*
* Copyright 2010-2022 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.fir.lazy
import org.jetbrains.kotlin.descriptors.DescriptorVisibility
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.fir.backend.Fir2IrComponents
import org.jetbrains.kotlin.fir.backend.declareThisReceiverParameter
import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration
import org.jetbrains.kotlin.fir.declarations.FirReceiverParameter
import org.jetbrains.kotlin.fir.declarations.utils.*
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.declarations.lazy.AbstractIrLazyFunction
import org.jetbrains.kotlin.ir.declarations.lazy.IrLazyFunctionBase
import org.jetbrains.kotlin.ir.declarations.lazy.lazyVar
import org.jetbrains.kotlin.ir.expressions.IrBody
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.util.isFacadeClass
import org.jetbrains.kotlin.ir.util.isObject
import kotlin.properties.ReadWriteProperty
abstract class AbstractFir2IrLazyFunction(
protected val c: Fir2IrComponents,
override val startOffset: Int,
override val endOffset: Int,
override var origin: IrDeclarationOrigin,
override val symbol: IrSimpleFunctionSymbol,
override var parent: IrDeclarationParent,
override var isFakeOverride: Boolean
) : AbstractIrLazyFunction(), AbstractFir2IrLazyDeclaration, Fir2IrTypeParametersContainer, IrLazyFunctionBase,
Fir2IrComponents by c {
override lateinit var typeParameters: List
override var isTailrec: Boolean
get() = fir.isTailRec
set(_) = mutationNotSupported()
override var isSuspend: Boolean
get() = fir.isSuspend
set(_) = mutationNotSupported()
override var isOperator: Boolean
get() = fir.isOperator
set(_) = mutationNotSupported()
override var isInfix: Boolean
get() = fir.isInfix
set(_) = mutationNotSupported()
@ObsoleteDescriptorBasedAPI
override val descriptor: FunctionDescriptor
get() = symbol.descriptor
override var isInline: Boolean
get() = fir.isInline
set(_) = mutationNotSupported()
override var isExternal: Boolean
get() = fir.isExternal
set(_) = mutationNotSupported()
override var isExpect: Boolean
get() = fir.isExpect
set(_) = mutationNotSupported()
override var body: IrBody? by lazyVar(lock) {
if (tryLoadIr()) body else null
}
override var visibility: DescriptorVisibility by lazyVar(lock) {
c.visibilityConverter.convertToDescriptorVisibility(fir.visibility)
}
override var modality: Modality
get() = fir.modality!!
set(_) = mutationNotSupported()
override var correspondingPropertySymbol: IrPropertySymbol? = null
override var attributeOwnerId: IrAttributeContainer = this
override var originalBeforeInline: IrAttributeContainer? = null
override var metadata: MetadataSource?
get() = null
set(_) = error("We should never need to store metadata of external declarations.")
protected fun shouldHaveDispatchReceiver(containingClass: IrClass): Boolean {
return !fir.isStatic && !containingClass.isFacadeClass &&
(!containingClass.isObject || containingClass.isCompanion || !extensions.isTrueStatic(fir, session))
}
protected fun createThisReceiverParameter(thisType: IrType, explicitReceiver: FirReceiverParameter? = null): IrValueParameter {
declarationStorage.enterScope(this.symbol)
return declareThisReceiverParameter(c, thisType, origin, explicitReceiver = explicitReceiver).apply {
declarationStorage.leaveScope([email protected])
}
}
override val factory: IrFactory
get() = super.factory
override fun createLazyAnnotations(): ReadWriteProperty> {
return super.createLazyAnnotations()
}
override val isDeserializationEnabled: Boolean
get() = extensions.irNeedsDeserialization
override fun lazyParent(): IrDeclarationParent {
return super.lazyParent()
}
}