Skip to content

Commit 2b4e3a7

Browse files
committed
Dataflow: Refactor the getEnclosingCallable and ParameterNode interface.
1 parent beb0902 commit 2b4e3a7

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

java/ql/lib/semmle/code/java/dataflow/internal/DataFlowImplCommon.qll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ private module Cached {
251251
predicate forceCachingInSameStage() { any() }
252252

253253
cached
254-
predicate nodeEnclosingCallable(Node n, DataFlowCallable c) { c = n.getEnclosingCallable() }
254+
predicate nodeEnclosingCallable(Node n, DataFlowCallable c) { c = nodeGetEnclosingCallable(n) }
255255

256256
cached
257257
predicate callEnclosingCallable(DataFlowCall call, DataFlowCallable c) {
@@ -316,9 +316,7 @@ private module Cached {
316316
}
317317

318318
cached
319-
predicate parameterNode(Node n, DataFlowCallable c, int i) {
320-
n.(ParameterNode).isParameterOf(c, i)
321-
}
319+
predicate parameterNode(Node p, DataFlowCallable c, int pos) { isParameterNode(p, c, pos) }
322320

323321
cached
324322
predicate argumentNode(Node n, DataFlowCall call, int pos) {

java/ql/lib/semmle/code/java/dataflow/internal/DataFlowImplConsistency.qll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module Consistency {
3131
query predicate uniqueEnclosingCallable(Node n, string msg) {
3232
exists(int c |
3333
n instanceof RelevantNode and
34-
c = count(n.getEnclosingCallable()) and
34+
c = count(nodeGetEnclosingCallable(n)) and
3535
c != 1 and
3636
msg = "Node should have one enclosing callable but has " + c + "."
3737
)
@@ -85,13 +85,13 @@ module Consistency {
8585
}
8686

8787
query predicate parameterCallable(ParameterNode p, string msg) {
88-
exists(DataFlowCallable c | p.isParameterOf(c, _) and c != p.getEnclosingCallable()) and
88+
exists(DataFlowCallable c | isParameterNode(p, c, _) and c != nodeGetEnclosingCallable(p)) and
8989
msg = "Callable mismatch for parameter."
9090
}
9191

9292
query predicate localFlowIsLocal(Node n1, Node n2, string msg) {
9393
simpleLocalFlowStep(n1, n2) and
94-
n1.getEnclosingCallable() != n2.getEnclosingCallable() and
94+
nodeGetEnclosingCallable(n1) != nodeGetEnclosingCallable(n2) and
9595
msg = "Local flow step does not preserve enclosing callable."
9696
}
9797

@@ -106,7 +106,7 @@ module Consistency {
106106
query predicate unreachableNodeCCtx(Node n, DataFlowCall call, string msg) {
107107
isUnreachableInCall(n, call) and
108108
exists(DataFlowCallable c |
109-
c = n.getEnclosingCallable() and
109+
c = nodeGetEnclosingCallable(n) and
110110
not viableCallable(call) = c
111111
) and
112112
msg = "Call context for isUnreachableInCall is inconsistent with call graph."
@@ -120,7 +120,7 @@ module Consistency {
120120
n.(ArgumentNode).argumentOf(call, _) and
121121
msg = "ArgumentNode and call does not share enclosing callable."
122122
) and
123-
n.getEnclosingCallable() != call.getEnclosingCallable()
123+
nodeGetEnclosingCallable(n) != call.getEnclosingCallable()
124124
}
125125

126126
// This predicate helps the compiler forget that in some languages
@@ -151,7 +151,7 @@ module Consistency {
151151
}
152152

153153
query predicate postIsInSameCallable(PostUpdateNode n, string msg) {
154-
n.getEnclosingCallable() != n.getPreUpdateNode().getEnclosingCallable() and
154+
nodeGetEnclosingCallable(n) != nodeGetEnclosingCallable(n.getPreUpdateNode()) and
155155
msg = "PostUpdateNode does not share callable with its pre-update node."
156156
}
157157

java/ql/lib/semmle/code/java/dataflow/internal/DataFlowNodes.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,14 @@ private class ImplicitExprPostUpdate extends ImplicitPostUpdateNode, TImplicitEx
304304
}
305305

306306
module Private {
307+
/** Gets the callable in which this node occurs. */
308+
DataFlowCallable nodeGetEnclosingCallable(Node n) { result = n.getEnclosingCallable() }
309+
310+
/** Holds if `p` is a `ParameterNode` of `c` with position `pos`. */
311+
predicate isParameterNode(ParameterNode p, DataFlowCallable c, int pos) {
312+
p.isParameterOf(c, pos)
313+
}
314+
307315
/**
308316
* A data flow node that occurs as the argument of a call and is passed as-is
309317
* to the callable. Arguments that are wrapped in an implicit varargs array

0 commit comments

Comments
 (0)