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

Skip to content

Commit d6692e4

Browse files
committed
Kotlin: Add support for "is" ("instanceof")
1 parent d05643f commit d6692e4

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1466,12 +1466,35 @@ class X {
14661466
tw.writeHasLocation(id, locId)
14671467
extractExpressionExpr(e.argument, callable, id, 0)
14681468
}
1469+
is IrTypeOperatorCall -> {
1470+
extractTypeOperatorCall(e, callable, parent, idx)
1471+
}
14691472
else -> {
14701473
logger.warnElement(Severity.ErrorSevere, "Unrecognised IrExpression: " + e.javaClass, e)
14711474
}
14721475
}
14731476
}
14741477

1478+
fun extractTypeOperatorCall(e: IrTypeOperatorCall, callable: Label<out DbCallable>, parent: Label<out DbExprparent>, idx: Int) {
1479+
when(e.operator) {
1480+
IrTypeOperator.INSTANCEOF -> {
1481+
val id = tw.getFreshIdLabel<DbInstanceofexpr>()
1482+
val locId = tw.getLocation(e)
1483+
val type = useType(e.type)
1484+
tw.writeExprs_instanceofexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
1485+
tw.writeHasLocation(id, locId)
1486+
extractExpressionExpr(e.argument, callable, id, 0)
1487+
val typeArg = useType(e.typeOperand)
1488+
val typeAccessId = tw.getFreshIdLabel<DbUnannotatedtypeaccess>()
1489+
tw.writeExprs_unannotatedtypeaccess(typeAccessId, typeArg.javaResult.id, typeArg.kotlinResult.id, id, 1)
1490+
// TODO: Type access location
1491+
}
1492+
else -> {
1493+
logger.warnElement(Severity.ErrorSevere, "Unrecognised IrTypeOperatorCall: " + e.render(), e)
1494+
}
1495+
}
1496+
}
1497+
14751498
private fun extractBreakContinue(
14761499
e: IrBreakContinue,
14771500
id: Label<out DbBreakcontinuestmt>
@@ -1491,4 +1514,4 @@ class X {
14911514

14921515
tw.writeKtBreakContinueTargets(id, loopId)
14931516
}
1494-
}
1517+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
| exprs.kt:39:5:39:38 | strWithQuote | LocalVariableDeclExpr |
5353
| exprs.kt:39:25:39:37 | string " lit | StringLiteral |
5454
| exprs.kt:40:5:40:22 | b6 | LocalVariableDeclExpr |
55+
| exprs.kt:40:14:40:15 | i1 | VarAccess |
56+
| exprs.kt:40:14:40:22 | ...instanceof... | InstanceOfExpr |
5557
| exprs.kt:41:5:41:23 | b7 | LocalVariableDeclExpr |
5658
| exprs.kt:42:5:42:26 | b8 | LocalVariableDeclExpr |
5759
| exprs.kt:43:5:43:35 | str1 | LocalVariableDeclExpr |
@@ -72,3 +74,4 @@
7274
| exprs.kt:53:9:53:18 | n | VarAccess |
7375
| exprs.kt:54:27:54:31 | new C(...) | ClassInstanceExpr |
7476
| exprs.kt:54:29:54:30 | 42 | IntegerLiteral |
77+
| file://:0:0:0:0 | int | TypeAccess |

0 commit comments

Comments
 (0)