Extract reference equals

This commit is contained in:
Tamas Vajk
2024-10-15 15:07:29 +02:00
parent bc35c509f0
commit 227d30243c
2 changed files with 21 additions and 41 deletions

View File

@@ -2992,18 +2992,6 @@ OLD: KE1
tw.writeExprsKotlinType(id, type.kotlinResult.id)
binOp(id, dr, callable, enclosingStmt)
}
c.origin == IrStatementOrigin.EXCLEQEQ &&
isFunction(target, "kotlin", "Boolean", "not") &&
c.valueArgumentsCount == 0 &&
dr != null &&
dr is IrCall &&
isBuiltinCallInternal(dr, "EQEQEQ") -> {
val id = tw.getFreshIdLabel<DbNeexpr>()
val type = useType(c.type)
tw.writeExprs_neexpr(id, type.javaResult.id, parent, idx)
tw.writeExprsKotlinType(id, type.kotlinResult.id)
binOp(id, dr, callable, enclosingStmt)
}
c.origin == IrStatementOrigin.EXCLEQ &&
isFunction(target, "kotlin", "Boolean", "not") &&
c.valueArgumentsCount == 0 &&
@@ -3113,16 +3101,6 @@ OLD: KE1
tw.writeExprsKotlinType(id, type.kotlinResult.id)
binOp(id, c, callable, enclosingStmt)
}
isBuiltinCallInternal(c, "EQEQEQ") -> {
if (c.origin != IrStatementOrigin.EQEQEQ) {
logger.warnElement("Unexpected origin for EQEQEQ: ${c.origin}", c)
}
val id = tw.getFreshIdLabel<DbEqexpr>()
val type = useType(c.type)
tw.writeExprs_eqexpr(id, type.javaResult.id, parent, idx)
tw.writeExprsKotlinType(id, type.kotlinResult.id)
binOp(id, c, callable, enclosingStmt)
}
isBuiltinCallInternal(c, "ieee754equals") -> {
if (c.origin != IrStatementOrigin.EQEQ) {
logger.warnElement("Unexpected origin for ieee754equals: ${c.origin}", c)

View File

@@ -256,13 +256,14 @@ private fun KaFunctionSymbol.hasName(
)
}
private fun KaFunctionSymbol.isNumericWithName(functionName: String): Boolean {
return this.hasName("kotlin", "Int", functionName) ||
this.hasName("kotlin", "Byte", functionName) ||
this.hasName("kotlin", "Short", functionName) ||
this.hasName("kotlin", "Long", functionName) ||
this.hasName("kotlin", "Float", functionName) ||
this.hasName("kotlin", "Double", functionName)
private fun KaFunctionSymbol?.isNumericWithName(functionName: String): Boolean {
return this != null &&
(this.hasName("kotlin", "Int", functionName) ||
this.hasName("kotlin", "Byte", functionName) ||
this.hasName("kotlin", "Short", functionName) ||
this.hasName("kotlin", "Long", functionName) ||
this.hasName("kotlin", "Float", functionName) ||
this.hasName("kotlin", "Double", functionName))
}
context(KaSession)
@@ -297,10 +298,6 @@ private fun KotlinFileExtractor.extractBinaryExpression(
val op = expression.operationToken
val target = expression.resolveCallTarget()?.symbol
if (target == null) {
TODO()
}
if (op == KtTokens.PLUS && target.isBinaryPlus()) {
extractBinaryExpression(expression, callable, parent, tw::writeExprs_addexpr)
} else if (op == KtTokens.MINUS && target.isNumericWithName("minus")) {
@@ -323,19 +320,24 @@ private fun KotlinFileExtractor.extractBinaryExpression(
extractBinaryExpression(expression, callable, parent, tw::writeExprs_rshiftexpr)
} else if (op == KtTokens.IDENTIFIER && target.isNumericWithName("ushr")) {
extractBinaryExpression(expression, callable, parent, tw::writeExprs_urshiftexpr)
} else if (op == KtTokens.EQEQEQ && target == null) {
extractBinaryExpression(expression, callable, parent, tw::writeExprs_eqexpr)
} else if (op == KtTokens.EXCLEQEQEQ && target == null) {
extractBinaryExpression(expression, callable, parent, tw::writeExprs_neexpr)
} else {
TODO("Extract as method call")
}
}
private fun KaFunctionSymbol.isBinaryPlus(): Boolean {
return this.isNumericWithName("plus") ||
this.hasName("kotlin", "String", "plus") ||
this.hasMatchingNames(
CallableId(FqName("kotlin"), null, Name.identifier("plus")),
ClassId(FqName("kotlin"), Name.identifier("String")),
nullability = KaTypeNullability.NULLABLE,
)
private fun KaFunctionSymbol?.isBinaryPlus(): Boolean {
return this != null && (
this.isNumericWithName("plus") ||
this.hasName("kotlin", "String", "plus") ||
this.hasMatchingNames(
CallableId(FqName("kotlin"), null, Name.identifier("plus")),
ClassId(FqName("kotlin"), Name.identifier("String")),
nullability = KaTypeNullability.NULLABLE,
))
}
context(KaSession)