1
1
/** Provides classes for working with locations. */
2
2
3
3
import files.FileSystem
4
+ import codeql.actions.Ast
4
5
5
6
bindingset [ loc]
6
7
pragma [ inline_late]
@@ -11,30 +12,57 @@ private string locationToString(Location loc) {
11
12
)
12
13
}
13
14
15
+ newtype TLocation =
16
+ TBaseLocation ( string filepath , int startline , int startcolumn , int endline , int endcolumn ) {
17
+ exists ( File file |
18
+ file .getAbsolutePath ( ) = filepath and
19
+ locations_default ( _, file , startline , startcolumn , endline , endcolumn )
20
+ )
21
+ or
22
+ exists ( ExpressionNode e |
23
+ e .hasLocationInfo ( filepath , startline , startcolumn , endline , endcolumn )
24
+ )
25
+ or
26
+ filepath = "" and startline = 0 and startcolumn = 0 and endline = 0 and endcolumn = 0
27
+ }
28
+
14
29
/**
15
30
* A location as given by a file, a start line, a start column,
16
31
* an end line, and an end column.
17
32
*
18
33
* For more information about locations see [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
19
34
*/
20
- class Location extends @location_default {
35
+ class Location extends TLocation , TBaseLocation {
36
+ string filepath ;
37
+ int startline ;
38
+ int startcolumn ;
39
+ int endline ;
40
+ int endcolumn ;
41
+
42
+ Location ( ) { this = TBaseLocation ( filepath , startline , startcolumn , endline , endcolumn ) }
43
+
21
44
/** Gets the file for this location. */
22
- File getFile ( ) { locations_default ( this , result , _, _, _, _) }
45
+ File getFile ( ) {
46
+ exists ( File file |
47
+ file .getAbsolutePath ( ) = filepath and
48
+ result = file
49
+ )
50
+ }
23
51
24
52
/** Gets the 1-based line number (inclusive) where this location starts. */
25
- int getStartLine ( ) { locations_default ( this , _ , result , _ , _ , _ ) }
53
+ int getStartLine ( ) { result = startline }
26
54
27
55
/** Gets the 1-based column number (inclusive) where this location starts. */
28
- int getStartColumn ( ) { locations_default ( this , _ , _ , result , _ , _ ) }
56
+ int getStartColumn ( ) { result = startcolumn }
29
57
30
- /** Gets the 1-based line number (inclusive) where this location ends. */
31
- int getEndLine ( ) { locations_default ( this , _ , _ , _ , result , _ ) }
58
+ /** Gets the 1-based line number (inclusive) where this.getLocationDefault() location ends. */
59
+ int getEndLine ( ) { result = endline }
32
60
33
- /** Gets the 1-based column number (inclusive) where this location ends. */
34
- int getEndColumn ( ) { locations_default ( this , _ , _ , _ , _ , result ) }
61
+ /** Gets the 1-based column number (inclusive) where this.getLocationDefault() location ends. */
62
+ int getEndColumn ( ) { result = endcolumn }
35
63
36
64
/** Gets the number of lines covered by this location. */
37
- int getNumLines ( ) { result = this . getEndLine ( ) - this . getStartLine ( ) + 1 }
65
+ int getNumLines ( ) { result = endline - startline + 1 }
38
66
39
67
/** Gets a textual representation of this element. */
40
68
pragma [ inline]
@@ -47,13 +75,12 @@ class Location extends @location_default {
47
75
* For more information, see
48
76
* [Providing locations in CodeQL queries](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
49
77
*/
50
- predicate hasLocationInfo (
51
- string filepath , int startline , int startcolumn , int endline , int endcolumn
52
- ) {
53
- exists ( File f |
54
- locations_default ( this , f , startline , startcolumn , endline , endcolumn ) and
55
- filepath = f .getAbsolutePath ( )
56
- )
78
+ predicate hasLocationInfo ( string p , int sl , int sc , int el , int ec ) {
79
+ p = filepath and
80
+ sl = startline and
81
+ sc = startcolumn and
82
+ el = endline and
83
+ ec = endcolumn
57
84
}
58
85
59
86
/** Holds if this location starts strictly before the specified location. */
0 commit comments