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

Skip to content

Commit 97722fa

Browse files
committed
Kotlin: Add do/while loops
1 parent 0c429e4 commit 97722fa

2 files changed

Lines changed: 14 additions & 0 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
@@ -35,6 +35,7 @@ import org.jetbrains.kotlin.ir.expressions.IrWhen
3535
import org.jetbrains.kotlin.ir.expressions.IrElseBranch
3636
import org.jetbrains.kotlin.ir.expressions.IrWhileLoop
3737
import org.jetbrains.kotlin.ir.expressions.IrBlock
38+
import org.jetbrains.kotlin.ir.expressions.IrDoWhileLoop
3839
import org.jetbrains.kotlin.ir.IrStatement
3940
import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol
4041

@@ -357,6 +358,16 @@ class KotlinFileExtractor(val tw: TrapWriter) {
357358
if(body != null) {
358359
extractExpression(body, callable, id, 1) // TODO: The QLLs think this is a Stmt
359360
}
361+
} is IrDoWhileLoop -> {
362+
val id = tw.getFreshIdLabel<DbDostmt>()
363+
val locId = tw.getLocation(e.startOffset, e.endOffset)
364+
tw.writeStmts_dostmt(id, parent, idx, callable)
365+
tw.writeHasLocation(id, locId)
366+
extractExpression(e.condition, callable, id, 0)
367+
val body = e.body
368+
if(body != null) {
369+
extractExpression(body, callable, id, 1) // TODO: The QLLs think this is a Stmt
370+
}
360371
} is IrWhen -> {
361372
if(e.origin == IF) {
362373
var branchParent = parent

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ fun topLevelMethod(x: Int, y: Int): Int {
99
while(x < y) {
1010
return y
1111
}
12+
do {
13+
return y
14+
} while(x < y)
1215
return x + y
1316
}
1417

0 commit comments

Comments
 (0)