Skip to content

Commit 5e29cd3

Browse files
committed
Extract reference equals
1 parent 2ec23e9 commit 5e29cd3

File tree

2 files changed

+21
-41
lines changed

2 files changed

+21
-41
lines changed

java/kotlin-extractor2/src/main/kotlin/KotlinFileExtractor.kt

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3708,18 +3708,6 @@ OLD: KE1
37083708
tw.writeExprsKotlinType(id, type.kotlinResult.id)
37093709
binOp(id, dr, callable, enclosingStmt)
37103710
}
3711-
c.origin == IrStatementOrigin.EXCLEQEQ &&
3712-
isFunction(target, "kotlin", "Boolean", "not") &&
3713-
c.valueArgumentsCount == 0 &&
3714-
dr != null &&
3715-
dr is IrCall &&
3716-
isBuiltinCallInternal(dr, "EQEQEQ") -> {
3717-
val id = tw.getFreshIdLabel<DbNeexpr>()
3718-
val type = useType(c.type)
3719-
tw.writeExprs_neexpr(id, type.javaResult.id, parent, idx)
3720-
tw.writeExprsKotlinType(id, type.kotlinResult.id)
3721-
binOp(id, dr, callable, enclosingStmt)
3722-
}
37233711
c.origin == IrStatementOrigin.EXCLEQ &&
37243712
isFunction(target, "kotlin", "Boolean", "not") &&
37253713
c.valueArgumentsCount == 0 &&
@@ -3829,16 +3817,6 @@ OLD: KE1
38293817
tw.writeExprsKotlinType(id, type.kotlinResult.id)
38303818
binOp(id, c, callable, enclosingStmt)
38313819
}
3832-
isBuiltinCallInternal(c, "EQEQEQ") -> {
3833-
if (c.origin != IrStatementOrigin.EQEQEQ) {
3834-
logger.warnElement("Unexpected origin for EQEQEQ: ${c.origin}", c)
3835-
}
3836-
val id = tw.getFreshIdLabel<DbEqexpr>()
3837-
val type = useType(c.type)
3838-
tw.writeExprs_eqexpr(id, type.javaResult.id, parent, idx)
3839-
tw.writeExprsKotlinType(id, type.kotlinResult.id)
3840-
binOp(id, c, callable, enclosingStmt)
3841-
}
38423820
isBuiltinCallInternal(c, "ieee754equals") -> {
38433821
if (c.origin != IrStatementOrigin.EQEQ) {
38443822
logger.warnElement("Unexpected origin for ieee754equals: ${c.origin}", c)

java/kotlin-extractor2/src/main/kotlin/entities/Expression.kt

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,14 @@ private fun KaFunctionSymbol.hasName(
257257
)
258258
}
259259

260-
private fun KaFunctionSymbol.isNumericWithName(functionName: String): Boolean {
261-
return this.hasName("kotlin", "Int", functionName) ||
262-
this.hasName("kotlin", "Byte", functionName) ||
263-
this.hasName("kotlin", "Short", functionName) ||
264-
this.hasName("kotlin", "Long", functionName) ||
265-
this.hasName("kotlin", "Float", functionName) ||
266-
this.hasName("kotlin", "Double", functionName)
260+
private fun KaFunctionSymbol?.isNumericWithName(functionName: String): Boolean {
261+
return this != null &&
262+
(this.hasName("kotlin", "Int", functionName) ||
263+
this.hasName("kotlin", "Byte", functionName) ||
264+
this.hasName("kotlin", "Short", functionName) ||
265+
this.hasName("kotlin", "Long", functionName) ||
266+
this.hasName("kotlin", "Float", functionName) ||
267+
this.hasName("kotlin", "Double", functionName))
267268
}
268269

269270
/**
@@ -291,10 +292,6 @@ private fun KotlinFileExtractor.extractBinaryExpression(
291292
val op = expression.operationToken as? KtToken
292293
val target = ((expression.resolveToCall() as? KaSuccessCallInfo)?.call as? KaSimpleFunctionCall)?.symbol
293294

294-
if (target == null) {
295-
TODO()
296-
}
297-
298295
if (op == KtTokens.PLUS && target.isBinaryPlus()) {
299296
extractBinaryExpression(expression, callable, parent, tw::writeExprs_addexpr)
300297
} else if (op == KtTokens.MINUS && target.isNumericWithName("minus")) {
@@ -317,19 +314,24 @@ private fun KotlinFileExtractor.extractBinaryExpression(
317314
extractBinaryExpression(expression, callable, parent, tw::writeExprs_rshiftexpr)
318315
} else if (op == KtTokens.IDENTIFIER && target.isNumericWithName("ushr")) {
319316
extractBinaryExpression(expression, callable, parent, tw::writeExprs_urshiftexpr)
317+
} else if (op == KtTokens.EQEQEQ && target == null) {
318+
extractBinaryExpression(expression, callable, parent, tw::writeExprs_eqexpr)
319+
} else if (op == KtTokens.EXCLEQEQEQ && target == null) {
320+
extractBinaryExpression(expression, callable, parent, tw::writeExprs_neexpr)
320321
} else {
321322
TODO("Extract as method call")
322323
}
323324
}
324325

325-
private fun KaFunctionSymbol.isBinaryPlus(): Boolean {
326-
return this.isNumericWithName("plus") ||
327-
this.hasName("kotlin", "String", "plus") ||
328-
this.hasMatchingNames(
329-
CallableId(FqName("kotlin"), null, Name.identifier("plus")),
330-
ClassId(FqName("kotlin"), Name.identifier("String")),
331-
nullability = KaTypeNullability.NULLABLE,
332-
)
326+
private fun KaFunctionSymbol?.isBinaryPlus(): Boolean {
327+
return this != null && (
328+
this.isNumericWithName("plus") ||
329+
this.hasName("kotlin", "String", "plus") ||
330+
this.hasMatchingNames(
331+
CallableId(FqName("kotlin"), null, Name.identifier("plus")),
332+
ClassId(FqName("kotlin"), Name.identifier("String")),
333+
nullability = KaTypeNullability.NULLABLE,
334+
))
333335
}
334336

335337
context(KaSession)

0 commit comments

Comments
 (0)