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

Skip to content

Commit 1b40f78

Browse files
committed
Kotlin: Recognise + etc for Double
1 parent 5b5a604 commit 1b40f78

3 files changed

Lines changed: 18 additions & 9 deletions

File tree

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,11 @@ open class KotlinFileExtractor(
606606
return true
607607
}
608608

609+
fun isNumericFunction(fName: String): Boolean {
610+
return isFunction("kotlin", "Int", fName) ||
611+
isFunction("kotlin", "Double", fName)
612+
}
613+
609614
fun binopDisp(id: Label<out DbExpr>) {
610615
val locId = tw.getLocation(c)
611616
tw.writeHasLocation(id, locId)
@@ -635,25 +640,25 @@ open class KotlinFileExtractor(
635640
val dr = c.dispatchReceiver
636641
when {
637642
c.origin == IrStatementOrigin.PLUS &&
638-
(isFunction("kotlin", "Int", "plus") || isFunction("kotlin", "String", "plus")) -> {
643+
(isNumericFunction("plus") || isFunction("kotlin", "String", "plus")) -> {
639644
val id = tw.getFreshIdLabel<DbAddexpr>()
640645
val type = useType(c.type)
641646
tw.writeExprs_addexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
642647
binopDisp(id)
643648
}
644-
c.origin == IrStatementOrigin.MINUS && isFunction("kotlin", "Int", "minus") -> {
649+
c.origin == IrStatementOrigin.MINUS && isNumericFunction("minus") -> {
645650
val id = tw.getFreshIdLabel<DbSubexpr>()
646651
val type = useType(c.type)
647652
tw.writeExprs_subexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
648653
binopDisp(id)
649654
}
650-
c.origin == IrStatementOrigin.DIV && isFunction("kotlin", "Int", "div") -> {
655+
c.origin == IrStatementOrigin.DIV && isNumericFunction("div") -> {
651656
val id = tw.getFreshIdLabel<DbDivexpr>()
652657
val type = useType(c.type)
653658
tw.writeExprs_divexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
654659
binopDisp(id)
655660
}
656-
c.origin == IrStatementOrigin.PERC && isFunction("kotlin", "Int", "rem") -> {
661+
c.origin == IrStatementOrigin.PERC && isNumericFunction("rem") -> {
657662
val id = tw.getFreshIdLabel<DbRemexpr>()
658663
val type = useType(c.type)
659664
tw.writeExprs_remexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
@@ -1456,4 +1461,4 @@ open class KotlinFileExtractor(
14561461

14571462
private val IrType.isAnonymous: Boolean
14581463
get() = ((this as? IrSimpleType)?.classifier?.owner as? IrClass)?.isAnonymousObject ?: false
1459-
}
1464+
}

java/ql/test/kotlin/library-tests/exprs/binop.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
| exprs.kt:22:15:22:20 | ... >= ... | exprs.kt:22:15:22:15 | x | exprs.kt:22:20:22:20 | y |
1111
| exprs.kt:23:15:23:21 | ... == ... | exprs.kt:23:15:23:15 | x | exprs.kt:23:21:23:21 | y |
1212
| exprs.kt:24:15:24:21 | ... != ... | exprs.kt:24:15:24:15 | x | exprs.kt:24:21:24:21 | y |
13+
| exprs.kt:32:14:32:20 | ... + ... | exprs.kt:32:14:32:15 | dx | exprs.kt:32:19:32:20 | dy |
14+
| exprs.kt:33:14:33:20 | ... - ... | exprs.kt:33:14:33:15 | dx | exprs.kt:33:19:33:20 | dy |
15+
| exprs.kt:34:14:34:20 | ... / ... | exprs.kt:34:14:34:15 | dx | exprs.kt:34:19:34:20 | dy |
16+
| exprs.kt:35:14:35:20 | ... % ... | exprs.kt:35:14:35:15 | dx | exprs.kt:35:19:35:20 | dy |
1317
| exprs.kt:36:14:36:21 | ... == ... | exprs.kt:36:14:36:15 | dx | exprs.kt:36:20:36:21 | dy |
1418
| exprs.kt:37:14:37:21 | ... != ... | exprs.kt:37:14:37:15 | dx | exprs.kt:37:20:37:21 | dy |
1519
| exprs.kt:38:14:38:20 | ... < ... | exprs.kt:38:14:38:15 | dx | exprs.kt:38:19:38:20 | dy |

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,19 @@
7979
| exprs.kt:31:14:31:16 | 1.0 | exprs.kt:4:1:70:1 | topLevelMethod | DoubleLiteral |
8080
| exprs.kt:32:5:32:20 | d2 | exprs.kt:4:1:70:1 | topLevelMethod | LocalVariableDeclExpr |
8181
| exprs.kt:32:14:32:15 | dx | exprs.kt:4:1:70:1 | topLevelMethod | VarAccess |
82-
| exprs.kt:32:14:32:20 | plus(...) | exprs.kt:4:1:70:1 | topLevelMethod | MethodAccess |
82+
| exprs.kt:32:14:32:20 | ... + ... | exprs.kt:4:1:70:1 | topLevelMethod | AddExpr |
8383
| exprs.kt:32:19:32:20 | dy | exprs.kt:4:1:70:1 | topLevelMethod | VarAccess |
8484
| exprs.kt:33:5:33:20 | d3 | exprs.kt:4:1:70:1 | topLevelMethod | LocalVariableDeclExpr |
8585
| exprs.kt:33:14:33:15 | dx | exprs.kt:4:1:70:1 | topLevelMethod | VarAccess |
86-
| exprs.kt:33:14:33:20 | minus(...) | exprs.kt:4:1:70:1 | topLevelMethod | MethodAccess |
86+
| exprs.kt:33:14:33:20 | ... - ... | exprs.kt:4:1:70:1 | topLevelMethod | SubExpr |
8787
| exprs.kt:33:19:33:20 | dy | exprs.kt:4:1:70:1 | topLevelMethod | VarAccess |
8888
| exprs.kt:34:5:34:20 | d4 | exprs.kt:4:1:70:1 | topLevelMethod | LocalVariableDeclExpr |
8989
| exprs.kt:34:14:34:15 | dx | exprs.kt:4:1:70:1 | topLevelMethod | VarAccess |
90-
| exprs.kt:34:14:34:20 | div(...) | exprs.kt:4:1:70:1 | topLevelMethod | MethodAccess |
90+
| exprs.kt:34:14:34:20 | ... / ... | exprs.kt:4:1:70:1 | topLevelMethod | DivExpr |
9191
| exprs.kt:34:19:34:20 | dy | exprs.kt:4:1:70:1 | topLevelMethod | VarAccess |
9292
| exprs.kt:35:5:35:20 | d5 | exprs.kt:4:1:70:1 | topLevelMethod | LocalVariableDeclExpr |
9393
| exprs.kt:35:14:35:15 | dx | exprs.kt:4:1:70:1 | topLevelMethod | VarAccess |
94-
| exprs.kt:35:14:35:20 | rem(...) | exprs.kt:4:1:70:1 | topLevelMethod | MethodAccess |
94+
| exprs.kt:35:14:35:20 | ... % ... | exprs.kt:4:1:70:1 | topLevelMethod | RemExpr |
9595
| exprs.kt:35:19:35:20 | dy | exprs.kt:4:1:70:1 | topLevelMethod | VarAccess |
9696
| exprs.kt:36:5:36:21 | d6 | exprs.kt:4:1:70:1 | topLevelMethod | LocalVariableDeclExpr |
9797
| exprs.kt:36:14:36:15 | dx | exprs.kt:4:1:70:1 | topLevelMethod | VarAccess |

0 commit comments

Comments
 (0)