Skip to content

Commit 4f234c3

Browse files
committed
C#: Add the same strategy in as in Java for XML element discarding.
1 parent c44b747 commit 4f234c3

File tree

1 file changed

+47
-11
lines changed

1 file changed

+47
-11
lines changed

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

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,39 @@ private string getLocationFilePath(@location_default loc) {
1515
exists(@file file | locations_default(loc, file, _, _, _, _) | files(file, result))
1616
}
1717

18+
overlay[local]
19+
private class DiscardableEntityBase extends @locatable {
20+
/** Gets the path to the file in which this element occurs. */
21+
abstract string getFilePath();
22+
23+
/** Holds if this element exists in the base variant. */
24+
predicate existsInBase() { not isOverlay() }
25+
26+
/** Holds if this element exists in the overlay variant. */
27+
predicate existsInOverlay() { isOverlay() }
28+
29+
/** Gets a textual representation of this discardable element. */
30+
string toString() { none() }
31+
}
32+
33+
/**
34+
* A class of Xml locatables that can be discarded from the base.
35+
*/
36+
overlay[local]
37+
private class DiscardableXmlEntity extends DiscardableEntityBase instanceof @xmllocatable {
38+
/** Gets the path to the file in which this element occurs. */
39+
override string getFilePath() {
40+
exists(@location_default loc | result = getLocationFilePath(loc) | xmllocations(this, loc))
41+
}
42+
}
43+
1844
/**
1945
* A class of elements that can be discarded from the base.
2046
*/
2147
overlay[local]
22-
private class DiscardableEntity extends @locatable {
48+
private class DiscardableEntity extends DiscardableEntityBase {
2349
/** Gets the path to the file in which this element occurs. */
24-
string getFilePath() {
50+
override string getFilePath() {
2551
exists(@location_default loc | result = getLocationFilePath(loc) |
2652
expr_location(this, loc) or
2753
stmt_location(this, loc) or
@@ -50,15 +76,6 @@ private class DiscardableEntity extends @locatable {
5076
extractor_messages(this, _, _, _, _, loc, _)
5177
)
5278
}
53-
54-
/** Holds if this element exists in the base variant. */
55-
predicate existsInBase() { not isOverlay() }
56-
57-
/** Holds if this element exists in the overlay variant. */
58-
predicate existsInOverlay() { isOverlay() }
59-
60-
/** Gets a textual representation of this discardable element. */
61-
string toString() { none() }
6279
}
6380

6481
/**
@@ -103,3 +120,22 @@ overlay[discard_entity]
103120
private predicate discardLocation(@location_default loc) {
104121
exists(string path | discardableLocation(loc, path) | overlayChangedFiles(path))
105122
}
123+
124+
overlay[local]
125+
private predicate overlayXmlExtracted(string file) {
126+
exists(DiscardableXmlEntity dxe |
127+
dxe.existsInOverlay() and
128+
file = dxe.getFilePath() and
129+
not files(dxe, _) and
130+
not xmlNs(dxe, _, _, _)
131+
)
132+
}
133+
134+
overlay[discard_entity]
135+
private predicate discardXmlEntity(@xmllocatable xml) {
136+
overlayChangedFiles(xml.(DiscardableXmlEntity).getFilePath())
137+
or
138+
// The XML extractor is not incremental and may extract more
139+
// XML files than those included in overlayChangedFiles.
140+
overlayXmlExtracted(xml.(DiscardableXmlEntity).getFilePath())
141+
}

0 commit comments

Comments
 (0)