Rust: add Locatable::hasLocationInfo

This commit is contained in:
Arthur Baars
2024-10-17 17:54:08 +02:00
parent f213a2d640
commit 1b7b24ecb8
2 changed files with 18 additions and 14 deletions

View File

@@ -25,14 +25,7 @@ module Impl {
)
}
/**
* Holds if this element is at the specified location.
* The location spans column `startcolumn` of line `startline` to
* column `endcolumn` of line `endline` in file `filepath`.
* For more information, see
* [Providing locations in CodeQL queries](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
*/
predicate hasLocationInfo(
override predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
argument.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)

View File

@@ -19,15 +19,26 @@ module Impl {
final Location getLocation() {
exists(Raw::Locatable raw |
raw = Synth::convertLocatableToRaw(this) and
(
locatable_locations(raw, result)
or
not exists(Location loc | locatable_locations(raw, loc)) and
result instanceof EmptyLocation
)
locatable_locations(raw, result)
)
}
/**
* Holds if this element is at the specified location.
* The location spans column `startcolumn` of line `startline` to
* column `endcolumn` of line `endline` in file `filepath`.
* For more information, see
* [Providing locations in CodeQL queries](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
*/
predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
or
not exists(this.getLocation()) and
any(EmptyLocation e).hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
}
/**
* Gets the primary file where this element occurs.
*/