psi2ir: improve backing field usage generation
Also update corresponding tests data.
This commit is contained in:
+12
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.psi2ir.generators
|
|||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||||
|
import org.jetbrains.kotlin.descriptors.impl.SyntheticFieldDescriptor
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrExpressionWithCopy
|
import org.jetbrains.kotlin.ir.expressions.IrExpressionWithCopy
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.IrGetObjectValueImpl
|
import org.jetbrains.kotlin.ir.expressions.impl.IrGetObjectValueImpl
|
||||||
@@ -86,6 +87,17 @@ private fun generateThisOrSuperReceiver(receiver: ReceiverValue, classDescriptor
|
|||||||
return IrGetValueImpl(ktReceiver.startOffset, ktReceiver.endOffset, classDescriptor.thisAsReceiverParameter)
|
return IrGetValueImpl(ktReceiver.startOffset, ktReceiver.endOffset, classDescriptor.thisAsReceiverParameter)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun StatementGenerator.generateBackingFieldReceiver(
|
||||||
|
ktDefaultElement: KtElement,
|
||||||
|
resolvedCall: ResolvedCall<*>?,
|
||||||
|
fieldDescriptor: SyntheticFieldDescriptor
|
||||||
|
): IntermediateValue? {
|
||||||
|
|
||||||
|
val receiver = resolvedCall?.dispatchReceiver ?: fieldDescriptor.getDispatchReceiverForBackend() ?: return null
|
||||||
|
|
||||||
|
return this.generateReceiver(ktDefaultElement, receiver)
|
||||||
|
}
|
||||||
|
|
||||||
fun StatementGenerator.generateCallReceiver(
|
fun StatementGenerator.generateCallReceiver(
|
||||||
ktDefaultElement: KtElement,
|
ktDefaultElement: KtElement,
|
||||||
dispatchReceiver: ReceiverValue?,
|
dispatchReceiver: ReceiverValue?,
|
||||||
|
|||||||
+2
-3
@@ -110,9 +110,8 @@ class AssignmentGenerator(statementGenerator: StatementGenerator) : StatementGen
|
|||||||
|
|
||||||
return when (descriptor) {
|
return when (descriptor) {
|
||||||
is SyntheticFieldDescriptor -> {
|
is SyntheticFieldDescriptor -> {
|
||||||
val receiverValue = resolvedCall.dispatchReceiver?.let {
|
val receiverValue = statementGenerator.generateBackingFieldReceiver(ktLeft, resolvedCall, descriptor)
|
||||||
statementGenerator.generateReceiver(ktLeft, it)
|
|
||||||
}
|
|
||||||
BackingFieldLValue(ktLeft.startOffset, ktLeft.endOffset, descriptor.propertyDescriptor,
|
BackingFieldLValue(ktLeft.startOffset, ktLeft.endOffset, descriptor.propertyDescriptor,
|
||||||
receiverValue, origin)
|
receiverValue, origin)
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.kotlin.psi2ir.generators
|
package org.jetbrains.kotlin.psi2ir.generators
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
|
import org.jetbrains.kotlin.descriptors.impl.SyntheticFieldDescriptor
|
||||||
import org.jetbrains.kotlin.ir.IrStatement
|
import org.jetbrains.kotlin.ir.IrStatement
|
||||||
import org.jetbrains.kotlin.ir.assertCast
|
import org.jetbrains.kotlin.ir.assertCast
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
||||||
@@ -277,6 +278,10 @@ class StatementGenerator(
|
|||||||
is PropertyDescriptor -> {
|
is PropertyDescriptor -> {
|
||||||
CallGenerator(this).generateCall(expression.startOffset, expression.endOffset, pregenerateCall(resolvedCall!!))
|
CallGenerator(this).generateCall(expression.startOffset, expression.endOffset, pregenerateCall(resolvedCall!!))
|
||||||
}
|
}
|
||||||
|
is SyntheticFieldDescriptor -> {
|
||||||
|
val receiver = generateBackingFieldReceiver(expression, resolvedCall, descriptor)
|
||||||
|
IrGetFieldImpl(expression.startOffset, expression.endOffset, descriptor.propertyDescriptor, receiver?.load())
|
||||||
|
}
|
||||||
is VariableDescriptor ->
|
is VariableDescriptor ->
|
||||||
CallGenerator(this).generateGetVariable(expression.startOffset, expression.endOffset, descriptor,
|
CallGenerator(this).generateGetVariable(expression.startOffset, expression.endOffset, descriptor,
|
||||||
getTypeArguments(resolvedCall))
|
getTypeArguments(resolvedCall))
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ FILE /initVar.kt
|
|||||||
FUN public final fun <set-x>(value: kotlin.Int): kotlin.Unit
|
FUN public final fun <set-x>(value: kotlin.Int): kotlin.Unit
|
||||||
BLOCK_BODY
|
BLOCK_BODY
|
||||||
SET_FIELD 'x: Int' type=kotlin.Unit origin=EQ
|
SET_FIELD 'x: Int' type=kotlin.Unit origin=EQ
|
||||||
|
receiver: GET_VAR '<receiver: TestInitVarWithCustomSetter>' type=TestInitVarWithCustomSetter origin=null
|
||||||
value: GET_VAR 'value-parameter value: Int' type=kotlin.Int origin=null
|
value: GET_VAR 'value-parameter value: Int' type=kotlin.Int origin=null
|
||||||
CLASS CLASS TestInitVarWithCustomSetterWithExplicitCtor
|
CLASS CLASS TestInitVarWithCustomSetterWithExplicitCtor
|
||||||
PROPERTY public final var x: kotlin.Int
|
PROPERTY public final var x: kotlin.Int
|
||||||
@@ -88,6 +89,7 @@ FILE /initVar.kt
|
|||||||
FUN public final fun <set-x>(value: kotlin.Int): kotlin.Unit
|
FUN public final fun <set-x>(value: kotlin.Int): kotlin.Unit
|
||||||
BLOCK_BODY
|
BLOCK_BODY
|
||||||
SET_FIELD 'x: Int' type=kotlin.Unit origin=EQ
|
SET_FIELD 'x: Int' type=kotlin.Unit origin=EQ
|
||||||
|
receiver: GET_VAR '<receiver: TestInitVarWithCustomSetterWithExplicitCtor>' type=TestInitVarWithCustomSetterWithExplicitCtor origin=null
|
||||||
value: GET_VAR 'value-parameter value: Int' type=kotlin.Int origin=null
|
value: GET_VAR 'value-parameter value: Int' type=kotlin.Int origin=null
|
||||||
ANONYMOUS_INITIALIZER TestInitVarWithCustomSetterWithExplicitCtor
|
ANONYMOUS_INITIALIZER TestInitVarWithCustomSetterWithExplicitCtor
|
||||||
BLOCK_BODY
|
BLOCK_BODY
|
||||||
@@ -109,6 +111,7 @@ FILE /initVar.kt
|
|||||||
FUN public final fun <set-x>(value: kotlin.Int): kotlin.Unit
|
FUN public final fun <set-x>(value: kotlin.Int): kotlin.Unit
|
||||||
BLOCK_BODY
|
BLOCK_BODY
|
||||||
SET_FIELD 'x: Int' type=kotlin.Unit origin=EQ
|
SET_FIELD 'x: Int' type=kotlin.Unit origin=EQ
|
||||||
|
receiver: GET_VAR '<receiver: TestInitVarWithCustomSetterInCtor>' type=TestInitVarWithCustomSetterInCtor origin=null
|
||||||
value: GET_VAR 'value-parameter value: Int' type=kotlin.Int origin=null
|
value: GET_VAR 'value-parameter value: Int' type=kotlin.Int origin=null
|
||||||
CONSTRUCTOR public constructor TestInitVarWithCustomSetterInCtor()
|
CONSTRUCTOR public constructor TestInitVarWithCustomSetterInCtor()
|
||||||
BLOCK_BODY
|
BLOCK_BODY
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ FILE /classLevelProperties.kt
|
|||||||
FUN public final fun <set-test4>(value: kotlin.Int): kotlin.Unit
|
FUN public final fun <set-test4>(value: kotlin.Int): kotlin.Unit
|
||||||
BLOCK_BODY
|
BLOCK_BODY
|
||||||
SET_FIELD 'test4: Int' type=kotlin.Unit origin=EQ
|
SET_FIELD 'test4: Int' type=kotlin.Unit origin=EQ
|
||||||
|
receiver: GET_VAR '<receiver: C>' type=C origin=null
|
||||||
value: GET_VAR 'value-parameter value: Int' type=kotlin.Int origin=null
|
value: GET_VAR 'value-parameter value: Int' type=kotlin.Int origin=null
|
||||||
PROPERTY public final var test5: kotlin.Int
|
PROPERTY public final var test5: kotlin.Int
|
||||||
FIELD PROPERTY_BACKING_FIELD public final var test5: kotlin.Int
|
FIELD PROPERTY_BACKING_FIELD public final var test5: kotlin.Int
|
||||||
|
|||||||
Reference in New Issue
Block a user