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

Skip to content

Commit b25ea03

Browse files
committed
Kotlin: Add while statements
1 parent 00cff55 commit b25ea03

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.ir.expressions.IrConst
3333
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin.*
3434
import org.jetbrains.kotlin.ir.expressions.IrWhen
3535
import org.jetbrains.kotlin.ir.expressions.IrElseBranch
36+
import org.jetbrains.kotlin.ir.expressions.IrWhileLoop
3637
import org.jetbrains.kotlin.ir.IrStatement
3738
import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol
3839

@@ -288,6 +289,16 @@ class KotlinFileExtractor(val tw: TrapWriter) {
288289
tw.writeStmts_returnstmt(id, parent, idx, callable)
289290
tw.writeHasLocation(id, locId)
290291
extractExpression(s.value, id, 0)
292+
} is IrWhileLoop -> {
293+
val id = tw.getFreshIdLabel<DbWhilestmt>()
294+
val locId = tw.getLocation(s.startOffset, s.endOffset)
295+
tw.writeStmts_whilestmt(id, parent, idx, callable)
296+
tw.writeHasLocation(id, locId)
297+
extractExpression(s.condition, id, 0)
298+
val body = s.body
299+
if(body != null) {
300+
extractExpression(body, id, 1) // TODO: The QLLs think this is a Stmt
301+
}
291302
} is IrWhen -> {
292303
val x: IrWhen = s
293304
if(s.origin == IF) {
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
| stmts.kt:2:41:8:1 | { ... } |
1+
| stmts.kt:2:41:10:1 | { ... } |
22
| stmts.kt:3:8:3:12 | if (...) |
33
| stmts.kt:4:15:4:19 | if (...) |
4-
| stmts.kt:7:5:7:16 | return ... |
4+
| stmts.kt:7:5:8:16 | while (...) |
5+
| stmts.kt:9:5:9:16 | return ... |

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ fun topLevelMethod(x: Int, y: Int): Int {
44
} else if(x < y) {
55
} else {
66
}
7+
while(x > y)
8+
return x
79
return x + y
810
}
911

0 commit comments

Comments
 (0)