[FIR] Drop redundant FirIntegerOperatorCall and number of fir copy methods

This commit is contained in:
Dmitriy Novozhilov
2022-01-28 14:23:32 +03:00
committed by teamcity
parent 27901a55c4
commit 84913772ec
8 changed files with 66 additions and 280 deletions
@@ -5,60 +5,21 @@
package org.jetbrains.kotlin.fir
import org.jetbrains.kotlin.KtSourceElement
import org.jetbrains.kotlin.contracts.description.EventOccurrencesRange
import org.jetbrains.kotlin.descriptors.EffectiveVisibility
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.descriptors.Visibility
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.declarations.builder.buildAnonymousFunction
import org.jetbrains.kotlin.fir.declarations.FirDeclarationStatus
import org.jetbrains.kotlin.fir.declarations.FirTypeParameter
import org.jetbrains.kotlin.fir.declarations.builder.buildTypeParameter
import org.jetbrains.kotlin.fir.declarations.impl.FirDeclarationStatusImpl
import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic
import org.jetbrains.kotlin.fir.expressions.*
import org.jetbrains.kotlin.fir.expressions.builder.*
import org.jetbrains.kotlin.fir.references.FirControlFlowGraphReference
import org.jetbrains.kotlin.fir.references.FirNamedReference
import org.jetbrains.kotlin.fir.references.FirReference
import org.jetbrains.kotlin.fir.scopes.impl.FirIntegerOperatorCall
import org.jetbrains.kotlin.fir.scopes.impl.FirIntegerOperatorCallBuilder
import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.fir.types.builder.buildErrorTypeRef
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
fun FirFunctionCall.copy(
annotations: List<FirAnnotation> = this.annotations,
argumentList: FirArgumentList = this.argumentList,
calleeReference: FirNamedReference = this.calleeReference,
explicitReceiver: FirExpression? = this.explicitReceiver,
dispatchReceiver: FirExpression = this.dispatchReceiver,
extensionReceiver: FirExpression = this.extensionReceiver,
source: KtSourceElement? = this.source,
typeArguments: List<FirTypeProjection> = this.typeArguments,
resultType: FirTypeRef = this.typeRef
): FirFunctionCall {
val builder = if (this is FirIntegerOperatorCall) {
FirIntegerOperatorCallBuilder().apply {
this.calleeReference = calleeReference
}
} else {
FirFunctionCallBuilder().apply {
this.calleeReference = calleeReference
}
}
builder.apply {
this.source = source
this.annotations.addAll(annotations)
this.argumentList = argumentList
this.explicitReceiver = explicitReceiver
this.dispatchReceiver = dispatchReceiver
this.extensionReceiver = extensionReceiver
this.typeArguments.addAll(typeArguments)
this.typeRef = resultType
}
return (builder as FirCallBuilder).build() as FirFunctionCall
}
inline fun FirFunctionCall.copyAsImplicitInvokeCall(
setupCopy: FirImplicitInvokeCallBuilder.() -> Unit
): FirImplicitInvokeCall {
@@ -78,39 +39,6 @@ inline fun FirFunctionCall.copyAsImplicitInvokeCall(
}
}
fun FirAnonymousFunction.copy(
receiverTypeRef: FirTypeRef? = this.receiverTypeRef,
source: KtSourceElement? = this.source,
moduleData: FirModuleData = this.moduleData,
origin: FirDeclarationOrigin = this.origin,
returnTypeRef: FirTypeRef = this.returnTypeRef,
valueParameters: List<FirValueParameter> = this.valueParameters,
body: FirBlock? = this.body,
annotations: List<FirAnnotation> = this.annotations,
typeRef: FirTypeRef = this.typeRef,
label: FirLabel? = this.label,
controlFlowGraphReference: FirControlFlowGraphReference? = this.controlFlowGraphReference,
invocationKind: EventOccurrencesRange? = this.invocationKind
): FirAnonymousFunction {
return buildAnonymousFunction {
this.source = source
this.moduleData = moduleData
this.origin = origin
this.returnTypeRef = returnTypeRef
this.receiverTypeRef = receiverTypeRef
symbol = this@copy.symbol
isLambda = this@copy.isLambda
hasExplicitParameterList = this@copy.hasExplicitParameterList
this.valueParameters.addAll(valueParameters)
this.body = body
this.annotations.addAll(annotations)
this.typeRef = typeRef
this.label = label
this.controlFlowGraphReference = controlFlowGraphReference
this.invocationKind = invocationKind
}
}
fun FirTypeRef.resolvedTypeFromPrototype(
type: ConeKotlinType
): FirResolvedTypeRef {
@@ -138,65 +66,6 @@ fun FirTypeRef.errorTypeFromPrototype(
}
}
fun FirTypeParameter.copy(
bounds: List<FirTypeRef> = this.bounds,
annotations: List<FirAnnotation> = this.annotations
): FirTypeParameter {
return buildTypeParameter {
source = this@copy.source
resolvePhase = this@copy.resolvePhase
moduleData = this@copy.moduleData
name = this@copy.name
symbol = this@copy.symbol
variance = this@copy.variance
isReified = this@copy.isReified
this.bounds += bounds
this.annotations += annotations
}
}
fun FirWhenExpression.copy(
resultType: FirTypeRef = this.typeRef,
calleeReference: FirReference = this.calleeReference,
annotations: List<FirAnnotation> = this.annotations
): FirWhenExpression = buildWhenExpression {
source = this@copy.source
subject = this@copy.subject
subjectVariable = this@copy.subjectVariable
this.calleeReference = calleeReference
branches += this@copy.branches
typeRef = resultType
this.annotations += annotations
usedAsExpression = this@copy.usedAsExpression
exhaustivenessStatus = this@copy.exhaustivenessStatus
}
fun FirTryExpression.copy(
resultType: FirTypeRef = this.typeRef,
calleeReference: FirReference = this.calleeReference,
annotations: List<FirAnnotation> = this.annotations
): FirTryExpression = buildTryExpression {
source = this@copy.source
tryBlock = this@copy.tryBlock
finallyBlock = this@copy.finallyBlock
this.calleeReference = calleeReference
catches += this@copy.catches
typeRef = resultType
this.annotations += annotations
}
fun FirCheckNotNullCall.copy(
resultType: FirTypeRef = this.typeRef,
calleeReference: FirReference = this.calleeReference,
annotations: List<FirAnnotation> = this.annotations
): FirCheckNotNullCall = buildCheckNotNullCall {
source = this@copy.source
this.calleeReference = calleeReference
argumentList = this@copy.argumentList
this.typeRef = resultType
this.annotations += annotations
}
fun FirDeclarationStatus.copy(
isExpect: Boolean = this.isExpect,
newModality: Modality? = null,
@@ -1,81 +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.scopes.impl
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.FirExpression
import org.jetbrains.kotlin.fir.expressions.FirFunctionCallOrigin
import org.jetbrains.kotlin.fir.expressions.builder.FirCallBuilder
import org.jetbrains.kotlin.fir.expressions.builder.FirExpressionBuilder
import org.jetbrains.kotlin.fir.expressions.builder.FirQualifiedAccessBuilder
import org.jetbrains.kotlin.fir.expressions.impl.FirFunctionCallImpl
import org.jetbrains.kotlin.fir.expressions.impl.FirNoReceiverExpression
import org.jetbrains.kotlin.fir.references.FirNamedReference
import org.jetbrains.kotlin.fir.types.FirTypeProjection
import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.fir.types.builder.buildImplicitTypeRef
@OptIn(FirImplementationDetail::class)
class FirIntegerOperatorCall @FirImplementationDetail constructor(
source: KtSourceElement?,
typeRef: FirTypeRef,
annotations: MutableList<FirAnnotation>,
typeArguments: MutableList<FirTypeProjection>,
explicitReceiver: FirExpression?,
dispatchReceiver: FirExpression,
extensionReceiver: FirExpression,
argumentList: FirArgumentList,
calleeReference: FirNamedReference,
) : FirFunctionCallImpl(
source,
typeRef,
annotations,
typeArguments,
explicitReceiver,
dispatchReceiver,
extensionReceiver,
argumentList,
calleeReference,
FirFunctionCallOrigin.Operator
)
@FirBuilderDsl
class FirIntegerOperatorCallBuilder : FirQualifiedAccessBuilder, FirCallBuilder, FirAnnotationContainerBuilder, FirExpressionBuilder {
override var source: KtSourceElement? = null
override var typeRef: FirTypeRef = buildImplicitTypeRef()
override val annotations: MutableList<FirAnnotation> = mutableListOf()
override val typeArguments: MutableList<FirTypeProjection> = mutableListOf()
override var explicitReceiver: FirExpression? = null
override var dispatchReceiver: FirExpression = FirNoReceiverExpression
override var extensionReceiver: FirExpression = FirNoReceiverExpression
lateinit var calleeReference: FirNamedReference
override lateinit var argumentList: FirArgumentList
@OptIn(FirImplementationDetail::class)
override fun build(): FirIntegerOperatorCall {
return FirIntegerOperatorCall(
source,
typeRef,
annotations,
typeArguments,
explicitReceiver,
dispatchReceiver,
extensionReceiver,
argumentList,
calleeReference,
)
}
}
inline fun buildIntegerOperatorFunctionCall(init: FirIntegerOperatorCallBuilder.() -> Unit): FirIntegerOperatorCall {
return FirIntegerOperatorCallBuilder().apply(init).build()
}