diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ClassGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ClassGenerator.kt index d4449a6b5dd..8fe3052d301 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ClassGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ClassGenerator.kt @@ -212,7 +212,8 @@ class ClassGenerator(val declarationGenerator: DeclarationGenerator) : Generator ktClassOrObject.getPrimaryConstructor()?.let { ktPrimaryConstructor -> for (ktParameter in ktPrimaryConstructor.valueParameters) { if (ktParameter.hasValOrVar()) { - irClass.addMember(generatePropertyForPrimaryConstructorParameter(ktParameter)) + val irProperty = PropertyGenerator(declarationGenerator).generatePropertyForPrimaryConstructorParameter(ktParameter) + irClass.addMember(irProperty) } } } @@ -227,18 +228,6 @@ class ClassGenerator(val declarationGenerator: DeclarationGenerator) : Generator } } - private fun generatePropertyForPrimaryConstructorParameter(ktParameter: KtParameter): IrDeclaration { - val valueParameterDescriptor = getOrFail(BindingContext.VALUE_PARAMETER, ktParameter) - val propertyDescriptor = getOrFail(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, ktParameter) - val irProperty = IrPropertyImpl(ktParameter.startOffset, ktParameter.endOffset, IrDeclarationOrigin.DEFINED, false, propertyDescriptor) - val irField = IrFieldImpl(ktParameter.startOffset, ktParameter.endOffset, IrDeclarationOrigin.PROPERTY_BACKING_FIELD, propertyDescriptor) - irProperty.backingField = irField - val irGetParameter = IrGetVariableImpl(ktParameter.startOffset, ktParameter.endOffset, - valueParameterDescriptor, IrOperator.INITIALIZE_PROPERTY_FROM_PARAMETER) - irField.initializer = IrExpressionBodyImpl(ktParameter.startOffset, ktParameter.endOffset, irGetParameter) - return irProperty - } - fun generateEnumEntry(ktEnumEntry: KtEnumEntry): IrEnumEntry { val enumEntryDescriptor = getOrFail(BindingContext.CLASS, ktEnumEntry) val irEnumEntry = IrEnumEntryImpl(ktEnumEntry.startOffset, ktEnumEntry.endOffset, IrDeclarationOrigin.DEFINED, enumEntryDescriptor) diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/DeclarationGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/DeclarationGenerator.kt index 4e0158edc58..31b65148428 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/DeclarationGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/DeclarationGenerator.kt @@ -16,12 +16,12 @@ package org.jetbrains.kotlin.psi2ir.generators -import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.descriptors.CallableDescriptor +import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.declarations.impl.* import org.jetbrains.kotlin.ir.expressions.IrBody import org.jetbrains.kotlin.ir.expressions.IrExpressionBody -import org.jetbrains.kotlin.ir.expressions.impl.* import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.endOffset import org.jetbrains.kotlin.psi.psiUtil.startOffset @@ -34,7 +34,7 @@ class DeclarationGenerator(override val context: GeneratorContext) : Generator { is KtNamedFunction -> generateFunctionDeclaration(ktDeclaration) is KtProperty -> - generatePropertyDeclaration(ktDeclaration) + PropertyGenerator(this).generatePropertyDeclaration(ktDeclaration) is KtClassOrObject -> generateClassOrObjectDeclaration(ktDeclaration) is KtTypeAlias -> @@ -106,113 +106,10 @@ class DeclarationGenerator(override val context: GeneratorContext) : Generator { return irConstructor } - fun generatePropertyDeclaration(ktProperty: KtProperty): IrProperty { - val propertyDescriptor = getPropertyDescriptor(ktProperty) - val ktDelegate = ktProperty.delegate - return if (ktDelegate != null) - generateDelegatedProperty(ktProperty, ktDelegate, propertyDescriptor) - else - generateSimpleProperty(ktProperty, propertyDescriptor) - } - - private fun generateDelegatedProperty(ktProperty: KtProperty, ktDelegate: KtPropertyDelegate, propertyDescriptor: PropertyDescriptor): IrProperty { - val ktDelegateExpression = ktDelegate.expression!! - val irDelegateInitializer = generateInitializerBody(propertyDescriptor, ktDelegateExpression) - return DelegatedPropertyGenerator(context).generateDelegatedProperty(ktProperty, ktDelegate, propertyDescriptor, irDelegateInitializer) - } - - private fun generateSimpleProperty(ktProperty: KtProperty, propertyDescriptor: PropertyDescriptor): IrProperty { - val irProperty = IrPropertyImpl(ktProperty.startOffset, ktProperty.endOffset, IrDeclarationOrigin.DEFINED, false, propertyDescriptor) - - val irField = if (propertyDescriptor.hasBackingField()) { - IrFieldImpl(ktProperty.startOffset, ktProperty.endOffset, IrDeclarationOrigin.PROPERTY_BACKING_FIELD, propertyDescriptor, - ktProperty.initializer?.let { generateInitializerBody(propertyDescriptor, it) }) - } - else null - irProperty.backingField = irField - - irProperty.getter = ktProperty.getter?.let { ktGetter -> - val accessorDescriptor = getOrFail(BindingContext.PROPERTY_ACCESSOR, ktGetter) - val getterDescriptor = accessorDescriptor as? PropertyGetterDescriptor ?: TODO("not a getter?") - val irGetter = IrFunctionImpl(ktGetter.startOffset, ktGetter.endOffset, IrDeclarationOrigin.DEFINED, getterDescriptor) - irGetter.body = ktGetter.bodyExpression?.let { generateFunctionBody(getterDescriptor, it ) } - irGetter - } ?: generateDefaultGetterIfRequired(ktProperty, irField) - - irProperty.setter = ktProperty.setter?.let { ktSetter -> - val accessorDescriptor = getOrFail(BindingContext.PROPERTY_ACCESSOR, ktSetter) - val setterDescriptor = accessorDescriptor as? PropertySetterDescriptor ?: TODO("not a setter?") - val irSetter = IrFunctionImpl(ktSetter.startOffset, ktSetter.endOffset, IrDeclarationOrigin.DEFINED, setterDescriptor) - irSetter.body = ktSetter.bodyExpression?.let { generateFunctionBody(setterDescriptor, it ) } - irSetter - } ?: generateDefaultSetterIfRequired(ktProperty, irField) - - return irProperty - } - - private fun PropertyDescriptor.hasBackingField(): Boolean = - get(BindingContext.BACKING_FIELD_REQUIRED, this) ?: false - - private fun generateDefaultGetterIfRequired(ktProperty: KtProperty, irField: IrField?): IrFunction? { - if (irField == null) return null - - val property = irField.descriptor - val getter = property.getter ?: return null - - val irGetter = IrFunctionImpl(ktProperty.startOffset, ktProperty.endOffset, IrDeclarationOrigin.DEFAULT_PROPERTY_ACCESSOR, getter) - val irBody = IrBlockBodyImpl(ktProperty.startOffset, ktProperty.endOffset) - irGetter.body = irBody - - val containingDeclaration = property.containingDeclaration - val receiver = - if (containingDeclaration is ClassDescriptor) - IrThisReferenceImpl(ktProperty.startOffset, ktProperty.endOffset, containingDeclaration.defaultType, - containingDeclaration) - else - null - - irBody.addStatement(IrReturnImpl(ktProperty.startOffset, ktProperty.endOffset, context.builtIns.nothingType, getter, - IrGetFieldImpl(ktProperty.startOffset, ktProperty.endOffset, property, receiver))) - - return irGetter - } - - private fun generateDefaultSetterIfRequired(ktProperty: KtProperty, irField: IrField?): IrFunction? { - if (irField == null) return null - - val property = irField.descriptor - if (!property.isVar) return null - val setter = property.setter ?: return null - - val irSetter = IrFunctionImpl(ktProperty.startOffset, ktProperty.endOffset, IrDeclarationOrigin.DEFAULT_PROPERTY_ACCESSOR, setter) - val irBody = IrBlockBodyImpl(ktProperty.startOffset, ktProperty.endOffset) - irSetter.body = irBody - - val containingDeclaration = property.containingDeclaration - val receiver = - if (containingDeclaration is ClassDescriptor) - IrThisReferenceImpl(ktProperty.startOffset, ktProperty.endOffset, containingDeclaration.defaultType, - containingDeclaration) - else - null - - val setterParameter = setter.valueParameters.single() - irBody.addStatement(IrSetFieldImpl(ktProperty.startOffset, ktProperty.endOffset, property, receiver, - IrGetVariableImpl(ktProperty.startOffset, ktProperty.endOffset, setterParameter))) - - return irSetter - } - - private fun getPropertyDescriptor(ktProperty: KtProperty): PropertyDescriptor { - val variableDescriptor = getOrFail(BindingContext.VARIABLE, ktProperty) - val propertyDescriptor = variableDescriptor as? PropertyDescriptor ?: TODO("not a property?") - return propertyDescriptor - } - - private fun generateFunctionBody(scopeOwner: CallableDescriptor, ktBody: KtExpression): IrBody = + fun generateFunctionBody(scopeOwner: CallableDescriptor, ktBody: KtExpression): IrBody = createBodyGenerator(scopeOwner).generateFunctionBody(ktBody) - private fun generateInitializerBody(scopeOwner: CallableDescriptor, ktBody: KtExpression): IrExpressionBody = + fun generateInitializerBody(scopeOwner: CallableDescriptor, ktBody: KtExpression): IrExpressionBody = createBodyGenerator(scopeOwner).generatePropertyInitializerBody(ktBody) private fun createBodyGenerator(descriptor: CallableDescriptor) = diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/PropertyGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/PropertyGenerator.kt new file mode 100644 index 00000000000..c4da3ed2736 --- /dev/null +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/PropertyGenerator.kt @@ -0,0 +1,185 @@ +/* + * 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.psi2ir.generators + +import org.jetbrains.kotlin.descriptors.ClassDescriptor +import org.jetbrains.kotlin.descriptors.PropertyDescriptor +import org.jetbrains.kotlin.descriptors.PropertyGetterDescriptor +import org.jetbrains.kotlin.descriptors.PropertySetterDescriptor +import org.jetbrains.kotlin.ir.declarations.IrDeclaration +import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin +import org.jetbrains.kotlin.ir.declarations.IrFunction +import org.jetbrains.kotlin.ir.declarations.IrProperty +import org.jetbrains.kotlin.ir.declarations.impl.IrFieldImpl +import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl +import org.jetbrains.kotlin.ir.declarations.impl.IrPropertyImpl +import org.jetbrains.kotlin.ir.expressions.IrBlockBody +import org.jetbrains.kotlin.ir.expressions.IrOperator +import org.jetbrains.kotlin.ir.expressions.impl.* +import org.jetbrains.kotlin.psi.KtElement +import org.jetbrains.kotlin.psi.KtParameter +import org.jetbrains.kotlin.psi.KtProperty +import org.jetbrains.kotlin.psi.KtPropertyDelegate +import org.jetbrains.kotlin.psi.psiUtil.endOffset +import org.jetbrains.kotlin.psi.psiUtil.startOffset +import org.jetbrains.kotlin.resolve.BindingContext +import org.jetbrains.kotlin.resolve.DescriptorUtils + +class PropertyGenerator(val declarationGenerator: DeclarationGenerator) : Generator { + override val context: GeneratorContext get() = declarationGenerator.context + + fun generatePropertyDeclaration(ktProperty: KtProperty): IrProperty { + val propertyDescriptor = getPropertyDescriptor(ktProperty) + val ktDelegate = ktProperty.delegate + return if (ktDelegate != null) + generateDelegatedProperty(ktProperty, ktDelegate, propertyDescriptor) + else + generateSimpleProperty(ktProperty, propertyDescriptor) + } + + fun generatePropertyForPrimaryConstructorParameter(ktParameter: KtParameter): IrDeclaration { + val valueParameterDescriptor = getOrFail(BindingContext.VALUE_PARAMETER, ktParameter) + val propertyDescriptor = getOrFail(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, ktParameter) + + val irProperty = IrPropertyImpl(ktParameter.startOffset, ktParameter.endOffset, IrDeclarationOrigin.DEFINED, false, propertyDescriptor) + + val irField = IrFieldImpl(ktParameter.startOffset, ktParameter.endOffset, IrDeclarationOrigin.PROPERTY_BACKING_FIELD, propertyDescriptor) + val irGetParameter = IrGetVariableImpl(ktParameter.startOffset, ktParameter.endOffset, + valueParameterDescriptor, IrOperator.INITIALIZE_PROPERTY_FROM_PARAMETER) + irField.initializer = IrExpressionBodyImpl(ktParameter.startOffset, ktParameter.endOffset, irGetParameter) + irProperty.backingField = irField + + val getter = propertyDescriptor.getter ?: + throw AssertionError("Property declared in primary constructor has no getter: $propertyDescriptor") + val irGetter = IrFunctionImpl(ktParameter.startOffset, ktParameter.endOffset, IrDeclarationOrigin.DEFAULT_PROPERTY_ACCESSOR, getter) + irProperty.getter = irGetter + irGetter.body = generateDefaultGetterBody(ktParameter, getter) + + if (propertyDescriptor.isVar) { + val setter = propertyDescriptor.setter ?: + throw AssertionError("Property declared in primary constructor has no setter: $propertyDescriptor") + val irSetter = IrFunctionImpl(ktParameter.startOffset, ktParameter.endOffset, IrDeclarationOrigin.DEFAULT_PROPERTY_ACCESSOR, setter) + irSetter.body = generateDefaultSetterBody(ktParameter, setter) + irProperty.setter = irSetter + } + + return irProperty + } + + private fun generateDelegatedProperty(ktProperty: KtProperty, ktDelegate: KtPropertyDelegate, propertyDescriptor: PropertyDescriptor): IrProperty { + val ktDelegateExpression = ktDelegate.expression!! + val irDelegateInitializer = declarationGenerator.generateInitializerBody(propertyDescriptor, ktDelegateExpression) + return DelegatedPropertyGenerator(context).generateDelegatedProperty(ktProperty, ktDelegate, propertyDescriptor, irDelegateInitializer) + } + + private fun generateSimpleProperty(ktProperty: KtProperty, propertyDescriptor: PropertyDescriptor): IrProperty { + val irProperty = IrPropertyImpl(ktProperty.startOffset, ktProperty.endOffset, IrDeclarationOrigin.DEFINED, false, propertyDescriptor) + + val irField = if (propertyDescriptor.hasBackingField()) { + IrFieldImpl(ktProperty.startOffset, ktProperty.endOffset, IrDeclarationOrigin.PROPERTY_BACKING_FIELD, propertyDescriptor, + ktProperty.initializer?.let { declarationGenerator.generateInitializerBody(propertyDescriptor, it) }) + } + else null + irProperty.backingField = irField + + irProperty.getter = generateGetterIfRequired(ktProperty, propertyDescriptor) + + irProperty.setter = generateSetterIfRequired(ktProperty, propertyDescriptor) + + return irProperty + } + + private fun PropertyDescriptor.hasBackingField(): Boolean = + get(BindingContext.BACKING_FIELD_REQUIRED, this) ?: false + + private fun generateGetterIfRequired(ktProperty: KtProperty, property: PropertyDescriptor): IrFunction? { + val getter = property.getter ?: return null + + val ktGetter = ktProperty.getter + if (DescriptorUtils.isInterface(property.containingDeclaration) && ktGetter == null) return null + + val irGetter = ktGetter?.let { + IrFunctionImpl(it.startOffset, it.endOffset, IrDeclarationOrigin.DEFINED, getter) + } ?: IrFunctionImpl(ktProperty.startOffset, ktProperty.endOffset, IrDeclarationOrigin.DEFAULT_PROPERTY_ACCESSOR, getter) + + irGetter.body = ktGetter?.bodyExpression?.let { + declarationGenerator.generateFunctionBody(getter, it ) + } ?: generateDefaultGetterBody(ktProperty, getter) + + return irGetter + } + + private fun generateSetterIfRequired(ktProperty: KtProperty, property: PropertyDescriptor): IrFunction? { + if (!property.isVar) return null + val setter = property.setter ?: return null + + val ktSetter = ktProperty.setter + if (DescriptorUtils.isInterface(property.containingDeclaration) && ktSetter == null) return null + + val irSetter = ktSetter?.let { + IrFunctionImpl(it.startOffset, it.endOffset, IrDeclarationOrigin.DEFINED, setter) + } ?: IrFunctionImpl(ktProperty.startOffset, ktProperty.endOffset, IrDeclarationOrigin.DEFAULT_PROPERTY_ACCESSOR, setter) + + irSetter.body = ktSetter?.bodyExpression?.let { + declarationGenerator.generateFunctionBody(setter, it ) + } ?: generateDefaultSetterBody(ktProperty, setter) + + return irSetter + } + + private fun generateDefaultGetterBody(ktProperty: KtElement, getter: PropertyGetterDescriptor): IrBlockBody { + val property = getter.correspondingProperty + + val irBody = IrBlockBodyImpl(ktProperty.startOffset, ktProperty.endOffset) + + val receiver = generateReceiverExpressionForDefaultPropertyAccessor(ktProperty, property) + + irBody.addStatement(IrReturnImpl(ktProperty.startOffset, ktProperty.endOffset, context.builtIns.nothingType, getter, + IrGetFieldImpl(ktProperty.startOffset, ktProperty.endOffset, property, receiver))) + return irBody + } + + private fun generateDefaultSetterBody(ktProperty: KtElement, setter: PropertySetterDescriptor): IrBlockBody { + val property = setter.correspondingProperty + + val irBody = IrBlockBodyImpl(ktProperty.startOffset, ktProperty.endOffset) + + val receiver = generateReceiverExpressionForDefaultPropertyAccessor(ktProperty, property) + + val setterParameter = setter.valueParameters.single() + irBody.addStatement(IrSetFieldImpl(ktProperty.startOffset, ktProperty.endOffset, property, receiver, + IrGetVariableImpl(ktProperty.startOffset, ktProperty.endOffset, setterParameter))) + return irBody + } + + private fun generateReceiverExpressionForDefaultPropertyAccessor(ktProperty: KtElement, property: PropertyDescriptor): IrThisReferenceImpl? { + val containingDeclaration = property.containingDeclaration + val receiver = + if (containingDeclaration is ClassDescriptor) + IrThisReferenceImpl(ktProperty.startOffset, ktProperty.endOffset, containingDeclaration.defaultType, + containingDeclaration) + else + null + return receiver + } + + private fun getPropertyDescriptor(ktProperty: KtProperty): PropertyDescriptor { + val variableDescriptor = getOrFail(BindingContext.VARIABLE, ktProperty) + val propertyDescriptor = variableDescriptor as? PropertyDescriptor ?: TODO("not a property?") + return propertyDescriptor + } +} diff --git a/compiler/testData/ir/irText/classes/argumentReorderingInDelegatingConstructorCall.txt b/compiler/testData/ir/irText/classes/argumentReorderingInDelegatingConstructorCall.txt index 2f6c3fcf0cb..53c528ea550 100644 --- a/compiler/testData/ir/irText/classes/argumentReorderingInDelegatingConstructorCall.txt +++ b/compiler/testData/ir/irText/classes/argumentReorderingInDelegatingConstructorCall.txt @@ -8,10 +8,20 @@ FILE /argumentReorderingInDelegatingConstructorCall.kt FIELD public final val x: kotlin.Int EXPRESSION_BODY GET_VAR 'value-parameter x: Int' type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN public final fun (): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + GET_BACKING_FIELD 'x: Int' type=kotlin.Int operator=null + receiver: THIS of 'Base' type=Base PROPERTY public final val y: kotlin.Int FIELD public final val y: kotlin.Int EXPRESSION_BODY GET_VAR 'value-parameter y: Int' type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN public final fun (): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + GET_BACKING_FIELD 'y: Int' type=kotlin.Int operator=null + receiver: THIS of 'Base' type=Base CLASS CLASS Test1 CONSTRUCTOR public constructor Test1(xx: kotlin.Int, yy: kotlin.Int) BLOCK_BODY diff --git a/compiler/testData/ir/irText/classes/classMembers.txt b/compiler/testData/ir/irText/classes/classMembers.txt index da139937548..add81c2cb89 100644 --- a/compiler/testData/ir/irText/classes/classMembers.txt +++ b/compiler/testData/ir/irText/classes/classMembers.txt @@ -10,10 +10,25 @@ FILE /classMembers.kt FIELD public final val y: kotlin.Int EXPRESSION_BODY GET_VAR 'value-parameter y: Int' type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN public final fun (): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + GET_BACKING_FIELD 'y: Int' type=kotlin.Int operator=null + receiver: THIS of 'C' type=C PROPERTY public final var z: kotlin.Int FIELD public final var z: kotlin.Int EXPRESSION_BODY GET_VAR 'value-parameter z: Int = ...' type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN public final fun (): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + GET_BACKING_FIELD 'z: Int' type=kotlin.Int operator=null + receiver: THIS of 'C' type=C + FUN public final fun (: kotlin.Int): kotlin.Unit + BLOCK_BODY + SET_BACKING_FIELD 'z: Int' type=kotlin.Unit operator=null + receiver: THIS of 'C' type=C + value: GET_VAR 'value-parameter : Int' type=kotlin.Int operator=null CONSTRUCTOR public constructor C() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor C(Int, Int, Int = ...)' diff --git a/compiler/testData/ir/irText/classes/dataClasses.txt b/compiler/testData/ir/irText/classes/dataClasses.txt index 1addb2407e6..09e73cab7d2 100644 --- a/compiler/testData/ir/irText/classes/dataClasses.txt +++ b/compiler/testData/ir/irText/classes/dataClasses.txt @@ -8,14 +8,29 @@ FILE /dataClasses.kt FIELD public final val x: kotlin.Int EXPRESSION_BODY GET_VAR 'value-parameter x: Int' type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN public final fun (): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + GET_BACKING_FIELD 'x: Int' type=kotlin.Int operator=null + receiver: THIS of 'Test1' type=Test1 PROPERTY public final val y: kotlin.String FIELD public final val y: kotlin.String EXPRESSION_BODY GET_VAR 'value-parameter y: String' type=kotlin.String operator=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN public final fun (): kotlin.String + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): String' + GET_BACKING_FIELD 'y: String' type=kotlin.String operator=null + receiver: THIS of 'Test1' type=Test1 PROPERTY public final val z: kotlin.Any FIELD public final val z: kotlin.Any EXPRESSION_BODY GET_VAR 'value-parameter z: Any' type=kotlin.Any operator=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN public final fun (): kotlin.Any + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Any' + GET_BACKING_FIELD 'z: Any' type=kotlin.Any operator=null + receiver: THIS of 'Test1' type=Test1 FUN public final operator fun component1(): kotlin.Int BLOCK_BODY RETURN type=kotlin.Nothing from='component1(): Int' diff --git a/compiler/testData/ir/irText/classes/enum.txt b/compiler/testData/ir/irText/classes/enum.txt index b89ad1c5ca2..d3410e1b7b2 100644 --- a/compiler/testData/ir/irText/classes/enum.txt +++ b/compiler/testData/ir/irText/classes/enum.txt @@ -21,6 +21,11 @@ FILE /enum.kt FIELD public final val x: kotlin.Int EXPRESSION_BODY GET_VAR 'value-parameter x: Int' type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN public final fun (): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + GET_BACKING_FIELD 'x: Int' type=kotlin.Int operator=null + receiver: THIS of 'TestEnum2' type=TestEnum2 ENUM_ENTRY enum entry TEST1 init: ENUM_CONSTRUCTOR_CALL 'constructor TestEnum2(Int)' TEST1 x: CONST Int type=kotlin.Int value='1' @@ -64,6 +69,11 @@ FILE /enum.kt FIELD public final val x: kotlin.Int EXPRESSION_BODY GET_VAR 'value-parameter x: Int' type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN public final fun (): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + GET_BACKING_FIELD 'x: Int' type=kotlin.Int operator=null + receiver: THIS of 'TestEnum4' type=TestEnum4 ENUM_ENTRY enum entry TEST1 init: ENUM_CONSTRUCTOR_CALL 'constructor TEST1()' TEST1 class: CLASS ENUM_ENTRY TEST1 diff --git a/compiler/testData/ir/irText/classes/initBlock.txt b/compiler/testData/ir/irText/classes/initBlock.txt index a5563853ba3..4a683c79f66 100644 --- a/compiler/testData/ir/irText/classes/initBlock.txt +++ b/compiler/testData/ir/irText/classes/initBlock.txt @@ -16,6 +16,11 @@ FILE /initBlock.kt FIELD public final val x: kotlin.Int EXPRESSION_BODY GET_VAR 'value-parameter x: Int' type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN public final fun (): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + GET_BACKING_FIELD 'x: Int' type=kotlin.Int operator=null + receiver: THIS of 'Test2' type=Test2 ANONYMOUS_INITIALIZER Test2 BLOCK_BODY CALL 'println(): Unit' type=kotlin.Unit operator=null diff --git a/compiler/testData/ir/irText/classes/initVal.txt b/compiler/testData/ir/irText/classes/initVal.txt index 29992f92439..b0bca8f8021 100644 --- a/compiler/testData/ir/irText/classes/initVal.txt +++ b/compiler/testData/ir/irText/classes/initVal.txt @@ -8,6 +8,11 @@ FILE /initVal.kt FIELD public final val x: kotlin.Int EXPRESSION_BODY GET_VAR 'value-parameter x: Int' type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN public final fun (): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + GET_BACKING_FIELD 'x: Int' type=kotlin.Int operator=null + receiver: THIS of 'TestInitValFromParameter' type=TestInitValFromParameter CLASS CLASS TestInitValInClass CONSTRUCTOR public constructor TestInitValInClass() BLOCK_BODY diff --git a/compiler/testData/ir/irText/classes/initVar.txt b/compiler/testData/ir/irText/classes/initVar.txt index cdd1c8c9dd5..c03ee6aa8fc 100644 --- a/compiler/testData/ir/irText/classes/initVar.txt +++ b/compiler/testData/ir/irText/classes/initVar.txt @@ -8,6 +8,16 @@ FILE /initVar.kt FIELD public final var x: kotlin.Int EXPRESSION_BODY GET_VAR 'value-parameter x: Int' type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN public final fun (): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + GET_BACKING_FIELD 'x: Int' type=kotlin.Int operator=null + receiver: THIS of 'TestInitVarFromParameter' type=TestInitVarFromParameter + FUN public final fun (: kotlin.Int): kotlin.Unit + BLOCK_BODY + SET_BACKING_FIELD 'x: Int' type=kotlin.Unit operator=null + receiver: THIS of 'TestInitVarFromParameter' type=TestInitVarFromParameter + value: GET_VAR 'value-parameter : Int' type=kotlin.Int operator=null CLASS CLASS TestInitVarInClass CONSTRUCTOR public constructor TestInitVarInClass() BLOCK_BODY diff --git a/compiler/testData/ir/irText/classes/primaryConstructor.txt b/compiler/testData/ir/irText/classes/primaryConstructor.txt index 1e0d0205c59..e097698d236 100644 --- a/compiler/testData/ir/irText/classes/primaryConstructor.txt +++ b/compiler/testData/ir/irText/classes/primaryConstructor.txt @@ -8,10 +8,20 @@ FILE /primaryConstructor.kt FIELD public final val x: kotlin.Int EXPRESSION_BODY GET_VAR 'value-parameter x: Int' type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN public final fun (): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + GET_BACKING_FIELD 'x: Int' type=kotlin.Int operator=null + receiver: THIS of 'Test1' type=Test1 PROPERTY public final val y: kotlin.Int FIELD public final val y: kotlin.Int EXPRESSION_BODY GET_VAR 'value-parameter y: Int' type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN public final fun (): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + GET_BACKING_FIELD 'y: Int' type=kotlin.Int operator=null + receiver: THIS of 'Test1' type=Test1 CLASS CLASS Test2 CONSTRUCTOR public constructor Test2(x: kotlin.Int, y: kotlin.Int) BLOCK_BODY @@ -21,6 +31,11 @@ FILE /primaryConstructor.kt FIELD public final val y: kotlin.Int EXPRESSION_BODY GET_VAR 'value-parameter y: Int' type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN public final fun (): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + GET_BACKING_FIELD 'y: Int' type=kotlin.Int operator=null + receiver: THIS of 'Test2' type=Test2 PROPERTY public final val x: kotlin.Int FIELD public final val x: kotlin.Int EXPRESSION_BODY @@ -39,6 +54,11 @@ FILE /primaryConstructor.kt FIELD public final val y: kotlin.Int EXPRESSION_BODY GET_VAR 'value-parameter y: Int' type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN public final fun (): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + GET_BACKING_FIELD 'y: Int' type=kotlin.Int operator=null + receiver: THIS of 'Test3' type=Test3 PROPERTY public final val x: kotlin.Int FIELD public final val x: kotlin.Int FUN public final fun (): kotlin.Int diff --git a/compiler/testData/ir/irText/classes/primaryConstructorWithSuperConstructorCall.txt b/compiler/testData/ir/irText/classes/primaryConstructorWithSuperConstructorCall.txt index ec7276fbb62..8f12ff5e238 100644 --- a/compiler/testData/ir/irText/classes/primaryConstructorWithSuperConstructorCall.txt +++ b/compiler/testData/ir/irText/classes/primaryConstructorWithSuperConstructorCall.txt @@ -23,10 +23,20 @@ FILE /primaryConstructorWithSuperConstructorCall.kt FIELD public final val x: kotlin.Int EXPRESSION_BODY GET_VAR 'value-parameter x: Int' type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN public final fun (): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + GET_BACKING_FIELD 'x: Int' type=kotlin.Int operator=null + receiver: THIS of 'TestWithDelegatingConstructor' type=TestWithDelegatingConstructor PROPERTY public final val y: kotlin.Int FIELD public final val y: kotlin.Int EXPRESSION_BODY GET_VAR 'value-parameter y: Int' type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN public final fun (): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + GET_BACKING_FIELD 'y: Int' type=kotlin.Int operator=null + receiver: THIS of 'TestWithDelegatingConstructor' type=TestWithDelegatingConstructor CONSTRUCTOR public constructor TestWithDelegatingConstructor(x: kotlin.Int) BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor TestWithDelegatingConstructor(Int, Int)' diff --git a/compiler/testData/ir/irText/classes/sealedClasses.txt b/compiler/testData/ir/irText/classes/sealedClasses.txt index f96fc7eb82e..32ec20f8ded 100644 --- a/compiler/testData/ir/irText/classes/sealedClasses.txt +++ b/compiler/testData/ir/irText/classes/sealedClasses.txt @@ -13,6 +13,11 @@ FILE /sealedClasses.kt FIELD public final val number: kotlin.Double EXPRESSION_BODY GET_VAR 'value-parameter number: Double' type=kotlin.Double operator=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN public final fun (): kotlin.Double + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Double' + GET_BACKING_FIELD 'number: Double' type=kotlin.Double operator=null + receiver: THIS of 'Const' type=Expr.Const CLASS CLASS Sum CONSTRUCTOR public constructor Sum(e1: Expr, e2: Expr) BLOCK_BODY @@ -22,10 +27,20 @@ FILE /sealedClasses.kt FIELD public final val e1: Expr EXPRESSION_BODY GET_VAR 'value-parameter e1: Expr' type=Expr operator=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN public final fun (): Expr + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Expr' + GET_BACKING_FIELD 'e1: Expr' type=Expr operator=null + receiver: THIS of 'Sum' type=Expr.Sum PROPERTY public final val e2: Expr FIELD public final val e2: Expr EXPRESSION_BODY GET_VAR 'value-parameter e2: Expr' type=Expr operator=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN public final fun (): Expr + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Expr' + GET_BACKING_FIELD 'e2: Expr' type=Expr operator=null + receiver: THIS of 'Sum' type=Expr.Sum CLASS OBJECT NotANumber CONSTRUCTOR private constructor NotANumber() BLOCK_BODY diff --git a/compiler/testData/ir/irText/declarations/classLevelProperties.kt b/compiler/testData/ir/irText/declarations/classLevelProperties.kt new file mode 100644 index 00000000000..cd1e5d802b0 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/classLevelProperties.kt @@ -0,0 +1,21 @@ +// WITH_RUNTIME + +class C { + val test1 = 0 + + val test2: Int get() = 0 + + var test3 = 0 + + var test4 = 1; set(value) { + field = value + } + + var test5 = 1; private set + + val test6 = 1; get + + val test7 by lazy { 42 } + + var test8 by hashMapOf() +} \ No newline at end of file diff --git a/compiler/testData/ir/irText/declarations/classLevelProperties.txt b/compiler/testData/ir/irText/declarations/classLevelProperties.txt new file mode 100644 index 00000000000..e2a61086a72 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/classLevelProperties.txt @@ -0,0 +1,109 @@ +FILE /classLevelProperties.kt + CLASS CLASS C + CONSTRUCTOR public constructor C() + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' + INSTANCE_INITIALIZER_CALL classDescriptor='C' + PROPERTY public final val test1: kotlin.Int = 0 + FIELD public final val test1: kotlin.Int = 0 + EXPRESSION_BODY + CONST Int type=kotlin.Int value='0' + FUN public final fun (): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + GET_BACKING_FIELD 'test1: Int' type=kotlin.Int operator=null + receiver: THIS of 'C' type=C + PROPERTY public final val test2: kotlin.Int + FUN public final fun (): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + CONST Int type=kotlin.Int value='0' + PROPERTY public final var test3: kotlin.Int + FIELD public final var test3: kotlin.Int + EXPRESSION_BODY + CONST Int type=kotlin.Int value='0' + FUN public final fun (): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + GET_BACKING_FIELD 'test3: Int' type=kotlin.Int operator=null + receiver: THIS of 'C' type=C + FUN public final fun (: kotlin.Int): kotlin.Unit + BLOCK_BODY + SET_BACKING_FIELD 'test3: Int' type=kotlin.Unit operator=null + receiver: THIS of 'C' type=C + value: GET_VAR 'value-parameter : Int' type=kotlin.Int operator=null + PROPERTY public final var test4: kotlin.Int + FIELD public final var test4: kotlin.Int + EXPRESSION_BODY + CONST Int type=kotlin.Int value='1' + FUN public final fun (): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + GET_BACKING_FIELD 'test4: Int' type=kotlin.Int operator=null + receiver: THIS of 'C' type=C + FUN public final fun (value: kotlin.Int): kotlin.Unit + BLOCK_BODY + SET_BACKING_FIELD 'test4: Int' type=kotlin.Unit operator=EQ + value: GET_VAR 'value-parameter value: Int' type=kotlin.Int operator=null + PROPERTY public final var test5: kotlin.Int + FIELD public final var test5: kotlin.Int + EXPRESSION_BODY + CONST Int type=kotlin.Int value='1' + FUN public final fun (): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + GET_BACKING_FIELD 'test5: Int' type=kotlin.Int operator=null + receiver: THIS of 'C' type=C + FUN private final fun (: kotlin.Int): kotlin.Unit + BLOCK_BODY + SET_BACKING_FIELD 'test5: Int' type=kotlin.Unit operator=null + receiver: THIS of 'C' type=C + value: GET_VAR 'value-parameter : Int' type=kotlin.Int operator=null + PROPERTY public final val test6: kotlin.Int = 1 + FIELD public final val test6: kotlin.Int = 1 + EXPRESSION_BODY + CONST Int type=kotlin.Int value='1' + FUN public final fun (): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + GET_BACKING_FIELD 'test6: Int' type=kotlin.Int operator=null + receiver: THIS of 'C' type=C + PROPERTY public final val test7: kotlin.Int + FIELD val `test7$delegate`: kotlin.Lazy + EXPRESSION_BODY + CALL 'lazy(() -> Int): Lazy' type=kotlin.Lazy operator=null + initializer: BLOCK type=() -> kotlin.Int operator=LAMBDA + FUN local final fun (): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + CONST Int type=kotlin.Int value='42' + CALLABLE_REFERENCE '(): Int' type=() -> kotlin.Int operator=LAMBDA + FUN public final fun (): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + CALL 'getValue(Any?, KProperty<*>) on Lazy: Int' type=kotlin.Int operator=null + $receiver: GET_BACKING_FIELD '`test7$delegate`: Lazy' type=kotlin.Lazy operator=null + receiver: THIS of 'C' type=C + thisRef: THIS of 'C' type=C + property: CALLABLE_REFERENCE 'test7: Int' type=kotlin.reflect.KProperty1 operator=PROPERTY_REFERENCE_FOR_DELEGATE + PROPERTY public final var test8: kotlin.Int + FIELD val `test8$delegate`: java.util.HashMap + EXPRESSION_BODY + CALL 'hashMapOf(vararg Pair): HashMap' type=java.util.HashMap operator=null + FUN public final fun (): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + CALL 'getValue(Any?, KProperty<*>) on MutableMap: Int' type=kotlin.Int operator=null + $receiver: GET_BACKING_FIELD '`test8$delegate`: HashMap' type=java.util.HashMap operator=null + receiver: THIS of 'C' type=C + thisRef: THIS of 'C' type=C + property: CALLABLE_REFERENCE 'test8: Int' type=kotlin.reflect.KMutableProperty1 operator=PROPERTY_REFERENCE_FOR_DELEGATE + FUN public final fun (: kotlin.Int): kotlin.Unit + BLOCK_BODY + RETURN type=kotlin.Nothing from='(Int): Unit' + CALL 'setValue(Any?, KProperty<*>, Int) on MutableMap: Unit' type=kotlin.Unit operator=null + $receiver: GET_BACKING_FIELD '`test8$delegate`: HashMap' type=java.util.HashMap operator=null + receiver: THIS of 'C' type=C + thisRef: THIS of 'C' type=C + property: CALLABLE_REFERENCE 'test8: Int' type=kotlin.reflect.KMutableProperty1 operator=PROPERTY_REFERENCE_FOR_DELEGATE + value: GET_VAR 'value-parameter : Int' type=kotlin.Int operator=null diff --git a/compiler/testData/ir/irText/declarations/delegatedProperties.txt b/compiler/testData/ir/irText/declarations/delegatedProperties.txt index d5487cdcf2c..993596f3439 100644 --- a/compiler/testData/ir/irText/declarations/delegatedProperties.txt +++ b/compiler/testData/ir/irText/declarations/delegatedProperties.txt @@ -25,6 +25,11 @@ FILE /delegatedProperties.kt FIELD public final val map: kotlin.collections.MutableMap EXPRESSION_BODY GET_VAR 'value-parameter map: MutableMap' type=kotlin.collections.MutableMap operator=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN public final fun (): kotlin.collections.MutableMap + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): MutableMap' + GET_BACKING_FIELD 'map: MutableMap' type=kotlin.collections.MutableMap operator=null + receiver: THIS of 'C' type=C PROPERTY public final val test2: kotlin.Int FIELD val `test2$delegate`: kotlin.Lazy EXPRESSION_BODY diff --git a/compiler/testData/ir/irText/declarations/packageLevelProperties.kt b/compiler/testData/ir/irText/declarations/packageLevelProperties.kt new file mode 100644 index 00000000000..5a5e196f10c --- /dev/null +++ b/compiler/testData/ir/irText/declarations/packageLevelProperties.kt @@ -0,0 +1,17 @@ +// WITH_RUNTIME + +val test1 = 0 + +val test2: Int get() = 0 + +var test3 = 0 + +var test4 = 1; set(value) { field = value } + +var test5 = 1; private set + +val test6 = 1; get + +val test7 by lazy { 42 } + +var test8 by hashMapOf() diff --git a/compiler/testData/ir/irText/declarations/packageLevelProperties.txt b/compiler/testData/ir/irText/declarations/packageLevelProperties.txt new file mode 100644 index 00000000000..c03ec85dbe8 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/packageLevelProperties.txt @@ -0,0 +1,94 @@ +FILE /packageLevelProperties.kt + PROPERTY public val test1: kotlin.Int = 0 + FIELD public val test1: kotlin.Int = 0 + EXPRESSION_BODY + CONST Int type=kotlin.Int value='0' + FUN public fun (): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + GET_BACKING_FIELD 'test1: Int' type=kotlin.Int operator=null + PROPERTY public val test2: kotlin.Int + FUN public fun (): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + CONST Int type=kotlin.Int value='0' + PROPERTY public var test3: kotlin.Int + FIELD public var test3: kotlin.Int + EXPRESSION_BODY + CONST Int type=kotlin.Int value='0' + FUN public fun (): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + GET_BACKING_FIELD 'test3: Int' type=kotlin.Int operator=null + FUN public fun (: kotlin.Int): kotlin.Unit + BLOCK_BODY + SET_BACKING_FIELD 'test3: Int' type=kotlin.Unit operator=null + value: GET_VAR 'value-parameter : Int' type=kotlin.Int operator=null + PROPERTY public var test4: kotlin.Int + FIELD public var test4: kotlin.Int + EXPRESSION_BODY + CONST Int type=kotlin.Int value='1' + FUN public fun (): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + GET_BACKING_FIELD 'test4: Int' type=kotlin.Int operator=null + FUN public fun (value: kotlin.Int): kotlin.Unit + BLOCK_BODY + SET_BACKING_FIELD 'test4: Int' type=kotlin.Unit operator=EQ + value: GET_VAR 'value-parameter value: Int' type=kotlin.Int operator=null + PROPERTY public var test5: kotlin.Int + FIELD public var test5: kotlin.Int + EXPRESSION_BODY + CONST Int type=kotlin.Int value='1' + FUN public fun (): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + GET_BACKING_FIELD 'test5: Int' type=kotlin.Int operator=null + FUN private fun (: kotlin.Int): kotlin.Unit + BLOCK_BODY + SET_BACKING_FIELD 'test5: Int' type=kotlin.Unit operator=null + value: GET_VAR 'value-parameter : Int' type=kotlin.Int operator=null + PROPERTY public val test6: kotlin.Int = 1 + FIELD public val test6: kotlin.Int = 1 + EXPRESSION_BODY + CONST Int type=kotlin.Int value='1' + FUN public fun (): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + GET_BACKING_FIELD 'test6: Int' type=kotlin.Int operator=null + PROPERTY public val test7: kotlin.Int + FIELD val `test7$delegate`: kotlin.Lazy + EXPRESSION_BODY + CALL 'lazy(() -> Int): Lazy' type=kotlin.Lazy operator=null + initializer: BLOCK type=() -> kotlin.Int operator=LAMBDA + FUN local final fun (): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + CONST Int type=kotlin.Int value='42' + CALLABLE_REFERENCE '(): Int' type=() -> kotlin.Int operator=LAMBDA + FUN public fun (): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + CALL 'getValue(Any?, KProperty<*>) on Lazy: Int' type=kotlin.Int operator=null + $receiver: GET_BACKING_FIELD '`test7$delegate`: Lazy' type=kotlin.Lazy operator=null + thisRef: CONST Null type=kotlin.Nothing? value='null' + property: CALLABLE_REFERENCE 'test7: Int' type=kotlin.reflect.KProperty0 operator=PROPERTY_REFERENCE_FOR_DELEGATE + PROPERTY public var test8: kotlin.Int + FIELD val `test8$delegate`: java.util.HashMap + EXPRESSION_BODY + CALL 'hashMapOf(vararg Pair): HashMap' type=java.util.HashMap operator=null + FUN public fun (): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + CALL 'getValue(Any?, KProperty<*>) on MutableMap: Int' type=kotlin.Int operator=null + $receiver: GET_BACKING_FIELD '`test8$delegate`: HashMap' type=java.util.HashMap operator=null + thisRef: CONST Null type=kotlin.Nothing? value='null' + property: CALLABLE_REFERENCE 'test8: Int' type=kotlin.reflect.KMutableProperty0 operator=PROPERTY_REFERENCE_FOR_DELEGATE + FUN public fun (: kotlin.Int): kotlin.Unit + BLOCK_BODY + RETURN type=kotlin.Nothing from='(Int): Unit' + CALL 'setValue(Any?, KProperty<*>, Int) on MutableMap: Unit' type=kotlin.Unit operator=null + $receiver: GET_BACKING_FIELD '`test8$delegate`: HashMap' type=java.util.HashMap operator=null + thisRef: CONST Null type=kotlin.Nothing? value='null' + property: CALLABLE_REFERENCE 'test8: Int' type=kotlin.reflect.KMutableProperty0 operator=PROPERTY_REFERENCE_FOR_DELEGATE + value: GET_VAR 'value-parameter : Int' type=kotlin.Int operator=null diff --git a/compiler/testData/ir/irText/declarations/primaryCtorProperties.kt b/compiler/testData/ir/irText/declarations/primaryCtorProperties.kt new file mode 100644 index 00000000000..5a322a49d6d --- /dev/null +++ b/compiler/testData/ir/irText/declarations/primaryCtorProperties.kt @@ -0,0 +1,4 @@ +class C( + val test1: Int, + var test2: Int +) \ No newline at end of file diff --git a/compiler/testData/ir/irText/declarations/primaryCtorProperties.txt b/compiler/testData/ir/irText/declarations/primaryCtorProperties.txt new file mode 100644 index 00000000000..6a35b502ebb --- /dev/null +++ b/compiler/testData/ir/irText/declarations/primaryCtorProperties.txt @@ -0,0 +1,29 @@ +FILE /primaryCtorProperties.kt + CLASS CLASS C + CONSTRUCTOR public constructor C(test1: kotlin.Int, test2: kotlin.Int) + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' + INSTANCE_INITIALIZER_CALL classDescriptor='C' + PROPERTY public final val test1: kotlin.Int + FIELD public final val test1: kotlin.Int + EXPRESSION_BODY + GET_VAR 'value-parameter test1: Int' type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN public final fun (): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + GET_BACKING_FIELD 'test1: Int' type=kotlin.Int operator=null + receiver: THIS of 'C' type=C + PROPERTY public final var test2: kotlin.Int + FIELD public final var test2: kotlin.Int + EXPRESSION_BODY + GET_VAR 'value-parameter test2: Int' type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN public final fun (): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + GET_BACKING_FIELD 'test2: Int' type=kotlin.Int operator=null + receiver: THIS of 'C' type=C + FUN public final fun (: kotlin.Int): kotlin.Unit + BLOCK_BODY + SET_BACKING_FIELD 'test2: Int' type=kotlin.Unit operator=null + receiver: THIS of 'C' type=C + value: GET_VAR 'value-parameter : Int' type=kotlin.Int operator=null diff --git a/compiler/testData/ir/irText/expressions/arrayAugmentedAssignment1.txt b/compiler/testData/ir/irText/expressions/arrayAugmentedAssignment1.txt index db94fb88bb4..f3c2b05823e 100644 --- a/compiler/testData/ir/irText/expressions/arrayAugmentedAssignment1.txt +++ b/compiler/testData/ir/irText/expressions/arrayAugmentedAssignment1.txt @@ -20,6 +20,11 @@ FILE /arrayAugmentedAssignment1.kt FIELD public final val x: kotlin.IntArray EXPRESSION_BODY GET_VAR 'value-parameter x: IntArray' type=kotlin.IntArray operator=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN public final fun (): kotlin.IntArray + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): IntArray' + GET_BACKING_FIELD 'x: IntArray' type=kotlin.IntArray operator=null + receiver: THIS of 'C' type=C FUN public fun testVariable(): kotlin.Unit BLOCK_BODY VAR var x: kotlin.IntArray diff --git a/compiler/testData/ir/irText/expressions/assignments.txt b/compiler/testData/ir/irText/expressions/assignments.txt index ccb7ccaa2b1..90b12b57422 100644 --- a/compiler/testData/ir/irText/expressions/assignments.txt +++ b/compiler/testData/ir/irText/expressions/assignments.txt @@ -8,6 +8,16 @@ FILE /assignments.kt FIELD public final var x: kotlin.Int EXPRESSION_BODY GET_VAR 'value-parameter x: Int' type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN public final fun (): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + GET_BACKING_FIELD 'x: Int' type=kotlin.Int operator=null + receiver: THIS of 'Ref' type=Ref + FUN public final fun (: kotlin.Int): kotlin.Unit + BLOCK_BODY + SET_BACKING_FIELD 'x: Int' type=kotlin.Unit operator=null + receiver: THIS of 'Ref' type=Ref + value: GET_VAR 'value-parameter : Int' type=kotlin.Int operator=null FUN public fun test1(): kotlin.Unit BLOCK_BODY VAR var x: kotlin.Int diff --git a/compiler/testData/ir/irText/expressions/complexAugmentedAssignment.txt b/compiler/testData/ir/irText/expressions/complexAugmentedAssignment.txt index 65ab40ad7eb..9ec40b92323 100644 --- a/compiler/testData/ir/irText/expressions/complexAugmentedAssignment.txt +++ b/compiler/testData/ir/irText/expressions/complexAugmentedAssignment.txt @@ -130,6 +130,16 @@ FILE /complexAugmentedAssignment.kt FIELD public final var s: kotlin.Int EXPRESSION_BODY GET_VAR 'value-parameter s: Int = ...' type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN public final fun (): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + GET_BACKING_FIELD 's: Int' type=kotlin.Int operator=null + receiver: THIS of 'B' type=B + FUN public final fun (: kotlin.Int): kotlin.Unit + BLOCK_BODY + SET_BACKING_FIELD 's: Int' type=kotlin.Unit operator=null + receiver: THIS of 'B' type=B + value: GET_VAR 'value-parameter : Int' type=kotlin.Int operator=null CLASS OBJECT Host CONSTRUCTOR private constructor Host() BLOCK_BODY diff --git a/compiler/testData/ir/irText/expressions/forWithImplicitReceivers.txt b/compiler/testData/ir/irText/expressions/forWithImplicitReceivers.txt index 1692fc10fc3..76177bb041f 100644 --- a/compiler/testData/ir/irText/expressions/forWithImplicitReceivers.txt +++ b/compiler/testData/ir/irText/expressions/forWithImplicitReceivers.txt @@ -13,6 +13,16 @@ FILE /forWithImplicitReceivers.kt FIELD public final var value: kotlin.Int EXPRESSION_BODY GET_VAR 'value-parameter value: Int' type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN public final fun (): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + GET_BACKING_FIELD 'value: Int' type=kotlin.Int operator=null + receiver: THIS of 'IntCell' type=IntCell + FUN public final fun (: kotlin.Int): kotlin.Unit + BLOCK_BODY + SET_BACKING_FIELD 'value: Int' type=kotlin.Unit operator=null + receiver: THIS of 'IntCell' type=IntCell + value: GET_VAR 'value-parameter : Int' type=kotlin.Int operator=null CLASS INTERFACE IReceiver FUN public open operator fun FiveTimes.iterator(): IntCell BLOCK_BODY diff --git a/compiler/testData/ir/irText/expressions/safeCalls.txt b/compiler/testData/ir/irText/expressions/safeCalls.txt index 3a8e05a4dc5..c93005655a1 100644 --- a/compiler/testData/ir/irText/expressions/safeCalls.txt +++ b/compiler/testData/ir/irText/expressions/safeCalls.txt @@ -8,6 +8,16 @@ FILE /safeCalls.kt FIELD public final var value: kotlin.Int EXPRESSION_BODY GET_VAR 'value-parameter value: Int' type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN public final fun (): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + GET_BACKING_FIELD 'value: Int' type=kotlin.Int operator=null + receiver: THIS of 'Ref' type=Ref + FUN public final fun (: kotlin.Int): kotlin.Unit + BLOCK_BODY + SET_BACKING_FIELD 'value: Int' type=kotlin.Unit operator=null + receiver: THIS of 'Ref' type=Ref + value: GET_VAR 'value-parameter : Int' type=kotlin.Int operator=null CLASS INTERFACE IHost FUN public open fun kotlin.String.extLength(): kotlin.Int BLOCK_BODY diff --git a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java index 84c158091f3..6f9d73aa865 100644 --- a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java @@ -190,6 +190,12 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/ir/irText/declarations"), Pattern.compile("^(.+)\\.kt$"), true); } + @TestMetadata("classLevelProperties.kt") + public void testClassLevelProperties() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/declarations/classLevelProperties.kt"); + doTest(fileName); + } + @TestMetadata("defaultArguments.kt") public void testDefaultArguments() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/declarations/defaultArguments.kt"); @@ -214,6 +220,18 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase { doTest(fileName); } + @TestMetadata("packageLevelProperties.kt") + public void testPackageLevelProperties() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/declarations/packageLevelProperties.kt"); + doTest(fileName); + } + + @TestMetadata("primaryCtorProperties.kt") + public void testPrimaryCtorProperties() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/declarations/primaryCtorProperties.kt"); + doTest(fileName); + } + @TestMetadata("typeAlias.kt") public void testTypeAlias() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/declarations/typeAlias.kt");