mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
C/C++ overlay: Address review comments
Split the discard predicate into two: one for single-location elements and one for multi-location elements.
This commit is contained in:
@@ -16,58 +16,49 @@ private string getLocationFilePath(@location_default loc) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An element with a single location. Discard if in a changed file.
|
* Gets the file path for an element with a single location.
|
||||||
*/
|
*/
|
||||||
overlay[local]
|
overlay[local]
|
||||||
abstract private class Discardable extends @element {
|
private string getSingleLocationFilePath(@element e) {
|
||||||
abstract string getFilePath();
|
// @var_decl has a direct location in the var_decls relation
|
||||||
|
exists(@location_default loc | var_decls(e, _, _, _, loc) | result = getLocationFilePath(loc))
|
||||||
predicate existsInBase() { not isOverlay() }
|
//TODO: add other kinds of elements with single locations
|
||||||
|
|
||||||
string toString() { none() }
|
|
||||||
}
|
|
||||||
|
|
||||||
overlay[discard_entity]
|
|
||||||
private predicate discardable(@element e) {
|
|
||||||
e = any(Discardable d | d.existsInBase() and overlayChangedFiles(d.getFilePath()))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An element with potentially multiple locations, e.g., variables, functions and types.
|
* Gets the file path for an element with potentially multiple locations.
|
||||||
* Discard only if all locations are in changed files.
|
|
||||||
*/
|
*/
|
||||||
overlay[local]
|
overlay[local]
|
||||||
abstract private class MultiDiscardable extends @element {
|
private string getMultiLocationFilePath(@element e) {
|
||||||
abstract string getFilePath();
|
// @variable gets its location(s) from its @var_decl(s)
|
||||||
|
exists(@var_decl vd, @location_default loc | var_decls(vd, e, _, _, loc) |
|
||||||
predicate existsInBase() { not isOverlay() }
|
result = getLocationFilePath(loc)
|
||||||
|
)
|
||||||
string toString() { none() }
|
//TODO: add other kinds of elements with multiple locations
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Holds if `e` exists in the base variant. */
|
||||||
|
overlay[local]
|
||||||
|
private predicate existsInBase(@element e) {
|
||||||
|
not isOverlay() and
|
||||||
|
(exists(getSingleLocationFilePath(e)) or exists(getMultiLocationFilePath(e)))
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Discard an element with a single location if it is in a changed file.
|
||||||
|
*/
|
||||||
overlay[discard_entity]
|
overlay[discard_entity]
|
||||||
private predicate multiDiscardable(@element e) {
|
private predicate discardSingleLocationElement(@element e) {
|
||||||
e =
|
existsInBase(e) and
|
||||||
any(MultiDiscardable d |
|
overlayChangedFiles(getSingleLocationFilePath(e))
|
||||||
d.existsInBase() and
|
|
||||||
forall(string path | path = d.getFilePath() | overlayChangedFiles(path))
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
overlay[local]
|
/**
|
||||||
private class DiscardableVarDecl extends Discardable instanceof @var_decl {
|
* Discard an element with multiple locations only if all its locations are in changed files.
|
||||||
override string getFilePath() {
|
*/
|
||||||
exists(@location_default loc | var_decls(this, _, _, _, loc) |
|
overlay[discard_entity]
|
||||||
result = getLocationFilePath(loc)
|
private predicate discardMultiLocationElement(@element e) {
|
||||||
)
|
existsInBase(e) and
|
||||||
}
|
exists(getMultiLocationFilePath(e)) and
|
||||||
}
|
forall(string path | path = getMultiLocationFilePath(e) | overlayChangedFiles(path))
|
||||||
|
|
||||||
overlay[local]
|
|
||||||
private class DiscardableVariable extends MultiDiscardable instanceof @variable {
|
|
||||||
override string getFilePath() {
|
|
||||||
exists(@var_decl vd, @location_default loc | var_decls(vd, this, _, _, loc) |
|
|
||||||
result = getLocationFilePath(loc)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user