33import go
44private import internal.Locations
55
6+ private module DbLocationInput implements LocationClassInputSig {
7+ class Base = TDbLocation ;
8+
9+ predicate locationInfo (
10+ Base b , string filepath , int startline , int startcolumn , int endline , int endcolumn
11+ ) {
12+ exists ( File f |
13+ dbLocationInfo ( b , f , startline , startcolumn , endline , endcolumn ) and
14+ filepath = f .getAbsolutePath ( )
15+ )
16+ }
17+
18+ File getFile ( Base b ) { dbLocationInfo ( b , result , _, _, _, _) }
19+ }
20+
621/**
722 * A location as given by a file, a start line, a start column,
823 * an end line, and an end column.
@@ -11,51 +26,63 @@ private import internal.Locations
1126 *
1227 * For more information about locations see [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
1328 */
14- class DbLocation extends TDbLocation {
15- /** Gets the file for this location. */
16- File getFile ( ) { dbLocationInfo ( this , result , _, _, _, _) }
29+ class DbLocation = LocationClass< DbLocationInput > :: Location ;
1730
18- /** Gets the 1-based line number (inclusive) where this location starts. */
19- int getStartLine ( ) { dbLocationInfo ( this , _ , result , _ , _ , _ ) }
31+ private module DbOrBasicBlockLocationInput implements LocationClassInputSig {
32+ class Base = TDbLocation or TBasicBlockLocation ;
2033
21- /** Gets the 1-based column number (inclusive) where this location starts. */
22- int getStartColumn ( ) { dbLocationInfo ( this , _, _, result , _, _) }
34+ predicate locationInfo (
35+ Base b , string filepath , int startline , int startcolumn , int endline , int endcolumn
36+ ) {
37+ DbLocationInput:: locationInfo ( b , filepath , startline , startcolumn , endline , endcolumn )
38+ or
39+ basicBlockLocationInfo ( b , filepath , startline , startcolumn , endline , endcolumn )
40+ }
2341
24- /** Gets the 1-based line number (inclusive) where this location ends. */
25- int getEndLine ( ) { dbLocationInfo ( this , _, _, _, result , _) }
42+ File getFile ( Base b ) {
43+ result = DbLocationInput:: getFile ( b )
44+ or
45+ basicBlockLocationInfo ( b , result .getAbsolutePath ( ) , _, _, _, _)
46+ }
47+ }
2648
27- /** Gets the 1-based column number (inclusive) where this location ends. */
28- int getEndColumn ( ) { dbLocationInfo ( this , _, _, _, _, result ) }
49+ /**
50+ * A location as given by a file, a start line, a start column,
51+ * an end line, and an end column.
52+ *
53+ * This class is restricted to locations created by the extractor or
54+ * synthesized for basic blocks.
55+ *
56+ * For more information about locations see [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
57+ */
58+ class DbOrBasicBlockLocation = LocationClass< DbOrBasicBlockLocationInput > :: Location ;
2959
30- /** Gets the number of lines covered by this location. */
31- int getNumLines ( ) { result = this . getEndLine ( ) - this . getStartLine ( ) + 1 }
60+ private module LocationInput implements LocationClassInputSig {
61+ class Base = TLocation ;
3262
33- /** Gets a textual representation of this element. */
34- string toString ( ) {
35- exists ( string filepath , int startline , int startcolumn , int endline , int endcolumn |
36- this .hasLocationInfo ( filepath , startline , startcolumn , endline , endcolumn ) and
37- result = filepath + "@" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
38- )
63+ predicate locationInfo (
64+ Base b , string filepath , int startline , int startcolumn , int endline , int endcolumn
65+ ) {
66+ DbOrBasicBlockLocationInput:: locationInfo ( b , filepath , startline , startcolumn , endline ,
67+ endcolumn )
68+ or
69+ dataFlowNodeLocationInfo ( b , filepath , startline , startcolumn , endline , endcolumn )
3970 }
4071
41- /**
42- * Holds if this element is at the specified location.
43- * The location spans column `startcolumn` of line `startline` to
44- * column `endcolumn` of line `endline` in file `filepath`.
45- * For more information, see
46- * [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
47- */
48- predicate hasLocationInfo (
49- string filepath , int startline , int startcolumn , int endline , int endcolumn
50- ) {
51- exists ( File f |
52- dbLocationInfo ( this , f , startline , startcolumn , endline , endcolumn ) and
53- filepath = f .getAbsolutePath ( )
54- )
72+ File getFile ( Base b ) {
73+ result = DbOrBasicBlockLocationInput:: getFile ( b )
74+ or
75+ dataFlowNodeLocationInfo ( b , result .getAbsolutePath ( ) , _, _, _, _)
5576 }
5677}
5778
58- final class Location = LocationImpl ;
79+ /**
80+ * A location as given by a file, a start line, a start column,
81+ * an end line, and an end column.
82+ *
83+ * For more information about locations see [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
84+ */
85+ class Location = LocationClass< LocationInput > :: Location ;
5986
6087/** A program element with a location. */
6188class Locatable extends @locatable {
0 commit comments