Generate backing fields and initializers for external constants
This commit is contained in:
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.resolve.source.KotlinSourceElement
|
||||
fun PropertyDescriptor.hasBackingField(bindingContext: BindingContext?): Boolean = when {
|
||||
kind == CallableMemberDescriptor.Kind.FAKE_OVERRIDE -> overriddenDescriptors.any { it.hasBackingField(bindingContext) }
|
||||
source is KotlinSourceElement && bindingContext != null -> bindingContext.get(BindingContext.BACKING_FIELD_REQUIRED, this) ?: false
|
||||
compileTimeInitializer != null -> true
|
||||
getter != null -> false
|
||||
else -> true
|
||||
}
|
||||
|
||||
@@ -81,14 +81,11 @@ class DeclarationStubGenerator(
|
||||
|
||||
internal fun generatePropertyStub(descriptor: PropertyDescriptor, bindingContext: BindingContext? = null): IrProperty =
|
||||
IrPropertyImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor).also { irProperty ->
|
||||
val getterDescriptor = descriptor.getter
|
||||
if (descriptor.hasBackingField(bindingContext)) {
|
||||
irProperty.backingField = generateFieldStub(descriptor)
|
||||
}
|
||||
if (getterDescriptor != null) {
|
||||
irProperty.getter = generateFunctionStub(getterDescriptor)
|
||||
}
|
||||
|
||||
irProperty.getter = descriptor.getter?.let { generateFunctionStub(it) }
|
||||
irProperty.setter = descriptor.setter?.let { generateFunctionStub(it) }
|
||||
}
|
||||
|
||||
@@ -109,7 +106,15 @@ class DeclarationStubGenerator(
|
||||
origin,
|
||||
descriptor.original,
|
||||
descriptor.type.toIrType()
|
||||
)
|
||||
).apply {
|
||||
initializer = descriptor.compileTimeInitializer?.let {
|
||||
IrExpressionBodyImpl(
|
||||
constantValueGenerator.generateConstantValueAsExpression(
|
||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET, it
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun generateFunctionStub(descriptor: FunctionDescriptor): IrSimpleFunction {
|
||||
|
||||
@@ -217,15 +217,27 @@ CLASS IR_EXTERNAL_DECLARATION_STUB CLASS name:Int modality:FINAL visibility:publ
|
||||
$this: VALUE_PARAMETER IR_EXTERNAL_DECLARATION_STUB name:<this> type:kotlin.Int.Companion flags:
|
||||
CONSTRUCTOR IR_EXTERNAL_DECLARATION_STUB visibility:private <> () returnType:kotlin.Int.Companion flags:primary
|
||||
PROPERTY IR_EXTERNAL_DECLARATION_STUB name:MAX_VALUE visibility:public modality:FINAL flags:const,val
|
||||
FIELD IR_EXTERNAL_DECLARATION_STUB name:MAX_VALUE type:kotlin.Int visibility:public flags:final
|
||||
EXPRESSION_BODY
|
||||
CONST Int type=kotlin.Int value=2147483647
|
||||
FUN IR_EXTERNAL_DECLARATION_STUB name:<get-MAX_VALUE> visibility:public modality:FINAL <> ($this:kotlin.Int.Companion) returnType:kotlin.Int flags:
|
||||
$this: VALUE_PARAMETER IR_EXTERNAL_DECLARATION_STUB name:<this> type:kotlin.Int.Companion flags:
|
||||
PROPERTY IR_EXTERNAL_DECLARATION_STUB name:MIN_VALUE visibility:public modality:FINAL flags:const,val
|
||||
FIELD IR_EXTERNAL_DECLARATION_STUB name:MIN_VALUE type:kotlin.Int visibility:public flags:final
|
||||
EXPRESSION_BODY
|
||||
CONST Int type=kotlin.Int value=-2147483648
|
||||
FUN IR_EXTERNAL_DECLARATION_STUB name:<get-MIN_VALUE> visibility:public modality:FINAL <> ($this:kotlin.Int.Companion) returnType:kotlin.Int flags:
|
||||
$this: VALUE_PARAMETER IR_EXTERNAL_DECLARATION_STUB name:<this> type:kotlin.Int.Companion flags:
|
||||
PROPERTY IR_EXTERNAL_DECLARATION_STUB name:SIZE_BITS visibility:public modality:FINAL flags:const,val
|
||||
FIELD IR_EXTERNAL_DECLARATION_STUB name:SIZE_BITS type:kotlin.Int visibility:public flags:final
|
||||
EXPRESSION_BODY
|
||||
CONST Int type=kotlin.Int value=32
|
||||
FUN IR_EXTERNAL_DECLARATION_STUB name:<get-SIZE_BITS> visibility:public modality:FINAL <> ($this:kotlin.Int.Companion) returnType:kotlin.Int flags:
|
||||
$this: VALUE_PARAMETER IR_EXTERNAL_DECLARATION_STUB name:<this> type:kotlin.Int.Companion flags:
|
||||
PROPERTY IR_EXTERNAL_DECLARATION_STUB name:SIZE_BYTES visibility:public modality:FINAL flags:const,val
|
||||
FIELD IR_EXTERNAL_DECLARATION_STUB name:SIZE_BYTES type:kotlin.Int visibility:public flags:final
|
||||
EXPRESSION_BODY
|
||||
CONST Int type=kotlin.Int value=4
|
||||
FUN IR_EXTERNAL_DECLARATION_STUB name:<get-SIZE_BYTES> visibility:public modality:FINAL <> ($this:kotlin.Int.Companion) returnType:kotlin.Int flags:
|
||||
$this: VALUE_PARAMETER IR_EXTERNAL_DECLARATION_STUB name:<this> type:kotlin.Int.Companion flags:
|
||||
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean flags:
|
||||
|
||||
Reference in New Issue
Block a user