mirror of
https://github.com/github/codeql.git
synced 2026-04-30 19:26:02 +02:00
Kotlin: Extract properties
This commit is contained in:
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
|
||||
import org.jetbrains.kotlin.ir.declarations.IrProperty
|
||||
import org.jetbrains.kotlin.ir.util.dump
|
||||
import org.jetbrains.kotlin.ir.util.IdSignature
|
||||
import org.jetbrains.kotlin.ir.util.packageFqName
|
||||
@@ -148,6 +149,7 @@ class KotlinFileExtractor(val tw: TrapWriter) {
|
||||
when (declaration) {
|
||||
is IrClass -> extractClass(declaration)
|
||||
is IrFunction -> extractFunction(declaration, parentid)
|
||||
is IrProperty -> extractProperty(declaration, parentid)
|
||||
else -> extractorBug("Unrecognised IrDeclaration: " + declaration.javaClass)
|
||||
}
|
||||
}
|
||||
@@ -266,6 +268,26 @@ class KotlinFileExtractor(val tw: TrapWriter) {
|
||||
}
|
||||
}
|
||||
|
||||
fun useProperty(p: IrProperty): Label<out DbField> {
|
||||
val parentId = useDeclarationParent(p.parent)
|
||||
val label = "@\"field;{$parentId};${p.name.asString()}\""
|
||||
val id: Label<DbField> = tw.getLabelFor(label)
|
||||
return id
|
||||
}
|
||||
|
||||
fun extractProperty(p: IrProperty, parentid: Label<out DbPackage_or_reftype>) {
|
||||
val bf = p.backingField
|
||||
if(bf == null) {
|
||||
extractorBug("IrProperty without backing field")
|
||||
} else {
|
||||
val id = useProperty(p)
|
||||
val locId = tw.getLocation(p.startOffset, p.endOffset)
|
||||
val typeId = useType(bf.type)
|
||||
tw.writeFields(id, p.name.asString(), typeId, parentid, id)
|
||||
tw.writeHasLocation(id, locId)
|
||||
}
|
||||
}
|
||||
|
||||
fun extractBody(b: IrBody, callable: Label<out DbCallable>) {
|
||||
when(b) {
|
||||
is IrBlockBody -> extractBlockBody(b, callable, callable, 0)
|
||||
|
||||
@@ -319,7 +319,7 @@ fields(
|
||||
unique int id: @field,
|
||||
string nodeName: string ref,
|
||||
int typeid: @type ref,
|
||||
int parentid: @reftype ref,
|
||||
int parentid: @package_or_reftype ref,
|
||||
int sourceid: @field ref
|
||||
);
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
| stmts.kt:2:41:13:1 | { ... } |
|
||||
| stmts.kt:2:41:16:1 | { ... } |
|
||||
| stmts.kt:3:8:3:12 | if (...) |
|
||||
| stmts.kt:3:15:4:5 | { ... } |
|
||||
| stmts.kt:4:15:4:19 | if (...) |
|
||||
@@ -8,4 +8,6 @@
|
||||
| stmts.kt:9:5:11:5 | while (...) |
|
||||
| stmts.kt:9:18:11:5 | { ... } |
|
||||
| stmts.kt:10:9:10:16 | return ... |
|
||||
| stmts.kt:12:5:12:16 | return ... |
|
||||
| stmts.kt:12:5:14:18 | do ... while (...) |
|
||||
| stmts.kt:12:5:14:18 | { ... } |
|
||||
| stmts.kt:15:5:15:16 | return ... |
|
||||
|
||||
Reference in New Issue
Block a user