Kotlin: More expressions

This commit is contained in:
Ian Lynagh
2021-08-12 17:29:58 +01:00
parent 90161b9e9d
commit 1de12e72d4
3 changed files with 39 additions and 10 deletions

View File

@@ -455,13 +455,30 @@ class KotlinFileExtractor(val tw: TrapWriter) {
when(e) {
is IrCall -> extractCall(e, callable, parent, idx)
is IrConst<*> -> {
val v = e.value as Int
val id = tw.getFreshIdLabel<DbIntegerliteral>()
val typeId = useType(e.type)
val locId = tw.getLocation(e.startOffset, e.endOffset)
tw.writeExprs_integerliteral(id, typeId, parent, idx)
tw.writeHasLocation(id, locId)
tw.writeNamestrings(v.toString(), v.toString(), id)
val v = e.value
when(v) {
is Int -> {
val id = tw.getFreshIdLabel<DbIntegerliteral>()
val typeId = useType(e.type)
val locId = tw.getLocation(e.startOffset, e.endOffset)
tw.writeExprs_integerliteral(id, typeId, parent, idx)
tw.writeHasLocation(id, locId)
tw.writeNamestrings(v.toString(), v.toString(), id)
} is Boolean -> {
val id = tw.getFreshIdLabel<DbBooleanliteral>()
val typeId = useType(e.type)
val locId = tw.getLocation(e.startOffset, e.endOffset)
tw.writeExprs_booleanliteral(id, typeId, parent, idx)
tw.writeHasLocation(id, locId)
tw.writeNamestrings(v.toString(), v.toString(), id)
} else -> {
if(v == null) {
extractorBug("Unrecognised IrConst: null value")
} else {
extractorBug("Unrecognised IrConst: " + v.javaClass)
}
}
}
}
is IrGetValue -> {
val id = tw.getFreshIdLabel<DbVaraccess>()

View File

@@ -30,9 +30,16 @@
| exprs.kt:20:15:20:15 | x |
| exprs.kt:20:15:20:20 | ... >= ... |
| exprs.kt:20:20:20:20 | y |
| exprs.kt:23:12:23:14 | 123 |
| exprs.kt:23:12:23:20 | ... + ... |
| exprs.kt:23:18:23:20 | 456 |
| exprs.kt:23:14:23:17 | true |
| exprs.kt:24:14:24:18 | false |
| exprs.kt:28:12:28:14 | 123 |
| exprs.kt:28:12:28:20 | ... + ... |
| exprs.kt:28:18:28:20 | 456 |
| file://:0:0:0:0 | b1 |
| file://:0:0:0:0 | b2 |
| file://:0:0:0:0 | b3 |
| file://:0:0:0:0 | b4 |
| file://:0:0:0:0 | b5 |
| file://:0:0:0:0 | i1 |
| file://:0:0:0:0 | i2 |
| file://:0:0:0:0 | i3 |

View File

@@ -20,6 +20,11 @@ fun topLevelMethod(x: Int, y: Int): Int {
val i18 = x >= y
val i20 = x in x .. y
val i21 = x !in x .. y
val b1 = true
val b2 = false
val b3 = b1 && b2
val b4 = b1 || b2
val b5 = !b1
return 123 + 456
}