IR: IrSimpleFunction.correspondingProperty: IrProperty?

Non-null for a property accessor, points to a corresponding property.
This commit is contained in:
Dmitry Petrov
2018-05-24 16:47:25 +03:00
parent 216dbf9637
commit ab455d6572
146 changed files with 604 additions and 20 deletions
@@ -191,7 +191,11 @@ class ClassGenerator(declarationGenerator: DeclarationGenerator) : DeclarationGe
irClass.addMember(generateDelegatedFunction(irDelegate, delegated, overridden))
}
private fun generateDelegatedFunction(irDelegate: IrField, delegated: FunctionDescriptor, overridden: FunctionDescriptor): IrFunction =
private fun generateDelegatedFunction(
irDelegate: IrField,
delegated: FunctionDescriptor,
overridden: FunctionDescriptor
): IrSimpleFunction =
context.symbolTable.declareSimpleFunctionWithOverrides(
irDelegate.startOffset, irDelegate.endOffset,
IrDeclarationOrigin.DELEGATED_MEMBER,
@@ -170,7 +170,7 @@ class DeclarationGenerator(override val context: GeneratorContext) : Generator {
propertyDescriptor.setter?.let { generateFakeOverrideFunction(it, ktElement) }
)
private fun generateFakeOverrideFunction(functionDescriptor: FunctionDescriptor, ktElement: KtElement): IrFunction =
private fun generateFakeOverrideFunction(functionDescriptor: FunctionDescriptor, ktElement: KtElement): IrSimpleFunction =
FunctionGenerator(this).generateFakeOverrideFunction(functionDescriptor, ktElement)
}
@@ -93,7 +93,7 @@ class DelegatedPropertyGenerator(declarationGenerator: DeclarationGenerator) : D
ktDelegate: KtPropertyDelegate,
accessorDescriptor: PropertyAccessorDescriptor,
generateBody: (IrFunction) -> IrBody
): IrFunction =
): IrSimpleFunction =
context.symbolTable.declareSimpleFunctionWithOverrides(
ktDelegate.startOffset, ktDelegate.endOffset,
IrDeclarationOrigin.DELEGATED_PROPERTY_ACCESSOR,
@@ -47,7 +47,7 @@ class FunctionGenerator(declarationGenerator: DeclarationGenerator) : Declaratio
ktFunction.bodyExpression?.let { generateFunctionBody(it) }
}
fun generateLambdaFunctionDeclaration(ktFunction: KtFunctionLiteral): IrFunction =
fun generateLambdaFunctionDeclaration(ktFunction: KtFunctionLiteral): IrSimpleFunction =
declareSimpleFunction(
ktFunction,
null,
@@ -57,7 +57,7 @@ class FunctionGenerator(declarationGenerator: DeclarationGenerator) : Declaratio
generateLambdaBody(ktFunction)
}
fun generateFakeOverrideFunction(functionDescriptor: FunctionDescriptor, ktElement: KtElement): IrFunction =
fun generateFakeOverrideFunction(functionDescriptor: FunctionDescriptor, ktElement: KtElement): IrSimpleFunction =
context.symbolTable.declareSimpleFunctionWithOverrides(
ktElement.startOffsetOrUndefined, ktElement.endOffsetOrUndefined,
IrDeclarationOrigin.FAKE_OVERRIDE,
@@ -113,7 +113,7 @@ class FunctionGenerator(declarationGenerator: DeclarationGenerator) : Declaratio
fun generateDefaultAccessorForPrimaryConstructorParameter(
descriptor: PropertyAccessorDescriptor,
ktParameter: KtParameter
): IrFunction =
): IrSimpleFunction =
context.symbolTable.declareSimpleFunctionWithOverrides(
ktParameter.startOffsetOrUndefined,
ktParameter.endOffsetOrUndefined,
@@ -113,19 +113,18 @@ class PropertyGenerator(declarationGenerator: DeclarationGenerator) : Declaratio
null
irProperty.getter = generateGetterIfRequired(ktProperty, propertyDescriptor)
irProperty.setter = generateSetterIfRequired(ktProperty, propertyDescriptor)
}
private fun PropertyDescriptor.hasBackingField(): Boolean =
get(BindingContext.BACKING_FIELD_REQUIRED, this) ?: false
private fun generateGetterIfRequired(ktProperty: KtProperty, property: PropertyDescriptor): IrFunction? {
private fun generateGetterIfRequired(ktProperty: KtProperty, property: PropertyDescriptor): IrSimpleFunction? {
val getter = property.getter ?: return null
return FunctionGenerator(declarationGenerator).generatePropertyAccessor(getter, ktProperty, ktProperty.getter)
}
private fun generateSetterIfRequired(ktProperty: KtProperty, property: PropertyDescriptor): IrFunction? {
private fun generateSetterIfRequired(ktProperty: KtProperty, property: PropertyDescriptor): IrSimpleFunction? {
if (!property.isVar) return null
val setter = property.setter ?: return null
return FunctionGenerator(declarationGenerator).generatePropertyAccessor(setter, ktProperty, ktProperty.setter)