[FIR] Make constructor delegate lazy in RawFirBuilder
Fifth step for ^KT-52615 Merge-request: KT-MR-7860 Merged-by: Egor Kulikov <Egor.Kulikov@jetbrains.com>
This commit is contained in:
@@ -133,6 +133,10 @@ class FirJavaConstructor @FirImplementationDetail constructor(
|
||||
valueParameters += newValueParameters
|
||||
}
|
||||
|
||||
override fun replaceDelegatedConstructor(newDelegatedConstructor: FirDelegatedConstructorCall?) {
|
||||
error("Delegated constructor cannot be replaced for FirJavaConstructor")
|
||||
}
|
||||
|
||||
override fun replaceReceiverParameter(newReceiverParameter: FirReceiverParameter?) {}
|
||||
|
||||
override fun replaceDeprecationsProvider(newDeprecationsProvider: DeprecationsProvider) {
|
||||
|
||||
+81
-38
@@ -188,6 +188,29 @@ open class RawFirBuilder(
|
||||
return buildOrLazy(buildBlock, ::buildLazyBlock)
|
||||
}
|
||||
|
||||
private inline fun buildOrLazyDelegatedConstructorCall(
|
||||
isThis: Boolean,
|
||||
constructedTypeRef: FirTypeRef,
|
||||
buildCall: () -> FirDelegatedConstructorCall
|
||||
): FirDelegatedConstructorCall {
|
||||
return buildOrLazy(buildCall, {
|
||||
buildLazyDelegatedConstructorCall {
|
||||
this.isThis = isThis
|
||||
this.constructedTypeRef = constructedTypeRef
|
||||
calleeReference = if (isThis) {
|
||||
buildExplicitThisReference {
|
||||
source = null
|
||||
}
|
||||
} else {
|
||||
buildExplicitSuperReference {
|
||||
source = null
|
||||
superTypeRef = constructedTypeRef
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
open fun convertElement(element: KtElement): FirElement? =
|
||||
element.accept(this@Visitor, Unit)
|
||||
|
||||
@@ -206,7 +229,8 @@ open class RawFirBuilder(
|
||||
defaultTypeRef: FirTypeRef? = null,
|
||||
valueParameterDeclaration: ValueParameterDeclaration,
|
||||
additionalAnnotations: List<FirAnnotation> = emptyList()
|
||||
): FirValueParameter = valueParameter.toFirValueParameter(defaultTypeRef, functionSymbol, valueParameterDeclaration, additionalAnnotations)
|
||||
): FirValueParameter =
|
||||
valueParameter.toFirValueParameter(defaultTypeRef, functionSymbol, valueParameterDeclaration, additionalAnnotations)
|
||||
|
||||
private fun KtTypeReference?.toFirOrImplicitType(): FirTypeRef =
|
||||
convertSafe() ?: buildImplicitTypeRef {
|
||||
@@ -291,14 +315,12 @@ open class RawFirBuilder(
|
||||
): FirDeclaration {
|
||||
return when (this) {
|
||||
is KtSecondaryConstructor -> {
|
||||
disabledLazyMode {
|
||||
toFirConstructor(
|
||||
delegatedSuperType,
|
||||
delegatedSelfType,
|
||||
owner,
|
||||
ownerTypeParameters
|
||||
)
|
||||
}
|
||||
toFirConstructor(
|
||||
if (isDelegatedCallToThis()) delegatedSelfType else delegatedSuperType,
|
||||
delegatedSelfType,
|
||||
owner,
|
||||
ownerTypeParameters,
|
||||
)
|
||||
}
|
||||
is KtEnumEntry -> {
|
||||
val primaryConstructor = owner.primaryConstructor
|
||||
@@ -890,11 +912,12 @@ open class RawFirBuilder(
|
||||
if (primaryConstructor != null || (this !is KtClass || !this.isInterface()) && shouldGenerateImplicitPrimaryConstructor) {
|
||||
val firPrimaryConstructor = primaryConstructor.toFirConstructor(
|
||||
superTypeCallEntry,
|
||||
delegatedSuperTypeRef!!,
|
||||
delegatedSuperTypeRef,
|
||||
delegatedSelfTypeRef ?: delegatedSuperTypeRef!!,
|
||||
owner = this,
|
||||
containerTypeParameters,
|
||||
containingClassIsExpectClass,
|
||||
copyConstructedTypeRefWithImplicitSource = true,
|
||||
)
|
||||
container.declarations += firPrimaryConstructor
|
||||
}
|
||||
@@ -902,27 +925,49 @@ open class RawFirBuilder(
|
||||
return delegatedSuperTypeRef!! to delegateFieldsMap.takeIf { it.isNotEmpty() }
|
||||
}
|
||||
|
||||
private fun KtPrimaryConstructor?.toFirConstructor(
|
||||
/**
|
||||
* @param delegatedSuperTypeRef can be null if containingClassIsExpectClass is true
|
||||
*/
|
||||
protected fun KtPrimaryConstructor?.toFirConstructor(
|
||||
superTypeCallEntry: KtSuperTypeCallEntry?,
|
||||
delegatedSuperTypeRef: FirTypeRef,
|
||||
delegatedSuperTypeRef: FirTypeRef?,
|
||||
delegatedSelfTypeRef: FirTypeRef,
|
||||
owner: KtClassOrObject,
|
||||
ownerTypeParameters: List<FirTypeParameterRef>,
|
||||
containingClassIsExpectClass: Boolean,
|
||||
copyConstructedTypeRefWithImplicitSource: Boolean,
|
||||
): FirConstructor {
|
||||
val constructorCall = superTypeCallEntry?.toFirSourceElement()
|
||||
val constructorSource = this?.toFirSourceElement()
|
||||
?: owner.toKtPsiSourceElement(KtFakeSourceElementKind.ImplicitConstructor)
|
||||
val firDelegatedCall = if (containingClassIsExpectClass) null else buildDelegatedConstructorCall {
|
||||
source = constructorCall ?: constructorSource.fakeElement(KtFakeSourceElementKind.DelegatingConstructorCall)
|
||||
constructedTypeRef = delegatedSuperTypeRef.copyWithNewSourceKind(KtFakeSourceElementKind.ImplicitTypeRef)
|
||||
isThis = false
|
||||
calleeReference = buildExplicitSuperReference {
|
||||
source = superTypeCallEntry?.calleeExpression?.toFirSourceElement(KtFakeSourceElementKind.DelegatingConstructorCall)
|
||||
?: this@buildDelegatedConstructorCall.source?.fakeElement(KtFakeSourceElementKind.DelegatingConstructorCall)
|
||||
superTypeRef = this@buildDelegatedConstructorCall.constructedTypeRef
|
||||
val firDelegatedCall = if (containingClassIsExpectClass) null else {
|
||||
val constructedTypeRef = if (copyConstructedTypeRefWithImplicitSource) {
|
||||
delegatedSuperTypeRef!!.copyWithNewSourceKind(KtFakeSourceElementKind.ImplicitTypeRef)
|
||||
} else {
|
||||
delegatedSuperTypeRef!!
|
||||
}
|
||||
superTypeCallEntry?.extractArgumentsTo(this)
|
||||
val delegatedConstructorCall = {
|
||||
buildDelegatedConstructorCall {
|
||||
source = constructorCall ?: constructorSource.fakeElement(KtFakeSourceElementKind.DelegatingConstructorCall)
|
||||
this.constructedTypeRef = constructedTypeRef
|
||||
isThis = false
|
||||
calleeReference = buildExplicitSuperReference {
|
||||
source =
|
||||
superTypeCallEntry?.calleeExpression?.toFirSourceElement(KtFakeSourceElementKind.DelegatingConstructorCall)
|
||||
?: this@buildDelegatedConstructorCall.source?.fakeElement(KtFakeSourceElementKind.DelegatingConstructorCall)
|
||||
superTypeRef = this@buildDelegatedConstructorCall.constructedTypeRef
|
||||
}
|
||||
superTypeCallEntry?.extractArgumentsTo(this)
|
||||
}
|
||||
}
|
||||
if (this == null && owner !is KtEnumEntry) {
|
||||
// primary constructor without body
|
||||
delegatedConstructorCall()
|
||||
} else buildOrLazyDelegatedConstructorCall(
|
||||
isThis = false,
|
||||
constructedTypeRef,
|
||||
delegatedConstructorCall,
|
||||
)
|
||||
}
|
||||
|
||||
// See DescriptorUtils#getDefaultConstructorVisibility in core.descriptors
|
||||
@@ -1003,7 +1048,7 @@ open class RawFirBuilder(
|
||||
}
|
||||
}
|
||||
|
||||
private fun convertScript(script: KtScript, containingFile: FirFileBuilder,): FirScript {
|
||||
private fun convertScript(script: KtScript, containingFile: FirFileBuilder): FirScript {
|
||||
return buildScript {
|
||||
source = script.toFirSourceElement()
|
||||
moduleData = baseModuleData
|
||||
@@ -1086,7 +1131,8 @@ open class RawFirBuilder(
|
||||
delegatedEntrySelfType,
|
||||
owner = ktEnumEntry,
|
||||
typeParameters,
|
||||
containingClassIsExpectClass
|
||||
containingClassIsExpectClass,
|
||||
copyConstructedTypeRefWithImplicitSource = true,
|
||||
)
|
||||
// Use ANONYMOUS_OBJECT_NAME for the owner class id for enum entry declarations (see KT-42351)
|
||||
withChildClassName(SpecialNames.ANONYMOUS, forceLocalContext = true, isExpect = false) {
|
||||
@@ -1541,9 +1587,9 @@ open class RawFirBuilder(
|
||||
}
|
||||
}
|
||||
|
||||
private fun KtSecondaryConstructor.toFirConstructor(
|
||||
delegatedSuperTypeRef: FirTypeRef,
|
||||
delegatedSelfTypeRef: FirTypeRef,
|
||||
protected fun KtSecondaryConstructor.toFirConstructor(
|
||||
delegatedTypeRef: FirTypeRef,
|
||||
selfTypeRef: FirTypeRef,
|
||||
owner: KtClassOrObject,
|
||||
ownerTypeParameters: List<FirTypeParameterRef>
|
||||
): FirConstructor {
|
||||
@@ -1552,7 +1598,7 @@ open class RawFirBuilder(
|
||||
source = this@toFirConstructor.toFirSourceElement()
|
||||
moduleData = baseModuleData
|
||||
origin = FirDeclarationOrigin.Source
|
||||
returnTypeRef = delegatedSelfTypeRef
|
||||
returnTypeRef = selfTypeRef
|
||||
val explicitVisibility = visibility
|
||||
status = FirDeclarationStatusImpl(explicitVisibility, Modality.FINAL).apply {
|
||||
isExpect = hasExpectModifier() || this@RawFirBuilder.context.containerIsExpect
|
||||
@@ -1563,10 +1609,12 @@ open class RawFirBuilder(
|
||||
}
|
||||
dispatchReceiverType = owner.obtainDispatchReceiverForConstructor()
|
||||
symbol = FirConstructorSymbol(callableIdForClassConstructor())
|
||||
delegatedConstructor = getDelegationCall().convert(
|
||||
delegatedSuperTypeRef,
|
||||
delegatedSelfTypeRef,
|
||||
)
|
||||
delegatedConstructor = buildOrLazyDelegatedConstructorCall(
|
||||
isThis = isDelegatedCallToThis(),
|
||||
constructedTypeRef = delegatedTypeRef,
|
||||
) {
|
||||
getDelegationCall().convert(delegatedTypeRef)
|
||||
}
|
||||
this@RawFirBuilder.context.firFunctionTargets += target
|
||||
extractAnnotationsTo(this)
|
||||
typeParameters += constructorTypeParametersFromConstructedClass(ownerTypeParameters)
|
||||
@@ -1583,8 +1631,7 @@ open class RawFirBuilder(
|
||||
}
|
||||
|
||||
private fun KtConstructorDelegationCall.convert(
|
||||
delegatedSuperTypeRef: FirTypeRef,
|
||||
delegatedSelfTypeRef: FirTypeRef,
|
||||
delegatedType: FirTypeRef,
|
||||
): FirDelegatedConstructorCall {
|
||||
val isThis = isCallToThis //|| (isImplicit && hasPrimaryConstructor)
|
||||
val source = if (isImplicit) {
|
||||
@@ -1592,10 +1639,6 @@ open class RawFirBuilder(
|
||||
} else {
|
||||
this.toFirSourceElement()
|
||||
}
|
||||
val delegatedType = when {
|
||||
isThis -> delegatedSelfTypeRef
|
||||
else -> delegatedSuperTypeRef
|
||||
}
|
||||
return buildDelegatedConstructorCall {
|
||||
this.source = source
|
||||
constructedTypeRef = delegatedType.copyWithNewSourceKind(KtFakeSourceElementKind.ImplicitTypeRef)
|
||||
@@ -1619,7 +1662,7 @@ open class RawFirBuilder(
|
||||
}
|
||||
|
||||
private fun KtDeclarationWithInitializer.toInitializerExpression() =
|
||||
runIf (hasInitializer()) {
|
||||
runIf(hasInitializer()) {
|
||||
buildOrLazyExpression(initializer?.toFirSourceElement()) {
|
||||
initializer.toFirExpression("Should have initializer")
|
||||
}
|
||||
|
||||
+2
-2
@@ -13,14 +13,14 @@ FILE: annotation.kt
|
||||
}
|
||||
@base() public? final? class correct : R|kotlin/Any| {
|
||||
public? constructor(@base() x: Int): R|correct| {
|
||||
super<R|kotlin/Any|>()
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
@base() public? final? val x: Int = R|<local>/x|
|
||||
public? get(): Int
|
||||
|
||||
@base() public? constructor(): R|correct| {
|
||||
this<R|correct|>(IntegerLiteral(0))
|
||||
LAZY_this<R|correct|>
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Vendored
+2
-2
@@ -1,7 +1,7 @@
|
||||
FILE: constructorInObject.kt
|
||||
public? final? object A : R|kotlin/Any| {
|
||||
public? constructor(): R|A| {
|
||||
super<R|kotlin/Any|>()
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
init { LAZY_BLOCK }
|
||||
@@ -30,7 +30,7 @@ FILE: constructorInObject.kt
|
||||
|
||||
public? final? companion object Companion : R|kotlin/Any| {
|
||||
public? constructor(): R|C.Companion| {
|
||||
super<R|kotlin/Any|>()
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-2
@@ -15,7 +15,7 @@ FILE: propertyAccessorsContractDescription.kt
|
||||
}
|
||||
public? final? class AnotherClass : R|kotlin/Any| {
|
||||
public? constructor(multiplier: Int): R|AnotherClass| {
|
||||
super<R|kotlin/Any|>()
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
public? final? var anotherInt: Int = LAZY_EXPRESSION
|
||||
@@ -33,7 +33,7 @@ FILE: propertyAccessorsContractDescription.kt
|
||||
}
|
||||
public? final? class SomeClass : R|kotlin/Any| {
|
||||
public? constructor(multiplier: Int?): R|SomeClass| {
|
||||
super<R|kotlin/Any|>()
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
public? final? var someInt: Int = LAZY_EXPRESSION
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
FILE: derivedClass.kt
|
||||
public? open class Base<T> : R|kotlin/Any| {
|
||||
public? constructor<T>(x: T): R|Base<T>| {
|
||||
super<R|kotlin/Any|>()
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
public? final? val x: T = R|<local>/x|
|
||||
@@ -10,7 +10,7 @@ FILE: derivedClass.kt
|
||||
}
|
||||
public? final? class Derived<T : Any> : Base<T> {
|
||||
public? constructor<T : Any>(x: T): R|Derived<T>| {
|
||||
super<Base<T>>(x#)
|
||||
LAZY_super<Base<T>>
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-2
@@ -19,7 +19,7 @@ FILE: enums.kt
|
||||
}
|
||||
public? final? enum class Planet : R|kotlin/Enum<Planet>| {
|
||||
private constructor(m: Double, r: Double): R|Planet| {
|
||||
super<R|kotlin/Enum<Planet>|>()
|
||||
LAZY_super<R|kotlin/Enum<Planet>|>
|
||||
}
|
||||
|
||||
public? final? val m: Double = R|<local>/m|
|
||||
@@ -58,7 +58,7 @@ FILE: enums.kt
|
||||
}
|
||||
public? final? enum class PseudoInsn : R|kotlin/Enum<PseudoInsn>| {
|
||||
private constructor(signature: String = String(()V)): R|PseudoInsn| {
|
||||
super<R|kotlin/Enum<PseudoInsn>|>()
|
||||
LAZY_super<R|kotlin/Enum<PseudoInsn>|>
|
||||
}
|
||||
|
||||
public? final? val signature: String = R|<local>/signature|
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ FILE: enums2.kt
|
||||
}
|
||||
public? final? enum class SomeEnum : R|kotlin/Enum<SomeEnum>| {
|
||||
private constructor(x: Some): R|SomeEnum| {
|
||||
super<R|kotlin/Enum<SomeEnum>|>()
|
||||
LAZY_super<R|kotlin/Enum<SomeEnum>|>
|
||||
}
|
||||
|
||||
public? final? val x: Some = R|<local>/x|
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
FILE: nestedClass.kt
|
||||
public? abstract class Base : R|kotlin/Any| {
|
||||
public? constructor(s: String): R|Base| {
|
||||
super<R|kotlin/Any|>()
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
public? final? val s: String = R|<local>/s|
|
||||
@@ -15,7 +15,7 @@ FILE: nestedClass.kt
|
||||
|
||||
public? final? class Derived : Base {
|
||||
public? constructor(s: String): R|Outer.Derived| {
|
||||
super<Base>(s#)
|
||||
LAZY_super<Base>
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
FILE: noParameterTypRefInPrimaryConstructor.kt
|
||||
public? final? class X : R|kotlin/Any| {
|
||||
public? constructor(x: <ERROR TYPE REF: No type for parameter>): R|X| {
|
||||
super<R|kotlin/Any|>()
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
FILE: noParameterTypRefInPrimaryConsturctorVal.kt
|
||||
public? final? class X : R|kotlin/Any| {
|
||||
public? constructor(x: <ERROR TYPE REF: No type for parameter>): R|X| {
|
||||
super<R|kotlin/Any|>()
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
public? final? val x: <ERROR TYPE REF: No type for parameter> = R|<local>/x|
|
||||
|
||||
+1
-3
@@ -1,7 +1,5 @@
|
||||
FILE: noParameterTypRefInSecondaryConstructor.kt
|
||||
public? final? class C : R|kotlin/Any| {
|
||||
public? constructor(x: <ERROR TYPE REF: No type for parameter>): R|C| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
public? constructor(x: <ERROR TYPE REF: No type for parameter>): R|C| { LAZY_BLOCK }
|
||||
|
||||
}
|
||||
|
||||
Vendored
+2
-5
@@ -3,13 +3,10 @@ FILE: noPrimaryConstructor.kt
|
||||
public? final? val x: String
|
||||
public? get(): String
|
||||
|
||||
public? constructor(x: String): R|NoPrimary| {
|
||||
super<R|kotlin/Any|>()
|
||||
this#.x# = x#
|
||||
}
|
||||
public? constructor(x: String): R|NoPrimary| { LAZY_BLOCK }
|
||||
|
||||
public? constructor(): R|NoPrimary| {
|
||||
this<R|NoPrimary|>(String())
|
||||
LAZY_this<R|NoPrimary|>
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ FILE: annotated.kt
|
||||
public? final? fun foo(arg: Int): Int { LAZY_BLOCK }
|
||||
public? final? data class Two : R|kotlin/Any| {
|
||||
public? constructor(x: Int, y: Int): R|Two| {
|
||||
super<R|kotlin/Any|>()
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
public? final? val x: Int = R|<local>/x|
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ FILE: arrayAccess.kt
|
||||
public? final? fun foo(): <implicit> { LAZY_BLOCK }
|
||||
public? final? class Wrapper : R|kotlin/Any| {
|
||||
public? constructor(v: IntArray): R|Wrapper| {
|
||||
super<R|kotlin/Any|>()
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
public? final? val v: IntArray = R|<local>/v|
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ FILE: calls.kt
|
||||
public? final? fun testRegular(): Int { LAZY_BLOCK }
|
||||
public? final? class My : R|kotlin/Any| {
|
||||
public? constructor(x: Int): R|My| {
|
||||
super<R|kotlin/Any|>()
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
public? final? var x: Int = R|<local>/x|
|
||||
|
||||
Vendored
+3
-3
@@ -1,7 +1,7 @@
|
||||
FILE: collectionLiterals.kt
|
||||
public? final? annotation class Ann1 : R|kotlin/Annotation| {
|
||||
public? constructor(arr: IntArray): R|Ann1| {
|
||||
super<R|kotlin/Any|>()
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
public? final? val arr: IntArray = R|<local>/arr|
|
||||
@@ -10,7 +10,7 @@ FILE: collectionLiterals.kt
|
||||
}
|
||||
public? final? annotation class Ann2 : R|kotlin/Annotation| {
|
||||
public? constructor(arr: DoubleArray): R|Ann2| {
|
||||
super<R|kotlin/Any|>()
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
public? final? val arr: DoubleArray = R|<local>/arr|
|
||||
@@ -19,7 +19,7 @@ FILE: collectionLiterals.kt
|
||||
}
|
||||
public? final? annotation class Ann3 : R|kotlin/Annotation| {
|
||||
public? constructor(arr: Array<String>): R|Ann3| {
|
||||
super<R|kotlin/Any|>()
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
public? final? val arr: Array<String> = R|<local>/arr|
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
FILE: destructuring.kt
|
||||
public? final? data class Some : R|kotlin/Any| {
|
||||
public? constructor(first: Int, second: Double, third: String): R|Some| {
|
||||
super<R|kotlin/Any|>()
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
public? final? val first: Int = R|<local>/first|
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ FILE: for.kt
|
||||
public? final? fun bar(list: List<String>): R|kotlin/Unit| { LAZY_BLOCK }
|
||||
public? final? data class Some : R|kotlin/Any| {
|
||||
public? constructor(x: Int, y: Int): R|Some| {
|
||||
super<R|kotlin/Any|>()
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
public? final? val x: Int = R|<local>/x|
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
FILE: init.kt
|
||||
public? final? class WithInit : R|kotlin/Any| {
|
||||
public? constructor(x: Int): R|WithInit| {
|
||||
super<R|kotlin/Any|>()
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
public? final? val x: Int
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
FILE: lambda.kt
|
||||
public? final? data class Tuple : R|kotlin/Any| {
|
||||
public? constructor(x: Int, y: Int): R|Tuple| {
|
||||
super<R|kotlin/Any|>()
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
public? final? val x: Int = R|<local>/x|
|
||||
|
||||
+2
-2
@@ -2,7 +2,7 @@ FILE: unary.kt
|
||||
public? final? fun test(): R|kotlin/Unit| { LAZY_BLOCK }
|
||||
public? final? class X : R|kotlin/Any| {
|
||||
public? constructor(i: Int): R|X| {
|
||||
super<R|kotlin/Any|>()
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
public? final? val i: Int = R|<local>/i|
|
||||
@@ -13,7 +13,7 @@ FILE: unary.kt
|
||||
public? final? fun test3(arr: Array<Int>): R|kotlin/Unit| { LAZY_BLOCK }
|
||||
public? final? class Y : R|kotlin/Any| {
|
||||
public? constructor(arr: Array<Int>): R|Y| {
|
||||
super<R|kotlin/Any|>()
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
public? final? val arr: Array<Int> = R|<local>/arr|
|
||||
|
||||
@@ -65,6 +65,8 @@ abstract class FirConstructor : FirFunction(), FirTypeParameterRefsOwner {
|
||||
|
||||
abstract override fun replaceValueParameters(newValueParameters: List<FirValueParameter>)
|
||||
|
||||
abstract fun replaceDelegatedConstructor(newDelegatedConstructor: FirDelegatedConstructorCall?)
|
||||
|
||||
abstract override fun replaceBody(newBody: FirBlock?)
|
||||
|
||||
abstract override fun <D> transformTypeParameters(transformer: FirTransformer<D>, data: D): FirConstructor
|
||||
|
||||
@@ -159,6 +159,10 @@ internal class FirConstructorImpl(
|
||||
valueParameters.addAll(newValueParameters)
|
||||
}
|
||||
|
||||
override fun replaceDelegatedConstructor(newDelegatedConstructor: FirDelegatedConstructorCall?) {
|
||||
delegatedConstructor = newDelegatedConstructor
|
||||
}
|
||||
|
||||
override fun replaceBody(newBody: FirBlock?) {
|
||||
body = newBody
|
||||
}
|
||||
|
||||
+4
@@ -160,6 +160,10 @@ class FirPrimaryConstructor @FirImplementationDetail constructor(
|
||||
valueParameters.addAll(newValueParameters)
|
||||
}
|
||||
|
||||
override fun replaceDelegatedConstructor(newDelegatedConstructor: FirDelegatedConstructorCall?) {
|
||||
delegatedConstructor = newDelegatedConstructor
|
||||
}
|
||||
|
||||
override fun replaceBody(newBody: FirBlock?) {
|
||||
body = newBody
|
||||
}
|
||||
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@file:Suppress("DuplicatedCode")
|
||||
|
||||
package org.jetbrains.kotlin.fir.expressions.builder
|
||||
|
||||
import kotlin.contracts.*
|
||||
import org.jetbrains.kotlin.KtSourceElement
|
||||
import org.jetbrains.kotlin.fir.FirImplementationDetail
|
||||
import org.jetbrains.kotlin.fir.builder.FirAnnotationContainerBuilder
|
||||
import org.jetbrains.kotlin.fir.builder.FirBuilderDsl
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
|
||||
import org.jetbrains.kotlin.fir.expressions.FirArgumentList
|
||||
import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall
|
||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||
import org.jetbrains.kotlin.fir.expressions.impl.FirLazyDelegatedConstructorCall
|
||||
import org.jetbrains.kotlin.fir.references.FirReference
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
import org.jetbrains.kotlin.fir.visitors.*
|
||||
|
||||
/*
|
||||
* This file was generated automatically
|
||||
* DO NOT MODIFY IT MANUALLY
|
||||
*/
|
||||
|
||||
@FirBuilderDsl
|
||||
class FirLazyDelegatedConstructorCallBuilder : FirAnnotationContainerBuilder {
|
||||
lateinit var constructedTypeRef: FirTypeRef
|
||||
lateinit var calleeReference: FirReference
|
||||
var isThis: Boolean by kotlin.properties.Delegates.notNull<Boolean>()
|
||||
|
||||
@OptIn(FirImplementationDetail::class)
|
||||
override fun build(): FirDelegatedConstructorCall {
|
||||
return FirLazyDelegatedConstructorCall(
|
||||
constructedTypeRef,
|
||||
calleeReference,
|
||||
isThis,
|
||||
)
|
||||
}
|
||||
|
||||
@Deprecated("Modification of 'source' has no impact for FirLazyDelegatedConstructorCallBuilder", level = DeprecationLevel.HIDDEN)
|
||||
override var source: KtSourceElement?
|
||||
get() = throw IllegalStateException()
|
||||
set(_) {
|
||||
throw IllegalStateException()
|
||||
}
|
||||
|
||||
@Deprecated("Modification of 'annotations' has no impact for FirLazyDelegatedConstructorCallBuilder", level = DeprecationLevel.HIDDEN)
|
||||
override val annotations: MutableList<FirAnnotation> = mutableListOf()
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
inline fun buildLazyDelegatedConstructorCall(init: FirLazyDelegatedConstructorCallBuilder.() -> Unit): FirDelegatedConstructorCall {
|
||||
contract {
|
||||
callsInPlace(init, kotlin.contracts.InvocationKind.EXACTLY_ONCE)
|
||||
}
|
||||
return FirLazyDelegatedConstructorCallBuilder().apply(init).build()
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@file:Suppress("DuplicatedCode")
|
||||
|
||||
package org.jetbrains.kotlin.fir.expressions.impl
|
||||
|
||||
import org.jetbrains.kotlin.KtSourceElement
|
||||
import org.jetbrains.kotlin.fir.FirImplementationDetail
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
|
||||
import org.jetbrains.kotlin.fir.expressions.FirArgumentList
|
||||
import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall
|
||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||
import org.jetbrains.kotlin.fir.references.FirReference
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
import org.jetbrains.kotlin.fir.visitors.*
|
||||
|
||||
/*
|
||||
* This file was generated automatically
|
||||
* DO NOT MODIFY IT MANUALLY
|
||||
*/
|
||||
|
||||
class FirLazyDelegatedConstructorCall @FirImplementationDetail constructor(
|
||||
override var constructedTypeRef: FirTypeRef,
|
||||
override var calleeReference: FirReference,
|
||||
override val isThis: Boolean,
|
||||
) : FirDelegatedConstructorCall() {
|
||||
override val source: KtSourceElement? get() = error("FirLazyDelegatedConstructorCall should be calculated before accessing")
|
||||
override val annotations: List<FirAnnotation> get() = error("FirLazyDelegatedConstructorCall should be calculated before accessing")
|
||||
override val argumentList: FirArgumentList get() = error("FirLazyDelegatedConstructorCall should be calculated before accessing")
|
||||
override val contextReceiverArguments: List<FirExpression> get() = error("FirLazyDelegatedConstructorCall should be calculated before accessing")
|
||||
override val dispatchReceiver: FirExpression get() = error("FirLazyDelegatedConstructorCall should be calculated before accessing")
|
||||
override val isSuper: Boolean get() = !isThis
|
||||
|
||||
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
|
||||
constructedTypeRef.accept(visitor, data)
|
||||
calleeReference.accept(visitor, data)
|
||||
}
|
||||
|
||||
override fun <D> transformChildren(transformer: FirTransformer<D>, data: D): FirLazyDelegatedConstructorCall {
|
||||
constructedTypeRef = constructedTypeRef.transform(transformer, data)
|
||||
transformCalleeReference(transformer, data)
|
||||
return this
|
||||
}
|
||||
|
||||
override fun <D> transformAnnotations(transformer: FirTransformer<D>, data: D): FirLazyDelegatedConstructorCall {
|
||||
return this
|
||||
}
|
||||
|
||||
override fun <D> transformDispatchReceiver(transformer: FirTransformer<D>, data: D): FirLazyDelegatedConstructorCall {
|
||||
return this
|
||||
}
|
||||
|
||||
override fun <D> transformCalleeReference(transformer: FirTransformer<D>, data: D): FirLazyDelegatedConstructorCall {
|
||||
calleeReference = calleeReference.transform(transformer, data)
|
||||
return this
|
||||
}
|
||||
|
||||
override fun replaceArgumentList(newArgumentList: FirArgumentList) {}
|
||||
|
||||
override fun replaceContextReceiverArguments(newContextReceiverArguments: List<FirExpression>) {}
|
||||
|
||||
override fun replaceConstructedTypeRef(newConstructedTypeRef: FirTypeRef) {
|
||||
constructedTypeRef = newConstructedTypeRef
|
||||
}
|
||||
|
||||
override fun replaceCalleeReference(newCalleeReference: FirReference) {
|
||||
calleeReference = newCalleeReference
|
||||
}
|
||||
}
|
||||
@@ -654,10 +654,15 @@ class FirRenderer(
|
||||
}
|
||||
|
||||
override fun visitDelegatedConstructorCall(delegatedConstructorCall: FirDelegatedConstructorCall) {
|
||||
val dispatchReceiver = delegatedConstructorCall.dispatchReceiver
|
||||
if (dispatchReceiver !is FirNoReceiverExpression) {
|
||||
dispatchReceiver.accept(this)
|
||||
print(".")
|
||||
if (delegatedConstructorCall !is FirLazyDelegatedConstructorCall) {
|
||||
val dispatchReceiver = delegatedConstructorCall.dispatchReceiver
|
||||
if (dispatchReceiver !is FirNoReceiverExpression) {
|
||||
dispatchReceiver.accept(this)
|
||||
print(".")
|
||||
}
|
||||
}
|
||||
if (delegatedConstructorCall is FirLazyDelegatedConstructorCall) {
|
||||
print("LAZY_")
|
||||
}
|
||||
if (delegatedConstructorCall.isSuper) {
|
||||
print("super<")
|
||||
@@ -666,7 +671,9 @@ class FirRenderer(
|
||||
}
|
||||
delegatedConstructorCall.constructedTypeRef.accept(this)
|
||||
print(">")
|
||||
visitCall(delegatedConstructorCall)
|
||||
if (delegatedConstructorCall !is FirLazyDelegatedConstructorCall) {
|
||||
visitCall(delegatedConstructorCall)
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitTypeRef(typeRef: FirTypeRef) {
|
||||
|
||||
+1
-1
@@ -190,7 +190,7 @@ object BuilderConfigurator : AbstractBuilderConfigurator<FirTreeBuilder>(FirTree
|
||||
defaultNull("label")
|
||||
}
|
||||
|
||||
builder(delegatedConstructorCall) {
|
||||
builder(delegatedConstructorCall, type = "FirDelegatedConstructorCallImpl") {
|
||||
parents += callBuilder
|
||||
default("argumentList") {
|
||||
value = "FirEmptyArgumentList"
|
||||
|
||||
+29
@@ -128,6 +128,35 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
|
||||
useTypes(explicitThisReferenceType, explicitSuperReferenceType)
|
||||
}
|
||||
|
||||
impl(delegatedConstructorCall, "FirLazyDelegatedConstructorCall") {
|
||||
val error = """error("FirLazyDelegatedConstructorCall should be calculated before accessing")"""
|
||||
default("source") {
|
||||
value = error
|
||||
withGetter = true
|
||||
}
|
||||
default("annotations") {
|
||||
value = error
|
||||
withGetter = true
|
||||
}
|
||||
default("argumentList") {
|
||||
value = error
|
||||
withGetter = true
|
||||
}
|
||||
default("contextReceiverArguments") {
|
||||
value = error
|
||||
withGetter = true
|
||||
}
|
||||
default("dispatchReceiver") {
|
||||
value = error
|
||||
withGetter = true
|
||||
}
|
||||
default("isSuper") {
|
||||
value = "!isThis"
|
||||
withGetter = true
|
||||
}
|
||||
publicImplementation()
|
||||
}
|
||||
|
||||
impl(expression, "FirElseIfTrueCondition") {
|
||||
defaultTypeRefWithSource("FirImplicitBooleanTypeRef")
|
||||
useTypes(implicitBooleanTypeRefType)
|
||||
|
||||
+1
-1
@@ -379,7 +379,7 @@ object NodeConfigurator : AbstractFieldConfigurator<FirTreeBuilder>(FirTreeBuild
|
||||
constructor.configure {
|
||||
+annotations
|
||||
+symbol("FirConstructorSymbol")
|
||||
+field("delegatedConstructor", delegatedConstructorCall, nullable = true).withTransform()
|
||||
+field("delegatedConstructor", delegatedConstructorCall, nullable = true, withReplace = true).withTransform()
|
||||
+body(nullable = true)
|
||||
+booleanField("isPrimary")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user