11/** Provides classes for working with locations and program elements that have locations. */
22
33import go
4+ private import internal.Locations
45
56/**
67 * A location as given by a file, a start line, a start column,
78 * an end line, and an end column.
89 *
10+ * This class is restricted to locations created by the extractor.
11+ *
912 * For more information about locations see [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
1013 */
11- class Location extends @location {
14+ class DbLocation extends TDbLocation {
15+ private @location loc ;
16+
17+ DbLocation ( ) { this = TDbLocation ( loc ) }
18+
1219 /** Gets the file for this location. */
13- File getFile ( ) { locations_default ( this , result , _, _, _, _) }
20+ File getFile ( ) { locations_default ( loc , result , _, _, _, _) }
1421
1522 /** Gets the 1-based line number (inclusive) where this location starts. */
16- int getStartLine ( ) { locations_default ( this , _, result , _, _, _) }
23+ int getStartLine ( ) { locations_default ( loc , _, result , _, _, _) }
1724
1825 /** Gets the 1-based column number (inclusive) where this location starts. */
19- int getStartColumn ( ) { locations_default ( this , _, _, result , _, _) }
26+ int getStartColumn ( ) { locations_default ( loc , _, _, result , _, _) }
2027
2128 /** Gets the 1-based line number (inclusive) where this location ends. */
22- int getEndLine ( ) { locations_default ( this , _, _, _, result , _) }
29+ int getEndLine ( ) { locations_default ( loc , _, _, _, result , _) }
2330
2431 /** Gets the 1-based column number (inclusive) where this location ends. */
25- int getEndColumn ( ) { locations_default ( this , _, _, _, _, result ) }
32+ int getEndColumn ( ) { locations_default ( loc , _, _, _, _, result ) }
2633
2734 /** Gets the number of lines covered by this location. */
2835 int getNumLines ( ) { result = this .getEndLine ( ) - this .getStartLine ( ) + 1 }
@@ -46,19 +53,28 @@ class Location extends @location {
4653 string filepath , int startline , int startcolumn , int endline , int endcolumn
4754 ) {
4855 exists ( File f |
49- locations_default ( this , f , startline , startcolumn , endline , endcolumn ) and
56+ locations_default ( loc , f , startline , startcolumn , endline , endcolumn ) and
5057 filepath = f .getAbsolutePath ( )
5158 )
5259 }
5360}
5461
62+ final class Location = LocationImpl ;
63+
5564/** A program element with a location. */
5665class Locatable extends @locatable {
5766 /** Gets the file this program element comes from. */
5867 File getFile ( ) { result = this .getLocation ( ) .getFile ( ) }
5968
6069 /** Gets this element's location. */
61- Location getLocation ( ) { has_location ( this , result ) }
70+ final DbLocation getLocation ( ) {
71+ exists ( @location loc |
72+ has_location ( this , loc ) or
73+ xmllocations ( this , loc )
74+ |
75+ result = TDbLocation ( loc )
76+ )
77+ }
6278
6379 /** Gets the number of lines covered by this element. */
6480 int getNumLines ( ) { result = this .getLocation ( ) .getNumLines ( ) }
0 commit comments