Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c125c1a

Browse files
committed
Kotlin: getFunctionLabel: Make parentId be nullable
This allows us to simplify the set of functions.
1 parent dd51141 commit c125c1a

2 files changed

Lines changed: 7 additions & 19 deletions

File tree

java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ open class KotlinFileExtractor(
412412
}
413413

414414
// add method:
415-
val obinitLabel = getFunctionLabel(c, "<obinit>", listOf(), pluginContext.irBuiltIns.unitType, extensionReceiverParameter = null, functionTypeParameters = listOf(), classTypeArgsIncludingOuterClasses = listOf())
415+
val obinitLabel = getFunctionLabel(c, parentId, "<obinit>", listOf(), pluginContext.irBuiltIns.unitType, extensionReceiverParameter = null, functionTypeParameters = listOf(), classTypeArgsIncludingOuterClasses = listOf())
416416
val obinitId = tw.getLabelFor<DbMethod>(obinitLabel)
417417
val returnType = useType(pluginContext.irBuiltIns.unitType)
418418
tw.writeMethods(obinitId, "<obinit>", "<obinit>()", returnType.javaResult.id, returnType.kotlinResult.id, parentId, obinitId)
@@ -1561,7 +1561,7 @@ open class KotlinFileExtractor(
15611561
val id = tw.getFreshIdLabel<DbMethodaccess>()
15621562
val type = useType(e.type)
15631563
val locId = tw.getLocation(e)
1564-
val methodLabel = getFunctionLabel(irCallable.parent, "<obinit>", listOf(), e.type, null, functionTypeParameters = listOf(), classTypeArgsIncludingOuterClasses = listOf())
1564+
val methodLabel = getFunctionLabel(irCallable.parent, null, "<obinit>", listOf(), e.type, null, functionTypeParameters = listOf(), classTypeArgsIncludingOuterClasses = listOf())
15651565
val methodId = tw.getLabelFor<DbMethod>(methodLabel)
15661566
tw.writeExprs_methodaccess(id, type.javaResult.id, type.kotlinResult.id, exprParent.parent, exprParent.idx)
15671567
tw.writeHasLocation(id, locId)

java/kotlin-extractor/src/main/kotlin/KotlinUsesExtractor.kt

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -627,43 +627,31 @@ class X {
627627
else -> listOf()
628628
}
629629

630-
fun getFunctionLabel(f: IrFunction, classTypeArgsIncludingOuterClasses: List<IrTypeArgument>? = null) : String {
631-
return getFunctionLabel(f.parent, getFunctionShortName(f), f.valueParameters, f.returnType, f.extensionReceiverParameter, getFunctionTypeParameters(f), classTypeArgsIncludingOuterClasses)
632-
}
633-
634630
fun getEnclosingClass(it: IrDeclarationParent): IrClass? =
635631
when(it) {
636632
is IrClass -> it
637633
is IrFunction -> getEnclosingClass(it.parent)
638634
else -> null
639635
}
640636

641-
fun getFunctionLabel(
642-
parent: IrDeclarationParent,
643-
name: String,
644-
parameters: List<IrValueParameter>,
645-
returnType: IrType,
646-
extensionReceiverParameter: IrValueParameter?,
647-
functionTypeParameters: List<IrTypeParameter>,
648-
classTypeArgsIncludingOuterClasses: List<IrTypeArgument>?
649-
): String {
650-
val parentId = useDeclarationParent(parent, false, classTypeArgsIncludingOuterClasses, true)
651-
return getFunctionLabel(parent, parentId, name, parameters, returnType, extensionReceiverParameter, functionTypeParameters, classTypeArgsIncludingOuterClasses)
637+
fun getFunctionLabel(f: IrFunction, classTypeArgsIncludingOuterClasses: List<IrTypeArgument>? = null) : String {
638+
return getFunctionLabel(f, null, classTypeArgsIncludingOuterClasses)
652639
}
653640

654-
fun getFunctionLabel(f: IrFunction, parentId: Label<out DbElement>, classTypeArgsIncludingOuterClasses: List<IrTypeArgument>?) =
641+
fun getFunctionLabel(f: IrFunction, parentId: Label<out DbElement>?, classTypeArgsIncludingOuterClasses: List<IrTypeArgument>?) =
655642
getFunctionLabel(f.parent, parentId, getFunctionShortName(f), f.valueParameters, f.returnType, f.extensionReceiverParameter, getFunctionTypeParameters(f), classTypeArgsIncludingOuterClasses)
656643

657644
fun getFunctionLabel(
658645
parent: IrDeclarationParent,
659-
parentId: Label<out DbElement>,
646+
maybeParentId: Label<out DbElement>?,
660647
name: String,
661648
parameters: List<IrValueParameter>,
662649
returnType: IrType,
663650
extensionReceiverParameter: IrValueParameter?,
664651
functionTypeParameters: List<IrTypeParameter>,
665652
classTypeArgsIncludingOuterClasses: List<IrTypeArgument>?
666653
): String {
654+
val parentId = maybeParentId ?: useDeclarationParent(parent, false, classTypeArgsIncludingOuterClasses, true)
667655
val allParams = if (extensionReceiverParameter == null) {
668656
parameters
669657
} else {

0 commit comments

Comments
 (0)