Skip to content

Commit 90fbacc

Browse files
committed
Java/Shared: Use getLocation instead of hasLocationInfo.
1 parent 2fd57f6 commit 90fbacc

File tree

3 files changed

+13
-24
lines changed

3 files changed

+13
-24
lines changed

java/ql/lib/semmle/code/java/dataflow/TypeFlow.qll

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ private import semmle.code.java.dataflow.internal.BaseSSA
1414
private import semmle.code.java.controlflow.Guards
1515
private import codeql.typeflow.TypeFlow
1616

17-
private module Input implements TypeFlowInput {
17+
private module Input implements TypeFlowInput<J::Location> {
1818
private newtype TTypeFlowNode =
1919
TField(Field f) { not f.getType() instanceof PrimitiveType } or
2020
TSsa(BaseSsaVariable ssa) { not ssa.getSourceVariable().getType() instanceof PrimitiveType } or
@@ -38,12 +38,6 @@ private module Input implements TypeFlowInput {
3838
result = this.asMethod().toString()
3939
}
4040

41-
predicate hasLocationInfo(
42-
string filepath, int startline, int startcolumn, int endline, int endcolumn
43-
) {
44-
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
45-
}
46-
4741
Location getLocation() {
4842
result = this.asField().getLocation() or
4943
result = this.asSsa().getLocation() or
@@ -164,7 +158,7 @@ private module Input implements TypeFlowInput {
164158
*/
165159
pragma[nomagic]
166160
private predicate upcastCand(TypeFlowNode n, RefType t1, RefType t1e, RefType t2, RefType t2e) {
167-
exists(TypeFlowNode next | step(n, next) or Make<Input>::joinStep(n, next) |
161+
exists(TypeFlowNode next | step(n, next) or Make<J::Location, Input>::joinStep(n, next) |
168162
n.getType() = t1 and
169163
next.getType() = t2 and
170164
t1.getErasure() = t1e and
@@ -356,7 +350,7 @@ private module Input implements TypeFlowInput {
356350

357351
cached
358352
private module TypeFlowBounds {
359-
private module TypeFlow = Make<Input>;
353+
private module TypeFlow = Make<J::Location, Input>;
360354

361355
/**
362356
* Holds if the runtime type of `f` is bounded by `t` and if this bound is

shared/typeflow/codeql/typeflow/TypeFlow.qll

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
* explicit or implicit cast that lost type information.
99
*/
1010

11+
private import codeql.util.Location
12+
1113
/** Provides the input specification. */
12-
signature module TypeFlowInput {
14+
signature module TypeFlowInput<LocationSig Location> {
1315
/**
1416
* A node for which type information is available. For example, expressions
1517
* and method declarations.
@@ -21,16 +23,8 @@ signature module TypeFlowInput {
2123
/** Gets the type of this node. */
2224
Type getType();
2325

24-
/**
25-
* Holds if this element is at the specified location.
26-
* The location spans column `startcolumn` of line `startline` to
27-
* column `endcolumn` of line `endline` in file `filepath`.
28-
* For more information, see
29-
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
30-
*/
31-
predicate hasLocationInfo(
32-
string filepath, int startline, int startcolumn, int endline, int endcolumn
33-
);
26+
/** Gets the location of this node. */
27+
Location getLocation();
3428
}
3529

3630
/**
@@ -112,6 +106,6 @@ private import internal.TypeFlowImpl as Impl
112106
/**
113107
* Provides an implementation of type-flow using input `I`.
114108
*/
115-
module Make<TypeFlowInput I> {
116-
import Impl::TypeFlow<I>
109+
module Make<LocationSig Location, TypeFlowInput<Location> I> {
110+
import Impl::TypeFlow<Location, I>
117111
}

shared/typeflow/codeql/typeflow/internal/TypeFlowImpl.qll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
private import codeql.typeflow.TypeFlow
2+
private import codeql.util.Location
23
private import codeql.util.Unit
34

4-
module TypeFlow<TypeFlowInput I> {
5+
module TypeFlow<LocationSig Location, TypeFlowInput<Location> I> {
56
private import I
67

78
/**
@@ -56,7 +57,7 @@ module TypeFlow<TypeFlowInput I> {
5657
n1 =
5758
rank[r](TypeFlowNode n, int startline, int startcolumn |
5859
edge(n, n2) and
59-
n.hasLocationInfo(_, startline, startcolumn, _, _)
60+
n.getLocation().hasLocationInfo(_, startline, startcolumn, _, _)
6061
|
6162
n order by startline, startcolumn
6263
)

0 commit comments

Comments
 (0)