Skip to content

Commit e4a4c18

Browse files
committed
Go: Implement new data flow interface
1 parent 8d76786 commit e4a4c18

19 files changed

+200
-38
lines changed

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

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

33
import go
4+
private import semmle.go.internal.Locations
45

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

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

go/ql/lib/semmle/go/Files.qll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ class Folder extends Container, Impl::Folder {
5050
class ExtractedOrExternalFile extends Container, Impl::File, Documentable, ExprParent,
5151
GoModExprParent, DeclParent, ScopeNode
5252
{
53-
override Location getLocation() { has_location(this, result) }
54-
5553
/** Gets the number of lines in this file. */
5654
int getNumberOfLines() { numlines(this, result, _, _) }
5755

go/ql/lib/semmle/go/HTML.qll

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ module HTML {
1515
class Element extends Locatable, @xmlelement {
1616
Element() { exists(HtmlFile f | xmlElements(this, _, _, _, f)) }
1717

18-
override Location getLocation() { xmllocations(this, result) }
19-
2018
/**
2119
* Gets the name of this HTML element.
2220
*
@@ -97,8 +95,6 @@ module HTML {
9795
class Attribute extends Locatable, @xmlattribute {
9896
Attribute() { xmlAttrs(this, _, _, _, _, any(HtmlFile f)) }
9997

100-
override Location getLocation() { xmllocations(this, result) }
101-
10298
/**
10399
* Gets the element to which this attribute belongs.
104100
*/
@@ -180,8 +176,6 @@ module HTML {
180176
* Holds if this text node is inside a `CDATA` tag.
181177
*/
182178
predicate isCData() { xmlChars(this, _, _, _, 1, _) }
183-
184-
override Location getLocation() { xmllocations(this, result) }
185179
}
186180

187181
/**
@@ -203,7 +197,5 @@ module HTML {
203197
string getText() { result = this.toString().regexpCapture("(?s)<!--(.*)-->", 1) }
204198

205199
override string toString() { xmlComments(this, result, _, _) }
206-
207-
override Location getLocation() { xmllocations(this, result) }
208200
}
209201
}

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

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

33
import 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 {
1215
/** Gets the file for this location. */
13-
File getFile() { locations_default(this, result, _, _, _, _) }
16+
File getFile() { dbLocationInfo(this, result, _, _, _, _) }
1417

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

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

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

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

2730
/** Gets the number of lines covered by this location. */
2831
int getNumLines() { result = this.getEndLine() - this.getStartLine() + 1 }
@@ -46,19 +49,21 @@ class Location extends @location {
4649
string filepath, int startline, int startcolumn, int endline, int endcolumn
4750
) {
4851
exists(File f |
49-
locations_default(this, f, startline, startcolumn, endline, endcolumn) and
52+
dbLocationInfo(this, f, startline, startcolumn, endline, endcolumn) and
5053
filepath = f.getAbsolutePath()
5154
)
5255
}
5356
}
5457

58+
final class Location = LocationImpl;
59+
5560
/** A program element with a location. */
5661
class Locatable extends @locatable {
5762
/** Gets the file this program element comes from. */
5863
File getFile() { result = this.getLocation().getFile() }
5964

6065
/** Gets this element's location. */
61-
Location getLocation() { has_location(this, result) }
66+
final DbLocation getLocation() { result = getLocatableLocation(this) }
6267

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

go/ql/lib/semmle/go/dataflow/DataFlow.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import go
2424
module DataFlow {
2525
private import semmle.go.dataflow.internal.DataFlowImplSpecific
2626
private import codeql.dataflow.DataFlow
27-
import DataFlowMake<GoDataFlow>
27+
import DataFlowMake<Location, GoDataFlow>
2828
import semmle.go.dataflow.internal.DataFlowImpl1
2929
import Properties
3030
}

go/ql/lib/semmle/go/dataflow/TaintTracking.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ module TaintTracking {
1313
import semmle.go.dataflow.internal.tainttracking1.TaintTrackingParameter::Public
1414
private import semmle.go.dataflow.internal.DataFlowImplSpecific
1515
private import semmle.go.dataflow.internal.TaintTrackingImplSpecific
16+
private import semmle.go.Locations
1617
private import codeql.dataflow.TaintTracking
17-
import TaintFlowMake<GoDataFlow, GoTaintTracking>
18+
import TaintFlowMake<Location, GoDataFlow, GoTaintTracking>
1819
import semmle.go.dataflow.internal.tainttracking1.TaintTrackingImpl
1920
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
private import DataFlowImplSpecific
22
private import codeql.dataflow.internal.DataFlowImpl
3-
import MakeImpl<GoDataFlow>
3+
private import semmle.go.Locations
4+
import MakeImpl<Location, GoDataFlow>
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
private import DataFlowImplSpecific
22
private import codeql.dataflow.internal.DataFlowImplCommon
3-
import MakeImplCommon<GoDataFlow>
3+
private import semmle.go.Locations
4+
import MakeImplCommon<Location, GoDataFlow>

go/ql/lib/semmle/go/dataflow/internal/DataFlowImplConsistency.qll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ private import go
77
private import DataFlowImplSpecific
88
private import TaintTrackingImplSpecific
99
private import codeql.dataflow.internal.DataFlowImplConsistency
10+
private import semmle.go.dataflow.internal.DataFlowNodes
1011

11-
private module Input implements InputSig<GoDataFlow> { }
12+
private module Input implements InputSig<Location, GoDataFlow> { }
1213

13-
module Consistency = MakeConsistency<GoDataFlow, GoTaintTracking, Input>;
14+
module Consistency = MakeConsistency<Location, GoDataFlow, GoTaintTracking, Input>;

go/ql/lib/semmle/go/dataflow/internal/DataFlowImplSpecific.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44

55
private import codeql.dataflow.DataFlow
6+
private import semmle.go.Locations
67

78
module Private {
89
import DataFlowPrivate
@@ -13,7 +14,7 @@ module Public {
1314
import DataFlowUtil
1415
}
1516

16-
module GoDataFlow implements InputSig {
17+
module GoDataFlow implements InputSig<Location> {
1718
import Private
1819
import Public
1920

0 commit comments

Comments
 (0)