FIR. Refactor smart-cast representation in FIR tree

Make smart-casts non-transparent expression without delegation
to underlying FirQualifiedAccessExpression, as children delegation in
fir tree has unclear semantics
Remove two different kinds of tree nodes for smart-casts
This commit is contained in:
Simon Ogorodnik
2022-08-02 00:49:24 +02:00
committed by teamcity
parent bc9db58b3c
commit 513af2dfbc
154 changed files with 9573 additions and 9320 deletions
@@ -1,70 +0,0 @@
/*
* 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.
*/
package org.jetbrains.kotlin.fir.expressions
import org.jetbrains.kotlin.KtSourceElement
import org.jetbrains.kotlin.fir.FirElement
import org.jetbrains.kotlin.fir.references.FirReference
import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.fir.types.FirTypeProjection
import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.types.SmartcastStability
import org.jetbrains.kotlin.fir.visitors.*
import org.jetbrains.kotlin.fir.FirImplementationDetail
/*
* This file was generated automatically
* DO NOT MODIFY IT MANUALLY
*/
abstract class FirExpressionWithSmartcast : FirQualifiedAccessExpression(), FirWrappedExpressionWithSmartcast<FirQualifiedAccessExpression> {
abstract override val source: KtSourceElement?
abstract override val typeRef: FirTypeRef
abstract override val annotations: List<FirAnnotation>
abstract override val calleeReference: FirReference
abstract override val contextReceiverArguments: List<FirExpression>
abstract override val typeArguments: List<FirTypeProjection>
abstract override val explicitReceiver: FirExpression?
abstract override val dispatchReceiver: FirExpression
abstract override val extensionReceiver: FirExpression
abstract override val originalExpression: FirQualifiedAccessExpression
abstract override val typesFromSmartCast: Collection<ConeKotlinType>
abstract override val originalType: FirTypeRef
abstract override val smartcastType: FirTypeRef
abstract override val isStable: Boolean
abstract override val smartcastStability: SmartcastStability
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R = visitor.visitExpressionWithSmartcast(this, data)
@Suppress("UNCHECKED_CAST")
override fun <E: FirElement, D> transform(transformer: FirTransformer<D>, data: D): E =
transformer.transformExpressionWithSmartcast(this, data) as E
@FirImplementationDetail
abstract override fun replaceSource(newSource: KtSourceElement?)
abstract override fun replaceTypeRef(newTypeRef: FirTypeRef)
abstract override fun replaceCalleeReference(newCalleeReference: FirReference)
abstract override fun replaceContextReceiverArguments(newContextReceiverArguments: List<FirExpression>)
abstract override fun replaceTypeArguments(newTypeArguments: List<FirTypeProjection>)
abstract override fun replaceExplicitReceiver(newExplicitReceiver: FirExpression?)
abstract override fun <D> transformAnnotations(transformer: FirTransformer<D>, data: D): FirExpressionWithSmartcast
abstract override fun <D> transformCalleeReference(transformer: FirTransformer<D>, data: D): FirExpressionWithSmartcast
abstract override fun <D> transformTypeArguments(transformer: FirTransformer<D>, data: D): FirExpressionWithSmartcast
abstract override fun <D> transformExplicitReceiver(transformer: FirTransformer<D>, data: D): FirExpressionWithSmartcast
abstract override fun <D> transformDispatchReceiver(transformer: FirTransformer<D>, data: D): FirExpressionWithSmartcast
abstract override fun <D> transformExtensionReceiver(transformer: FirTransformer<D>, data: D): FirExpressionWithSmartcast
}
@@ -1,71 +0,0 @@
/*
* 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.
*/
package org.jetbrains.kotlin.fir.expressions
import org.jetbrains.kotlin.KtSourceElement
import org.jetbrains.kotlin.fir.FirElement
import org.jetbrains.kotlin.fir.references.FirReference
import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.fir.types.FirTypeProjection
import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.types.SmartcastStability
import org.jetbrains.kotlin.fir.visitors.*
import org.jetbrains.kotlin.fir.FirImplementationDetail
/*
* This file was generated automatically
* DO NOT MODIFY IT MANUALLY
*/
abstract class FirExpressionWithSmartcastToNothing : FirExpressionWithSmartcast(), FirWrappedExpressionWithSmartcastToNothing<FirQualifiedAccessExpression> {
abstract override val source: KtSourceElement?
abstract override val typeRef: FirTypeRef
abstract override val annotations: List<FirAnnotation>
abstract override val calleeReference: FirReference
abstract override val contextReceiverArguments: List<FirExpression>
abstract override val typeArguments: List<FirTypeProjection>
abstract override val explicitReceiver: FirExpression?
abstract override val dispatchReceiver: FirExpression
abstract override val extensionReceiver: FirExpression
abstract override val originalExpression: FirQualifiedAccessExpression
abstract override val typesFromSmartCast: Collection<ConeKotlinType>
abstract override val originalType: FirTypeRef
abstract override val smartcastType: FirTypeRef
abstract override val isStable: Boolean
abstract override val smartcastStability: SmartcastStability
abstract override val smartcastTypeWithoutNullableNothing: FirTypeRef
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R = visitor.visitExpressionWithSmartcastToNothing(this, data)
@Suppress("UNCHECKED_CAST")
override fun <E: FirElement, D> transform(transformer: FirTransformer<D>, data: D): E =
transformer.transformExpressionWithSmartcastToNothing(this, data) as E
@FirImplementationDetail
abstract override fun replaceSource(newSource: KtSourceElement?)
abstract override fun replaceTypeRef(newTypeRef: FirTypeRef)
abstract override fun replaceCalleeReference(newCalleeReference: FirReference)
abstract override fun replaceContextReceiverArguments(newContextReceiverArguments: List<FirExpression>)
abstract override fun replaceTypeArguments(newTypeArguments: List<FirTypeProjection>)
abstract override fun replaceExplicitReceiver(newExplicitReceiver: FirExpression?)
abstract override fun <D> transformAnnotations(transformer: FirTransformer<D>, data: D): FirExpressionWithSmartcastToNothing
abstract override fun <D> transformCalleeReference(transformer: FirTransformer<D>, data: D): FirExpressionWithSmartcastToNothing
abstract override fun <D> transformTypeArguments(transformer: FirTransformer<D>, data: D): FirExpressionWithSmartcastToNothing
abstract override fun <D> transformExplicitReceiver(transformer: FirTransformer<D>, data: D): FirExpressionWithSmartcastToNothing
abstract override fun <D> transformDispatchReceiver(transformer: FirTransformer<D>, data: D): FirExpressionWithSmartcastToNothing
abstract override fun <D> transformExtensionReceiver(transformer: FirTransformer<D>, data: D): FirExpressionWithSmartcastToNothing
}
@@ -7,7 +7,6 @@ package org.jetbrains.kotlin.fir.expressions
import org.jetbrains.kotlin.KtSourceElement
import org.jetbrains.kotlin.fir.FirElement
import org.jetbrains.kotlin.fir.FirExpressionRef
import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.types.SmartcastStability
@@ -18,25 +17,26 @@ import org.jetbrains.kotlin.fir.visitors.*
* DO NOT MODIFY IT MANUALLY
*/
abstract class FirWhenSubjectExpressionWithSmartcast : FirWhenSubjectExpression(), FirWrappedExpressionWithSmartcast<FirWhenSubjectExpression> {
abstract class FirSmartCastExpression : FirExpression() {
abstract override val source: KtSourceElement?
abstract override val typeRef: FirTypeRef
abstract override val annotations: List<FirAnnotation>
abstract override val whenRef: FirExpressionRef<FirWhenExpression>
abstract override val originalExpression: FirWhenSubjectExpression
abstract override val typesFromSmartCast: Collection<ConeKotlinType>
abstract override val originalType: FirTypeRef
abstract override val smartcastType: FirTypeRef
abstract override val isStable: Boolean
abstract override val smartcastStability: SmartcastStability
abstract override val typeRef: FirTypeRef
abstract val originalExpression: FirExpression
abstract val typesFromSmartCast: Collection<ConeKotlinType>
abstract val smartcastType: FirTypeRef
abstract val smartcastTypeWithoutNullableNothing: FirTypeRef?
abstract val isStable: Boolean
abstract val smartcastStability: SmartcastStability
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R = visitor.visitWhenSubjectExpressionWithSmartcast(this, data)
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R = visitor.visitSmartCastExpression(this, data)
@Suppress("UNCHECKED_CAST")
override fun <E: FirElement, D> transform(transformer: FirTransformer<D>, data: D): E =
transformer.transformWhenSubjectExpressionWithSmartcast(this, data) as E
transformer.transformSmartCastExpression(this, data) as E
abstract override fun replaceTypeRef(newTypeRef: FirTypeRef)
abstract override fun <D> transformAnnotations(transformer: FirTransformer<D>, data: D): FirWhenSubjectExpressionWithSmartcast
abstract override fun <D> transformAnnotations(transformer: FirTransformer<D>, data: D): FirSmartCastExpression
abstract fun <D> transformOriginalExpression(transformer: FirTransformer<D>, data: D): FirSmartCastExpression
}
@@ -1,43 +0,0 @@
/*
* 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.
*/
package org.jetbrains.kotlin.fir.expressions
import org.jetbrains.kotlin.KtSourceElement
import org.jetbrains.kotlin.fir.FirElement
import org.jetbrains.kotlin.fir.FirExpressionRef
import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.types.SmartcastStability
import org.jetbrains.kotlin.fir.visitors.*
/*
* This file was generated automatically
* DO NOT MODIFY IT MANUALLY
*/
abstract class FirWhenSubjectExpressionWithSmartcastToNothing : FirWhenSubjectExpression(), FirWrappedExpressionWithSmartcastToNothing<FirWhenSubjectExpression> {
abstract override val source: KtSourceElement?
abstract override val typeRef: FirTypeRef
abstract override val annotations: List<FirAnnotation>
abstract override val whenRef: FirExpressionRef<FirWhenExpression>
abstract override val originalExpression: FirWhenSubjectExpression
abstract override val typesFromSmartCast: Collection<ConeKotlinType>
abstract override val originalType: FirTypeRef
abstract override val smartcastType: FirTypeRef
abstract override val isStable: Boolean
abstract override val smartcastStability: SmartcastStability
abstract override val smartcastTypeWithoutNullableNothing: FirTypeRef
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R = visitor.visitWhenSubjectExpressionWithSmartcastToNothing(this, data)
@Suppress("UNCHECKED_CAST")
override fun <E: FirElement, D> transform(transformer: FirTransformer<D>, data: D): E =
transformer.transformWhenSubjectExpressionWithSmartcastToNothing(this, data) as E
abstract override fun replaceTypeRef(newTypeRef: FirTypeRef)
abstract override fun <D> transformAnnotations(transformer: FirTransformer<D>, data: D): FirWhenSubjectExpressionWithSmartcastToNothing
}
@@ -1,37 +0,0 @@
/*
* 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.
*/
package org.jetbrains.kotlin.fir.expressions
import org.jetbrains.kotlin.KtSourceElement
import org.jetbrains.kotlin.fir.FirElement
import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.types.SmartcastStability
import org.jetbrains.kotlin.fir.visitors.*
/*
* This file was generated automatically
* DO NOT MODIFY IT MANUALLY
*/
interface FirWrappedExpressionWithSmartcast<E : FirExpression> : FirElement {
override val source: KtSourceElement?
val typeRef: FirTypeRef
val originalExpression: E
val typesFromSmartCast: Collection<ConeKotlinType>
val originalType: FirTypeRef
val smartcastType: FirTypeRef
val isStable: Boolean
val smartcastStability: SmartcastStability
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R = visitor.visitWrappedExpressionWithSmartcast(this, data)
@Suppress("UNCHECKED_CAST")
override fun <E: FirElement, D> transform(transformer: FirTransformer<D>, data: D): E =
transformer.transformWrappedExpressionWithSmartcast(this, data) as E
fun replaceTypeRef(newTypeRef: FirTypeRef)
}
@@ -1,38 +0,0 @@
/*
* 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.
*/
package org.jetbrains.kotlin.fir.expressions
import org.jetbrains.kotlin.KtSourceElement
import org.jetbrains.kotlin.fir.FirElement
import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.types.SmartcastStability
import org.jetbrains.kotlin.fir.visitors.*
/*
* This file was generated automatically
* DO NOT MODIFY IT MANUALLY
*/
interface FirWrappedExpressionWithSmartcastToNothing<E : FirExpression> : FirWrappedExpressionWithSmartcast<E> {
override val source: KtSourceElement?
override val typeRef: FirTypeRef
override val originalExpression: E
override val typesFromSmartCast: Collection<ConeKotlinType>
override val originalType: FirTypeRef
override val smartcastType: FirTypeRef
override val isStable: Boolean
override val smartcastStability: SmartcastStability
val smartcastTypeWithoutNullableNothing: FirTypeRef
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R = visitor.visitWrappedExpressionWithSmartcastToNothing(this, data)
@Suppress("UNCHECKED_CAST")
override fun <E: FirElement, D> transform(transformer: FirTransformer<D>, data: D): E =
transformer.transformWrappedExpressionWithSmartcastToNothing(this, data) as E
override fun replaceTypeRef(newTypeRef: FirTypeRef)
}
@@ -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.builder.FirAnnotationContainerBuilder
import org.jetbrains.kotlin.fir.builder.FirBuilderDsl
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
import org.jetbrains.kotlin.fir.expressions.FirExpression
import org.jetbrains.kotlin.fir.expressions.FirSmartCastExpression
import org.jetbrains.kotlin.fir.expressions.builder.FirExpressionBuilder
import org.jetbrains.kotlin.fir.expressions.impl.FirSmartCastExpressionImpl
import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.fir.visitors.*
import org.jetbrains.kotlin.types.SmartcastStability
/*
* This file was generated automatically
* DO NOT MODIFY IT MANUALLY
*/
@FirBuilderDsl
class FirSmartCastExpressionBuilder : FirAnnotationContainerBuilder, FirExpressionBuilder {
override var source: KtSourceElement? = null
override val annotations: MutableList<FirAnnotation> = mutableListOf()
override lateinit var typeRef: FirTypeRef
lateinit var originalExpression: FirExpression
lateinit var typesFromSmartCast: Collection<ConeKotlinType>
lateinit var smartcastType: FirTypeRef
var smartcastTypeWithoutNullableNothing: FirTypeRef? = null
lateinit var smartcastStability: SmartcastStability
override fun build(): FirSmartCastExpression {
return FirSmartCastExpressionImpl(
source,
annotations,
typeRef,
originalExpression,
typesFromSmartCast,
smartcastType,
smartcastTypeWithoutNullableNothing,
smartcastStability,
)
}
}
@OptIn(ExperimentalContracts::class)
inline fun buildSmartCastExpression(init: FirSmartCastExpressionBuilder.() -> Unit): FirSmartCastExpression {
contract {
callsInPlace(init, kotlin.contracts.InvocationKind.EXACTLY_ONCE)
}
return FirSmartCastExpressionBuilder().apply(init).build()
}
@@ -0,0 +1,66 @@
/*
* 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.expressions.FirAnnotation
import org.jetbrains.kotlin.fir.expressions.FirExpression
import org.jetbrains.kotlin.fir.expressions.FirSmartCastExpression
import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.types.SmartcastStability
import org.jetbrains.kotlin.fir.visitors.*
/*
* This file was generated automatically
* DO NOT MODIFY IT MANUALLY
*/
internal class FirSmartCastExpressionImpl(
override val source: KtSourceElement?,
override val annotations: MutableList<FirAnnotation>,
override var typeRef: FirTypeRef,
override var originalExpression: FirExpression,
override val typesFromSmartCast: Collection<ConeKotlinType>,
override var smartcastType: FirTypeRef,
override var smartcastTypeWithoutNullableNothing: FirTypeRef?,
override val smartcastStability: SmartcastStability,
) : FirSmartCastExpression() {
override val isStable: Boolean get() = smartcastStability == SmartcastStability.STABLE_VALUE
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
annotations.forEach { it.accept(visitor, data) }
typeRef.accept(visitor, data)
originalExpression.accept(visitor, data)
smartcastType.accept(visitor, data)
smartcastTypeWithoutNullableNothing?.accept(visitor, data)
}
override fun <D> transformChildren(transformer: FirTransformer<D>, data: D): FirSmartCastExpressionImpl {
transformAnnotations(transformer, data)
typeRef = typeRef.transform(transformer, data)
transformOriginalExpression(transformer, data)
smartcastType = smartcastType.transform(transformer, data)
smartcastTypeWithoutNullableNothing = smartcastTypeWithoutNullableNothing?.transform(transformer, data)
return this
}
override fun <D> transformAnnotations(transformer: FirTransformer<D>, data: D): FirSmartCastExpressionImpl {
annotations.transformInplace(transformer, data)
return this
}
override fun <D> transformOriginalExpression(transformer: FirTransformer<D>, data: D): FirSmartCastExpressionImpl {
originalExpression = originalExpression.transform(transformer, data)
return this
}
override fun replaceTypeRef(newTypeRef: FirTypeRef) {
typeRef = newTypeRef
}
}
@@ -98,10 +98,7 @@ import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall
import org.jetbrains.kotlin.fir.expressions.FirComponentCall
import org.jetbrains.kotlin.fir.expressions.FirCallableReferenceAccess
import org.jetbrains.kotlin.fir.expressions.FirThisReceiverExpression
import org.jetbrains.kotlin.fir.expressions.FirWrappedExpressionWithSmartcast
import org.jetbrains.kotlin.fir.expressions.FirWrappedExpressionWithSmartcastToNothing
import org.jetbrains.kotlin.fir.expressions.FirExpressionWithSmartcast
import org.jetbrains.kotlin.fir.expressions.FirExpressionWithSmartcastToNothing
import org.jetbrains.kotlin.fir.expressions.FirSmartCastExpression
import org.jetbrains.kotlin.fir.expressions.FirSafeCallExpression
import org.jetbrains.kotlin.fir.expressions.FirCheckedSafeCallSubject
import org.jetbrains.kotlin.fir.expressions.FirGetClassCall
@@ -119,8 +116,6 @@ import org.jetbrains.kotlin.fir.expressions.FirStringConcatenationCall
import org.jetbrains.kotlin.fir.expressions.FirThrowExpression
import org.jetbrains.kotlin.fir.expressions.FirVariableAssignment
import org.jetbrains.kotlin.fir.expressions.FirWhenSubjectExpression
import org.jetbrains.kotlin.fir.expressions.FirWhenSubjectExpressionWithSmartcast
import org.jetbrains.kotlin.fir.expressions.FirWhenSubjectExpressionWithSmartcastToNothing
import org.jetbrains.kotlin.fir.expressions.FirWrappedDelegateExpression
import org.jetbrains.kotlin.fir.references.FirNamedReference
import org.jetbrains.kotlin.fir.references.FirErrorNamedReference
@@ -223,7 +218,7 @@ abstract class FirDefaultVisitor<out R, in D> : FirVisitor<R, D>() {
override fun visitThisReceiverExpression(thisReceiverExpression: FirThisReceiverExpression, data: D): R = visitQualifiedAccessExpression(thisReceiverExpression, data)
override fun <E : FirExpression> visitWrappedExpressionWithSmartcastToNothing(wrappedExpressionWithSmartcastToNothing: FirWrappedExpressionWithSmartcastToNothing<E>, data: D): R = visitWrappedExpressionWithSmartcast(wrappedExpressionWithSmartcastToNothing, data)
override fun visitSmartCastExpression(smartCastExpression: FirSmartCastExpression, data: D): R = visitExpression(smartCastExpression, data)
override fun visitSafeCallExpression(safeCallExpression: FirSafeCallExpression, data: D): R = visitExpression(safeCallExpression, data)
@@ -98,10 +98,7 @@ import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall
import org.jetbrains.kotlin.fir.expressions.FirComponentCall
import org.jetbrains.kotlin.fir.expressions.FirCallableReferenceAccess
import org.jetbrains.kotlin.fir.expressions.FirThisReceiverExpression
import org.jetbrains.kotlin.fir.expressions.FirWrappedExpressionWithSmartcast
import org.jetbrains.kotlin.fir.expressions.FirWrappedExpressionWithSmartcastToNothing
import org.jetbrains.kotlin.fir.expressions.FirExpressionWithSmartcast
import org.jetbrains.kotlin.fir.expressions.FirExpressionWithSmartcastToNothing
import org.jetbrains.kotlin.fir.expressions.FirSmartCastExpression
import org.jetbrains.kotlin.fir.expressions.FirSafeCallExpression
import org.jetbrains.kotlin.fir.expressions.FirCheckedSafeCallSubject
import org.jetbrains.kotlin.fir.expressions.FirGetClassCall
@@ -119,8 +116,6 @@ import org.jetbrains.kotlin.fir.expressions.FirStringConcatenationCall
import org.jetbrains.kotlin.fir.expressions.FirThrowExpression
import org.jetbrains.kotlin.fir.expressions.FirVariableAssignment
import org.jetbrains.kotlin.fir.expressions.FirWhenSubjectExpression
import org.jetbrains.kotlin.fir.expressions.FirWhenSubjectExpressionWithSmartcast
import org.jetbrains.kotlin.fir.expressions.FirWhenSubjectExpressionWithSmartcastToNothing
import org.jetbrains.kotlin.fir.expressions.FirWrappedDelegateExpression
import org.jetbrains.kotlin.fir.references.FirNamedReference
import org.jetbrains.kotlin.fir.references.FirErrorNamedReference
@@ -223,7 +218,7 @@ abstract class FirDefaultVisitorVoid : FirVisitorVoid() {
override fun visitThisReceiverExpression(thisReceiverExpression: FirThisReceiverExpression) = visitQualifiedAccessExpression(thisReceiverExpression)
override fun <E : FirExpression> visitWrappedExpressionWithSmartcastToNothing(wrappedExpressionWithSmartcastToNothing: FirWrappedExpressionWithSmartcastToNothing<E>) = visitWrappedExpressionWithSmartcast(wrappedExpressionWithSmartcastToNothing)
override fun visitSmartCastExpression(smartCastExpression: FirSmartCastExpression) = visitExpression(smartCastExpression)
override fun visitSafeCallExpression(safeCallExpression: FirSafeCallExpression) = visitExpression(safeCallExpression)
@@ -98,10 +98,7 @@ import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall
import org.jetbrains.kotlin.fir.expressions.FirComponentCall
import org.jetbrains.kotlin.fir.expressions.FirCallableReferenceAccess
import org.jetbrains.kotlin.fir.expressions.FirThisReceiverExpression
import org.jetbrains.kotlin.fir.expressions.FirWrappedExpressionWithSmartcast
import org.jetbrains.kotlin.fir.expressions.FirWrappedExpressionWithSmartcastToNothing
import org.jetbrains.kotlin.fir.expressions.FirExpressionWithSmartcast
import org.jetbrains.kotlin.fir.expressions.FirExpressionWithSmartcastToNothing
import org.jetbrains.kotlin.fir.expressions.FirSmartCastExpression
import org.jetbrains.kotlin.fir.expressions.FirSafeCallExpression
import org.jetbrains.kotlin.fir.expressions.FirCheckedSafeCallSubject
import org.jetbrains.kotlin.fir.expressions.FirGetClassCall
@@ -119,8 +116,6 @@ import org.jetbrains.kotlin.fir.expressions.FirStringConcatenationCall
import org.jetbrains.kotlin.fir.expressions.FirThrowExpression
import org.jetbrains.kotlin.fir.expressions.FirVariableAssignment
import org.jetbrains.kotlin.fir.expressions.FirWhenSubjectExpression
import org.jetbrains.kotlin.fir.expressions.FirWhenSubjectExpressionWithSmartcast
import org.jetbrains.kotlin.fir.expressions.FirWhenSubjectExpressionWithSmartcastToNothing
import org.jetbrains.kotlin.fir.expressions.FirWrappedDelegateExpression
import org.jetbrains.kotlin.fir.references.FirNamedReference
import org.jetbrains.kotlin.fir.references.FirErrorNamedReference
@@ -522,20 +517,8 @@ abstract class FirTransformer<in D> : FirVisitor<FirElement, D>() {
return transformElement(thisReceiverExpression, data)
}
open fun <E : FirExpression> transformWrappedExpressionWithSmartcast(wrappedExpressionWithSmartcast: FirWrappedExpressionWithSmartcast<E>, data: D): FirWrappedExpressionWithSmartcast<E> {
return transformElement(wrappedExpressionWithSmartcast, data)
}
open fun <E : FirExpression> transformWrappedExpressionWithSmartcastToNothing(wrappedExpressionWithSmartcastToNothing: FirWrappedExpressionWithSmartcastToNothing<E>, data: D): FirWrappedExpressionWithSmartcastToNothing<E> {
return transformElement(wrappedExpressionWithSmartcastToNothing, data)
}
open fun transformExpressionWithSmartcast(expressionWithSmartcast: FirExpressionWithSmartcast, data: D): FirStatement {
return transformElement(expressionWithSmartcast, data)
}
open fun transformExpressionWithSmartcastToNothing(expressionWithSmartcastToNothing: FirExpressionWithSmartcastToNothing, data: D): FirStatement {
return transformElement(expressionWithSmartcastToNothing, data)
open fun transformSmartCastExpression(smartCastExpression: FirSmartCastExpression, data: D): FirStatement {
return transformElement(smartCastExpression, data)
}
open fun transformSafeCallExpression(safeCallExpression: FirSafeCallExpression, data: D): FirStatement {
@@ -606,14 +589,6 @@ abstract class FirTransformer<in D> : FirVisitor<FirElement, D>() {
return transformElement(whenSubjectExpression, data)
}
open fun transformWhenSubjectExpressionWithSmartcast(whenSubjectExpressionWithSmartcast: FirWhenSubjectExpressionWithSmartcast, data: D): FirStatement {
return transformElement(whenSubjectExpressionWithSmartcast, data)
}
open fun transformWhenSubjectExpressionWithSmartcastToNothing(whenSubjectExpressionWithSmartcastToNothing: FirWhenSubjectExpressionWithSmartcastToNothing, data: D): FirStatement {
return transformElement(whenSubjectExpressionWithSmartcastToNothing, data)
}
open fun transformWrappedDelegateExpression(wrappedDelegateExpression: FirWrappedDelegateExpression, data: D): FirStatement {
return transformElement(wrappedDelegateExpression, data)
}
@@ -1078,20 +1053,8 @@ abstract class FirTransformer<in D> : FirVisitor<FirElement, D>() {
return transformThisReceiverExpression(thisReceiverExpression, data)
}
final override fun <E : FirExpression> visitWrappedExpressionWithSmartcast(wrappedExpressionWithSmartcast: FirWrappedExpressionWithSmartcast<E>, data: D): FirWrappedExpressionWithSmartcast<E> {
return transformWrappedExpressionWithSmartcast(wrappedExpressionWithSmartcast, data)
}
final override fun <E : FirExpression> visitWrappedExpressionWithSmartcastToNothing(wrappedExpressionWithSmartcastToNothing: FirWrappedExpressionWithSmartcastToNothing<E>, data: D): FirWrappedExpressionWithSmartcastToNothing<E> {
return transformWrappedExpressionWithSmartcastToNothing(wrappedExpressionWithSmartcastToNothing, data)
}
final override fun visitExpressionWithSmartcast(expressionWithSmartcast: FirExpressionWithSmartcast, data: D): FirStatement {
return transformExpressionWithSmartcast(expressionWithSmartcast, data)
}
final override fun visitExpressionWithSmartcastToNothing(expressionWithSmartcastToNothing: FirExpressionWithSmartcastToNothing, data: D): FirStatement {
return transformExpressionWithSmartcastToNothing(expressionWithSmartcastToNothing, data)
final override fun visitSmartCastExpression(smartCastExpression: FirSmartCastExpression, data: D): FirStatement {
return transformSmartCastExpression(smartCastExpression, data)
}
final override fun visitSafeCallExpression(safeCallExpression: FirSafeCallExpression, data: D): FirStatement {
@@ -1162,14 +1125,6 @@ abstract class FirTransformer<in D> : FirVisitor<FirElement, D>() {
return transformWhenSubjectExpression(whenSubjectExpression, data)
}
final override fun visitWhenSubjectExpressionWithSmartcast(whenSubjectExpressionWithSmartcast: FirWhenSubjectExpressionWithSmartcast, data: D): FirStatement {
return transformWhenSubjectExpressionWithSmartcast(whenSubjectExpressionWithSmartcast, data)
}
final override fun visitWhenSubjectExpressionWithSmartcastToNothing(whenSubjectExpressionWithSmartcastToNothing: FirWhenSubjectExpressionWithSmartcastToNothing, data: D): FirStatement {
return transformWhenSubjectExpressionWithSmartcastToNothing(whenSubjectExpressionWithSmartcastToNothing, data)
}
final override fun visitWrappedDelegateExpression(wrappedDelegateExpression: FirWrappedDelegateExpression, data: D): FirStatement {
return transformWrappedDelegateExpression(wrappedDelegateExpression, data)
}
@@ -98,10 +98,7 @@ import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall
import org.jetbrains.kotlin.fir.expressions.FirComponentCall
import org.jetbrains.kotlin.fir.expressions.FirCallableReferenceAccess
import org.jetbrains.kotlin.fir.expressions.FirThisReceiverExpression
import org.jetbrains.kotlin.fir.expressions.FirWrappedExpressionWithSmartcast
import org.jetbrains.kotlin.fir.expressions.FirWrappedExpressionWithSmartcastToNothing
import org.jetbrains.kotlin.fir.expressions.FirExpressionWithSmartcast
import org.jetbrains.kotlin.fir.expressions.FirExpressionWithSmartcastToNothing
import org.jetbrains.kotlin.fir.expressions.FirSmartCastExpression
import org.jetbrains.kotlin.fir.expressions.FirSafeCallExpression
import org.jetbrains.kotlin.fir.expressions.FirCheckedSafeCallSubject
import org.jetbrains.kotlin.fir.expressions.FirGetClassCall
@@ -119,8 +116,6 @@ import org.jetbrains.kotlin.fir.expressions.FirStringConcatenationCall
import org.jetbrains.kotlin.fir.expressions.FirThrowExpression
import org.jetbrains.kotlin.fir.expressions.FirVariableAssignment
import org.jetbrains.kotlin.fir.expressions.FirWhenSubjectExpression
import org.jetbrains.kotlin.fir.expressions.FirWhenSubjectExpressionWithSmartcast
import org.jetbrains.kotlin.fir.expressions.FirWhenSubjectExpressionWithSmartcastToNothing
import org.jetbrains.kotlin.fir.expressions.FirWrappedDelegateExpression
import org.jetbrains.kotlin.fir.references.FirNamedReference
import org.jetbrains.kotlin.fir.references.FirErrorNamedReference
@@ -337,13 +332,7 @@ abstract class FirVisitor<out R, in D> {
open fun visitThisReceiverExpression(thisReceiverExpression: FirThisReceiverExpression, data: D): R = visitElement(thisReceiverExpression, data)
open fun <E : FirExpression> visitWrappedExpressionWithSmartcast(wrappedExpressionWithSmartcast: FirWrappedExpressionWithSmartcast<E>, data: D): R = visitElement(wrappedExpressionWithSmartcast, data)
open fun <E : FirExpression> visitWrappedExpressionWithSmartcastToNothing(wrappedExpressionWithSmartcastToNothing: FirWrappedExpressionWithSmartcastToNothing<E>, data: D): R = visitElement(wrappedExpressionWithSmartcastToNothing, data)
open fun visitExpressionWithSmartcast(expressionWithSmartcast: FirExpressionWithSmartcast, data: D): R = visitElement(expressionWithSmartcast, data)
open fun visitExpressionWithSmartcastToNothing(expressionWithSmartcastToNothing: FirExpressionWithSmartcastToNothing, data: D): R = visitElement(expressionWithSmartcastToNothing, data)
open fun visitSmartCastExpression(smartCastExpression: FirSmartCastExpression, data: D): R = visitElement(smartCastExpression, data)
open fun visitSafeCallExpression(safeCallExpression: FirSafeCallExpression, data: D): R = visitElement(safeCallExpression, data)
@@ -379,10 +368,6 @@ abstract class FirVisitor<out R, in D> {
open fun visitWhenSubjectExpression(whenSubjectExpression: FirWhenSubjectExpression, data: D): R = visitElement(whenSubjectExpression, data)
open fun visitWhenSubjectExpressionWithSmartcast(whenSubjectExpressionWithSmartcast: FirWhenSubjectExpressionWithSmartcast, data: D): R = visitElement(whenSubjectExpressionWithSmartcast, data)
open fun visitWhenSubjectExpressionWithSmartcastToNothing(whenSubjectExpressionWithSmartcastToNothing: FirWhenSubjectExpressionWithSmartcastToNothing, data: D): R = visitElement(whenSubjectExpressionWithSmartcastToNothing, data)
open fun visitWrappedDelegateExpression(wrappedDelegateExpression: FirWrappedDelegateExpression, data: D): R = visitElement(wrappedDelegateExpression, data)
open fun visitNamedReference(namedReference: FirNamedReference, data: D): R = visitElement(namedReference, data)
@@ -98,10 +98,7 @@ import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall
import org.jetbrains.kotlin.fir.expressions.FirComponentCall
import org.jetbrains.kotlin.fir.expressions.FirCallableReferenceAccess
import org.jetbrains.kotlin.fir.expressions.FirThisReceiverExpression
import org.jetbrains.kotlin.fir.expressions.FirWrappedExpressionWithSmartcast
import org.jetbrains.kotlin.fir.expressions.FirWrappedExpressionWithSmartcastToNothing
import org.jetbrains.kotlin.fir.expressions.FirExpressionWithSmartcast
import org.jetbrains.kotlin.fir.expressions.FirExpressionWithSmartcastToNothing
import org.jetbrains.kotlin.fir.expressions.FirSmartCastExpression
import org.jetbrains.kotlin.fir.expressions.FirSafeCallExpression
import org.jetbrains.kotlin.fir.expressions.FirCheckedSafeCallSubject
import org.jetbrains.kotlin.fir.expressions.FirGetClassCall
@@ -119,8 +116,6 @@ import org.jetbrains.kotlin.fir.expressions.FirStringConcatenationCall
import org.jetbrains.kotlin.fir.expressions.FirThrowExpression
import org.jetbrains.kotlin.fir.expressions.FirVariableAssignment
import org.jetbrains.kotlin.fir.expressions.FirWhenSubjectExpression
import org.jetbrains.kotlin.fir.expressions.FirWhenSubjectExpressionWithSmartcast
import org.jetbrains.kotlin.fir.expressions.FirWhenSubjectExpressionWithSmartcastToNothing
import org.jetbrains.kotlin.fir.expressions.FirWrappedDelegateExpression
import org.jetbrains.kotlin.fir.references.FirNamedReference
import org.jetbrains.kotlin.fir.references.FirErrorNamedReference
@@ -521,20 +516,8 @@ abstract class FirVisitorVoid : FirVisitor<Unit, Nothing?>() {
visitElement(thisReceiverExpression)
}
open fun <E : FirExpression> visitWrappedExpressionWithSmartcast(wrappedExpressionWithSmartcast: FirWrappedExpressionWithSmartcast<E>) {
visitElement(wrappedExpressionWithSmartcast)
}
open fun <E : FirExpression> visitWrappedExpressionWithSmartcastToNothing(wrappedExpressionWithSmartcastToNothing: FirWrappedExpressionWithSmartcastToNothing<E>) {
visitElement(wrappedExpressionWithSmartcastToNothing)
}
open fun visitExpressionWithSmartcast(expressionWithSmartcast: FirExpressionWithSmartcast) {
visitElement(expressionWithSmartcast)
}
open fun visitExpressionWithSmartcastToNothing(expressionWithSmartcastToNothing: FirExpressionWithSmartcastToNothing) {
visitElement(expressionWithSmartcastToNothing)
open fun visitSmartCastExpression(smartCastExpression: FirSmartCastExpression) {
visitElement(smartCastExpression)
}
open fun visitSafeCallExpression(safeCallExpression: FirSafeCallExpression) {
@@ -605,14 +588,6 @@ abstract class FirVisitorVoid : FirVisitor<Unit, Nothing?>() {
visitElement(whenSubjectExpression)
}
open fun visitWhenSubjectExpressionWithSmartcast(whenSubjectExpressionWithSmartcast: FirWhenSubjectExpressionWithSmartcast) {
visitElement(whenSubjectExpressionWithSmartcast)
}
open fun visitWhenSubjectExpressionWithSmartcastToNothing(whenSubjectExpressionWithSmartcastToNothing: FirWhenSubjectExpressionWithSmartcastToNothing) {
visitElement(whenSubjectExpressionWithSmartcastToNothing)
}
open fun visitWrappedDelegateExpression(wrappedDelegateExpression: FirWrappedDelegateExpression) {
visitElement(wrappedDelegateExpression)
}
@@ -1077,20 +1052,8 @@ abstract class FirVisitorVoid : FirVisitor<Unit, Nothing?>() {
visitThisReceiverExpression(thisReceiverExpression)
}
final override fun <E : FirExpression> visitWrappedExpressionWithSmartcast(wrappedExpressionWithSmartcast: FirWrappedExpressionWithSmartcast<E>, data: Nothing?) {
visitWrappedExpressionWithSmartcast(wrappedExpressionWithSmartcast)
}
final override fun <E : FirExpression> visitWrappedExpressionWithSmartcastToNothing(wrappedExpressionWithSmartcastToNothing: FirWrappedExpressionWithSmartcastToNothing<E>, data: Nothing?) {
visitWrappedExpressionWithSmartcastToNothing(wrappedExpressionWithSmartcastToNothing)
}
final override fun visitExpressionWithSmartcast(expressionWithSmartcast: FirExpressionWithSmartcast, data: Nothing?) {
visitExpressionWithSmartcast(expressionWithSmartcast)
}
final override fun visitExpressionWithSmartcastToNothing(expressionWithSmartcastToNothing: FirExpressionWithSmartcastToNothing, data: Nothing?) {
visitExpressionWithSmartcastToNothing(expressionWithSmartcastToNothing)
final override fun visitSmartCastExpression(smartCastExpression: FirSmartCastExpression, data: Nothing?) {
visitSmartCastExpression(smartCastExpression)
}
final override fun visitSafeCallExpression(safeCallExpression: FirSafeCallExpression, data: Nothing?) {
@@ -1161,14 +1124,6 @@ abstract class FirVisitorVoid : FirVisitor<Unit, Nothing?>() {
visitWhenSubjectExpression(whenSubjectExpression)
}
final override fun visitWhenSubjectExpressionWithSmartcast(whenSubjectExpressionWithSmartcast: FirWhenSubjectExpressionWithSmartcast, data: Nothing?) {
visitWhenSubjectExpressionWithSmartcast(whenSubjectExpressionWithSmartcast)
}
final override fun visitWhenSubjectExpressionWithSmartcastToNothing(whenSubjectExpressionWithSmartcastToNothing: FirWhenSubjectExpressionWithSmartcastToNothing, data: Nothing?) {
visitWhenSubjectExpressionWithSmartcastToNothing(whenSubjectExpressionWithSmartcastToNothing)
}
final override fun visitWrappedDelegateExpression(wrappedDelegateExpression: FirWrappedDelegateExpression, data: Nothing?) {
visitWrappedDelegateExpression(wrappedDelegateExpression)
}
@@ -75,6 +75,7 @@ fun FirExpression.toResolvedCallableReference(): FirResolvedNamedReference? {
fun FirExpression.toReference(): FirReference? {
if (this is FirWrappedArgumentExpression) return expression.toResolvedCallableReference()
if (this is FirSmartCastExpression) return originalExpression.toReference()
return (this as? FirResolvable)?.calleeReference
}
@@ -1,20 +0,0 @@
/*
* Copyright 2010-2020 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.
*/
package org.jetbrains.kotlin.fir.expressions.builder
import org.jetbrains.kotlin.fir.expressions.FirExpressionWithSmartcast
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression
import org.jetbrains.kotlin.fir.expressions.impl.FirExpressionWithSmartcastImpl
class FirExpressionWithSmartcastBuilder : FirWrappedExpressionWithSmartcastBuilder<FirQualifiedAccessExpression>() {
override fun build(): FirExpressionWithSmartcast {
return FirExpressionWithSmartcastImpl(originalExpression, smartcastType, typesFromSmartCast, smartcastStability)
}
}
inline fun buildExpressionWithSmartcast(init: FirExpressionWithSmartcastBuilder.() -> Unit): FirExpressionWithSmartcast {
return FirExpressionWithSmartcastBuilder().apply(init).build()
}
@@ -1,26 +0,0 @@
/*
* Copyright 2010-2021 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.
*/
package org.jetbrains.kotlin.fir.expressions.builder
import org.jetbrains.kotlin.fir.expressions.FirExpressionWithSmartcastToNothing
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression
import org.jetbrains.kotlin.fir.expressions.impl.FirExpressionWithSmartcastToNothingImpl
class FirExpressionWithSmartcastToNothingBuilder : FirWrappedExpressionWithSmartcastToNothingBuilder<FirQualifiedAccessExpression>() {
override fun build(): FirExpressionWithSmartcastToNothing {
return FirExpressionWithSmartcastToNothingImpl(
originalExpression,
smartcastType,
typesFromSmartCast,
smartcastStability,
smartcastTypeWithoutNullableNothing
)
}
}
inline fun buildExpressionWithSmartcastToNothing(init: FirExpressionWithSmartcastToNothingBuilder.() -> Unit): FirExpressionWithSmartcastToNothing {
return FirExpressionWithSmartcastToNothingBuilder().apply(init).build()
}
@@ -1,20 +0,0 @@
/*
* Copyright 2010-2021 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.
*/
package org.jetbrains.kotlin.fir.expressions.builder
import org.jetbrains.kotlin.fir.expressions.FirWhenSubjectExpression
import org.jetbrains.kotlin.fir.expressions.FirWhenSubjectExpressionWithSmartcast
import org.jetbrains.kotlin.fir.expressions.impl.FirWhenSubjectExpressionWithSmartcastImpl
class FirWhenSubjectExpressionWithSmartcastBuilder : FirWrappedExpressionWithSmartcastBuilder<FirWhenSubjectExpression>() {
override fun build(): FirWhenSubjectExpressionWithSmartcast {
return FirWhenSubjectExpressionWithSmartcastImpl(originalExpression, smartcastType, typesFromSmartCast, smartcastStability)
}
}
fun buildWhenSubjectExpressionWithSmartcast(init: FirWhenSubjectExpressionWithSmartcastBuilder.() -> Unit): FirWhenSubjectExpressionWithSmartcast {
return FirWhenSubjectExpressionWithSmartcastBuilder().apply(init).build()
}
@@ -1,26 +0,0 @@
/*
* Copyright 2010-2021 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.
*/
package org.jetbrains.kotlin.fir.expressions.builder
import org.jetbrains.kotlin.fir.expressions.FirWhenSubjectExpression
import org.jetbrains.kotlin.fir.expressions.FirWhenSubjectExpressionWithSmartcastToNothing
import org.jetbrains.kotlin.fir.expressions.impl.FirWhenSubjectExpressionWithSmartcastToNothingImpl
class FirWhenSubjectExpressionWithSmartcastToNothingBuilder : FirWrappedExpressionWithSmartcastToNothingBuilder<FirWhenSubjectExpression>() {
override fun build(): FirWhenSubjectExpressionWithSmartcastToNothing {
return FirWhenSubjectExpressionWithSmartcastToNothingImpl(
originalExpression,
smartcastType,
typesFromSmartCast,
smartcastStability,
smartcastTypeWithoutNullableNothing
)
}
}
fun buildWhenSubjectExpressionWithSmartcastToNothing(init: FirWhenSubjectExpressionWithSmartcastToNothingBuilder.() -> Unit): FirWhenSubjectExpressionWithSmartcastToNothing {
return FirWhenSubjectExpressionWithSmartcastToNothingBuilder().apply(init).build()
}
@@ -1,24 +0,0 @@
/*
* Copyright 2010-2021 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.
*/
package org.jetbrains.kotlin.fir.expressions.builder
import org.jetbrains.kotlin.fir.expressions.FirExpression
import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.types.SmartcastStability
abstract class FirWrappedExpressionWithSmartcastBuilder<E : FirExpression> {
lateinit var originalExpression: E
lateinit var smartcastType: FirTypeRef
lateinit var typesFromSmartCast: Collection<ConeKotlinType>
lateinit var smartcastStability: SmartcastStability
abstract fun build(): E
}
abstract class FirWrappedExpressionWithSmartcastToNothingBuilder<E : FirExpression> : FirWrappedExpressionWithSmartcastBuilder<E>() {
lateinit var smartcastTypeWithoutNullableNothing: FirTypeRef
}
@@ -1,104 +0,0 @@
/*
* Copyright 2010-2019 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.
*/
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.FirExpression
import org.jetbrains.kotlin.fir.expressions.FirExpressionWithSmartcast
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression
import org.jetbrains.kotlin.fir.references.FirReference
import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
import org.jetbrains.kotlin.fir.types.FirTypeProjection
import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.fir.visitors.FirTransformer
import org.jetbrains.kotlin.fir.visitors.FirVisitor
import org.jetbrains.kotlin.fir.visitors.transformSingle
import org.jetbrains.kotlin.types.SmartcastStability
internal class FirExpressionWithSmartcastImpl(
override var originalExpression: FirQualifiedAccessExpression,
override val smartcastType: FirTypeRef,
override val typesFromSmartCast: Collection<ConeKotlinType>,
override val smartcastStability: SmartcastStability
) : FirExpressionWithSmartcast() {
init {
assert(originalExpression.typeRef is FirResolvedTypeRef)
}
override val source: KtSourceElement? get() = originalExpression.source
override val annotations: List<FirAnnotation> get() = originalExpression.annotations
override val typeArguments: List<FirTypeProjection> get() = originalExpression.typeArguments
override val explicitReceiver: FirExpression? get() = originalExpression.explicitReceiver
override val dispatchReceiver: FirExpression get() = originalExpression.dispatchReceiver
override val extensionReceiver: FirExpression get() = originalExpression.extensionReceiver
override val contextReceiverArguments: List<FirExpression> get() = originalExpression.contextReceiverArguments
override val calleeReference: FirReference get() = originalExpression.calleeReference
override val originalType: FirTypeRef get() = originalExpression.typeRef
override val isStable: Boolean get() = smartcastStability == SmartcastStability.STABLE_VALUE
// A FirExpressionWithSmartcast is only an effective smartcast if `smartcastStability == SmartcastStability.STABLE_VALUE`. Otherwise,
// it's the same as the `originalExpression` under the hood. The reason we still create such a smartcast expression is for diagnostics
// purpose only.
override val typeRef: FirTypeRef get() = if (isStable) smartcastType else originalType
override fun <D> transformChildren(transformer: FirTransformer<D>, data: D): FirExpressionWithSmartcast {
originalExpression = originalExpression.transformSingle(transformer, data)
return this
}
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
originalExpression.accept(visitor, data)
}
override fun <D> transformCalleeReference(transformer: FirTransformer<D>, data: D): FirExpressionWithSmartcast {
throw IllegalStateException()
}
override fun <D> transformExplicitReceiver(transformer: FirTransformer<D>, data: D): FirExpressionWithSmartcast {
throw IllegalStateException()
}
override fun <D> transformDispatchReceiver(transformer: FirTransformer<D>, data: D): FirExpressionWithSmartcast {
throw IllegalStateException()
}
override fun <D> transformExtensionReceiver(transformer: FirTransformer<D>, data: D): FirExpressionWithSmartcast {
throw IllegalStateException()
}
override fun <D> transformTypeArguments(transformer: FirTransformer<D>, data: D): FirExpressionWithSmartcast {
throw IllegalStateException()
}
override fun <D> transformAnnotations(transformer: FirTransformer<D>, data: D): FirExpressionWithSmartcast {
throw IllegalStateException()
}
override fun replaceTypeArguments(newTypeArguments: List<FirTypeProjection>) {
throw IllegalStateException()
}
override fun replaceCalleeReference(newCalleeReference: FirReference) {
throw IllegalStateException()
}
override fun replaceExplicitReceiver(newExplicitReceiver: FirExpression?) {
throw IllegalStateException()
}
override fun replaceTypeRef(newTypeRef: FirTypeRef) {}
@FirImplementationDetail
override fun replaceSource(newSource: KtSourceElement?) {
}
override fun replaceContextReceiverArguments(newContextReceiverArguments: List<FirExpression>) {
throw IllegalStateException()
}
}
@@ -1,105 +0,0 @@
/*
* Copyright 2010-2021 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.
*/
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.FirExpression
import org.jetbrains.kotlin.fir.expressions.FirExpressionWithSmartcastToNothing
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression
import org.jetbrains.kotlin.fir.references.FirReference
import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
import org.jetbrains.kotlin.fir.types.FirTypeProjection
import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.fir.visitors.FirTransformer
import org.jetbrains.kotlin.fir.visitors.FirVisitor
import org.jetbrains.kotlin.fir.visitors.transformSingle
import org.jetbrains.kotlin.types.SmartcastStability
class FirExpressionWithSmartcastToNothingImpl(
override var originalExpression: FirQualifiedAccessExpression,
override val smartcastType: FirTypeRef,
override val typesFromSmartCast: Collection<ConeKotlinType>,
override val smartcastStability: SmartcastStability,
override val smartcastTypeWithoutNullableNothing: FirTypeRef
) : FirExpressionWithSmartcastToNothing() {
init {
assert(originalExpression.typeRef is FirResolvedTypeRef)
}
override val source: KtSourceElement? get() = originalExpression.source
override val annotations: List<FirAnnotation> get() = originalExpression.annotations
override val typeArguments: List<FirTypeProjection> get() = originalExpression.typeArguments
override val explicitReceiver: FirExpression? get() = originalExpression.explicitReceiver
override val dispatchReceiver: FirExpression get() = originalExpression.dispatchReceiver
override val extensionReceiver: FirExpression get() = originalExpression.extensionReceiver
override val contextReceiverArguments: List<FirExpression> get() = originalExpression.contextReceiverArguments
override val isStable: Boolean get() = smartcastStability == SmartcastStability.STABLE_VALUE
override val calleeReference: FirReference get() = originalExpression.calleeReference
override val originalType: FirTypeRef get() = originalExpression.typeRef
// A FirExpressionWithSmartcast is only an effective smartcast if `smartcastStability == SmartcastStability.STABLE_VALUE`. Otherwise,
// it's the same as the `originalExpression` under the hood. The reason we still create such a smartcast expression is for diagnostics
// purpose only.
override val typeRef: FirTypeRef get() = if (isStable) smartcastType else originalType
override fun <D> transformChildren(transformer: FirTransformer<D>, data: D): FirExpressionWithSmartcastToNothing {
originalExpression = originalExpression.transformSingle(transformer, data)
return this
}
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
originalExpression.accept(visitor, data)
}
override fun <D> transformCalleeReference(transformer: FirTransformer<D>, data: D): FirExpressionWithSmartcastToNothing {
throw IllegalStateException()
}
override fun <D> transformExplicitReceiver(transformer: FirTransformer<D>, data: D): FirExpressionWithSmartcastToNothing {
throw IllegalStateException()
}
override fun <D> transformDispatchReceiver(transformer: FirTransformer<D>, data: D): FirExpressionWithSmartcastToNothing {
throw IllegalStateException()
}
override fun <D> transformExtensionReceiver(transformer: FirTransformer<D>, data: D): FirExpressionWithSmartcastToNothing {
throw IllegalStateException()
}
override fun <D> transformTypeArguments(transformer: FirTransformer<D>, data: D): FirExpressionWithSmartcastToNothing {
throw IllegalStateException()
}
override fun <D> transformAnnotations(transformer: FirTransformer<D>, data: D): FirExpressionWithSmartcastToNothing {
throw IllegalStateException()
}
override fun replaceTypeArguments(newTypeArguments: List<FirTypeProjection>) {
throw IllegalStateException()
}
override fun replaceCalleeReference(newCalleeReference: FirReference) {
throw IllegalStateException()
}
override fun replaceExplicitReceiver(newExplicitReceiver: FirExpression?) {
throw IllegalStateException()
}
override fun replaceTypeRef(newTypeRef: FirTypeRef) {}
@FirImplementationDetail
override fun replaceSource(newSource: KtSourceElement?) {
}
override fun replaceContextReceiverArguments(newContextReceiverArguments: List<FirExpression>) {
throw IllegalStateException()
}
}
@@ -1,51 +0,0 @@
/*
* Copyright 2010-2021 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.
*/
package org.jetbrains.kotlin.fir.expressions.impl
import org.jetbrains.kotlin.KtSourceElement
import org.jetbrains.kotlin.fir.FirElement
import org.jetbrains.kotlin.fir.FirExpressionRef
import org.jetbrains.kotlin.fir.expressions.*
import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.fir.visitors.FirTransformer
import org.jetbrains.kotlin.fir.visitors.FirVisitor
import org.jetbrains.kotlin.types.SmartcastStability
class FirWhenSubjectExpressionWithSmartcastImpl(
override var originalExpression: FirWhenSubjectExpression,
override val smartcastType: FirTypeRef,
override val typesFromSmartCast: Collection<ConeKotlinType>,
override val smartcastStability: SmartcastStability
) : FirWhenSubjectExpressionWithSmartcast() {
init {
assert(originalExpression.typeRef is FirResolvedTypeRef)
}
override val source: KtSourceElement? get() = originalExpression.source
override val annotations: List<FirAnnotation> get() = originalExpression.annotations
override val whenRef: FirExpressionRef<FirWhenExpression> get() = originalExpression.whenRef
override val originalType: FirTypeRef get() = originalExpression.typeRef
override val isStable: Boolean get() = smartcastStability == SmartcastStability.STABLE_VALUE
override val typeRef: FirTypeRef get() = if (isStable) smartcastType else originalExpression.typeRef
override fun replaceTypeRef(newTypeRef: FirTypeRef) {}
override fun <D> transformAnnotations(transformer: FirTransformer<D>, data: D): FirWhenSubjectExpressionWithSmartcast {
throw IllegalStateException()
}
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
originalExpression.accept(visitor, data)
}
override fun <D> transformChildren(transformer: FirTransformer<D>, data: D): FirWhenSubjectExpressionWithSmartcastImpl {
originalExpression = originalExpression.transform(transformer, data)
return this
}
}
@@ -1,52 +0,0 @@
/*
* Copyright 2010-2021 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.
*/
package org.jetbrains.kotlin.fir.expressions.impl
import org.jetbrains.kotlin.KtSourceElement
import org.jetbrains.kotlin.fir.FirElement
import org.jetbrains.kotlin.fir.FirExpressionRef
import org.jetbrains.kotlin.fir.expressions.*
import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.fir.visitors.FirTransformer
import org.jetbrains.kotlin.fir.visitors.FirVisitor
import org.jetbrains.kotlin.types.SmartcastStability
class FirWhenSubjectExpressionWithSmartcastToNothingImpl(
override var originalExpression: FirWhenSubjectExpression,
override val smartcastType: FirTypeRef,
override val typesFromSmartCast: Collection<ConeKotlinType>,
override val smartcastStability: SmartcastStability,
override val smartcastTypeWithoutNullableNothing: FirTypeRef
) : FirWhenSubjectExpressionWithSmartcastToNothing() {
init {
assert(originalExpression.typeRef is FirResolvedTypeRef)
}
override val source: KtSourceElement? get() = originalExpression.source
override val annotations: List<FirAnnotation> get() = originalExpression.annotations
override val whenRef: FirExpressionRef<FirWhenExpression> get() = originalExpression.whenRef
override val originalType: FirTypeRef get() = originalExpression.typeRef
override val isStable: Boolean get() = smartcastStability == SmartcastStability.STABLE_VALUE
override val typeRef: FirTypeRef get() = if (isStable) smartcastType else originalExpression.typeRef
override fun replaceTypeRef(newTypeRef: FirTypeRef) {}
override fun <D> transformAnnotations(transformer: FirTransformer<D>, data: D): FirWhenSubjectExpressionWithSmartcastToNothingImpl {
throw IllegalStateException()
}
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
originalExpression.accept(visitor, data)
}
override fun <D> transformChildren(transformer: FirTransformer<D>, data: D): FirWhenSubjectExpressionWithSmartcastToNothingImpl {
originalExpression = originalExpression.transform(transformer, data)
return this
}
}
@@ -906,8 +906,8 @@ class FirRenderer(
visitQualifiedAccessExpression(thisReceiverExpression)
}
override fun visitExpressionWithSmartcast(expressionWithSmartcast: FirExpressionWithSmartcast) {
visitQualifiedAccessExpression(expressionWithSmartcast)
override fun visitSmartCastExpression(smartCastExpression: FirSmartCastExpression) {
smartCastExpression.originalExpression.accept(this)
}
override fun visitVariableAssignment(variableAssignment: FirVariableAssignment) {
@@ -7,15 +7,10 @@ package org.jetbrains.kotlin.fir.types
import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
import org.jetbrains.kotlin.fir.expressions.FirConstExpression
import org.jetbrains.kotlin.fir.expressions.FirExpression
import org.jetbrains.kotlin.fir.expressions.FirExpressionWithSmartcast
import org.jetbrains.kotlin.fir.expressions.*
import org.jetbrains.kotlin.fir.extensions.extensionService
import org.jetbrains.kotlin.fir.extensions.typeAttributeExtensions
import org.jetbrains.kotlin.fir.render
import org.jetbrains.kotlin.fir.renderer.ConeTypeRenderer
import org.jetbrains.kotlin.fir.renderer.ConeTypeRendererForDebugging
import org.jetbrains.kotlin.fir.types.impl.FirImplicitBuiltinTypeRef
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.StandardClassIds
@@ -60,9 +55,9 @@ val FirExpression.isNullLiteral: Boolean
@OptIn(ExperimentalContracts::class)
fun FirExpression.isStableSmartcast(): Boolean {
contract {
returns(true) implies (this@isStableSmartcast is FirExpressionWithSmartcast)
returns(true) implies (this@isStableSmartcast is FirSmartCastExpression)
}
return this is FirExpressionWithSmartcast && this.isStable
return this is FirSmartCastExpression && this.isStable
}
private val FirTypeRef.lookupTagBasedOrNull: ConeLookupTagBasedType?
@@ -310,6 +310,9 @@ object BuilderConfigurator : AbstractBuilderConfigurator<FirTreeBuilder>(FirTree
withCopy()
}
builder(smartCastExpression) {
}
builder(tryExpression) {
default("calleeReference", "FirStubReference")
useTypes(stubReferenceType)
@@ -120,10 +120,8 @@ object FirTreeBuilder : AbstractFirTreeBuilder() {
val componentCall by element(Expression, functionCall)
val callableReferenceAccess by element(Expression, qualifiedAccessExpression)
val thisReceiverExpression by element(Expression, qualifiedAccessExpression)
val wrappedExpressionWithSmartcast by element(Expression)
val wrappedExpressionWithSmartcastToNothing by element(Expression, wrappedExpressionWithSmartcast)
val expressionWithSmartcast by element(Expression, qualifiedAccessExpression, wrappedExpressionWithSmartcast)
val expressionWithSmartcastToNothing by element(Expression, expressionWithSmartcast, wrappedExpressionWithSmartcastToNothing)
val smartCastExpression by element(Expression, expression)
val safeCallExpression by element(Expression, expression)
val checkedSafeCallSubject by element(Expression, expression)
val getClassCall by element(Expression, expression, call)
@@ -142,8 +140,6 @@ object FirTreeBuilder : AbstractFirTreeBuilder() {
val throwExpression by element(Expression, expression)
val variableAssignment by element(Expression, qualifiedAccess)
val whenSubjectExpression by element(Expression, expression)
val whenSubjectExpressionWithSmartcast by element(Expression, whenSubjectExpression, wrappedExpressionWithSmartcast)
val whenSubjectExpressionWithSmartcastToNothing by element(Expression, whenSubjectExpression, wrappedExpressionWithSmartcastToNothing)
val wrappedDelegateExpression by element(Expression, wrappedExpression)
@@ -189,12 +189,6 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
publicImplementation()
}
noImpl(expressionWithSmartcast)
noImpl(expressionWithSmartcastToNothing)
noImpl(whenSubjectExpressionWithSmartcast)
noImpl(whenSubjectExpressionWithSmartcastToNothing)
impl(getClassCall) {
default("argument") {
value = "argumentList.arguments.first()"
@@ -360,6 +354,13 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
}
}
impl(smartCastExpression) {
default("isStable") {
value = "smartcastStability == SmartcastStability.STABLE_VALUE"
withGetter = true
}
}
impl(resolvedNamedReference) {
defaultNull("candidateSymbol", withGetter = true)
}
@@ -562,7 +563,8 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
"FirIntegerLiteralOperatorCallImpl",
"FirContextReceiverImpl",
"FirClassReferenceExpressionImpl",
"FirGetClassCallImpl"
"FirGetClassCallImpl",
"FirSmartCastExpressionImpl"
)
configureFieldInAllImplementations(
field = "typeRef",
@@ -490,31 +490,16 @@ object NodeConfigurator : AbstractFieldConfigurator<FirTreeBuilder>(FirTreeBuild
+intField("componentIndex")
}
wrappedExpressionWithSmartcast.configure {
withArg("E", expression)
smartCastExpression.configure {
+typeRefField
+field("originalExpression", "E", packageName = null)
+field("originalExpression", expression).withTransform()
+field("typesFromSmartCast", "Collection<ConeKotlinType>", null, customType = coneKotlinTypeType)
+field("originalType", typeRef)
+field("smartcastType", typeRef)
+field("smartcastTypeWithoutNullableNothing", typeRef, nullable = true)
+booleanField("isStable")
+smartcastStability
}
wrappedExpressionWithSmartcastToNothing.configure {
withArg("E", expression)
parentArg(wrappedExpressionWithSmartcast, "E", "E")
+field("smartcastTypeWithoutNullableNothing", typeRef)
}
expressionWithSmartcast.configure {
parentArg(wrappedExpressionWithSmartcast, "E", qualifiedAccessExpression)
}
expressionWithSmartcastToNothing.configure {
parentArg(wrappedExpressionWithSmartcastToNothing, "E", qualifiedAccessExpression)
}
safeCallExpression.configure {
+field("receiver", expression).withTransform()
// Special node that might be used as a reference to receiver of a safe call after null check
@@ -581,14 +566,6 @@ object NodeConfigurator : AbstractFieldConfigurator<FirTreeBuilder>(FirTreeBuild
+field("whenRef", whenRefType)
}
whenSubjectExpressionWithSmartcast.configure {
parentArg(wrappedExpressionWithSmartcast, "E", whenSubjectExpression)
}
whenSubjectExpressionWithSmartcastToNothing.configure {
parentArg(wrappedExpressionWithSmartcastToNothing, "E", whenSubjectExpression)
}
wrappedExpression.configure {
+field(expression).withReplace()
}