Skip to content

Commit d7b4f21

Browse files
committed
Extract comparison operators
1 parent 53abcd3 commit d7b4f21

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
@@ -3051,46 +3051,6 @@ OLD: KE1
30513051
// We need to handle all the builtin operators defines in BuiltInOperatorNames in
30523052
// compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/IrBuiltIns.kt
30533053
// as they can't be extracted as external dependencies.
3054-
isBuiltinCallInternal(c, "less") -> {
3055-
if (c.origin != IrStatementOrigin.LT) {
3056-
logger.warnElement("Unexpected origin for LT: ${c.origin}", c)
3057-
}
3058-
val id = tw.getFreshIdLabel<DbLtexpr>()
3059-
val type = useType(c.type)
3060-
tw.writeExprs_ltexpr(id, type.javaResult.id, parent, idx)
3061-
tw.writeExprsKotlinType(id, type.kotlinResult.id)
3062-
binOp(id, c, callable, enclosingStmt)
3063-
}
3064-
isBuiltinCallInternal(c, "lessOrEqual") -> {
3065-
if (c.origin != IrStatementOrigin.LTEQ) {
3066-
logger.warnElement("Unexpected origin for LTEQ: ${c.origin}", c)
3067-
}
3068-
val id = tw.getFreshIdLabel<DbLeexpr>()
3069-
val type = useType(c.type)
3070-
tw.writeExprs_leexpr(id, type.javaResult.id, parent, idx)
3071-
tw.writeExprsKotlinType(id, type.kotlinResult.id)
3072-
binOp(id, c, callable, enclosingStmt)
3073-
}
3074-
isBuiltinCallInternal(c, "greater") -> {
3075-
if (c.origin != IrStatementOrigin.GT) {
3076-
logger.warnElement("Unexpected origin for GT: ${c.origin}", c)
3077-
}
3078-
val id = tw.getFreshIdLabel<DbGtexpr>()
3079-
val type = useType(c.type)
3080-
tw.writeExprs_gtexpr(id, type.javaResult.id, parent, idx)
3081-
tw.writeExprsKotlinType(id, type.kotlinResult.id)
3082-
binOp(id, c, callable, enclosingStmt)
3083-
}
3084-
isBuiltinCallInternal(c, "greaterOrEqual") -> {
3085-
if (c.origin != IrStatementOrigin.GTEQ) {
3086-
logger.warnElement("Unexpected origin for GTEQ: ${c.origin}", c)
3087-
}
3088-
val id = tw.getFreshIdLabel<DbGeexpr>()
3089-
val type = useType(c.type)
3090-
tw.writeExprs_geexpr(id, type.javaResult.id, parent, idx)
3091-
tw.writeExprsKotlinType(id, type.kotlinResult.id)
3092-
binOp(id, c, callable, enclosingStmt)
3093-
}
30943054
isBuiltinCallInternal(c, "EQEQ") -> {
30953055
if (c.origin != IrStatementOrigin.EQEQ) {
30963056
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
@@ -324,8 +324,21 @@ private fun KotlinFileExtractor.extractBinaryExpression(
324324
extractBinaryExpression(expression, callable, parent, tw::writeExprs_eqexpr)
325325
} else if (op == KtTokens.EXCLEQEQEQ && target == null) {
326326
extractBinaryExpression(expression, callable, parent, tw::writeExprs_neexpr)
327+
} else if (op in listOf(KtTokens.LT, KtTokens.GT, KtTokens.LTEQ, KtTokens.GTEQ)) {
328+
if (target.isNumericWithName("compareTo")) {
329+
when (op) {
330+
KtTokens.LT -> extractBinaryExpression(expression, callable, parent, tw::writeExprs_ltexpr)
331+
KtTokens.GT -> extractBinaryExpression(expression, callable, parent, tw::writeExprs_gtexpr)
332+
KtTokens.LTEQ -> extractBinaryExpression(expression, callable, parent, tw::writeExprs_leexpr)
333+
KtTokens.GTEQ -> extractBinaryExpression(expression, callable, parent, tw::writeExprs_gtexpr)
334+
else -> TODO("error")
335+
}
336+
} else {
337+
TODO("Extract lowered equivalent call, such as `a.compareTo(b) < 0`")
338+
}
339+
327340
} else {
328-
// todo: other operators, such as .., ..<, in, !in, +=, -=, *=, /=, %=, <, >, <=, >=, ==, !=,
341+
// todo: other operators, such as .., ..<, in, !in, =, +=, -=, *=, /=, %=, ==, !=,
329342
TODO("Extract as method call")
330343
}
331344
}

0 commit comments

Comments
 (0)