Java: Replace ControlFlowNode.asCall with Call.getControlFlowNode.

This commit is contained in:
Anders Schack-Mulligen
2026-02-06 16:37:43 +01:00
parent 2e987343dd
commit 4a97a449fc
6 changed files with 23 additions and 11 deletions

View File

@@ -162,12 +162,6 @@ module ControlFlow {
/** Gets the expression this `Node` corresponds to, if any. */
Expr asExpr() { this = TExprNode(result) }
/** Gets the call this `Node` corresponds to, if any. */
Call asCall() {
result = this.asExpr() or
result = this.asStmt()
}
/** Gets a textual representation of this element. */
string toString() { none() }

View File

@@ -1245,6 +1245,9 @@ class ClassInstanceExpr extends Expr, ConstructorCall, @classinstancexpr {
/** Gets the immediately enclosing statement of this class instance creation expression. */
override Stmt getEnclosingStmt() { result = Expr.super.getEnclosingStmt() }
/** Gets the `ControlFlowNode` corresponding to this call. */
override ControlFlowNode getControlFlowNode() { result = Expr.super.getControlFlowNode() }
/** Gets a printable representation of this expression. */
override string toString() {
result = "new " + this.getConstructor().getName() + "(...)"
@@ -2113,6 +2116,9 @@ class MethodCall extends Expr, Call, @methodaccess {
/** Gets the immediately enclosing statement that contains this method access. */
override Stmt getEnclosingStmt() { result = Expr.super.getEnclosingStmt() }
/** Gets the `ControlFlowNode` corresponding to this call. */
override ControlFlowNode getControlFlowNode() { result = Expr.super.getControlFlowNode() }
/** Gets a printable representation of this expression. */
override string toString() {
if exists(this.getMethod())
@@ -2305,6 +2311,9 @@ class Call extends ExprParent, @caller {
/** Gets the enclosing statement of this call. */
/*abstract*/ Stmt getEnclosingStmt() { none() }
/** Gets the `ControlFlowNode` corresponding to this call. */
/*abstract*/ ControlFlowNode getControlFlowNode() { none() }
/** Gets the number of arguments provided in this call. */
int getNumArgument() { count(this.getAnArgument()) = result }

View File

@@ -960,6 +960,9 @@ class ThisConstructorInvocationStmt extends Stmt, ConstructorCall, @constructori
/** Gets the immediately enclosing statement of this constructor invocation. */
override Stmt getEnclosingStmt() { result = this }
/** Gets the `ControlFlowNode` corresponding to this call. */
override ControlFlowNode getControlFlowNode() { result = Stmt.super.getControlFlowNode() }
override string pp() { result = "this(...)" }
override string toString() { result = "this(...)" }
@@ -1001,6 +1004,9 @@ class SuperConstructorInvocationStmt extends Stmt, ConstructorCall, @superconstr
/** Gets the immediately enclosing statement of this constructor invocation. */
override Stmt getEnclosingStmt() { result = this }
/** Gets the `ControlFlowNode` corresponding to this call. */
override ControlFlowNode getControlFlowNode() { result = Stmt.super.getControlFlowNode() }
override string pp() { result = "super(...)" }
override string toString() { result = "super(...)" }

View File

@@ -34,7 +34,7 @@ abstract class ActionConfiguration extends string {
private BasicBlock actionBlock(ActionConfiguration conf) {
exists(ControlFlowNode node | result = node.getBasicBlock() |
conf.isAction(node) or
callAlwaysPerformsAction(node.asCall(), conf)
callAlwaysPerformsAction(any(Call call | call.getControlFlowNode() = node), conf)
)
}

View File

@@ -229,7 +229,7 @@ class InstanceAccessExt extends TInstanceAccessExt {
/** Gets the control flow node associated with this instance access. */
ControlFlowNode getCfgNode() {
exists(ExprParent e | e = this.getAssociatedExprOrStmt() |
result.asCall() = e
result = e.(Call).getControlFlowNode()
or
e.(InstanceAccess).getControlFlowNode() = result
or

View File

@@ -153,7 +153,7 @@ private predicate hasEntryDef(TrackedVar v, BasicBlock b) {
overlay[global]
pragma[nomagic]
private predicate uncertainVariableUpdateImpl(TrackedVar v, ControlFlowNode n, BasicBlock b, int i) {
exists(Call c | c = n.asCall() | updatesNamedField(c, v, _)) and
exists(Call c | c.getControlFlowNode() = n | updatesNamedField(c, v, _)) and
b.getNode(i) = n and
hasDominanceInformation(b)
or
@@ -525,8 +525,11 @@ private module Cached {
overlay[global]
cached
predicate defUpdatesNamedField(SsaImplicitWrite calldef, TrackedField f, Callable setter) {
f = calldef.getSourceVariable() and
updatesNamedField0(calldef.getControlFlowNode().asCall(), f, setter)
exists(Call call |
f = calldef.getSourceVariable() and
call.getControlFlowNode() = calldef.getControlFlowNode() and
updatesNamedField0(call, f, setter)
)
}
/** Holds if `init` is a closure variable that captures the value of `capturedvar`. */