[IR] Make IrFunctionWithLateBinding a subclass of IrSimpleFunction
This commit is contained in:
committed by
Space Team
parent
88da053408
commit
3828552a1c
+3
-8
@@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.ir.declarations
|
package org.jetbrains.kotlin.ir.declarations
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.Modality
|
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -16,12 +15,8 @@ import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
|||||||
*
|
*
|
||||||
* Generated from: [org.jetbrains.kotlin.ir.generator.IrTree.functionWithLateBinding]
|
* Generated from: [org.jetbrains.kotlin.ir.generator.IrTree.functionWithLateBinding]
|
||||||
*/
|
*/
|
||||||
interface IrFunctionWithLateBinding : IrDeclaration {
|
abstract class IrFunctionWithLateBinding : IrSimpleFunction() {
|
||||||
override val symbol: IrSimpleFunctionSymbol
|
abstract val isBound: Boolean
|
||||||
|
|
||||||
var modality: Modality
|
abstract fun acquireSymbol(symbol: IrSimpleFunctionSymbol): IrFunctionWithLateBinding
|
||||||
|
|
||||||
val isBound: Boolean
|
|
||||||
|
|
||||||
fun acquireSymbol(symbol: IrSimpleFunctionSymbol): IrSimpleFunction
|
|
||||||
}
|
}
|
||||||
|
|||||||
+62
-54
@@ -21,12 +21,14 @@ import org.jetbrains.kotlin.ir.types.impl.ReturnTypeIsNotInitializedException
|
|||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource
|
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource
|
||||||
|
|
||||||
abstract class IrFunctionCommonImpl(
|
class IrFunctionImpl(
|
||||||
override val startOffset: Int,
|
override val startOffset: Int,
|
||||||
override val endOffset: Int,
|
override val endOffset: Int,
|
||||||
override var origin: IrDeclarationOrigin,
|
override var origin: IrDeclarationOrigin,
|
||||||
|
override val symbol: IrSimpleFunctionSymbol,
|
||||||
override var name: Name,
|
override var name: Name,
|
||||||
override var visibility: DescriptorVisibility,
|
override var visibility: DescriptorVisibility,
|
||||||
|
override var modality: Modality,
|
||||||
returnType: IrType,
|
returnType: IrType,
|
||||||
override var isInline: Boolean,
|
override var isInline: Boolean,
|
||||||
override var isExternal: Boolean,
|
override var isExternal: Boolean,
|
||||||
@@ -35,8 +37,17 @@ abstract class IrFunctionCommonImpl(
|
|||||||
override var isOperator: Boolean,
|
override var isOperator: Boolean,
|
||||||
override var isInfix: Boolean,
|
override var isInfix: Boolean,
|
||||||
override var isExpect: Boolean,
|
override var isExpect: Boolean,
|
||||||
override var containerSource: DeserializedContainerSource?,
|
override var isFakeOverride: Boolean = origin == IrDeclarationOrigin.FAKE_OVERRIDE,
|
||||||
|
override var containerSource: DeserializedContainerSource? = null,
|
||||||
|
override val factory: IrFactory = IrFactoryImpl,
|
||||||
) : IrSimpleFunction() {
|
) : IrSimpleFunction() {
|
||||||
|
@ObsoleteDescriptorBasedAPI
|
||||||
|
override val descriptor: FunctionDescriptor
|
||||||
|
get() = symbol.descriptor
|
||||||
|
|
||||||
|
init {
|
||||||
|
symbol.bind(this)
|
||||||
|
}
|
||||||
|
|
||||||
override lateinit var parent: IrDeclarationParent
|
override lateinit var parent: IrDeclarationParent
|
||||||
override var annotations: List<IrConstructorCall> = emptyList()
|
override var annotations: List<IrConstructorCall> = emptyList()
|
||||||
@@ -62,68 +73,31 @@ abstract class IrFunctionCommonImpl(
|
|||||||
|
|
||||||
override var overriddenSymbols: List<IrSimpleFunctionSymbol> = emptyList()
|
override var overriddenSymbols: List<IrSimpleFunctionSymbol> = emptyList()
|
||||||
|
|
||||||
@Suppress("LeakingThis")
|
|
||||||
override var attributeOwnerId: IrAttributeContainer = this
|
override var attributeOwnerId: IrAttributeContainer = this
|
||||||
override var originalBeforeInline: IrAttributeContainer? = null
|
override var originalBeforeInline: IrAttributeContainer? = null
|
||||||
|
|
||||||
override var correspondingPropertySymbol: IrPropertySymbol? = null
|
override var correspondingPropertySymbol: IrPropertySymbol? = null
|
||||||
}
|
}
|
||||||
|
|
||||||
class IrFunctionImpl(
|
|
||||||
startOffset: Int,
|
|
||||||
endOffset: Int,
|
|
||||||
origin: IrDeclarationOrigin,
|
|
||||||
override val symbol: IrSimpleFunctionSymbol,
|
|
||||||
name: Name,
|
|
||||||
visibility: DescriptorVisibility,
|
|
||||||
override var modality: Modality,
|
|
||||||
returnType: IrType,
|
|
||||||
isInline: Boolean,
|
|
||||||
isExternal: Boolean,
|
|
||||||
isTailrec: Boolean,
|
|
||||||
isSuspend: Boolean,
|
|
||||||
isOperator: Boolean,
|
|
||||||
isInfix: Boolean,
|
|
||||||
isExpect: Boolean,
|
|
||||||
override var isFakeOverride: Boolean = origin == IrDeclarationOrigin.FAKE_OVERRIDE,
|
|
||||||
containerSource: DeserializedContainerSource? = null,
|
|
||||||
override val factory: IrFactory = IrFactoryImpl,
|
|
||||||
) : IrFunctionCommonImpl(
|
|
||||||
startOffset, endOffset, origin, name, visibility, returnType, isInline,
|
|
||||||
isExternal, isTailrec, isSuspend, isOperator, isInfix, isExpect,
|
|
||||||
containerSource,
|
|
||||||
) {
|
|
||||||
@ObsoleteDescriptorBasedAPI
|
|
||||||
override val descriptor: FunctionDescriptor
|
|
||||||
get() = symbol.descriptor
|
|
||||||
|
|
||||||
init {
|
|
||||||
symbol.bind(this)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class IrFunctionWithLateBindingImpl(
|
class IrFunctionWithLateBindingImpl(
|
||||||
startOffset: Int,
|
override val startOffset: Int,
|
||||||
endOffset: Int,
|
override val endOffset: Int,
|
||||||
origin: IrDeclarationOrigin,
|
override var origin: IrDeclarationOrigin,
|
||||||
name: Name,
|
override var name: Name,
|
||||||
visibility: DescriptorVisibility,
|
override var visibility: DescriptorVisibility,
|
||||||
override var modality: Modality,
|
override var modality: Modality,
|
||||||
returnType: IrType,
|
returnType: IrType,
|
||||||
isInline: Boolean,
|
override var isInline: Boolean,
|
||||||
isExternal: Boolean,
|
override var isExternal: Boolean,
|
||||||
isTailrec: Boolean,
|
override var isTailrec: Boolean,
|
||||||
isSuspend: Boolean,
|
override var isSuspend: Boolean,
|
||||||
isOperator: Boolean,
|
override var isOperator: Boolean,
|
||||||
isInfix: Boolean,
|
override var isInfix: Boolean,
|
||||||
isExpect: Boolean,
|
override var isExpect: Boolean,
|
||||||
override var isFakeOverride: Boolean = origin == IrDeclarationOrigin.FAKE_OVERRIDE,
|
override var isFakeOverride: Boolean = origin == IrDeclarationOrigin.FAKE_OVERRIDE,
|
||||||
override val factory: IrFactory = IrFactoryImpl
|
override val factory: IrFactory = IrFactoryImpl
|
||||||
) : IrFunctionCommonImpl(
|
) : IrFunctionWithLateBinding() {
|
||||||
startOffset, endOffset, origin, name, visibility, returnType, isInline,
|
|
||||||
isExternal, isTailrec, isSuspend, isOperator, isInfix, isExpect,
|
|
||||||
containerSource = null,
|
|
||||||
), IrFunctionWithLateBinding {
|
|
||||||
private var _symbol: IrSimpleFunctionSymbol? = null
|
private var _symbol: IrSimpleFunctionSymbol? = null
|
||||||
|
|
||||||
override val symbol: IrSimpleFunctionSymbol
|
override val symbol: IrSimpleFunctionSymbol
|
||||||
@@ -133,7 +107,7 @@ class IrFunctionWithLateBindingImpl(
|
|||||||
override val descriptor
|
override val descriptor
|
||||||
get() = _symbol?.descriptor ?: this.toIrBasedDescriptor()
|
get() = _symbol?.descriptor ?: this.toIrBasedDescriptor()
|
||||||
|
|
||||||
override fun acquireSymbol(symbol: IrSimpleFunctionSymbol): IrSimpleFunction {
|
override fun acquireSymbol(symbol: IrSimpleFunctionSymbol): IrFunctionWithLateBinding {
|
||||||
assert(_symbol == null) { "$this already has symbol _symbol" }
|
assert(_symbol == null) { "$this already has symbol _symbol" }
|
||||||
_symbol = symbol
|
_symbol = symbol
|
||||||
symbol.bind(this)
|
symbol.bind(this)
|
||||||
@@ -142,4 +116,38 @@ class IrFunctionWithLateBindingImpl(
|
|||||||
|
|
||||||
override val isBound: Boolean
|
override val isBound: Boolean
|
||||||
get() = _symbol != null
|
get() = _symbol != null
|
||||||
|
|
||||||
|
override val containerSource: DeserializedContainerSource?
|
||||||
|
get() = null
|
||||||
|
|
||||||
|
override lateinit var parent: IrDeclarationParent
|
||||||
|
|
||||||
|
override var annotations: List<IrConstructorCall> = emptyList()
|
||||||
|
|
||||||
|
override var returnType: IrType = returnType
|
||||||
|
get() = if (field === IrUninitializedType) {
|
||||||
|
throw ReturnTypeIsNotInitializedException(this)
|
||||||
|
} else {
|
||||||
|
field
|
||||||
|
}
|
||||||
|
|
||||||
|
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 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
|
||||||
}
|
}
|
||||||
|
|||||||
+22
-31
@@ -36,6 +36,24 @@ object IrTree : AbstractTreeBuilder() {
|
|||||||
private fun descriptor(typeName: String): SimpleFieldConfig =
|
private fun descriptor(typeName: String): SimpleFieldConfig =
|
||||||
field("descriptor", ClassRef<TypeParameterRef>(TypeKind.Interface, "org.jetbrains.kotlin.descriptors", typeName), mutable = false)
|
field("descriptor", ClassRef<TypeParameterRef>(TypeKind.Interface, "org.jetbrains.kotlin.descriptors", typeName), mutable = false)
|
||||||
|
|
||||||
|
private fun declarationWithLateBinding(symbol: ClassRef<*>, initializer: ElementConfig.() -> Unit) = element(Declaration) {
|
||||||
|
initializer()
|
||||||
|
|
||||||
|
+field("isBound", boolean, mutable = false)
|
||||||
|
|
||||||
|
val oldCallback = generationCallback
|
||||||
|
generationCallback = {
|
||||||
|
oldCallback?.invoke(this)
|
||||||
|
addFunction(
|
||||||
|
FunSpec.builder("acquireSymbol")
|
||||||
|
.addModifiers(KModifier.ABSTRACT)
|
||||||
|
.addParameter("symbol", symbol.toPoet())
|
||||||
|
.returns(this@element.toPoet())
|
||||||
|
.build(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private val factory: SimpleFieldConfig = field("factory", type(Packages.declarations, "IrFactory"), mutable = false)
|
private val factory: SimpleFieldConfig = field("factory", type(Packages.declarations, "IrFactory"), mutable = false)
|
||||||
|
|
||||||
override val rootElement: ElementConfig by element(Other, name = "element") {
|
override val rootElement: ElementConfig by element(Other, name = "element") {
|
||||||
@@ -349,39 +367,11 @@ object IrTree : AbstractTreeBuilder() {
|
|||||||
baseGetter = code("error(\"Should never be called\")")
|
baseGetter = code("error(\"Should never be called\")")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val functionWithLateBinding: ElementConfig by element(Declaration) {
|
val functionWithLateBinding: ElementConfig by declarationWithLateBinding(simpleFunctionSymbolType) {
|
||||||
typeKind = TypeKind.Interface
|
parent(simpleFunction)
|
||||||
|
|
||||||
parent(declaration)
|
|
||||||
|
|
||||||
+symbol(simpleFunctionSymbolType)
|
|
||||||
+field("modality", type<Modality>())
|
|
||||||
+field("isBound", boolean, mutable = false)
|
|
||||||
generationCallback = {
|
|
||||||
addFunction(
|
|
||||||
FunSpec.builder("acquireSymbol")
|
|
||||||
.addModifiers(KModifier.ABSTRACT)
|
|
||||||
.addParameter("symbol", simpleFunctionSymbolType.toPoet())
|
|
||||||
.returns(simpleFunction.toPoet())
|
|
||||||
.build()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
val propertyWithLateBinding: ElementConfig by element(Declaration) {
|
val propertyWithLateBinding: ElementConfig by declarationWithLateBinding(propertySymbolType) {
|
||||||
typeKind = TypeKind.Class
|
|
||||||
|
|
||||||
parent(property)
|
parent(property)
|
||||||
|
|
||||||
+field("isBound", boolean, mutable = false)
|
|
||||||
generationCallback = {
|
|
||||||
addFunction(
|
|
||||||
FunSpec.builder("acquireSymbol")
|
|
||||||
.addModifiers(KModifier.ABSTRACT)
|
|
||||||
.addParameter("symbol", propertySymbolType.toPoet())
|
|
||||||
.returns(this@element.toPoet())
|
|
||||||
.build()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
val field: ElementConfig by element(Declaration) {
|
val field: ElementConfig by element(Declaration) {
|
||||||
visitorParent = declarationBase
|
visitorParent = declarationBase
|
||||||
@@ -485,6 +475,7 @@ object IrTree : AbstractTreeBuilder() {
|
|||||||
}
|
}
|
||||||
val simpleFunction: ElementConfig by element(Declaration) {
|
val simpleFunction: ElementConfig by element(Declaration) {
|
||||||
visitorParent = function
|
visitorParent = function
|
||||||
|
isForcedLeaf = true
|
||||||
|
|
||||||
parent(function)
|
parent(function)
|
||||||
parent(overridableDeclaration.withArgs("S" to simpleFunctionSymbolType))
|
parent(overridableDeclaration.withArgs("S" to simpleFunctionSymbolType))
|
||||||
|
|||||||
-1
@@ -183,7 +183,6 @@ class FakeOverrideBuilder(
|
|||||||
function: IrFunctionWithLateBinding,
|
function: IrFunctionWithLateBinding,
|
||||||
manglerCompatibleMode: Boolean
|
manglerCompatibleMode: Boolean
|
||||||
): Pair<IdSignature, IrSimpleFunctionSymbol> {
|
): Pair<IdSignature, IrSimpleFunctionSymbol> {
|
||||||
require(function is IrSimpleFunction) { "Unexpected fake override function: $function" }
|
|
||||||
val parent = function.parentAsClass
|
val parent = function.parentAsClass
|
||||||
|
|
||||||
val signature = composeSignature(function, manglerCompatibleMode)
|
val signature = composeSignature(function, manglerCompatibleMode)
|
||||||
|
|||||||
Reference in New Issue
Block a user