IR: IrSimpleFunction.correspondingProperty: IrProperty?

Non-null for a property accessor, points to a corresponding property.
This commit is contained in:
Dmitry Petrov
2018-05-24 16:47:25 +03:00
parent 216dbf9637
commit ab455d6572
146 changed files with 604 additions and 20 deletions
@@ -38,6 +38,6 @@ interface IrProperty : IrDeclaration {
val typeParameters: MutableList<IrTypeParameter>
var backingField: IrField?
var getter: IrFunction?
var setter: IrFunction?
var getter: IrSimpleFunction?
var setter: IrSimpleFunction?
}
@@ -18,12 +18,16 @@ package org.jetbrains.kotlin.ir.declarations
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
import org.jetbrains.kotlin.name.Name
interface IrSimpleFunction : IrFunction, IrSymbolDeclaration<IrSimpleFunctionSymbol> {
val modality: Modality
val isTailrec: Boolean
val isSuspend: Boolean
var correspondingProperty: IrProperty?
val overriddenSymbols: MutableList<IrSimpleFunctionSymbol>
}
}
val IrFunction.isPropertyAccessor: Boolean
get() = this is IrSimpleFunction && correspondingProperty != null
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.descriptors.Visibility
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrProperty
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
import org.jetbrains.kotlin.ir.expressions.IrBody
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
@@ -50,6 +51,8 @@ class IrFunctionImpl(
override val overriddenSymbols: MutableList<IrSimpleFunctionSymbol> = SmartList()
override var correspondingProperty: IrProperty? = null
constructor(
startOffset: Int,
endOffset: Int,
@@ -86,8 +86,8 @@ class IrPropertyImpl(
isDelegated: Boolean,
descriptor: PropertyDescriptor,
backingField: IrField?,
getter: IrFunction?,
setter: IrFunction?
getter: IrSimpleFunction?,
setter: IrSimpleFunction?
) : this(startOffset, endOffset, origin, isDelegated, descriptor, backingField) {
this.getter = getter
this.setter = setter
@@ -95,8 +95,8 @@ class IrPropertyImpl(
override val typeParameters: MutableList<IrTypeParameter> = SmartList()
override var backingField: IrField? = null
override var getter: IrFunction? = null
override var setter: IrFunction? = null
override var getter: IrSimpleFunction? = null
override var setter: IrSimpleFunction? = null
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R {
return visitor.visitProperty(this, data)
@@ -112,7 +112,7 @@ class IrPropertyImpl(
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
typeParameters.transform { it.transform(transformer, data) }
backingField = backingField?.transform(transformer, data) as? IrField
getter = getter?.transform(transformer, data) as? IrFunction
setter = setter?.transform(transformer, data) as? IrFunction
getter = getter?.run { transform(transformer, data) as IrSimpleFunction }
setter = setter?.run { transform(transformer, data) as IrSimpleFunction }
}
}
@@ -103,6 +103,7 @@ class DumpIrTreeVisitor(out: Appendable) : IrElementVisitor<Unit, String> {
override fun visitSimpleFunction(declaration: IrSimpleFunction, data: String) {
declaration.dumpLabeledElementWith(data) {
dumpAnnotations(declaration)
declaration.correspondingProperty?.render("correspondingProperty")
declaration.overriddenSymbols.renderDeclarationElementsOrDescriptors("overridden")
declaration.typeParameters.dumpElements()
declaration.dispatchReceiverParameter?.accept(this, "\$this")
@@ -164,7 +164,7 @@ fun IrClass.addFakeOverrides() {
val startOffset = this.startOffset
val endOffset = this.endOffset
fun FunctionDescriptor.createFunction(): IrFunction = IrFunctionImpl(
fun FunctionDescriptor.createFunction(): IrSimpleFunction = IrFunctionImpl(
startOffset, endOffset,
IrDeclarationOrigin.FAKE_OVERRIDE, this
).apply {
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent
import org.jetbrains.kotlin.ir.declarations.IrPackageFragment
import org.jetbrains.kotlin.ir.declarations.IrProperty
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
import org.jetbrains.kotlin.ir.visitors.acceptVoid
@@ -52,6 +53,13 @@ class PatchDeclarationParentsVisitor() : IrElementVisitorVoid {
}
}
override fun visitProperty(declaration: IrProperty) {
declaration.getter?.let { it.correspondingProperty = declaration }
declaration.setter?.let { it.correspondingProperty = declaration }
super.visitProperty(declaration)
}
private fun patchParent(declaration: IrDeclaration) {
declaration.parent = declarationParentsStack.peekFirst()
}