-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathOverlay.qll
More file actions
80 lines (68 loc) · 2.47 KB
/
Overlay.qll
File metadata and controls
80 lines (68 loc) · 2.47 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
overlay[local?]
module;
import java
/**
* 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.
*/
overlay[local]
predicate isOverlay() { databaseMetadata("isOverlay", "true") }
/** Gets the raw file for a locatable. */
overlay[local]
string getRawFile(@locatable el) {
exists(@location loc, @file file |
hasLocation(el, loc) and
locations_default(loc, file, _, _, _, _) and
files(file, result)
)
}
/** Gets the raw file for a location. */
overlay[local]
string getRawFileForLoc(@location l) {
exists(@file f | locations_default(l, f, _, _, _, _) and files(f, result))
}
/** Holds for files fully extracted in the overlay. */
overlay[local]
predicate extractedInOverlay(string file) {
isOverlay() and
// numlines is used to restrict attention to fully extracted files and
// ignore skeleton extracted files in the overlay
exists(@locatable l | numlines(l, _, _, _) and file = getRawFile(l))
}
/**
* A `@locatable` that should be discarded in the base variant if its file is
* extracted in the overlay variant.
*/
overlay[local]
abstract class DiscardableLocatable extends @locatable {
/** Gets the raw file for a locatable in base. */
string getRawFileInBase() { not isOverlay() and result = getRawFile(this) }
/** Gets a textual representation of this discardable locatable. */
string toString() { none() }
}
overlay[discard_entity]
private predicate discardLocatable(@locatable el) {
extractedInOverlay(el.(DiscardableLocatable).getRawFileInBase())
}
/**
* A `@locatable` that should be discarded in the base variant if its file is
* extracted in the overlay variant and it is itself not extracted in the
* overlay, that is, it is deleted in the overlay.
*/
overlay[local]
abstract class DiscardableReferableLocatable extends @locatable {
/** Gets the raw file for a locatable in base. */
string getRawFileInBase() { not isOverlay() and result = getRawFile(this) }
/** Holds if the locatable exists in the overlay. */
predicate existsInOverlay() { isOverlay() and exists(this) }
/** Gets a textual representation of this discardable locatable. */
string toString() { none() }
}
overlay[discard_entity]
private predicate discardReferableLocatable(@locatable el) {
exists(DiscardableReferableLocatable drl | drl = el |
extractedInOverlay(drl.getRawFileInBase()) and
not drl.existsInOverlay()
)
}