KE2: Get some kind of function ID written

This commit is contained in:
Ian Lynagh
2024-08-30 12:35:01 +01:00
parent 4e9a1ef925
commit 770f2d6949
2 changed files with 92 additions and 21 deletions

View File

@@ -1802,13 +1802,12 @@ OLD: KE1
typeSubstitution: TypeSubstitution?,
classTypeArgsIncludingOuterClasses: List<IrTypeArgument>?
*/
) =
null // TODO
): Label<out DbCallable> {
/*
OLD: KE1
if (isFake(f)) {
if (needsInterfaceForwarder(f))
makeInterfaceForwarder(
if (needsInterfaceForwarder(f)) {
return makeInterfaceForwarder(
f,
parentId,
extractBody,
@@ -1816,27 +1815,32 @@ OLD: KE1
typeSubstitution,
classTypeArgsIncludingOuterClasses
)
else null
} else {
return null
}
} else {
*/
/*
OLD: KE1
// Work around an apparent bug causing redeclarations of `fun toString(): String`
// specifically in interfaces loaded from Java classes show up like fake overrides.
val overriddenVisibility =
if (f.isFakeOverride && isJavaBinaryObjectMethodRedeclaration(f))
OverriddenFunctionAttributes(visibility = DescriptorVisibilities.PUBLIC)
else null
forceExtractFunction(
*/
return forceExtractFunction(
f,
parentId,
/*
OLD: KE1
extractBody,
extractMethodAndParameterTypeAccesses,
extractAnnotations,
typeSubstitution,
classTypeArgsIncludingOuterClasses,
overriddenAttributes = overriddenVisibility
*/
)
/*
OLD: KE1
.also {
// The defaults-forwarder function is a static utility, not a member, so we only
// need to extract this for the unspecialised instance of this class.
@@ -1857,8 +1861,8 @@ OLD: KE1
classTypeArgsIncludingOuterClasses
)
}
}
*/
}
/*
OLD: KE1
@@ -2413,10 +2417,13 @@ OLD: KE1
}
}
}
*/
private fun forceExtractFunction(
f: IrFunction,
f: KtFunction,
parentId: Label<out DbReftype>,
/*
OLD: KE1
extractBody: Boolean,
extractMethodAndParameterTypeAccesses: Boolean,
extractAnnotations: Boolean,
@@ -2424,8 +2431,11 @@ OLD: KE1
classTypeArgsIncludingOuterClasses: List<IrTypeArgument>?,
extractOrigin: Boolean = true,
overriddenAttributes: OverriddenFunctionAttributes? = null
*/
): Label<out DbCallable> {
with("function", f) {
/*
OLD: KE1
DeclarationStackAdjuster(f, overriddenAttributes).use {
val javaCallable = getJavaCallable(f)
getFunctionTypeParameters(f).mapIndexed { idx, tp ->
@@ -2437,19 +2447,28 @@ OLD: KE1
?.getOrNull(idx)
)
}
*/
val id =
/*
OLD: KE1
overriddenAttributes?.id
?: // If this is a class that would ordinarily be replaced by a Java
// equivalent (e.g. kotlin.Map -> java.util.Map),
// don't replace here, really extract the Kotlin version:
*/
useFunction<DbCallable>(
f,
parentId,
/*
OLD: KE1
classTypeArgsIncludingOuterClasses,
noReplace = true
*/
)
/*
OLD: KE1
val sourceDeclaration =
overriddenAttributes?.sourceDeclarationId
?: if (typeSubstitution != null && overriddenAttributes?.id == null) {
@@ -2612,12 +2631,18 @@ OLD: KE1
extractMethodAndParameterTypeAccesses
)
}
*/
return id
/*
OLD: KE1
}
*/
}
}
/*
OLD: KE1
private fun isStaticFunction(f: IrFunction): Boolean {
return f.dispatchReceiverParameter == null // Has no dispatch receiver,
&&

View File

@@ -1379,16 +1379,25 @@ OLD: KE1
* that omit one or more parameters that has a default value specified.
*/
@OptIn(ObsoleteDescriptorBasedAPI::class)
*/
fun getFunctionLabel(
f: IrFunction,
f: KtFunction,
parentId: Label<out DbElement>,
/*
OLD: KE1
classTypeArgsIncludingOuterClasses: List<IrTypeArgument>?,
maybeParameterList: List<IrValueParameter>? = null
*/
): String =
getFunctionLabel(
/*
OLD: KE1
f.parent,
*/
parentId,
getFunctionShortName(f).nameInDB,
f.getNameAsName()!!.asString(), // TODO: Remove the !! // OLD KE1: getFunctionShortName(f).nameInDB,
/*
OLD: KE1
(maybeParameterList ?: f.valueParameters).map { it.type },
getAdjustedReturnType(f),
f.extensionReceiverParameter?.type,
@@ -1397,8 +1406,11 @@ OLD: KE1
overridesCollectionsMethodWithAlteredParameterTypes(f),
getJavaCallable(f),
!getInnermostWildcardSupppressionAnnotation(f)
*/
)
/*
OLD: KE1
/*
* This function actually generates the label for a function.
* Sometimes, a function is only generated by kotlinc when writing a
@@ -1406,13 +1418,19 @@ OLD: KE1
* This function therefore takes all the constituent parts of a
* function instead.
*/
*/
fun getFunctionLabel(
/*
OLD: KE1
// The parent of the function; normally f.parent.
parent: IrDeclarationParent,
// The ID of the function's parent, or null if we should work it out ourselves.
*/
// OLD: KE1: The ID of the function's parent, or null if we should work it out ourselves.
parentId: Label<out DbElement>,
// The name of the function; normally f.name.asString().
// OLD: KE1: The name of the function; normally f.name.asString().
name: String,
/*
OLD: KE1
// The types of the value parameters that the functions takes; normally
// f.valueParameters.map { it.type }.
parameterTypes: List<IrType>,
@@ -1440,7 +1458,10 @@ OLD: KE1
// The prefix used in the label. "callable", unless a property label is created, then it's
// "property".
prefix: String = "callable"
*/
): String {
/*
OLD: KE1
val allParamTypes =
if (extensionParamType == null) parameterTypes
else listOf(extensionParamType) + parameterTypes
@@ -1521,9 +1542,16 @@ OLD: KE1
)
"<${functionTypeParameters.size}>"
else ""
*/
val prefix = "x" // TODO
val paramTypeIds = "x" // TODO
val returnTypeId = "x" // TODO
val typeArgSuffix = "x" // TODO
return "@\"$prefix;{$parentId}.$name($paramTypeIds){$returnTypeId}$typeArgSuffix\""
}
/*
OLD: KE1
val javaLangClass by lazy { referenceExternalClass("java.lang.Class") }
fun kClassToJavaClass(t: IrType): IrType {
@@ -1763,39 +1791,57 @@ OLD: KE1
}
return useFunction(f, javaFun, parentId, classTypeArgsIncludingOuterClasses)
}
*/
fun <T : DbCallable> useFunction(
f: IrFunction,
f: KtFunction,
parentId: Label<out DbElement>,
/*
OLD: KE1
classTypeArgsIncludingOuterClasses: List<IrTypeArgument>?,
noReplace: Boolean = false
*/
): Label<out T> {
/*
OLD: KE1
if (f.isLocalFunction()) {
val ids = getLocallyVisibleFunctionLabels(f)
return ids.function.cast<T>()
}
val javaFun = kotlinFunctionToJavaEquivalent(f, noReplace)
return useFunction(f, javaFun, parentId, classTypeArgsIncludingOuterClasses)
*/
val javaFun = f // TODO: kotlinFunctionToJavaEquivalent(f, noReplace)
return useFunction(f, javaFun, parentId /* TODO , classTypeArgsIncludingOuterClasses */)
}
private fun <T : DbCallable> useFunction(
f: IrFunction,
javaFun: IrFunction,
f: KtFunction,
javaFun: KtFunction,
parentId: Label<out DbElement>,
/*
OLD: KE1
classTypeArgsIncludingOuterClasses: List<IrTypeArgument>?
*/
): Label<out T> {
val label = getFunctionLabel(javaFun, parentId, classTypeArgsIncludingOuterClasses)
val label = getFunctionLabel(javaFun, parentId /* TODO , classTypeArgsIncludingOuterClasses */)
val id: Label<T> =
tw.getLabelFor(label) {
/*
OLD: KE1
extractPrivateSpecialisedDeclaration(f, classTypeArgsIncludingOuterClasses)
*/
}
/*
OLD: KE1
if (isExternalDeclaration(javaFun)) {
extractFunctionLaterIfExternalFileMember(javaFun)
extractExternalEnclosingClassLater(javaFun)
}
*/
return id
}
/*
OLD: KE1
private fun extractPrivateSpecialisedDeclaration(
d: IrDeclaration,
classTypeArgsIncludingOuterClasses: List<IrTypeArgument>?