mirror of
https://github.com/github/codeql.git
synced 2025-12-24 04:36:35 +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:
@@ -93,9 +93,9 @@ class ExternalDeclExtractor(val logger: FileLogger, val invocationTrapFile: Stri
|
|||||||
ftw.writeHasLocation(ftw.fileId, ftw.getWholeFileLocation())
|
ftw.writeHasLocation(ftw.fileId, ftw.getWholeFileLocation())
|
||||||
ftw.writeCupackage(ftw.fileId, pkgId)
|
ftw.writeCupackage(ftw.fileId, pkgId)
|
||||||
|
|
||||||
fileExtractor.extractClassSource(irDecl, extractDeclarations = !irDecl.isFileClass, extractStaticInitializer = false, extractPrivateMembers = false)
|
fileExtractor.extractClassSource(irDecl, extractDeclarations = !irDecl.isFileClass, extractStaticInitializer = false, extractPrivateMembers = false, extractFunctionBodies = false)
|
||||||
} else {
|
} else {
|
||||||
fileExtractor.extractDeclaration(irDecl, extractPrivateMembers = false)
|
fileExtractor.extractDeclaration(irDecl, extractPrivateMembers = false, extractFunctionBodies = false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
extractStaticInitializer(file, null)
|
||||||
CommentExtractor(this, file, tw.fileId).extract()
|
CommentExtractor(this, file, tw.fileId).extract()
|
||||||
}
|
}
|
||||||
@@ -98,7 +98,7 @@ open class KotlinFileExtractor(
|
|||||||
else -> true
|
else -> true
|
||||||
}
|
}
|
||||||
|
|
||||||
fun extractDeclaration(declaration: IrDeclaration, extractPrivateMembers: Boolean) {
|
fun extractDeclaration(declaration: IrDeclaration, extractPrivateMembers: Boolean, extractFunctionBodies: Boolean) {
|
||||||
with("declaration", declaration) {
|
with("declaration", declaration) {
|
||||||
if (!shouldExtractDecl(declaration, extractPrivateMembers))
|
if (!shouldExtractDecl(declaration, extractPrivateMembers))
|
||||||
return
|
return
|
||||||
@@ -107,13 +107,13 @@ open class KotlinFileExtractor(
|
|||||||
if (isExternalDeclaration(declaration)) {
|
if (isExternalDeclaration(declaration)) {
|
||||||
extractExternalClassLater(declaration)
|
extractExternalClassLater(declaration)
|
||||||
} else {
|
} else {
|
||||||
extractClassSource(declaration, extractDeclarations = true, extractStaticInitializer = true, extractPrivateMembers = extractPrivateMembers)
|
extractClassSource(declaration, extractDeclarations = true, extractStaticInitializer = true, extractPrivateMembers = extractPrivateMembers, extractFunctionBodies = extractFunctionBodies)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is IrFunction -> {
|
is IrFunction -> {
|
||||||
val parentId = useDeclarationParent(declaration.parent, false)?.cast<DbReftype>()
|
val parentId = useDeclarationParent(declaration.parent, false)?.cast<DbReftype>()
|
||||||
if (parentId != null) {
|
if (parentId != null) {
|
||||||
extractFunction(declaration, parentId, true, null, listOf())
|
extractFunction(declaration, parentId, extractFunctionBodies, null, listOf())
|
||||||
}
|
}
|
||||||
Unit
|
Unit
|
||||||
}
|
}
|
||||||
@@ -130,7 +130,7 @@ open class KotlinFileExtractor(
|
|||||||
is IrEnumEntry -> {
|
is IrEnumEntry -> {
|
||||||
val parentId = useDeclarationParent(declaration.parent, false)?.cast<DbReftype>()
|
val parentId = useDeclarationParent(declaration.parent, false)?.cast<DbReftype>()
|
||||||
if (parentId != null) {
|
if (parentId != null) {
|
||||||
extractEnumEntry(declaration, parentId)
|
extractEnumEntry(declaration, parentId, extractFunctionBodies)
|
||||||
}
|
}
|
||||||
Unit
|
Unit
|
||||||
}
|
}
|
||||||
@@ -360,7 +360,7 @@ open class KotlinFileExtractor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun extractLocalTypeDeclStmt(c: IrClass, callable: Label<out DbCallable>, parent: Label<out DbStmtparent>, idx: Int) {
|
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)
|
extractLocalTypeDeclStmt(id, c, callable, parent, idx)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -372,7 +372,7 @@ open class KotlinFileExtractor(
|
|||||||
tw.writeHasLocation(stmtId, locId)
|
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) {
|
with("class source", c) {
|
||||||
DeclarationStackAdjuster(c).use {
|
DeclarationStackAdjuster(c).use {
|
||||||
|
|
||||||
@@ -410,7 +410,7 @@ open class KotlinFileExtractor(
|
|||||||
|
|
||||||
c.typeParameters.mapIndexed { idx, param -> extractTypeParameter(param, idx) }
|
c.typeParameters.mapIndexed { idx, param -> extractTypeParameter(param, idx) }
|
||||||
if (extractDeclarations) {
|
if (extractDeclarations) {
|
||||||
c.declarations.map { extractDeclaration(it, extractPrivateMembers) }
|
c.declarations.map { extractDeclaration(it, extractPrivateMembers = extractPrivateMembers, extractFunctionBodies = extractFunctionBodies) }
|
||||||
if (extractStaticInitializer)
|
if (extractStaticInitializer)
|
||||||
extractStaticInitializer(c, id)
|
extractStaticInitializer(c, id)
|
||||||
}
|
}
|
||||||
@@ -515,11 +515,11 @@ open class KotlinFileExtractor(
|
|||||||
return FieldResult(instanceId, instanceName)
|
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) {
|
with("value parameter", vp) {
|
||||||
val location = getLocation(vp, classTypeArgsIncludingOuterClasses)
|
val location = getLocation(vp, classTypeArgsIncludingOuterClasses)
|
||||||
val id = useValueParameter(vp, parent)
|
val id = useValueParameter(vp, parent)
|
||||||
if (!isExternalDeclaration(vp)) {
|
if (extractTypeAccess) {
|
||||||
extractTypeAccessRecursive(vp.type, location, id, -1)
|
extractTypeAccessRecursive(vp.type, location, id, -1)
|
||||||
}
|
}
|
||||||
return extractValueParameter(id, vp.type, vp.name.asString(), location, parent, idx, typeSubstitution, useValueParameter(vp, parentSourceDeclaration), vp.isVararg)
|
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 extReceiver = f.extensionReceiverParameter
|
||||||
val idxOffset = if (extReceiver != null) 1 else 0
|
val idxOffset = if (extReceiver != null) 1 else 0
|
||||||
val paramTypes = f.valueParameters.mapIndexed { i, vp ->
|
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 allParamTypes = if (extReceiver != null) {
|
||||||
val extendedType = useType(extReceiver.type)
|
val extendedType = useType(extReceiver.type)
|
||||||
tw.writeKtExtensionFunctions(id.cast<DbMethod>(), extendedType.javaResult.id, extendedType.kotlinResult.id)
|
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
|
listOf(t) + paramTypes
|
||||||
} else {
|
} else {
|
||||||
paramTypes
|
paramTypes
|
||||||
@@ -741,7 +741,7 @@ open class KotlinFileExtractor(
|
|||||||
tw.writeMethods(methodId, shortName.nameInDB, "${shortName.nameInDB}$paramsSignature", returnType.javaResult.id, parentId, sourceDeclaration.cast<DbMethod>())
|
tw.writeMethods(methodId, shortName.nameInDB, "${shortName.nameInDB}$paramsSignature", returnType.javaResult.id, parentId, sourceDeclaration.cast<DbMethod>())
|
||||||
tw.writeMethodsKotlinType(methodId, returnType.kotlinResult.id)
|
tw.writeMethodsKotlinType(methodId, returnType.kotlinResult.id)
|
||||||
|
|
||||||
if (!isExternalDeclaration(f)) {
|
if (extractBody) {
|
||||||
extractTypeAccessRecursive(f.returnType, locId, id, -1)
|
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) {
|
with("enum entry", ee) {
|
||||||
DeclarationStackAdjuster(ee).use {
|
DeclarationStackAdjuster(ee).use {
|
||||||
val id = useEnumEntry(ee)
|
val id = useEnumEntry(ee)
|
||||||
@@ -884,7 +884,7 @@ open class KotlinFileExtractor(
|
|||||||
val locId = tw.getLocation(ee)
|
val locId = tw.getLocation(ee)
|
||||||
tw.writeHasLocation(id, locId)
|
tw.writeHasLocation(id, locId)
|
||||||
|
|
||||||
if (!isExternalDeclaration(ee)) {
|
if (extractTypeAccess) {
|
||||||
val fieldDeclarationId = tw.getFreshIdLabel<DbFielddecl>()
|
val fieldDeclarationId = tw.getFreshIdLabel<DbFielddecl>()
|
||||||
tw.writeFielddecls(fieldDeclarationId, parentId)
|
tw.writeFielddecls(fieldDeclarationId, parentId)
|
||||||
tw.writeFieldDeclaredIn(id, fieldDeclarationId, 0)
|
tw.writeFieldDeclaredIn(id, fieldDeclarationId, 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user