Skip to content

Commit dfdf566

Browse files
committed
Extract comparison operators
1 parent a19b5e6 commit dfdf566

File tree

2 files changed

+14
-41
lines changed

2 files changed

+14
-41
lines changed

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

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3767,46 +3767,6 @@ OLD: KE1
37673767
// We need to handle all the builtin operators defines in BuiltInOperatorNames in
37683768
// compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/IrBuiltIns.kt
37693769
// as they can't be extracted as external dependencies.
3770-
isBuiltinCallInternal(c, "less") -> {
3771-
if (c.origin != IrStatementOrigin.LT) {
3772-
logger.warnElement("Unexpected origin for LT: ${c.origin}", c)
3773-
}
3774-
val id = tw.getFreshIdLabel<DbLtexpr>()
3775-
val type = useType(c.type)
3776-
tw.writeExprs_ltexpr(id, type.javaResult.id, parent, idx)
3777-
tw.writeExprsKotlinType(id, type.kotlinResult.id)
3778-
binOp(id, c, callable, enclosingStmt)
3779-
}
3780-
isBuiltinCallInternal(c, "lessOrEqual") -> {
3781-
if (c.origin != IrStatementOrigin.LTEQ) {
3782-
logger.warnElement("Unexpected origin for LTEQ: ${c.origin}", c)
3783-
}
3784-
val id = tw.getFreshIdLabel<DbLeexpr>()
3785-
val type = useType(c.type)
3786-
tw.writeExprs_leexpr(id, type.javaResult.id, parent, idx)
3787-
tw.writeExprsKotlinType(id, type.kotlinResult.id)
3788-
binOp(id, c, callable, enclosingStmt)
3789-
}
3790-
isBuiltinCallInternal(c, "greater") -> {
3791-
if (c.origin != IrStatementOrigin.GT) {
3792-
logger.warnElement("Unexpected origin for GT: ${c.origin}", c)
3793-
}
3794-
val id = tw.getFreshIdLabel<DbGtexpr>()
3795-
val type = useType(c.type)
3796-
tw.writeExprs_gtexpr(id, type.javaResult.id, parent, idx)
3797-
tw.writeExprsKotlinType(id, type.kotlinResult.id)
3798-
binOp(id, c, callable, enclosingStmt)
3799-
}
3800-
isBuiltinCallInternal(c, "greaterOrEqual") -> {
3801-
if (c.origin != IrStatementOrigin.GTEQ) {
3802-
logger.warnElement("Unexpected origin for GTEQ: ${c.origin}", c)
3803-
}
3804-
val id = tw.getFreshIdLabel<DbGeexpr>()
3805-
val type = useType(c.type)
3806-
tw.writeExprs_geexpr(id, type.javaResult.id, parent, idx)
3807-
tw.writeExprsKotlinType(id, type.kotlinResult.id)
3808-
binOp(id, c, callable, enclosingStmt)
3809-
}
38103770
isBuiltinCallInternal(c, "EQEQ") -> {
38113771
if (c.origin != IrStatementOrigin.EQEQ) {
38123772
logger.warnElement("Unexpected origin for EQEQ: ${c.origin}", c)

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,21 @@ private fun KotlinFileExtractor.extractBinaryExpression(
318318
extractBinaryExpression(expression, callable, parent, tw::writeExprs_eqexpr)
319319
} else if (op == KtTokens.EXCLEQEQEQ && target == null) {
320320
extractBinaryExpression(expression, callable, parent, tw::writeExprs_neexpr)
321+
} else if (op in listOf(KtTokens.LT, KtTokens.GT, KtTokens.LTEQ, KtTokens.GTEQ)) {
322+
if (target.isNumericWithName("compareTo")) {
323+
when (op) {
324+
KtTokens.LT -> extractBinaryExpression(expression, callable, parent, tw::writeExprs_ltexpr)
325+
KtTokens.GT -> extractBinaryExpression(expression, callable, parent, tw::writeExprs_gtexpr)
326+
KtTokens.LTEQ -> extractBinaryExpression(expression, callable, parent, tw::writeExprs_leexpr)
327+
KtTokens.GTEQ -> extractBinaryExpression(expression, callable, parent, tw::writeExprs_gtexpr)
328+
else -> TODO("error")
329+
}
330+
} else {
331+
TODO("Extract lowered equivalent call, such as `a.compareTo(b) < 0`")
332+
}
333+
321334
} else {
322-
// todo: other operators, such as .., ..<, in, !in, +=, -=, *=, /=, %=, <, >, <=, >=, ==, !=,
335+
// todo: other operators, such as .., ..<, in, !in, =, +=, -=, *=, /=, %=, ==, !=,
323336
TODO("Extract as method call")
324337
}
325338
}

0 commit comments

Comments
 (0)