Shrinking IR: GetProperty / SetProperty expressions are now generated as calls.

This commit is contained in:
Dmitry Petrov
2016-08-19 16:22:43 +03:00
committed by Dmitry Petrov
parent 8500f5ddb2
commit 70dfb75f82
22 changed files with 233 additions and 256 deletions
@@ -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<out CallableDescriptor>,
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 {
@@ -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
@@ -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
@@ -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
}
}
@@ -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
const val LOOP_CONDITION_SLOT = -2
const val SETTER_ARGUMENT_INDEX = 0
@@ -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 <R, D> accept(visitor: IrElementVisitor<R, D>, 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
}
}
@@ -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<CallableDescriptor>(startOffset, endOffset, type, descriptor), IrGetExtensionReceiverExpression {
descriptor: ReceiverParameterDescriptor
) : IrTerminalDeclarationReferenceBase<ReceiverParameterDescriptor>(startOffset, endOffset, type, descriptor), IrGetExtensionReceiverExpression {
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitGetExtensionReceiver(this, data)
}
@@ -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
}
@@ -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
@@ -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 <R, D> accept(visitor: IrElementVisitor<R, D>, 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 <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R {
return visitor.visitSetProperty(this, data)
}
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
super.acceptChildren(visitor, data)
value.accept(visitor, data)
}
}
@@ -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<Unit, String> {
}
}
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 ->
@@ -79,14 +79,6 @@ class RenderIrElementVisitor : IrElementVisitor<String, Nothing?> {
"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}"
@@ -47,16 +47,13 @@ interface IrElementVisitor<out R, in D> {
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)
+2 -2
View File
@@ -14,6 +14,6 @@ IrFile /assignments.kt
IrFunction public fun test2(/*0*/ r: Ref): kotlin.Unit
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
SET_PROPERTY .xtype=<no-type> operator=EQ
CALL .<set-x> type=kotlin.Unit operator=EQ
$this: GET_VAR r type=Ref operator=null
$value: LITERAL Int type=kotlin.Int value='0'
<set-?>: LITERAL Int type=kotlin.Int value='0'
+15 -15
View File
@@ -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=<no-type> operator=PLUSEQ
$value: CALL .plus type=kotlin.Int operator=PLUSEQ
$this: GET_PROPERTY .p type=kotlin.Int operator=PLUSEQ
CALL .<set-p> type=kotlin.Unit operator=PLUSEQ
<set-?>: CALL .plus type=kotlin.Int operator=PLUSEQ
$this: CALL .<get-p> type=kotlin.Int operator=GET_PROPERTY
other: LITERAL Int type=kotlin.Int value='1'
SET_PROPERTY .ptype=<no-type> operator=MINUSEQ
$value: CALL .minus type=kotlin.Int operator=MINUSEQ
$this: GET_PROPERTY .p type=kotlin.Int operator=MINUSEQ
CALL .<set-p> type=kotlin.Unit operator=MINUSEQ
<set-?>: CALL .minus type=kotlin.Int operator=MINUSEQ
$this: CALL .<get-p> type=kotlin.Int operator=GET_PROPERTY
other: LITERAL Int type=kotlin.Int value='2'
SET_PROPERTY .ptype=<no-type> operator=MULTEQ
$value: CALL .times type=kotlin.Int operator=MULTEQ
$this: GET_PROPERTY .p type=kotlin.Int operator=MULTEQ
CALL .<set-p> type=kotlin.Unit operator=MULTEQ
<set-?>: CALL .times type=kotlin.Int operator=MULTEQ
$this: CALL .<get-p> type=kotlin.Int operator=GET_PROPERTY
other: LITERAL Int type=kotlin.Int value='3'
SET_PROPERTY .ptype=<no-type> operator=DIVEQ
$value: CALL .div type=kotlin.Int operator=DIVEQ
$this: GET_PROPERTY .p type=kotlin.Int operator=DIVEQ
CALL .<set-p> type=kotlin.Unit operator=DIVEQ
<set-?>: CALL .div type=kotlin.Int operator=DIVEQ
$this: CALL .<get-p> type=kotlin.Int operator=GET_PROPERTY
other: LITERAL Int type=kotlin.Int value='4'
SET_PROPERTY .ptype=<no-type> operator=PERCEQ
$value: CALL .mod type=kotlin.Int operator=PERCEQ
$this: GET_PROPERTY .p type=kotlin.Int operator=PERCEQ
CALL .<set-p> type=kotlin.Unit operator=PERCEQ
<set-?>: CALL .mod type=kotlin.Int operator=PERCEQ
$this: CALL .<get-p> type=kotlin.Int operator=GET_PROPERTY
other: LITERAL Int type=kotlin.Int value='5'
+5 -5
View File
@@ -42,17 +42,17 @@ IrFile /augmentedAssignment2.kt
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
CALL .plusAssign type=kotlin.Unit operator=PLUSEQ
$receiver: GET_PROPERTY .p type=A operator=PLUSEQ
$receiver: CALL .<get-p> 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 .<get-p> 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 .<get-p> 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 .<get-p> 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 .<get-p> type=A operator=GET_PROPERTY
s: LITERAL String type=kotlin.String value='%='
+2 -2
View File
@@ -3,12 +3,12 @@ IrFile /dotQualified.kt
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
GET_PROPERTY .length type=kotlin.Int operator=null
CALL .<get-length> 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=<no-type> hasResult=false operator=null
RETURN type=<no-type>
GET_PROPERTY ?.length type=kotlin.Int? operator=null
CALL ?.<get-length> type=kotlin.Int? operator=GET_PROPERTY
$this: TYPE_OP operator=IMPLICIT_CAST typeOperand=kotlin.String
GET_VAR s type=kotlin.String? operator=null
@@ -9,5 +9,5 @@ IrFile /extensionPropertyGetterCall.kt
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
GET_PROPERTY .okext type=kotlin.String operator=null
CALL .<get-okext> type=kotlin.String operator=GET_PROPERTY
$receiver: $RECEIVER of: test5 type=kotlin.String
+8 -8
View File
@@ -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=<no-type> operator=PREFIX_INCR
$value: GET_VAR tmp0 type=kotlin.Int operator=null
$this: CALL .<get-p> type=kotlin.Int operator=GET_PROPERTY
CALL .<set-p> type=kotlin.Unit operator=PREFIX_INCR
<set-?>: 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=<no-type> operator=PREFIX_DECR
$value: GET_VAR tmp1 type=kotlin.Int operator=null
$this: CALL .<get-p> type=kotlin.Int operator=GET_PROPERTY
CALL .<set-p> type=kotlin.Unit operator=PREFIX_DECR
<set-?>: 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 .<get-arr> 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 .<get-arr> 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
+4 -4
View File
@@ -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 .<get-ok> type=kotlin.String operator=GET_PROPERTY
IrProperty public val ok3: kotlin.String getter=<get-ok3> setter=null
IrPropertyGetter public fun <get-ok3>(): kotlin.String property=ok3
IrExpressionBody
@@ -15,7 +15,7 @@ IrFile /references.kt
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
GET_PROPERTY .ok type=kotlin.String operator=null
CALL .<get-ok> type=kotlin.String operator=GET_PROPERTY
IrFunction public fun test2(/*0*/ x: kotlin.String): kotlin.String
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
@@ -32,7 +32,7 @@ IrFile /references.kt
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
GET_PROPERTY .ok3 type=kotlin.String operator=null
CALL .<get-ok3> type=kotlin.String operator=GET_PROPERTY
IrProperty public val kotlin.String.okext: kotlin.String getter=<get-okext> setter=null
IrPropertyGetter public fun kotlin.String.<get-okext>(): kotlin.String property=okext
IrExpressionBody
@@ -43,5 +43,5 @@ IrFile /references.kt
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
GET_PROPERTY .okext type=kotlin.String operator=null
CALL .<get-okext> type=kotlin.String operator=GET_PROPERTY
$receiver: $RECEIVER of: test5 type=kotlin.String
+2 -2
View File
@@ -23,14 +23,14 @@ IrFile /smartCasts.kt
GET_VAR x type=kotlin.Any operator=null
then: RETURN type=<no-type>
CALL .println type=kotlin.Unit operator=null
message: GET_PROPERTY .length type=kotlin.Int operator=null
message: CALL .<get-length> 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 .<get-length> 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
+1 -1
View File
@@ -19,7 +19,7 @@ IrFile /values.kt
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
GET_PROPERTY .a type=kotlin.Int operator=null
CALL .<get-a> type=kotlin.Int operator=GET_PROPERTY
IrFunction public fun test4(): Z.Companion
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null