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

@@ -319,15 +319,19 @@ class KotlinFileExtractor(val tw: TrapWriter) {
}
}
fun extractVariable(v: IrVariable, parent: Label<out DbStmtparent>, idx: Int) {
val id = tw.getFreshIdLabel<DbLocalvariabledeclexpr>()
fun extractVariable(v: IrVariable, callable: Label<out DbCallable>) {
val id = tw.getFreshIdLabel<DbLocalvar>()
val locId = tw.getLocation(v.startOffset, v.endOffset)
val typeId = useType(v.type)
tw.writeExprs_localvariabledeclexpr(id, typeId, parent, idx)
val decId = tw.getFreshIdLabel<DbLocalvariabledeclexpr>()
tw.writeLocalvars(id, v.name.asString(), typeId, decId)
tw.writeHasLocation(id, locId)
val varId = tw.getFreshIdLabel<DbLocalvar>()
tw.writeLocalvars(varId, v.name.asString(), typeId, id)
tw.writeHasLocation(varId, locId)
tw.writeExprs_localvariabledeclexpr(decId, typeId, id, 0)
tw.writeHasLocation(id, locId)
val i = v.initializer
if(i != null) {
extractExpression(i, callable, decId, 0)
}
}
fun extractStatement(s: IrStatement, callable: Label<out DbCallable>, parent: Label<out DbStmtparent>, idx: Int) {
@@ -336,7 +340,7 @@ class KotlinFileExtractor(val tw: TrapWriter) {
extractExpression(s, callable, parent, idx)
}
is IrVariable -> {
extractVariable(s, parent, idx)
extractVariable(s, callable)
}
else -> {
extractorBug("Unrecognised IrStatement: " + s.javaClass)