mirror of
https://github.com/github/codeql.git
synced 2025-12-22 19:56:32 +01:00
Only extract parameter and method type-accesses once
Previously we extracted them whenever something was non-external, but this led to re-extraction when an instance of a generic type defined in source was extracted multiple times.
This commit is contained in:
@@ -74,7 +74,7 @@ open class KotlinFileExtractor(
|
||||
}
|
||||
}
|
||||
|
||||
file.declarations.map { extractDeclaration(it, extractPrivateMembers = true) }
|
||||
file.declarations.map { extractDeclaration(it, extractPrivateMembers = true, extractFunctionBodies = true) }
|
||||
extractStaticInitializer(file, null)
|
||||
CommentExtractor(this, file, tw.fileId).extract()
|
||||
}
|
||||
@@ -98,7 +98,7 @@ open class KotlinFileExtractor(
|
||||
else -> true
|
||||
}
|
||||
|
||||
fun extractDeclaration(declaration: IrDeclaration, extractPrivateMembers: Boolean) {
|
||||
fun extractDeclaration(declaration: IrDeclaration, extractPrivateMembers: Boolean, extractFunctionBodies: Boolean) {
|
||||
with("declaration", declaration) {
|
||||
if (!shouldExtractDecl(declaration, extractPrivateMembers))
|
||||
return
|
||||
@@ -107,13 +107,13 @@ open class KotlinFileExtractor(
|
||||
if (isExternalDeclaration(declaration)) {
|
||||
extractExternalClassLater(declaration)
|
||||
} else {
|
||||
extractClassSource(declaration, extractDeclarations = true, extractStaticInitializer = true, extractPrivateMembers = extractPrivateMembers)
|
||||
extractClassSource(declaration, extractDeclarations = true, extractStaticInitializer = true, extractPrivateMembers = extractPrivateMembers, extractFunctionBodies = extractFunctionBodies)
|
||||
}
|
||||
}
|
||||
is IrFunction -> {
|
||||
val parentId = useDeclarationParent(declaration.parent, false)?.cast<DbReftype>()
|
||||
if (parentId != null) {
|
||||
extractFunction(declaration, parentId, true, null, listOf())
|
||||
extractFunction(declaration, parentId, extractFunctionBodies, null, listOf())
|
||||
}
|
||||
Unit
|
||||
}
|
||||
@@ -130,7 +130,7 @@ open class KotlinFileExtractor(
|
||||
is IrEnumEntry -> {
|
||||
val parentId = useDeclarationParent(declaration.parent, false)?.cast<DbReftype>()
|
||||
if (parentId != null) {
|
||||
extractEnumEntry(declaration, parentId)
|
||||
extractEnumEntry(declaration, parentId, extractFunctionBodies)
|
||||
}
|
||||
Unit
|
||||
}
|
||||
@@ -360,7 +360,7 @@ open class KotlinFileExtractor(
|
||||
}
|
||||
|
||||
private fun extractLocalTypeDeclStmt(c: IrClass, callable: Label<out DbCallable>, parent: Label<out DbStmtparent>, idx: Int) {
|
||||
val id = extractClassSource(c, extractDeclarations = true, extractStaticInitializer = true, extractPrivateMembers = true).cast<DbClass>()
|
||||
val id = extractClassSource(c, extractDeclarations = true, extractStaticInitializer = true, extractPrivateMembers = true, extractFunctionBodies = true).cast<DbClass>()
|
||||
extractLocalTypeDeclStmt(id, c, callable, parent, idx)
|
||||
}
|
||||
|
||||
@@ -372,7 +372,7 @@ open class KotlinFileExtractor(
|
||||
tw.writeHasLocation(stmtId, locId)
|
||||
}
|
||||
|
||||
fun extractClassSource(c: IrClass, extractDeclarations: Boolean, extractStaticInitializer: Boolean, extractPrivateMembers: Boolean): Label<out DbClassorinterface> {
|
||||
fun extractClassSource(c: IrClass, extractDeclarations: Boolean, extractStaticInitializer: Boolean, extractPrivateMembers: Boolean, extractFunctionBodies: Boolean): Label<out DbClassorinterface> {
|
||||
with("class source", c) {
|
||||
DeclarationStackAdjuster(c).use {
|
||||
|
||||
@@ -410,7 +410,7 @@ open class KotlinFileExtractor(
|
||||
|
||||
c.typeParameters.mapIndexed { idx, param -> extractTypeParameter(param, idx) }
|
||||
if (extractDeclarations) {
|
||||
c.declarations.map { extractDeclaration(it, extractPrivateMembers) }
|
||||
c.declarations.map { extractDeclaration(it, extractPrivateMembers = extractPrivateMembers, extractFunctionBodies = extractFunctionBodies) }
|
||||
if (extractStaticInitializer)
|
||||
extractStaticInitializer(c, id)
|
||||
}
|
||||
@@ -515,11 +515,11 @@ open class KotlinFileExtractor(
|
||||
return FieldResult(instanceId, instanceName)
|
||||
}
|
||||
|
||||
private fun extractValueParameter(vp: IrValueParameter, parent: Label<out DbCallable>, idx: Int, typeSubstitution: TypeSubstitution?, parentSourceDeclaration: Label<out DbCallable>, classTypeArgsIncludingOuterClasses: List<IrTypeArgument>?): TypeResults {
|
||||
private fun extractValueParameter(vp: IrValueParameter, parent: Label<out DbCallable>, idx: Int, typeSubstitution: TypeSubstitution?, parentSourceDeclaration: Label<out DbCallable>, classTypeArgsIncludingOuterClasses: List<IrTypeArgument>?, extractTypeAccess: Boolean): TypeResults {
|
||||
with("value parameter", vp) {
|
||||
val location = getLocation(vp, classTypeArgsIncludingOuterClasses)
|
||||
val id = useValueParameter(vp, parent)
|
||||
if (!isExternalDeclaration(vp)) {
|
||||
if (extractTypeAccess) {
|
||||
extractTypeAccessRecursive(vp.type, location, id, -1)
|
||||
}
|
||||
return extractValueParameter(id, vp.type, vp.name.asString(), location, parent, idx, typeSubstitution, useValueParameter(vp, parentSourceDeclaration), vp.isVararg)
|
||||
@@ -706,13 +706,13 @@ open class KotlinFileExtractor(
|
||||
val extReceiver = f.extensionReceiverParameter
|
||||
val idxOffset = if (extReceiver != null) 1 else 0
|
||||
val paramTypes = f.valueParameters.mapIndexed { i, vp ->
|
||||
extractValueParameter(vp, id, i + idxOffset, typeSubstitution, sourceDeclaration, classTypeArgsIncludingOuterClasses)
|
||||
extractValueParameter(vp, id, i + idxOffset, typeSubstitution, sourceDeclaration, classTypeArgsIncludingOuterClasses, extractTypeAccess = extractBody)
|
||||
}
|
||||
val allParamTypes = if (extReceiver != null) {
|
||||
val extendedType = useType(extReceiver.type)
|
||||
tw.writeKtExtensionFunctions(id.cast<DbMethod>(), extendedType.javaResult.id, extendedType.kotlinResult.id)
|
||||
|
||||
val t = extractValueParameter(extReceiver, id, 0, null, sourceDeclaration, classTypeArgsIncludingOuterClasses)
|
||||
val t = extractValueParameter(extReceiver, id, 0, null, sourceDeclaration, classTypeArgsIncludingOuterClasses, extractTypeAccess = extractBody)
|
||||
listOf(t) + paramTypes
|
||||
} else {
|
||||
paramTypes
|
||||
@@ -741,7 +741,7 @@ open class KotlinFileExtractor(
|
||||
tw.writeMethods(methodId, shortName.nameInDB, "${shortName.nameInDB}$paramsSignature", returnType.javaResult.id, parentId, sourceDeclaration.cast<DbMethod>())
|
||||
tw.writeMethodsKotlinType(methodId, returnType.kotlinResult.id)
|
||||
|
||||
if (!isExternalDeclaration(f)) {
|
||||
if (extractBody) {
|
||||
extractTypeAccessRecursive(f.returnType, locId, id, -1)
|
||||
}
|
||||
|
||||
@@ -874,7 +874,7 @@ open class KotlinFileExtractor(
|
||||
}
|
||||
}
|
||||
|
||||
fun extractEnumEntry(ee: IrEnumEntry, parentId: Label<out DbReftype>) {
|
||||
fun extractEnumEntry(ee: IrEnumEntry, parentId: Label<out DbReftype>, extractTypeAccess: Boolean) {
|
||||
with("enum entry", ee) {
|
||||
DeclarationStackAdjuster(ee).use {
|
||||
val id = useEnumEntry(ee)
|
||||
@@ -884,7 +884,7 @@ open class KotlinFileExtractor(
|
||||
val locId = tw.getLocation(ee)
|
||||
tw.writeHasLocation(id, locId)
|
||||
|
||||
if (!isExternalDeclaration(ee)) {
|
||||
if (extractTypeAccess) {
|
||||
val fieldDeclarationId = tw.getFreshIdLabel<DbFielddecl>()
|
||||
tw.writeFielddecls(fieldDeclarationId, parentId)
|
||||
tw.writeFieldDeclaredIn(id, fieldDeclarationId, 0)
|
||||
|
||||
Reference in New Issue
Block a user