Skip to content

Commit 8fccc34

Browse files
authored
Merge pull request #21017 from github/idrissrio/cpp/overlay/xml
2 parents 5db6b92 + 926d7f5 commit 8fccc34

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

config/identical-files.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@
282282
"java/ql/lib/semmle/code/java/internal/OverlayXml.qll",
283283
"go/ql/lib/semmle/go/internal/OverlayXml.qll",
284284
"python/ql/lib/semmle/python/internal/OverlayXml.qll",
285-
"csharp/ql/lib/semmle/code/csharp/internal/OverlayXml.qll"
285+
"csharp/ql/lib/semmle/code/csharp/internal/OverlayXml.qll",
286+
"cpp/ql/lib/semmle/code/cpp/internal/OverlayXml.qll"
286287
]
287288
}

cpp/ql/lib/semmle/code/cpp/internal/Overlay.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
* Defines entity discard predicates for C++ overlay analysis.
33
*/
44

5+
private import OverlayXml
6+
57
/**
68
* Holds always for the overlay variant and never for the base variant.
79
* This local predicate is used to define local predicates that behave
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
overlay[local]
2+
module;
3+
4+
/**
5+
* A local predicate that always holds for the overlay variant and never holds for the base variant.
6+
* This is used to define local predicates that behave differently for the base and overlay variant.
7+
*/
8+
private predicate isOverlay() { databaseMetadata("isOverlay", "true") }
9+
10+
private string getXmlFile(@xmllocatable locatable) {
11+
exists(@location_default location, @file file | xmllocations(locatable, location) |
12+
locations_default(location, file, _, _, _, _) and
13+
files(file, result)
14+
)
15+
}
16+
17+
private string getXmlFileInBase(@xmllocatable locatable) {
18+
not isOverlay() and
19+
result = getXmlFile(locatable)
20+
}
21+
22+
/**
23+
* Holds if the given `file` was extracted as part of the overlay and was extracted by the HTML/XML
24+
* extractor.
25+
*/
26+
private predicate overlayXmlExtracted(string file) {
27+
isOverlay() and
28+
exists(@xmllocatable locatable |
29+
not files(locatable, _) and not xmlNs(locatable, _, _, _) and file = getXmlFile(locatable)
30+
)
31+
}
32+
33+
/**
34+
* Holds if the given XML `locatable` should be discarded, because it is part of the overlay base
35+
* and is in a file that was also extracted as part of the overlay database.
36+
*/
37+
overlay[discard_entity]
38+
private predicate discardXmlLocatable(@xmllocatable locatable) {
39+
exists(string file | file = getXmlFileInBase(locatable) |
40+
overlayChangedFiles(file)
41+
or
42+
// The HTML/XML extractor is currently not incremental and may extract more files than those
43+
// included in overlayChangedFiles.
44+
overlayXmlExtracted(file)
45+
)
46+
}

0 commit comments

Comments
 (0)