Drop IrPropertyAccessor (and subclasses).

Drop IrLocalPropertyAccessor (and subclasses).
Introduce IrField.
This commit is contained in:
Dmitry Petrov
2016-09-12 12:07:10 +03:00
committed by Dmitry Petrov
parent 121e949a33
commit 5c720845a8
81 changed files with 1124 additions and 831 deletions
@@ -19,11 +19,12 @@ package org.jetbrains.kotlin.backend.common
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.declarations.IrGeneralFunction
import org.jetbrains.kotlin.ir.declarations.IrLocalPropertyAccessor
import org.jetbrains.kotlin.ir.declarations.IrFunction
import org.jetbrains.kotlin.ir.declarations.IrLocalDelegatedProperty
import org.jetbrains.kotlin.ir.expressions.*
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
import org.jetbrains.kotlin.ir.visitors.acceptVoid
import org.jetbrains.kotlin.resolve.DescriptorUtils
import java.util.*
@@ -103,7 +104,7 @@ abstract class AbstractClosureAnnotator : IrElementVisitorVoid {
closuresStack.peek()?.addNested(closure)
}
override fun visitGeneralFunction(declaration: IrGeneralFunction) {
override fun visitFunction(declaration: IrFunction) {
val functionDescriptor = declaration.descriptor
val closureBuilder = ClosureBuilder(functionDescriptor)
@@ -120,8 +121,9 @@ abstract class AbstractClosureAnnotator : IrElementVisitorVoid {
closuresStack.peek()?.addNested(closure)
}
override fun visitLocalPropertyAccessor(declaration: IrLocalPropertyAccessor) {
// Local property accessors are created for delegated local properties and have no closure.
override fun visitLocalDelegatedProperty(declaration: IrLocalDelegatedProperty) {
// Getter and setter of local delegated properties are special generated functions and don't have closure.
declaration.delegate.initializer?.acceptVoid(this)
}
override fun visitThisReference(expression: IrThisReference) {
@@ -92,9 +92,9 @@ class CallGenerator(statementGenerator: StatementGenerator): StatementGeneratorE
extensionReceiverValue?.load(),
IrOperator.GET_PROPERTY,
call.superQualifier)
} ?: IrGetBackingFieldImpl(startOffset, endOffset, descriptor,
dispatchReceiverValue?.load(),
IrOperator.GET_PROPERTY, call.superQualifier)
} ?: IrGetFieldImpl(startOffset, endOffset, descriptor,
dispatchReceiverValue?.load(),
IrOperator.GET_PROPERTY, call.superQualifier)
}
}
@@ -112,8 +112,8 @@ class ClassGenerator(val declarationGenerator: DeclarationGenerator) : Generator
val superClass = superTypeConstructorDescriptor as? ClassDescriptor ?:
throw AssertionError("Unexpected supertype constructor for delegation: $superTypeConstructorDescriptor")
val delegateDescriptor = IrImplementingDelegateDescriptorImpl(irClass.descriptor, delegateType, superType)
val irDelegate = IrSimplePropertyImpl(ktDelegateExpression.startOffset, ktDelegateExpression.endOffset, IrDeclarationOrigin.DELEGATE,
delegateDescriptor)
val irDelegate = IrFieldImpl(ktDelegateExpression.startOffset, ktDelegateExpression.endOffset, IrDeclarationOrigin.DELEGATE,
delegateDescriptor)
val bodyGenerator = BodyGenerator(irClass.descriptor, context)
irDelegate.initializer = bodyGenerator.generatePropertyInitializerBody(ktDelegateExpression)
irClass.addMember(irDelegate)
@@ -126,7 +126,8 @@ class ClassGenerator(val declarationGenerator: DeclarationGenerator) : Generator
}
}
private fun generateDelegatedMember(irClass: IrClassImpl, irDelegate: IrSimplePropertyImpl, delegatedMember: CallableMemberDescriptor, overriddenMember: CallableMemberDescriptor) {
private fun generateDelegatedMember(irClass: IrClassImpl, irDelegate: IrFieldImpl,
delegatedMember: CallableMemberDescriptor, overriddenMember: CallableMemberDescriptor) {
when (delegatedMember) {
is FunctionDescriptor ->
generateDelegatedFunction(irClass, irDelegate, delegatedMember, overriddenMember as FunctionDescriptor)
@@ -136,15 +137,16 @@ class ClassGenerator(val declarationGenerator: DeclarationGenerator) : Generator
}
private fun generateDelegatedProperty(irClass: IrClassImpl, irDelegate: IrSimplePropertyImpl, delegated: PropertyDescriptor, overridden: PropertyDescriptor) {
val irProperty = IrSimplePropertyImpl(irDelegate.startOffset, irDelegate.endOffset, IrDeclarationOrigin.DELEGATED_MEMBER, delegated)
private fun generateDelegatedProperty(irClass: IrClassImpl, irDelegate: IrFieldImpl,
delegated: PropertyDescriptor, overridden: PropertyDescriptor) {
val irProperty = IrPropertyImpl(irDelegate.startOffset, irDelegate.endOffset, IrDeclarationOrigin.DELEGATED_MEMBER, false, delegated)
val irGetter = IrPropertyGetterImpl(irDelegate.startOffset, irDelegate.endOffset, IrDeclarationOrigin.DELEGATED_MEMBER, delegated.getter!!)
val irGetter = IrFunctionImpl(irDelegate.startOffset, irDelegate.endOffset, IrDeclarationOrigin.DELEGATED_MEMBER, delegated.getter!!)
irGetter.body = generateDelegateFunctionBody(irDelegate, delegated.getter!!, overridden.getter!!)
irProperty.getter = irGetter
if (delegated.isVar) {
val irSetter = IrPropertySetterImpl(irDelegate.startOffset, irDelegate.endOffset, IrDeclarationOrigin.DELEGATED_MEMBER, delegated.setter!!)
val irSetter = IrFunctionImpl(irDelegate.startOffset, irDelegate.endOffset, IrDeclarationOrigin.DELEGATED_MEMBER, delegated.setter!!)
irSetter.body = generateDelegateFunctionBody(irDelegate, delegated.setter!!, overridden.setter!!)
irProperty.setter = irSetter
}
@@ -152,13 +154,13 @@ class ClassGenerator(val declarationGenerator: DeclarationGenerator) : Generator
irClass.addMember(irProperty)
}
private fun generateDelegatedFunction(irClass: IrClassImpl, irDelegate: IrSimplePropertyImpl, delegated: FunctionDescriptor, overridden: FunctionDescriptor) {
private fun generateDelegatedFunction(irClass: IrClassImpl, irDelegate: IrFieldImpl, delegated: FunctionDescriptor, overridden: FunctionDescriptor) {
val irFunction = IrFunctionImpl(irDelegate.startOffset, irDelegate.endOffset, IrDeclarationOrigin.DELEGATED_MEMBER, delegated)
irFunction.body = generateDelegateFunctionBody(irDelegate, delegated, overridden)
irClass.addMember(irFunction)
}
private fun generateDelegateFunctionBody(irDelegate: IrSimplePropertyImpl, delegated: FunctionDescriptor, overridden: FunctionDescriptor): IrBlockBodyImpl {
private fun generateDelegateFunctionBody(irDelegate: IrFieldImpl, delegated: FunctionDescriptor, overridden: FunctionDescriptor): IrBlockBodyImpl {
val irBlockBody = IrBlockBodyImpl(irDelegate.startOffset, irDelegate.endOffset)
val returnType = overridden.returnType!!
val irCall = IrCallImpl(irDelegate.startOffset, irDelegate.endOffset, returnType, overridden)
@@ -228,10 +230,12 @@ 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 = IrSimplePropertyImpl(ktParameter.startOffset, ktParameter.endOffset, IrDeclarationOrigin.DEFINED, propertyDescriptor)
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)
irProperty.initializer = IrExpressionBodyImpl(ktParameter.startOffset, ktParameter.endOffset, irGetParameter)
valueParameterDescriptor, IrOperator.INITIALIZE_PROPERTY_FROM_PARAMETER)
irField.initializer = IrExpressionBodyImpl(ktParameter.startOffset, ktParameter.endOffset, irGetParameter)
return irProperty
}
@@ -21,6 +21,7 @@ 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
@@ -74,7 +75,7 @@ class DeclarationGenerator(override val context: GeneratorContext) : Generator {
return irAnonymousInitializer
}
fun generateFunctionDeclaration(ktFunction: KtNamedFunction): IrGeneralFunction {
fun generateFunctionDeclaration(ktFunction: KtNamedFunction): IrFunction {
val functionDescriptor = getOrFail(BindingContext.FUNCTION, ktFunction)
val irFunction = IrFunctionImpl(ktFunction.startOffset, ktFunction.endOffset, IrDeclarationOrigin.DEFINED, functionDescriptor)
val bodyGenerator = createBodyGenerator(functionDescriptor)
@@ -83,7 +84,7 @@ class DeclarationGenerator(override val context: GeneratorContext) : Generator {
return irFunction
}
fun generateSecondaryConstructor(ktConstructor: KtSecondaryConstructor) : IrGeneralFunction {
fun generateSecondaryConstructor(ktConstructor: KtSecondaryConstructor): IrFunction {
if (ktConstructor.isConstructorDelegatingToSuper(context.bindingContext)) {
return generateSecondaryConstructorWithNestedInitializers(ktConstructor)
}
@@ -96,7 +97,7 @@ class DeclarationGenerator(override val context: GeneratorContext) : Generator {
}
private fun generateSecondaryConstructorWithNestedInitializers(ktConstructor: KtSecondaryConstructor): IrGeneralFunction {
private fun generateSecondaryConstructorWithNestedInitializers(ktConstructor: KtSecondaryConstructor): IrFunction {
val constructorDescriptor = getOrFail(BindingContext.CONSTRUCTOR, ktConstructor)
val irConstructor = IrConstructorImpl(ktConstructor.startOffset, ktConstructor.endOffset, IrDeclarationOrigin.DEFINED, constructorDescriptor)
val bodyGenerator = createBodyGenerator(constructorDescriptor)
@@ -120,30 +121,87 @@ class DeclarationGenerator(override val context: GeneratorContext) : Generator {
return DelegatedPropertyGenerator(context).generateDelegatedProperty(ktProperty, ktDelegate, propertyDescriptor, irDelegateInitializer)
}
private fun generateSimpleProperty(ktProperty: KtProperty, propertyDescriptor: PropertyDescriptor): IrSimplePropertyImpl {
val initializer = ktProperty.initializer?.let { generateInitializerBody(propertyDescriptor, it) }
val irProperty = IrSimplePropertyImpl(ktProperty.startOffset, ktProperty.endOffset, IrDeclarationOrigin.DEFINED,
propertyDescriptor, initializer)
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 = IrPropertyGetterImpl(ktGetter.startOffset, ktGetter.endOffset, IrDeclarationOrigin.DEFINED, getterDescriptor)
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 = IrPropertySetterImpl(ktSetter.startOffset, ktSetter.endOffset, IrDeclarationOrigin.DEFINED, setterDescriptor)
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)
@@ -46,20 +46,20 @@ class DelegatedPropertyGenerator(override val context: GeneratorContext) : Gener
ktDelegate: KtPropertyDelegate,
propertyDescriptor: PropertyDescriptor,
irDelegateInitializer: IrExpressionBody
): IrDelegatedProperty {
): IrProperty {
val delegateDescriptor = createPropertyDelegateDescriptor(ktDelegate, propertyDescriptor)
val irDelegate = IrSimplePropertyImpl(
val irDelegate = IrFieldImpl(
ktDelegate.startOffset, ktDelegate.endOffset, IrDeclarationOrigin.DELEGATE,
delegateDescriptor, irDelegateInitializer)
val irProperty = IrDelegatedPropertyImpl(
ktProperty.startOffset, ktProperty.endOffset, IrDeclarationOrigin.DEFINED,
val irProperty = IrPropertyImpl(
ktProperty.startOffset, ktProperty.endOffset, IrDeclarationOrigin.DEFINED, true,
propertyDescriptor, irDelegate)
val delegateReceiverValue = createBackingFieldValueForDelegate(delegateDescriptor, ktDelegate)
val getterDescriptor = propertyDescriptor.getter!!
irProperty.getter = IrPropertyGetterImpl(
irProperty.getter = IrFunctionImpl(
ktDelegate.startOffset, ktDelegate.endOffset, IrDeclarationOrigin.DELEGATED_PROPERTY_ACCESSOR,
getterDescriptor,
generateDelegatedPropertyGetterBody(
@@ -68,7 +68,7 @@ class DelegatedPropertyGenerator(override val context: GeneratorContext) : Gener
if (propertyDescriptor.isVar) {
val setterDescriptor = propertyDescriptor.setter!!
irProperty.setter = IrPropertySetterImpl(
irProperty.setter = IrFunctionImpl(
ktDelegate.startOffset, ktDelegate.endOffset, IrDeclarationOrigin.DELEGATED_PROPERTY_ACCESSOR,
setterDescriptor,
generateDelegatedPropertySetterBody(
@@ -89,14 +89,14 @@ class DelegatedPropertyGenerator(override val context: GeneratorContext) : Gener
private fun createCallableReference(ktElement: KtElement, type: KotlinType, referencedDescriptor: CallableDescriptor): IrCallableReference =
IrCallableReferenceImpl(ktElement.startOffset, ktElement.endOffset, type,
referencedDescriptor, IrOperator.PROPERTY_REFERENCE_FOR_DELEGATE)
referencedDescriptor, IrOperator.PROPERTY_REFERENCE_FOR_DELEGATE)
fun generateLocalDelegatedProperty(
ktProperty: KtProperty,
ktDelegate: KtPropertyDelegate,
variableDescriptor: VariableDescriptorWithAccessors,
irDelegateInitializer: IrExpression
) : IrLocalDelegatedProperty {
): IrLocalDelegatedProperty {
val delegateDescriptor = createLocalPropertyDelegatedDescriptor(ktDelegate, variableDescriptor)
val irDelegate = IrVariableImpl(
@@ -132,8 +132,8 @@ class DelegatedPropertyGenerator(override val context: GeneratorContext) : Gener
VariableLValue(ktDelegate.startOffset, ktDelegate.endOffset, delegateDescriptor)
private fun createLocalPropertyAccessor(getterDescriptor: VariableAccessorDescriptor, ktDelegate: KtPropertyDelegate, body: IrBody) =
IrLocalPropertyAccessorImpl(ktDelegate.startOffset, ktDelegate.endOffset, IrDeclarationOrigin.DELEGATED_PROPERTY_ACCESSOR,
getterDescriptor, body)
IrFunctionImpl(ktDelegate.startOffset, ktDelegate.endOffset, IrDeclarationOrigin.DELEGATED_PROPERTY_ACCESSOR,
getterDescriptor, body)
private fun createLocalPropertyDelegatedDescriptor(
ktDelegate: KtPropertyDelegate,
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.psi2ir.generators
import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrGeneralFunction
import org.jetbrains.kotlin.ir.declarations.IrFunction
import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrBlockImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrCallableReferenceImpl
@@ -64,7 +64,7 @@ class LocalFunctionGenerator(statementGenerator: StatementGenerator) : Statement
irBlock
}
private fun generateFunctionDeclaration(ktFun: KtNamedFunction): IrGeneralFunction {
private fun generateFunctionDeclaration(ktFun: KtNamedFunction): IrFunction {
val funDescriptor = getOrFail(BindingContext.FUNCTION, ktFun)
val irFun = IrFunctionImpl(ktFun.startOffset, ktFun.endOffset, IrDeclarationOrigin.DEFINED, funDescriptor)
irFun.body = BodyGenerator(funDescriptor, statementGenerator.context).generateFunctionBody(ktFun.bodyExpression!!)
@@ -18,8 +18,8 @@ package org.jetbrains.kotlin.psi2ir.intermediate
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.ir.expressions.*
import org.jetbrains.kotlin.ir.expressions.impl.IrGetBackingFieldImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrSetBackingFieldImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrGetFieldImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrSetFieldImpl
import org.jetbrains.kotlin.types.KotlinType
class BackingFieldLValue(
@@ -32,10 +32,10 @@ class BackingFieldLValue(
override val type: KotlinType get() = descriptor.type
override fun store(irExpression: IrExpression): IrExpression =
IrSetBackingFieldImpl(startOffset, endOffset, descriptor, receiver?.load(), irExpression, operator)
IrSetFieldImpl(startOffset, endOffset, descriptor, receiver?.load(), irExpression, operator)
override fun load(): IrExpression =
IrGetBackingFieldImpl(startOffset, endOffset, descriptor, receiver?.load(), operator)
IrGetFieldImpl(startOffset, endOffset, descriptor, receiver?.load(), operator)
override fun assign(withLValue: (LValue) -> IrExpression): IrExpression =
withLValue(this)
@@ -44,8 +44,8 @@ class SimplePropertyLValue(
extensionReceiverValue?.load(),
irOperator,
superQualifier)
} ?: IrGetBackingFieldImpl(startOffset, endOffset, descriptor,
dispatchReceiverValue?.load(), irOperator, superQualifier)
} ?: IrGetFieldImpl(startOffset, endOffset, descriptor,
dispatchReceiverValue?.load(), irOperator, superQualifier)
}
override fun store(irExpression: IrExpression) =
@@ -57,8 +57,8 @@ class SimplePropertyLValue(
irExpression,
irOperator,
superQualifier)
} ?: IrSetBackingFieldImpl(startOffset, endOffset, descriptor,
dispatchReceiverValue?.load(), irExpression, irOperator, superQualifier)
} ?: IrSetFieldImpl(startOffset, endOffset, descriptor,
dispatchReceiverValue?.load(), irExpression, irOperator, superQualifier)
}
override fun assign(withLValue: (LValue) -> IrExpression) =
@@ -79,7 +79,7 @@ class InsertImplicitCasts(val builtIns: KotlinBuiltIns): IrElementVisitorVoid {
expression.value.replaceWithCast(expression.descriptor.type)
}
override fun visitSetBackingField(expression: IrSetBackingField) {
override fun visitSetBackingField(expression: IrSetField) {
expression.acceptChildrenVoid(this)
expression.value.replaceWithCast(expression.descriptor.type)
@@ -44,6 +44,7 @@ const val TRY_RESULT_SLOT = -13
const val FINALLY_EXPRESSION_SLOT = -14
const val PROPERTY_GETTER_SLOT = -15
const val PROPERTY_SETTER_SLOT = -16
const val DELEGATE_SLOT = -17
const val BACKING_FIELD_SLOT = -17
const val ENUM_ENTRY_CLASS_SLOT = -18
const val ENUM_ENTRY_INITIALIZER_SLOT = -19
const val ENUM_ENTRY_INITIALIZER_SLOT = -19
const val LOCAL_DELEGATE_SLOT = -20
@@ -32,10 +32,10 @@ fun IrClass.getInstanceInitializerMembers() =
when (it) {
is IrAnonymousInitializer ->
true
is IrSimpleProperty ->
is IrProperty ->
it.backingField?.initializer != null
is IrField ->
it.initializer != null
is IrDelegatedProperty ->
true
else -> false
}
}
@@ -33,6 +33,7 @@ enum class IrDeclarationKind {
FUNCTION,
CONSTRUCTOR,
PROPERTY,
FIELD,
PROPERTY_ACCESSOR,
VARIABLE,
LOCAL_PROPERTY,
@@ -44,6 +45,8 @@ enum class IrDeclarationKind {
enum class IrDeclarationOrigin {
DEFINED,
PROPERTY_BACKING_FIELD,
DEFAULT_PROPERTY_ACCESSOR,
DELEGATE,
DELEGATED_PROPERTY_ACCESSOR,
DELEGATED_MEMBER,
@@ -21,15 +21,13 @@ import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.ir.expressions.IrBody
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
interface IrGeneralFunction : IrDeclaration {
interface IrFunction : IrDeclaration {
override val descriptor: FunctionDescriptor
var body: IrBody?
override val declarationKind: IrDeclarationKind
get() = IrDeclarationKind.FUNCTION
}
interface IrFunction : IrGeneralFunction {
fun putDefault(parameter: ValueParameterDescriptor, expressionBody: IrExpressionBody)
fun getDefault(parameter: ValueParameterDescriptor): IrExpressionBody?
}
@@ -22,17 +22,9 @@ import org.jetbrains.kotlin.descriptors.VariableDescriptorWithAccessors
interface IrLocalDelegatedProperty : IrDeclaration {
override val descriptor: VariableDescriptorWithAccessors
var delegate: IrVariable
var getter: IrLocalPropertyAccessor
var setter: IrLocalPropertyAccessor?
var getter: IrFunction
var setter: IrFunction?
override val declarationKind: IrDeclarationKind
get() = IrDeclarationKind.LOCAL_PROPERTY
}
interface IrLocalPropertyAccessor : IrGeneralFunction {
override val descriptor: VariableAccessorDescriptor
override val declarationKind: IrDeclarationKind
get() = IrDeclarationKind.LOCAL_PROPERTY_ACCESSOR
}
@@ -17,22 +17,24 @@
package org.jetbrains.kotlin.ir.declarations
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.ir.expressions.IrBody
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
interface IrProperty : IrDeclaration {
override val descriptor: PropertyDescriptor
var getter: IrPropertyGetter?
var setter: IrPropertySetter?
val isDelegated: Boolean
var backingField: IrField?
var getter: IrFunction?
var setter: IrFunction?
override val declarationKind: IrDeclarationKind
get() = IrDeclarationKind.PROPERTY
}
interface IrSimpleProperty : IrProperty {
var initializer: IrBody?
}
interface IrField : IrDeclaration {
override val descriptor: PropertyDescriptor
interface IrDelegatedProperty : IrProperty {
var delegate: IrSimpleProperty
}
override val declarationKind: IrDeclarationKind
get() = IrDeclarationKind.FIELD
var initializer: IrExpressionBody?
}
@@ -1,39 +0,0 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.ir.declarations
import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor
import org.jetbrains.kotlin.descriptors.PropertyGetterDescriptor
import org.jetbrains.kotlin.descriptors.PropertySetterDescriptor
interface IrPropertyAccessor : IrGeneralFunction {
override val descriptor: PropertyAccessorDescriptor
override val declarationKind: IrDeclarationKind
get() = IrDeclarationKind.PROPERTY_ACCESSOR
}
interface IrPropertyGetter : IrPropertyAccessor {
override val descriptor: PropertyGetterDescriptor
}
interface IrPropertySetter : IrPropertyAccessor {
override val descriptor: PropertySetterDescriptor
}
@@ -1,72 +0,0 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.ir.declarations.impl
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.ir.*
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrDelegatedProperty
import org.jetbrains.kotlin.ir.declarations.IrSimpleProperty
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
class IrDelegatedPropertyImpl(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
descriptor: PropertyDescriptor
) : IrPropertyBase(startOffset, endOffset, origin, descriptor), IrDelegatedProperty {
constructor(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
descriptor: PropertyDescriptor,
delegate: IrSimpleProperty
) : this(startOffset, endOffset, origin, descriptor) {
this.delegate = delegate
}
private var delegateImpl: IrSimpleProperty? = null
override var delegate: IrSimpleProperty
get() = delegateImpl!!
set(value) {
delegateImpl?.detach()
delegateImpl = value
value.setTreeLocation(this, DELEGATE_SLOT)
}
override fun getChild(slot: Int): IrElement? =
when (slot) {
DELEGATE_SLOT -> delegate
else -> super.getChild(slot)
}
override fun replaceChild(slot: Int, newChild: IrElement) {
when (slot) {
DELEGATE_SLOT -> delegate = newChild.assertCast()
else -> super.replaceChild(slot, newChild)
}
}
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitDelegatedProperty(this, data)
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
delegate.accept(visitor, data)
getter?.accept(visitor, data)
setter?.accept(visitor, data)
}
}
@@ -19,18 +19,24 @@ package org.jetbrains.kotlin.ir.declarations.impl
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.ir.*
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrSimpleProperty
import org.jetbrains.kotlin.ir.expressions.IrBody
import org.jetbrains.kotlin.ir.declarations.IrField
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
class IrSimplePropertyImpl(
class IrFieldImpl(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
descriptor: PropertyDescriptor,
valueInitializer: IrBody? = null
) : IrPropertyBase(startOffset, endOffset, origin, descriptor), IrSimpleProperty {
override var initializer: IrBody? = valueInitializer
override val descriptor: PropertyDescriptor
): IrDeclarationBase(startOffset, endOffset, origin), IrField {
constructor(startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, descriptor: PropertyDescriptor,
initializer: IrExpressionBody?
) : this(startOffset, endOffset, origin, descriptor) {
this.initializer = initializer
}
override var initializer: IrExpressionBody? = null
set(value) {
field?.detach()
field = value
@@ -40,22 +46,21 @@ class IrSimplePropertyImpl(
override fun getChild(slot: Int): IrElement? =
when (slot) {
INITIALIZER_SLOT -> initializer
else -> super.getChild(slot)
else -> null
}
override fun replaceChild(slot: Int, newChild: IrElement) {
when (slot) {
INITIALIZER_SLOT -> initializer = newChild.assertCast()
else -> super.replaceChild(slot, newChild)
else -> throwNoSuchSlot(slot)
}
}
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitSimpleProperty(this, data)
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R {
return visitor.visitField(this, data)
}
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
initializer?.accept(visitor, data)
getter?.accept(visitor, data)
setter?.accept(visitor, data)
}
}
@@ -18,8 +18,7 @@ package org.jetbrains.kotlin.ir.declarations.impl
import org.jetbrains.kotlin.ir.*
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrGeneralFunction
import org.jetbrains.kotlin.ir.declarations.impl.IrDeclarationBase
import org.jetbrains.kotlin.ir.declarations.IrFunction
import org.jetbrains.kotlin.ir.expressions.IrBody
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
@@ -27,16 +26,7 @@ abstract class IrGeneralFunctionBase(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin
) : IrDeclarationBase(startOffset, endOffset, origin), IrGeneralFunction {
constructor(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
body: IrBody
) : this(startOffset, endOffset, origin) {
this.body = body
}
) : IrDeclarationBase(startOffset, endOffset, origin), IrFunction {
final override var body: IrBody? = null
set(newValue) {
field?.detach()
@@ -18,10 +18,7 @@ package org.jetbrains.kotlin.ir.declarations.impl
import org.jetbrains.kotlin.descriptors.VariableDescriptorWithAccessors
import org.jetbrains.kotlin.ir.*
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrLocalDelegatedProperty
import org.jetbrains.kotlin.ir.declarations.IrLocalPropertyAccessor
import org.jetbrains.kotlin.ir.declarations.IrVariable
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.declarations.impl.IrDeclarationBase
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
@@ -47,11 +44,11 @@ class IrLocalDelegatedPropertyImpl(
set(value) {
delegateImpl?.detach()
delegateImpl = value
value.setTreeLocation(this, DELEGATE_SLOT)
value.setTreeLocation(this, LOCAL_DELEGATE_SLOT)
}
private var getterImpl: IrLocalPropertyAccessor? = null
override var getter: IrLocalPropertyAccessor
private var getterImpl: IrFunction? = null
override var getter: IrFunction
get() = getterImpl!!
set(value) {
getterImpl?.detach()
@@ -59,7 +56,7 @@ class IrLocalDelegatedPropertyImpl(
value.setTreeLocation(this, PROPERTY_GETTER_SLOT)
}
override var setter: IrLocalPropertyAccessor? = null
override var setter: IrFunction? = null
set(value) {
field?.detach()
field = value
@@ -68,7 +65,7 @@ class IrLocalDelegatedPropertyImpl(
override fun getChild(slot: Int): IrElement? =
when (slot) {
DELEGATE_SLOT -> delegate
LOCAL_DELEGATE_SLOT -> delegate
PROPERTY_GETTER_SLOT -> getter
PROPERTY_SETTER_SLOT -> setter
else -> null
@@ -76,7 +73,7 @@ class IrLocalDelegatedPropertyImpl(
override fun replaceChild(slot: Int, newChild: IrElement) {
when (slot) {
DELEGATE_SLOT -> delegate = newChild.assertCast()
LOCAL_DELEGATE_SLOT -> delegate = newChild.assertCast()
PROPERTY_GETTER_SLOT -> getter = newChild.assertCast()
PROPERTY_SETTER_SLOT -> setter = newChild.assertCast()
else -> throwNoSuchSlot(slot)
@@ -1,44 +0,0 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.ir.declarations.impl
import org.jetbrains.kotlin.descriptors.VariableAccessorDescriptor
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrLocalPropertyAccessor
import org.jetbrains.kotlin.ir.expressions.IrBody
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
class IrLocalPropertyAccessorImpl(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
override val descriptor: VariableAccessorDescriptor
) : IrGeneralFunctionBase(startOffset, endOffset, origin), IrLocalPropertyAccessor {
constructor(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
descriptor: VariableAccessorDescriptor,
body: IrBody
) : this(startOffset, endOffset, origin, descriptor) {
this.body = body
}
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R {
return visitor.visitLocalPropertyAccessor(this, data)
}
}
@@ -1,26 +0,0 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.ir.declarations.impl
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrPropertyAccessor
abstract class IrPropertyAccessorBase(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin
) : IrGeneralFunctionBase(startOffset, endOffset, origin), IrPropertyAccessor
@@ -1,61 +0,0 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.ir.declarations.impl
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.ir.*
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrProperty
import org.jetbrains.kotlin.ir.declarations.IrPropertyGetter
import org.jetbrains.kotlin.ir.declarations.IrPropertySetter
import org.jetbrains.kotlin.ir.declarations.impl.IrDeclarationBase
abstract class IrPropertyBase(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
override val descriptor: PropertyDescriptor
) : IrDeclarationBase(startOffset, endOffset, origin), IrProperty {
override var getter: IrPropertyGetter? = null
set(newGetter) {
field?.detach()
field = newGetter
newGetter?.setTreeLocation(this, PROPERTY_GETTER_SLOT)
}
override var setter: IrPropertySetter? = null
set(newSetter) {
field?.detach()
field = newSetter
newSetter?.setTreeLocation(this, PROPERTY_SETTER_SLOT)
}
override fun getChild(slot: Int): IrElement? =
when (slot) {
PROPERTY_GETTER_SLOT -> getter
PROPERTY_SETTER_SLOT -> setter
else -> null
}
override fun replaceChild(slot: Int, newChild: IrElement) {
when (slot) {
PROPERTY_GETTER_SLOT -> getter = newChild.assertCast()
PROPERTY_SETTER_SLOT -> setter = newChild.assertCast()
else -> throwNoSuchSlot(slot)
}
}
}
@@ -1,43 +0,0 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.ir.declarations.impl
import org.jetbrains.kotlin.descriptors.PropertyGetterDescriptor
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrPropertyGetter
import org.jetbrains.kotlin.ir.expressions.IrBody
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
class IrPropertyGetterImpl(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
override val descriptor: PropertyGetterDescriptor
) : IrPropertyAccessorBase(startOffset, endOffset, origin), IrPropertyGetter {
constructor(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
descriptor: PropertyGetterDescriptor,
body: IrBody
) : this(startOffset, endOffset, origin, descriptor) {
this.body = body
}
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitPropertyGetter(this, data)
}
@@ -0,0 +1,96 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.ir.declarations.impl
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.ir.*
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrField
import org.jetbrains.kotlin.ir.declarations.IrFunction
import org.jetbrains.kotlin.ir.declarations.IrProperty
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
class IrPropertyImpl(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
override val isDelegated: Boolean,
override val descriptor: PropertyDescriptor
) : IrDeclarationBase(startOffset, endOffset, origin), IrProperty {
constructor(
startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, isDelegated: Boolean, descriptor: PropertyDescriptor,
backingField: IrField?
) : this(startOffset, endOffset, origin, isDelegated, descriptor) {
this.backingField = backingField
}
constructor(
startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, isDelegated: Boolean, descriptor: PropertyDescriptor,
backingField: IrField?, getter: IrFunction?, setter: IrFunction?
) : this(startOffset, endOffset, origin, isDelegated, descriptor, backingField) {
this.getter = getter
this.setter = setter
}
override var backingField: IrField? = null
set(value) {
field?.detach()
field = value
value?.setTreeLocation(this, BACKING_FIELD_SLOT)
}
override var getter: IrFunction? = null
set(value) {
field?.detach()
field = value
value?.setTreeLocation(this, PROPERTY_GETTER_SLOT)
}
override var setter: IrFunction? = null
set(value) {
field?.detach()
field = value
value?.setTreeLocation(this, PROPERTY_SETTER_SLOT)
}
override fun getChild(slot: Int): IrElement? =
when (slot) {
BACKING_FIELD_SLOT -> backingField
PROPERTY_GETTER_SLOT -> getter
PROPERTY_SETTER_SLOT -> setter
else -> null
}
override fun replaceChild(slot: Int, newChild: IrElement) {
when (slot) {
BACKING_FIELD_SLOT -> backingField = newChild.assertCast()
PROPERTY_GETTER_SLOT -> getter = newChild.assertCast()
PROPERTY_SETTER_SLOT -> setter = newChild.assertCast()
else -> throwNoSuchSlot(slot)
}
}
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R {
return visitor.visitProperty(this, data)
}
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
backingField?.accept(visitor, data)
getter?.accept(visitor, data)
setter?.accept(visitor, data)
}
}
@@ -1,43 +0,0 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.ir.declarations.impl
import org.jetbrains.kotlin.descriptors.PropertySetterDescriptor
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrPropertySetter
import org.jetbrains.kotlin.ir.expressions.IrBody
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
class IrPropertySetterImpl(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
override val descriptor: PropertySetterDescriptor
) : IrPropertyAccessorBase(startOffset, endOffset, origin), IrPropertySetter {
constructor(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
descriptor: PropertySetterDescriptor,
body: IrBody
) : this(startOffset, endOffset, origin, descriptor) {
this.body = body
}
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitPropertySetter(this, data)
}
@@ -19,15 +19,15 @@ package org.jetbrains.kotlin.ir.expressions
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
interface IrBackingFieldExpression : IrDeclarationReference {
interface IrFieldExpression : IrDeclarationReference {
override val descriptor: PropertyDescriptor
val superQualifier: ClassDescriptor?
var receiver: IrExpression?
val operator: IrOperator?
}
interface IrGetBackingField : IrBackingFieldExpression
interface IrGetField : IrFieldExpression
interface IrSetBackingField : IrBackingFieldExpression {
interface IrSetField : IrFieldExpression {
var value: IrExpression
}
@@ -19,19 +19,19 @@ package org.jetbrains.kotlin.ir.expressions.impl
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.ir.*
import org.jetbrains.kotlin.ir.expressions.IrBackingFieldExpression
import org.jetbrains.kotlin.ir.expressions.IrFieldExpression
import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.ir.expressions.IrOperator
import org.jetbrains.kotlin.types.KotlinType
abstract class IrBackingFieldExpressionBase(
abstract class IrFieldExpressionBase(
startOffset: Int,
endOffset: Int,
descriptor: PropertyDescriptor,
type: KotlinType,
override val operator: IrOperator? = null,
override val superQualifier: ClassDescriptor? = null
) : IrDeclarationReferenceBase<PropertyDescriptor>(startOffset, endOffset, type, descriptor), IrBackingFieldExpression {
) : IrDeclarationReferenceBase<PropertyDescriptor>(startOffset, endOffset, type, descriptor), IrFieldExpression {
override final var receiver: IrExpression? = null
set(value) {
field?.detach()
@@ -20,17 +20,17 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.ir.expressions.IrGetBackingField
import org.jetbrains.kotlin.ir.expressions.IrGetField
import org.jetbrains.kotlin.ir.expressions.IrOperator
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
class IrGetBackingFieldImpl(
class IrGetFieldImpl(
startOffset: Int,
endOffset: Int,
descriptor: PropertyDescriptor,
operator: IrOperator? = null,
superQualifier: ClassDescriptor? = null
) : IrBackingFieldExpressionBase(startOffset, endOffset, descriptor, descriptor.type, operator, superQualifier), IrGetBackingField {
) : IrFieldExpressionBase(startOffset, endOffset, descriptor, descriptor.type, operator, superQualifier), IrGetField {
constructor(
startOffset: Int,
endOffset: Int,
@@ -50,7 +50,7 @@ class IrGetBackingFieldImpl(
}
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R {
return visitor.visitGetBackingField(this, data)
return visitor.visitGetField(this, data)
}
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
@@ -21,18 +21,18 @@ import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.ir.*
import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.ir.expressions.IrOperator
import org.jetbrains.kotlin.ir.expressions.IrSetBackingField
import org.jetbrains.kotlin.ir.expressions.impl.IrBackingFieldExpressionBase
import org.jetbrains.kotlin.ir.expressions.IrSetField
import org.jetbrains.kotlin.ir.expressions.impl.IrFieldExpressionBase
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
import org.jetbrains.kotlin.types.typeUtil.builtIns
class IrSetBackingFieldImpl(
class IrSetFieldImpl(
startOffset: Int,
endOffset: Int,
descriptor: PropertyDescriptor,
operator: IrOperator? = null,
superQualifier: ClassDescriptor? = null
) : IrBackingFieldExpressionBase(startOffset, endOffset, descriptor, descriptor.type.builtIns.unitType, operator, superQualifier), IrSetBackingField {
) : IrFieldExpressionBase(startOffset, endOffset, descriptor, descriptor.type.builtIns.unitType, operator, superQualifier), IrSetField {
constructor(
startOffset: Int,
endOffset: Int,
@@ -69,7 +69,7 @@ class IrSetBackingFieldImpl(
}
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R {
return visitor.visitSetBackingField(this, data)
return visitor.visitSetField(this, data)
}
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
@@ -72,14 +72,6 @@ class DumpIrTreeVisitor(out: Appendable): IrElementVisitor<Unit, String> {
visitFunctionWithParameters(declaration, data)
}
override fun visitDelegatedProperty(declaration: IrDelegatedProperty, data: String) {
declaration.dumpLabeledElementWith(data) {
declaration.delegate.accept(this, "delegate")
declaration.getter?.accept(this, "")
declaration.setter?.accept(this, "")
}
}
override fun visitErrorCallExpression(expression: IrErrorCallExpression, data: String) {
expression.dumpLabeledElementWith(data) {
expression.explicitReceiver?.accept(this, "receiver")
@@ -113,13 +105,13 @@ class DumpIrTreeVisitor(out: Appendable): IrElementVisitor<Unit, String> {
}
}
override fun visitGetBackingField(expression: IrGetBackingField, data: String) {
override fun visitGetField(expression: IrGetField, data: String) {
expression.dumpLabeledElementWith(data) {
expression.receiver?.accept(this, "receiver")
}
}
override fun visitSetBackingField(expression: IrSetBackingField, data: String) {
override fun visitSetField(expression: IrSetField, data: String) {
expression.dumpLabeledElementWith(data) {
expression.receiver?.accept(this, "receiver")
expression.value.accept(this, "value")
@@ -51,11 +51,8 @@ class RenderIrElementVisitor : IrElementVisitor<String, Nothing?> {
override fun visitProperty(declaration: IrProperty, data: Nothing?): String =
"PROPERTY ${declaration.renderDeclared()}"
override fun visitPropertyGetter(declaration: IrPropertyGetter, data: Nothing?): String =
"PROPERTY_GETTER ${declaration.renderDeclared()}"
override fun visitPropertySetter(declaration: IrPropertySetter, data: Nothing?): String =
"PROPERTY_SETTER ${declaration.renderDeclared()}"
override fun visitField(declaration: IrField, data: Nothing?): String =
"FIELD ${declaration.renderDeclared()}"
override fun visitClass(declaration: IrClass, data: Nothing?): String =
"CLASS ${declaration.descriptor.kind} ${declaration.descriptor.ref()}"
@@ -75,9 +72,6 @@ class RenderIrElementVisitor : IrElementVisitor<String, Nothing?> {
override fun visitLocalDelegatedProperty(declaration: IrLocalDelegatedProperty, data: Nothing?): String =
"LOCAL_DELEGATED_PROPERTY ${declaration.renderDeclared()}"
override fun visitLocalPropertyAccessor(declaration: IrLocalPropertyAccessor, data: Nothing?): String =
"LOCAL_PROPERTY_ACCESSOR ${declaration.descriptor.ref()}" // can't render, see nullability for modality
override fun visitExpressionBody(body: IrExpressionBody, data: Nothing?): String =
"EXPRESSION_BODY"
@@ -140,10 +134,10 @@ class RenderIrElementVisitor : IrElementVisitor<String, Nothing?> {
override fun visitSetVariable(expression: IrSetVariable, data: Nothing?): String =
"SET_VAR '${expression.descriptor.ref()}' type=${expression.type.render()} operator=${expression.operator}"
override fun visitGetBackingField(expression: IrGetBackingField, data: Nothing?): String =
override fun visitGetField(expression: IrGetField, data: Nothing?): String =
"GET_BACKING_FIELD '${expression.descriptor.ref()}' type=${expression.type.render()} operator=${expression.operator}"
override fun visitSetBackingField(expression: IrSetBackingField, data: Nothing?): String =
override fun visitSetField(expression: IrSetField, data: Nothing?): String =
"SET_BACKING_FIELD '${expression.descriptor.ref()}' type=${expression.type.render()} operator=${expression.operator}"
override fun visitGetObjectValue(expression: IrGetObjectValue, data: Nothing?): String =
@@ -28,16 +28,11 @@ interface IrElementVisitor<out R, in D> {
fun visitDeclaration(declaration: IrDeclaration, data: D) = visitElement(declaration, data)
fun visitClass(declaration: IrClass, data: D) = visitDeclaration(declaration, data)
fun visitTypeAlias(declaration: IrTypeAlias, data: D) = visitDeclaration(declaration, data)
fun visitGeneralFunction(declaration: IrGeneralFunction, data: D) = visitDeclaration(declaration, data)
fun visitFunction(declaration: IrFunction, data: D) = visitGeneralFunction(declaration, data)
fun visitPropertyGetter(declaration: IrPropertyGetter, data: D) = visitGeneralFunction(declaration, data)
fun visitPropertySetter(declaration: IrPropertySetter, data: D) = visitGeneralFunction(declaration, data)
fun visitConstructor(declaration: IrConstructor, data: D) = visitGeneralFunction(declaration, data)
fun visitFunction(declaration: IrFunction, data: D) = visitDeclaration(declaration, data)
fun visitConstructor(declaration: IrConstructor, data: D) = visitFunction(declaration, data)
fun visitProperty(declaration: IrProperty, data: D) = visitDeclaration(declaration, data)
fun visitSimpleProperty(declaration: IrSimpleProperty, data: D) = visitProperty(declaration, data)
fun visitDelegatedProperty(declaration: IrDelegatedProperty, data: D) = visitProperty(declaration, data)
fun visitField(declaration: IrField, data: D) = visitDeclaration(declaration, data)
fun visitLocalDelegatedProperty(declaration: IrLocalDelegatedProperty, data: D) = visitDeclaration(declaration, data)
fun visitLocalPropertyAccessor(declaration: IrLocalPropertyAccessor, data: D) = visitGeneralFunction(declaration, data)
fun visitVariable(declaration: IrVariable, data: D) = visitDeclaration(declaration, data)
fun visitEnumEntry(declaration: IrEnumEntry, data: D) = visitDeclaration(declaration, data)
fun visitAnonymousInitializer(declaration: IrAnonymousInitializer, data: D) = visitDeclaration(declaration, data)
@@ -65,9 +60,9 @@ interface IrElementVisitor<out R, in D> {
fun visitVariableAccess(expression: IrVariableAccessExpression, data: D) = visitDeclarationReference(expression, data)
fun visitGetVariable(expression: IrGetVariable, data: D) = visitVariableAccess(expression, data)
fun visitSetVariable(expression: IrSetVariable, data: D) = visitVariableAccess(expression, data)
fun visitBackingFieldReference(expression: IrBackingFieldExpression, data: D) = visitDeclarationReference(expression, data)
fun visitGetBackingField(expression: IrGetBackingField, data: D) = visitBackingFieldReference(expression, data)
fun visitSetBackingField(expression: IrSetBackingField, data: D) = visitBackingFieldReference(expression, data)
fun visitBackingFieldReference(expression: IrFieldExpression, data: D) = visitDeclarationReference(expression, data)
fun visitGetField(expression: IrGetField, data: D) = visitBackingFieldReference(expression, data)
fun visitSetField(expression: IrSetField, data: D) = visitBackingFieldReference(expression, data)
fun visitGetExtensionReceiver(expression: IrGetExtensionReceiver, data: D) = visitDeclarationReference(expression, data)
fun visitGeneralCall(expression: IrGeneralCall, data: D) = visitDeclarationReference(expression, data)
fun visitCall(expression: IrCall, data: D) = visitGeneralCall(expression, data)
@@ -39,36 +39,21 @@ interface IrElementVisitorVoid : IrElementVisitor<Unit, Nothing?> {
fun visitTypeAlias(declaration: IrTypeAlias) = visitDeclaration(declaration)
override fun visitTypeAlias(declaration: IrTypeAlias, data: Nothing?) = visitTypeAlias(declaration)
fun visitGeneralFunction(declaration: IrGeneralFunction) = visitDeclaration(declaration)
override fun visitGeneralFunction(declaration: IrGeneralFunction, data: Nothing?) = visitGeneralFunction(declaration)
fun visitFunction(declaration: IrFunction) = visitGeneralFunction(declaration)
fun visitFunction(declaration: IrFunction) = visitDeclaration(declaration)
override fun visitFunction(declaration: IrFunction, data: Nothing?) = visitFunction(declaration)
fun visitPropertyGetter(declaration: IrPropertyGetter) = visitGeneralFunction(declaration)
override fun visitPropertyGetter(declaration: IrPropertyGetter, data: Nothing?) = visitPropertyGetter(declaration)
fun visitPropertySetter(declaration: IrPropertySetter) = visitGeneralFunction(declaration)
override fun visitPropertySetter(declaration: IrPropertySetter, data: Nothing?) = visitPropertySetter(declaration)
fun visitConstructor(declaration: IrConstructor) = visitGeneralFunction(declaration)
fun visitConstructor(declaration: IrConstructor) = visitFunction(declaration)
override fun visitConstructor(declaration: IrConstructor, data: Nothing?) = visitConstructor(declaration)
fun visitProperty(declaration: IrProperty) = visitDeclaration(declaration)
override fun visitProperty(declaration: IrProperty, data: Nothing?) = visitProperty(declaration)
fun visitSimpleProperty(declaration: IrSimpleProperty) = visitProperty(declaration)
override fun visitSimpleProperty(declaration: IrSimpleProperty, data: Nothing?) = visitSimpleProperty(declaration)
fun visitDelegatedProperty(declaration: IrDelegatedProperty) = visitProperty(declaration)
override fun visitDelegatedProperty(declaration: IrDelegatedProperty, data: Nothing?) = visitDelegatedProperty(declaration)
fun visitField(declaration: IrField) = visitDeclaration(declaration)
override fun visitField(declaration: IrField, data: Nothing?) = visitField(declaration)
fun visitLocalDelegatedProperty(declaration: IrLocalDelegatedProperty) = visitDeclaration(declaration)
override fun visitLocalDelegatedProperty(declaration: IrLocalDelegatedProperty, data: Nothing?) = visitLocalDelegatedProperty(declaration)
fun visitLocalPropertyAccessor(declaration: IrLocalPropertyAccessor) = visitGeneralFunction(declaration)
override fun visitLocalPropertyAccessor(declaration: IrLocalPropertyAccessor, data: Nothing?) = visitLocalPropertyAccessor(declaration)
fun visitVariable(declaration: IrVariable) = visitDeclaration(declaration)
override fun visitVariable(declaration: IrVariable, data: Nothing?) = visitVariable(declaration)
@@ -138,14 +123,14 @@ interface IrElementVisitorVoid : IrElementVisitor<Unit, Nothing?> {
fun visitSetVariable(expression: IrSetVariable) = visitVariableAccess(expression)
override fun visitSetVariable(expression: IrSetVariable, data: Nothing?) = visitSetVariable(expression)
fun visitBackingFieldReference(expression: IrBackingFieldExpression) = visitDeclarationReference(expression)
override fun visitBackingFieldReference(expression: IrBackingFieldExpression, data: Nothing?) = visitBackingFieldReference(expression)
fun visitBackingFieldReference(expression: IrFieldExpression) = visitDeclarationReference(expression)
override fun visitBackingFieldReference(expression: IrFieldExpression, data: Nothing?) = visitBackingFieldReference(expression)
fun visitGetBackingField(expression: IrGetBackingField) = visitBackingFieldReference(expression)
override fun visitGetBackingField(expression: IrGetBackingField, data: Nothing?) = visitGetBackingField(expression)
fun visitGetBackingField(expression: IrGetField) = visitBackingFieldReference(expression)
override fun visitGetField(expression: IrGetField, data: Nothing?) = visitGetBackingField(expression)
fun visitSetBackingField(expression: IrSetBackingField) = visitBackingFieldReference(expression)
override fun visitSetBackingField(expression: IrSetBackingField, data: Nothing?) = visitSetBackingField(expression)
fun visitSetBackingField(expression: IrSetField) = visitBackingFieldReference(expression)
override fun visitSetField(expression: IrSetField, data: Nothing?) = visitSetBackingField(expression)
fun visitGetExtensionReceiver(expression: IrGetExtensionReceiver) = visitDeclarationReference(expression)
override fun visitGetExtensionReceiver(expression: IrGetExtensionReceiver, data: Nothing?) = visitGetExtensionReceiver(expression)