Skip to content

Commit 7f6d238

Browse files
committed
Extract more numeric binary operators
1 parent 1a5bd3c commit 7f6d238

File tree

2 files changed

+12
-66
lines changed

2 files changed

+12
-66
lines changed

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

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -2979,68 +2979,6 @@ OLD: KE1
29792979
29802980
val dr = c.dispatchReceiver
29812981
when {
2982-
isNumericFunction(
2983-
target,
2984-
"and",
2985-
"or",
2986-
"xor",
2987-
"shl",
2988-
"shr",
2989-
"ushr"
2990-
) -> {
2991-
val type = useType(c.type)
2992-
val id: Label<out DbExpr> =
2993-
when (val targetName = target.name.asString()) {
2994-
"and" -> {
2995-
val id = tw.getFreshIdLabel<DbAndbitexpr>()
2996-
tw.writeExprs_andbitexpr(id, type.javaResult.id, parent, idx)
2997-
id
2998-
}
2999-
"or" -> {
3000-
val id = tw.getFreshIdLabel<DbOrbitexpr>()
3001-
tw.writeExprs_orbitexpr(id, type.javaResult.id, parent, idx)
3002-
id
3003-
}
3004-
"xor" -> {
3005-
val id = tw.getFreshIdLabel<DbXorbitexpr>()
3006-
tw.writeExprs_xorbitexpr(id, type.javaResult.id, parent, idx)
3007-
id
3008-
}
3009-
"shl" -> {
3010-
val id = tw.getFreshIdLabel<DbLshiftexpr>()
3011-
tw.writeExprs_lshiftexpr(id, type.javaResult.id, parent, idx)
3012-
id
3013-
}
3014-
"shr" -> {
3015-
val id = tw.getFreshIdLabel<DbRshiftexpr>()
3016-
tw.writeExprs_rshiftexpr(id, type.javaResult.id, parent, idx)
3017-
id
3018-
}
3019-
"ushr" -> {
3020-
val id = tw.getFreshIdLabel<DbUrshiftexpr>()
3021-
tw.writeExprs_urshiftexpr(id, type.javaResult.id, parent, idx)
3022-
id
3023-
}
3024-
else -> {
3025-
logger.errorElement("Unhandled binary target name: $targetName", c)
3026-
return
3027-
}
3028-
}
3029-
tw.writeExprsKotlinType(id, type.kotlinResult.id)
3030-
if (
3031-
isFunction(
3032-
target,
3033-
"kotlin",
3034-
"Byte or Short",
3035-
{ it == "Byte" || it == "Short" },
3036-
"and",
3037-
"or",
3038-
"xor"
3039-
)
3040-
)
3041-
binopExt(id)
3042-
else binopDisp(id)
3043-
}
30442982
// != gets desugared into not and ==. Here we resugar it.
30452983
c.origin == IrStatementOrigin.EXCLEQ &&
30462984
isFunction(target, "kotlin", "Boolean", "not") &&

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,19 @@ private fun KotlinFileExtractor.extractBinaryExpression(
311311
extractBinaryExpression(expression, callable, parent, tw::writeExprs_divexpr)
312312
} else if (op == KtTokens.PERC && target.isNumericWithName("rem")) {
313313
extractBinaryExpression(expression, callable, parent, tw::writeExprs_remexpr)
314+
} else if (op == KtTokens.IDENTIFIER && target.isNumericWithName("and")) {
315+
extractBinaryExpression(expression, callable, parent, tw::writeExprs_andbitexpr)
316+
} else if (op == KtTokens.IDENTIFIER && target.isNumericWithName("or")) {
317+
extractBinaryExpression(expression, callable, parent, tw::writeExprs_orbitexpr)
318+
} else if (op == KtTokens.IDENTIFIER && target.isNumericWithName("xor")) {
319+
extractBinaryExpression(expression, callable, parent, tw::writeExprs_xorbitexpr)
320+
} else if (op == KtTokens.IDENTIFIER && target.isNumericWithName("shl")) {
321+
extractBinaryExpression(expression, callable, parent, tw::writeExprs_lshiftexpr)
322+
} else if (op == KtTokens.IDENTIFIER && target.isNumericWithName("shr")) {
323+
extractBinaryExpression(expression, callable, parent, tw::writeExprs_rshiftexpr)
324+
} else if (op == KtTokens.IDENTIFIER && target.isNumericWithName("ushr")) {
325+
extractBinaryExpression(expression, callable, parent, tw::writeExprs_urshiftexpr)
314326
} else {
315-
if (op !in listOf(KtTokens.PLUS, KtTokens.MINUS, KtTokens.MUL, KtTokens.DIV, KtTokens.PERC)) {
316-
TODO("Unhandled binary op")
317-
}
318-
319327
TODO("Extract as method call")
320328
}
321329
}

0 commit comments

Comments
 (0)