[FIR] Remove FirOperatorCall node from fir tree

This commit is contained in:
Ivan Kylchik
2020-07-20 10:48:21 +03:00
parent 3c01a39846
commit 8b9fb6a6cd
22 changed files with 2 additions and 252 deletions
@@ -1331,20 +1331,6 @@ class HtmlFirDump internal constructor(private var linkResolver: FirLinkResolver
generate(second)
}
private fun FlowContent.generateUnary(expression: FirOperatorCall) {
unresolved { +expression.operation.operator }
ws
generate(expression.argument)
}
private fun FlowContent.generate(expression: FirOperatorCall) {
when (expression.arguments.size) {
1 -> generateUnary(expression)
2 -> generateBinary(expression.arguments[0], expression.arguments[1], expression.operation)
else -> inlineUnsupported(expression)
}
}
private fun FlowContent.generate(typeOperatorCall: FirTypeOperatorCall) {
generate(typeOperatorCall.argument)
ws
@@ -1569,7 +1555,6 @@ class HtmlFirDump internal constructor(private var linkResolver: FirLinkResolver
generate(expression.expression)
}
is FirTypeOperatorCall -> generate(expression)
is FirOperatorCall -> generate(expression)
is FirAssignmentOperatorStatement -> generateBinary(expression.leftArgument, expression.rightArgument, expression.operation)
is FirEqualityOperatorCall -> generate(expression)
is FirBinaryLogicExpression -> generate(expression)
@@ -839,9 +839,6 @@ class Fir2IrVisitor(
override fun visitComparisonExpression(comparisonExpression: FirComparisonExpression, data: Any?): IrElement =
operatorGenerator.convertComparisonExpression(comparisonExpression)
override fun visitOperatorCall(operatorCall: FirOperatorCall, data: Any?): IrElement =
operatorGenerator.convertOperatorCall(operatorCall)
override fun visitStringConcatenationCall(stringConcatenationCall: FirStringConcatenationCall, data: Any?): IrElement {
return stringConcatenationCall.convertWithOffsets { startOffset, endOffset ->
IrStringConcatenationImpl(
@@ -34,13 +34,6 @@ internal class OperatorExpressionGenerator(
}
}
fun convertOperatorCall(operatorCall: FirOperatorCall): IrExpression {
return when (val operation = operatorCall.operation) {
FirOperation.EXCL -> visitor.convertToIrExpression(operatorCall.arguments[0]).negate(IrStatementOrigin.EXCL)
else -> error("Unexpected operation: $operation")
}
}
fun convertEqualityOperatorCall(equalityOperatorCall: FirEqualityOperatorCall): IrExpression {
return equalityOperatorCall.convertWithOffsets { startOffset, endOffset ->
generateEqualityOperatorCall(startOffset, endOffset, equalityOperatorCall.operation, equalityOperatorCall.arguments)
@@ -378,14 +378,7 @@ class ExpressionsConverter(
explicitReceiver = getAsFirExpression(argument, "No operand")
}
}
else -> {
val firOperation = operationToken.toFirOperation()
buildOperatorCall {
source = unaryExpression.toFirSourceElement()
operation = firOperation
argumentList = buildUnaryArgumentList(getAsFirExpression<FirExpression>(argument, "No operand"))
}
}
else -> throw IllegalStateException("Unexpected expression: ${unaryExpression.asText}")
}
}
@@ -35,7 +35,6 @@ data class WhenEntry(
fun toFirWhenConditionWithoutSubject(): FirExpression {
return when (val condition = conditions.firstOrNull()) {
// is FirOperatorCall -> condition.arguments.first()
null -> buildErrorExpression(null, ConeSimpleDiagnostic("No expression in condition with expression", DiagnosticKind.Syntax))
else -> condition
}
@@ -1687,13 +1687,7 @@ class RawFirBuilder(
explicitReceiver = argument.toFirExpression("No operand")
}
}
else -> {
buildOperatorCall {
source = expression.toFirSourceElement()
operation = operationToken.toFirOperation()
argumentList = buildUnaryArgumentList(argument.toFirExpression("No operand"))
}
}
else -> throw IllegalStateException("Unexpected expression: ${expression.text}")
}
}
@@ -119,10 +119,6 @@ class IntegerLiteralTypeApproximationTransformer(
}.compose()
}
override fun transformOperatorCall(operatorCall: FirOperatorCall, data: ConeKotlinType?): CompositeTransformResult<FirStatement> {
return operatorCall.compose()
}
// TODO: call outside
override fun transformTypeOperatorCall(
typeOperatorCall: FirTypeOperatorCall,
@@ -132,10 +132,6 @@ open class FirBodyResolveTransformer(
return expressionsTransformer.transformComparisonExpression(comparisonExpression, data)
}
override fun transformOperatorCall(operatorCall: FirOperatorCall, data: ResolutionMode): CompositeTransformResult<FirStatement> {
return expressionsTransformer.transformOperatorCall(operatorCall, data)
}
override fun transformTypeOperatorCall(typeOperatorCall: FirTypeOperatorCall, data: ResolutionMode): CompositeTransformResult<FirStatement> {
return expressionsTransformer.transformTypeOperatorCall(typeOperatorCall, data)
}
@@ -429,10 +429,6 @@ open class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransform
return result.compose()
}
override fun transformOperatorCall(operatorCall: FirOperatorCall, data: ResolutionMode): CompositeTransformResult<FirStatement> {
throw IllegalArgumentException(operatorCall.render())
}
private inline fun <T> resolveCandidateForAssignmentOperatorCall(block: () -> T): T {
return dataFlowAnalyzer.withIgnoreFunctionCalls {
callResolver.withNoArgumentsTransform {
@@ -145,10 +145,6 @@ private class FirExpressionsResolveTransformerForSpecificAnnotations(
return comparisonExpression.compose()
}
override fun transformOperatorCall(operatorCall: FirOperatorCall, data: ResolutionMode): CompositeTransformResult<FirStatement> {
return operatorCall.compose()
}
override fun transformTypeOperatorCall(
typeOperatorCall: FirTypeOperatorCall,
data: ResolutionMode
@@ -1,31 +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
import org.jetbrains.kotlin.fir.FirSourceElement
import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.fir.visitors.*
/*
* This file was generated automatically
* DO NOT MODIFY IT MANUALLY
*/
abstract class FirOperatorCall : FirExpression(), FirCall {
abstract override val source: FirSourceElement?
abstract override val typeRef: FirTypeRef
abstract override val annotations: List<FirAnnotationCall>
abstract override val argumentList: FirArgumentList
abstract val operation: FirOperation
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R = visitor.visitOperatorCall(this, data)
abstract override fun replaceTypeRef(newTypeRef: FirTypeRef)
abstract override fun replaceArgumentList(newArgumentList: FirArgumentList)
abstract override fun <D> transformAnnotations(transformer: FirTransformer<D>, data: D): FirOperatorCall
}
@@ -1,59 +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 kotlin.contracts.*
import org.jetbrains.kotlin.fir.FirSourceElement
import org.jetbrains.kotlin.fir.builder.FirAnnotationContainerBuilder
import org.jetbrains.kotlin.fir.builder.FirBuilderDsl
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
import org.jetbrains.kotlin.fir.expressions.FirArgumentList
import org.jetbrains.kotlin.fir.expressions.FirOperation
import org.jetbrains.kotlin.fir.expressions.FirOperatorCall
import org.jetbrains.kotlin.fir.expressions.builder.FirCallBuilder
import org.jetbrains.kotlin.fir.expressions.builder.FirExpressionBuilder
import org.jetbrains.kotlin.fir.expressions.impl.FirOperatorCallImpl
import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.fir.types.impl.FirImplicitTypeRefImpl
import org.jetbrains.kotlin.fir.visitors.*
/*
* This file was generated automatically
* DO NOT MODIFY IT MANUALLY
*/
@FirBuilderDsl
class FirOperatorCallBuilder : FirCallBuilder, FirAnnotationContainerBuilder, FirExpressionBuilder {
override var source: FirSourceElement? = null
override val annotations: MutableList<FirAnnotationCall> = mutableListOf()
override lateinit var argumentList: FirArgumentList
lateinit var operation: FirOperation
override fun build(): FirOperatorCall {
return FirOperatorCallImpl(
source,
annotations,
argumentList,
operation,
)
}
@Deprecated("Modification of 'typeRef' has no impact for FirOperatorCallBuilder", level = DeprecationLevel.HIDDEN)
override var typeRef: FirTypeRef
get() = throw IllegalStateException()
set(value) {
throw IllegalStateException()
}
}
@OptIn(ExperimentalContracts::class)
inline fun buildOperatorCall(init: FirOperatorCallBuilder.() -> Unit): FirOperatorCall {
contract {
callsInPlace(init, kotlin.contracts.InvocationKind.EXACTLY_ONCE)
}
return FirOperatorCallBuilder().apply(init).build()
}
@@ -1,55 +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.impl
import org.jetbrains.kotlin.fir.FirSourceElement
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
import org.jetbrains.kotlin.fir.expressions.FirArgumentList
import org.jetbrains.kotlin.fir.expressions.FirOperation
import org.jetbrains.kotlin.fir.expressions.FirOperatorCall
import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.fir.types.impl.FirImplicitTypeRefImpl
import org.jetbrains.kotlin.fir.visitors.*
/*
* This file was generated automatically
* DO NOT MODIFY IT MANUALLY
*/
internal class FirOperatorCallImpl(
override val source: FirSourceElement?,
override val annotations: MutableList<FirAnnotationCall>,
override var argumentList: FirArgumentList,
override val operation: FirOperation,
) : FirOperatorCall() {
override var typeRef: FirTypeRef = FirImplicitTypeRefImpl(null)
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
typeRef.accept(visitor, data)
annotations.forEach { it.accept(visitor, data) }
argumentList.accept(visitor, data)
}
override fun <D> transformChildren(transformer: FirTransformer<D>, data: D): FirOperatorCallImpl {
typeRef = typeRef.transformSingle(transformer, data)
transformAnnotations(transformer, data)
argumentList = argumentList.transformSingle(transformer, data)
return this
}
override fun <D> transformAnnotations(transformer: FirTransformer<D>, data: D): FirOperatorCallImpl {
annotations.transformInplace(transformer, data)
return this
}
override fun replaceTypeRef(newTypeRef: FirTypeRef) {
typeRef = newTypeRef
}
override fun replaceArgumentList(newArgumentList: FirArgumentList) {
argumentList = newArgumentList
}
}
@@ -68,7 +68,6 @@ import org.jetbrains.kotlin.fir.types.FirTypeProjectionWithVariance
import org.jetbrains.kotlin.fir.expressions.FirArgumentList
import org.jetbrains.kotlin.fir.expressions.FirCall
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
import org.jetbrains.kotlin.fir.expressions.FirOperatorCall
import org.jetbrains.kotlin.fir.expressions.FirComparisonExpression
import org.jetbrains.kotlin.fir.expressions.FirTypeOperatorCall
import org.jetbrains.kotlin.fir.expressions.FirAssignmentOperatorStatement
@@ -390,10 +389,6 @@ abstract class FirTransformer<in D> : FirVisitor<CompositeTransformResult<FirEle
return transformElement(annotationCall, data)
}
open fun transformOperatorCall(operatorCall: FirOperatorCall, data: D): CompositeTransformResult<FirStatement> {
return transformElement(operatorCall, data)
}
open fun transformComparisonExpression(comparisonExpression: FirComparisonExpression, data: D): CompositeTransformResult<FirStatement> {
return transformElement(comparisonExpression, data)
}
@@ -894,10 +889,6 @@ abstract class FirTransformer<in D> : FirVisitor<CompositeTransformResult<FirEle
return transformAnnotationCall(annotationCall, data)
}
final override fun visitOperatorCall(operatorCall: FirOperatorCall, data: D): CompositeTransformResult<FirStatement> {
return transformOperatorCall(operatorCall, data)
}
final override fun visitComparisonExpression(comparisonExpression: FirComparisonExpression, data: D): CompositeTransformResult<FirStatement> {
return transformComparisonExpression(comparisonExpression, data)
}
@@ -68,7 +68,6 @@ import org.jetbrains.kotlin.fir.types.FirTypeProjectionWithVariance
import org.jetbrains.kotlin.fir.expressions.FirArgumentList
import org.jetbrains.kotlin.fir.expressions.FirCall
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
import org.jetbrains.kotlin.fir.expressions.FirOperatorCall
import org.jetbrains.kotlin.fir.expressions.FirComparisonExpression
import org.jetbrains.kotlin.fir.expressions.FirTypeOperatorCall
import org.jetbrains.kotlin.fir.expressions.FirAssignmentOperatorStatement
@@ -264,8 +263,6 @@ abstract class FirVisitor<out R, in D> {
open fun visitAnnotationCall(annotationCall: FirAnnotationCall, data: D): R = visitElement(annotationCall, data)
open fun visitOperatorCall(operatorCall: FirOperatorCall, data: D): R = visitElement(operatorCall, data)
open fun visitComparisonExpression(comparisonExpression: FirComparisonExpression, data: D): R = visitElement(comparisonExpression, data)
open fun visitTypeOperatorCall(typeOperatorCall: FirTypeOperatorCall, data: D): R = visitElement(typeOperatorCall, data)
@@ -68,7 +68,6 @@ import org.jetbrains.kotlin.fir.types.FirTypeProjectionWithVariance
import org.jetbrains.kotlin.fir.expressions.FirArgumentList
import org.jetbrains.kotlin.fir.expressions.FirCall
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
import org.jetbrains.kotlin.fir.expressions.FirOperatorCall
import org.jetbrains.kotlin.fir.expressions.FirComparisonExpression
import org.jetbrains.kotlin.fir.expressions.FirTypeOperatorCall
import org.jetbrains.kotlin.fir.expressions.FirAssignmentOperatorStatement
@@ -388,10 +387,6 @@ abstract class FirVisitorVoid : FirVisitor<Unit, Nothing?>() {
visitElement(annotationCall)
}
open fun visitOperatorCall(operatorCall: FirOperatorCall) {
visitElement(operatorCall)
}
open fun visitComparisonExpression(comparisonExpression: FirComparisonExpression) {
visitElement(comparisonExpression)
}
@@ -892,10 +887,6 @@ abstract class FirVisitorVoid : FirVisitor<Unit, Nothing?>() {
visitAnnotationCall(annotationCall)
}
final override fun visitOperatorCall(operatorCall: FirOperatorCall, data: Nothing?) {
visitOperatorCall(operatorCall)
}
final override fun visitComparisonExpression(comparisonExpression: FirComparisonExpression, data: Nothing?) {
visitComparisonExpression(comparisonExpression)
}
@@ -1081,16 +1081,6 @@ class FirRenderer(builder: StringBuilder, private val mode: RenderMode = RenderM
visitCall(functionCall)
}
override fun visitOperatorCall(operatorCall: FirOperatorCall) {
operatorCall.annotations.renderAnnotations()
print(operatorCall.operation.operator)
if (operatorCall is FirTypeOperatorCall) {
print("/")
operatorCall.conversionTypeRef.accept(this)
}
visitCall(operatorCall)
}
override fun visitComparisonExpression(comparisonExpression: FirComparisonExpression) {
print("CMP(${comparisonExpression.operation.operator}, ")
comparisonExpression.compareToCall.accept(this)
@@ -174,10 +174,6 @@ object BuilderConfigurator : AbstractBuilderConfigurator<FirTreeBuilder>(FirTree
default("resolvePhase", "FirResolvePhase.RAW_FIR")
}
builder(operatorCall) {
parents += callBuilder
}
builder(typeOperatorCall) {
parents += callBuilder
default("argumentList") {
@@ -83,7 +83,6 @@ object FirTreeBuilder : AbstractFirTreeBuilder() {
val argumentList = element("ArgumentList", Expression)
val call = element("Call", Expression, statement) // TODO: may smth like `CallWithArguments` or `ElementWithArguments`?
val annotationCall = element("AnnotationCall", Expression, expression, call)
val operatorCall = element("OperatorCall", Expression, expression, call)
val comparisonExpression = element("ComparisonExpression", Expression, expression)
val typeOperatorCall = element("TypeOperatorCall", Expression, expression, call)
val assignmentOperatorStatement = element("AssignmentOperatorStatement", Expression, statement)
@@ -225,11 +225,6 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
}
}
impl(operatorCall) {
default("typeRef", "FirImplicitTypeRefImpl(null)")
useTypes(implicitTypeRefType)
}
impl(comparisonExpression) {
default("typeRef", "FirImplicitBooleanTypeRef(null)")
useTypes(implicitBooleanTypeRefType)
@@ -207,10 +207,6 @@ object NodeConfigurator : AbstractFieldConfigurator<FirTreeBuilder>(FirTreeBuild
+field("calleeReference", namedReference)
}
operatorCall.configure {
+field("operation", operationType)
}
comparisonExpression.configure {
+field("operation", operationType)
+field("compareToCall", functionCall)
@@ -222,7 +222,6 @@ class FirVisualizer(private val firFile: FirFile) : BaseRenderer() {
expression.operationReference.let {
expression.allOfTypeWithLocalReplace<FirFunctionCall>(it) { this.calleeReference.name.asString() }
?: expression.firstOfTypeWithLocalReplace<FirVariableAssignment>(it) { this.lValue.toString() }
?: expression.firstOfTypeWithRender<FirOperatorCall>(it)
}
super.visitBinaryExpression(expression)
}
@@ -392,10 +391,6 @@ class FirVisualizer(private val firFile: FirFile) : BaseRenderer() {
}
}
override fun visitOperatorCall(operatorCall: FirOperatorCall, data: StringBuilder) {
data.append("operator call ${operatorCall.operation}")
}
override fun visitComparisonExpression(comparisonExpression: FirComparisonExpression, data: StringBuilder) {
data.append("CMP(${comparisonExpression.operation.operator}, ")
comparisonExpression.compareToCall.accept(this, data)