Skip to content

Commit fc4dfbe

Browse files
committed
Extract reference equals
1 parent 7f6d238 commit fc4dfbe

File tree

2 files changed

+21
-41
lines changed

2 files changed

+21
-41
lines changed

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

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2992,18 +2992,6 @@ OLD: KE1
29922992
tw.writeExprsKotlinType(id, type.kotlinResult.id)
29932993
binOp(id, dr, callable, enclosingStmt)
29942994
}
2995-
c.origin == IrStatementOrigin.EXCLEQEQ &&
2996-
isFunction(target, "kotlin", "Boolean", "not") &&
2997-
c.valueArgumentsCount == 0 &&
2998-
dr != null &&
2999-
dr is IrCall &&
3000-
isBuiltinCallInternal(dr, "EQEQEQ") -> {
3001-
val id = tw.getFreshIdLabel<DbNeexpr>()
3002-
val type = useType(c.type)
3003-
tw.writeExprs_neexpr(id, type.javaResult.id, parent, idx)
3004-
tw.writeExprsKotlinType(id, type.kotlinResult.id)
3005-
binOp(id, dr, callable, enclosingStmt)
3006-
}
30072995
c.origin == IrStatementOrigin.EXCLEQ &&
30082996
isFunction(target, "kotlin", "Boolean", "not") &&
30092997
c.valueArgumentsCount == 0 &&
@@ -3113,16 +3101,6 @@ OLD: KE1
31133101
tw.writeExprsKotlinType(id, type.kotlinResult.id)
31143102
binOp(id, c, callable, enclosingStmt)
31153103
}
3116-
isBuiltinCallInternal(c, "EQEQEQ") -> {
3117-
if (c.origin != IrStatementOrigin.EQEQEQ) {
3118-
logger.warnElement("Unexpected origin for EQEQEQ: ${c.origin}", c)
3119-
}
3120-
val id = tw.getFreshIdLabel<DbEqexpr>()
3121-
val type = useType(c.type)
3122-
tw.writeExprs_eqexpr(id, type.javaResult.id, parent, idx)
3123-
tw.writeExprsKotlinType(id, type.kotlinResult.id)
3124-
binOp(id, c, callable, enclosingStmt)
3125-
}
31263104
isBuiltinCallInternal(c, "ieee754equals") -> {
31273105
if (c.origin != IrStatementOrigin.EQEQ) {
31283106
logger.warnElement("Unexpected origin for ieee754equals: ${c.origin}", c)

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

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,14 @@ private fun KaFunctionSymbol.hasName(
256256
)
257257
}
258258

259-
private fun KaFunctionSymbol.isNumericWithName(functionName: String): Boolean {
260-
return this.hasName("kotlin", "Int", functionName) ||
261-
this.hasName("kotlin", "Byte", functionName) ||
262-
this.hasName("kotlin", "Short", functionName) ||
263-
this.hasName("kotlin", "Long", functionName) ||
264-
this.hasName("kotlin", "Float", functionName) ||
265-
this.hasName("kotlin", "Double", functionName)
259+
private fun KaFunctionSymbol?.isNumericWithName(functionName: String): Boolean {
260+
return this != null &&
261+
(this.hasName("kotlin", "Int", functionName) ||
262+
this.hasName("kotlin", "Byte", functionName) ||
263+
this.hasName("kotlin", "Short", functionName) ||
264+
this.hasName("kotlin", "Long", functionName) ||
265+
this.hasName("kotlin", "Float", functionName) ||
266+
this.hasName("kotlin", "Double", functionName))
266267
}
267268

268269
context(KaSession)
@@ -297,10 +298,6 @@ private fun KotlinFileExtractor.extractBinaryExpression(
297298
val op = expression.operationToken
298299
val target = expression.resolveCallTarget()?.symbol
299300

300-
if (target == null) {
301-
TODO()
302-
}
303-
304301
if (op == KtTokens.PLUS && target.isBinaryPlus()) {
305302
extractBinaryExpression(expression, callable, parent, tw::writeExprs_addexpr)
306303
} else if (op == KtTokens.MINUS && target.isNumericWithName("minus")) {
@@ -323,19 +320,24 @@ private fun KotlinFileExtractor.extractBinaryExpression(
323320
extractBinaryExpression(expression, callable, parent, tw::writeExprs_rshiftexpr)
324321
} else if (op == KtTokens.IDENTIFIER && target.isNumericWithName("ushr")) {
325322
extractBinaryExpression(expression, callable, parent, tw::writeExprs_urshiftexpr)
323+
} else if (op == KtTokens.EQEQEQ && target == null) {
324+
extractBinaryExpression(expression, callable, parent, tw::writeExprs_eqexpr)
325+
} else if (op == KtTokens.EXCLEQEQEQ && target == null) {
326+
extractBinaryExpression(expression, callable, parent, tw::writeExprs_neexpr)
326327
} else {
327328
TODO("Extract as method call")
328329
}
329330
}
330331

331-
private fun KaFunctionSymbol.isBinaryPlus(): Boolean {
332-
return this.isNumericWithName("plus") ||
333-
this.hasName("kotlin", "String", "plus") ||
334-
this.hasMatchingNames(
335-
CallableId(FqName("kotlin"), null, Name.identifier("plus")),
336-
ClassId(FqName("kotlin"), Name.identifier("String")),
337-
nullability = KaTypeNullability.NULLABLE,
338-
)
332+
private fun KaFunctionSymbol?.isBinaryPlus(): Boolean {
333+
return this != null && (
334+
this.isNumericWithName("plus") ||
335+
this.hasName("kotlin", "String", "plus") ||
336+
this.hasMatchingNames(
337+
CallableId(FqName("kotlin"), null, Name.identifier("plus")),
338+
ClassId(FqName("kotlin"), Name.identifier("String")),
339+
nullability = KaTypeNullability.NULLABLE,
340+
))
339341
}
340342

341343
context(KaSession)

0 commit comments

Comments
 (0)