Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KE2: Small refactoring #18075

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 54 additions & 59 deletions java/kotlin-extractor2/src/main/kotlin/entities/Expression.kt
Original file line number Diff line number Diff line change
Expand Up @@ -385,69 +385,64 @@ private fun KotlinFileExtractor.extractBinaryExpression(
return extractBinaryExpression(expression, callable, parent, trapWriterWriteExpr)
}

when {
op in listOf(KtTokens.LT, KtTokens.GT, KtTokens.LTEQ, KtTokens.GTEQ) -> {
// Extract lowered equivalent call, such as `a.compareTo(b) < 0` instead of `a < b` in the below:
// ```
// fun test(a: Data, b: Data) {
// a < b
// }
//
// class Data(val v: Int) : Comparable<Data> {
// override fun compareTo(other: Data) = v.compareTo(other.v)
// }
// ```

val exprParent = parent.expr(expression, callable)

val trapWriterWriteExpr = when (op) {
KtTokens.LT -> tw::writeExprs_ltexpr
KtTokens.GT -> tw::writeExprs_gtexpr
KtTokens.LTEQ -> tw::writeExprs_leexpr
KtTokens.GTEQ -> tw::writeExprs_geexpr
else -> TODO("error")
}

val id = extractRawBinaryExpression(builtinTypes.boolean, exprParent, trapWriterWriteExpr)
extractExprContext(id, tw.getLocation(expression), callable, exprParent.enclosingStmt)

extractRawMethodAccess(
target,
tw.getLocation(expression),
target.returnType,
callable,
id,
0,
exprParent.enclosingStmt,
if (target.isExtension) null else expression.left!!,
if (target.isExtension) expression.left!! else null,
listOf(expression.right!!)
)

extractConstantInteger(
"0",
builtinTypes.int,
0,
tw.getLocation(expression),
id,
1,
callable,
exprParent.enclosingStmt,
/*
OLD: KE1
overrideId = overrideId
*/
)
val trapWriterWriteExprComparison = when (op) {
KtTokens.LT -> tw::writeExprs_ltexpr
KtTokens.GT -> tw::writeExprs_gtexpr
KtTokens.LTEQ -> tw::writeExprs_leexpr
KtTokens.GTEQ -> tw::writeExprs_geexpr
else -> null
}

return id
}
if (trapWriterWriteExprComparison != null) {
// Extract lowered equivalent call, such as `a.compareTo(b) < 0` instead of `a < b` in the below:
// ```
// fun test(a: Data, b: Data) {
// a < b
// }
//
// class Data(val v: Int) : Comparable<Data> {
// override fun compareTo(other: Data) = v.compareTo(other.v)
// }
// ```

val exprParent = parent.expr(expression, callable)

val id = extractRawBinaryExpression(builtinTypes.boolean, exprParent, trapWriterWriteExprComparison)
extractExprContext(id, tw.getLocation(expression), callable, exprParent.enclosingStmt)

extractRawMethodAccess(
target,
tw.getLocation(expression),
target.returnType,
callable,
id,
0,
exprParent.enclosingStmt,
if (target.isExtension) null else expression.left!!,
if (target.isExtension) expression.left!! else null,
listOf(expression.right!!)
)

else -> {
// todo: other operators, such as .., ..<, in, !in, =, +=, -=, *=, /=, %=, ==, !=,
TODO("Extract as method call")
}
extractConstantInteger(
"0",
builtinTypes.int,
0,
tw.getLocation(expression),
id,
1,
callable,
exprParent.enclosingStmt,
/*
OLD: KE1
overrideId = overrideId
*/
)

return id
}

// todo: other operators, such as .., ..<, in, !in, =, +=, -=, *=, /=, %=, ==, !=,
TODO("Extract as method call")
}


Expand Down