KE2: Start extracting method return types

This commit is contained in:
Ian Lynagh
2024-09-03 10:35:20 +01:00
parent 581fed8ae9
commit d85f05be0c
2 changed files with 37 additions and 5 deletions

View File

@@ -1,6 +1,7 @@
package com.github.codeql
import org.jetbrains.kotlin.analysis.api.KaSession
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.*
@@ -2308,19 +2309,29 @@ OLD: KE1
)
tw.writeConstrsKotlinType(id, unitType.kotlinResult.id)
}
*/
// TODO: Can this be inlined?
private fun extractMethod(
id: Label<out DbMethod>,
/*
OLD: KE1
locId: Label<out DbLocation>,
shortName: String,
returnType: IrType,
*/
returnType: KaType,
/*
OLD: KE1
paramsSignature: String,
parentId: Label<out DbReftype>,
sourceDeclaration: Label<out DbMethod>,
origin: IrDeclarationOrigin?,
extractTypeAccess: Boolean
*/
) {
val returnTypeResults = useType(returnType, TypeContext.RETURN)
/*
OLD: KE1
tw.writeMethods(
id,
shortName,
@@ -2350,8 +2361,11 @@ OLD: KE1
if (extractTypeAccess) {
extractTypeAccessRecursive(returnType, locId, id, -1)
}
*/
}
/*
OLD: KE1
private fun signatureOrWarn(t: TypeResult<*>, associatedElement: IrElement?) =
t.signature
?: "<signature unavailable>"
@@ -2421,6 +2435,7 @@ OLD: KE1
}
*/
// TODO: Can this be inlined?
private fun forceExtractFunction(
f: KtFunction,
parentId: Label<out DbReftype>,
@@ -2553,19 +2568,28 @@ OLD: KE1
)
} else {
val shortNames = getFunctionShortName(f)
*/
val methodId = id.cast<DbMethod>()
extractMethod(
methodId,
/*
OLD: KE1
locId,
shortNames.nameInDB,
substReturnType,
*/
f.returnType, // OLD: KE1: substReturnType,
/*
OLD: KE1
paramsSignature,
parentId,
sourceDeclaration.cast(),
if (extractOrigin) f.origin else null,
extractMethodAndParameterTypeAccesses
*/
)
/*
OLD: KE1
if (shortNames.nameInDB != shortNames.kotlinName) {
tw.writeKtFunctionOriginalNames(methodId, shortNames.kotlinName)
}

View File

@@ -577,19 +577,24 @@ OLD: KE1
*/
val classLabelResult = getClassLabel(c /* TODO replacedClass, replacedArgsIncludingOuterClasses */)
TODO()
/*
OLD: KE1
var instanceSeenBefore = true
*/
val classLabel: Label<out DbClassorinterface> =
tw.getLabelFor(classLabelResult.classLabel) {
/*
OLD: KE1
instanceSeenBefore = false
extractClassLaterIfExternal(replacedClass)
*/
}
/*
OLD: KE1
if (
replacedArgsIncludingOuterClasses == null ||
replacedArgsIncludingOuterClasses.isNotEmpty()
@@ -621,8 +626,8 @@ OLD: KE1
} else {
fqName.asString()
}
return TypeResult(classLabel, signature, classLabelResult.shortName)
*/
return TypeResult(classLabel /* TODO , signature, classLabelResult.shortName */)
}
/*
@@ -675,7 +680,9 @@ OLD: KE1
TypeResult(fakeKotlinType(), "TODO", "TODO")
)
}
*/
// TODO
fun fakeKotlinType(): Label<out DbKt_type> {
val fakeKotlinPackageId: Label<DbPackage> =
tw.getLabelFor("@\"FakeKotlinPackage\"", { tw.writePackages(it, "fake.kotlin") })
@@ -692,6 +699,7 @@ OLD: KE1
return fakeKotlinTypeId
}
/*
// `args` can be null to describe a raw generic type.
// For non-generic types it will be zero-length list.
fun useSimpleTypeClass(
@@ -725,7 +733,7 @@ OLD: KE1
c: KaClassType
): TypeResults {
val javaResult = addClassLabel(c)
val kotlinResult = TODO()
val kotlinResult = TypeResult(fakeKotlinType() /* , "TODO", "TODO" */)
return TypeResults(javaResult, kotlinResult)
}