@@ -3,10 +3,12 @@ private import codeql.rust.elements.internal.LocatableImpl::Impl as LocatableImp
33private import codeql.rust.elements.Locatable
44private import codeql.rust.elements.Format
55private import codeql.rust.elements.FormatArgument
6+ private import codeql.rust.internal.CachedStages
67
78module LocationImpl {
9+ cached
810 newtype TLocation =
9- TLocationDefault ( @location_default location ) or
11+ TLocationDefault ( @location_default location ) { Stages :: AstStage :: ref ( ) } or
1012 TLocationSynth ( File file , int beginLine , int beginColumn , int endLine , int endColumn ) {
1113 not locations_default ( _, file , beginLine , beginColumn , endLine , endColumn ) and
1214 any ( LocatableImpl:: SynthLocatable l )
@@ -55,10 +57,26 @@ module LocationImpl {
5557 * For more information, see
5658 * [Providing locations in CodeQL queries](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
5759 */
58- abstract predicate hasLocationInfo (
59- string filepath , int startline , int startcolumn , int endline , int endcolumn
60+ abstract predicate hasLocationFileInfo (
61+ File file , int startline , int startcolumn , int endline , int endcolumn
6062 ) ;
6163
64+ /**
65+ * Holds if this element is at the specified location.
66+ * The location spans column `startcolumn` of line `startline` to
67+ * column `endcolumn` of line `endline` in file `filepath`.
68+ * For more information, see
69+ * [Providing locations in CodeQL queries](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
70+ */
71+ final predicate hasLocationInfo (
72+ string filepath , int startline , int startcolumn , int endline , int endcolumn
73+ ) {
74+ exists ( File file |
75+ this .hasLocationFileInfo ( file , startline , startcolumn , endline , endcolumn ) and
76+ filepath = file .getAbsolutePath ( )
77+ )
78+ }
79+
6280 /** Holds if this location starts strictly before the specified location. */
6381 pragma [ inline]
6482 predicate strictlyBefore ( Location other ) {
@@ -68,18 +86,15 @@ module LocationImpl {
6886 }
6987 }
7088
71- private class LocationDefault extends Location , TLocationDefault {
89+ class LocationDefault extends Location , TLocationDefault {
7290 @location_default self ;
7391
7492 LocationDefault ( ) { this = TLocationDefault ( self ) }
7593
76- override predicate hasLocationInfo (
77- string filepath , int startline , int startcolumn , int endline , int endcolumn
94+ override predicate hasLocationFileInfo (
95+ File file , int startline , int startcolumn , int endline , int endcolumn
7896 ) {
79- exists ( File f |
80- locations_default ( self , f , startline , startcolumn , endline , endcolumn ) and
81- filepath = f .getAbsolutePath ( )
82- )
97+ locations_default ( self , file , startline , startcolumn , endline , endcolumn )
8398 }
8499 }
85100
@@ -88,13 +103,11 @@ module LocationImpl {
88103 EmptyLocation ( ) { empty_location ( self ) }
89104 }
90105
91- private class LocationSynth extends Location , TLocationSynth {
92- override predicate hasLocationInfo (
93- string filepath , int startline , int startcolumn , int endline , int endcolumn
106+ class LocationSynth extends Location , TLocationSynth {
107+ override predicate hasLocationFileInfo (
108+ File file , int startline , int startcolumn , int endline , int endcolumn
94109 ) {
95- this =
96- TLocationSynth ( any ( File f | f .getAbsolutePath ( ) = filepath ) , startline , startcolumn ,
97- endline , endcolumn )
110+ this = TLocationSynth ( file , startline , startcolumn , endline , endcolumn )
98111 }
99112 }
100113}
0 commit comments