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

Skip to content

Commit 90161b9

Browse files
committed
Kotlin: Add more expressions
1 parent 492dc3d commit 90161b9

3 files changed

Lines changed: 80 additions & 3 deletions

File tree

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,48 @@ class KotlinFileExtractor(val tw: TrapWriter) {
391391
tw.writeExprs_remexpr(id, typeId, parent, idx)
392392
tw.writeHasLocation(id, locId)
393393
id
394+
} c.origin == EQEQ -> {
395+
val id = tw.getFreshIdLabel<DbEqexpr>()
396+
val typeId = useType(c.type)
397+
val locId = tw.getLocation(c.startOffset, c.endOffset)
398+
tw.writeExprs_eqexpr(id, typeId, parent, idx)
399+
tw.writeHasLocation(id, locId)
400+
id
401+
} c.origin == EXCLEQ -> {
402+
val id = tw.getFreshIdLabel<DbNeexpr>()
403+
val typeId = useType(c.type)
404+
val locId = tw.getLocation(c.startOffset, c.endOffset)
405+
tw.writeExprs_neexpr(id, typeId, parent, idx)
406+
tw.writeHasLocation(id, locId)
407+
id
408+
} c.origin == LT -> {
409+
val id = tw.getFreshIdLabel<DbLtexpr>()
410+
val typeId = useType(c.type)
411+
val locId = tw.getLocation(c.startOffset, c.endOffset)
412+
tw.writeExprs_ltexpr(id, typeId, parent, idx)
413+
tw.writeHasLocation(id, locId)
414+
id
415+
} c.origin == LTEQ -> {
416+
val id = tw.getFreshIdLabel<DbLeexpr>()
417+
val typeId = useType(c.type)
418+
val locId = tw.getLocation(c.startOffset, c.endOffset)
419+
tw.writeExprs_leexpr(id, typeId, parent, idx)
420+
tw.writeHasLocation(id, locId)
421+
id
422+
} c.origin == GT -> {
423+
val id = tw.getFreshIdLabel<DbGtexpr>()
424+
val typeId = useType(c.type)
425+
val locId = tw.getLocation(c.startOffset, c.endOffset)
426+
tw.writeExprs_gtexpr(id, typeId, parent, idx)
427+
tw.writeHasLocation(id, locId)
428+
id
429+
} c.origin == GTEQ -> {
430+
val id = tw.getFreshIdLabel<DbGeexpr>()
431+
val typeId = useType(c.type)
432+
val locId = tw.getLocation(c.startOffset, c.endOffset)
433+
tw.writeExprs_geexpr(id, typeId, parent, idx)
434+
tw.writeHasLocation(id, locId)
435+
id
394436
} else -> {
395437
extractorBug("Unrecognised IrCall: " + c.render())
396438
return

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

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,28 @@
1111
| exprs.kt:7:14:7:14 | x |
1212
| exprs.kt:7:14:7:18 | ... % ... |
1313
| exprs.kt:7:18:7:18 | y |
14-
| exprs.kt:15:12:15:14 | 123 |
15-
| exprs.kt:15:12:15:20 | ... + ... |
16-
| exprs.kt:15:18:15:20 | 456 |
14+
| exprs.kt:15:15:15:15 | x |
15+
| exprs.kt:15:15:15:20 | ... == ... |
16+
| exprs.kt:15:20:15:20 | y |
17+
| exprs.kt:16:15:16:15 | x |
18+
| exprs.kt:16:15:16:20 | ... != ... |
19+
| exprs.kt:16:15:16:20 | ... != ... |
20+
| exprs.kt:16:20:16:20 | y |
21+
| exprs.kt:17:15:17:15 | x |
22+
| exprs.kt:17:15:17:19 | ... < ... |
23+
| exprs.kt:17:19:17:19 | y |
24+
| exprs.kt:18:15:18:15 | x |
25+
| exprs.kt:18:15:18:20 | ... <= ... |
26+
| exprs.kt:18:20:18:20 | y |
27+
| exprs.kt:19:15:19:15 | x |
28+
| exprs.kt:19:15:19:19 | ... > ... |
29+
| exprs.kt:19:19:19:19 | y |
30+
| exprs.kt:20:15:20:15 | x |
31+
| exprs.kt:20:15:20:20 | ... >= ... |
32+
| exprs.kt:20:20:20:20 | y |
33+
| exprs.kt:23:12:23:14 | 123 |
34+
| exprs.kt:23:12:23:20 | ... + ... |
35+
| exprs.kt:23:18:23:20 | 456 |
1736
| file://:0:0:0:0 | i1 |
1837
| file://:0:0:0:0 | i2 |
1938
| file://:0:0:0:0 | i3 |
@@ -26,3 +45,11 @@
2645
| file://:0:0:0:0 | i10 |
2746
| file://:0:0:0:0 | i11 |
2847
| file://:0:0:0:0 | i12 |
48+
| file://:0:0:0:0 | i13 |
49+
| file://:0:0:0:0 | i14 |
50+
| file://:0:0:0:0 | i15 |
51+
| file://:0:0:0:0 | i16 |
52+
| file://:0:0:0:0 | i17 |
53+
| file://:0:0:0:0 | i18 |
54+
| file://:0:0:0:0 | i20 |
55+
| file://:0:0:0:0 | i21 |

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ fun topLevelMethod(x: Int, y: Int): Int {
1212
val i10 = x or y
1313
val i11 = x xor y
1414
val i12 = x.inv()
15+
val i13 = x == y
16+
val i14 = x != y
17+
val i15 = x < y
18+
val i16 = x <= y
19+
val i17 = x > y
20+
val i18 = x >= y
21+
val i20 = x in x .. y
22+
val i21 = x !in x .. y
1523
return 123 + 456
1624
}
1725

0 commit comments

Comments
 (0)