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

Skip to content

Commit 2b973fa

Browse files
committed
Kotlin: Add support for IrSyntheticBody
I'm not sure it's worth adding an entity to the database for them, although that would allow us to use a 'case' in the dbscheme for the different kinds. There's no QLL support for this info yet.
1 parent 4ca024f commit 2b973fa

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,21 +459,31 @@ open class KotlinFileExtractor(
459459

460460
fun extractBody(b: IrBody, callable: Label<out DbCallable>) {
461461
when(b) {
462-
is IrBlockBody -> extractBlockBody(b, callable, callable, 0)
463-
else -> logger.warnElement(Severity.ErrorSevere, "Unrecognised IrBody: " + b.javaClass, b)
462+
is IrBlockBody -> extractBlockBody(b, callable)
463+
is IrSyntheticBody -> extractSyntheticBody(b, callable)
464+
else -> {
465+
logger.warnElement(Severity.ErrorSevere, "Unrecognised IrBody: " + b.javaClass, b)
466+
}
464467
}
465468
}
466469

467-
fun extractBlockBody(b: IrBlockBody, callable: Label<out DbCallable>, parent: Label<out DbStmtparent>, idx: Int) {
470+
fun extractBlockBody(b: IrBlockBody, callable: Label<out DbCallable>) {
468471
val id = tw.getFreshIdLabel<DbBlock>()
469472
val locId = tw.getLocation(b)
470-
tw.writeStmts_block(id, parent, idx, callable)
473+
tw.writeStmts_block(id, callable, 0, callable)
471474
tw.writeHasLocation(id, locId)
472475
for((sIdx, stmt) in b.statements.withIndex()) {
473476
extractStatement(stmt, callable, id, sIdx)
474477
}
475478
}
476479

480+
fun extractSyntheticBody(b: IrSyntheticBody, callable: Label<out DbCallable>) {
481+
when (b.kind) {
482+
IrSyntheticBodyKind.ENUM_VALUES -> tw.writeKtSyntheticBody(callable, 1)
483+
IrSyntheticBodyKind.ENUM_VALUEOF -> tw.writeKtSyntheticBody(callable, 2)
484+
}
485+
}
486+
477487
fun extractVariable(v: IrVariable, callable: Label<out DbCallable>, parent: Label<out DbStmtparent>, idx: Int) {
478488
val stmtId = tw.getFreshIdLabel<DbLocalvariabledeclstmt>()
479489
val locId = tw.getLocation(v)

java/ql/lib/config/semmlecode.dbscheme

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,3 +1137,10 @@ ktAnonymousClassDeclarationStmts(
11371137
unique int id: @anonymousclassdeclstmt ref,
11381138
int classId: @class ref
11391139
)
1140+
1141+
ktSyntheticBody(
1142+
unique int id: @callable ref,
1143+
int kind: int ref
1144+
// 1: ENUM_VALUES
1145+
// 2: ENUM_VALUEOF
1146+
)

0 commit comments

Comments
 (0)