Skip to content

Commit b5f70fc

Browse files
committed
Java: Replace ControlFlowNode.asCall with Call.getControlFlowNode.
1 parent c90831d commit b5f70fc

File tree

6 files changed

+23
-11
lines changed

6 files changed

+23
-11
lines changed

java/ql/lib/semmle/code/java/ControlFlowGraph.qll

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,6 @@ module ControlFlow {
162162
/** Gets the expression this `Node` corresponds to, if any. */
163163
Expr asExpr() { this = TExprNode(result) }
164164

165-
/** Gets the call this `Node` corresponds to, if any. */
166-
Call asCall() {
167-
result = this.asExpr() or
168-
result = this.asStmt()
169-
}
170-
171165
/** Gets a textual representation of this element. */
172166
string toString() { none() }
173167

java/ql/lib/semmle/code/java/Expr.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,6 +1245,9 @@ class ClassInstanceExpr extends Expr, ConstructorCall, @classinstancexpr {
12451245
/** Gets the immediately enclosing statement of this class instance creation expression. */
12461246
override Stmt getEnclosingStmt() { result = Expr.super.getEnclosingStmt() }
12471247

1248+
/** Gets the `ControlFlowNode` corresponding to this call. */
1249+
override ControlFlowNode getControlFlowNode() { result = Expr.super.getControlFlowNode() }
1250+
12481251
/** Gets a printable representation of this expression. */
12491252
override string toString() {
12501253
result = "new " + this.getConstructor().getName() + "(...)"
@@ -2113,6 +2116,9 @@ class MethodCall extends Expr, Call, @methodaccess {
21132116
/** Gets the immediately enclosing statement that contains this method access. */
21142117
override Stmt getEnclosingStmt() { result = Expr.super.getEnclosingStmt() }
21152118

2119+
/** Gets the `ControlFlowNode` corresponding to this call. */
2120+
override ControlFlowNode getControlFlowNode() { result = Expr.super.getControlFlowNode() }
2121+
21162122
/** Gets a printable representation of this expression. */
21172123
override string toString() {
21182124
if exists(this.getMethod())
@@ -2305,6 +2311,9 @@ class Call extends ExprParent, @caller {
23052311
/** Gets the enclosing statement of this call. */
23062312
/*abstract*/ Stmt getEnclosingStmt() { none() }
23072313

2314+
/** Gets the `ControlFlowNode` corresponding to this call. */
2315+
/*abstract*/ ControlFlowNode getControlFlowNode() { none() }
2316+
23082317
/** Gets the number of arguments provided in this call. */
23092318
int getNumArgument() { count(this.getAnArgument()) = result }
23102319

java/ql/lib/semmle/code/java/Statement.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,9 @@ class ThisConstructorInvocationStmt extends Stmt, ConstructorCall, @constructori
960960
/** Gets the immediately enclosing statement of this constructor invocation. */
961961
override Stmt getEnclosingStmt() { result = this }
962962

963+
/** Gets the `ControlFlowNode` corresponding to this call. */
964+
override ControlFlowNode getControlFlowNode() { result = Stmt.super.getControlFlowNode() }
965+
963966
override string pp() { result = "this(...)" }
964967

965968
override string toString() { result = "this(...)" }
@@ -1001,6 +1004,9 @@ class SuperConstructorInvocationStmt extends Stmt, ConstructorCall, @superconstr
10011004
/** Gets the immediately enclosing statement of this constructor invocation. */
10021005
override Stmt getEnclosingStmt() { result = this }
10031006

1007+
/** Gets the `ControlFlowNode` corresponding to this call. */
1008+
override ControlFlowNode getControlFlowNode() { result = Stmt.super.getControlFlowNode() }
1009+
10041010
override string pp() { result = "super(...)" }
10051011

10061012
override string toString() { result = "super(...)" }

java/ql/lib/semmle/code/java/controlflow/Paths.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ abstract class ActionConfiguration extends string {
3434
private BasicBlock actionBlock(ActionConfiguration conf) {
3535
exists(ControlFlowNode node | result = node.getBasicBlock() |
3636
conf.isAction(node) or
37-
callAlwaysPerformsAction(node.asCall(), conf)
37+
callAlwaysPerformsAction(any(Call call | call.getControlFlowNode() = node), conf)
3838
)
3939
}
4040

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ class InstanceAccessExt extends TInstanceAccessExt {
229229
/** Gets the control flow node associated with this instance access. */
230230
ControlFlowNode getCfgNode() {
231231
exists(ExprParent e | e = this.getAssociatedExprOrStmt() |
232-
result.asCall() = e
232+
result = e.(Call).getControlFlowNode()
233233
or
234234
e.(InstanceAccess).getControlFlowNode() = result
235235
or

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ private predicate hasEntryDef(TrackedVar v, BasicBlock b) {
153153
overlay[global]
154154
pragma[nomagic]
155155
private predicate uncertainVariableUpdateImpl(TrackedVar v, ControlFlowNode n, BasicBlock b, int i) {
156-
exists(Call c | c = n.asCall() | updatesNamedField(c, v, _)) and
156+
exists(Call c | c.getControlFlowNode() = n | updatesNamedField(c, v, _)) and
157157
b.getNode(i) = n and
158158
hasDominanceInformation(b)
159159
or
@@ -525,8 +525,11 @@ private module Cached {
525525
overlay[global]
526526
cached
527527
predicate defUpdatesNamedField(SsaImplicitWrite calldef, TrackedField f, Callable setter) {
528-
f = calldef.getSourceVariable() and
529-
updatesNamedField0(calldef.getControlFlowNode().asCall(), f, setter)
528+
exists(Call call |
529+
f = calldef.getSourceVariable() and
530+
call.getControlFlowNode() = calldef.getControlFlowNode() and
531+
updatesNamedField0(call, f, setter)
532+
)
530533
}
531534

532535
/** Holds if `init` is a closure variable that captures the value of `capturedvar`. */

0 commit comments

Comments
 (0)