1
1
/** Provides classes for working with locations and program elements that have locations. */
2
2
3
3
import javascript
4
+ private import internal.Locations
4
5
5
6
/**
6
7
* A location as given by a file, a start line, a start column,
7
8
* an end line, and an end column.
8
9
*
10
+ * This class is restricted to locations created by the extractor.
11
+ *
9
12
* For more information about locations see [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
10
13
*/
11
- class Location extends @location {
14
+ class DbLocation extends TDbLocation {
12
15
/** Gets the file for this location. */
13
- File getFile ( ) { locations_default ( this , result , _, _, _, _) }
16
+ File getFile ( ) { dbLocationInfo ( this , result , _, _, _, _) }
14
17
15
18
/** Gets the 1-based line number (inclusive) where this location starts. */
16
- int getStartLine ( ) { locations_default ( this , _, result , _, _, _) }
19
+ int getStartLine ( ) { dbLocationInfo ( this , _, result , _, _, _) }
17
20
18
21
/** Gets the 1-based column number (inclusive) where this location starts. */
19
- int getStartColumn ( ) { locations_default ( this , _, _, result , _, _) }
22
+ int getStartColumn ( ) { dbLocationInfo ( this , _, _, result , _, _) }
20
23
21
24
/** Gets the 1-based line number (inclusive) where this location ends. */
22
- int getEndLine ( ) { locations_default ( this , _, _, _, result , _) }
25
+ int getEndLine ( ) { dbLocationInfo ( this , _, _, _, result , _) }
23
26
24
27
/** Gets the 1-based column number (inclusive) where this location ends. */
25
- int getEndColumn ( ) { locations_default ( this , _, _, _, _, result ) }
28
+ int getEndColumn ( ) { dbLocationInfo ( this , _, _, _, _, result ) }
26
29
27
30
/** Gets the number of lines covered by this location. */
28
31
int getNumLines ( ) { result = this .getEndLine ( ) - this .getStartLine ( ) + 1 }
29
32
30
33
/** Holds if this location starts before location `that`. */
31
34
pragma [ inline]
32
- predicate startsBefore ( Location that ) {
35
+ predicate startsBefore ( DbLocation that ) {
33
36
exists ( File f , int sl1 , int sc1 , int sl2 , int sc2 |
34
- locations_default ( this , f , sl1 , sc1 , _, _) and
35
- locations_default ( that , f , sl2 , sc2 , _, _)
37
+ dbLocationInfo ( this , f , sl1 , sc1 , _, _) and
38
+ dbLocationInfo ( that , f , sl2 , sc2 , _, _)
36
39
|
37
40
sl1 < sl2
38
41
or
@@ -42,10 +45,10 @@ class Location extends @location {
42
45
43
46
/** Holds if this location ends after location `that`. */
44
47
pragma [ inline]
45
- predicate endsAfter ( Location that ) {
48
+ predicate endsAfter ( DbLocation that ) {
46
49
exists ( File f , int el1 , int ec1 , int el2 , int ec2 |
47
- locations_default ( this , f , _, _, el1 , ec1 ) and
48
- locations_default ( that , f , _, _, el2 , ec2 )
50
+ dbLocationInfo ( this , f , _, _, el1 , ec1 ) and
51
+ dbLocationInfo ( that , f , _, _, el2 , ec2 )
49
52
|
50
53
el1 > el2
51
54
or
@@ -57,10 +60,10 @@ class Location extends @location {
57
60
* Holds if this location contains location `that`, meaning that it starts
58
61
* before and ends after it.
59
62
*/
60
- predicate contains ( Location that ) { this .startsBefore ( that ) and this .endsAfter ( that ) }
63
+ predicate contains ( DbLocation that ) { this .startsBefore ( that ) and this .endsAfter ( that ) }
61
64
62
65
/** Holds if this location is empty. */
63
- predicate isEmpty ( ) { exists ( int l , int c | locations_default ( this , _, l , c , l , c - 1 ) ) }
66
+ predicate isEmpty ( ) { exists ( int l , int c | dbLocationInfo ( this , _, l , c , l , c - 1 ) ) }
64
67
65
68
/** Gets a textual representation of this element. */
66
69
string toString ( ) { result = this .getFile ( ) .getBaseName ( ) + ":" + this .getStartLine ( ) .toString ( ) }
@@ -76,22 +79,21 @@ class Location extends @location {
76
79
string filepath , int startline , int startcolumn , int endline , int endcolumn
77
80
) {
78
81
exists ( File f |
79
- locations_default ( this , f , startline , startcolumn , endline , endcolumn ) and
82
+ dbLocationInfo ( this , f , startline , startcolumn , endline , endcolumn ) and
80
83
filepath = f .getAbsolutePath ( )
81
84
)
82
85
}
83
86
}
84
87
88
+ final class Location = LocationImpl ;
89
+
85
90
/** A program element with a location. */
86
91
class Locatable extends @locatable {
87
92
/** Gets the file this program element comes from. */
88
93
File getFile ( ) { result = this .getLocation ( ) .getFile ( ) }
89
94
90
95
/** Gets this element's location. */
91
- Location getLocation ( ) {
92
- // overridden by subclasses
93
- none ( )
94
- }
96
+ final DbLocation getLocation ( ) { result = getLocatableLocation ( this ) }
95
97
96
98
/**
97
99
* Gets the line on which this element starts.
@@ -142,16 +144,3 @@ class Locatable extends @locatable {
142
144
*/
143
145
string getAPrimaryQlClass ( ) { result = "???" }
144
146
}
145
-
146
- /**
147
- * A `File`, considered as a `Locatable`.
148
- *
149
- * For reasons of backwards compatibility, @file is a subtype of @locatable. This class exists to
150
- * provide an override of `Locatable.getLocation()` for @files, since it would otherwise default
151
- * to `none()`, which is unhelpful.
152
- */
153
- private class FileLocatable extends File , Locatable {
154
- override Location getLocation ( ) { result = File .super .getLocation ( ) }
155
-
156
- override string toString ( ) { result = File .super .toString ( ) }
157
- }
0 commit comments