diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/CallGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/CallGenerator.kt index 1e032dd295a..f4bcef01b73 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/CallGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/CallGenerator.kt @@ -95,25 +95,30 @@ class CallGenerator(val statementGenerator: StatementGenerator) : IrGenerator { superQualifier: ClassDescriptor? = null ): IrExpression { val descriptor = resolvedCall.resultingDescriptor - val returnType = getReturnType(resolvedCall) return when (descriptor) { is PropertyDescriptor -> - IrGetPropertyExpressionImpl( - ktElement.startOffset, ktElement.endOffset, - returnType, - resolvedCall.call.isSafeCall(), descriptor - ).apply { - dispatchReceiver = generateReceiver(ktElement, resolvedCall.dispatchReceiver, descriptor.dispatchReceiverParameter) - extensionReceiver = generateReceiver(ktElement, resolvedCall.extensionReceiver, descriptor.extensionReceiverParameter) - } + generatePropertyGetterCall(descriptor, ktElement, resolvedCall) is FunctionDescriptor -> - generateFunctionCall(descriptor, ktElement, returnType, operator, resolvedCall, superQualifier) + generateFunctionCall(descriptor, ktElement, operator, resolvedCall, superQualifier) else -> TODO("Unexpected callable descriptor: $descriptor ${descriptor.javaClass.simpleName}") } } + private fun CallGenerator.generatePropertyGetterCall( + descriptor: PropertyDescriptor, + ktElement: KtElement, + resolvedCall: ResolvedCall<*> + ): IrGetterCallExpressionImpl { + val returnType = getReturnType(resolvedCall) + val dispatchReceiver = generateReceiver(ktElement, resolvedCall.dispatchReceiver, descriptor.dispatchReceiverParameter) + val extensionReceiver = generateReceiver(ktElement, resolvedCall.extensionReceiver, descriptor.extensionReceiverParameter) + return IrGetterCallExpressionImpl(ktElement.startOffset, ktElement.endOffset, + returnType, descriptor.getter!!, resolvedCall.call.isSafeCall(), + dispatchReceiver, extensionReceiver, IrOperator.GET_PROPERTY) + } + private fun ResolvedCall<*>.requiresArgumentReordering(): Boolean { var lastValueParameterIndex = -1 for (valueArgument in call.valueArguments) { @@ -131,20 +136,21 @@ class CallGenerator(val statementGenerator: StatementGenerator) : IrGenerator { private fun generateFunctionCall( descriptor: FunctionDescriptor, ktElement: KtElement, - resultType: KotlinType?, operator: IrOperator?, resolvedCall: ResolvedCall, superQualifier: ClassDescriptor? ): IrExpression { + val returnType = descriptor.returnType + val irCall = IrCallExpressionImpl( - ktElement.startOffset, ktElement.endOffset, resultType, + ktElement.startOffset, ktElement.endOffset, returnType, descriptor, resolvedCall.call.isSafeCall(), operator, superQualifier ) irCall.dispatchReceiver = generateReceiver(ktElement, resolvedCall.dispatchReceiver, descriptor.dispatchReceiverParameter) irCall.extensionReceiver = generateReceiver(ktElement, resolvedCall.extensionReceiver, descriptor.extensionReceiverParameter) return if (resolvedCall.requiresArgumentReordering()) { - generateCallWithArgumentReordering(irCall, ktElement, resolvedCall, resultType) + generateCallWithArgumentReordering(irCall, ktElement, resolvedCall, returnType) } else { irCall.apply { diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/OperatorConventions.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/OperatorConventions.kt index c18982883db..82f8ac7c8fd 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/OperatorConventions.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/OperatorConventions.kt @@ -17,13 +17,12 @@ package org.jetbrains.kotlin.psi2ir.generators import com.intellij.psi.tree.IElementType -import org.jetbrains.kotlin.ir.expressions.IrBinaryOperator import org.jetbrains.kotlin.ir.expressions.IrOperator import org.jetbrains.kotlin.ir.expressions.IrTypeOperator import org.jetbrains.kotlin.lexer.KtTokens -fun getIrBinaryOperator(ktOperator: IElementType): IrBinaryOperator? = +fun getIrBinaryOperator(ktOperator: IElementType): IrOperator? = when (ktOperator) { KtTokens.EQ -> IrOperator.EQ KtTokens.PLUSEQ -> IrOperator.PLUSEQ diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/OperatorExpressionGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/OperatorExpressionGenerator.kt index 245c9a12b0c..f225111076a 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/OperatorExpressionGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/OperatorExpressionGenerator.kt @@ -114,7 +114,7 @@ class OperatorExpressionGenerator(val statementGenerator: StatementGenerator): I ) } - private fun generateBinaryBooleanOperator(expression: KtBinaryExpression, irOperator: IrBinaryOperator): IrExpression { + private fun generateBinaryBooleanOperator(expression: KtBinaryExpression, irOperator: IrOperator): IrExpression { val irArgument0 = statementGenerator.generateExpression(expression.left!!).toExpectedType(context.builtIns.booleanType) val irArgument1 = statementGenerator.generateExpression(expression.right!!).toExpectedType(context.builtIns.booleanType) return IrBinaryOperatorExpressionImpl( @@ -135,7 +135,7 @@ class OperatorExpressionGenerator(val statementGenerator: StatementGenerator): I IrOperator.EXCL, null, irOperatorCall) } - private fun generateIdentityOperator(expression: KtBinaryExpression, irOperator: IrBinaryOperator): IrExpression { + private fun generateIdentityOperator(expression: KtBinaryExpression, irOperator: IrOperator): IrExpression { val irArgument0 = statementGenerator.generateExpression(expression.left!!) val irArgument1 = statementGenerator.generateExpression(expression.right!!) return IrBinaryOperatorExpressionImpl( @@ -144,7 +144,7 @@ class OperatorExpressionGenerator(val statementGenerator: StatementGenerator): I ) } - private fun generateEqualityOperator(expression: KtBinaryExpression, irOperator: IrBinaryOperator): IrExpression { + private fun generateEqualityOperator(expression: KtBinaryExpression, irOperator: IrOperator): IrExpression { val relatedCall = getResolvedCall(expression)!! val relatedDescriptor = relatedCall.resultingDescriptor @@ -169,7 +169,7 @@ class OperatorExpressionGenerator(val statementGenerator: StatementGenerator): I ) } - private fun generateComparisonOperator(expression: KtBinaryExpression, irOperator: IrBinaryOperator): IrExpression { + private fun generateComparisonOperator(expression: KtBinaryExpression, irOperator: IrOperator): IrExpression { val compareToCall = getResolvedCall(expression)!! val compareToDescriptor = compareToCall.resultingDescriptor diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/values/PropertyLValue.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/values/PropertyLValue.kt index 509c82159a9..837cdd5da06 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/values/PropertyLValue.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/values/PropertyLValue.kt @@ -35,21 +35,21 @@ class PropertyLValue( override val type: KotlinType? get() = descriptor.type - private fun IrPropertyAccessExpression.setReceivers() = - apply { - dispatchReceiver = this@PropertyLValue.dispatchReceiver - extensionReceiver = this@PropertyLValue.extensionReceiver - } + override fun load(): IrExpression { + val getter = descriptor.getter!! + return IrGetterCallExpressionImpl( + ktElement.startOffset, ktElement.endOffset, + getter.returnType, getter, isSafe, + dispatchReceiver, extensionReceiver, IrOperator.GET_PROPERTY + ) + } - override fun load(): IrExpression = - IrGetPropertyExpressionImpl( - ktElement.startOffset, ktElement.endOffset, - descriptor.type, isSafe, descriptor, irOperator - ).setReceivers() - - override fun store(irExpression: IrExpression): IrExpression = - IrSetPropertyExpressionImpl( - ktElement.startOffset, ktElement.endOffset, - isSafe, descriptor, irExpression.toExpectedType(descriptor.type), irOperator - ).setReceivers() + override fun store(irExpression: IrExpression): IrExpression { + val setter = descriptor.setter!! + val irArgument = irExpression.toExpectedType(descriptor.type) + val irCall = IrSetterCallExpressionImpl(ktElement.startOffset, ktElement.endOffset, + setter.returnType, setter, isSafe, + dispatchReceiver, extensionReceiver, irArgument, irOperator) + return irCall + } } \ No newline at end of file diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/IrSlots.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/IrSlots.kt index b8a31dbe78a..a40bc2a0536 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/IrSlots.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/IrSlots.kt @@ -29,4 +29,5 @@ const val WHEN_SUBJECT_VARIABLE_SLOT = -1 const val WHEN_ELSE_EXPRESSION_SLOT = -2 const val BRANCH_RESULT_SLOT = -1 const val LOOP_BODY_SLOT = -1 -const val LOOP_CONDITION_SLOT = -2 \ No newline at end of file +const val LOOP_CONDITION_SLOT = -2 +const val SETTER_ARGUMENT_INDEX = 0 \ No newline at end of file diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrCallExpression.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrCallExpression.kt index 8682d35b958..898b59386dd 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrCallExpression.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrCallExpression.kt @@ -38,7 +38,7 @@ class IrCallExpressionImpl( type: KotlinType?, override val descriptor: CallableDescriptor, isSafe: Boolean, - override val operator: IrOperator?, + override val operator: IrOperator? = null, override val superQualifier: ClassDescriptor? = null ) : IrMemberAccessExpressionBase(startOffset, endOffset, type, isSafe), IrCallExpression { private val argumentsByParameterIndex = @@ -83,3 +83,98 @@ class IrCallExpressionImpl( argumentsByParameterIndex.forEach { it?.accept(visitor, data) } } } + +abstract class IrPropertyAccessorCallExpressionBase( + startOffset: Int, + endOffset: Int, + type: KotlinType?, + override val descriptor: CallableDescriptor, + isSafe: Boolean, + override val operator: IrOperator? = null, + override val superQualifier: ClassDescriptor? = null +) : IrMemberAccessExpressionBase(startOffset, endOffset, type, isSafe), IrCallExpression { + override fun accept(visitor: IrElementVisitor, data: D): R { + return visitor.visitCallExpression(this, data) + } +} + +class IrGetterCallExpressionImpl( + startOffset: Int, + endOffset: Int, + type: KotlinType?, + descriptor: CallableDescriptor, + isSafe: Boolean, + operator: IrOperator? = null, + superQualifier: ClassDescriptor? = null +) : IrPropertyAccessorCallExpressionBase(startOffset, endOffset, type, descriptor, isSafe, operator, superQualifier), IrCallExpression { + constructor( + startOffset: Int, + endOffset: Int, + type: KotlinType?, + descriptor: CallableDescriptor, + isSafe: Boolean, + dispatchReceiver: IrExpression?, + extensionReceiver: IrExpression?, + operator: IrOperator? = null, + superQualifier: ClassDescriptor? = null + ) : this(startOffset, endOffset, type, descriptor, isSafe, operator, superQualifier) { + this.dispatchReceiver = dispatchReceiver + this.extensionReceiver = extensionReceiver + } + + override fun getArgument(index: Int): IrExpression? = null + + override fun putArgument(index: Int, valueArgument: IrExpression?) { + throw UnsupportedOperationException("Property setter call has no arguments") + } + + override fun removeArgument(index: Int) { + throw UnsupportedOperationException("Property getter call has no arguments") + } +} + +class IrSetterCallExpressionImpl( + startOffset: Int, + endOffset: Int, + type: KotlinType?, + descriptor: CallableDescriptor, + isSafe: Boolean, + operator: IrOperator? = null, + superQualifier: ClassDescriptor? = null +) : IrPropertyAccessorCallExpressionBase(startOffset, endOffset, type, descriptor, isSafe, operator, superQualifier), IrCallExpression { + constructor( + startOffset: Int, + endOffset: Int, + type: KotlinType?, + descriptor: CallableDescriptor, + isSafe: Boolean, + dispatchReceiver: IrExpression?, + extensionReceiver: IrExpression?, + argument: IrExpression, + operator: IrOperator? = null, + superQualifier: ClassDescriptor? = null + ) : this(startOffset, endOffset, type, descriptor, isSafe, operator, superQualifier) { + this.dispatchReceiver = dispatchReceiver + this.extensionReceiver = extensionReceiver + putArgument(SETTER_ARGUMENT_INDEX, argument) + } + + private var argumentImpl: IrExpression? = null + + override fun getArgument(index: Int): IrExpression? = + if (index == SETTER_ARGUMENT_INDEX) argumentImpl!! else null + + override fun putArgument(index: Int, valueArgument: IrExpression?) { + if (index != SETTER_ARGUMENT_INDEX) return + argumentImpl?.detach() + valueArgument?.assertDetached() + argumentImpl = valueArgument + valueArgument?.setTreeLocation(this, SETTER_ARGUMENT_INDEX) + } + + override fun removeArgument(index: Int) { + if (index != SETTER_ARGUMENT_INDEX) return + argumentImpl?.detach() + argumentImpl = null + } +} \ No newline at end of file diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrGetExtensionReceiverExpression.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrGetExtensionReceiverExpression.kt index 20c258b0264..37f0f2c76a3 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrGetExtensionReceiverExpression.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrGetExtensionReceiverExpression.kt @@ -16,20 +16,20 @@ package org.jetbrains.kotlin.ir.expressions -import org.jetbrains.kotlin.descriptors.CallableDescriptor +import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor import org.jetbrains.kotlin.ir.visitors.IrElementVisitor import org.jetbrains.kotlin.types.KotlinType interface IrGetExtensionReceiverExpression : IrDeclarationReference { - override val descriptor: CallableDescriptor + override val descriptor: ReceiverParameterDescriptor } class IrGetExtensionReceiverExpressionImpl( startOffset: Int, endOffset: Int, type: KotlinType?, - descriptor: CallableDescriptor -) : IrTerminalDeclarationReferenceBase(startOffset, endOffset, type, descriptor), IrGetExtensionReceiverExpression { + descriptor: ReceiverParameterDescriptor +) : IrTerminalDeclarationReferenceBase(startOffset, endOffset, type, descriptor), IrGetExtensionReceiverExpression { override fun accept(visitor: IrElementVisitor, data: D): R = visitor.visitGetExtensionReceiver(this, data) } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrOperator.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrOperator.kt index f9e43696597..65c9b04d6bb 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrOperator.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrOperator.kt @@ -17,51 +17,58 @@ package org.jetbrains.kotlin.ir.expressions interface IrOperator { - object UMINUS : IrOperatorImpl("UMINUS"), IrUnaryOperator - object EXCL : IrOperatorImpl("EXCL"), IrUnaryOperator - object EXCLEXCL : IrOperatorImpl("EXCLEXCL"), IrUnaryOperator + abstract class IrOperatorImpl(val debugName: String): IrOperator { + override fun toString(): String = debugName + } + + object UMINUS : IrOperatorImpl("UMINUS") + object EXCL : IrOperatorImpl("EXCL") + object EXCLEXCL : IrOperatorImpl("EXCLEXCL") - object IMPLICIT_NOTNULL : IrOperatorImpl("IMPLICIT_NOTNULL"), IrUnaryOperator + object IMPLICIT_NOTNULL : IrOperatorImpl("IMPLICIT_NOTNULL") - object ELVIS : IrOperatorImpl("ELVIS"), IrBinaryOperator + object ELVIS : IrOperatorImpl("ELVIS") - object LT : IrOperatorImpl("LT"), IrBinaryOperator - object GT : IrOperatorImpl("GT"), IrBinaryOperator - object LTEQ : IrOperatorImpl("LTEQ"), IrBinaryOperator - object GTEQ : IrOperatorImpl("GTEQ"), IrBinaryOperator + object LT : IrOperatorImpl("LT") + object GT : IrOperatorImpl("GT") + object LTEQ : IrOperatorImpl("LTEQ") + object GTEQ : IrOperatorImpl("GTEQ") - object EQEQ : IrOperatorImpl("EQEQ"), IrBinaryOperator - object EQEQEQ : IrOperatorImpl("EQEQEQ"), IrBinaryOperator - object EXCLEQ : IrOperatorImpl("EXCLEQ"), IrBinaryOperator - object EXCLEQEQ : IrOperatorImpl("EXCLEQEQ"), IrBinaryOperator + object EQEQ : IrOperatorImpl("EQEQ") + object EQEQEQ : IrOperatorImpl("EQEQEQ") + object EXCLEQ : IrOperatorImpl("EXCLEQ") + object EXCLEQEQ : IrOperatorImpl("EXCLEQEQ") - object IN : IrOperatorImpl("IN"), IrBinaryOperator - object NOT_IN : IrOperatorImpl("NOT_IN"), IrBinaryOperator - object ANDAND : IrOperatorImpl("ANDAND"), IrBinaryOperator - object OROR : IrOperatorImpl("OROR"), IrBinaryOperator + object IN : IrOperatorImpl("IN") + object NOT_IN : IrOperatorImpl("NOT_IN") + object ANDAND : IrOperatorImpl("ANDAND") + object OROR : IrOperatorImpl("OROR") - object PLUS : IrOperatorImpl("PLUS"), IrBinaryOperator - object MINUS : IrOperatorImpl("MINUS"), IrBinaryOperator - object MUL : IrOperatorImpl("MUL"), IrBinaryOperator - object DIV : IrOperatorImpl("DIV"), IrBinaryOperator - object PERC : IrOperatorImpl("PERC"), IrBinaryOperator - object RANGE : IrOperatorImpl("RANGE"), IrBinaryOperator + object PLUS : IrOperatorImpl("PLUS") + object MINUS : IrOperatorImpl("MINUS") + object MUL : IrOperatorImpl("MUL") + object DIV : IrOperatorImpl("DIV") + object PERC : IrOperatorImpl("PERC") + object RANGE : IrOperatorImpl("RANGE") - object INVOKE : IrOperatorImpl("INVOKE"), IrUnaryOperator + object INVOKE : IrOperatorImpl("INVOKE") - object PREFIX_INCR : IrOperatorImpl("PREFIX_INCR"), IrUnaryOperator - object PREFIX_DECR : IrOperatorImpl("PREFIX_DECR"), IrUnaryOperator - object POSTFIX_INCR : IrOperatorImpl("POSTFIX_INCR"), IrUnaryOperator - object POSTFIX_DECR : IrOperatorImpl("POSTFIX_DECR"), IrUnaryOperator + object PREFIX_INCR : IrOperatorImpl("PREFIX_INCR") + object PREFIX_DECR : IrOperatorImpl("PREFIX_DECR") + object POSTFIX_INCR : IrOperatorImpl("POSTFIX_INCR") + object POSTFIX_DECR : IrOperatorImpl("POSTFIX_DECR") - object EQ : IrOperatorImpl("EQ"), IrBinaryOperator - object PLUSEQ : IrOperatorImpl("PLUSEQ"), IrBinaryOperator - object MINUSEQ : IrOperatorImpl("MINUSEQ"), IrBinaryOperator - object MULTEQ : IrOperatorImpl("MULTEQ"), IrBinaryOperator - object DIVEQ : IrOperatorImpl("DIVEQ"), IrBinaryOperator - object PERCEQ : IrOperatorImpl("PERCEQ"), IrBinaryOperator + object EQ : IrOperatorImpl("EQ") + object PLUSEQ : IrOperatorImpl("PLUSEQ") + object MINUSEQ : IrOperatorImpl("MINUSEQ") + object MULTEQ : IrOperatorImpl("MULTEQ") + object DIVEQ : IrOperatorImpl("DIVEQ") + object PERCEQ : IrOperatorImpl("PERCEQ") object SYNTHETIC_BLOCK : IrOperatorImpl("SYNTHETIC_BLOCK") + + object GET_PROPERTY : IrOperatorImpl("GET_PROPERTY") + object SET_PROPERTY : IrOperatorImpl("SET_PROPERTY") data class COMPONENT_N private constructor(val index: Int) : IrOperatorImpl("COMPONENT_$index") { companion object { @@ -75,10 +82,3 @@ interface IrOperator { } } } - -interface IrUnaryOperator : IrOperator -interface IrBinaryOperator : IrOperator - -abstract class IrOperatorImpl(val debugName: String): IrOperator { - override fun toString(): String = debugName -} \ No newline at end of file diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrOperatorExpression.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrOperatorExpression.kt index b91cb6d80ef..a7fd09fd926 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrOperatorExpression.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrOperatorExpression.kt @@ -27,12 +27,12 @@ interface IrOperatorExpression : IrExpression { } interface IrUnaryOperatorExpression : IrOperatorExpression { - override val operator: IrUnaryOperator + override val operator: IrOperator var argument: IrExpression } interface IrBinaryOperatorExpression : IrOperatorExpression { - override val operator: IrBinaryOperator + override val operator: IrOperator var argument0: IrExpression var argument1: IrExpression } @@ -41,14 +41,14 @@ class IrUnaryOperatorExpressionImpl( startOffset: Int, endOffset: Int, type: KotlinType?, - override val operator: IrUnaryOperator, + override val operator: IrOperator, override val relatedDescriptor: CallableDescriptor? ) : IrExpressionBase(startOffset, endOffset, type), IrUnaryOperatorExpression { constructor( startOffset: Int, endOffset: Int, type: KotlinType?, - operator: IrUnaryOperator, + operator: IrOperator, relatedDescriptor: CallableDescriptor?, argument: IrExpression ) : this(startOffset, endOffset, type, operator, relatedDescriptor) { @@ -91,14 +91,14 @@ class IrBinaryOperatorExpressionImpl( startOffset: Int, endOffset: Int, type: KotlinType?, - override val operator: IrBinaryOperator, + override val operator: IrOperator, override val relatedDescriptor: CallableDescriptor? ) : IrExpressionBase(startOffset, endOffset, type), IrBinaryOperatorExpression { constructor( startOffset: Int, endOffset: Int, type: KotlinType?, - operator: IrBinaryOperator, + operator: IrOperator, relatedDescriptor: CallableDescriptor?, argument0: IrExpression, argument1: IrExpression diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrPropertyAccessExpression.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrPropertyAccessExpression.kt deleted file mode 100644 index 20407e643bc..00000000000 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrPropertyAccessExpression.kt +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2010-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.ir.expressions - -import org.jetbrains.kotlin.descriptors.PropertyDescriptor -import org.jetbrains.kotlin.ir.* -import org.jetbrains.kotlin.ir.visitors.IrElementVisitor -import org.jetbrains.kotlin.types.KotlinType - -interface IrPropertyAccessExpression : IrMemberAccessExpression { - override val descriptor: PropertyDescriptor - val operator: IrOperator? -} - -interface IrGetPropertyExpression : IrPropertyAccessExpression - -interface IrSetPropertyExpression : IrPropertyAccessExpression { - var value: IrExpression -} - -class IrGetPropertyExpressionImpl( - startOffset: Int, - endOffset: Int, - type: KotlinType?, - isSafe: Boolean, - override val descriptor: PropertyDescriptor, - override val operator: IrOperator? = null -) : IrMemberAccessExpressionBase(startOffset, endOffset, type, isSafe), IrGetPropertyExpression { - override fun accept(visitor: IrElementVisitor, data: D): R = - visitor.visitGetProperty(this, data) -} - -class IrSetPropertyExpressionImpl( - startOffset: Int, - endOffset: Int, - isSafe: Boolean, - override val descriptor: PropertyDescriptor, - override val operator: IrOperator? = null -) : IrMemberAccessExpressionBase(startOffset, endOffset, null, isSafe), IrSetPropertyExpression { - constructor( - startOffset: Int, - endOffset: Int, - isSafe: Boolean, - descriptor: PropertyDescriptor, - value: IrExpression, - operator: IrOperator? = null - ) : this(startOffset, endOffset, isSafe, descriptor, operator) { - this.value = value - } - - private var valueImpl: IrExpression? = null - override var value: IrExpression - get() = valueImpl!! - set(value) { - value.assertDetached() - valueImpl?.detach() - valueImpl = value - value.setTreeLocation(this, ARGUMENT0_SLOT) - } - - override fun getChild(slot: Int): IrElement? = - when (slot) { - ARGUMENT0_SLOT -> value - else -> super.getChild(slot) - } - - override fun replaceChild(slot: Int, newChild: IrElement) { - when (slot) { - ARGUMENT0_SLOT -> value = newChild.assertCast() - else -> super.replaceChild(slot, newChild) - } - } - - override fun accept(visitor: IrElementVisitor, data: D): R { - return visitor.visitSetProperty(this, data) - } - - override fun acceptChildren(visitor: IrElementVisitor, data: D) { - super.acceptChildren(visitor, data) - value.accept(visitor, data) - } -} diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DumpIrTree.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DumpIrTree.kt index d96b95827b1..c25f1efa23a 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DumpIrTree.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DumpIrTree.kt @@ -20,8 +20,6 @@ import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.SourceLocationManager import org.jetbrains.kotlin.ir.declarations.IrFile import org.jetbrains.kotlin.ir.expressions.IrCallExpression -import org.jetbrains.kotlin.ir.expressions.IrGetPropertyExpression -import org.jetbrains.kotlin.ir.expressions.IrSetPropertyExpression import org.jetbrains.kotlin.ir.expressions.IrWhenExpression import org.jetbrains.kotlin.ir.visitors.IrElementVisitor import org.jetbrains.kotlin.utils.Printer @@ -56,21 +54,6 @@ class DumpIrTreeVisitor(out: Appendable): IrElementVisitor { } } - override fun visitGetProperty(expression: IrGetPropertyExpression, data: String) { - expression.dumpLabeledElementWith(data) { - expression.dispatchReceiver?.accept(this, "\$this") - expression.extensionReceiver?.accept(this, "\$receiver") - } - } - - override fun visitSetProperty(expression: IrSetPropertyExpression, data: String) { - expression.dumpLabeledElementWith(data) { - expression.dispatchReceiver?.accept(this, "\$this") - expression.extensionReceiver?.accept(this, "\$receiver") - expression.value.accept(this, "\$value") - } - } - override fun visitWhenExpression(expression: IrWhenExpression, data: String) { expression.dumpLabeledElementWith(data) { expression.subject?.let { subject -> diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/RenderIrElement.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/RenderIrElement.kt index 340254556b3..47cb3e0c6b3 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/RenderIrElement.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/RenderIrElement.kt @@ -79,14 +79,6 @@ class RenderIrElementVisitor : IrElementVisitor { "CALL ${if (expression.isSafe) "?." else "."}${expression.descriptor.name} " + "type=${expression.renderType()} operator=${expression.operator}" - override fun visitGetProperty(expression: IrGetPropertyExpression, data: Nothing?): String = - "GET_PROPERTY ${if (expression.isSafe) "?." else "."}${expression.descriptor.name} " + - "type=${expression.renderType()} operator=${expression.operator}" - - override fun visitSetProperty(expression: IrSetPropertyExpression, data: Nothing?): String = - "SET_PROPERTY ${if (expression.isSafe) "?." else "."}${expression.descriptor.name}" + - "type=${expression.renderType()} operator=${expression.operator}" - override fun visitGetVariable(expression: IrGetVariableExpression, data: Nothing?): String = "GET_VAR ${expression.descriptor.name} type=${expression.renderType()} operator=${expression.operator}" diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/visitors/IrElementVisitor.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/visitors/IrElementVisitor.kt index b085a1472b6..d29ed9816ad 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/visitors/IrElementVisitor.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/visitors/IrElementVisitor.kt @@ -47,16 +47,13 @@ interface IrElementVisitor { fun visitThisExpression(expression: IrThisExpression, data: D) = visitExpression(expression, data) fun visitDeclarationReference(expression: IrDeclarationReference, data: D) = visitExpression(expression, data) - fun visitGetObjectValue(expression: IrGetObjectValueExpression, data: D) = visitDeclarationReference(expression, data) - fun visitGetEnumValue(expression: IrGetEnumValueExpression, data: D) = visitDeclarationReference(expression, data) + fun visitSingletonReference(expression: IrGetSingletonValueExpression, data: D) = visitDeclarationReference(expression, data) + fun visitGetObjectValue(expression: IrGetObjectValueExpression, data: D) = visitSingletonReference(expression, data) + fun visitGetEnumValue(expression: IrGetEnumValueExpression, data: D) = visitSingletonReference(expression, data) fun visitGetVariable(expression: IrGetVariableExpression, data: D) = visitDeclarationReference(expression, data) fun visitSetVariable(expression: IrSetVariableExpression, data: D) = visitDeclarationReference(expression, data) fun visitGetExtensionReceiver(expression: IrGetExtensionReceiverExpression, data: D) = visitDeclarationReference(expression, data) - fun visitMemberAccess(expression: IrMemberAccessExpression, data: D) = visitDeclarationReference(expression, data) - fun visitCallExpression(expression: IrCallExpression, data: D) = visitMemberAccess(expression, data) - fun visitPropertyAccess(expression: IrPropertyAccessExpression, data: D) = visitMemberAccess(expression, data) - fun visitGetProperty(expression: IrGetPropertyExpression, data: D) = visitPropertyAccess(expression, data) - fun visitSetProperty(expression: IrSetPropertyExpression, data: D) = visitPropertyAccess(expression, data) + fun visitCallExpression(expression: IrCallExpression, data: D) = visitDeclarationReference(expression, data) fun visitOperatorExpression(expression: IrOperatorExpression, data: D) = visitExpression(expression, data) fun visitUnaryOperator(expression: IrUnaryOperatorExpression, data: D) = visitOperatorExpression(expression, data) diff --git a/compiler/testData/ir/irText/assignments.txt b/compiler/testData/ir/irText/assignments.txt index 1e5c79b7fd1..c66737e0f5d 100644 --- a/compiler/testData/ir/irText/assignments.txt +++ b/compiler/testData/ir/irText/assignments.txt @@ -14,6 +14,6 @@ IrFile /assignments.kt IrFunction public fun test2(/*0*/ r: Ref): kotlin.Unit IrExpressionBody BLOCK type= hasResult=false operator=null - SET_PROPERTY .xtype= operator=EQ + CALL . type=kotlin.Unit operator=EQ $this: GET_VAR r type=Ref operator=null - $value: LITERAL Int type=kotlin.Int value='0' + : LITERAL Int type=kotlin.Int value='0' diff --git a/compiler/testData/ir/irText/augmentedAssignment1.txt b/compiler/testData/ir/irText/augmentedAssignment1.txt index 6b38bfe0df3..5a6be13b3a9 100644 --- a/compiler/testData/ir/irText/augmentedAssignment1.txt +++ b/compiler/testData/ir/irText/augmentedAssignment1.txt @@ -30,23 +30,23 @@ IrFile /augmentedAssignment1.kt IrFunction public fun testProperty(): kotlin.Unit IrExpressionBody BLOCK type=kotlin.Int hasResult=true operator=null - SET_PROPERTY .ptype= operator=PLUSEQ - $value: CALL .plus type=kotlin.Int operator=PLUSEQ - $this: GET_PROPERTY .p type=kotlin.Int operator=PLUSEQ + CALL . type=kotlin.Unit operator=PLUSEQ + : CALL .plus type=kotlin.Int operator=PLUSEQ + $this: CALL . type=kotlin.Int operator=GET_PROPERTY other: LITERAL Int type=kotlin.Int value='1' - SET_PROPERTY .ptype= operator=MINUSEQ - $value: CALL .minus type=kotlin.Int operator=MINUSEQ - $this: GET_PROPERTY .p type=kotlin.Int operator=MINUSEQ + CALL . type=kotlin.Unit operator=MINUSEQ + : CALL .minus type=kotlin.Int operator=MINUSEQ + $this: CALL . type=kotlin.Int operator=GET_PROPERTY other: LITERAL Int type=kotlin.Int value='2' - SET_PROPERTY .ptype= operator=MULTEQ - $value: CALL .times type=kotlin.Int operator=MULTEQ - $this: GET_PROPERTY .p type=kotlin.Int operator=MULTEQ + CALL . type=kotlin.Unit operator=MULTEQ + : CALL .times type=kotlin.Int operator=MULTEQ + $this: CALL . type=kotlin.Int operator=GET_PROPERTY other: LITERAL Int type=kotlin.Int value='3' - SET_PROPERTY .ptype= operator=DIVEQ - $value: CALL .div type=kotlin.Int operator=DIVEQ - $this: GET_PROPERTY .p type=kotlin.Int operator=DIVEQ + CALL . type=kotlin.Unit operator=DIVEQ + : CALL .div type=kotlin.Int operator=DIVEQ + $this: CALL . type=kotlin.Int operator=GET_PROPERTY other: LITERAL Int type=kotlin.Int value='4' - SET_PROPERTY .ptype= operator=PERCEQ - $value: CALL .mod type=kotlin.Int operator=PERCEQ - $this: GET_PROPERTY .p type=kotlin.Int operator=PERCEQ + CALL . type=kotlin.Unit operator=PERCEQ + : CALL .mod type=kotlin.Int operator=PERCEQ + $this: CALL . type=kotlin.Int operator=GET_PROPERTY other: LITERAL Int type=kotlin.Int value='5' diff --git a/compiler/testData/ir/irText/augmentedAssignment2.txt b/compiler/testData/ir/irText/augmentedAssignment2.txt index 2ac2f045002..435b4e4572b 100644 --- a/compiler/testData/ir/irText/augmentedAssignment2.txt +++ b/compiler/testData/ir/irText/augmentedAssignment2.txt @@ -42,17 +42,17 @@ IrFile /augmentedAssignment2.kt IrExpressionBody BLOCK type= hasResult=false operator=null CALL .plusAssign type=kotlin.Unit operator=PLUSEQ - $receiver: GET_PROPERTY .p type=A operator=PLUSEQ + $receiver: CALL . type=A operator=GET_PROPERTY s: LITERAL String type=kotlin.String value='+=' CALL .minusAssign type=kotlin.Unit operator=MINUSEQ - $receiver: GET_PROPERTY .p type=A operator=MINUSEQ + $receiver: CALL . type=A operator=GET_PROPERTY s: LITERAL String type=kotlin.String value='-=' CALL .timesAssign type=kotlin.Unit operator=MULTEQ - $receiver: GET_PROPERTY .p type=A operator=MULTEQ + $receiver: CALL . type=A operator=GET_PROPERTY s: LITERAL String type=kotlin.String value='*=' CALL .divAssign type=kotlin.Unit operator=DIVEQ - $receiver: GET_PROPERTY .p type=A operator=DIVEQ + $receiver: CALL . type=A operator=GET_PROPERTY s: LITERAL String type=kotlin.String value='/=' CALL .modAssign type=kotlin.Unit operator=PERCEQ - $receiver: GET_PROPERTY .p type=A operator=PERCEQ + $receiver: CALL . type=A operator=GET_PROPERTY s: LITERAL String type=kotlin.String value='%=' diff --git a/compiler/testData/ir/irText/dotQualified.txt b/compiler/testData/ir/irText/dotQualified.txt index 897e7bcf4d6..0b3fc2c1904 100644 --- a/compiler/testData/ir/irText/dotQualified.txt +++ b/compiler/testData/ir/irText/dotQualified.txt @@ -3,12 +3,12 @@ IrFile /dotQualified.kt IrExpressionBody BLOCK type= hasResult=false operator=null RETURN type= - GET_PROPERTY .length type=kotlin.Int operator=null + CALL . type=kotlin.Int operator=GET_PROPERTY $this: GET_VAR s type=kotlin.String operator=null IrFunction public fun lengthN(/*0*/ s: kotlin.String?): kotlin.Int? IrExpressionBody BLOCK type= hasResult=false operator=null RETURN type= - GET_PROPERTY ?.length type=kotlin.Int? operator=null + CALL ?. type=kotlin.Int? operator=GET_PROPERTY $this: TYPE_OP operator=IMPLICIT_CAST typeOperand=kotlin.String GET_VAR s type=kotlin.String? operator=null diff --git a/compiler/testData/ir/irText/extensionPropertyGetterCall.txt b/compiler/testData/ir/irText/extensionPropertyGetterCall.txt index e3a8fbfb789..ccd0518ad0d 100644 --- a/compiler/testData/ir/irText/extensionPropertyGetterCall.txt +++ b/compiler/testData/ir/irText/extensionPropertyGetterCall.txt @@ -9,5 +9,5 @@ IrFile /extensionPropertyGetterCall.kt IrExpressionBody BLOCK type= hasResult=false operator=null RETURN type= - GET_PROPERTY .okext type=kotlin.String operator=null + CALL . type=kotlin.String operator=GET_PROPERTY $receiver: $RECEIVER of: test5 type=kotlin.String diff --git a/compiler/testData/ir/irText/incrementDecrement.txt b/compiler/testData/ir/irText/incrementDecrement.txt index 924099536c1..5b2e42fd9a0 100644 --- a/compiler/testData/ir/irText/incrementDecrement.txt +++ b/compiler/testData/ir/irText/incrementDecrement.txt @@ -34,17 +34,17 @@ IrFile /incrementDecrement.kt BLOCK type=kotlin.Int hasResult=true operator=PREFIX_INCR VAR val tmp0: kotlin.Int CALL .inc type=kotlin.Int operator=PREFIX_INCR - $this: GET_PROPERTY .p type=kotlin.Int operator=PREFIX_INCR - SET_PROPERTY .ptype= operator=PREFIX_INCR - $value: GET_VAR tmp0 type=kotlin.Int operator=null + $this: CALL . type=kotlin.Int operator=GET_PROPERTY + CALL . type=kotlin.Unit operator=PREFIX_INCR + : GET_VAR tmp0 type=kotlin.Int operator=null GET_VAR tmp0 type=kotlin.Int operator=null VAR val p2: kotlin.Int BLOCK type=kotlin.Int hasResult=true operator=PREFIX_DECR VAR val tmp1: kotlin.Int CALL .dec type=kotlin.Int operator=PREFIX_DECR - $this: GET_PROPERTY .p type=kotlin.Int operator=PREFIX_DECR - SET_PROPERTY .ptype= operator=PREFIX_DECR - $value: GET_VAR tmp1 type=kotlin.Int operator=null + $this: CALL . type=kotlin.Int operator=GET_PROPERTY + CALL . type=kotlin.Unit operator=PREFIX_DECR + : GET_VAR tmp1 type=kotlin.Int operator=null GET_VAR tmp1 type=kotlin.Int operator=null IrFunction public fun testArray(): kotlin.Unit IrExpressionBody @@ -52,7 +52,7 @@ IrFile /incrementDecrement.kt VAR val a1: kotlin.Int BLOCK type=kotlin.Int hasResult=true operator=PREFIX_INCR VAR val tmp0_array: kotlin.IntArray - GET_PROPERTY .arr type=kotlin.IntArray operator=null + CALL . type=kotlin.IntArray operator=GET_PROPERTY VAR val tmp1: kotlin.Int CALL .inc type=kotlin.Int operator=PREFIX_INCR $this: CALL .get type=kotlin.Int operator=PREFIX_INCR @@ -66,7 +66,7 @@ IrFile /incrementDecrement.kt VAR val a2: kotlin.Int BLOCK type=kotlin.Int hasResult=true operator=PREFIX_DECR VAR val tmp2_array: kotlin.IntArray - GET_PROPERTY .arr type=kotlin.IntArray operator=null + CALL . type=kotlin.IntArray operator=GET_PROPERTY VAR val tmp3: kotlin.Int CALL .dec type=kotlin.Int operator=PREFIX_DECR $this: CALL .get type=kotlin.Int operator=PREFIX_DECR diff --git a/compiler/testData/ir/irText/references.txt b/compiler/testData/ir/irText/references.txt index 5a7d1b5fc81..26ad5e17b95 100644 --- a/compiler/testData/ir/irText/references.txt +++ b/compiler/testData/ir/irText/references.txt @@ -4,7 +4,7 @@ IrFile /references.kt LITERAL String type=kotlin.String value='OK' IrProperty public val ok2: kotlin.String = "OK" getter=null setter=null IrExpressionBody - GET_PROPERTY .ok type=kotlin.String operator=null + CALL . type=kotlin.String operator=GET_PROPERTY IrProperty public val ok3: kotlin.String getter= setter=null IrPropertyGetter public fun (): kotlin.String property=ok3 IrExpressionBody @@ -15,7 +15,7 @@ IrFile /references.kt IrExpressionBody BLOCK type= hasResult=false operator=null RETURN type= - GET_PROPERTY .ok type=kotlin.String operator=null + CALL . type=kotlin.String operator=GET_PROPERTY IrFunction public fun test2(/*0*/ x: kotlin.String): kotlin.String IrExpressionBody BLOCK type= hasResult=false operator=null @@ -32,7 +32,7 @@ IrFile /references.kt IrExpressionBody BLOCK type= hasResult=false operator=null RETURN type= - GET_PROPERTY .ok3 type=kotlin.String operator=null + CALL . type=kotlin.String operator=GET_PROPERTY IrProperty public val kotlin.String.okext: kotlin.String getter= setter=null IrPropertyGetter public fun kotlin.String.(): kotlin.String property=okext IrExpressionBody @@ -43,5 +43,5 @@ IrFile /references.kt IrExpressionBody BLOCK type= hasResult=false operator=null RETURN type= - GET_PROPERTY .okext type=kotlin.String operator=null + CALL . type=kotlin.String operator=GET_PROPERTY $receiver: $RECEIVER of: test5 type=kotlin.String diff --git a/compiler/testData/ir/irText/smartCasts.txt b/compiler/testData/ir/irText/smartCasts.txt index ac4f30942cb..811526b0440 100644 --- a/compiler/testData/ir/irText/smartCasts.txt +++ b/compiler/testData/ir/irText/smartCasts.txt @@ -23,14 +23,14 @@ IrFile /smartCasts.kt GET_VAR x type=kotlin.Any operator=null then: RETURN type= CALL .println type=kotlin.Unit operator=null - message: GET_PROPERTY .length type=kotlin.Int operator=null + message: CALL . type=kotlin.Int operator=GET_PROPERTY $this: TYPE_OP operator=IMPLICIT_CAST typeOperand=kotlin.String GET_VAR x type=kotlin.Any operator=null CALL .expectsString type=kotlin.Unit operator=null s: TYPE_OP operator=IMPLICIT_CAST typeOperand=kotlin.String GET_VAR x type=kotlin.Any operator=null CALL .expectsInt type=kotlin.Unit operator=null - i: GET_PROPERTY .length type=kotlin.Int operator=null + i: CALL . type=kotlin.Int operator=GET_PROPERTY $this: TYPE_OP operator=IMPLICIT_CAST typeOperand=kotlin.String GET_VAR x type=kotlin.Any operator=null CALL .expectsString type=kotlin.Unit operator=null diff --git a/compiler/testData/ir/irText/values.txt b/compiler/testData/ir/irText/values.txt index 9a1cb660d03..bf14da34f5d 100644 --- a/compiler/testData/ir/irText/values.txt +++ b/compiler/testData/ir/irText/values.txt @@ -19,7 +19,7 @@ IrFile /values.kt IrExpressionBody BLOCK type= hasResult=false operator=null RETURN type= - GET_PROPERTY .a type=kotlin.Int operator=null + CALL . type=kotlin.Int operator=GET_PROPERTY IrFunction public fun test4(): Z.Companion IrExpressionBody BLOCK type= hasResult=false operator=null