Files
codeql/java/ql/lib/utils/test/AstCfg.qll
Anders Schack-Mulligen eb37c413f2 Java: Accept revised CFG.
2026-02-23 15:10:00 +01:00

29 lines
731 B
Plaintext

/**
* Provides utilities for getting an AST-based control flow graph in tests.
*/
overlay[local?]
module;
import java
private predicate isAstNode(ControlFlowNode n) {
n.injects(_) or
n instanceof ControlFlow::EntryNode or
n instanceof ControlFlow::AnnotatedExitNode or
n instanceof ControlFlow::ExitNode
}
private predicate succToAst(ControlFlowNode n1, ControlFlowNode n2) {
n2 = n1.getASuccessor() and
isAstNode(n2)
or
exists(ControlFlowNode mid |
mid = n1.getASuccessor() and
not isAstNode(mid) and
succToAst(mid, n2)
)
}
/** Gets a control flow successor of `n` that skips over non-AST nodes. */
ControlFlowNode getAnAstSuccessor(ControlFlowNode n) { isAstNode(n) and succToAst(n, result) }