FIR2IR: convert annotations on delegated members

This commit is contained in:
Jinseong Jeon
2020-11-17 14:32:25 -08:00
committed by teamcityserver
parent d980074624
commit eff4cec3e0
8 changed files with 28 additions and 8 deletions
@@ -301,7 +301,6 @@ class Fir2IrConverter(
components.fakeOverrideGenerator = fakeOverrideGenerator
val callGenerator = CallAndReferenceGenerator(components, fir2irVisitor, conversionScope)
components.callGenerator = callGenerator
declarationStorage.annotationGenerator = AnnotationGenerator(components)
for (firFile in firFiles) {
converter.processClassHeaders(firFile)
}
@@ -59,7 +59,7 @@ class Fir2IrDeclarationStorage(
private val moduleDescriptor: FirModuleDescriptor
) : Fir2IrComponents by components {
internal var annotationGenerator: AnnotationGenerator? = null
private val annotationGenerator = AnnotationGenerator(this)
private val firSymbolProvider = session.firSymbolProvider
@@ -36,6 +36,8 @@ internal class DelegatedMemberGenerator(
private val components: Fir2IrComponents
) : Fir2IrComponents by components {
private val annotationGenerator = AnnotationGenerator(this)
// Generate delegated members for [subClass]. The synthetic field [irField] has the super interface type.
fun generate(irField: IrField, firField: FirField, firSubClass: FirClass<*>, subClass: IrClass) {
val subClassLookupTag = firSubClass.symbol.toLookupTag()
@@ -76,11 +78,12 @@ internal class DelegatedMemberGenerator(
val member = declarationStorage.getIrPropertySymbol(unwrapped.symbol).owner as? IrProperty
?: return@processAllProperties
val irSubFunction =
generateDelegatedProperty(subClass, firSubClass, irField, member, propertySymbol.fir)
val irSubProperty = generateDelegatedProperty(
subClass, firSubClass, irField, member, propertySymbol.fir
)
declarationStorage.cacheDelegatedProperty(propertySymbol.fir, irSubFunction)
subClass.addMember(irSubFunction)
declarationStorage.cacheDelegatedProperty(propertySymbol.fir, irSubProperty)
subClass.addMember(irSubProperty)
}
}
@@ -135,6 +138,7 @@ internal class DelegatedMemberGenerator(
delegateFunction.overriddenSymbols =
delegateOverride.generateOverriddenFunctionSymbols(firSubClass, session, scopeSession, declarationStorage)
.filter { it.owner != delegateFunction }
annotationGenerator.generate(delegateFunction, delegateOverride)
val body = createDelegateBody(irField, delegateFunction, superFunction)
delegateFunction.body = body
@@ -197,16 +201,19 @@ internal class DelegatedMemberGenerator(
firDelegateProperty, subClass, origin = IrDeclarationOrigin.DELEGATED_MEMBER,
containingClass = firSubClass.symbol.toLookupTag()
)
annotationGenerator.generate(delegateProperty, firDelegateProperty)
delegateProperty.getter!!.body = createDelegateBody(irField, delegateProperty.getter!!, superProperty.getter!!)
delegateProperty.getter!!.overriddenSymbols =
firDelegateProperty.generateOverriddenAccessorSymbols(firSubClass, isGetter = true, session, scopeSession, declarationStorage)
annotationGenerator.generate(delegateProperty.getter!!, firDelegateProperty)
if (delegateProperty.isVar) {
delegateProperty.setter!!.body = createDelegateBody(irField, delegateProperty.setter!!, superProperty.setter!!)
delegateProperty.setter!!.overriddenSymbols =
firDelegateProperty.generateOverriddenAccessorSymbols(
firSubClass, isGetter = false, session, scopeSession, declarationStorage
)
annotationGenerator.generate(delegateProperty.setter!!, firDelegateProperty)
}
return delegateProperty
@@ -1,6 +1,5 @@
// !LANGUAGE: -DoNotGenerateThrowsForDelegatedKotlinMembers
// TARGET_BACKEND: JVM
// IGNORE_BACKEND_FIR: JVM_IR
// WITH_RUNTIME
// FILE: A.kt
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// FILE: A.kt
@@ -51,6 +51,8 @@ FILE fqName:<root> fileName:/delegatedImplementationOfJavaInterface.kt
receiver: GET_VAR '<this>: <root>.Test declared in <root>.Test.takeFlexible' type=<root>.Test origin=null
x: GET_VAR 'x: kotlin.String? declared in <root>.Test.takeFlexible' type=kotlin.String? origin=null
FUN DELEGATED_MEMBER name:returnNotNull visibility:public modality:OPEN <> ($this:<root>.Test) returnType:@[EnhancedNullability] kotlin.String
annotations:
NotNull(value = <null>)
overridden:
public abstract fun returnNotNull (): @[EnhancedNullability] kotlin.String declared in <root>.J
$this: VALUE_PARAMETER name:<this> type:<root>.Test
@@ -60,6 +62,8 @@ FILE fqName:<root> fileName:/delegatedImplementationOfJavaInterface.kt
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.J visibility:local [final]' type=<root>.J origin=null
receiver: GET_VAR '<this>: <root>.Test declared in <root>.Test.returnNotNull' type=<root>.Test origin=null
FUN DELEGATED_MEMBER name:returnNullable visibility:public modality:OPEN <> ($this:<root>.Test) returnType:@[FlexibleNullability] kotlin.String?
annotations:
Nullable(value = <null>)
overridden:
public abstract fun returnNullable (): @[FlexibleNullability] kotlin.String? declared in <root>.J
$this: VALUE_PARAMETER name:<this> type:<root>.Test
@@ -63,6 +63,8 @@ FILE fqName:<root> fileName:/annotationsOnDelegatedMembers.kt
receiver: GET_VAR '<this>: <root>.DFoo declared in <root>.DFoo' type=<root>.DFoo origin=null
value: GET_VAR 'd: <root>.IFoo declared in <root>.DFoo.<init>' type=<root>.IFoo origin=null
FUN DELEGATED_MEMBER name:testFun visibility:public modality:OPEN <> ($this:<root>.DFoo) returnType:kotlin.Unit
annotations:
Ann
overridden:
public abstract fun testFun (): kotlin.Unit declared in <root>.IFoo
$this: VALUE_PARAMETER name:<this> type:<root>.DFoo
@@ -71,6 +73,8 @@ FILE fqName:<root> fileName:/annotationsOnDelegatedMembers.kt
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.IFoo visibility:local [final]' type=<root>.IFoo origin=null
receiver: GET_VAR '<this>: <root>.DFoo declared in <root>.DFoo.testFun' type=<root>.DFoo origin=null
FUN DELEGATED_MEMBER name:testExtFun visibility:public modality:OPEN <> ($this:<root>.DFoo, $receiver:kotlin.String) returnType:kotlin.Unit
annotations:
Ann
overridden:
public abstract fun testExtFun (): kotlin.Unit declared in <root>.IFoo
$this: VALUE_PARAMETER name:<this> type:<root>.DFoo
@@ -81,6 +85,8 @@ FILE fqName:<root> fileName:/annotationsOnDelegatedMembers.kt
receiver: GET_VAR '<this>: <root>.DFoo declared in <root>.DFoo.testExtFun' type=<root>.DFoo origin=null
$receiver: GET_VAR '<this>: kotlin.String declared in <root>.DFoo.testExtFun' type=kotlin.String origin=null
PROPERTY DELEGATED_MEMBER name:testVal visibility:public modality:OPEN [val]
annotations:
Ann
FUN DELEGATED_MEMBER name:<get-testVal> visibility:public modality:OPEN <> ($this:<root>.DFoo) returnType:kotlin.String
correspondingProperty: PROPERTY DELEGATED_MEMBER name:testVal visibility:public modality:OPEN [val]
overridden:
@@ -92,6 +98,8 @@ FILE fqName:<root> fileName:/annotationsOnDelegatedMembers.kt
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.IFoo visibility:local [final]' type=<root>.IFoo origin=null
receiver: GET_VAR '<this>: <root>.DFoo declared in <root>.DFoo.<get-testVal>' type=<root>.DFoo origin=null
PROPERTY DELEGATED_MEMBER name:testExtVal visibility:public modality:OPEN [val]
annotations:
Ann
FUN DELEGATED_MEMBER name:<get-testExtVal> visibility:public modality:OPEN <> ($this:<root>.DFoo, $receiver:kotlin.String) returnType:kotlin.String
correspondingProperty: PROPERTY DELEGATED_MEMBER name:testExtVal visibility:public modality:OPEN [val]
overridden:
@@ -44,6 +44,8 @@ FILE fqName:<root> fileName:/inheritingDeprecation.kt
receiver: GET_VAR '<this>: <root>.Delegated declared in <root>.Delegated' type=<root>.Delegated origin=null
value: GET_VAR 'foo: <root>.IFoo declared in <root>.Delegated.<init>' type=<root>.IFoo origin=null
PROPERTY DELEGATED_MEMBER name:prop visibility:public modality:OPEN [val]
annotations:
Deprecated(message = '', replaceWith = <null>, level = <null>)
FUN DELEGATED_MEMBER name:<get-prop> visibility:public modality:OPEN <> ($this:<root>.Delegated) returnType:kotlin.String
correspondingProperty: PROPERTY DELEGATED_MEMBER name:prop visibility:public modality:OPEN [val]
overridden:
@@ -55,6 +57,8 @@ FILE fqName:<root> fileName:/inheritingDeprecation.kt
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.IFoo visibility:local [final]' type=<root>.IFoo origin=null
receiver: GET_VAR '<this>: <root>.Delegated declared in <root>.Delegated.<get-prop>' type=<root>.Delegated origin=null
PROPERTY DELEGATED_MEMBER name:extProp visibility:public modality:OPEN [val]
annotations:
Deprecated(message = '', replaceWith = <null>, level = <null>)
FUN DELEGATED_MEMBER name:<get-extProp> visibility:public modality:OPEN <> ($this:<root>.Delegated, $receiver:kotlin.String) returnType:kotlin.String
correspondingProperty: PROPERTY DELEGATED_MEMBER name:extProp visibility:public modality:OPEN [val]
overridden: