Kotlin: getFunctionLabel: Small refactoring

We now pass the IrDeclarationParent of the function to the final
getFunctionLabel function, and that takes care of finding the
enclosing class.
This commit is contained in:
Ian Lynagh
2022-01-19 15:16:33 +00:00
parent 27b0d579d0
commit 72a6bfe7db

View File

@@ -648,14 +648,14 @@ class X {
classTypeArguments: List<IrTypeArgument>?
): String {
val parentId = useDeclarationParent(parent, false, classTypeArguments, true)
return getFunctionLabel(getEnclosingClass(parent), parentId, name, parameters, returnType, extensionReceiverParameter, functionTypeParameters, classTypeArguments)
return getFunctionLabel(parent, parentId, name, parameters, returnType, extensionReceiverParameter, functionTypeParameters, classTypeArguments)
}
fun getFunctionLabel(f: IrFunction, parentId: Label<out DbElement>, classTypeArgsIncludingOuterClasses: List<IrTypeArgument>?) =
getFunctionLabel(getEnclosingClass(f), parentId, getFunctionShortName(f), f.valueParameters, f.returnType, f.extensionReceiverParameter, getFunctionTypeParameters(f), classTypeArgsIncludingOuterClasses)
getFunctionLabel(f.parent, parentId, getFunctionShortName(f), f.valueParameters, f.returnType, f.extensionReceiverParameter, getFunctionTypeParameters(f), classTypeArgsIncludingOuterClasses)
fun getFunctionLabel(
enclosingClass: IrClass?,
parent: IrDeclarationParent,
parentId: Label<out DbElement>,
name: String,
parameters: List<IrValueParameter>,
@@ -673,10 +673,12 @@ class X {
}
val substitutionMap = classTypeArgsIncludingOuterClasses?.let { notNullArgs ->
if (notNullArgs.isEmpty())
if (notNullArgs.isEmpty()) {
null
else
} else {
val enclosingClass = getEnclosingClass(parent)
enclosingClass?.let { notNullClass -> makeTypeGenericSubstitutionMap(notNullClass, notNullArgs) }
}
}
val getIdForFunctionLabel = { it: IrValueParameter ->
// Mimic the Java extractor's behaviour: functions with type parameters are named for their erased types;