Skip to content

Commit 87d001f

Browse files
committed
Go: implement overlay discarding for @locatable
1 parent 774eb0d commit 87d001f

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

go/ql/lib/semmle/go/Locations.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/** Provides classes for working with locations and program elements that have locations. */
22

33
import go
4+
private import semmle.go.Overlay
45

56
/**
67
* A location as given by a file, a start line, a start column,

go/ql/lib/semmle/go/Overlay.qll

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Defines entity discard predicates for Go overlay analysis.
3+
*/
4+
overlay[local]
5+
module;
6+
7+
/**
8+
* A local predicate that always holds for the overlay variant and never holds for the base variant.
9+
* This is used to define local predicates that behave differently for the base and overlay variant.
10+
*/
11+
private predicate isOverlay() { databaseMetadata("isOverlay", "true") }
12+
13+
/** Gets the file containing the given `locatable`. */
14+
private @file getFile(@locatable locatable) {
15+
exists(@location_default location | has_location(locatable, location) |
16+
locations_default(location, result, _, _, _, _)
17+
)
18+
}
19+
20+
/** Holds if the `locatable` is in the `file` and is part of the overlay base database. */
21+
private predicate discardableLocatable(@file file, @locatable locatable) {
22+
not isOverlay() and
23+
file = getFile(locatable)
24+
}
25+
26+
/**
27+
* Holds if the given `locatable` should be discarded, because it is part of the overlay base and is
28+
* in a file that was also extracted as part of the overlay database.
29+
*/
30+
overlay[discard_entity]
31+
private predicate discardLocatable(@locatable locatable) {
32+
exists(@file file, string path | files(file, path) |
33+
discardableLocatable(file, locatable) and overlayChangedFiles(path)
34+
)
35+
}

0 commit comments

Comments
 (0)