From 985f3b20c748758534d5a9d024c27bf697ff7add Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Mon, 22 Aug 2016 16:05:42 +0300 Subject: [PATCH] Unary operators. --- .../kotlin/psi2ir/generators/CallGenerator.kt | 17 ++- .../psi2ir/generators/IrBlockBuilder.kt | 58 ++++++++-- .../psi2ir/generators/IrBodyGenerator.kt | 19 +++- .../generators/OperatorExpressionGenerator.kt | 81 +++++++++---- .../kotlin/psi2ir/generators/Scope.kt | 106 +++++++++--------- .../psi2ir/generators/StatementGenerator.kt | 10 +- .../generators/WhenExpressionGenerator.kt | 7 +- .../{ => operators}/OperatorConventions.kt | 18 +-- .../psi2ir/generators/values/IndexedLValue.kt | 50 ++++++--- .../kotlin/psi2ir/generators/values/Value.kt | 3 +- .../kotlin/ir/expressions/IrConst.kt | 32 +++--- .../kotlin/ir/expressions/IrOperator.kt | 1 + .../kotlin/ir/util/RenderIrElement.kt | 2 +- .../testData/ir/irText/arrayAssignment.txt | 8 +- .../ir/irText/arrayAugmentedAssignment1.txt | 16 +-- .../ir/irText/arrayAugmentedAssignment2.txt | 6 +- compiler/testData/ir/irText/assignments.txt | 8 +- .../ir/irText/augmentedAssignment1.txt | 24 ++-- .../ir/irText/augmentedAssignment2.txt | 20 ++-- .../testData/ir/irText/booleanOperators.txt | 4 +- compiler/testData/ir/irText/boxOk.txt | 2 +- .../ir/irText/callWithReorderedArguments.txt | 10 +- compiler/testData/ir/irText/calls.txt | 2 +- compiler/testData/ir/irText/elvis.kt | 11 +- compiler/testData/ir/irText/elvis.txt | 64 ++++++++++- .../ir/irText/extensionPropertyGetterCall.txt | 2 +- compiler/testData/ir/irText/ifElseIf.txt | 15 +-- .../ir/irText/implicitCastOnPlatformType.txt | 13 ++- .../testData/ir/irText/incrementDecrement.kt | 22 +++- .../testData/ir/irText/incrementDecrement.txt | 89 +++++++++++++-- compiler/testData/ir/irText/literals.kt | 6 + compiler/testData/ir/irText/literals.txt | 20 ++++ compiler/testData/ir/irText/references.txt | 8 +- .../ir/irText/simpleUnaryOperators.kt | 8 ++ .../ir/irText/simpleUnaryOperators.txt | 37 ++++++ compiler/testData/ir/irText/smartCasts.txt | 4 +- .../ir/irText/smartCastsWithDestructuring.txt | 4 +- compiler/testData/ir/irText/smoke.txt | 10 +- compiler/testData/ir/irText/stringPlus.txt | 6 +- compiler/testData/ir/irText/values.txt | 2 +- compiler/testData/ir/irText/when.txt | 62 +++++----- .../kotlin/ir/IrTextTestCaseGenerated.java | 12 ++ 42 files changed, 629 insertions(+), 270 deletions(-) rename compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/{ => operators}/OperatorConventions.kt (85%) create mode 100644 compiler/testData/ir/irText/literals.kt create mode 100644 compiler/testData/ir/irText/literals.txt create mode 100644 compiler/testData/ir/irText/simpleUnaryOperators.kt create mode 100644 compiler/testData/ir/irText/simpleUnaryOperators.txt 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 99e79b4015f..401a45fdce9 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 @@ -28,7 +28,7 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.* import org.jetbrains.kotlin.types.KotlinType import java.util.* -class CallGenerator(statementGenerator: StatementGenerator) : IrChildBodyGeneratorBase(statementGenerator) { +class CallGenerator(parentGenerator: StatementGenerator) : IrChildBodyGeneratorBase(parentGenerator) { fun generateCall( ktElement: KtElement, resolvedCall: ResolvedCall, @@ -94,15 +94,14 @@ class CallGenerator(statementGenerator: StatementGenerator) : IrChildBodyGenerat generateCallWithArgumentReordering(irCall, ktElement, resolvedCall, returnType) } else { - irCall.apply { - val valueArguments = resolvedCall.valueArgumentsByIndex - for (index in valueArguments!!.indices) { - val valueArgument = valueArguments[index] - val valueParameter = descriptor.valueParameters[index] - val irArgument = generateValueArgument(valueArgument, valueParameter) ?: continue - irCall.putArgument(index, irArgument) - } + val valueArguments = resolvedCall.valueArgumentsByIndex + for (index in valueArguments!!.indices) { + val valueArgument = valueArguments[index] + val valueParameter = descriptor.valueParameters[index] + val irArgument = generateValueArgument(valueArgument, valueParameter) ?: continue + irCall.putArgument(index, irArgument) } + irCall } } diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/IrBlockBuilder.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/IrBlockBuilder.kt index 87410b336b3..243ffac9288 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/IrBlockBuilder.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/IrBlockBuilder.kt @@ -16,10 +16,10 @@ package org.jetbrains.kotlin.psi2ir.generators +import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.ir.IrStatement -import org.jetbrains.kotlin.ir.expressions.IrBlockImpl -import org.jetbrains.kotlin.ir.expressions.IrExpression -import org.jetbrains.kotlin.ir.expressions.IrOperator +import org.jetbrains.kotlin.ir.assertCast +import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.psi.KtElement import org.jetbrains.kotlin.psi.psiUtil.endOffset import org.jetbrains.kotlin.psi.psiUtil.startOffset @@ -42,20 +42,56 @@ class IrBlockBuilder(val startOffset: Int, val endOffset: Int, val irOperator: I fun result(irExpression: T): T { resultType = irExpression.type hasResult = true + statements.add(irExpression) return irExpression } fun build() = if (statements.size == 1) statements[0] - else - IrBlockImpl(startOffset, endOffset, resultType, hasResult, irOperator).apply { - statements.forEach { addStatement(it) } - } + else { + val block = IrBlockImpl(startOffset, endOffset, resultType, hasResult, irOperator) + statements.forEach { block.addStatement(it) } + block + } } -fun IrBodyGenerator.block(ktElement: KtElement, irOperator: IrOperator, body: IrBlockBuilder.() -> Unit) = - IrBlockBuilder(ktElement.startOffset, ktElement.endOffset, irOperator, this).apply(body).build() +fun IrBodyGenerator.block(ktElement: KtElement, irOperator: IrOperator, body: IrBlockBuilder.() -> Unit): IrExpression = + IrBlockBuilder(ktElement.startOffset, ktElement.endOffset, irOperator, this).apply(body).build().assertCast() -fun IrBodyGenerator.block(irExpression: IrExpression, irOperator: IrOperator, body: IrBlockBuilder.() -> Unit) = - IrBlockBuilder(irExpression.startOffset, irExpression.endOffset, irOperator, this).apply(body).build() \ No newline at end of file +fun IrBodyGenerator.block(irExpression: IrExpression, irOperator: IrOperator, body: IrBlockBuilder.() -> Unit): IrExpression = + IrBlockBuilder(irExpression.startOffset, irExpression.endOffset, irOperator, this).apply(body).build().assertCast() + +fun IrBlockBuilder.constType(constKind: IrConstKind<*>): KotlinType = + when (constKind) { + IrConstKind.Null -> generator.context.builtIns.nullableNothingType + IrConstKind.Boolean -> generator.context.builtIns.anyType + IrConstKind.Byte -> generator.context.builtIns.byteType + IrConstKind.Short -> generator.context.builtIns.shortType + IrConstKind.Int -> generator.context.builtIns.intType + IrConstKind.Long -> generator.context.builtIns.longType + IrConstKind.String -> generator.context.builtIns.stringType + IrConstKind.Float -> generator.context.builtIns.floatType + IrConstKind.Double -> generator.context.builtIns.doubleType + } + +fun IrBlockBuilder.const(constKind: IrConstKind, value: T) = + IrConstImpl(startOffset, endOffset, constType(constKind), constKind, value) + +fun IrBlockBuilder.constNull() = + const(IrConstKind.Null, null) + +fun IrBlockBuilder.op0(operatorDescriptor: CallableDescriptor) = + IrNullaryOperatorImpl(startOffset, endOffset, irOperator, operatorDescriptor) + +fun IrBlockBuilder.op1(operatorDescriptor: CallableDescriptor, argument: IrExpression) = + IrUnaryOperatorImpl(startOffset, endOffset, irOperator, operatorDescriptor, argument) + +fun IrBlockBuilder.op2(operatorDescriptor: CallableDescriptor, argument1: IrExpression, argument2: IrExpression) = + IrBinaryOperatorImpl(startOffset, endOffset, irOperator, operatorDescriptor, argument1, argument2) + +fun IrBlockBuilder.equalsNull(argument: IrExpression) = + op2(generator.context.irBuiltIns.eqeq, argument, constNull()) + +fun IrBlockBuilder.ifThenElse(type: KotlinType?, condition: IrExpression, thenBranch: IrExpression, elseBranch: IrExpression) = + IrIfThenElseImpl(startOffset, endOffset, type, condition, thenBranch, elseBranch, irOperator) diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/IrBodyGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/IrBodyGenerator.kt index 1a68ed4cb54..db3c06fc274 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/IrBodyGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/IrBodyGenerator.kt @@ -27,9 +27,11 @@ interface IrBodyGenerator : IrGenerator { val scope: Scope } -abstract class IrChildBodyGeneratorBase(val parentGenerator: T) : IrBodyGenerator { +abstract class IrChildBodyGeneratorBase( + val parentGenerator: T +) : IrBodyGenerator { override val context: GeneratorContext get() = parentGenerator.context - override val scope: Scope get() = parentGenerator.scope + override val scope: Scope = Scope(parentGenerator.scope) } fun IrBodyGenerator.toExpectedType(irExpression: IrExpression, expectedType: KotlinType?): IrExpression { @@ -41,9 +43,13 @@ fun IrBodyGenerator.toExpectedType(irExpression: IrExpression, expectedType: Kot val valueType = irExpression.type ?: throw AssertionError("expectedType != null, valueType == null: $this") if (valueType.isNullabilityFlexible() && !expectedType.isMarkedNullable) { - return IrUnaryOperatorImpl(irExpression.startOffset, irExpression.endOffset, IrOperator.IMPLICIT_NOTNULL, - context.irBuiltIns.implicitNotNull, - irExpression) + return block(irExpression, IrOperator.IMPLICIT_NOTNULL) { + add(scope.introduceTemporary(irExpression)) + result(ifThenElse(expectedType, + equalsNull(scope.valueOf(irExpression)!!), + op0(context.irBuiltIns.throwNpe), + scope.valueOf(irExpression)!!)) + } } if (!KotlinTypeChecker.DEFAULT.isSubtypeOf(valueType, expectedType)) { @@ -58,4 +64,5 @@ fun StatementGenerator.generateExpressionWithExpectedType(ktExpression: KtExpres toExpectedType(generateExpression(ktExpression), expectedType) fun IrBodyGenerator.toExpectedTypeOrNull(irExpression: IrExpression?, expectedType: KotlinType?): IrExpression? = - irExpression?.let { toExpectedType(it, expectedType) } \ No newline at end of file + irExpression?.let { toExpectedType(it, expectedType) } + 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 3a3119951a7..74a52cbfe2f 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 @@ -25,27 +25,36 @@ import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.endOffset import org.jetbrains.kotlin.psi.psiUtil.startOffset import org.jetbrains.kotlin.psi2ir.defaultLoad +import org.jetbrains.kotlin.psi2ir.generators.operators.* import org.jetbrains.kotlin.psi2ir.generators.values.* import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.calls.callUtil.isSafeCall import org.jetbrains.kotlin.types.typeUtil.makeNullable -import java.lang.AssertionError -class OperatorExpressionGenerator(statementGenerator: StatementGenerator) : IrChildBodyGeneratorBase(statementGenerator) { + +class OperatorExpressionGenerator(parentGenerator: StatementGenerator) : IrChildBodyGeneratorBase(parentGenerator) { fun generatePrefixExpression(expression: KtPrefixExpression): IrExpression { val ktOperator = expression.operationReference.getReferencedNameElementType() - val irOperator = getIrPrefixOperator(ktOperator) + val irOperator = getPrefixOperator(ktOperator) return when (irOperator) { - null -> createDummyExpression(expression, ktOperator.toString()) - in PREFIX_INCREMENT_DECREMENT_OPERATORS -> generatePrefixIncrementDecrementOperator(expression, irOperator) + null -> throw AssertionError("Unexpected prefix operator: $ktOperator") + in INCREMENT_DECREMENT_OPERATORS -> generatePrefixIncrementDecrementOperator(expression, irOperator) + in OPERATORS_DESUGARED_TO_CALLS -> generatePrefixOperatorAsCall(expression, irOperator) else -> createDummyExpression(expression, ktOperator.toString()) } } fun generatePostfixExpression(expression: KtPostfixExpression): IrExpression { - TODO("not implemented") + val ktOperator = expression.operationReference.getReferencedNameElementType() + val irOperator = getPostfixOperator(ktOperator) + + return when (irOperator) { + null -> throw AssertionError("Unexpected postfix operator: $ktOperator") + in INCREMENT_DECREMENT_OPERATORS -> generatePostfixIncrementDecrementOperator(expression, irOperator) + else -> createDummyExpression(expression, ktOperator.toString()) + } } fun generateCastExpression(expression: KtBinaryExpressionWithTypeRHS): IrExpression { @@ -78,17 +87,17 @@ class OperatorExpressionGenerator(statementGenerator: StatementGenerator) : IrCh fun generateBinaryExpression(expression: KtBinaryExpression): IrExpression { val ktOperator = expression.operationReference.getReferencedNameElementType() if (ktOperator == KtTokens.IDENTIFIER) { - return generateBinaryOperatorWithConventionalCall(expression, null) + return generateBinaryOperatorAsCall(expression, null) } - val irOperator = getIrBinaryOperator(ktOperator) + val irOperator = getInfixOperator(ktOperator) return when (irOperator) { - null -> createDummyExpression(expression, ktOperator.toString()) + null -> throw AssertionError("Unexpected infix operator: $ktOperator") IrOperator.EQ -> generateAssignment(expression) IrOperator.ELVIS -> generateElvis(expression) in AUGMENTED_ASSIGNMENTS -> generateAugmentedAssignment(expression, irOperator) - in BINARY_OPERATORS_DESUGARED_TO_CALLS -> generateBinaryOperatorWithConventionalCall(expression, irOperator) + in OPERATORS_DESUGARED_TO_CALLS -> generateBinaryOperatorAsCall(expression, irOperator) in COMPARISON_OPERATORS -> generateComparisonOperator(expression, irOperator) in EQUALITY_OPERATORS -> generateEqualityOperator(expression, irOperator) in IDENTITY_OPERATORS -> generateIdentityOperator(expression, irOperator) @@ -99,21 +108,22 @@ class OperatorExpressionGenerator(statementGenerator: StatementGenerator) : IrCh } private fun generateElvis(expression: KtBinaryExpression): IrExpression { - // TODO desugar '?:' to 'if' val specialCallForElvis = getResolvedCall(expression)!! val returnType = specialCallForElvis.resultingDescriptor.returnType!! - val irArgument0 = toExpectedType(parentGenerator.generateExpression(expression.left!!), returnType.makeNullable()) - val irArgument1 = toExpectedType(parentGenerator.generateExpression(expression.right!!), returnType) -// return IrBinaryOperatorImpl( -// expression.startOffset, expression.endOffset, returnType, -// IrOperator.ELVIS, null, irArgument0, irArgument1 -// ) - return createDummyExpression(expression, "elvis") + val irArgument0 = parentGenerator.generateExpressionWithExpectedType(expression.left!!, returnType.makeNullable()) + val irArgument1 = parentGenerator.generateExpressionWithExpectedType(expression.right!!, returnType) + return block(expression, IrOperator.ELVIS) { + add(scope.introduceTemporary(irArgument0)) + result(ifThenElse(returnType, + equalsNull(scope.valueOf(irArgument0)!!), + irArgument1, + scope.valueOf(irArgument0)!!)) + } } private fun generateBinaryBooleanOperator(expression: KtBinaryExpression, irOperator: IrOperator): IrExpression { - val irArgument0 = toExpectedType(parentGenerator.generateExpression(expression.left!!), context.builtIns.booleanType) - val irArgument1 = toExpectedType(parentGenerator.generateExpression(expression.right!!), context.builtIns.booleanType) + val irArgument0 = parentGenerator.generateExpressionWithExpectedType(expression.left!!, context.builtIns.booleanType) + val irArgument1 = parentGenerator.generateExpressionWithExpectedType(expression.right!!, context.builtIns.booleanType) return when (irOperator) { IrOperator.OROR -> IrIfThenElseImpl.oror(expression.startOffset, expression.endOffset, irArgument0, irArgument1) @@ -198,7 +208,7 @@ class OperatorExpressionGenerator(statementGenerator: StatementGenerator) : IrCh } - private fun generateBinaryOperatorWithConventionalCall(expression: KtBinaryExpression, irOperator: IrOperator?): IrExpression { + private fun generateBinaryOperatorAsCall(expression: KtBinaryExpression, irOperator: IrOperator?): IrExpression { val operatorCall = getResolvedCall(expression)!! return CallGenerator(parentGenerator).generateCall(expression, operatorCall, irOperator) } @@ -222,6 +232,35 @@ class OperatorExpressionGenerator(statementGenerator: StatementGenerator) : IrCh return irBlock } + private fun generatePostfixIncrementDecrementOperator(expression: KtPostfixExpression, irOperator: IrOperator): IrExpression { + val ktBaseExpression = expression.baseExpression!! + val irLValue = generateLValue(ktBaseExpression, irOperator) + val operatorCall = getResolvedCall(expression)!! + + if (irLValue is IrLValueWithAugmentedStore) { + return irLValue.postfixAugmentedStore(operatorCall, irOperator) + } + + val irBlock = IrBlockImpl(expression.startOffset, expression.endOffset, irLValue.type, true, irOperator) + val opCallGenerator = CallGenerator(parentGenerator) + + val irTmp = parentGenerator.scope.createTemporaryVariable(irLValue.load()) + irBlock.addStatement(irTmp) + + opCallGenerator.scope.putValue(ktBaseExpression, VariableLValue(this, irTmp, irOperator)) + val irOpCall = opCallGenerator.generateCall(expression, operatorCall, irOperator) + irBlock.addStatement(irLValue.store(irOpCall)) + + irBlock.addStatement(irTmp.defaultLoad()) + + return irBlock + } + + private fun generatePrefixOperatorAsCall(expression: KtPrefixExpression, irOperator: IrOperator): IrExpression { + val resolvedCall = getResolvedCall(expression)!! + return CallGenerator(parentGenerator).generateCall(expression, resolvedCall, irOperator) + } + private fun generateAugmentedAssignment(expression: KtBinaryExpression, irOperator: IrOperator): IrExpression { val ktLeft = expression.left!! val irLValue = generateLValue(ktLeft, irOperator) diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/Scope.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/Scope.kt index 3ed82308463..4407a0151c5 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/Scope.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/Scope.kt @@ -43,78 +43,82 @@ class Scope private constructor(val scopeOwner: DeclarationDescriptor, val paren private var lastTemporaryIndex: Int = parent?.lastTemporaryIndex ?: 0 private fun nextTemporaryIndex(): Int = parent?.nextTemporaryIndex() ?: lastTemporaryIndex++ - private val expressionValues = HashMap() - private val receiverValues = HashMap() - private val valueArgumentValues = HashMap() + private val values = HashMap() + + private inline fun introduceTemporary(irExpression: IrExpression, nameHint: String?, register: (IrValue) -> Unit): IrVariable? { + val rematerializable = createRematerializableValue(irExpression) + return if (rematerializable != null) { + register(rematerializable) + null + } + else { + createTemporary(irExpression, nameHint, register) + } + } + + private inline fun createTemporary(irExpression: IrExpression, nameHint: String?, register: (IrValue) -> Unit): IrVariable { + val irTemporary = createTemporaryVariable(irExpression, nameHint) + register(VariableLValue(generator, irTemporary)) + return irTemporary + } private fun createDescriptorForTemporaryVariable(type: KotlinType, nameHint: String? = null): IrTemporaryVariableDescriptor = - IrTemporaryVariableDescriptorImpl( - scopeOwner, - Name.identifier( - if (nameHint != null) - "tmp${nextTemporaryIndex()}_$nameHint" - else - "tmp${nextTemporaryIndex()}" - ), - type) + IrTemporaryVariableDescriptorImpl(scopeOwner, Name.identifier(getNameForTemporary(nameHint)), type) + + private fun getNameForTemporary(nameHint: String?): String { + val index = nextTemporaryIndex() + return if (nameHint != null) "tmp${index}_$nameHint" else "tmp$index" + } fun createTemporaryVariable(irExpression: IrExpression, nameHint: String? = null): IrVariable = - IrVariableImpl(irExpression.startOffset, irExpression.endOffset, IrDeclarationOriginKind.IR_TEMPORARY_VARIABLE, - createDescriptorForTemporaryVariable( - irExpression.type ?: throw AssertionError("No type for $irExpression"), - nameHint - ), - irExpression) + IrVariableImpl( + irExpression.startOffset, irExpression.endOffset, IrDeclarationOriginKind.IR_TEMPORARY_VARIABLE, + createDescriptorForTemporaryVariable( + irExpression.type ?: throw AssertionError("No type for $irExpression"), + nameHint + ), + irExpression + ) - fun introduceTemporary(ktExpression: KtExpression, irExpression: IrExpression, nameHint: String? = null): IrVariable? { - val rematerializable = createRematerializableValue(irExpression) - if (rematerializable != null) { - putValue(ktExpression, rematerializable) - return null - } + fun introduceTemporary(ktExpression: KtExpression, irExpression: IrExpression, nameHint: String? = null): IrVariable? = + introduceTemporary(irExpression, nameHint) { putValue(ktExpression, it) } - return createTemporary(ktExpression, irExpression, nameHint) - } + fun introduceTemporary(valueParameterDescriptor: ValueParameterDescriptor, irExpression: IrExpression): IrVariable? = + introduceTemporary(irExpression, valueParameterDescriptor.name.asString()) { putValue(valueParameterDescriptor, it) } - fun createTemporary(ktExpression: KtExpression, irExpression: IrExpression, nameHint: String?): IrVariable { - val irTmpVar = createTemporaryVariable(irExpression, nameHint) - putValue(ktExpression, VariableLValue(generator, irTmpVar)) - return irTmpVar - } + fun introduceTemporary(irExpression: IrExpression): IrVariable? = + introduceTemporary(irExpression, null) { putValue(irExpression, it) } - fun createTemporary(irExpression: IrExpression, nameHint: String?): IrVariable = - createTemporaryVariable(irExpression, nameHint) - - fun introduceTemporary(valueParameterDescriptor: ValueParameterDescriptor, irExpression: IrExpression): IrVariable? { - val rematerializable = createRematerializableValue(irExpression) - if (rematerializable != null) { - putValue(valueParameterDescriptor, rematerializable) - return null - } - - val irTmpVar = createTemporaryVariable(irExpression, valueParameterDescriptor.name.asString()) - putValue(valueParameterDescriptor, VariableLValue(generator, irTmpVar)) - return irTmpVar - } + fun createTemporary(ktExpression: KtExpression, irExpression: IrExpression, nameHint: String?): IrVariable = + createTemporary(irExpression, nameHint) { putValue(ktExpression, it) } fun putValue(ktExpression: KtExpression, irValue: IrValue) { - expressionValues[ktExpression] = irValue + values[ktExpression] = irValue } fun putValue(receiver: ReceiverValue, irValue: IrValue) { - receiverValues[receiver] = irValue + values[receiver] = irValue } fun putValue(parameter: ValueParameterDescriptor, irValue: IrValue) { - valueArgumentValues[parameter] = irValue + values[parameter] = irValue + } + + fun putValue(irExpression: IrExpression, irValue: IrValue) { + values[irExpression] = irValue } fun valueOf(ktExpression: KtExpression): IrExpression? = - expressionValues[ktExpression]?.load() ?: parent?.valueOf(ktExpression) + values[ktExpression]?.load() ?: parent?.valueOf(ktExpression) + fun valueOf(receiver: ReceiverValue): IrExpression? = - receiverValues[receiver]?.load() ?: parent?.valueOf(receiver) + values[receiver]?.load() ?: parent?.valueOf(receiver) + fun valueOf(parameter: ValueParameterDescriptor): IrExpression? = - valueArgumentValues[parameter]?.load() ?: parent?.valueOf(parameter) + values[parameter]?.load() ?: parent?.valueOf(parameter) + + fun valueOf(irExpression: IrExpression): IrExpression? = + values[irExpression]?.load() ?: parent?.valueOf(irExpression) companion object { fun rootScope(scopeOwner: DeclarationDescriptor, generator: IrBodyGenerator): Scope { diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/StatementGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/StatementGenerator.kt index 07241c3fa85..ab2398ae50c 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/StatementGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/StatementGenerator.kt @@ -33,6 +33,7 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject +import org.jetbrains.kotlin.resolve.constants.BooleanValue import org.jetbrains.kotlin.resolve.constants.IntValue import org.jetbrains.kotlin.resolve.constants.NullValue import org.jetbrains.kotlin.resolve.constants.StringValue @@ -40,6 +41,7 @@ import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluat import org.jetbrains.kotlin.resolve.descriptorUtil.classValueType import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils import org.jetbrains.kotlin.utils.SmartList +import org.jetbrains.kotlin.utils.addToStdlib.constant class StatementGenerator( override val context: GeneratorContext, @@ -145,6 +147,8 @@ class StatementGenerator( IrConstImpl.int(expression.startOffset, expression.endOffset, constantType, constantValue.value) is NullValue -> IrConstImpl.constNull(expression.startOffset, expression.endOffset, constantType) + is BooleanValue -> + IrConstImpl.boolean(expression.startOffset, expression.endOffset, constantType, constantValue.value) else -> TODO("handle other literal types: ${constantValue.type}") } @@ -171,7 +175,7 @@ class StatementGenerator( IrConstImpl.string(entry.startOffset, entry.endOffset, context.builtIns.stringType, entry.text) override fun visitSimpleNameExpression(expression: KtSimpleNameExpression, data: Nothing?): IrExpression { - val resolvedCall = getResolvedCall(expression)!! + val resolvedCall = getResolvedCall(expression) ?: throw AssertionError("No resolved call for ${expression.text}") if (resolvedCall is VariableAsFunctionResolvedCall) { TODO("Unexpected VariableAsFunctionResolvedCall") @@ -271,8 +275,8 @@ class StatementGenerator( var irElseBranch: IrExpression? = null whenBranches@while (true) { - val irCondition = generateExpressionWithExpectedType(expression.condition!!, context.builtIns.booleanType) - val irThenBranch = generateExpressionWithExpectedType(expression.then!!, resultType) + val irCondition = generateExpressionWithExpectedType(ktLastIf.condition!!, context.builtIns.booleanType) + val irThenBranch = generateExpressionWithExpectedType(ktLastIf.then!!, resultType) irBranches.add(Pair(irCondition, irThenBranch)) val ktElse = ktLastIf.`else`?.deparenthesize() diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/WhenExpressionGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/WhenExpressionGenerator.kt index e27534f5610..9205e475217 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/WhenExpressionGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/WhenExpressionGenerator.kt @@ -22,10 +22,11 @@ import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.endOffset import org.jetbrains.kotlin.psi.psiUtil.startOffset import org.jetbrains.kotlin.psi2ir.defaultLoad +import org.jetbrains.kotlin.psi2ir.generators.operators.getInfixOperator import org.jetbrains.kotlin.resolve.BindingContext -import java.util.* +import java.lang.AssertionError -class WhenExpressionGenerator(statementGenerator: StatementGenerator) : IrChildBodyGeneratorBase(statementGenerator) { +class WhenExpressionGenerator(parentGenerator: StatementGenerator) : IrChildBodyGeneratorBase(parentGenerator) { fun generate(expression: KtWhenExpression): IrExpression { val conditionsGenerator = CallGenerator(parentGenerator) @@ -114,7 +115,7 @@ class WhenExpressionGenerator(statementGenerator: StatementGenerator) : IrChildB private fun generateInRangeCondition(conditionsGenerator: CallGenerator, ktCondition: KtWhenConditionInRange): IrExpression { val inResolvedCall = getResolvedCall(ktCondition.operationReference)!! - val inOperator = getIrBinaryOperator(ktCondition.operationReference.getReferencedNameElementType()) + val inOperator = getInfixOperator(ktCondition.operationReference.getReferencedNameElementType()) val irInCall = conditionsGenerator.generateCall(ktCondition, inResolvedCall, inOperator) return when (inOperator) { IrOperator.IN -> irInCall 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/operators/OperatorConventions.kt similarity index 85% rename from compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/OperatorConventions.kt rename to compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/operators/OperatorConventions.kt index 82f8ac7c8fd..2eb6bff18b7 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/operators/OperatorConventions.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.jetbrains.kotlin.psi2ir.generators +package org.jetbrains.kotlin.psi2ir.generators.operators import com.intellij.psi.tree.IElementType import org.jetbrains.kotlin.ir.expressions.IrOperator @@ -22,7 +22,7 @@ import org.jetbrains.kotlin.ir.expressions.IrTypeOperator import org.jetbrains.kotlin.lexer.KtTokens -fun getIrBinaryOperator(ktOperator: IElementType): IrOperator? = +fun getInfixOperator(ktOperator: IElementType): IrOperator? = when (ktOperator) { KtTokens.EQ -> IrOperator.EQ KtTokens.PLUSEQ -> IrOperator.PLUSEQ @@ -52,16 +52,17 @@ fun getIrBinaryOperator(ktOperator: IElementType): IrOperator? = else -> null } -fun getIrPrefixOperator(ktOperator: IElementType): IrOperator? = +fun getPrefixOperator(ktOperator: IElementType): IrOperator? = when (ktOperator) { KtTokens.PLUSPLUS -> IrOperator.PREFIX_INCR KtTokens.MINUSMINUS -> IrOperator.PREFIX_DECR KtTokens.EXCL -> IrOperator.EXCL KtTokens.MINUS -> IrOperator.UMINUS + KtTokens.PLUS -> IrOperator.UPLUS else -> null } -fun getIrPostfixOperator(ktOperator: IElementType): IrOperator? = +fun getPostfixOperator(ktOperator: IElementType): IrOperator? = when (ktOperator) { KtTokens.PLUSPLUS -> IrOperator.POSTFIX_INCR KtTokens.MINUSMINUS -> IrOperator.POSTFIX_DECR @@ -81,8 +82,9 @@ fun getIrTypeOperator(ktOperator: IElementType): IrTypeOperator? = val AUGMENTED_ASSIGNMENTS = setOf(IrOperator.PLUSEQ, IrOperator.MINUSEQ, IrOperator.MULTEQ, IrOperator.DIVEQ, IrOperator.PERCEQ) -val BINARY_OPERATORS_DESUGARED_TO_CALLS = - setOf(IrOperator.PLUS, IrOperator.MINUS, IrOperator.MUL, IrOperator.DIV, IrOperator.PERC, IrOperator.RANGE) +val OPERATORS_DESUGARED_TO_CALLS = + setOf(IrOperator.PLUS, IrOperator.MINUS, IrOperator.MUL, IrOperator.DIV, IrOperator.PERC, IrOperator.RANGE, + IrOperator.EXCL, IrOperator.UMINUS, IrOperator.UPLUS) val COMPARISON_OPERATORS = setOf(IrOperator.LT, IrOperator.LTEQ, IrOperator.GT, IrOperator.GTEQ) @@ -99,8 +101,8 @@ val IN_OPERATORS = val BINARY_BOOLEAN_OPERATORS = setOf(IrOperator.ANDAND, IrOperator.OROR) -val PREFIX_INCREMENT_DECREMENT_OPERATORS = - setOf(IrOperator.PREFIX_INCR, IrOperator.PREFIX_DECR) +val INCREMENT_DECREMENT_OPERATORS = + setOf(IrOperator.PREFIX_INCR, IrOperator.PREFIX_DECR, IrOperator.POSTFIX_INCR, IrOperator.POSTFIX_DECR) val POSTFIX_INCREMENT_DECREMENT_OPERATORS = setOf(IrOperator.POSTFIX_INCR, IrOperator.POSTFIX_DECR) \ No newline at end of file diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/values/IndexedLValue.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/values/IndexedLValue.kt index fc3a2bb8772..937ad966a24 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/values/IndexedLValue.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/values/IndexedLValue.kt @@ -29,7 +29,7 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall import org.jetbrains.kotlin.types.KotlinType class IndexedLValue( - var statementGenerator: StatementGenerator, + val statementGenerator: StatementGenerator, val ktArrayAccessExpression: KtArrayAccessExpression, val irOperator: IrOperator?, val irArray: IrExpression, @@ -55,7 +55,7 @@ class IndexedLValue( setupCallGeneratorContext(callGenerator.scope) if (irArgument != null) { - callGenerator.scope.putValue(call.resultingDescriptor.valueParameters.last(), IrSingleExpressionValue(irArgument)) + callGenerator.scope.putValue(call.resultingDescriptor.valueParameters.last(), SingleExpressionValue(irArgument)) } return callGenerator.generateCall(ktArrayAccessExpression, call, irOperator) @@ -70,14 +70,14 @@ class IndexedLValue( val irBlock = createDesugaredBlockWithTemporaries(indexedSetCall, callGenerator, true, irOperator) val operatorCallReceiver = operatorCall.extensionReceiver ?: operatorCall.dispatchReceiver - callGenerator.scope.putValue(operatorCallReceiver!!, - IrSingleExpressionValue(callGenerator.generateCall(ktArrayAccessExpression, indexedGetCall, irOperator))) - val irTmp = statementGenerator.scope.createTemporaryVariable( - callGenerator.generateCall(ktArrayAccessExpression, operatorCall, irOperator)) + val irGetCall = callGenerator.generateCall(ktArrayAccessExpression, indexedGetCall, irOperator) + callGenerator.scope.putValue(operatorCallReceiver!!, SingleExpressionValue(irGetCall)) + + val irOpCall = callGenerator.generateCall(ktArrayAccessExpression, operatorCall, irOperator) + val irTmp = callGenerator.scope.createTemporaryVariable(irOpCall) irBlock.addStatement(irTmp) - callGenerator.scope.putValue(indexedSetCall.resultingDescriptor.valueParameters.last(), - VariableLValue(statementGenerator, irTmp)) + callGenerator.scope.putValue(indexedSetCall.resultingDescriptor.valueParameters.last(), VariableLValue(callGenerator, irTmp)) irBlock.addStatement(callGenerator.generateCall(ktArrayAccessExpression, indexedSetCall, irOperator)) @@ -86,6 +86,30 @@ class IndexedLValue( return irBlock } + override fun postfixAugmentedStore(operatorCall: ResolvedCall<*>, irOperator: IrOperator): IrExpression { + if (indexedGetCall == null) throw AssertionError("Indexed LValue has no 'get' call: ${ktArrayAccessExpression.text}") + if (indexedSetCall == null) throw AssertionError("Indexed LValue has no 'set' call: ${ktArrayAccessExpression.text}") + + val callGenerator = CallGenerator(statementGenerator) + + val irBlock = createDesugaredBlockWithTemporaries(indexedSetCall, callGenerator, true, irOperator) + + val irGetCall = callGenerator.generateCall(ktArrayAccessExpression, indexedGetCall, irOperator) + val irTmp = callGenerator.scope.createTemporaryVariable(irGetCall) + irBlock.addStatement(irTmp) + + val operatorCallReceiver = operatorCall.extensionReceiver ?: operatorCall.dispatchReceiver + callGenerator.scope.putValue(operatorCallReceiver!!, VariableLValue(callGenerator, irTmp)) + val irOpCall = callGenerator.generateCall(ktArrayAccessExpression, operatorCall, irOperator) + callGenerator.scope.putValue(indexedSetCall.resultingDescriptor.valueParameters.last(), SingleExpressionValue(irOpCall)) + val irSetCall = callGenerator.generateCall(ktArrayAccessExpression, indexedSetCall, irOperator) + irBlock.addStatement(irSetCall) + + irBlock.addStatement(irTmp.defaultLoad()) + + return irBlock + } + override fun augmentedStore(operatorCall: ResolvedCall<*>, irOperator: IrOperator, irOperatorArgument: IrExpression): IrExpression { if (indexedGetCall == null) throw AssertionError("Indexed LValue has no 'get' call: ${ktArrayAccessExpression.text}") if (indexedSetCall == null) throw AssertionError("Indexed LValue has no 'set' call: ${ktArrayAccessExpression.text}") @@ -94,14 +118,14 @@ class IndexedLValue( val irBlock = createDesugaredBlockWithTemporaries(indexedSetCall, callGenerator, false, irOperator) - callGenerator.scope.putValue(operatorCall.resultingDescriptor.valueParameters[0], IrSingleExpressionValue(irOperatorArgument)) + callGenerator.scope.putValue(operatorCall.resultingDescriptor.valueParameters[0], SingleExpressionValue(irOperatorArgument)) val operatorCallReceiver = operatorCall.extensionReceiver ?: operatorCall.dispatchReceiver callGenerator.scope.putValue(operatorCallReceiver!!, - IrSingleExpressionValue(callGenerator.generateCall(ktArrayAccessExpression, indexedGetCall, irOperator))) + SingleExpressionValue(callGenerator.generateCall(ktArrayAccessExpression, indexedGetCall, irOperator))) callGenerator.scope.putValue(indexedSetCall.resultingDescriptor.valueParameters.last(), - IrSingleExpressionValue(callGenerator.generateCall(ktArrayAccessExpression, operatorCall, irOperator))) + SingleExpressionValue(callGenerator.generateCall(ktArrayAccessExpression, operatorCall, irOperator))) irBlock.addStatement(callGenerator.generateCall(ktArrayAccessExpression, indexedSetCall, irOperator)) @@ -135,10 +159,10 @@ class IndexedLValue( } private fun setupCallGeneratorContext(scope: Scope) { - scope.putValue(ktArrayAccessExpression.arrayExpression!!, IrSingleExpressionValue(irArray)) + scope.putValue(ktArrayAccessExpression.arrayExpression!!, SingleExpressionValue(irArray)) for ((ktIndexExpression, irIndexValue) in indexValues) { - scope.putValue(ktIndexExpression, IrSingleExpressionValue(irIndexValue)) + scope.putValue(ktIndexExpression, SingleExpressionValue(irIndexValue)) } } } \ No newline at end of file diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/values/Value.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/values/Value.kt index 4c7f312b211..bc2fac03497 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/values/Value.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/values/Value.kt @@ -27,7 +27,7 @@ interface IrValue { val type: KotlinType? } -class IrSingleExpressionValue(val irExpression: IrExpression) : IrValue { +class SingleExpressionValue(val irExpression: IrExpression) : IrValue { init { irExpression.assertDetached() } @@ -50,6 +50,7 @@ interface IrLValue : IrValue { } interface IrLValueWithAugmentedStore : IrLValue { + fun postfixAugmentedStore(operatorCall: ResolvedCall<*>, irOperator: IrOperator): IrExpression fun prefixAugmentedStore(operatorCall: ResolvedCall<*>, irOperator: IrOperator): IrExpression fun augmentedStore(operatorCall: ResolvedCall<*>, irOperator: IrOperator, irOperatorArgument: IrExpression): IrExpression } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrConst.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrConst.kt index d67cad6bfee..c7654630ca2 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrConst.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrConst.kt @@ -20,24 +20,24 @@ import org.jetbrains.kotlin.ir.visitors.IrElementVisitor import org.jetbrains.kotlin.types.KotlinType interface IrConst : IrExpression { - val kind: IrLiteralKind + val kind: IrConstKind val value: T } -sealed class IrLiteralKind(val asString: kotlin.String) { +sealed class IrConstKind(val asString: kotlin.String) { @Suppress("UNCHECKED_CAST") fun valueOf(aConst: IrConst<*>) = (aConst as IrConst).value - object Null : IrLiteralKind("Null") - object Boolean : IrLiteralKind("Boolean") - object Byte : IrLiteralKind("Byte") - object Short : IrLiteralKind("Short") - object Int : IrLiteralKind("Int") - object Long : IrLiteralKind("Long") - object String : IrLiteralKind("String") - object Float : IrLiteralKind("Float") - object Double : IrLiteralKind("Double") + object Null : IrConstKind("Null") + object Boolean : IrConstKind("Boolean") + object Byte : IrConstKind("Byte") + object Short : IrConstKind("Short") + object Int : IrConstKind("Int") + object Long : IrConstKind("Long") + object String : IrConstKind("String") + object Float : IrConstKind("Float") + object Double : IrConstKind("Double") override fun toString() = asString } @@ -46,7 +46,7 @@ class IrConstImpl ( startOffset: Int, endOffset: Int, type: KotlinType?, - override val kind: IrLiteralKind, + override val kind: IrConstKind, override val value: T ) : IrTerminalExpressionBase(startOffset, endOffset, type), IrConst { override fun accept(visitor: IrElementVisitor, data: D): R = @@ -54,16 +54,16 @@ class IrConstImpl ( companion object { fun string(startOffset: Int, endOffset: Int, type: KotlinType, value: String): IrConstImpl = - IrConstImpl(startOffset, endOffset, type, IrLiteralKind.String, value) + IrConstImpl(startOffset, endOffset, type, IrConstKind.String, value) fun int(startOffset: Int, endOffset: Int, type: KotlinType, value: Int): IrConstImpl = - IrConstImpl(startOffset, endOffset, type, IrLiteralKind.Int, value) + IrConstImpl(startOffset, endOffset, type, IrConstKind.Int, value) fun constNull(startOffset: Int, endOffset: Int, type: KotlinType): IrConstImpl = - IrConstImpl(startOffset, endOffset, type, IrLiteralKind.Null, null) + IrConstImpl(startOffset, endOffset, type, IrConstKind.Null, null) fun boolean(startOffset: Int, endOffset: Int, type: KotlinType, value: Boolean): IrConstImpl = - IrConstImpl(startOffset, endOffset, type, IrLiteralKind.Boolean, value) + IrConstImpl(startOffset, endOffset, type, IrConstKind.Boolean, value) fun constTrue(startOffset: Int, endOffset: Int, type: KotlinType): IrConstImpl = boolean(startOffset, endOffset, type, true) 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 cbffea73a4a..600e8af113f 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 @@ -22,6 +22,7 @@ interface IrOperator { } object UMINUS : IrOperatorImpl("UMINUS") + object UPLUS : IrOperatorImpl("UPLUS") object EXCL : IrOperatorImpl("EXCL") object EXCLEXCL : IrOperatorImpl("EXCLEXCL") 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 d7fe9953148..fa0606d5c0f 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 @@ -61,7 +61,7 @@ class RenderIrElementVisitor : IrElementVisitor { "? ${expression.javaClass.simpleName} type=${expression.renderType()}" override fun visitConst(expression: IrConst, data: Nothing?): String = - "LITERAL ${expression.kind} type=${expression.renderType()} value='${expression.value}'" + "CONST ${expression.kind} type=${expression.renderType()} value='${expression.value}'" override fun visitBlock(expression: IrBlock, data: Nothing?): String = "BLOCK type=${expression.renderType()} hasResult=${expression.hasResult} operator=${expression.operator}" diff --git a/compiler/testData/ir/irText/arrayAssignment.txt b/compiler/testData/ir/irText/arrayAssignment.txt index 15934e0d3d4..68bcac7c335 100644 --- a/compiler/testData/ir/irText/arrayAssignment.txt +++ b/compiler/testData/ir/irText/arrayAssignment.txt @@ -7,13 +7,13 @@ IrFile /arrayAssignment.kt elements: DUMMY vararg type=kotlin.Int CALL .set type=kotlin.Unit operator=EQ $this: GET_VAR x type=kotlin.IntArray operator=null - index: LITERAL Int type=kotlin.Int value='1' - value: LITERAL Int type=kotlin.Int value='0' + index: CONST Int type=kotlin.Int value='1' + value: CONST Int type=kotlin.Int value='0' IrFunction public fun foo(): kotlin.Int IrExpressionBody BLOCK type= hasResult=false operator=null RETURN type= - LITERAL Int type=kotlin.Int value='1' + CONST Int type=kotlin.Int value='1' IrFunction public fun test2(): kotlin.Unit IrExpressionBody BLOCK type= hasResult=false operator=null @@ -21,4 +21,4 @@ IrFile /arrayAssignment.kt $this: CALL .intArrayOf type=kotlin.IntArray operator=null elements: DUMMY vararg type=kotlin.Int index: CALL .foo type=kotlin.Int operator=null - value: LITERAL Int type=kotlin.Int value='1' + value: CONST Int type=kotlin.Int value='1' diff --git a/compiler/testData/ir/irText/arrayAugmentedAssignment1.txt b/compiler/testData/ir/irText/arrayAugmentedAssignment1.txt index 3c1d7596468..15a9d30ceec 100644 --- a/compiler/testData/ir/irText/arrayAugmentedAssignment1.txt +++ b/compiler/testData/ir/irText/arrayAugmentedAssignment1.txt @@ -9,7 +9,7 @@ IrFile /arrayAugmentedAssignment1.kt IrExpressionBody BLOCK type= hasResult=false operator=null RETURN type= - LITERAL Int type=kotlin.Int value='42' + CONST Int type=kotlin.Int value='42' IrFunction public fun testVariable(): kotlin.Unit IrExpressionBody BLOCK type= hasResult=false operator=null @@ -18,23 +18,23 @@ IrFile /arrayAugmentedAssignment1.kt BLOCK type=kotlin.Unit hasResult=false operator=PLUSEQ CALL .set type=kotlin.Unit operator=PLUSEQ $this: GET_VAR x type=kotlin.IntArray operator=null - index: LITERAL Int type=kotlin.Int value='0' + index: CONST Int type=kotlin.Int value='0' value: CALL .plus type=kotlin.Int operator=PLUSEQ $this: CALL .get type=kotlin.Int operator=PLUSEQ $this: GET_VAR x type=kotlin.IntArray operator=null - index: LITERAL Int type=kotlin.Int value='0' - other: LITERAL Int type=kotlin.Int value='1' + index: CONST Int type=kotlin.Int value='0' + other: CONST Int type=kotlin.Int value='1' BLOCK type=kotlin.Unit hasResult=false operator=MULTEQ VAR val tmp0_array: kotlin.IntArray CALL .foo type=kotlin.IntArray operator=null CALL .set type=kotlin.Unit operator=MULTEQ $this: GET_VAR tmp0_array type=kotlin.IntArray operator=null - index: LITERAL Int type=kotlin.Int value='0' + index: CONST Int type=kotlin.Int value='0' value: CALL .times type=kotlin.Int operator=MULTEQ $this: CALL .get type=kotlin.Int operator=MULTEQ $this: GET_VAR tmp0_array type=kotlin.IntArray operator=null - index: LITERAL Int type=kotlin.Int value='0' - other: LITERAL Int type=kotlin.Int value='2' + index: CONST Int type=kotlin.Int value='0' + other: CONST Int type=kotlin.Int value='2' BLOCK type=kotlin.Unit hasResult=false operator=MINUSEQ VAR val tmp1_array: kotlin.IntArray CALL .foo type=kotlin.IntArray operator=null @@ -47,4 +47,4 @@ IrFile /arrayAugmentedAssignment1.kt $this: CALL .get type=kotlin.Int operator=MINUSEQ $this: GET_VAR tmp1_array type=kotlin.IntArray operator=null index: GET_VAR tmp2_index0 type=kotlin.Int operator=null - other: LITERAL Int type=kotlin.Int value='1' + other: CONST Int type=kotlin.Int value='1' diff --git a/compiler/testData/ir/irText/arrayAugmentedAssignment2.txt b/compiler/testData/ir/irText/arrayAugmentedAssignment2.txt index e8d19cee655..a1ce3539c94 100644 --- a/compiler/testData/ir/irText/arrayAugmentedAssignment2.txt +++ b/compiler/testData/ir/irText/arrayAugmentedAssignment2.txt @@ -8,9 +8,9 @@ IrFile /arrayAugmentedAssignment2.kt CALL .set type=kotlin.Unit operator=PLUSEQ $this: $RECEIVER of: test type=IB $receiver: GET_VAR a type=IA operator=null - index: LITERAL String type=kotlin.String value='' + index: CONST String type=kotlin.String value='' value: CALL .plus type=kotlin.Int operator=PLUSEQ $this: CALL .get type=kotlin.Int operator=PLUSEQ $this: GET_VAR a type=IA operator=null - index: LITERAL String type=kotlin.String value='' - other: LITERAL Int type=kotlin.Int value='42' + index: CONST String type=kotlin.String value='' + other: CONST Int type=kotlin.Int value='42' diff --git a/compiler/testData/ir/irText/assignments.txt b/compiler/testData/ir/irText/assignments.txt index c66737e0f5d..3b9e36b6410 100644 --- a/compiler/testData/ir/irText/assignments.txt +++ b/compiler/testData/ir/irText/assignments.txt @@ -4,16 +4,16 @@ IrFile /assignments.kt IrExpressionBody BLOCK type= hasResult=false operator=null VAR var x: kotlin.Int - LITERAL Int type=kotlin.Int value='0' + CONST Int type=kotlin.Int value='0' SET_VAR x type= operator=EQ - LITERAL Int type=kotlin.Int value='1' + CONST Int type=kotlin.Int value='1' SET_VAR x type= operator=EQ CALL .plus type=kotlin.Int operator=PLUS $this: GET_VAR x type=kotlin.Int operator=null - other: LITERAL Int type=kotlin.Int value='1' + other: CONST Int type=kotlin.Int value='1' IrFunction public fun test2(/*0*/ r: Ref): kotlin.Unit IrExpressionBody BLOCK type= hasResult=false operator=null CALL . type=kotlin.Unit operator=EQ $this: GET_VAR r type=Ref operator=null - : LITERAL Int type=kotlin.Int value='0' + : CONST Int type=kotlin.Int value='0' diff --git a/compiler/testData/ir/irText/augmentedAssignment1.txt b/compiler/testData/ir/irText/augmentedAssignment1.txt index 5a6be13b3a9..2ac3040a001 100644 --- a/compiler/testData/ir/irText/augmentedAssignment1.txt +++ b/compiler/testData/ir/irText/augmentedAssignment1.txt @@ -1,52 +1,52 @@ IrFile /augmentedAssignment1.kt IrProperty public var p: kotlin.Int getter=null setter=null IrExpressionBody - LITERAL Int type=kotlin.Int value='0' + CONST Int type=kotlin.Int value='0' IrFunction public fun testVariable(): kotlin.Unit IrExpressionBody BLOCK type=kotlin.Int hasResult=true operator=null VAR var x: kotlin.Int - LITERAL Int type=kotlin.Int value='0' + CONST Int type=kotlin.Int value='0' SET_VAR x type= operator=PLUSEQ CALL .plus type=kotlin.Int operator=PLUSEQ $this: GET_VAR x type=kotlin.Int operator=PLUSEQ - other: LITERAL Int type=kotlin.Int value='1' + other: CONST Int type=kotlin.Int value='1' SET_VAR x type= operator=MINUSEQ CALL .minus type=kotlin.Int operator=MINUSEQ $this: GET_VAR x type=kotlin.Int operator=MINUSEQ - other: LITERAL Int type=kotlin.Int value='2' + other: CONST Int type=kotlin.Int value='2' SET_VAR x type= operator=MULTEQ CALL .times type=kotlin.Int operator=MULTEQ $this: GET_VAR x type=kotlin.Int operator=MULTEQ - other: LITERAL Int type=kotlin.Int value='3' + other: CONST Int type=kotlin.Int value='3' SET_VAR x type= operator=DIVEQ CALL .div type=kotlin.Int operator=DIVEQ $this: GET_VAR x type=kotlin.Int operator=DIVEQ - other: LITERAL Int type=kotlin.Int value='4' + other: CONST Int type=kotlin.Int value='4' SET_VAR x type= operator=PERCEQ CALL .mod type=kotlin.Int operator=PERCEQ $this: GET_VAR x type=kotlin.Int operator=PERCEQ - other: LITERAL Int type=kotlin.Int value='5' + other: CONST Int type=kotlin.Int value='5' IrFunction public fun testProperty(): kotlin.Unit IrExpressionBody BLOCK type=kotlin.Int hasResult=true operator=null 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' + other: CONST Int type=kotlin.Int value='1' 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' + other: CONST Int type=kotlin.Int value='2' 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' + other: CONST Int type=kotlin.Int value='3' 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' + other: CONST Int type=kotlin.Int value='4' 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' + other: CONST Int type=kotlin.Int value='5' diff --git a/compiler/testData/ir/irText/augmentedAssignment2.txt b/compiler/testData/ir/irText/augmentedAssignment2.txt index 435b4e4572b..e7803bd395c 100644 --- a/compiler/testData/ir/irText/augmentedAssignment2.txt +++ b/compiler/testData/ir/irText/augmentedAssignment2.txt @@ -25,34 +25,34 @@ IrFile /augmentedAssignment2.kt CALL . type=A operator=null CALL .plusAssign type=kotlin.Unit operator=PLUSEQ $receiver: GET_VAR a type=A operator=PLUSEQ - s: LITERAL String type=kotlin.String value='+=' + s: CONST String type=kotlin.String value='+=' CALL .minusAssign type=kotlin.Unit operator=MINUSEQ $receiver: GET_VAR a type=A operator=MINUSEQ - s: LITERAL String type=kotlin.String value='-=' + s: CONST String type=kotlin.String value='-=' CALL .timesAssign type=kotlin.Unit operator=MULTEQ $receiver: GET_VAR a type=A operator=MULTEQ - s: LITERAL String type=kotlin.String value='*=' + s: CONST String type=kotlin.String value='*=' CALL .divAssign type=kotlin.Unit operator=DIVEQ $receiver: GET_VAR a type=A operator=DIVEQ - s: LITERAL String type=kotlin.String value='/=' + s: CONST String type=kotlin.String value='/=' CALL .modAssign type=kotlin.Unit operator=PERCEQ $receiver: GET_VAR a type=A operator=PERCEQ - s: LITERAL String type=kotlin.String value='*=' + s: CONST String type=kotlin.String value='*=' IrFunction public fun testProperty(): kotlin.Unit IrExpressionBody BLOCK type= hasResult=false operator=null CALL .plusAssign type=kotlin.Unit operator=PLUSEQ $receiver: CALL . type=A operator=GET_PROPERTY - s: LITERAL String type=kotlin.String value='+=' + s: CONST String type=kotlin.String value='+=' CALL .minusAssign type=kotlin.Unit operator=MINUSEQ $receiver: CALL . type=A operator=GET_PROPERTY - s: LITERAL String type=kotlin.String value='-=' + s: CONST String type=kotlin.String value='-=' CALL .timesAssign type=kotlin.Unit operator=MULTEQ $receiver: CALL . type=A operator=GET_PROPERTY - s: LITERAL String type=kotlin.String value='*=' + s: CONST String type=kotlin.String value='*=' CALL .divAssign type=kotlin.Unit operator=DIVEQ $receiver: CALL . type=A operator=GET_PROPERTY - s: LITERAL String type=kotlin.String value='/=' + s: CONST String type=kotlin.String value='/=' CALL .modAssign type=kotlin.Unit operator=PERCEQ $receiver: CALL . type=A operator=GET_PROPERTY - s: LITERAL String type=kotlin.String value='%=' + s: CONST String type=kotlin.String value='%=' diff --git a/compiler/testData/ir/irText/booleanOperators.txt b/compiler/testData/ir/irText/booleanOperators.txt index 76c6c931650..8b59b1309ea 100644 --- a/compiler/testData/ir/irText/booleanOperators.txt +++ b/compiler/testData/ir/irText/booleanOperators.txt @@ -6,14 +6,14 @@ IrFile /booleanOperators.kt WHEN type=kotlin.Boolean operator=ANDAND if: GET_VAR a type=kotlin.Boolean operator=null then: GET_VAR b type=kotlin.Boolean operator=null - else: LITERAL Boolean type=kotlin.Boolean value='false' + else: CONST Boolean type=kotlin.Boolean value='false' IrFunction public fun test2(/*0*/ a: kotlin.Boolean, /*1*/ b: kotlin.Boolean): kotlin.Boolean IrExpressionBody BLOCK type= hasResult=false operator=null RETURN type= WHEN type=kotlin.Boolean operator=OROR if: GET_VAR a type=kotlin.Boolean operator=null - then: LITERAL Boolean type=kotlin.Boolean value='true' + then: CONST Boolean type=kotlin.Boolean value='true' else: GET_VAR b type=kotlin.Boolean operator=null IrFunction public fun test1x(/*0*/ a: kotlin.Boolean, /*1*/ b: kotlin.Boolean): kotlin.Boolean IrExpressionBody diff --git a/compiler/testData/ir/irText/boxOk.txt b/compiler/testData/ir/irText/boxOk.txt index 139014c7d1a..1182d9727d2 100644 --- a/compiler/testData/ir/irText/boxOk.txt +++ b/compiler/testData/ir/irText/boxOk.txt @@ -3,4 +3,4 @@ IrFile /boxOk.kt IrExpressionBody BLOCK type= hasResult=false operator=null RETURN type= - LITERAL String type=kotlin.String value='OK' + CONST String type=kotlin.String value='OK' diff --git a/compiler/testData/ir/irText/callWithReorderedArguments.txt b/compiler/testData/ir/irText/callWithReorderedArguments.txt index c0632554db2..c7cad7315f2 100644 --- a/compiler/testData/ir/irText/callWithReorderedArguments.txt +++ b/compiler/testData/ir/irText/callWithReorderedArguments.txt @@ -6,22 +6,22 @@ IrFile /callWithReorderedArguments.kt IrExpressionBody BLOCK type= hasResult=false operator=null RETURN type= - LITERAL Int type=kotlin.Int value='1' + CONST Int type=kotlin.Int value='1' IrFunction public fun noReorder2(): kotlin.Int IrExpressionBody BLOCK type= hasResult=false operator=null RETURN type= - LITERAL Int type=kotlin.Int value='2' + CONST Int type=kotlin.Int value='2' IrFunction public fun reordered1(): kotlin.Int IrExpressionBody BLOCK type= hasResult=false operator=null RETURN type= - LITERAL Int type=kotlin.Int value='1' + CONST Int type=kotlin.Int value='1' IrFunction public fun reordered2(): kotlin.Int IrExpressionBody BLOCK type= hasResult=false operator=null RETURN type= - LITERAL Int type=kotlin.Int value='2' + CONST Int type=kotlin.Int value='2' IrFunction public fun test(): kotlin.Unit IrExpressionBody BLOCK type= hasResult=false operator=null @@ -41,4 +41,4 @@ IrFile /callWithReorderedArguments.kt CALL .reordered2 type=kotlin.Int operator=null CALL .foo type=kotlin.Unit operator=null a: GET_VAR tmp2_a type=kotlin.Int operator=null - b: LITERAL Int type=kotlin.Int value='1' + b: CONST Int type=kotlin.Int value='1' diff --git a/compiler/testData/ir/irText/calls.txt b/compiler/testData/ir/irText/calls.txt index 7fe3b4f58cd..34f7da84e07 100644 --- a/compiler/testData/ir/irText/calls.txt +++ b/compiler/testData/ir/irText/calls.txt @@ -10,7 +10,7 @@ IrFile /calls.kt RETURN type= CALL .foo type=kotlin.Int operator=null x: GET_VAR x type=kotlin.Int operator=null - y: LITERAL Int type=kotlin.Int value='1' + y: CONST Int type=kotlin.Int value='1' IrFunction public fun qux(/*0*/ x: kotlin.Int): kotlin.Int IrExpressionBody BLOCK type= hasResult=false operator=null diff --git a/compiler/testData/ir/irText/elvis.kt b/compiler/testData/ir/irText/elvis.kt index 90ad805d735..9531b0d86c7 100644 --- a/compiler/testData/ir/irText/elvis.kt +++ b/compiler/testData/ir/irText/elvis.kt @@ -1,8 +1,17 @@ +val p: Any? = null + +fun foo(): Any? = null + fun test1(a: Any?, b: Any) = a ?: b + fun test2(a: String?, b: Any) = a ?: b fun test3(a: Any?, b: Any?): String { if (b !is String) return "" if (a !is String?) return "" return a ?: b -} \ No newline at end of file +} + +fun test4(x: Any) = p ?: x + +fun test5(x: Any) = foo() ?: x \ No newline at end of file diff --git a/compiler/testData/ir/irText/elvis.txt b/compiler/testData/ir/irText/elvis.txt index 82e26336210..e6a81952180 100644 --- a/compiler/testData/ir/irText/elvis.txt +++ b/compiler/testData/ir/irText/elvis.txt @@ -1,14 +1,32 @@ IrFile /elvis.kt + IrProperty public val p: kotlin.Any? = null getter=null setter=null + IrExpressionBody + CONST Null type=kotlin.Nothing? value='null' + IrFunction public fun foo(): kotlin.Any? + IrExpressionBody + BLOCK type= hasResult=false operator=null + RETURN type= + CONST Null type=kotlin.Nothing? value='null' IrFunction public fun test1(/*0*/ a: kotlin.Any?, /*1*/ b: kotlin.Any): kotlin.Any IrExpressionBody BLOCK type= hasResult=false operator=null RETURN type= - DUMMY elvis type=kotlin.Any + WHEN type=kotlin.Any operator=ELVIS + if: CALL .EQEQ type=kotlin.Boolean operator=ELVIS + arg0: GET_VAR a type=kotlin.Any? operator=null + arg1: CONST Null type=kotlin.Nothing? value='null' + then: GET_VAR b type=kotlin.Any operator=null + else: GET_VAR a type=kotlin.Any? operator=null IrFunction public fun test2(/*0*/ a: kotlin.String?, /*1*/ b: kotlin.Any): kotlin.Any IrExpressionBody BLOCK type= hasResult=false operator=null RETURN type= - DUMMY elvis type=kotlin.Any + WHEN type=kotlin.Any operator=ELVIS + if: CALL .EQEQ type=kotlin.Boolean operator=ELVIS + arg0: GET_VAR a type=kotlin.String? operator=null + arg1: CONST Null type=kotlin.Nothing? value='null' + then: GET_VAR b type=kotlin.Any operator=null + else: GET_VAR a type=kotlin.String? operator=null IrFunction public fun test3(/*0*/ a: kotlin.Any?, /*1*/ b: kotlin.Any?): kotlin.String IrExpressionBody BLOCK type= hasResult=false operator=null @@ -16,11 +34,47 @@ IrFile /elvis.kt if: TYPE_OP operator=NOT_INSTANCEOF typeOperand=kotlin.String GET_VAR b type=kotlin.Any? operator=null then: RETURN type= - LITERAL String type=kotlin.String value='' + CONST String type=kotlin.String value='' WHEN type=kotlin.Unit operator=IF if: TYPE_OP operator=NOT_INSTANCEOF typeOperand=kotlin.String? GET_VAR a type=kotlin.Any? operator=null then: RETURN type= - LITERAL String type=kotlin.String value='' + CONST String type=kotlin.String value='' RETURN type= - DUMMY elvis type=kotlin.String + BLOCK type=kotlin.String hasResult=true operator=ELVIS + VAR val tmp0: kotlin.String? + TYPE_OP operator=IMPLICIT_CAST typeOperand=kotlin.String? + GET_VAR a type=kotlin.Any? operator=null + WHEN type=kotlin.String operator=ELVIS + if: CALL .EQEQ type=kotlin.Boolean operator=ELVIS + arg0: GET_VAR tmp0 type=kotlin.String? operator=null + arg1: CONST Null type=kotlin.Nothing? value='null' + then: TYPE_OP operator=IMPLICIT_CAST typeOperand=kotlin.String + GET_VAR b type=kotlin.Any? operator=null + else: GET_VAR tmp0 type=kotlin.String? operator=null + IrFunction public fun test4(/*0*/ x: kotlin.Any): kotlin.Any + IrExpressionBody + BLOCK type= hasResult=false operator=null + RETURN type= + BLOCK type=kotlin.Any hasResult=true operator=ELVIS + VAR val tmp0: kotlin.Any? + CALL . type=kotlin.Any? operator=GET_PROPERTY + WHEN type=kotlin.Any operator=ELVIS + if: CALL .EQEQ type=kotlin.Boolean operator=ELVIS + arg0: GET_VAR tmp0 type=kotlin.Any? operator=null + arg1: CONST Null type=kotlin.Nothing? value='null' + then: GET_VAR x type=kotlin.Any operator=null + else: GET_VAR tmp0 type=kotlin.Any? operator=null + IrFunction public fun test5(/*0*/ x: kotlin.Any): kotlin.Any + IrExpressionBody + BLOCK type= hasResult=false operator=null + RETURN type= + BLOCK type=kotlin.Any hasResult=true operator=ELVIS + VAR val tmp0: kotlin.Any? + CALL .foo type=kotlin.Any? operator=null + WHEN type=kotlin.Any operator=ELVIS + if: CALL .EQEQ type=kotlin.Boolean operator=ELVIS + arg0: GET_VAR tmp0 type=kotlin.Any? operator=null + arg1: CONST Null type=kotlin.Nothing? value='null' + then: GET_VAR x type=kotlin.Any operator=null + else: GET_VAR tmp0 type=kotlin.Any? operator=null diff --git a/compiler/testData/ir/irText/extensionPropertyGetterCall.txt b/compiler/testData/ir/irText/extensionPropertyGetterCall.txt index ccd0518ad0d..18d3a8bf0f5 100644 --- a/compiler/testData/ir/irText/extensionPropertyGetterCall.txt +++ b/compiler/testData/ir/irText/extensionPropertyGetterCall.txt @@ -4,7 +4,7 @@ IrFile /extensionPropertyGetterCall.kt IrExpressionBody BLOCK type= hasResult=false operator=null RETURN type= - LITERAL String type=kotlin.String value='OK' + CONST String type=kotlin.String value='OK' IrFunction public fun kotlin.String.test5(): kotlin.String IrExpressionBody BLOCK type= hasResult=false operator=null diff --git a/compiler/testData/ir/irText/ifElseIf.txt b/compiler/testData/ir/irText/ifElseIf.txt index 96275adff19..22f319172a5 100644 --- a/compiler/testData/ir/irText/ifElseIf.txt +++ b/compiler/testData/ir/irText/ifElseIf.txt @@ -7,11 +7,12 @@ IrFile /ifElseIf.kt if: CALL .GT0 type=kotlin.Boolean operator=GT arg0: CALL .compareTo type=kotlin.Int operator=GT $this: GET_VAR i type=kotlin.Int operator=null - other: LITERAL Int type=kotlin.Int value='0' - then: LITERAL Int type=kotlin.Int value='1' - if: CALL .GT0 type=kotlin.Boolean operator=GT - arg0: CALL .compareTo type=kotlin.Int operator=GT + other: CONST Int type=kotlin.Int value='0' + then: CONST Int type=kotlin.Int value='1' + if: CALL .LT0 type=kotlin.Boolean operator=LT + arg0: CALL .compareTo type=kotlin.Int operator=LT $this: GET_VAR i type=kotlin.Int operator=null - other: LITERAL Int type=kotlin.Int value='0' - then: LITERAL Int type=kotlin.Int value='1' - else: LITERAL Int type=kotlin.Int value='0' + other: CONST Int type=kotlin.Int value='0' + then: CALL .unaryMinus type=kotlin.Int operator=UMINUS + $this: CONST Int type=kotlin.Int value='1' + else: CONST Int type=kotlin.Int value='0' diff --git a/compiler/testData/ir/irText/implicitCastOnPlatformType.txt b/compiler/testData/ir/irText/implicitCastOnPlatformType.txt index 3699eaa09a8..281b8aec90e 100644 --- a/compiler/testData/ir/irText/implicitCastOnPlatformType.txt +++ b/compiler/testData/ir/irText/implicitCastOnPlatformType.txt @@ -3,6 +3,13 @@ IrFile /implicitCastOnPlatformType.kt IrExpressionBody BLOCK type= hasResult=false operator=null RETURN type= - CALL .IMPLICIT_NOT_NULL type=kotlin.Any operator=IMPLICIT_NOTNULL - arg0: CALL .getProperty type=kotlin.String! operator=null - p0: LITERAL String type=kotlin.String value='test' + BLOCK type=kotlin.String hasResult=true operator=IMPLICIT_NOTNULL + VAR val tmp0: kotlin.String! + CALL .getProperty type=kotlin.String! operator=null + p0: CONST String type=kotlin.String value='test' + WHEN type=kotlin.String operator=IMPLICIT_NOTNULL + if: CALL .EQEQ type=kotlin.Boolean operator=IMPLICIT_NOTNULL + arg0: GET_VAR tmp0 type=kotlin.String! operator=null + arg1: CONST Null type=kotlin.Nothing? value='null' + then: CALL .THROW_NPE type=kotlin.Nothing operator=IMPLICIT_NOTNULL + else: GET_VAR tmp0 type=kotlin.String! operator=null diff --git a/compiler/testData/ir/irText/incrementDecrement.kt b/compiler/testData/ir/irText/incrementDecrement.kt index 8f599f2a348..22e719f8d61 100644 --- a/compiler/testData/ir/irText/incrementDecrement.kt +++ b/compiler/testData/ir/irText/incrementDecrement.kt @@ -1,18 +1,34 @@ var p: Int = 0 val arr = intArrayOf(1, 2, 3) -fun testVar() { +fun testVarPrefix() { var x = 0 val x1 = ++x val x2 = --x } -fun testProp() { +fun testVarPostfix() { + var x = 0 + val x1 = x++ + val x2 = x-- +} + +fun testPropPrefix() { val p1 = ++p val p2 = --p } -fun testArray() { +fun testPropPostfix() { + val p1 = p++ + val p2 = --p +} + +fun testArrayPrefix() { val a1 = ++arr[0] val a2 = --arr[0] +} + +fun testArrayPostfix() { + val a1 = arr[0]++ + val a2 = arr[0]-- } \ No newline at end of file diff --git a/compiler/testData/ir/irText/incrementDecrement.txt b/compiler/testData/ir/irText/incrementDecrement.txt index 5b2e42fd9a0..c5bc4df73b4 100644 --- a/compiler/testData/ir/irText/incrementDecrement.txt +++ b/compiler/testData/ir/irText/incrementDecrement.txt @@ -1,16 +1,16 @@ IrFile /incrementDecrement.kt IrProperty public var p: kotlin.Int getter=null setter=null IrExpressionBody - LITERAL Int type=kotlin.Int value='0' + CONST Int type=kotlin.Int value='0' IrProperty public val arr: kotlin.IntArray getter=null setter=null IrExpressionBody CALL .intArrayOf type=kotlin.IntArray operator=null elements: DUMMY vararg type=kotlin.Int - IrFunction public fun testVar(): kotlin.Unit + IrFunction public fun testVarPrefix(): kotlin.Unit IrExpressionBody BLOCK type= hasResult=false operator=null VAR var x: kotlin.Int - LITERAL Int type=kotlin.Int value='0' + CONST Int type=kotlin.Int value='0' VAR val x1: kotlin.Int BLOCK type=kotlin.Int hasResult=true operator=PREFIX_INCR VAR val tmp0: kotlin.Int @@ -27,7 +27,28 @@ IrFile /incrementDecrement.kt SET_VAR x type= operator=PREFIX_DECR GET_VAR tmp1 type=kotlin.Int operator=null GET_VAR tmp1 type=kotlin.Int operator=null - IrFunction public fun testProp(): kotlin.Unit + IrFunction public fun testVarPostfix(): kotlin.Unit + IrExpressionBody + BLOCK type= hasResult=false operator=null + VAR var x: kotlin.Int + CONST Int type=kotlin.Int value='0' + VAR val x1: kotlin.Int + BLOCK type=kotlin.Int hasResult=true operator=POSTFIX_INCR + VAR val tmp0: kotlin.Int + GET_VAR x type=kotlin.Int operator=POSTFIX_INCR + SET_VAR x type= operator=POSTFIX_INCR + CALL .inc type=kotlin.Int operator=POSTFIX_INCR + $this: GET_VAR tmp0 type=kotlin.Int operator=POSTFIX_INCR + GET_VAR tmp0 type=kotlin.Int operator=null + VAR val x2: kotlin.Int + BLOCK type=kotlin.Int hasResult=true operator=POSTFIX_DECR + VAR val tmp1: kotlin.Int + GET_VAR x type=kotlin.Int operator=POSTFIX_DECR + SET_VAR x type= operator=POSTFIX_DECR + CALL .dec type=kotlin.Int operator=POSTFIX_DECR + $this: GET_VAR tmp1 type=kotlin.Int operator=POSTFIX_DECR + GET_VAR tmp1 type=kotlin.Int operator=null + IrFunction public fun testPropPrefix(): kotlin.Unit IrExpressionBody BLOCK type= hasResult=false operator=null VAR val p1: kotlin.Int @@ -46,7 +67,26 @@ IrFile /incrementDecrement.kt 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 + IrFunction public fun testPropPostfix(): kotlin.Unit + IrExpressionBody + BLOCK type= hasResult=false operator=null + VAR val p1: kotlin.Int + BLOCK type=kotlin.Int hasResult=true operator=POSTFIX_INCR + VAR val tmp0: kotlin.Int + CALL . type=kotlin.Int operator=GET_PROPERTY + CALL . type=kotlin.Unit operator=POSTFIX_INCR + : CALL .inc type=kotlin.Int operator=POSTFIX_INCR + $this: GET_VAR tmp0 type=kotlin.Int operator=POSTFIX_INCR + 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: 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 testArrayPrefix(): kotlin.Unit IrExpressionBody BLOCK type= hasResult=false operator=null VAR val a1: kotlin.Int @@ -57,10 +97,10 @@ IrFile /incrementDecrement.kt CALL .inc type=kotlin.Int operator=PREFIX_INCR $this: CALL .get type=kotlin.Int operator=PREFIX_INCR $this: GET_VAR tmp0_array type=kotlin.IntArray operator=null - index: LITERAL Int type=kotlin.Int value='0' + index: CONST Int type=kotlin.Int value='0' CALL .set type=kotlin.Unit operator=PREFIX_INCR $this: GET_VAR tmp0_array type=kotlin.IntArray operator=null - index: LITERAL Int type=kotlin.Int value='0' + index: CONST Int type=kotlin.Int value='0' value: GET_VAR tmp1 type=kotlin.Int operator=null GET_VAR tmp1 type=kotlin.Int operator=null VAR val a2: kotlin.Int @@ -71,9 +111,40 @@ IrFile /incrementDecrement.kt CALL .dec type=kotlin.Int operator=PREFIX_DECR $this: CALL .get type=kotlin.Int operator=PREFIX_DECR $this: GET_VAR tmp2_array type=kotlin.IntArray operator=null - index: LITERAL Int type=kotlin.Int value='0' + index: CONST Int type=kotlin.Int value='0' CALL .set type=kotlin.Unit operator=PREFIX_DECR $this: GET_VAR tmp2_array type=kotlin.IntArray operator=null - index: LITERAL Int type=kotlin.Int value='0' + index: CONST Int type=kotlin.Int value='0' value: GET_VAR tmp3 type=kotlin.Int operator=null GET_VAR tmp3 type=kotlin.Int operator=null + IrFunction public fun testArrayPostfix(): kotlin.Unit + IrExpressionBody + BLOCK type= hasResult=false operator=null + VAR val a1: kotlin.Int + BLOCK type=kotlin.Int hasResult=true operator=POSTFIX_INCR + VAR val tmp0_array: kotlin.IntArray + CALL . type=kotlin.IntArray operator=GET_PROPERTY + VAR val tmp1: kotlin.Int + CALL .get type=kotlin.Int operator=POSTFIX_INCR + $this: GET_VAR tmp0_array type=kotlin.IntArray operator=null + index: CONST Int type=kotlin.Int value='0' + CALL .set type=kotlin.Unit operator=POSTFIX_INCR + $this: GET_VAR tmp0_array type=kotlin.IntArray operator=null + index: CONST Int type=kotlin.Int value='0' + value: CALL .inc type=kotlin.Int operator=POSTFIX_INCR + $this: GET_VAR tmp1 type=kotlin.Int operator=null + GET_VAR tmp1 type=kotlin.Int operator=null + VAR val a2: kotlin.Int + BLOCK type=kotlin.Int hasResult=true operator=POSTFIX_DECR + VAR val tmp2_array: kotlin.IntArray + CALL . type=kotlin.IntArray operator=GET_PROPERTY + VAR val tmp3: kotlin.Int + CALL .get type=kotlin.Int operator=POSTFIX_DECR + $this: GET_VAR tmp2_array type=kotlin.IntArray operator=null + index: CONST Int type=kotlin.Int value='0' + CALL .set type=kotlin.Unit operator=POSTFIX_DECR + $this: GET_VAR tmp2_array type=kotlin.IntArray operator=null + index: CONST Int type=kotlin.Int value='0' + value: CALL .dec type=kotlin.Int operator=POSTFIX_DECR + $this: GET_VAR tmp3 type=kotlin.Int operator=null + GET_VAR tmp3 type=kotlin.Int operator=null diff --git a/compiler/testData/ir/irText/literals.kt b/compiler/testData/ir/irText/literals.kt new file mode 100644 index 00000000000..be88ac88d0d --- /dev/null +++ b/compiler/testData/ir/irText/literals.kt @@ -0,0 +1,6 @@ +val test1 = 1 +val test2 = -1 +val test3 = true +val test4 = false +val test5 = "abc" +val test6 = null \ No newline at end of file diff --git a/compiler/testData/ir/irText/literals.txt b/compiler/testData/ir/irText/literals.txt new file mode 100644 index 00000000000..c7fb2cca720 --- /dev/null +++ b/compiler/testData/ir/irText/literals.txt @@ -0,0 +1,20 @@ +IrFile /literals.kt + IrProperty public val test1: kotlin.Int = 1 getter=null setter=null + IrExpressionBody + CONST Int type=kotlin.Int value='1' + IrProperty public val test2: kotlin.Int = -1 getter=null setter=null + IrExpressionBody + CALL .unaryMinus type=kotlin.Int operator=UMINUS + $this: CONST Int type=kotlin.Int value='1' + IrProperty public val test3: kotlin.Boolean = true getter=null setter=null + IrExpressionBody + CONST Boolean type=kotlin.Boolean value='true' + IrProperty public val test4: kotlin.Boolean = false getter=null setter=null + IrExpressionBody + CONST Boolean type=kotlin.Boolean value='false' + IrProperty public val test5: kotlin.String = "abc" getter=null setter=null + IrExpressionBody + CONST String type=kotlin.String value='abc' + IrProperty public val test6: kotlin.Nothing? = null getter=null setter=null + IrExpressionBody + CONST Null type=kotlin.Nothing? value='null' diff --git a/compiler/testData/ir/irText/references.txt b/compiler/testData/ir/irText/references.txt index 26ad5e17b95..1a24de9a367 100644 --- a/compiler/testData/ir/irText/references.txt +++ b/compiler/testData/ir/irText/references.txt @@ -1,7 +1,7 @@ IrFile /references.kt IrProperty public val ok: kotlin.String = "OK" getter=null setter=null IrExpressionBody - LITERAL String type=kotlin.String value='OK' + CONST String type=kotlin.String value='OK' IrProperty public val ok2: kotlin.String = "OK" getter=null setter=null IrExpressionBody CALL . type=kotlin.String operator=GET_PROPERTY @@ -10,7 +10,7 @@ IrFile /references.kt IrExpressionBody BLOCK type= hasResult=false operator=null RETURN type= - LITERAL String type=kotlin.String value='OK' + CONST String type=kotlin.String value='OK' IrFunction public fun test1(): kotlin.String IrExpressionBody BLOCK type= hasResult=false operator=null @@ -25,7 +25,7 @@ IrFile /references.kt IrExpressionBody BLOCK type= hasResult=false operator=null VAR val x: kotlin.String = "OK" - LITERAL String type=kotlin.String value='OK' + CONST String type=kotlin.String value='OK' RETURN type= GET_VAR x type=kotlin.String operator=null IrFunction public fun test4(): kotlin.String @@ -38,7 +38,7 @@ IrFile /references.kt IrExpressionBody BLOCK type= hasResult=false operator=null RETURN type= - LITERAL String type=kotlin.String value='OK' + CONST String type=kotlin.String value='OK' IrFunction public fun kotlin.String.test5(): kotlin.String IrExpressionBody BLOCK type= hasResult=false operator=null diff --git a/compiler/testData/ir/irText/simpleUnaryOperators.kt b/compiler/testData/ir/irText/simpleUnaryOperators.kt new file mode 100644 index 00000000000..6b8127f57a4 --- /dev/null +++ b/compiler/testData/ir/irText/simpleUnaryOperators.kt @@ -0,0 +1,8 @@ +fun test1(x: Int) = -x +fun test2() = -42 + +fun test3(x: Int) = +x +fun test4() = +42 + +fun test5(x: Boolean) = !x +fun test6() = !true \ No newline at end of file diff --git a/compiler/testData/ir/irText/simpleUnaryOperators.txt b/compiler/testData/ir/irText/simpleUnaryOperators.txt new file mode 100644 index 00000000000..14cb53d7b60 --- /dev/null +++ b/compiler/testData/ir/irText/simpleUnaryOperators.txt @@ -0,0 +1,37 @@ +IrFile /simpleUnaryOperators.kt + IrFunction public fun test1(/*0*/ x: kotlin.Int): kotlin.Int + IrExpressionBody + BLOCK type= hasResult=false operator=null + RETURN type= + CALL .unaryMinus type=kotlin.Int operator=UMINUS + $this: GET_VAR x type=kotlin.Int operator=null + IrFunction public fun test2(): kotlin.Int + IrExpressionBody + BLOCK type= hasResult=false operator=null + RETURN type= + CALL .unaryMinus type=kotlin.Int operator=UMINUS + $this: CONST Int type=kotlin.Int value='42' + IrFunction public fun test3(/*0*/ x: kotlin.Int): kotlin.Int + IrExpressionBody + BLOCK type= hasResult=false operator=null + RETURN type= + CALL .unaryPlus type=kotlin.Int operator=UPLUS + $this: GET_VAR x type=kotlin.Int operator=null + IrFunction public fun test4(): kotlin.Int + IrExpressionBody + BLOCK type= hasResult=false operator=null + RETURN type= + CALL .unaryPlus type=kotlin.Int operator=UPLUS + $this: CONST Int type=kotlin.Int value='42' + IrFunction public fun test5(/*0*/ x: kotlin.Boolean): kotlin.Boolean + IrExpressionBody + BLOCK type= hasResult=false operator=null + RETURN type= + CALL .not type=kotlin.Boolean operator=EXCL + $this: GET_VAR x type=kotlin.Boolean operator=null + IrFunction public fun test6(): kotlin.Boolean + IrExpressionBody + BLOCK type= hasResult=false operator=null + RETURN type= + CALL .not type=kotlin.Boolean operator=EXCL + $this: CONST Boolean type=kotlin.Boolean value='true' diff --git a/compiler/testData/ir/irText/smartCasts.txt b/compiler/testData/ir/irText/smartCasts.txt index ef96aa06466..45ba5940157 100644 --- a/compiler/testData/ir/irText/smartCasts.txt +++ b/compiler/testData/ir/irText/smartCasts.txt @@ -44,7 +44,7 @@ IrFile /smartCasts.kt if: TYPE_OP operator=NOT_INSTANCEOF typeOperand=kotlin.String GET_VAR x type=kotlin.Any operator=null then: RETURN type= - LITERAL String type=kotlin.String value='' + CONST String type=kotlin.String value='' RETURN type= CALL .overloaded type=kotlin.String operator=null s: TYPE_OP operator=IMPLICIT_CAST typeOperand=kotlin.String @@ -56,7 +56,7 @@ IrFile /smartCasts.kt if: TYPE_OP operator=NOT_INSTANCEOF typeOperand=kotlin.String GET_VAR x type=kotlin.Any operator=null then: RETURN type= - LITERAL String type=kotlin.String value='' + CONST String type=kotlin.String value='' RETURN type= TYPE_OP operator=IMPLICIT_CAST typeOperand=kotlin.String GET_VAR x type=kotlin.Any operator=null diff --git a/compiler/testData/ir/irText/smartCastsWithDestructuring.txt b/compiler/testData/ir/irText/smartCastsWithDestructuring.txt index d5ad9930b2d..06393ca2a95 100644 --- a/compiler/testData/ir/irText/smartCastsWithDestructuring.txt +++ b/compiler/testData/ir/irText/smartCastsWithDestructuring.txt @@ -5,12 +5,12 @@ IrFile /smartCastsWithDestructuring.kt IrExpressionBody BLOCK type= hasResult=false operator=null RETURN type= - LITERAL Int type=kotlin.Int value='1' + CONST Int type=kotlin.Int value='1' IrFunction public operator fun I2.component2(): kotlin.String IrExpressionBody BLOCK type= hasResult=false operator=null RETURN type= - LITERAL String type=kotlin.String value='' + CONST String type=kotlin.String value='' IrFunction public fun test(/*0*/ x: I1): kotlin.Unit IrExpressionBody BLOCK type= hasResult=false operator=null diff --git a/compiler/testData/ir/irText/smoke.txt b/compiler/testData/ir/irText/smoke.txt index fc73a31db8a..dd94191b4a5 100644 --- a/compiler/testData/ir/irText/smoke.txt +++ b/compiler/testData/ir/irText/smoke.txt @@ -3,25 +3,25 @@ IrFile /smoke.kt IrExpressionBody BLOCK type= hasResult=false operator=null RETURN type= - LITERAL String type=kotlin.String value='OK' + CONST String type=kotlin.String value='OK' IrProperty public val testSimpleVal: kotlin.Int = 1 getter=null setter=null IrExpressionBody - LITERAL Int type=kotlin.Int value='1' + CONST Int type=kotlin.Int value='1' IrProperty public val testValWithGetter: kotlin.Int getter= setter=null IrPropertyGetter public fun (): kotlin.Int property=testValWithGetter IrExpressionBody BLOCK type= hasResult=false operator=null RETURN type= - LITERAL Int type=kotlin.Int value='42' + CONST Int type=kotlin.Int value='42' IrProperty public var testSimpleVar: kotlin.Int getter=null setter=null IrExpressionBody - LITERAL Int type=kotlin.Int value='2' + CONST Int type=kotlin.Int value='2' IrProperty public var testVarWithAccessors: kotlin.Int getter= setter= IrPropertyGetter public fun (): kotlin.Int property=testVarWithAccessors IrExpressionBody BLOCK type= hasResult=false operator=null RETURN type= - LITERAL Int type=kotlin.Int value='42' + CONST Int type=kotlin.Int value='42' IrPropertySetter public fun (/*0*/ v: kotlin.Int): kotlin.Unit property=testVarWithAccessors IrExpressionBody BLOCK type= hasResult=false operator=null diff --git a/compiler/testData/ir/irText/stringPlus.txt b/compiler/testData/ir/irText/stringPlus.txt index 6cb6a15007b..527c9084ce8 100644 --- a/compiler/testData/ir/irText/stringPlus.txt +++ b/compiler/testData/ir/irText/stringPlus.txt @@ -12,7 +12,7 @@ IrFile /stringPlus.kt RETURN type= STRING_CONCATENATION type=kotlin.String GET_VAR a type=kotlin.String operator=null - LITERAL String type=kotlin.String value='+' + CONST String type=kotlin.String value='+' GET_VAR b type=kotlin.Int operator=null IrFunction public fun test3(/*0*/ a: kotlin.String, /*1*/ b: kotlin.Int): kotlin.String IrExpressionBody @@ -20,8 +20,8 @@ IrFile /stringPlus.kt RETURN type= STRING_CONCATENATION type=kotlin.String GET_VAR a type=kotlin.String operator=null - LITERAL String type=kotlin.String value='+' + CONST String type=kotlin.String value='+' CALL .plus type=kotlin.Int operator=PLUS $this: GET_VAR b type=kotlin.Int operator=null - other: LITERAL Int type=kotlin.Int value='1' + other: CONST Int type=kotlin.Int value='1' GET_VAR a type=kotlin.String operator=null diff --git a/compiler/testData/ir/irText/values.txt b/compiler/testData/ir/irText/values.txt index bf14da34f5d..583d7945697 100644 --- a/compiler/testData/ir/irText/values.txt +++ b/compiler/testData/ir/irText/values.txt @@ -3,7 +3,7 @@ IrFile /values.kt DUMMY A IrProperty public val a: kotlin.Int = 0 getter=null setter=null IrExpressionBody - LITERAL Int type=kotlin.Int value='0' + CONST Int type=kotlin.Int value='0' DUMMY Z IrFunction public fun test1(): Enum IrExpressionBody diff --git a/compiler/testData/ir/irText/when.txt b/compiler/testData/ir/irText/when.txt index a824c5f84e3..8a95603868e 100644 --- a/compiler/testData/ir/irText/when.txt +++ b/compiler/testData/ir/irText/when.txt @@ -10,21 +10,21 @@ IrFile /when.kt WHEN type=kotlin.String operator=WHEN if: CALL .EQEQ type=kotlin.Boolean operator=EQEQ arg0: GET_VAR tmp0_subject type=kotlin.Any? operator=null - arg1: LITERAL Null type=kotlin.Nothing? value='null' - then: LITERAL String type=kotlin.String value='null' + arg1: CONST Null type=kotlin.Nothing? value='null' + then: CONST String type=kotlin.String value='null' if: CALL .EQEQ type=kotlin.Boolean operator=EQEQ arg0: GET_VAR tmp0_subject type=kotlin.Any? operator=null arg1: GET_OBJECT A type=A - then: LITERAL String type=kotlin.String value='A' + then: CONST String type=kotlin.String value='A' if: TYPE_OP operator=INSTANCEOF typeOperand=kotlin.String GET_VAR tmp0_subject type=kotlin.Any? operator=null - then: LITERAL String type=kotlin.String value='String' + then: CONST String type=kotlin.String value='String' if: CALL .contains type=kotlin.Boolean operator=IN $receiver: CALL .setOf type=kotlin.collections.Set operator=null element: TYPE_OP operator=IMPLICIT_CAST typeOperand=kotlin.Any GET_VAR tmp0_subject type=kotlin.Any? operator=null - then: LITERAL String type=kotlin.String value='nothingness?' - else: LITERAL String type=kotlin.String value='something' + then: CONST String type=kotlin.String value='nothingness?' + else: CONST String type=kotlin.String value='something' IrFunction public fun test(/*0*/ x: kotlin.Any?): kotlin.String IrExpressionBody BLOCK type= hasResult=false operator=null @@ -32,21 +32,21 @@ IrFile /when.kt WHEN type=kotlin.String operator=WHEN if: CALL .EQEQ type=kotlin.Boolean operator=EQEQ arg0: GET_VAR x type=kotlin.Any? operator=null - arg1: LITERAL Null type=kotlin.Nothing? value='null' - then: LITERAL String type=kotlin.String value='null' + arg1: CONST Null type=kotlin.Nothing? value='null' + then: CONST String type=kotlin.String value='null' if: CALL .EQEQ type=kotlin.Boolean operator=EQEQ arg0: GET_VAR x type=kotlin.Any? operator=null arg1: GET_OBJECT A type=A - then: LITERAL String type=kotlin.String value='A' + then: CONST String type=kotlin.String value='A' if: TYPE_OP operator=INSTANCEOF typeOperand=kotlin.String GET_VAR x type=kotlin.Any? operator=null - then: LITERAL String type=kotlin.String value='String' + then: CONST String type=kotlin.String value='String' if: CALL .contains type=kotlin.Boolean operator=IN $receiver: CALL .setOf type=kotlin.collections.Set operator=null element: TYPE_OP operator=IMPLICIT_CAST typeOperand=kotlin.Any GET_VAR x type=kotlin.Any? operator=null - then: LITERAL String type=kotlin.String value='nothingness?' - else: LITERAL String type=kotlin.String value='something' + then: CONST String type=kotlin.String value='nothingness?' + else: CONST String type=kotlin.String value='something' IrFunction public fun testComma(/*0*/ x: kotlin.Int): kotlin.String IrExpressionBody BLOCK type= hasResult=false operator=null @@ -60,41 +60,41 @@ IrFile /when.kt if: WHEN type=kotlin.Boolean operator=WHEN_COMMA if: CALL .EQEQ type=kotlin.Boolean operator=EQEQ arg0: GET_VAR tmp0_subject type=kotlin.Int operator=null - arg1: LITERAL Int type=kotlin.Int value='1' - then: LITERAL Boolean type=kotlin.Boolean value='true' + arg1: CONST Int type=kotlin.Int value='1' + then: CONST Boolean type=kotlin.Boolean value='true' else: CALL .EQEQ type=kotlin.Boolean operator=EQEQ arg0: GET_VAR tmp0_subject type=kotlin.Int operator=null - arg1: LITERAL Int type=kotlin.Int value='2' - then: LITERAL Boolean type=kotlin.Boolean value='true' + arg1: CONST Int type=kotlin.Int value='2' + then: CONST Boolean type=kotlin.Boolean value='true' else: CALL .EQEQ type=kotlin.Boolean operator=EQEQ arg0: GET_VAR tmp0_subject type=kotlin.Int operator=null - arg1: LITERAL Int type=kotlin.Int value='3' - then: LITERAL Boolean type=kotlin.Boolean value='true' + arg1: CONST Int type=kotlin.Int value='3' + then: CONST Boolean type=kotlin.Boolean value='true' else: CALL .EQEQ type=kotlin.Boolean operator=EQEQ arg0: GET_VAR tmp0_subject type=kotlin.Int operator=null - arg1: LITERAL Int type=kotlin.Int value='4' - then: LITERAL String type=kotlin.String value='1234' + arg1: CONST Int type=kotlin.Int value='4' + then: CONST String type=kotlin.String value='1234' if: WHEN type=kotlin.Boolean operator=WHEN_COMMA if: WHEN type=kotlin.Boolean operator=WHEN_COMMA if: CALL .EQEQ type=kotlin.Boolean operator=EQEQ arg0: GET_VAR tmp0_subject type=kotlin.Int operator=null - arg1: LITERAL Int type=kotlin.Int value='5' - then: LITERAL Boolean type=kotlin.Boolean value='true' + arg1: CONST Int type=kotlin.Int value='5' + then: CONST Boolean type=kotlin.Boolean value='true' else: CALL .EQEQ type=kotlin.Boolean operator=EQEQ arg0: GET_VAR tmp0_subject type=kotlin.Int operator=null - arg1: LITERAL Int type=kotlin.Int value='6' - then: LITERAL Boolean type=kotlin.Boolean value='true' + arg1: CONST Int type=kotlin.Int value='6' + then: CONST Boolean type=kotlin.Boolean value='true' else: CALL .EQEQ type=kotlin.Boolean operator=EQEQ arg0: GET_VAR tmp0_subject type=kotlin.Int operator=null - arg1: LITERAL Int type=kotlin.Int value='7' - then: LITERAL String type=kotlin.String value='567' + arg1: CONST Int type=kotlin.Int value='7' + then: CONST String type=kotlin.String value='567' if: WHEN type=kotlin.Boolean operator=WHEN_COMMA if: CALL .EQEQ type=kotlin.Boolean operator=EQEQ arg0: GET_VAR tmp0_subject type=kotlin.Int operator=null - arg1: LITERAL Int type=kotlin.Int value='8' - then: LITERAL Boolean type=kotlin.Boolean value='true' + arg1: CONST Int type=kotlin.Int value='8' + then: CONST Boolean type=kotlin.Boolean value='true' else: CALL .EQEQ type=kotlin.Boolean operator=EQEQ arg0: GET_VAR tmp0_subject type=kotlin.Int operator=null - arg1: LITERAL Int type=kotlin.Int value='9' - then: LITERAL String type=kotlin.String value='89' - else: LITERAL String type=kotlin.String value='?' + arg1: CONST Int type=kotlin.Int value='9' + then: CONST String type=kotlin.String value='89' + else: CONST String type=kotlin.String value='?' diff --git a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java index 65bcbdc96bf..a887f25d57b 100644 --- a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java @@ -161,6 +161,12 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase { doTest(fileName); } + @TestMetadata("literals.kt") + public void testLiterals() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/literals.kt"); + doTest(fileName); + } + @TestMetadata("primitiveComparisons.kt") public void testPrimitiveComparisons() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/primitiveComparisons.kt"); @@ -179,6 +185,12 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase { doTest(fileName); } + @TestMetadata("simpleUnaryOperators.kt") + public void testSimpleUnaryOperators() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/simpleUnaryOperators.kt"); + doTest(fileName); + } + @TestMetadata("smartCasts.kt") public void testSmartCasts() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/smartCasts.kt");