[FIR] Extract common code for converting unaryMinus call on integer literal
This commit is contained in:
committed by
teamcity
parent
563e649ac3
commit
cc86ca2a0f
+1
-11
@@ -408,17 +408,7 @@ class ExpressionsConverter(
|
||||
) { getAsFirExpression(this) }
|
||||
}
|
||||
val receiver = getAsFirExpression<FirExpression>(argument, "No operand")
|
||||
if (operationToken == PLUS || operationToken == MINUS) {
|
||||
if (receiver is FirConstExpression<*> && receiver.kind == ConstantValueKind.IntegerLiteral) {
|
||||
val value = receiver.value as Long
|
||||
val convertedValue = when (operationToken) {
|
||||
MINUS -> -value
|
||||
PLUS -> value
|
||||
else -> error("Should not be here")
|
||||
}
|
||||
return buildConstExpression(unaryExpression.toFirSourceElement(), ConstantValueKind.IntegerLiteral, convertedValue)
|
||||
}
|
||||
}
|
||||
convertUnaryPlusMinusCallOnIntegerLiteralIfNecessary(unaryExpression, receiver, operationToken)?.let { return it }
|
||||
buildFunctionCall {
|
||||
source = unaryExpression.toFirSourceElement()
|
||||
calleeReference = buildSimpleNamedReference {
|
||||
|
||||
@@ -2239,21 +2239,9 @@ open class RawFirBuilder(
|
||||
}
|
||||
|
||||
val receiver = argument.toFirExpression("No operand")
|
||||
if (operationToken == PLUS || operationToken == MINUS) {
|
||||
if (receiver is FirConstExpression<*> && receiver.kind == ConstantValueKind.IntegerLiteral) {
|
||||
val value = receiver.value as Long
|
||||
val convertedValue = when (operationToken) {
|
||||
MINUS -> -value
|
||||
PLUS -> value
|
||||
else -> error("Should not be here")
|
||||
}
|
||||
return buildConstExpression(
|
||||
expression.toKtPsiSourceElement(),
|
||||
ConstantValueKind.IntegerLiteral,
|
||||
convertedValue
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
convertUnaryPlusMinusCallOnIntegerLiteralIfNecessary(expression, receiver, operationToken)?.let { return it }
|
||||
|
||||
buildFunctionCall {
|
||||
source = expression.toFirSourceElement()
|
||||
calleeReference = buildSimpleNamedReference {
|
||||
|
||||
+24
-2
@@ -32,8 +32,7 @@ import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
|
||||
import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl
|
||||
import org.jetbrains.kotlin.lexer.KtTokens.CLOSING_QUOTE
|
||||
import org.jetbrains.kotlin.lexer.KtTokens.OPEN_QUOTE
|
||||
import org.jetbrains.kotlin.lexer.KtTokens.*
|
||||
import org.jetbrains.kotlin.name.CallableId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
@@ -409,6 +408,29 @@ abstract class BaseFirBuilder<T>(val baseSession: FirSession, val context: Conte
|
||||
}
|
||||
}
|
||||
|
||||
fun convertUnaryPlusMinusCallOnIntegerLiteralIfNecessary(
|
||||
source: T,
|
||||
receiver: FirExpression,
|
||||
operationToken: IElementType
|
||||
): FirExpression? {
|
||||
if (receiver !is FirConstExpression<*>) return null
|
||||
if (receiver.kind != ConstantValueKind.IntegerLiteral) return null
|
||||
if (operationToken != PLUS && operationToken != MINUS) return null
|
||||
|
||||
val value = receiver.value as Long
|
||||
val convertedValue = when (operationToken) {
|
||||
MINUS -> -value
|
||||
PLUS -> value
|
||||
else -> error("Should not be here")
|
||||
}
|
||||
|
||||
return buildConstExpression(
|
||||
source.toFirSourceElement(),
|
||||
ConstantValueKind.IntegerLiteral,
|
||||
convertedValue
|
||||
)
|
||||
}
|
||||
|
||||
fun Array<out T?>.toInterpolatingCall(
|
||||
base: T,
|
||||
getElementType: (T) -> IElementType = { it.elementType },
|
||||
|
||||
Reference in New Issue
Block a user