Kotlin: Variable initialisers

This commit is contained in:
Ian Lynagh
2021-08-12 12:17:41 +01:00
parent f5e2826b9f
commit 3daec4376f
4 changed files with 50 additions and 16 deletions

View File

@@ -1,6 +1,6 @@
| variables.kt:0:0:0:0 | other | variables.kt:0:0:0:0 | Any |
| variables.kt:0:0:0:0 | other | variables.kt:0:0:0:0 | Any |
| variables.kt:2:1:8:1 | other | variables.kt:0:0:0:0 | Any |
| variables.kt:3:5:3:21 | prop | file://:0:0:0:0 | int |
| variables.kt:5:20:5:29 | param | file://:0:0:0:0 | int |
| variables.kt:6:9:6:21 | int local | file://:0:0:0:0 | int |
| variables.kt:0:0:0:0 | other | variables.kt:0:0:0:0 | Any | file://:0:0:0:0 | <none> |
| variables.kt:0:0:0:0 | other | variables.kt:0:0:0:0 | Any | file://:0:0:0:0 | <none> |
| variables.kt:2:1:8:1 | other | variables.kt:0:0:0:0 | Any | file://:0:0:0:0 | <none> |
| variables.kt:3:5:3:21 | prop | file://:0:0:0:0 | int | file://:0:0:0:0 | <none> |
| variables.kt:5:20:5:29 | param | file://:0:0:0:0 | int | file://:0:0:0:0 | <none> |
| variables.kt:6:9:6:25 | int local | file://:0:0:0:0 | int | variables.kt:6:21:6:25 | ... + ... |

View File

@@ -3,7 +3,7 @@ class Foo {
val prop: Int = 1
fun myFunction(param: Int) {
val local = 2
val local = 2 + 3
}
}

View File

@@ -1,5 +1,35 @@
import java
from Variable v
select v, v.getType()
newtype TMaybeExpr =
TExpr(Expr c) or
TNoExpr()
class MaybeExpr extends TMaybeExpr {
abstract string toString();
abstract Location getLocation();
}
class YesMaybeExpr extends MaybeExpr {
Expr c;
YesMaybeExpr() { this = TExpr(c) }
override string toString() { result = c.toString() }
override Location getLocation() { result = c.getLocation() }
}
class NoMaybeExpr extends MaybeExpr {
NoMaybeExpr() { this = TNoExpr() }
override string toString() { result = "<none>" }
override Location getLocation() { none() }
}
MaybeExpr initializer(Variable v) {
if exists(v.getInitializer())
then result = TExpr(v.getInitializer())
else result = TNoExpr()
}
from Variable v
select v, v.getType(), initializer(v)