[FIR] Replace all necessary usages of operator call with new ones

#KT-38333 Fixed
This commit is contained in:
Ivan Kylchik
2020-07-15 21:53:05 +03:00
parent def47bdd9d
commit 9a119a6757
8 changed files with 153 additions and 121 deletions
@@ -869,6 +869,10 @@ class Fir2IrVisitor(
}
}
override fun visitEqualityOperatorCall(equalityOperatorCall: FirEqualityOperatorCall, data: Any?): IrElement {
return operatorGenerator.convertEqualityOperatorCall(equalityOperatorCall)
}
override fun visitCheckNotNullCall(checkNotNullCall: FirCheckNotNullCall, data: Any?): IrElement {
return checkNotNullCall.convertWithOffsets { startOffset, endOffset ->
IrCallImpl(
@@ -35,8 +35,15 @@ internal class OperatorExpressionGenerator(
}
fun convertOperatorCall(operatorCall: FirOperatorCall): IrExpression {
return operatorCall.convertWithOffsets { startOffset, endOffset ->
generateOperatorCall(startOffset, endOffset, operatorCall.operation, operatorCall.arguments)
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)
}
}
@@ -84,16 +91,15 @@ internal class OperatorExpressionGenerator(
}
}
private fun generateOperatorCall(
private fun generateEqualityOperatorCall(
startOffset: Int, endOffset: Int, operation: FirOperation, arguments: List<FirExpression>
): IrExpression = when (operation) {
FirOperation.EQ, FirOperation.NOT_EQ -> generateEqualityOperatorCall(startOffset, endOffset, operation, arguments)
FirOperation.IDENTITY, FirOperation.NOT_IDENTITY -> generateIdentityOperatorCall(startOffset, endOffset, operation, arguments)
FirOperation.EXCL -> visitor.convertToIrExpression(arguments[0]).negate(IrStatementOrigin.EXCL)
FirOperation.EQ, FirOperation.NOT_EQ -> transformEqualityOperatorCall(startOffset, endOffset, operation, arguments)
FirOperation.IDENTITY, FirOperation.NOT_IDENTITY -> transformIdentityOperatorCall(startOffset, endOffset, operation, arguments)
else -> error("Unexpected operation: $operation")
}
private fun generateEqualityOperatorCall(
private fun transformEqualityOperatorCall(
startOffset: Int, endOffset: Int, operation: FirOperation, arguments: List<FirExpression>
): IrExpression {
val origin = when (operation) {
@@ -117,7 +123,7 @@ internal class OperatorExpressionGenerator(
}
}
private fun generateIdentityOperatorCall(
private fun transformIdentityOperatorCall(
startOffset: Int, endOffset: Int, operation: FirOperation, arguments: List<FirExpression>
): IrExpression {
val origin = when (operation) {