From bc35c509f037e8ab8588098345732f6dca35f7cb Mon Sep 17 00:00:00 2001 From: Tamas Vajk Date: Tue, 15 Oct 2024 14:41:49 +0200 Subject: [PATCH] Extract more numeric binary operators --- .../src/main/kotlin/KotlinFileExtractor.kt | 62 ------------------- .../src/main/kotlin/entities/Expression.kt | 16 +++-- 2 files changed, 12 insertions(+), 66 deletions(-) diff --git a/java/kotlin-extractor2/src/main/kotlin/KotlinFileExtractor.kt b/java/kotlin-extractor2/src/main/kotlin/KotlinFileExtractor.kt index 7a94685ba6a..b9ac80027b4 100644 --- a/java/kotlin-extractor2/src/main/kotlin/KotlinFileExtractor.kt +++ b/java/kotlin-extractor2/src/main/kotlin/KotlinFileExtractor.kt @@ -2979,68 +2979,6 @@ OLD: KE1 val dr = c.dispatchReceiver when { - isNumericFunction( - target, - "and", - "or", - "xor", - "shl", - "shr", - "ushr" - ) -> { - val type = useType(c.type) - val id: Label = - when (val targetName = target.name.asString()) { - "and" -> { - val id = tw.getFreshIdLabel() - tw.writeExprs_andbitexpr(id, type.javaResult.id, parent, idx) - id - } - "or" -> { - val id = tw.getFreshIdLabel() - tw.writeExprs_orbitexpr(id, type.javaResult.id, parent, idx) - id - } - "xor" -> { - val id = tw.getFreshIdLabel() - tw.writeExprs_xorbitexpr(id, type.javaResult.id, parent, idx) - id - } - "shl" -> { - val id = tw.getFreshIdLabel() - tw.writeExprs_lshiftexpr(id, type.javaResult.id, parent, idx) - id - } - "shr" -> { - val id = tw.getFreshIdLabel() - tw.writeExprs_rshiftexpr(id, type.javaResult.id, parent, idx) - id - } - "ushr" -> { - val id = tw.getFreshIdLabel() - tw.writeExprs_urshiftexpr(id, type.javaResult.id, parent, idx) - id - } - else -> { - logger.errorElement("Unhandled binary target name: $targetName", c) - return - } - } - tw.writeExprsKotlinType(id, type.kotlinResult.id) - if ( - isFunction( - target, - "kotlin", - "Byte or Short", - { it == "Byte" || it == "Short" }, - "and", - "or", - "xor" - ) - ) - binopExt(id) - else binopDisp(id) - } // != gets desugared into not and ==. Here we resugar it. c.origin == IrStatementOrigin.EXCLEQ && isFunction(target, "kotlin", "Boolean", "not") && diff --git a/java/kotlin-extractor2/src/main/kotlin/entities/Expression.kt b/java/kotlin-extractor2/src/main/kotlin/entities/Expression.kt index 3c50a3ac855..14a30938b80 100644 --- a/java/kotlin-extractor2/src/main/kotlin/entities/Expression.kt +++ b/java/kotlin-extractor2/src/main/kotlin/entities/Expression.kt @@ -311,11 +311,19 @@ private fun KotlinFileExtractor.extractBinaryExpression( extractBinaryExpression(expression, callable, parent, tw::writeExprs_divexpr) } else if (op == KtTokens.PERC && target.isNumericWithName("rem")) { extractBinaryExpression(expression, callable, parent, tw::writeExprs_remexpr) + } else if (op == KtTokens.IDENTIFIER && target.isNumericWithName("and")) { + extractBinaryExpression(expression, callable, parent, tw::writeExprs_andbitexpr) + } else if (op == KtTokens.IDENTIFIER && target.isNumericWithName("or")) { + extractBinaryExpression(expression, callable, parent, tw::writeExprs_orbitexpr) + } else if (op == KtTokens.IDENTIFIER && target.isNumericWithName("xor")) { + extractBinaryExpression(expression, callable, parent, tw::writeExprs_xorbitexpr) + } else if (op == KtTokens.IDENTIFIER && target.isNumericWithName("shl")) { + extractBinaryExpression(expression, callable, parent, tw::writeExprs_lshiftexpr) + } else if (op == KtTokens.IDENTIFIER && target.isNumericWithName("shr")) { + 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 !in listOf(KtTokens.PLUS, KtTokens.MINUS, KtTokens.MUL, KtTokens.DIV, KtTokens.PERC)) { - TODO("Unhandled binary op") - } - TODO("Extract as method call") } }