IR: IrPropertySymbol introduced, some code cleaned up
#KT-30304
This commit is contained in:
+1
-1
@@ -80,7 +80,7 @@ class PrivateMembersLowering(val context: JsIrBackendContext) : ClassLoweringPas
|
|||||||
IrPropertyReferenceImpl(
|
IrPropertyReferenceImpl(
|
||||||
expression.startOffset, expression.endOffset,
|
expression.startOffset, expression.endOffset,
|
||||||
expression.type,
|
expression.type,
|
||||||
expression.descriptor,
|
expression.symbol, // TODO remap property symbol based on remapped getter/setter?
|
||||||
expression.typeArgumentsCount,
|
expression.typeArgumentsCount,
|
||||||
expression.field,
|
expression.field,
|
||||||
memberMap[expression.getter]?.symbol ?: expression.getter,
|
memberMap[expression.getter]?.symbol ?: expression.getter,
|
||||||
|
|||||||
+10
-6
@@ -292,6 +292,7 @@ private class IrUnboundSymbolReplacer(
|
|||||||
override fun visitPropertyReference(expression: IrPropertyReference): IrExpression {
|
override fun visitPropertyReference(expression: IrPropertyReference): IrExpression {
|
||||||
expression.replaceTypeArguments()
|
expression.replaceTypeArguments()
|
||||||
|
|
||||||
|
val property = expression.symbol.replaceOrSame(SymbolTable::referenceProperty)
|
||||||
val field = expression.field?.replaceOrSame(SymbolTable::referenceField)
|
val field = expression.field?.replaceOrSame(SymbolTable::referenceField)
|
||||||
val getter = expression.getter?.replace(SymbolTable::referenceSimpleFunction) ?: expression.getter
|
val getter = expression.getter?.replace(SymbolTable::referenceSimpleFunction) ?: expression.getter
|
||||||
val setter = expression.setter?.replace(SymbolTable::referenceSimpleFunction) ?: expression.setter
|
val setter = expression.setter?.replace(SymbolTable::referenceSimpleFunction) ?: expression.setter
|
||||||
@@ -302,12 +303,15 @@ private class IrUnboundSymbolReplacer(
|
|||||||
|
|
||||||
expression.transformChildrenVoid(this)
|
expression.transformChildrenVoid(this)
|
||||||
return with(expression) {
|
return with(expression) {
|
||||||
IrPropertyReferenceImpl(startOffset, endOffset, type, descriptor, 0,
|
IrPropertyReferenceImpl(
|
||||||
field,
|
startOffset, endOffset, type,
|
||||||
getter,
|
property,
|
||||||
setter,
|
0,
|
||||||
origin).also {
|
field,
|
||||||
|
getter,
|
||||||
|
setter,
|
||||||
|
origin
|
||||||
|
).also {
|
||||||
it.copyArgumentsFrom(this)
|
it.copyArgumentsFrom(this)
|
||||||
it.copyTypeArgumentsFrom(this)
|
it.copyTypeArgumentsFrom(this)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.psi2ir.generators
|
|||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrPropertyImpl
|
|
||||||
import org.jetbrains.kotlin.ir.descriptors.IrImplementingDelegateDescriptorImpl
|
import org.jetbrains.kotlin.ir.descriptors.IrImplementingDelegateDescriptorImpl
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.*
|
import org.jetbrains.kotlin.ir.expressions.impl.*
|
||||||
import org.jetbrains.kotlin.ir.expressions.mapValueParameters
|
import org.jetbrains.kotlin.ir.expressions.mapValueParameters
|
||||||
@@ -204,13 +203,13 @@ class ClassGenerator(
|
|||||||
irDelegate: IrField,
|
irDelegate: IrField,
|
||||||
delegatedDescriptor: PropertyDescriptor,
|
delegatedDescriptor: PropertyDescriptor,
|
||||||
overriddenDescriptor: PropertyDescriptor
|
overriddenDescriptor: PropertyDescriptor
|
||||||
): IrPropertyImpl {
|
): IrProperty {
|
||||||
val startOffset = irDelegate.startOffset
|
val startOffset = irDelegate.startOffset
|
||||||
val endOffset = irDelegate.endOffset
|
val endOffset = irDelegate.endOffset
|
||||||
|
|
||||||
val irProperty = IrPropertyImpl(
|
val irProperty = context.symbolTable.declareProperty(
|
||||||
startOffset, endOffset, IrDeclarationOrigin.DELEGATED_MEMBER,
|
startOffset, endOffset, IrDeclarationOrigin.DELEGATED_MEMBER,
|
||||||
false, delegatedDescriptor
|
delegatedDescriptor
|
||||||
)
|
)
|
||||||
|
|
||||||
irProperty.getter = generateDelegatedFunction(irDelegate, delegatedDescriptor.getter!!, overriddenDescriptor.getter!!)
|
irProperty.getter = generateDelegatedFunction(irDelegate, delegatedDescriptor.getter!!, overriddenDescriptor.getter!!)
|
||||||
|
|||||||
+35
-28
@@ -23,7 +23,6 @@ import org.jetbrains.kotlin.ir.builders.irGet
|
|||||||
import org.jetbrains.kotlin.ir.builders.irReturn
|
import org.jetbrains.kotlin.ir.builders.irReturn
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrLocalDelegatedPropertyImpl
|
import org.jetbrains.kotlin.ir.declarations.impl.IrLocalDelegatedPropertyImpl
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrPropertyImpl
|
|
||||||
import org.jetbrains.kotlin.ir.descriptors.IrLocalDelegatedPropertyDelegateDescriptor
|
import org.jetbrains.kotlin.ir.descriptors.IrLocalDelegatedPropertyDelegateDescriptor
|
||||||
import org.jetbrains.kotlin.ir.descriptors.IrLocalDelegatedPropertyDelegateDescriptorImpl
|
import org.jetbrains.kotlin.ir.descriptors.IrLocalDelegatedPropertyDelegateDescriptorImpl
|
||||||
import org.jetbrains.kotlin.ir.descriptors.IrPropertyDelegateDescriptor
|
import org.jetbrains.kotlin.ir.descriptors.IrPropertyDelegateDescriptor
|
||||||
@@ -55,10 +54,10 @@ class DelegatedPropertyGenerator(declarationGenerator: DeclarationGenerator) : D
|
|||||||
|
|
||||||
val kPropertyType = getKPropertyTypeForDelegatedProperty(propertyDescriptor)
|
val kPropertyType = getKPropertyTypeForDelegatedProperty(propertyDescriptor)
|
||||||
|
|
||||||
val irProperty = IrPropertyImpl(
|
val irProperty = context.symbolTable.declareProperty(
|
||||||
ktProperty.startOffsetSkippingComments, ktProperty.endOffset, IrDeclarationOrigin.DEFINED,
|
ktProperty.startOffsetSkippingComments, ktProperty.endOffset, IrDeclarationOrigin.DEFINED,
|
||||||
isDelegated = true,
|
propertyDescriptor,
|
||||||
descriptor = propertyDescriptor
|
isDelegated = true
|
||||||
).apply {
|
).apply {
|
||||||
backingField = generateDelegateFieldForProperty(propertyDescriptor, kPropertyType, ktDelegate)
|
backingField = generateDelegateFieldForProperty(propertyDescriptor, kPropertyType, ktDelegate)
|
||||||
}
|
}
|
||||||
@@ -145,14 +144,15 @@ class DelegatedPropertyGenerator(declarationGenerator: DeclarationGenerator) : D
|
|||||||
val irDelegateInitializer = declarationGenerator.generateInitializerBody(scopeOwner, ktDelegateExpression)
|
val irDelegateInitializer = declarationGenerator.generateInitializerBody(scopeOwner, ktDelegateExpression)
|
||||||
|
|
||||||
val provideDelegateResolvedCall = get(BindingContext.PROVIDE_DELEGATE_RESOLVED_CALL, property)
|
val provideDelegateResolvedCall = get(BindingContext.PROVIDE_DELEGATE_RESOLVED_CALL, property)
|
||||||
?: return irDelegateInitializer
|
?: return irDelegateInitializer
|
||||||
|
|
||||||
val statementGenerator = createBodyGenerator(scopeOwner).createStatementGenerator()
|
val statementGenerator = createBodyGenerator(scopeOwner).createStatementGenerator()
|
||||||
val provideDelegateCall = statementGenerator.pregenerateCall(provideDelegateResolvedCall)
|
val provideDelegateCall = statementGenerator.pregenerateCall(provideDelegateResolvedCall)
|
||||||
provideDelegateCall.setExplicitReceiverValue(OnceExpressionValue(irDelegateInitializer.expression))
|
provideDelegateCall.setExplicitReceiverValue(OnceExpressionValue(irDelegateInitializer.expression))
|
||||||
provideDelegateCall.irValueArgumentsByIndex[1] = createCallableReference(ktDelegate, kPropertyType, property, scopeOwner)
|
provideDelegateCall.irValueArgumentsByIndex[1] = createCallableReference(ktDelegate, kPropertyType, property, scopeOwner)
|
||||||
val irProvideDelegate =
|
val irProvideDelegate = CallGenerator(statementGenerator).generateCall(
|
||||||
CallGenerator(statementGenerator).generateCall(ktDelegate.startOffsetSkippingComments, ktDelegate.endOffset, provideDelegateCall)
|
ktDelegate.startOffsetSkippingComments, ktDelegate.endOffset, provideDelegateCall
|
||||||
|
)
|
||||||
return IrExpressionBodyImpl(irProvideDelegate)
|
return IrExpressionBodyImpl(irProvideDelegate)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,30 +241,30 @@ class DelegatedPropertyGenerator(declarationGenerator: DeclarationGenerator) : D
|
|||||||
val getterDescriptor = variableDescriptor.getter!!
|
val getterDescriptor = variableDescriptor.getter!!
|
||||||
val delegateReceiverValue = createVariableValueForDelegate(irDelegate.symbol, ktDelegate)
|
val delegateReceiverValue = createVariableValueForDelegate(irDelegate.symbol, ktDelegate)
|
||||||
irLocalDelegatedProperty.getter =
|
irLocalDelegatedProperty.getter =
|
||||||
createLocalPropertyAccessor(getterDescriptor, ktDelegate) { irGetter ->
|
createLocalPropertyAccessor(getterDescriptor, ktDelegate) { irGetter ->
|
||||||
generateDelegatedPropertyGetterBody(
|
generateDelegatedPropertyGetterBody(
|
||||||
irGetter, ktDelegate, getterDescriptor, delegateReceiverValue,
|
irGetter, ktDelegate, getterDescriptor, delegateReceiverValue,
|
||||||
createLocalDelegatedPropertyReference(
|
createLocalDelegatedPropertyReference(
|
||||||
ktDelegate, kPropertyType,
|
ktDelegate, kPropertyType,
|
||||||
variableDescriptor, irDelegate.symbol,
|
variableDescriptor, irDelegate.symbol,
|
||||||
irGetter.symbol
|
irGetter.symbol
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if (variableDescriptor.isVar) {
|
if (variableDescriptor.isVar) {
|
||||||
val setterDescriptor = variableDescriptor.setter!!
|
val setterDescriptor = variableDescriptor.setter!!
|
||||||
irLocalDelegatedProperty.setter =
|
irLocalDelegatedProperty.setter =
|
||||||
createLocalPropertyAccessor(setterDescriptor, ktDelegate) { irSetter ->
|
createLocalPropertyAccessor(setterDescriptor, ktDelegate) { irSetter ->
|
||||||
generateDelegatedPropertySetterBody(
|
generateDelegatedPropertySetterBody(
|
||||||
irSetter, ktDelegate, setterDescriptor, delegateReceiverValue,
|
irSetter, ktDelegate, setterDescriptor, delegateReceiverValue,
|
||||||
createLocalDelegatedPropertyReference(
|
createLocalDelegatedPropertyReference(
|
||||||
ktDelegate, kPropertyType,
|
ktDelegate, kPropertyType,
|
||||||
variableDescriptor, irDelegate.symbol,
|
variableDescriptor, irDelegate.symbol,
|
||||||
irSetter.symbol
|
irSetter.symbol
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return irLocalDelegatedProperty
|
return irLocalDelegatedProperty
|
||||||
@@ -320,14 +320,21 @@ class DelegatedPropertyGenerator(declarationGenerator: DeclarationGenerator) : D
|
|||||||
val provideDelegateCall = statementGenerator.pregenerateCall(provideDelegateResolvedCall).apply {
|
val provideDelegateCall = statementGenerator.pregenerateCall(provideDelegateResolvedCall).apply {
|
||||||
setExplicitReceiverValue(OnceExpressionValue(irDelegateInitializer))
|
setExplicitReceiverValue(OnceExpressionValue(irDelegateInitializer))
|
||||||
irValueArgumentsByIndex[1] =
|
irValueArgumentsByIndex[1] =
|
||||||
createLocalDelegatedPropertyReference(ktDelegate, kPropertyType, variableDescriptor, delegateSymbol, scopeOwner)
|
createLocalDelegatedPropertyReference(ktDelegate, kPropertyType, variableDescriptor, delegateSymbol, scopeOwner)
|
||||||
}
|
}
|
||||||
|
|
||||||
return CallGenerator(statementGenerator).generateCall(ktDelegate.startOffsetSkippingComments, ktDelegate.endOffset, provideDelegateCall)
|
return CallGenerator(statementGenerator).generateCall(
|
||||||
|
ktDelegate.startOffsetSkippingComments, ktDelegate.endOffset, provideDelegateCall
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createVariableValueForDelegate(irDelegate: IrVariableSymbol, ktDelegate: KtPropertyDelegate) =
|
private fun createVariableValueForDelegate(irDelegate: IrVariableSymbol, ktDelegate: KtPropertyDelegate) =
|
||||||
VariableLValue(context, ktDelegate.startOffsetSkippingComments, ktDelegate.endOffset, irDelegate, irDelegate.descriptor.type.toIrType())
|
VariableLValue(
|
||||||
|
context,
|
||||||
|
ktDelegate.startOffsetSkippingComments, ktDelegate.endOffset,
|
||||||
|
irDelegate,
|
||||||
|
irDelegate.descriptor.type.toIrType()
|
||||||
|
)
|
||||||
|
|
||||||
private inline fun createLocalPropertyAccessor(
|
private inline fun createLocalPropertyAccessor(
|
||||||
getterDescriptor: VariableAccessorDescriptor,
|
getterDescriptor: VariableAccessorDescriptor,
|
||||||
|
|||||||
+48
-51
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.psi2ir.generators
|
|||||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrPropertyImpl
|
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
|
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.IrExpressionBodyImpl
|
import org.jetbrains.kotlin.ir.expressions.impl.IrExpressionBodyImpl
|
||||||
@@ -27,9 +26,9 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrGetValueImpl
|
|||||||
import org.jetbrains.kotlin.ir.util.declareFieldWithOverrides
|
import org.jetbrains.kotlin.ir.util.declareFieldWithOverrides
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.startOffsetSkippingComments
|
||||||
import org.jetbrains.kotlin.psi2ir.pureEndOffsetOrUndefined
|
import org.jetbrains.kotlin.psi2ir.pureEndOffsetOrUndefined
|
||||||
import org.jetbrains.kotlin.psi2ir.pureStartOffsetOrUndefined
|
import org.jetbrains.kotlin.psi2ir.pureStartOffsetOrUndefined
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.startOffsetSkippingComments
|
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
import org.jetbrains.kotlin.resolve.hasBackingField
|
import org.jetbrains.kotlin.resolve.hasBackingField
|
||||||
|
|
||||||
@@ -47,33 +46,34 @@ class PropertyGenerator(declarationGenerator: DeclarationGenerator) : Declaratio
|
|||||||
val propertyDescriptor = getOrFail(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, ktParameter)
|
val propertyDescriptor = getOrFail(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, ktParameter)
|
||||||
|
|
||||||
val irPropertyType = propertyDescriptor.type.toIrType()
|
val irPropertyType = propertyDescriptor.type.toIrType()
|
||||||
return IrPropertyImpl(
|
return context.symbolTable.declareProperty(
|
||||||
ktParameter.startOffsetSkippingComments, ktParameter.endOffset,
|
ktParameter.startOffsetSkippingComments, ktParameter.endOffset,
|
||||||
IrDeclarationOrigin.DEFINED, false,
|
IrDeclarationOrigin.DEFINED,
|
||||||
propertyDescriptor
|
propertyDescriptor,
|
||||||
|
isDelegated = false
|
||||||
).also { irProperty ->
|
).also { irProperty ->
|
||||||
irProperty.backingField =
|
irProperty.backingField =
|
||||||
generatePropertyBackingField(ktParameter, propertyDescriptor) {
|
generatePropertyBackingField(ktParameter, propertyDescriptor) {
|
||||||
IrExpressionBodyImpl(
|
IrExpressionBodyImpl(
|
||||||
IrGetValueImpl(
|
IrGetValueImpl(
|
||||||
ktParameter.startOffsetSkippingComments, ktParameter.endOffset,
|
ktParameter.startOffsetSkippingComments, ktParameter.endOffset,
|
||||||
irPropertyType,
|
irPropertyType,
|
||||||
irValueParameter.symbol,
|
irValueParameter.symbol,
|
||||||
IrStatementOrigin.INITIALIZE_PROPERTY_FROM_PARAMETER
|
IrStatementOrigin.INITIALIZE_PROPERTY_FROM_PARAMETER
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}
|
)
|
||||||
|
}
|
||||||
|
|
||||||
val getter = propertyDescriptor.getter
|
val getter = propertyDescriptor.getter
|
||||||
?: throw AssertionError("Property declared in primary constructor has no getter: $propertyDescriptor")
|
?: throw AssertionError("Property declared in primary constructor has no getter: $propertyDescriptor")
|
||||||
irProperty.getter =
|
irProperty.getter =
|
||||||
FunctionGenerator(declarationGenerator).generateDefaultAccessorForPrimaryConstructorParameter(getter, ktParameter)
|
FunctionGenerator(declarationGenerator).generateDefaultAccessorForPrimaryConstructorParameter(getter, ktParameter)
|
||||||
|
|
||||||
if (propertyDescriptor.isVar) {
|
if (propertyDescriptor.isVar) {
|
||||||
val setter = propertyDescriptor.setter
|
val setter = propertyDescriptor.setter
|
||||||
?: throw AssertionError("Property declared in primary constructor has no setter: $propertyDescriptor")
|
?: throw AssertionError("Property declared in primary constructor has no setter: $propertyDescriptor")
|
||||||
irProperty.setter =
|
irProperty.setter =
|
||||||
FunctionGenerator(declarationGenerator).generateDefaultAccessorForPrimaryConstructorParameter(setter, ktParameter)
|
FunctionGenerator(declarationGenerator).generateDefaultAccessorForPrimaryConstructorParameter(setter, ktParameter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -101,35 +101,33 @@ class PropertyGenerator(declarationGenerator: DeclarationGenerator) : Declaratio
|
|||||||
.generateDelegatedProperty(ktProperty, ktDelegate, propertyDescriptor)
|
.generateDelegatedProperty(ktProperty, ktDelegate, propertyDescriptor)
|
||||||
|
|
||||||
private fun generateSimpleProperty(ktProperty: KtProperty, propertyDescriptor: PropertyDescriptor): IrProperty =
|
private fun generateSimpleProperty(ktProperty: KtProperty, propertyDescriptor: PropertyDescriptor): IrProperty =
|
||||||
IrPropertyImpl(
|
context.symbolTable.declareProperty(
|
||||||
ktProperty.startOffsetSkippingComments, ktProperty.endOffset,
|
ktProperty.startOffsetSkippingComments, ktProperty.endOffset,
|
||||||
IrDeclarationOrigin.DEFINED,
|
IrDeclarationOrigin.DEFINED,
|
||||||
false,
|
propertyDescriptor,
|
||||||
propertyDescriptor
|
isDelegated = false
|
||||||
).buildWithScope { irProperty ->
|
).buildWithScope { irProperty ->
|
||||||
irProperty.backingField =
|
irProperty.backingField =
|
||||||
if (propertyDescriptor.hasBackingField(context.bindingContext))
|
if (propertyDescriptor.hasBackingField(context.bindingContext))
|
||||||
generatePropertyBackingField(ktProperty, propertyDescriptor) { irField ->
|
generatePropertyBackingField(ktProperty, propertyDescriptor) { irField ->
|
||||||
ktProperty.initializer?.let { ktInitializer ->
|
ktProperty.initializer?.let { ktInitializer ->
|
||||||
val compileTimeConst = propertyDescriptor.compileTimeInitializer
|
val compileTimeConst = propertyDescriptor.compileTimeInitializer
|
||||||
if (propertyDescriptor.isConst && compileTimeConst != null)
|
if (propertyDescriptor.isConst && compileTimeConst != null)
|
||||||
IrExpressionBodyImpl(
|
IrExpressionBodyImpl(
|
||||||
context.constantValueGenerator.generateConstantValueAsExpression(
|
context.constantValueGenerator.generateConstantValueAsExpression(
|
||||||
ktInitializer.startOffsetSkippingComments, ktInitializer.endOffset,
|
ktInitializer.startOffsetSkippingComments, ktInitializer.endOffset,
|
||||||
compileTimeConst
|
compileTimeConst
|
||||||
)
|
|
||||||
)
|
)
|
||||||
else
|
)
|
||||||
declarationGenerator.generateInitializerBody(irField.symbol, ktInitializer)
|
else
|
||||||
}
|
declarationGenerator.generateInitializerBody(irField.symbol, ktInitializer)
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
null
|
else
|
||||||
|
null
|
||||||
|
|
||||||
irProperty.getter = generateGetterIfRequired(ktProperty, propertyDescriptor)
|
irProperty.getter = generateGetterIfRequired(ktProperty, propertyDescriptor)
|
||||||
irProperty.setter = generateSetterIfRequired(ktProperty, propertyDescriptor)
|
irProperty.setter = generateSetterIfRequired(ktProperty, propertyDescriptor)
|
||||||
|
|
||||||
irProperty.metadata = MetadataSource.Property(propertyDescriptor)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun generateFakeOverrideProperty(propertyDescriptor: PropertyDescriptor, ktElement: KtPureElement): IrProperty? {
|
fun generateFakeOverrideProperty(propertyDescriptor: PropertyDescriptor, ktElement: KtPureElement): IrProperty? {
|
||||||
@@ -142,21 +140,20 @@ class PropertyGenerator(declarationGenerator: DeclarationGenerator) : Declaratio
|
|||||||
if (propertyDescriptor.hasBackingField(context.bindingContext))
|
if (propertyDescriptor.hasBackingField(context.bindingContext))
|
||||||
context.symbolTable.declareFieldWithOverrides(
|
context.symbolTable.declareFieldWithOverrides(
|
||||||
startOffset, endOffset, IrDeclarationOrigin.FAKE_OVERRIDE,
|
startOffset, endOffset, IrDeclarationOrigin.FAKE_OVERRIDE,
|
||||||
propertyDescriptor, propertyDescriptor.type.toIrType(),
|
propertyDescriptor, propertyDescriptor.type.toIrType()
|
||||||
{ it.hasBackingField(context.bindingContext) }
|
) { it.hasBackingField(context.bindingContext) }
|
||||||
)
|
|
||||||
else
|
else
|
||||||
null
|
null
|
||||||
|
|
||||||
return IrPropertyImpl(
|
return context.symbolTable.declareProperty(startOffset, endOffset, IrDeclarationOrigin.FAKE_OVERRIDE, propertyDescriptor).apply {
|
||||||
startOffset, endOffset,
|
this.backingField = backingField
|
||||||
IrDeclarationOrigin.FAKE_OVERRIDE,
|
this.getter = propertyDescriptor.getter?.let {
|
||||||
false,
|
FunctionGenerator(declarationGenerator).generateFakeOverrideFunction(it, ktElement)
|
||||||
propertyDescriptor,
|
}
|
||||||
backingField,
|
this.setter = propertyDescriptor.setter?.let {
|
||||||
propertyDescriptor.getter?.let { FunctionGenerator(declarationGenerator).generateFakeOverrideFunction(it, ktElement) },
|
FunctionGenerator(declarationGenerator).generateFakeOverrideFunction(it, ktElement)
|
||||||
propertyDescriptor.setter?.let { FunctionGenerator(declarationGenerator).generateFakeOverrideFunction(it, ktElement) }
|
}
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun generateGetterIfRequired(ktProperty: KtProperty, property: PropertyDescriptor): IrSimpleFunction? {
|
private fun generateGetterIfRequired(ktProperty: KtProperty, property: PropertyDescriptor): IrSimpleFunction? {
|
||||||
@@ -172,7 +169,7 @@ class PropertyGenerator(declarationGenerator: DeclarationGenerator) : Declaratio
|
|||||||
|
|
||||||
private fun getPropertyDescriptor(ktProperty: KtProperty): PropertyDescriptor {
|
private fun getPropertyDescriptor(ktProperty: KtProperty): PropertyDescriptor {
|
||||||
val variableDescriptor = getOrFail(BindingContext.VARIABLE, ktProperty)
|
val variableDescriptor = getOrFail(BindingContext.VARIABLE, ktProperty)
|
||||||
return variableDescriptor as? PropertyDescriptor ?: TODO("not a property?")
|
return variableDescriptor as? PropertyDescriptor ?: TODO("not a property: $variableDescriptor")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-8
@@ -48,7 +48,7 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St
|
|||||||
} else {
|
} else {
|
||||||
val typeConstructorDeclaration = lhs.type.constructor.declarationDescriptor
|
val typeConstructorDeclaration = lhs.type.constructor.declarationDescriptor
|
||||||
val typeClass = typeConstructorDeclaration
|
val typeClass = typeConstructorDeclaration
|
||||||
?: throw AssertionError("Unexpected type constructor for ${lhs.type}: $typeConstructorDeclaration")
|
?: throw AssertionError("Unexpected type constructor for ${lhs.type}: $typeConstructorDeclaration")
|
||||||
IrClassReferenceImpl(
|
IrClassReferenceImpl(
|
||||||
ktClassLiteral.startOffsetSkippingComments, ktClassLiteral.endOffset, resultType,
|
ktClassLiteral.startOffsetSkippingComments, ktClassLiteral.endOffset, resultType,
|
||||||
context.symbolTable.referenceClassifier(typeClass), lhs.type.toIrType()
|
context.symbolTable.referenceClassifier(typeClass), lhs.type.toIrType()
|
||||||
@@ -139,17 +139,16 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St
|
|||||||
val getterDescriptor = propertyDescriptor.getter
|
val getterDescriptor = propertyDescriptor.getter
|
||||||
val setterDescriptor = if (mutable) propertyDescriptor.setter else null
|
val setterDescriptor = if (mutable) propertyDescriptor.setter else null
|
||||||
|
|
||||||
val fieldSymbol = if (getterDescriptor == null) context.symbolTable.referenceField(propertyDescriptor) else null
|
|
||||||
val getterSymbol = getterDescriptor?.let { context.symbolTable.referenceSimpleFunction(it.original) }
|
|
||||||
val setterSymbol = setterDescriptor?.let { context.symbolTable.referenceSimpleFunction(it.original) }
|
|
||||||
|
|
||||||
return IrPropertyReferenceImpl(
|
return IrPropertyReferenceImpl(
|
||||||
startOffset, endOffset, type.toIrType(),
|
startOffset, endOffset, type.toIrType(),
|
||||||
propertyDescriptor, propertyDescriptor.typeParametersCount,
|
context.symbolTable.referenceProperty(propertyDescriptor.original),
|
||||||
fieldSymbol, getterSymbol, setterSymbol,
|
propertyDescriptor.typeParametersCount,
|
||||||
|
getterDescriptor?.run { context.symbolTable.referenceField(propertyDescriptor) },
|
||||||
|
getterDescriptor?.let { context.symbolTable.referenceSimpleFunction(it.original) },
|
||||||
|
setterDescriptor?.let { context.symbolTable.referenceSimpleFunction(it.original) },
|
||||||
origin
|
origin
|
||||||
).apply {
|
).apply {
|
||||||
putTypeArguments(typeArguments) { it.toIrType()}
|
putTypeArguments(typeArguments) { it.toIrType() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.ir
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||||
import java.lang.AssertionError
|
|
||||||
|
|
||||||
interface IrElement {
|
interface IrElement {
|
||||||
val startOffset: Int
|
val startOffset: Int
|
||||||
|
|||||||
+3
-1
@@ -8,7 +8,9 @@ package org.jetbrains.kotlin.ir.builders.declarations
|
|||||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||||
import org.jetbrains.kotlin.descriptors.Visibility
|
import org.jetbrains.kotlin.descriptors.Visibility
|
||||||
import org.jetbrains.kotlin.ir.builders.IrElementBuilder
|
import org.jetbrains.kotlin.ir.builders.IrElementBuilder
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
||||||
|
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
||||||
|
import org.jetbrains.kotlin.ir.declarations.IrDeclarationWithVisibility
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
|
|
||||||
abstract class IrDeclarationBuilder : IrElementBuilder() {
|
abstract class IrDeclarationBuilder : IrElementBuilder() {
|
||||||
|
|||||||
@@ -19,10 +19,8 @@ package org.jetbrains.kotlin.ir.declarations
|
|||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||||
import org.jetbrains.kotlin.descriptors.Modality
|
import org.jetbrains.kotlin.descriptors.Modality
|
||||||
import org.jetbrains.kotlin.descriptors.Visibility
|
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
import org.jetbrains.kotlin.name.Name
|
|
||||||
|
|
||||||
interface IrClass :
|
interface IrClass :
|
||||||
IrSymbolDeclaration<IrClassSymbol>, IrDeclarationWithName, IrDeclarationWithVisibility,
|
IrSymbolDeclaration<IrClassSymbol>, IrDeclarationWithName, IrDeclarationWithVisibility,
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.ir.declarations
|
|||||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol
|
||||||
|
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
|
|
||||||
interface IrField : IrSymbolDeclaration<IrFieldSymbol>, IrOverridableDeclaration<IrFieldSymbol>,
|
interface IrField : IrSymbolDeclaration<IrFieldSymbol>, IrOverridableDeclaration<IrFieldSymbol>,
|
||||||
@@ -20,7 +21,9 @@ interface IrField : IrSymbolDeclaration<IrFieldSymbol>, IrOverridableDeclaration
|
|||||||
val isStatic: Boolean
|
val isStatic: Boolean
|
||||||
|
|
||||||
var initializer: IrExpressionBody?
|
var initializer: IrExpressionBody?
|
||||||
|
|
||||||
var correspondingProperty: IrProperty?
|
var correspondingProperty: IrProperty?
|
||||||
|
var correspondingPropertySymbol: IrPropertySymbol?
|
||||||
|
|
||||||
override val metadata: MetadataSource.Property?
|
override val metadata: MetadataSource.Property?
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,9 +18,15 @@ package org.jetbrains.kotlin.ir.declarations
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.Modality
|
import org.jetbrains.kotlin.descriptors.Modality
|
||||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||||
|
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
|
||||||
|
|
||||||
|
interface IrProperty :
|
||||||
|
IrDeclarationWithName,
|
||||||
|
IrDeclarationWithVisibility,
|
||||||
|
IrSymbolOwner {
|
||||||
|
|
||||||
interface IrProperty : IrDeclarationWithName, IrDeclarationWithVisibility {
|
|
||||||
override val descriptor: PropertyDescriptor
|
override val descriptor: PropertyDescriptor
|
||||||
|
override val symbol: IrPropertySymbol
|
||||||
|
|
||||||
val modality: Modality
|
val modality: Modality
|
||||||
val isVar: Boolean
|
val isVar: Boolean
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
package org.jetbrains.kotlin.ir.declarations
|
package org.jetbrains.kotlin.ir.declarations
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||||
import org.jetbrains.kotlin.ir.IrElement
|
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrReturnTargetSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrReturnTargetSymbol
|
||||||
|
|
||||||
interface IrReturnTarget : IrSymbolOwner {
|
interface IrReturnTarget : IrSymbolOwner {
|
||||||
|
|||||||
@@ -17,15 +17,21 @@
|
|||||||
package org.jetbrains.kotlin.ir.declarations
|
package org.jetbrains.kotlin.ir.declarations
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.Modality
|
import org.jetbrains.kotlin.descriptors.Modality
|
||||||
|
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||||
|
|
||||||
interface IrSimpleFunction : IrFunction, IrSymbolDeclaration<IrSimpleFunctionSymbol>, IrOverridableDeclaration<IrSimpleFunctionSymbol> {
|
interface IrSimpleFunction :
|
||||||
|
IrFunction,
|
||||||
|
IrSymbolDeclaration<IrSimpleFunctionSymbol>,
|
||||||
|
IrOverridableDeclaration<IrSimpleFunctionSymbol> {
|
||||||
|
|
||||||
val modality: Modality
|
val modality: Modality
|
||||||
val isTailrec: Boolean
|
val isTailrec: Boolean
|
||||||
val isSuspend: Boolean
|
val isSuspend: Boolean
|
||||||
|
|
||||||
var correspondingProperty: IrProperty?
|
var correspondingProperty: IrProperty?
|
||||||
|
var correspondingPropertySymbol: IrPropertySymbol?
|
||||||
}
|
}
|
||||||
|
|
||||||
val IrFunction.isPropertyAccessor: Boolean
|
val IrFunction.isPropertyAccessor: Boolean
|
||||||
get() = this is IrSimpleFunction && correspondingProperty != null
|
get() = this is IrSimpleFunction && correspondingPropertySymbol != null
|
||||||
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.ir.declarations.IrProperty
|
|||||||
import org.jetbrains.kotlin.ir.declarations.MetadataSource
|
import org.jetbrains.kotlin.ir.declarations.MetadataSource
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol
|
||||||
|
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl
|
import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
||||||
@@ -77,7 +78,15 @@ class IrFieldImpl(
|
|||||||
override val descriptor: PropertyDescriptor = symbol.descriptor
|
override val descriptor: PropertyDescriptor = symbol.descriptor
|
||||||
|
|
||||||
override var initializer: IrExpressionBody? = null
|
override var initializer: IrExpressionBody? = null
|
||||||
override var correspondingProperty: IrProperty? = null
|
|
||||||
|
override var correspondingProperty: IrProperty?
|
||||||
|
get() = correspondingPropertySymbol?.owner
|
||||||
|
set(value) {
|
||||||
|
correspondingPropertySymbol = value?.symbol
|
||||||
|
}
|
||||||
|
|
||||||
|
override var correspondingPropertySymbol: IrPropertySymbol? = null
|
||||||
|
|
||||||
override val overriddenSymbols: MutableList<IrFieldSymbol> = mutableListOf()
|
override val overriddenSymbols: MutableList<IrFieldSymbol> = mutableListOf()
|
||||||
|
|
||||||
override var metadata: MetadataSource.Property? = null
|
override var metadata: MetadataSource.Property? = null
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import org.jetbrains.kotlin.descriptors.Visibility
|
|||||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrProperty
|
import org.jetbrains.kotlin.ir.declarations.IrProperty
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
|
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
|
||||||
|
import org.jetbrains.kotlin.ir.expressions.IrBody
|
||||||
|
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl
|
import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
@@ -59,7 +61,13 @@ class IrFunctionImpl(
|
|||||||
|
|
||||||
override val overriddenSymbols: MutableList<IrSimpleFunctionSymbol> = SmartList()
|
override val overriddenSymbols: MutableList<IrSimpleFunctionSymbol> = SmartList()
|
||||||
|
|
||||||
override var correspondingProperty: IrProperty? = null
|
override var correspondingProperty: IrProperty?
|
||||||
|
get() = correspondingPropertySymbol?.owner
|
||||||
|
set(value) {
|
||||||
|
correspondingPropertySymbol = value?.symbol
|
||||||
|
}
|
||||||
|
|
||||||
|
override var correspondingPropertySymbol: IrPropertySymbol? = null
|
||||||
|
|
||||||
// Used by kotlin-native in InteropLowering.kt and IrUtils2.kt
|
// Used by kotlin-native in InteropLowering.kt and IrUtils2.kt
|
||||||
constructor(
|
constructor(
|
||||||
|
|||||||
-1
@@ -17,7 +17,6 @@
|
|||||||
package org.jetbrains.kotlin.ir.declarations.impl
|
package org.jetbrains.kotlin.ir.declarations.impl
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrExternalPackageFragment
|
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||||
|
|||||||
+47
-9
@@ -20,27 +20,56 @@ import org.jetbrains.kotlin.descriptors.Modality
|
|||||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.Visibility
|
import org.jetbrains.kotlin.descriptors.Visibility
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
|
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
|
||||||
|
import org.jetbrains.kotlin.ir.symbols.impl.IrPropertySymbolImpl
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isEffectivelyExternal
|
import org.jetbrains.kotlin.resolve.descriptorUtil.isEffectivelyExternal
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION_ERROR")
|
||||||
class IrPropertyImpl(
|
class IrPropertyImpl(
|
||||||
startOffset: Int,
|
startOffset: Int,
|
||||||
endOffset: Int,
|
endOffset: Int,
|
||||||
origin: IrDeclarationOrigin,
|
origin: IrDeclarationOrigin,
|
||||||
override val descriptor: PropertyDescriptor,
|
override val symbol: IrPropertySymbol,
|
||||||
override val name: Name,
|
override val name: Name = symbol.descriptor.name,
|
||||||
override val visibility: Visibility,
|
override val visibility: Visibility = symbol.descriptor.visibility,
|
||||||
override val modality: Modality,
|
override val modality: Modality = symbol.descriptor.modality,
|
||||||
override val isVar: Boolean,
|
override val isVar: Boolean = symbol.descriptor.isVar,
|
||||||
override val isConst: Boolean,
|
override val isConst: Boolean = symbol.descriptor.isConst,
|
||||||
override val isLateinit: Boolean,
|
override val isLateinit: Boolean = symbol.descriptor.isLateInit,
|
||||||
override val isDelegated: Boolean,
|
override val isDelegated: Boolean = symbol.descriptor.isDelegated,
|
||||||
override val isExternal: Boolean
|
override val isExternal: Boolean = symbol.descriptor.isEffectivelyExternal()
|
||||||
) : IrDeclarationBase(startOffset, endOffset, origin),
|
) : IrDeclarationBase(startOffset, endOffset, origin),
|
||||||
IrProperty {
|
IrProperty {
|
||||||
|
|
||||||
|
@Deprecated(message = "Don't use descriptor-based API for IrProperty", level = DeprecationLevel.ERROR)
|
||||||
|
constructor(
|
||||||
|
startOffset: Int,
|
||||||
|
endOffset: Int,
|
||||||
|
origin: IrDeclarationOrigin,
|
||||||
|
descriptor: PropertyDescriptor,
|
||||||
|
name: Name,
|
||||||
|
visibility: Visibility,
|
||||||
|
modality: Modality,
|
||||||
|
isVar: Boolean,
|
||||||
|
isConst: Boolean,
|
||||||
|
isLateinit: Boolean,
|
||||||
|
isDelegated: Boolean,
|
||||||
|
isExternal: Boolean
|
||||||
|
) : this(
|
||||||
|
startOffset, endOffset, origin,
|
||||||
|
IrPropertySymbolImpl(descriptor),
|
||||||
|
name, visibility, modality,
|
||||||
|
isVar = isVar,
|
||||||
|
isConst = isConst,
|
||||||
|
isLateinit = isLateinit,
|
||||||
|
isDelegated = isDelegated,
|
||||||
|
isExternal = isExternal
|
||||||
|
)
|
||||||
|
|
||||||
|
@Deprecated(message = "Don't use descriptor-based API for IrProperty", level = DeprecationLevel.ERROR)
|
||||||
constructor(
|
constructor(
|
||||||
startOffset: Int,
|
startOffset: Int,
|
||||||
endOffset: Int,
|
endOffset: Int,
|
||||||
@@ -57,6 +86,7 @@ class IrPropertyImpl(
|
|||||||
isExternal = descriptor.isEffectivelyExternal()
|
isExternal = descriptor.isEffectivelyExternal()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@Deprecated(message = "Don't use descriptor-based API for IrProperty", level = DeprecationLevel.ERROR)
|
||||||
constructor(
|
constructor(
|
||||||
startOffset: Int,
|
startOffset: Int,
|
||||||
endOffset: Int,
|
endOffset: Int,
|
||||||
@@ -64,6 +94,7 @@ class IrPropertyImpl(
|
|||||||
descriptor: PropertyDescriptor
|
descriptor: PropertyDescriptor
|
||||||
) : this(startOffset, endOffset, origin, descriptor.isDelegated, descriptor)
|
) : this(startOffset, endOffset, origin, descriptor.isDelegated, descriptor)
|
||||||
|
|
||||||
|
@Deprecated(message = "Don't use descriptor-based API for IrProperty", level = DeprecationLevel.ERROR)
|
||||||
constructor(
|
constructor(
|
||||||
startOffset: Int,
|
startOffset: Int,
|
||||||
endOffset: Int,
|
endOffset: Int,
|
||||||
@@ -75,6 +106,7 @@ class IrPropertyImpl(
|
|||||||
this.backingField = backingField
|
this.backingField = backingField
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated(message = "Don't use descriptor-based API for IrProperty", level = DeprecationLevel.ERROR)
|
||||||
constructor(
|
constructor(
|
||||||
startOffset: Int,
|
startOffset: Int,
|
||||||
endOffset: Int,
|
endOffset: Int,
|
||||||
@@ -89,6 +121,12 @@ class IrPropertyImpl(
|
|||||||
this.setter = setter
|
this.setter = setter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
symbol.bind(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
override val descriptor: PropertyDescriptor = symbol.descriptor
|
||||||
|
|
||||||
override var backingField: IrField? = null
|
override var backingField: IrField? = null
|
||||||
override var getter: IrSimpleFunction? = null
|
override var getter: IrSimpleFunction? = null
|
||||||
override var setter: IrSimpleFunction? = null
|
override var setter: IrSimpleFunction? = null
|
||||||
|
|||||||
+4
-1
@@ -8,7 +8,10 @@ package org.jetbrains.kotlin.ir.declarations.lazy
|
|||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.ir.IrElementBase
|
import org.jetbrains.kotlin.ir.IrElementBase
|
||||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
||||||
|
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
||||||
|
import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent
|
||||||
|
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl
|
import org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrCall
|
import org.jetbrains.kotlin.ir.expressions.IrCall
|
||||||
import org.jetbrains.kotlin.ir.util.DeclarationStubGenerator
|
import org.jetbrains.kotlin.ir.util.DeclarationStubGenerator
|
||||||
|
|||||||
+11
-2
@@ -5,11 +5,14 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.ir.declarations.lazy
|
package org.jetbrains.kotlin.ir.declarations.lazy
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||||
|
import org.jetbrains.kotlin.descriptors.Modality
|
||||||
|
import org.jetbrains.kotlin.descriptors.Visibility
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrProperty
|
import org.jetbrains.kotlin.ir.declarations.IrProperty
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
|
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrTypeParameter
|
import org.jetbrains.kotlin.ir.declarations.IrTypeParameter
|
||||||
|
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||||
import org.jetbrains.kotlin.ir.util.DeclarationStubGenerator
|
import org.jetbrains.kotlin.ir.util.DeclarationStubGenerator
|
||||||
import org.jetbrains.kotlin.ir.util.TypeTranslator
|
import org.jetbrains.kotlin.ir.util.TypeTranslator
|
||||||
@@ -82,7 +85,13 @@ class IrLazyFunction(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override var correspondingProperty: IrProperty? = null
|
override var correspondingProperty: IrProperty?
|
||||||
|
get() = correspondingPropertySymbol?.owner
|
||||||
|
set(value) {
|
||||||
|
correspondingPropertySymbol = value?.symbol
|
||||||
|
}
|
||||||
|
|
||||||
|
override var correspondingPropertySymbol: IrPropertySymbol? = null
|
||||||
|
|
||||||
init {
|
init {
|
||||||
symbol.bind(this)
|
symbol.bind(this)
|
||||||
|
|||||||
-2
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.ir.declarations.lazy
|
|||||||
import org.jetbrains.kotlin.descriptors.Visibility
|
import org.jetbrains.kotlin.descriptors.Visibility
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrTypeParameter
|
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
|
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrBody
|
import org.jetbrains.kotlin.ir.expressions.IrBody
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
@@ -18,7 +17,6 @@ import org.jetbrains.kotlin.ir.util.transform
|
|||||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.propertyIfAccessor
|
|
||||||
|
|
||||||
abstract class IrLazyFunctionBase(
|
abstract class IrLazyFunctionBase(
|
||||||
startOffset: Int,
|
startOffset: Int,
|
||||||
|
|||||||
+18
-9
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
|||||||
import org.jetbrains.kotlin.ir.declarations.IrField
|
import org.jetbrains.kotlin.ir.declarations.IrField
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrProperty
|
import org.jetbrains.kotlin.ir.declarations.IrProperty
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
|
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
|
||||||
|
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
|
||||||
import org.jetbrains.kotlin.ir.util.DeclarationStubGenerator
|
import org.jetbrains.kotlin.ir.util.DeclarationStubGenerator
|
||||||
import org.jetbrains.kotlin.ir.util.TypeTranslator
|
import org.jetbrains.kotlin.ir.util.TypeTranslator
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
||||||
@@ -25,7 +26,7 @@ class IrLazyProperty(
|
|||||||
startOffset: Int,
|
startOffset: Int,
|
||||||
endOffset: Int,
|
endOffset: Int,
|
||||||
origin: IrDeclarationOrigin,
|
origin: IrDeclarationOrigin,
|
||||||
override val descriptor: PropertyDescriptor,
|
override val symbol: IrPropertySymbol,
|
||||||
override val name: Name,
|
override val name: Name,
|
||||||
override val visibility: Visibility,
|
override val visibility: Visibility,
|
||||||
override val modality: Modality,
|
override val modality: Modality,
|
||||||
@@ -45,23 +46,31 @@ class IrLazyProperty(
|
|||||||
startOffset: Int,
|
startOffset: Int,
|
||||||
endOffset: Int,
|
endOffset: Int,
|
||||||
origin: IrDeclarationOrigin,
|
origin: IrDeclarationOrigin,
|
||||||
descriptor: PropertyDescriptor,
|
symbol: IrPropertySymbol,
|
||||||
stubGenerator: DeclarationStubGenerator,
|
stubGenerator: DeclarationStubGenerator,
|
||||||
typeTranslator: TypeTranslator,
|
typeTranslator: TypeTranslator,
|
||||||
bindingContext: BindingContext?
|
bindingContext: BindingContext?
|
||||||
) : this(
|
) : this(
|
||||||
startOffset, endOffset, origin, descriptor,
|
startOffset, endOffset, origin,
|
||||||
descriptor.name, descriptor.visibility, descriptor.modality,
|
symbol,
|
||||||
isVar = descriptor.isVar,
|
symbol.descriptor.name, symbol.descriptor.visibility, symbol.descriptor.modality,
|
||||||
isConst = descriptor.isConst,
|
isVar = symbol.descriptor.isVar,
|
||||||
isLateinit = descriptor.isLateInit,
|
isConst = symbol.descriptor.isConst,
|
||||||
isDelegated = descriptor.isDelegated,
|
isLateinit = symbol.descriptor.isLateInit,
|
||||||
isExternal = descriptor.isEffectivelyExternal(),
|
isDelegated = symbol.descriptor.isDelegated,
|
||||||
|
isExternal = symbol.descriptor.isEffectivelyExternal(),
|
||||||
stubGenerator = stubGenerator,
|
stubGenerator = stubGenerator,
|
||||||
typeTranslator = typeTranslator,
|
typeTranslator = typeTranslator,
|
||||||
bindingContext = bindingContext
|
bindingContext = bindingContext
|
||||||
)
|
)
|
||||||
|
|
||||||
|
init {
|
||||||
|
symbol.bind(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
override val descriptor: PropertyDescriptor
|
||||||
|
get() = symbol.descriptor
|
||||||
|
|
||||||
override var backingField: IrField? by lazyVar {
|
override var backingField: IrField? by lazyVar {
|
||||||
if (descriptor.hasBackingField(bindingContext)) {
|
if (descriptor.hasBackingField(bindingContext)) {
|
||||||
stubGenerator.generateFieldStub(descriptor).apply {
|
stubGenerator.generateFieldStub(descriptor).apply {
|
||||||
|
|||||||
+7
-2
@@ -5,9 +5,14 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.ir.declarations.lazy
|
package org.jetbrains.kotlin.ir.declarations.lazy
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor
|
||||||
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
|
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||||
|
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||||
import org.jetbrains.kotlin.ir.symbols.*
|
import org.jetbrains.kotlin.ir.symbols.*
|
||||||
import org.jetbrains.kotlin.ir.util.*
|
import org.jetbrains.kotlin.ir.util.DeclarationStubGenerator
|
||||||
|
import org.jetbrains.kotlin.ir.util.ReferenceSymbolTable
|
||||||
|
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||||
|
|
||||||
|
|
||||||
class IrLazySymbolTable(private val originalTable: SymbolTable) : ReferenceSymbolTable by originalTable {
|
class IrLazySymbolTable(private val originalTable: SymbolTable) : ReferenceSymbolTable by originalTable {
|
||||||
|
|||||||
+2
-3
@@ -6,11 +6,10 @@
|
|||||||
package org.jetbrains.kotlin.ir.declarations.lazy
|
package org.jetbrains.kotlin.ir.declarations.lazy
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrTypeParametersContainer
|
import org.jetbrains.kotlin.ir.declarations.IrTypeParametersContainer
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
|
||||||
import org.jetbrains.kotlin.ir.util.*
|
import org.jetbrains.kotlin.ir.util.ReferenceSymbolTable
|
||||||
|
import org.jetbrains.kotlin.ir.util.TypeParametersResolver
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class LazyScopedTypeParametersResolver(private val symbolTable: ReferenceSymbolTable) : TypeParametersResolver {
|
class LazyScopedTypeParametersResolver(private val symbolTable: ReferenceSymbolTable) : TypeParametersResolver {
|
||||||
|
|||||||
@@ -20,10 +20,7 @@ import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
|||||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.VariableDescriptorWithAccessors
|
import org.jetbrains.kotlin.descriptors.VariableDescriptorWithAccessors
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol
|
import org.jetbrains.kotlin.ir.symbols.*
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrVariableSymbol
|
|
||||||
|
|
||||||
interface IrCallableReference : IrMemberAccessExpression {
|
interface IrCallableReference : IrMemberAccessExpression {
|
||||||
override val descriptor: CallableDescriptor
|
override val descriptor: CallableDescriptor
|
||||||
@@ -36,6 +33,7 @@ interface IrFunctionReference : IrCallableReference {
|
|||||||
|
|
||||||
interface IrPropertyReference : IrCallableReference {
|
interface IrPropertyReference : IrCallableReference {
|
||||||
override val descriptor: PropertyDescriptor
|
override val descriptor: PropertyDescriptor
|
||||||
|
val symbol: IrPropertySymbol
|
||||||
val field: IrFieldSymbol?
|
val field: IrFieldSymbol?
|
||||||
val getter: IrSimpleFunctionSymbol?
|
val getter: IrSimpleFunctionSymbol?
|
||||||
val setter: IrSimpleFunctionSymbol?
|
val setter: IrSimpleFunctionSymbol?
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
package org.jetbrains.kotlin.ir.expressions.impl
|
package org.jetbrains.kotlin.ir.expressions.impl
|
||||||
|
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrBranch
|
import org.jetbrains.kotlin.ir.expressions.IrBranch
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
|
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
import org.jetbrains.kotlin.utils.SmartList
|
import org.jetbrains.kotlin.utils.SmartList
|
||||||
|
|||||||
+23
-1
@@ -20,7 +20,9 @@ import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
|||||||
import org.jetbrains.kotlin.ir.expressions.IrPropertyReference
|
import org.jetbrains.kotlin.ir.expressions.IrPropertyReference
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
|
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol
|
||||||
|
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||||
|
import org.jetbrains.kotlin.ir.symbols.impl.IrPropertySymbolImpl
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||||
|
|
||||||
@@ -28,7 +30,7 @@ class IrPropertyReferenceImpl(
|
|||||||
startOffset: Int,
|
startOffset: Int,
|
||||||
endOffset: Int,
|
endOffset: Int,
|
||||||
type: IrType,
|
type: IrType,
|
||||||
override val descriptor: PropertyDescriptor,
|
override val symbol: IrPropertySymbol,
|
||||||
typeArgumentsCount: Int,
|
typeArgumentsCount: Int,
|
||||||
override val field: IrFieldSymbol?,
|
override val field: IrFieldSymbol?,
|
||||||
override val getter: IrSimpleFunctionSymbol?,
|
override val getter: IrSimpleFunctionSymbol?,
|
||||||
@@ -38,6 +40,26 @@ class IrPropertyReferenceImpl(
|
|||||||
IrNoArgumentsCallableReferenceBase(startOffset, endOffset, type, typeArgumentsCount, origin),
|
IrNoArgumentsCallableReferenceBase(startOffset, endOffset, type, typeArgumentsCount, origin),
|
||||||
IrPropertyReference {
|
IrPropertyReference {
|
||||||
|
|
||||||
|
@Deprecated(message = "Don't use descriptor-based API for IrPropertyReference", level = DeprecationLevel.ERROR)
|
||||||
|
constructor(
|
||||||
|
startOffset: Int,
|
||||||
|
endOffset: Int,
|
||||||
|
type: IrType,
|
||||||
|
descriptor: PropertyDescriptor,
|
||||||
|
typeArgumentsCount: Int,
|
||||||
|
field: IrFieldSymbol?,
|
||||||
|
getter: IrSimpleFunctionSymbol?,
|
||||||
|
setter: IrSimpleFunctionSymbol?,
|
||||||
|
origin: IrStatementOrigin? = null
|
||||||
|
) : this(
|
||||||
|
startOffset, endOffset, type,
|
||||||
|
IrPropertySymbolImpl(descriptor),
|
||||||
|
typeArgumentsCount, field, getter, setter, origin
|
||||||
|
)
|
||||||
|
|
||||||
|
override val descriptor: PropertyDescriptor
|
||||||
|
get() = symbol.descriptor
|
||||||
|
|
||||||
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
|
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
|
||||||
visitor.visitPropertyReference(this, data)
|
visitor.visitPropertyReference(this, data)
|
||||||
}
|
}
|
||||||
@@ -73,3 +73,5 @@ interface IrConstructorSymbol : IrFunctionSymbol, IrBindableSymbol<ClassConstruc
|
|||||||
interface IrSimpleFunctionSymbol : IrFunctionSymbol, IrBindableSymbol<FunctionDescriptor, IrSimpleFunction>
|
interface IrSimpleFunctionSymbol : IrFunctionSymbol, IrBindableSymbol<FunctionDescriptor, IrSimpleFunction>
|
||||||
|
|
||||||
interface IrReturnableBlockSymbol : IrReturnTargetSymbol, IrBindableSymbol<FunctionDescriptor, IrReturnableBlock>
|
interface IrReturnableBlockSymbol : IrReturnTargetSymbol, IrBindableSymbol<FunctionDescriptor, IrReturnableBlock>
|
||||||
|
|
||||||
|
interface IrPropertySymbol : IrBindableSymbol<PropertyDescriptor, IrProperty>
|
||||||
@@ -101,3 +101,8 @@ class IrConstructorSymbolImpl(descriptor: ClassConstructorDescriptor) :
|
|||||||
class IrReturnableBlockSymbolImpl(descriptor: FunctionDescriptor) :
|
class IrReturnableBlockSymbolImpl(descriptor: FunctionDescriptor) :
|
||||||
IrBindableSymbolBase<FunctionDescriptor, IrReturnableBlock>(descriptor),
|
IrBindableSymbolBase<FunctionDescriptor, IrReturnableBlock>(descriptor),
|
||||||
IrReturnableBlockSymbol
|
IrReturnableBlockSymbol
|
||||||
|
|
||||||
|
|
||||||
|
class IrPropertySymbolImpl(descriptor: PropertyDescriptor) :
|
||||||
|
IrBindableSymbolBase<PropertyDescriptor, IrProperty>(descriptor),
|
||||||
|
IrPropertySymbol
|
||||||
@@ -84,10 +84,20 @@ class DeclarationStubGenerator(
|
|||||||
internal fun generatePropertyStub(
|
internal fun generatePropertyStub(
|
||||||
descriptor: PropertyDescriptor,
|
descriptor: PropertyDescriptor,
|
||||||
bindingContext: BindingContext? = null
|
bindingContext: BindingContext? = null
|
||||||
): IrProperty = symbolTable.referenceProperty(descriptor) {
|
): IrProperty {
|
||||||
deserializer?.findDeserializedDeclaration(descriptor) ?: IrLazyProperty(
|
val referenced = symbolTable.referenceProperty(descriptor)
|
||||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET, computeOrigin(descriptor), descriptor, this, typeTranslator, bindingContext
|
if (referenced.isBound) {
|
||||||
)
|
return referenced.owner
|
||||||
|
}
|
||||||
|
|
||||||
|
val origin = computeOrigin(descriptor)
|
||||||
|
return symbolTable.declareProperty(
|
||||||
|
UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor.original,
|
||||||
|
isDelegated = descriptor.isDelegated
|
||||||
|
) {
|
||||||
|
deserializer?.findDeserializedDeclaration(descriptor)
|
||||||
|
?: IrLazyProperty(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, it, this, typeTranslator, bindingContext)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun generateFieldStub(descriptor: PropertyDescriptor): IrField {
|
fun generateFieldStub(descriptor: PropertyDescriptor): IrField {
|
||||||
@@ -101,21 +111,13 @@ class DeclarationStubGenerator(
|
|||||||
IrDeclarationOrigin.FAKE_OVERRIDE
|
IrDeclarationOrigin.FAKE_OVERRIDE
|
||||||
else computeOrigin(descriptor)
|
else computeOrigin(descriptor)
|
||||||
|
|
||||||
return symbolTable.declareField(
|
return symbolTable.declareField(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor.original, descriptor.type.toIrType()) {
|
||||||
UNDEFINED_OFFSET,
|
|
||||||
UNDEFINED_OFFSET,
|
|
||||||
origin,
|
|
||||||
descriptor.original,
|
|
||||||
descriptor.type.toIrType()
|
|
||||||
) {
|
|
||||||
deserializer?.findDeserializedDeclaration(referenced) as? IrField
|
deserializer?.findDeserializedDeclaration(referenced) as? IrField
|
||||||
?: IrFieldImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, it, descriptor.type.toIrType())
|
?: IrFieldImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, it, descriptor.type.toIrType())
|
||||||
}.apply {
|
}.apply {
|
||||||
initializer = descriptor.compileTimeInitializer?.let {
|
initializer = descriptor.compileTimeInitializer?.let {
|
||||||
IrExpressionBodyImpl(
|
IrExpressionBodyImpl(
|
||||||
constantValueGenerator.generateConstantValueAsExpression(
|
constantValueGenerator.generateConstantValueAsExpression(UNDEFINED_OFFSET, UNDEFINED_OFFSET, it)
|
||||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET, it
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -188,9 +190,7 @@ class DeclarationStubGenerator(
|
|||||||
return referenceClass.owner
|
return referenceClass.owner
|
||||||
}
|
}
|
||||||
val origin = computeOrigin(descriptor)
|
val origin = computeOrigin(descriptor)
|
||||||
return symbolTable.declareClass(
|
return symbolTable.declareClass(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor) {
|
||||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor
|
|
||||||
) {
|
|
||||||
deserializer?.findDeserializedDeclaration(referenceClass) as? IrClass
|
deserializer?.findDeserializedDeclaration(referenceClass) as? IrClass
|
||||||
?: IrLazyClass(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, it, this, typeTranslator)
|
?: IrLazyClass(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, it, this, typeTranslator)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -203,9 +203,10 @@ open class DeepCopyIrTreeWithSymbols(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun visitProperty(declaration: IrProperty): IrProperty =
|
override fun visitProperty(declaration: IrProperty): IrProperty =
|
||||||
IrPropertyImpl(declaration.startOffset, declaration.endOffset,
|
IrPropertyImpl(
|
||||||
|
declaration.startOffset, declaration.endOffset,
|
||||||
mapDeclarationOrigin(declaration.origin),
|
mapDeclarationOrigin(declaration.origin),
|
||||||
declaration.descriptor,
|
symbolRemapper.getDeclaredProperty(declaration.symbol),
|
||||||
declaration.name,
|
declaration.name,
|
||||||
declaration.visibility,
|
declaration.visibility,
|
||||||
declaration.modality,
|
declaration.modality,
|
||||||
@@ -567,7 +568,7 @@ open class DeepCopyIrTreeWithSymbols(
|
|||||||
IrPropertyReferenceImpl(
|
IrPropertyReferenceImpl(
|
||||||
expression.startOffset, expression.endOffset,
|
expression.startOffset, expression.endOffset,
|
||||||
expression.type.remapType(),
|
expression.type.remapType(),
|
||||||
expression.descriptor,
|
symbolRemapper.getReferencedProperty(expression.symbol),
|
||||||
expression.typeArgumentsCount,
|
expression.typeArgumentsCount,
|
||||||
expression.field?.let { symbolRemapper.getReferencedField(it) },
|
expression.field?.let { symbolRemapper.getReferencedField(it) },
|
||||||
expression.getter?.let { symbolRemapper.getReferencedSimpleFunction(it) },
|
expression.getter?.let { symbolRemapper.getReferencedSimpleFunction(it) },
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ open class DeepCopySymbolRemapper(
|
|||||||
private val fields = hashMapOf<IrFieldSymbol, IrFieldSymbol>()
|
private val fields = hashMapOf<IrFieldSymbol, IrFieldSymbol>()
|
||||||
private val files = hashMapOf<IrFileSymbol, IrFileSymbol>()
|
private val files = hashMapOf<IrFileSymbol, IrFileSymbol>()
|
||||||
private val functions = hashMapOf<IrSimpleFunctionSymbol, IrSimpleFunctionSymbol>()
|
private val functions = hashMapOf<IrSimpleFunctionSymbol, IrSimpleFunctionSymbol>()
|
||||||
|
private val properties = hashMapOf<IrPropertySymbol, IrPropertySymbol>()
|
||||||
private val returnableBlocks = hashMapOf<IrReturnableBlockSymbol, IrReturnableBlockSymbol>()
|
private val returnableBlocks = hashMapOf<IrReturnableBlockSymbol, IrReturnableBlockSymbol>()
|
||||||
private val typeParameters = hashMapOf<IrTypeParameterSymbol, IrTypeParameterSymbol>()
|
private val typeParameters = hashMapOf<IrTypeParameterSymbol, IrTypeParameterSymbol>()
|
||||||
private val valueParameters = hashMapOf<IrValueParameterSymbol, IrValueParameterSymbol>()
|
private val valueParameters = hashMapOf<IrValueParameterSymbol, IrValueParameterSymbol>()
|
||||||
@@ -103,6 +104,13 @@ open class DeepCopySymbolRemapper(
|
|||||||
declaration.acceptChildrenVoid(this)
|
declaration.acceptChildrenVoid(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun visitProperty(declaration: IrProperty) {
|
||||||
|
remapSymbol(properties, declaration) {
|
||||||
|
IrPropertySymbolImpl(descriptorsRemapper.remapDeclaredProperty(it.descriptor))
|
||||||
|
}
|
||||||
|
declaration.acceptChildrenVoid(this)
|
||||||
|
}
|
||||||
|
|
||||||
override fun visitTypeParameter(declaration: IrTypeParameter) {
|
override fun visitTypeParameter(declaration: IrTypeParameter) {
|
||||||
remapSymbol(typeParameters, declaration) {
|
remapSymbol(typeParameters, declaration) {
|
||||||
IrTypeParameterSymbolImpl(descriptorsRemapper.remapDeclaredTypeParameter(it.descriptor))
|
IrTypeParameterSymbolImpl(descriptorsRemapper.remapDeclaredTypeParameter(it.descriptor))
|
||||||
@@ -143,6 +151,7 @@ open class DeepCopySymbolRemapper(
|
|||||||
|
|
||||||
override fun getDeclaredClass(symbol: IrClassSymbol): IrClassSymbol = classes.getDeclared(symbol)
|
override fun getDeclaredClass(symbol: IrClassSymbol): IrClassSymbol = classes.getDeclared(symbol)
|
||||||
override fun getDeclaredFunction(symbol: IrSimpleFunctionSymbol): IrSimpleFunctionSymbol = functions.getDeclared(symbol)
|
override fun getDeclaredFunction(symbol: IrSimpleFunctionSymbol): IrSimpleFunctionSymbol = functions.getDeclared(symbol)
|
||||||
|
override fun getDeclaredProperty(symbol: IrPropertySymbol): IrPropertySymbol = properties.getDeclared(symbol)
|
||||||
override fun getDeclaredField(symbol: IrFieldSymbol): IrFieldSymbol = fields.getDeclared(symbol)
|
override fun getDeclaredField(symbol: IrFieldSymbol): IrFieldSymbol = fields.getDeclared(symbol)
|
||||||
override fun getDeclaredFile(symbol: IrFileSymbol): IrFileSymbol = files.getDeclared(symbol)
|
override fun getDeclaredFile(symbol: IrFileSymbol): IrFileSymbol = files.getDeclared(symbol)
|
||||||
override fun getDeclaredConstructor(symbol: IrConstructorSymbol): IrConstructorSymbol = constructors.getDeclared(symbol)
|
override fun getDeclaredConstructor(symbol: IrConstructorSymbol): IrConstructorSymbol = constructors.getDeclared(symbol)
|
||||||
@@ -161,6 +170,7 @@ open class DeepCopySymbolRemapper(
|
|||||||
override fun getReferencedField(symbol: IrFieldSymbol): IrFieldSymbol = fields.getReferenced(symbol)
|
override fun getReferencedField(symbol: IrFieldSymbol): IrFieldSymbol = fields.getReferenced(symbol)
|
||||||
override fun getReferencedConstructor(symbol: IrConstructorSymbol): IrConstructorSymbol = constructors.getReferenced(symbol)
|
override fun getReferencedConstructor(symbol: IrConstructorSymbol): IrConstructorSymbol = constructors.getReferenced(symbol)
|
||||||
override fun getReferencedSimpleFunction(symbol: IrSimpleFunctionSymbol): IrSimpleFunctionSymbol = functions.getReferenced(symbol)
|
override fun getReferencedSimpleFunction(symbol: IrSimpleFunctionSymbol): IrSimpleFunctionSymbol = functions.getReferenced(symbol)
|
||||||
|
override fun getReferencedProperty(symbol: IrPropertySymbol): IrPropertySymbol = properties.getReferenced(symbol)
|
||||||
override fun getReferencedValue(symbol: IrValueSymbol): IrValueSymbol =
|
override fun getReferencedValue(symbol: IrValueSymbol): IrValueSymbol =
|
||||||
when (symbol) {
|
when (symbol) {
|
||||||
is IrValueParameterSymbol -> valueParameters.getReferenced(symbol)
|
is IrValueParameterSymbol -> valueParameters.getReferenced(symbol)
|
||||||
|
|||||||
+20
-7
@@ -20,6 +20,8 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
|||||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
||||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||||
|
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||||
|
import kotlin.math.min
|
||||||
|
|
||||||
class ExternalDependenciesGenerator(
|
class ExternalDependenciesGenerator(
|
||||||
moduleDescriptor: ModuleDescriptor,
|
moduleDescriptor: ModuleDescriptor,
|
||||||
@@ -49,6 +51,9 @@ class ExternalDependenciesGenerator(
|
|||||||
ArrayList(symbolTable.unboundSimpleFunctions).forEach {
|
ArrayList(symbolTable.unboundSimpleFunctions).forEach {
|
||||||
stubGenerator.generateFunctionStub(it.descriptor)
|
stubGenerator.generateFunctionStub(it.descriptor)
|
||||||
}
|
}
|
||||||
|
ArrayList(symbolTable.unboundProperties).forEach {
|
||||||
|
stubGenerator.generatePropertyStub(it.descriptor)
|
||||||
|
}
|
||||||
ArrayList(symbolTable.unboundTypeParameters).forEach {
|
ArrayList(symbolTable.unboundTypeParameters).forEach {
|
||||||
stubGenerator.generateOrGetTypeParameterStub(it.descriptor)
|
stubGenerator.generateOrGetTypeParameterStub(it.descriptor)
|
||||||
}
|
}
|
||||||
@@ -57,11 +62,19 @@ class ExternalDependenciesGenerator(
|
|||||||
|
|
||||||
if (deserializer != null) return
|
if (deserializer != null) return
|
||||||
|
|
||||||
assert(symbolTable.unboundClasses.isEmpty())
|
assertEmpty(symbolTable.unboundClasses, "classes")
|
||||||
assert(symbolTable.unboundConstructors.isEmpty())
|
assertEmpty(symbolTable.unboundConstructors, "constructors")
|
||||||
assert(symbolTable.unboundEnumEntries.isEmpty())
|
assertEmpty(symbolTable.unboundEnumEntries, "enum entries")
|
||||||
assert(symbolTable.unboundFields.isEmpty())
|
assertEmpty(symbolTable.unboundFields, "fields")
|
||||||
assert(symbolTable.unboundSimpleFunctions.isEmpty())
|
assertEmpty(symbolTable.unboundSimpleFunctions, "simple functions")
|
||||||
assert(symbolTable.unboundTypeParameters.isEmpty())
|
assertEmpty(symbolTable.unboundProperties, "properties")
|
||||||
|
assertEmpty(symbolTable.unboundTypeParameters, "type parameters")
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
private fun assertEmpty(s: Set<IrSymbol>, marker: String) {
|
||||||
|
assert(s.isEmpty()) {
|
||||||
|
"$marker: ${s.size} unbound:\n" +
|
||||||
|
s.toList().subList(0, min(10, s.size)).joinToString(separator = "\n") { it.descriptor.toString() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.ir.symbols.*
|
|||||||
interface SymbolRemapper {
|
interface SymbolRemapper {
|
||||||
fun getDeclaredClass(symbol: IrClassSymbol): IrClassSymbol
|
fun getDeclaredClass(symbol: IrClassSymbol): IrClassSymbol
|
||||||
fun getDeclaredFunction(symbol: IrSimpleFunctionSymbol): IrSimpleFunctionSymbol
|
fun getDeclaredFunction(symbol: IrSimpleFunctionSymbol): IrSimpleFunctionSymbol
|
||||||
|
fun getDeclaredProperty(symbol: IrPropertySymbol): IrPropertySymbol
|
||||||
fun getDeclaredField(symbol: IrFieldSymbol): IrFieldSymbol
|
fun getDeclaredField(symbol: IrFieldSymbol): IrFieldSymbol
|
||||||
fun getDeclaredFile(symbol: IrFileSymbol): IrFileSymbol
|
fun getDeclaredFile(symbol: IrFileSymbol): IrFileSymbol
|
||||||
fun getDeclaredConstructor(symbol: IrConstructorSymbol): IrConstructorSymbol
|
fun getDeclaredConstructor(symbol: IrConstructorSymbol): IrConstructorSymbol
|
||||||
@@ -37,6 +38,7 @@ interface SymbolRemapper {
|
|||||||
fun getReferencedConstructor(symbol: IrConstructorSymbol): IrConstructorSymbol
|
fun getReferencedConstructor(symbol: IrConstructorSymbol): IrConstructorSymbol
|
||||||
fun getReferencedValue(symbol: IrValueSymbol): IrValueSymbol
|
fun getReferencedValue(symbol: IrValueSymbol): IrValueSymbol
|
||||||
fun getReferencedFunction(symbol: IrFunctionSymbol): IrFunctionSymbol
|
fun getReferencedFunction(symbol: IrFunctionSymbol): IrFunctionSymbol
|
||||||
|
fun getReferencedProperty(symbol: IrPropertySymbol): IrPropertySymbol
|
||||||
fun getReferencedSimpleFunction(symbol: IrSimpleFunctionSymbol): IrSimpleFunctionSymbol
|
fun getReferencedSimpleFunction(symbol: IrSimpleFunctionSymbol): IrSimpleFunctionSymbol
|
||||||
fun getReferencedReturnableBlock(symbol: IrReturnableBlockSymbol): IrReturnableBlockSymbol
|
fun getReferencedReturnableBlock(symbol: IrReturnableBlockSymbol): IrReturnableBlockSymbol
|
||||||
fun getReferencedClassifier(symbol: IrClassifierSymbol): IrClassifierSymbol
|
fun getReferencedClassifier(symbol: IrClassifierSymbol): IrClassifierSymbol
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ interface IrDeserializer {
|
|||||||
// For now we have to live with a special treatment of properties.
|
// For now we have to live with a special treatment of properties.
|
||||||
// TODO: eventually get rid of this asymmetry.
|
// TODO: eventually get rid of this asymmetry.
|
||||||
fun findDeserializedDeclaration(propertyDescriptor: PropertyDescriptor): IrProperty?
|
fun findDeserializedDeclaration(propertyDescriptor: PropertyDescriptor): IrProperty?
|
||||||
|
|
||||||
fun declareForwardDeclarations()
|
fun declareForwardDeclarations()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,6 +201,7 @@ open class SymbolTable : ReferenceSymbolTable {
|
|||||||
private val enumEntrySymbolTable = FlatSymbolTable<ClassDescriptor, IrEnumEntry, IrEnumEntrySymbol>()
|
private val enumEntrySymbolTable = FlatSymbolTable<ClassDescriptor, IrEnumEntry, IrEnumEntrySymbol>()
|
||||||
private val fieldSymbolTable = FlatSymbolTable<PropertyDescriptor, IrField, IrFieldSymbol>()
|
private val fieldSymbolTable = FlatSymbolTable<PropertyDescriptor, IrField, IrFieldSymbol>()
|
||||||
private val simpleFunctionSymbolTable = FlatSymbolTable<FunctionDescriptor, IrSimpleFunction, IrSimpleFunctionSymbol>()
|
private val simpleFunctionSymbolTable = FlatSymbolTable<FunctionDescriptor, IrSimpleFunction, IrSimpleFunctionSymbol>()
|
||||||
|
private val propertySymbolTable = FlatSymbolTable<PropertyDescriptor, IrProperty, IrPropertySymbol>()
|
||||||
|
|
||||||
private val globalTypeParameterSymbolTable = FlatSymbolTable<TypeParameterDescriptor, IrTypeParameter, IrTypeParameterSymbol>()
|
private val globalTypeParameterSymbolTable = FlatSymbolTable<TypeParameterDescriptor, IrTypeParameter, IrTypeParameterSymbol>()
|
||||||
private val scopedTypeParameterSymbolTable = ScopedSymbolTable<TypeParameterDescriptor, IrTypeParameter, IrTypeParameterSymbol>()
|
private val scopedTypeParameterSymbolTable = ScopedSymbolTable<TypeParameterDescriptor, IrTypeParameter, IrTypeParameterSymbol>()
|
||||||
@@ -321,10 +323,35 @@ open class SymbolTable : ReferenceSymbolTable {
|
|||||||
|
|
||||||
val unboundFields: Set<IrFieldSymbol> get() = fieldSymbolTable.unboundSymbols
|
val unboundFields: Set<IrFieldSymbol> get() = fieldSymbolTable.unboundSymbols
|
||||||
|
|
||||||
|
@Deprecated(message = "Use declareProperty/referenceProperty", level = DeprecationLevel.WARNING)
|
||||||
val propertyTable = HashMap<PropertyDescriptor, IrProperty>()
|
val propertyTable = HashMap<PropertyDescriptor, IrProperty>()
|
||||||
|
|
||||||
override fun referenceProperty(descriptor: PropertyDescriptor, generate: () -> IrProperty): IrProperty =
|
override fun referenceProperty(descriptor: PropertyDescriptor, generate: () -> IrProperty): IrProperty =
|
||||||
propertyTable.getOrPut(descriptor, generate)
|
propertyTable.getOrPut(descriptor, generate)
|
||||||
|
|
||||||
|
fun declareProperty(
|
||||||
|
startOffset: Int,
|
||||||
|
endOffset: Int,
|
||||||
|
origin: IrDeclarationOrigin,
|
||||||
|
descriptor: PropertyDescriptor,
|
||||||
|
isDelegated: Boolean = descriptor.isDelegated,
|
||||||
|
propertyFactory: (IrPropertySymbol) -> IrProperty = { symbol ->
|
||||||
|
IrPropertyImpl(startOffset, endOffset, origin, symbol, isDelegated = isDelegated).apply {
|
||||||
|
metadata = MetadataSource.Property(symbol.descriptor)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
): IrProperty =
|
||||||
|
propertySymbolTable.declare(
|
||||||
|
descriptor,
|
||||||
|
{ IrPropertySymbolImpl(descriptor) },
|
||||||
|
propertyFactory
|
||||||
|
)
|
||||||
|
|
||||||
|
fun referenceProperty(descriptor: PropertyDescriptor): IrPropertySymbol =
|
||||||
|
propertySymbolTable.referenced(descriptor) { IrPropertySymbolImpl(descriptor) }
|
||||||
|
|
||||||
|
val unboundProperties: Set<IrPropertySymbol> get() = propertySymbolTable.unboundSymbols
|
||||||
|
|
||||||
fun declareSimpleFunction(
|
fun declareSimpleFunction(
|
||||||
startOffset: Int,
|
startOffset: Int,
|
||||||
endOffset: Int,
|
endOffset: Int,
|
||||||
|
|||||||
Reference in New Issue
Block a user