[IR] Make IrPropertyWithLateBinding a subclass of IrProperty
This commit is contained in:
committed by
Space Team
parent
4b523825be
commit
e6c4a8957d
+3
-12
@@ -8,7 +8,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.ir.declarations
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
|
||||
|
||||
/**
|
||||
@@ -16,16 +15,8 @@ import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
|
||||
*
|
||||
* Generated from: [org.jetbrains.kotlin.ir.generator.IrTree.propertyWithLateBinding]
|
||||
*/
|
||||
interface IrPropertyWithLateBinding : IrDeclaration {
|
||||
override val symbol: IrPropertySymbol
|
||||
abstract class IrPropertyWithLateBinding : IrProperty() {
|
||||
abstract val isBound: Boolean
|
||||
|
||||
var modality: Modality
|
||||
|
||||
var getter: IrSimpleFunction?
|
||||
|
||||
var setter: IrSimpleFunction?
|
||||
|
||||
val isBound: Boolean
|
||||
|
||||
fun acquireSymbol(symbol: IrPropertySymbol): IrProperty
|
||||
abstract fun acquireSymbol(symbol: IrPropertySymbol): IrPropertyWithLateBinding
|
||||
}
|
||||
|
||||
+17
-73
@@ -10,28 +10,40 @@ import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.descriptors.toIrBasedDescriptor
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
||||
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource
|
||||
|
||||
abstract class IrPropertyCommonImpl(
|
||||
class IrPropertyImpl(
|
||||
override val startOffset: Int,
|
||||
override val endOffset: Int,
|
||||
override var origin: IrDeclarationOrigin,
|
||||
override val symbol: IrPropertySymbol,
|
||||
override var name: Name,
|
||||
override var visibility: DescriptorVisibility,
|
||||
override var modality: Modality,
|
||||
override var isVar: Boolean,
|
||||
override var isConst: Boolean,
|
||||
override var isLateinit: Boolean,
|
||||
override var isDelegated: Boolean,
|
||||
override var isExternal: Boolean,
|
||||
override var isExpect: Boolean,
|
||||
override val containerSource: DeserializedContainerSource?,
|
||||
override var isExpect: Boolean = false,
|
||||
override var isFakeOverride: Boolean = origin == IrDeclarationOrigin.FAKE_OVERRIDE,
|
||||
override var containerSource: DeserializedContainerSource? = null,
|
||||
override val factory: IrFactory = IrFactoryImpl,
|
||||
) : IrProperty() {
|
||||
|
||||
init {
|
||||
symbol.bind(this)
|
||||
}
|
||||
|
||||
@ObsoleteDescriptorBasedAPI
|
||||
override val descriptor: PropertyDescriptor
|
||||
get() = symbol.descriptor
|
||||
|
||||
override lateinit var parent: IrDeclarationParent
|
||||
|
||||
override var annotations: List<IrConstructorCall> = emptyList()
|
||||
|
||||
override var backingField: IrField? = null
|
||||
@@ -45,74 +57,6 @@ abstract class IrPropertyCommonImpl(
|
||||
override var metadata: MetadataSource? = null
|
||||
|
||||
override var attributeOwnerId: IrAttributeContainer = this
|
||||
|
||||
override var originalBeforeInline: IrAttributeContainer? = null
|
||||
}
|
||||
|
||||
class IrPropertyImpl(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
override val symbol: IrPropertySymbol,
|
||||
name: Name,
|
||||
visibility: DescriptorVisibility,
|
||||
override var modality: Modality,
|
||||
isVar: Boolean,
|
||||
isConst: Boolean,
|
||||
isLateinit: Boolean,
|
||||
isDelegated: Boolean,
|
||||
isExternal: Boolean,
|
||||
isExpect: Boolean = false,
|
||||
override var isFakeOverride: Boolean = origin == IrDeclarationOrigin.FAKE_OVERRIDE,
|
||||
containerSource: DeserializedContainerSource? = null,
|
||||
override val factory: IrFactory = IrFactoryImpl,
|
||||
) : IrPropertyCommonImpl(
|
||||
startOffset, endOffset, origin, name, visibility, isVar, isConst, isLateinit, isDelegated, isExternal, isExpect,
|
||||
containerSource
|
||||
) {
|
||||
init {
|
||||
symbol.bind(this)
|
||||
}
|
||||
|
||||
@ObsoleteDescriptorBasedAPI
|
||||
override val descriptor: PropertyDescriptor
|
||||
get() = symbol.descriptor
|
||||
}
|
||||
|
||||
class IrPropertyWithLateBindingImpl(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
name: Name,
|
||||
visibility: DescriptorVisibility,
|
||||
override var modality: Modality,
|
||||
isVar: Boolean,
|
||||
isConst: Boolean,
|
||||
isLateinit: Boolean,
|
||||
isDelegated: Boolean,
|
||||
isExternal: Boolean,
|
||||
isExpect: Boolean,
|
||||
override var isFakeOverride: Boolean = origin == IrDeclarationOrigin.FAKE_OVERRIDE,
|
||||
override val factory: IrFactory = IrFactoryImpl,
|
||||
) : IrPropertyCommonImpl(
|
||||
startOffset, endOffset, origin, name, visibility, isVar, isConst, isLateinit, isDelegated, isExternal, isExpect,
|
||||
containerSource = null,
|
||||
), IrPropertyWithLateBinding {
|
||||
private var _symbol: IrPropertySymbol? = null
|
||||
|
||||
override val symbol: IrPropertySymbol
|
||||
get() = _symbol ?: error("$this has not acquired a symbol yet")
|
||||
|
||||
@ObsoleteDescriptorBasedAPI
|
||||
override val descriptor
|
||||
get() = _symbol?.descriptor ?: this.toIrBasedDescriptor()
|
||||
|
||||
override fun acquireSymbol(symbol: IrPropertySymbol): IrProperty {
|
||||
assert(_symbol == null) { "$this already has symbol _symbol" }
|
||||
_symbol = symbol
|
||||
symbol.bind(this)
|
||||
return this
|
||||
}
|
||||
|
||||
override val isBound: Boolean
|
||||
get() = _symbol != null
|
||||
}
|
||||
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright 2010-2023 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.ir.declarations.impl
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibility
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.descriptors.toIrBasedDescriptor
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
||||
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource
|
||||
|
||||
class IrPropertyWithLateBindingImpl(
|
||||
override val startOffset: Int,
|
||||
override val endOffset: Int,
|
||||
override var origin: IrDeclarationOrigin,
|
||||
override var name: Name,
|
||||
override var visibility: DescriptorVisibility,
|
||||
override var modality: Modality,
|
||||
override var isVar: Boolean,
|
||||
override var isConst: Boolean,
|
||||
override var isLateinit: Boolean,
|
||||
override var isDelegated: Boolean,
|
||||
override var isExternal: Boolean,
|
||||
override var isExpect: Boolean,
|
||||
override var isFakeOverride: Boolean = origin == IrDeclarationOrigin.FAKE_OVERRIDE,
|
||||
override val factory: IrFactory = IrFactoryImpl,
|
||||
) : IrPropertyWithLateBinding() {
|
||||
|
||||
private var _symbol: IrPropertySymbol? = null
|
||||
|
||||
override val symbol: IrPropertySymbol
|
||||
get() = _symbol ?: error("$this has not acquired a symbol yet")
|
||||
|
||||
@ObsoleteDescriptorBasedAPI
|
||||
override val descriptor
|
||||
get() = _symbol?.descriptor ?: this.toIrBasedDescriptor()
|
||||
|
||||
override fun acquireSymbol(symbol: IrPropertySymbol): IrPropertyWithLateBinding {
|
||||
assert(_symbol == null) { "$this already has symbol _symbol" }
|
||||
_symbol = symbol
|
||||
symbol.bind(this)
|
||||
return this
|
||||
}
|
||||
|
||||
override lateinit var parent: IrDeclarationParent
|
||||
override var annotations: List<IrConstructorCall> = emptyList()
|
||||
|
||||
override var backingField: IrField? = null
|
||||
|
||||
override var getter: IrSimpleFunction? = null
|
||||
|
||||
override var setter: IrSimpleFunction? = null
|
||||
|
||||
override var overriddenSymbols: List<IrPropertySymbol> = emptyList()
|
||||
|
||||
override var metadata: MetadataSource? = null
|
||||
|
||||
override var attributeOwnerId: IrAttributeContainer = this
|
||||
override var originalBeforeInline: IrAttributeContainer? = null
|
||||
|
||||
override val isBound: Boolean
|
||||
get() = _symbol != null
|
||||
|
||||
override val containerSource: DeserializedContainerSource?
|
||||
get() = null
|
||||
}
|
||||
@@ -368,21 +368,17 @@ object IrTree : AbstractTreeBuilder() {
|
||||
}
|
||||
}
|
||||
val propertyWithLateBinding: ElementConfig by element(Declaration) {
|
||||
typeKind = TypeKind.Interface
|
||||
typeKind = TypeKind.Class
|
||||
|
||||
parent(declaration)
|
||||
parent(property)
|
||||
|
||||
+symbol(propertySymbolType)
|
||||
+field("modality", type<Modality>())
|
||||
+field("getter", simpleFunction, nullable = true)
|
||||
+field("setter", simpleFunction, nullable = true)
|
||||
+field("isBound", boolean, mutable = false)
|
||||
generationCallback = {
|
||||
addFunction(
|
||||
FunSpec.builder("acquireSymbol")
|
||||
.addModifiers(KModifier.ABSTRACT)
|
||||
.addParameter("symbol", propertySymbolType.toPoet())
|
||||
.returns(property.toPoet())
|
||||
.returns(this@element.toPoet())
|
||||
.build()
|
||||
)
|
||||
}
|
||||
@@ -439,6 +435,7 @@ object IrTree : AbstractTreeBuilder() {
|
||||
}
|
||||
val property: ElementConfig by element(Declaration) {
|
||||
visitorParent = declarationBase
|
||||
isForcedLeaf = true
|
||||
|
||||
parent(declarationBase)
|
||||
parent(possiblyExternalDeclaration)
|
||||
|
||||
+8
@@ -37,6 +37,14 @@ class ElementConfig(
|
||||
|
||||
var ownsChildren = true // If false, acceptChildren/transformChildren will NOT be generated.
|
||||
|
||||
/**
|
||||
* Set this to `true` if the element should be a leaf semantically, but technically it's not.
|
||||
*
|
||||
* For example, we only generate [IrFactory] methods for leaf elements. If we want to generate a method for this element, but it has
|
||||
* subclasses, it can be done by setting this property to `true`.
|
||||
*/
|
||||
var isForcedLeaf = false
|
||||
|
||||
var typeKind: TypeKind? = null
|
||||
|
||||
var generationCallback: (TypeSpec.Builder.() -> Unit)? = null
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ class Element(
|
||||
get() = elementName2typeName(name)
|
||||
val allParents: List<ClassOrElementRef>
|
||||
get() = elementParents + otherParents
|
||||
var isLeaf = false
|
||||
var isLeaf = config.isForcedLeaf
|
||||
val childrenOrderOverride: List<String>? = config.childrenOrderOverride
|
||||
var walkableChildren: List<Field> = emptyList()
|
||||
val transformableChildren get() = walkableChildren.filter { it.transformable }
|
||||
|
||||
+3
-1
@@ -141,7 +141,9 @@ private fun markLeaves(elements: List<Element>) {
|
||||
|
||||
for (el in elements) {
|
||||
for (parent in el.elementParents) {
|
||||
leaves.remove(parent.element)
|
||||
if (!parent.element.isLeaf) {
|
||||
leaves.remove(parent.element)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-1
@@ -218,7 +218,6 @@ class FakeOverrideBuilder(
|
||||
property: IrPropertyWithLateBinding,
|
||||
manglerCompatibleMode: Boolean
|
||||
): Pair<IdSignature, IrPropertySymbol> {
|
||||
require(property is IrProperty) { "Unexpected fake override property: $property" }
|
||||
val parent = property.parentAsClass
|
||||
|
||||
val signature = composeSignature(property, manglerCompatibleMode)
|
||||
|
||||
Reference in New Issue
Block a user