Kotlin: Extract parameters

This commit is contained in:
Ian Lynagh
2021-08-11 19:06:50 +01:00
parent 799cf64fd2
commit 4ba13d3663
2 changed files with 21 additions and 4 deletions

View File

@@ -206,11 +206,12 @@ class KotlinFileExtractor(val tw: TrapWriter) {
}
fun useClass(c: IrClass): Label<out DbClass> {
if(c.name.asString() == "Unit" && tw.getExistingLabelFor<DbClass>(getClassLabel(c)) == null) {
return extractClass(c)
} else {
return addClassLabel(c)
if(c.name.asString() == "Any" || c.name.asString() == "Unit") {
if(tw.getExistingLabelFor<DbClass>(getClassLabel(c)) == null) {
return extractClass(c)
}
}
return addClassLabel(c)
}
fun extractClass(c: IrClass): Label<out DbClass> {
@@ -256,6 +257,15 @@ class KotlinFileExtractor(val tw: TrapWriter) {
return id
}
fun extractValueParameter(vp: IrValueParameter, parent: Label<out DbMethod>, idx: Int) {
val id = tw.getFreshIdLabel<DbParam>()
val typeId = useType(vp.type)
val locId = tw.getLocation(vp.startOffset, vp.endOffset)
tw.writeParams(id, typeId, idx, parent, id)
tw.writeHasLocation(id, locId)
tw.writeParamName(id, vp.name.asString())
}
fun extractFunction(f: IrFunction, parentid: Label<out DbPackage_or_reftype>) {
val id = useFunction(f)
val locId = tw.getLocation(f.startOffset, f.endOffset)
@@ -267,6 +277,9 @@ class KotlinFileExtractor(val tw: TrapWriter) {
if(body != null) {
extractBody(body, id)
}
f.valueParameters.forEachIndexed { i, vp ->
extractValueParameter(vp, id, i)
}
}
fun useProperty(p: IrProperty): Label<out DbField> {