Skip to content

Commit 2ec23e9

Browse files
committed
Extract more numeric binary operators
1 parent c8cdf84 commit 2ec23e9

File tree

2 files changed

+14
-67
lines changed

2 files changed

+14
-67
lines changed

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

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -3695,68 +3695,6 @@ OLD: KE1
36953695
36963696
val dr = c.dispatchReceiver
36973697
when {
3698-
isNumericFunction(
3699-
target,
3700-
"and",
3701-
"or",
3702-
"xor",
3703-
"shl",
3704-
"shr",
3705-
"ushr"
3706-
) -> {
3707-
val type = useType(c.type)
3708-
val id: Label<out DbExpr> =
3709-
when (val targetName = target.name.asString()) {
3710-
"and" -> {
3711-
val id = tw.getFreshIdLabel<DbAndbitexpr>()
3712-
tw.writeExprs_andbitexpr(id, type.javaResult.id, parent, idx)
3713-
id
3714-
}
3715-
"or" -> {
3716-
val id = tw.getFreshIdLabel<DbOrbitexpr>()
3717-
tw.writeExprs_orbitexpr(id, type.javaResult.id, parent, idx)
3718-
id
3719-
}
3720-
"xor" -> {
3721-
val id = tw.getFreshIdLabel<DbXorbitexpr>()
3722-
tw.writeExprs_xorbitexpr(id, type.javaResult.id, parent, idx)
3723-
id
3724-
}
3725-
"shl" -> {
3726-
val id = tw.getFreshIdLabel<DbLshiftexpr>()
3727-
tw.writeExprs_lshiftexpr(id, type.javaResult.id, parent, idx)
3728-
id
3729-
}
3730-
"shr" -> {
3731-
val id = tw.getFreshIdLabel<DbRshiftexpr>()
3732-
tw.writeExprs_rshiftexpr(id, type.javaResult.id, parent, idx)
3733-
id
3734-
}
3735-
"ushr" -> {
3736-
val id = tw.getFreshIdLabel<DbUrshiftexpr>()
3737-
tw.writeExprs_urshiftexpr(id, type.javaResult.id, parent, idx)
3738-
id
3739-
}
3740-
else -> {
3741-
logger.errorElement("Unhandled binary target name: $targetName", c)
3742-
return
3743-
}
3744-
}
3745-
tw.writeExprsKotlinType(id, type.kotlinResult.id)
3746-
if (
3747-
isFunction(
3748-
target,
3749-
"kotlin",
3750-
"Byte or Short",
3751-
{ it == "Byte" || it == "Short" },
3752-
"and",
3753-
"or",
3754-
"xor"
3755-
)
3756-
)
3757-
binopExt(id)
3758-
else binopDisp(id)
3759-
}
37603698
// != gets desugared into not and ==. Here we resugar it.
37613699
c.origin == IrStatementOrigin.EXCLEQ &&
37623700
isFunction(target, "kotlin", "Boolean", "not") &&

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.analysis.api.symbols.KaFunctionSymbol
1010
import org.jetbrains.kotlin.analysis.api.types.KaType
1111
import org.jetbrains.kotlin.analysis.api.types.KaTypeNullability
1212
import org.jetbrains.kotlin.analysis.api.types.symbol
13+
import org.jetbrains.kotlin.lexer.KtToken
1314
import org.jetbrains.kotlin.lexer.KtTokens
1415
import org.jetbrains.kotlin.name.CallableId
1516
import org.jetbrains.kotlin.name.ClassId
@@ -287,7 +288,7 @@ private fun KotlinFileExtractor.extractBinaryExpression(
287288
callable: Label<out DbCallable>,
288289
parent: StmtExprParent
289290
) {
290-
val op = expression.operationToken
291+
val op = expression.operationToken as? KtToken
291292
val target = ((expression.resolveToCall() as? KaSuccessCallInfo)?.call as? KaSimpleFunctionCall)?.symbol
292293

293294
if (target == null) {
@@ -304,11 +305,19 @@ private fun KotlinFileExtractor.extractBinaryExpression(
304305
extractBinaryExpression(expression, callable, parent, tw::writeExprs_divexpr)
305306
} else if (op == KtTokens.PERC && target.isNumericWithName("rem")) {
306307
extractBinaryExpression(expression, callable, parent, tw::writeExprs_remexpr)
308+
} else if (op == KtTokens.IDENTIFIER && target.isNumericWithName("and")) {
309+
extractBinaryExpression(expression, callable, parent, tw::writeExprs_andbitexpr)
310+
} else if (op == KtTokens.IDENTIFIER && target.isNumericWithName("or")) {
311+
extractBinaryExpression(expression, callable, parent, tw::writeExprs_orbitexpr)
312+
} else if (op == KtTokens.IDENTIFIER && target.isNumericWithName("xor")) {
313+
extractBinaryExpression(expression, callable, parent, tw::writeExprs_xorbitexpr)
314+
} else if (op == KtTokens.IDENTIFIER && target.isNumericWithName("shl")) {
315+
extractBinaryExpression(expression, callable, parent, tw::writeExprs_lshiftexpr)
316+
} else if (op == KtTokens.IDENTIFIER && target.isNumericWithName("shr")) {
317+
extractBinaryExpression(expression, callable, parent, tw::writeExprs_rshiftexpr)
318+
} else if (op == KtTokens.IDENTIFIER && target.isNumericWithName("ushr")) {
319+
extractBinaryExpression(expression, callable, parent, tw::writeExprs_urshiftexpr)
307320
} else {
308-
if (op !in listOf(KtTokens.PLUS, KtTokens.MINUS, KtTokens.MUL, KtTokens.DIV, KtTokens.PERC)) {
309-
TODO("Unhandled binary op")
310-
}
311-
312321
TODO("Extract as method call")
313322
}
314323
}

0 commit comments

Comments
 (0)