Skip to content

Commit fe212db

Browse files
committed
Go: Implement new data flow interface
1 parent 82fcca1 commit fe212db

File tree

16 files changed

+179
-34
lines changed

16 files changed

+179
-34
lines changed

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: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,35 @@
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 {
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. */
5665
class 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() }

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

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,14 @@ module Public {
157157
endcolumn = 0
158158
}
159159

160+
/** Gets the location of this node. */
161+
Location getLocation() {
162+
exists(string filepath, int startline, int startcolumn, int endline, int endcolumn |
163+
this.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) and
164+
result.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
165+
)
166+
}
167+
160168
/** Gets the file in which this node appears. */
161169
File getFile() { this.hasLocationInfo(result.getAbsolutePath(), _, _, _, _) }
162170

0 commit comments

Comments
 (0)