-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathOverlay.qll
More file actions
56 lines (50 loc) · 1.88 KB
/
Overlay.qll
File metadata and controls
56 lines (50 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
* Defines entity discard predicates for Go overlay analysis.
*/
overlay[local]
module;
private import internal.OverlayXml
/**
* A local predicate that always holds for the overlay variant and never holds for the base variant.
* This is used to define local predicates that behave differently for the base and overlay variant.
*/
private predicate isOverlay() { databaseMetadata("isOverlay", "true") }
/** Gets the file containing the given `locatable`. */
private @file getFile(@locatable locatable) {
exists(@location_default location | has_location(locatable, location) |
locations_default(location, result, _, _, _, _)
)
}
/** Holds if the `locatable` is in the `file` and is part of the overlay base database. */
private predicate discardableLocatable(@file file, @locatable locatable) {
not isOverlay() and
file = getFile(locatable) and
// Avoid discarding @file entities, since they are shared between base and overlay.
not locatable instanceof @file
}
/**
* Holds if the given `path` is for a file in the base database whose entities should be discarded.
*/
bindingset[path]
private predicate discardableFile(string path) {
isOverlay() and
(
overlayChangedFiles(path)
or
// The extractor unconditionally extracts files outside of the source directory (these are
// typically cgo-processed source files), so all entities in such files should be discarded.
not exists(string srcLoc | sourceLocationPrefix(srcLoc) |
path.substring(0, srcLoc.length()) = srcLoc
)
)
}
/**
* Holds if the given `locatable` should be discarded, because it is part of the overlay base and is
* in a file that was also extracted as part of the overlay database.
*/
overlay[discard_entity]
private predicate discardLocatable(@locatable locatable) {
exists(@file file, string path | files(file, path) |
discardableLocatable(file, locatable) and discardableFile(path)
)
}