mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Factor XML discard predicates into OverlayXml.qll
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
* Defines entity discard predicates for C# overlay analysis.
|
||||
*/
|
||||
|
||||
private import OverlayXml
|
||||
|
||||
/**
|
||||
* Holds always for the overlay variant and never for the base variant.
|
||||
* This local predicate is used to define local predicates that behave
|
||||
@@ -110,36 +112,6 @@ private predicate discardLocation(@location_default loc) {
|
||||
exists(string path | discardableLocation(loc, path) | overlayChangedFiles(path))
|
||||
}
|
||||
|
||||
/**
|
||||
* A class of Xml locatables that can be discarded from the base.
|
||||
*/
|
||||
overlay[local]
|
||||
private class DiscardableXmlEntity extends DiscardableEntityBase instanceof @xmllocatable {
|
||||
/** Gets the path to the file in which this element occurs. */
|
||||
override string getFilePath() {
|
||||
exists(@location_default loc | result = getLocationFilePath(loc) | xmllocations(this, loc))
|
||||
}
|
||||
}
|
||||
|
||||
overlay[local]
|
||||
private predicate overlayXmlExtracted(string file) {
|
||||
exists(DiscardableXmlEntity dxe |
|
||||
dxe.existsInOverlay() and
|
||||
file = dxe.getFilePath() and
|
||||
not files(dxe, _) and
|
||||
not xmlNs(dxe, _, _, _)
|
||||
)
|
||||
}
|
||||
|
||||
overlay[discard_entity]
|
||||
private predicate discardXmlEntity(@xmllocatable xml) {
|
||||
overlayChangedFiles(xml.(DiscardableXmlEntity).getFilePath())
|
||||
or
|
||||
// The XML extractor is not incremental and may extract more
|
||||
// XML files than those included in overlayChangedFiles.
|
||||
overlayXmlExtracted(xml.(DiscardableXmlEntity).getFilePath())
|
||||
}
|
||||
|
||||
overlay[local]
|
||||
private class DiscardableAspEntity extends DiscardableEntityBase instanceof @asp_element {
|
||||
/** Gets the path to the file in which this element occurs. */
|
||||
|
||||
45
csharp/ql/lib/semmle/code/csharp/internal/OverlayXml.qll
Normal file
45
csharp/ql/lib/semmle/code/csharp/internal/OverlayXml.qll
Normal file
@@ -0,0 +1,45 @@
|
||||
overlay[local]
|
||||
module;
|
||||
|
||||
/**
|
||||
* 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") }
|
||||
|
||||
private @file getXmlFile(@xmllocatable locatable) {
|
||||
exists(@location_default location | xmllocations(locatable, location) |
|
||||
locations_default(location, result, _, _, _, _)
|
||||
)
|
||||
}
|
||||
|
||||
private @file getXmlFileInBase(@xmllocatable locatable) {
|
||||
not isOverlay() and
|
||||
result = getXmlFile(locatable)
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if the given `file` was extracted as part of the overlay and was extracted by the HTML/XML
|
||||
* extractor.
|
||||
*/
|
||||
private predicate overlayXmlExtracted(@file file) {
|
||||
isOverlay() and
|
||||
exists(@xmllocatable locatable |
|
||||
not files(locatable, _) and not xmlNs(locatable, _, _, _) and file = getXmlFile(locatable)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if the given XML `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 discardXmlLocatable(@xmllocatable locatable) {
|
||||
exists(@file file | file = getXmlFileInBase(locatable) |
|
||||
exists(string path | files(file, path) | overlayChangedFiles(path))
|
||||
or
|
||||
// The HTML/XML extractor is currently not incremental and may extract more files than those
|
||||
// included in overlayChangedFiles.
|
||||
overlayXmlExtracted(file)
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user