Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b4c3f57

Browse files
committed
Kotlin: Get != working again
1 parent 956c479 commit b4c3f57

2 files changed

Lines changed: 62 additions & 26 deletions

File tree

java/kotlin-extractor/src/main/kotlin/KotlinExtractorExtension.kt

Lines changed: 56 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,32 @@ open class KotlinFileExtractor(
13971397
}
13981398

13991399
fun extractCall(c: IrCall, callable: Label<out DbCallable>, parent: Label<out DbExprparent>, idx: Int) {
1400-
fun isFunction(pkgName: String, className: String?, fName: String): Boolean {
1400+
fun isBuiltin(fName: String): Boolean {
1401+
val verbose = false
1402+
fun verboseln(s: String) { if(verbose) println(s) }
1403+
verboseln("Attempting builtin match for $fName")
1404+
val target = c.symbol.owner
1405+
if (target.name.asString() != fName) {
1406+
verboseln("No match as function name is ${target.name.asString()} not $fName")
1407+
return false
1408+
}
1409+
val extensionReceiverParameter = target.extensionReceiverParameter
1410+
// TODO: Are both branches of this `if` possible?:
1411+
val targetPkg = if (extensionReceiverParameter == null) target.parent
1412+
else (extensionReceiverParameter.type as? IrSimpleType)?.classifier?.owner
1413+
if (targetPkg !is IrPackageFragment) {
1414+
verboseln("No match as didn't find target package")
1415+
return false
1416+
}
1417+
if (targetPkg.fqName.asString() != "kotlin.internal.ir") {
1418+
verboseln("No match as package name is ${targetPkg.fqName.asString()}")
1419+
return false
1420+
}
1421+
verboseln("Match")
1422+
return true
1423+
}
1424+
1425+
fun isFunction(pkgName: String, className: String, fName: String): Boolean {
14011426
val verbose = false
14021427
fun verboseln(s: String) { if(verbose) println(s) }
14031428
verboseln("Attempting match for $pkgName $className $fName")
@@ -1409,20 +1434,15 @@ open class KotlinFileExtractor(
14091434
val extensionReceiverParameter = target.extensionReceiverParameter
14101435
val targetClass = if (extensionReceiverParameter == null) target.parent
14111436
else (extensionReceiverParameter.type as? IrSimpleType)?.classifier?.owner
1412-
val targetPkg =
1413-
if (className != null) {
1414-
if (targetClass !is IrClass) {
1415-
verboseln("No match as didn't find target class")
1416-
return false
1417-
}
1418-
if (targetClass.name.asString() != className) {
1419-
verboseln("No match as class name is ${targetClass.name.asString()} not $className")
1420-
return false
1421-
}
1422-
targetClass.parent
1423-
} else {
1424-
targetClass
1425-
}
1437+
if (targetClass !is IrClass) {
1438+
verboseln("No match as didn't find target class")
1439+
return false
1440+
}
1441+
if (targetClass.name.asString() != className) {
1442+
verboseln("No match as class name is ${targetClass.name.asString()} not $className")
1443+
return false
1444+
}
1445+
val targetPkg = targetClass.parent
14261446
if (targetPkg !is IrPackageFragment) {
14271447
verboseln("No match as didn't find target package")
14281448
return false
@@ -1521,7 +1541,11 @@ open class KotlinFileExtractor(
15211541
tw.writeExprs_remexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
15221542
binopDisp(id)
15231543
}
1524-
c.origin == EQEQ && isFunction("kotlin.internal.ir", null, "EQEQ") -> {
1544+
// compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/IrBuiltIns.kt
1545+
isBuiltin("EQEQ") -> {
1546+
if(c.origin != EQEQ) {
1547+
logger.warnElement(Severity.ErrorSevere, "Unexpected origin for EQEQ: ${c.origin}", c)
1548+
}
15251549
val id = tw.getFreshIdLabel<DbEqexpr>()
15261550
val type = useType(c.type)
15271551
tw.writeExprs_eqexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
@@ -1538,25 +1562,37 @@ TODO
15381562
tw.writeCallableEnclosingExpr(id, callable)
15391563
}
15401564
*/
1541-
c.origin == LT && isFunction("kotlin.internal.ir", null, "less") -> {
1565+
isBuiltin("less") -> {
1566+
if(c.origin != LT) {
1567+
logger.warnElement(Severity.ErrorSevere, "Unexpected origin for LT: ${c.origin}", c)
1568+
}
15421569
val id = tw.getFreshIdLabel<DbLtexpr>()
15431570
val type = useType(c.type)
15441571
tw.writeExprs_ltexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
15451572
binop(id)
15461573
}
1547-
c.origin == LTEQ && isFunction("kotlin.internal.ir", null, "lessOrEqual") -> {
1574+
isBuiltin("lessOrEqual") -> {
1575+
if(c.origin != LTEQ) {
1576+
logger.warnElement(Severity.ErrorSevere, "Unexpected origin for LTEQ: ${c.origin}", c)
1577+
}
15481578
val id = tw.getFreshIdLabel<DbLeexpr>()
15491579
val type = useType(c.type)
15501580
tw.writeExprs_leexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
15511581
binop(id)
15521582
}
1553-
c.origin == GT && isFunction("kotlin.internal.ir", null, "greater") -> {
1583+
isBuiltin("greater") -> {
1584+
if(c.origin != GT) {
1585+
logger.warnElement(Severity.ErrorSevere, "Unexpected origin for GT: ${c.origin}", c)
1586+
}
15541587
val id = tw.getFreshIdLabel<DbGtexpr>()
15551588
val type = useType(c.type)
15561589
tw.writeExprs_gtexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
15571590
binop(id)
15581591
}
1559-
c.origin == GTEQ && isFunction("kotlin.internal.ir", null, "greaterOrEqual") -> {
1592+
isBuiltin("greaterOrEqual") -> {
1593+
if(c.origin != GTEQ) {
1594+
logger.warnElement(Severity.ErrorSevere, "Unexpected origin for GTEQ: ${c.origin}", c)
1595+
}
15601596
val id = tw.getFreshIdLabel<DbGeexpr>()
15611597
val type = useType(c.type)
15621598
tw.writeExprs_geexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)

java/ql/test/kotlin/library-tests/exprs/exprs.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ TODO
1818
val i12 = x.inv()
1919
*/
2020
val i13 = x == y
21-
// TODO val i14 = x != y
21+
val i14 = x != y
2222
val i15 = x < y
2323
val i16 = x <= y
2424
val i17 = x > y
@@ -80,11 +80,11 @@ fun typeTests(x: Root, y: Subclass1) {
8080

8181
fun foo(p: Polygon) {
8282
val r = p.getBounds()
83-
// TODO if(r != null) {
84-
// TODO val r2: Rectangle = r
85-
// TODO val height = r2.height
86-
// TODO r2.height = 3
87-
// TODO }
83+
if(r != null) {
84+
val r2: Rectangle = r
85+
val height = r2.height
86+
r2.height = 3
87+
}
8888
}
8989

9090
enum class Direction {

0 commit comments

Comments
 (0)