Kotlin: Add suport for enum classes

This commit is contained in:
Ian Lynagh
2021-11-01 16:01:51 +00:00
parent 2b01c5d825
commit 81fd7c735a
5 changed files with 38 additions and 0 deletions

View File

@@ -292,6 +292,7 @@ open class KotlinFileExtractor(
// Leaving this intentionally empty. init blocks are extracted during class extraction.
}
is IrProperty -> extractProperty(declaration, parentId)
is IrEnumEntry -> extractEnumEntry(declaration, parentId)
else -> logger.warnElement(Severity.ErrorSevere, "Unrecognised IrDeclaration: " + declaration.javaClass, declaration)
}
}
@@ -978,6 +979,25 @@ class X {
}
}
private fun getEnumEntryLabel(ee: IrEnumEntry) : String {
val parentId = useDeclarationParent(ee.parent)
val label = "@\"field;{$parentId};${ee.name.asString()}\""
return label
}
fun useEnumEntry(ee: IrEnumEntry): Label<out DbField> {
var label = getEnumEntryLabel(ee)
val id: Label<DbField> = tw.getLabelFor(label)
return id
}
fun extractEnumEntry(ee: IrEnumEntry, parentId: Label<out DbReftype>) {
val id = useEnumEntry(ee)
val locId = tw.getLocation(ee)
tw.writeFields(id, ee.name.asString(), parentId, parentId, id)
tw.writeHasLocation(id, locId)
}
fun extractBody(b: IrBody, callable: Label<out DbCallable>) {
when(b) {
is IrBlockBody -> extractBlockBody(b, callable, callable, 0)