KE2: Start looking at extracting types

This commit is contained in:
Ian Lynagh
2024-09-02 15:59:26 +01:00
parent 74d2b43bfb
commit dbf82d5225
2 changed files with 24 additions and 1 deletions

View File

@@ -2,6 +2,7 @@ package com.github.codeql
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.analysis.api.KaSession
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.psi.*
/*
@@ -132,8 +133,12 @@ OLD: KE1
val typeResult: TypeResult<DbClassorinterface>,
val javaClass: IrClass
)
*/
fun useType(t: IrType, context: TypeContext = TypeContext.OTHER): TypeResults {
fun useType(t: KaType, context: TypeContext = TypeContext.OTHER): TypeResults {
TODO()
/*
OLD: KE1
when (t) {
is IrSimpleType -> return useSimpleType(t, context)
else -> {
@@ -141,8 +146,11 @@ OLD: KE1
return extractErrorType()
}
}
*/
}
/*
OLD: KE1
private fun extractJavaErrorType(): TypeResult<DbErrortype> {
val typeId = tw.getLabelFor<DbErrortype>("@\"errorType\"") { tw.writeError_type(it) }
return TypeResult(typeId, "<CodeQL error type>", "<CodeQL error type>")
@@ -833,6 +841,7 @@ OLD: KE1
return ArrayInfo(recInfo.elementTypeResults, typeResults, dimensions)
}
*/
enum class TypeContext {
RETURN,
@@ -840,6 +849,8 @@ OLD: KE1
OTHER
}
/*
OLD: KE1
private fun useSimpleType(s: IrSimpleType, context: TypeContext): TypeResults {
if (s.abbreviation != null) {
// TODO: Extract this information

View File

@@ -14,14 +14,21 @@ OLD: KE1
* arguments ("InnerClass<E>" or "OuterClass<ConcreteArgument>" or "OtherClass<? extends Bound>") or
* an array ("componentShortName[]").
*/
*/
data class TypeResultGeneric<SignatureType, out LabelType : AnyDbType>(
val id: Label<out LabelType>,
/*
OLD: KE1
val signature: SignatureType?,
val shortName: String
*/
) {
/*
OLD: KE1
fun <U : AnyDbType> cast(): TypeResultGeneric<SignatureType, U> {
@Suppress("UNCHECKED_CAST") return this as TypeResultGeneric<SignatureType, U>
}
*/
}
data class TypeResultsGeneric<SignatureType>(
@@ -29,12 +36,17 @@ data class TypeResultsGeneric<SignatureType>(
val kotlinResult: TypeResultGeneric<SignatureType, DbKt_type>
)
/*
OLD: KE1
typealias TypeResult<T> = TypeResultGeneric<String, T>
typealias TypeResultWithoutSignature<T> = TypeResultGeneric<Unit, T>
*/
typealias TypeResults = TypeResultsGeneric<String>
/*
OLD: KE1
typealias TypeResultsWithoutSignatures = TypeResultsGeneric<Unit>
fun <T : AnyDbType> TypeResult<T>.forgetSignature(): TypeResultWithoutSignature<T> {