mirror of
https://github.com/github/codeql.git
synced 2026-04-30 03:05:15 +02:00
Kotlin: Local variables
This commit is contained in:
@@ -17,6 +17,7 @@ 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.declarations.IrVariable
|
||||
import org.jetbrains.kotlin.ir.util.dump
|
||||
import org.jetbrains.kotlin.ir.util.IdSignature
|
||||
import org.jetbrains.kotlin.ir.util.packageFqName
|
||||
@@ -305,11 +306,25 @@ class KotlinFileExtractor(val tw: TrapWriter) {
|
||||
}
|
||||
}
|
||||
|
||||
fun extractVariable(v: IrVariable, parent: Label<out DbStmtparent>, idx: Int) {
|
||||
val id = tw.getFreshIdLabel<DbLocalvariabledeclexpr>()
|
||||
val locId = tw.getLocation(v.startOffset, v.endOffset)
|
||||
val typeId = useType(v.type)
|
||||
tw.writeExprs_localvariabledeclexpr(id, typeId, parent, idx)
|
||||
tw.writeHasLocation(id, locId)
|
||||
val varId = tw.getFreshIdLabel<DbLocalvar>()
|
||||
tw.writeLocalvars(varId, v.name.asString(), typeId, id)
|
||||
tw.writeHasLocation(varId, locId)
|
||||
}
|
||||
|
||||
fun extractStatement(s: IrStatement, callable: Label<out DbCallable>, parent: Label<out DbStmtparent>, idx: Int) {
|
||||
when(s) {
|
||||
is IrExpression -> {
|
||||
extractExpression(s, callable, parent, idx)
|
||||
}
|
||||
is IrVariable -> {
|
||||
extractVariable(s, parent, idx)
|
||||
}
|
||||
else -> {
|
||||
extractorBug("Unrecognised IrStatement: " + s.javaClass)
|
||||
}
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
| variables.kt:3:5:3:21 | prop |
|
||||
| variables.kt:3:5:3:21 | prop | file://:0:0:0:0 | int |
|
||||
| variables.kt:6:9:6:21 | int local | file://:0:0:0:0 | int |
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
|
||||
class Foo {
|
||||
val prop: Int = 1
|
||||
|
||||
fun myFunction(param: Int) {
|
||||
val local = 2
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: val topLevel: Int = 1
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import java
|
||||
|
||||
from Variable v
|
||||
select v
|
||||
select v, v.getType()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user