Skip to content

Commit ca0b363

Browse files
committed
Replace DbLocation with Location
1 parent f095182 commit ca0b363

File tree

5 files changed

+16
-172
lines changed

5 files changed

+16
-172
lines changed

go/ql/lib/semmle/go/DiagnosticsReporting.qll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/** Provides classes for working with errors and warnings recorded during extraction. */
22

33
import go
4-
private import semmle.go.internal.Locations
54

65
/** Gets the SARIF severity level that indicates an error. */
76
private int getErrorSeverity() { result = 2 }
@@ -30,7 +29,9 @@ private class Diagnostic extends @diagnostic {
3029
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
3130
*/
3231
predicate hasLocationInfo(string path, int sl, int sc, int el, int ec) {
33-
getDiagnosticLocation(this).hasLocationInfo(path, sl, sc, el, ec)
32+
exists(Location loc | diagnostics(this, _, _, _, _, loc) |
33+
loc.hasLocationInfo(path, sl, sc, el, ec)
34+
)
3435
}
3536

3637
string toString() { result = this.getMessage() }

go/ql/lib/semmle/go/Locations.qll

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/** Provides classes for working with locations and program elements that have locations. */
22

33
import go
4-
private import internal.Locations
54

65
/**
76
* A location as given by a file, a start line, a start column,
@@ -11,21 +10,21 @@ private import internal.Locations
1110
*
1211
* For more information about locations see [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
1312
*/
14-
class DbLocation extends TDbLocation {
13+
class Location extends @location {
1514
/** Gets the file for this location. */
16-
File getFile() { dbLocationInfo(this, result, _, _, _, _) }
15+
File getFile() { locations_default(this, result, _, _, _, _) }
1716

1817
/** Gets the 1-based line number (inclusive) where this location starts. */
19-
int getStartLine() { dbLocationInfo(this, _, result, _, _, _) }
18+
int getStartLine() { locations_default(this, _, result, _, _, _) }
2019

2120
/** Gets the 1-based column number (inclusive) where this location starts. */
22-
int getStartColumn() { dbLocationInfo(this, _, _, result, _, _) }
21+
int getStartColumn() { locations_default(this, _, _, result, _, _) }
2322

2423
/** Gets the 1-based line number (inclusive) where this location ends. */
25-
int getEndLine() { dbLocationInfo(this, _, _, _, result, _) }
24+
int getEndLine() { locations_default(this, _, _, _, result, _) }
2625

2726
/** Gets the 1-based column number (inclusive) where this location ends. */
28-
int getEndColumn() { dbLocationInfo(this, _, _, _, _, result) }
27+
int getEndColumn() { locations_default(this, _, _, _, _, result) }
2928

3029
/** Gets the number of lines covered by this location. */
3130
int getNumLines() { result = this.getEndLine() - this.getStartLine() + 1 }
@@ -48,22 +47,22 @@ class DbLocation extends TDbLocation {
4847
predicate hasLocationInfo(
4948
string filepath, int startline, int startcolumn, int endline, int endcolumn
5049
) {
51-
exists(File f |
52-
dbLocationInfo(this, f, startline, startcolumn, endline, endcolumn) and
50+
exists(File f | locations_default(this, f, startline, startcolumn, endline, endcolumn) |
5351
filepath = f.getAbsolutePath()
5452
)
5553
}
5654
}
5755

58-
final class Location = LocationImpl;
59-
6056
/** A program element with a location. */
6157
class Locatable extends @locatable {
6258
/** Gets the file this program element comes from. */
6359
File getFile() { result = this.getLocation().getFile() }
6460

6561
/** Gets this element's location. */
66-
final DbLocation getLocation() { result = getLocatableLocation(this) }
62+
final Location getLocation() {
63+
has_location(this, result) or
64+
xmllocations(this, result)
65+
}
6766

6867
/** Gets the number of lines covered by this element. */
6968
int getNumLines() { result = this.getLocation().getNumLines() }

go/ql/lib/semmle/go/internal/Locations.qll

Lines changed: 0 additions & 150 deletions
This file was deleted.

go/ql/test/extractor-tests/diagnostics/Diagnostics.ql

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import go
2-
private import semmle.go.internal.Locations
32

43
bindingset[path]
54
string baseName(string path) { result = path.regexpCapture(".*(/|\\\\)([^/\\\\]+)(/|\\\\)?$", 2) }
@@ -31,12 +30,7 @@ class Diagnostic extends @diagnostic {
3130
diagnostic_for(this, c, fileNum, idx)
3231
}
3332

34-
DbLocation getLocation() {
35-
exists(@location loc |
36-
diagnostics(this, _, _, _, _, loc) and
37-
result = TDbLocation(loc)
38-
)
39-
}
33+
Location getLocation() { diagnostics(this, _, _, _, _, result) }
4034

4135
// string getTag() {
4236
// diagnostics(this, _, result, _, _, _)

go/ql/test/library-tests/semmle/go/Types/Aliases.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ int countDecls(Entity e) { result = count(Ident decl | decl = e.getDeclaration()
55
query predicate entities(string fp, Entity e, int c, Type ty) {
66
c = countDecls(e) and
77
ty = e.getType() and
8-
exists(DbLocation loc |
8+
exists(Location loc |
99
loc = e.getDeclaration().getLocation() and
1010
fp = loc.getFile().getBaseName() and
1111
fp = "aliases.go"

0 commit comments

Comments
 (0)