Rust: Rename predicates.

This commit is contained in:
Geoffrey White
2024-10-29 11:18:57 +00:00
parent eb79bcbc34
commit 6a110368a5

View File

@@ -15,38 +15,40 @@ import codeql.rust.controlflow.internal.ControlFlowGraphImpl as ControlFlowGraph
/**
* Successor relation that includes unreachable AST nodes.
*/
predicate succFull(AstNode a, AstNode b) {
private predicate succ(AstNode a, AstNode b) {
exists(ControlFlowGraphImpl::ControlFlowTree cft | cft.succ(a, b, _))
}
/**
* Gets a node we'd prefer not to report as unreachable.
* Gets a node we'd prefer not to report as unreachable. These will be removed
* from the AST for the purposes of this query, with successor links being
* made across them where appropriate.
*/
predicate skipNode(AstNode n) {
predicate hiddenNode(AstNode n) {
// isolated node (not intended to be part of the CFG)
not succFull(n, _) and
not succFull(_, n)
not succ(n, _) and
not succ(_, n)
or
n instanceof ControlFlowGraphImpl::PostOrderTree // location is counter-intuitive
}
/**
* Successor relation for edges out of `skipNode`s.
* Successor relation for edges out of `hiddenNode`s.
*/
predicate succSkip(AstNode a, AstNode b) {
skipNode(a) and
succFull(a, b)
private predicate succHidden(AstNode a, AstNode b) {
hiddenNode(a) and
succ(a, b)
}
/**
* Successor relation that skips over `skipNode`s.
* Successor relation that removes / links over `hiddenNode`s.
*/
predicate succSkipping(AstNode a, AstNode b) {
private predicate succWithHiding(AstNode a, AstNode b) {
exists(AstNode mid |
not skipNode(a) and
succFull(a, mid) and
succSkip*(mid, b) and
not skipNode(b)
not hiddenNode(a) and
succ(a, mid) and
succHidden*(mid, b) and
not hiddenNode(b)
)
}
@@ -61,8 +63,8 @@ predicate reachable(AstNode n) { n = any(CfgNode cfn).getAstNode() }
*/
private predicate firstUnreachable(AstNode n) {
not reachable(n) and
not skipNode(n) and
forall(AstNode pred | succSkipping(pred, n) | reachable(pred))
not hiddenNode(n) and
forall(AstNode pred | succWithHiding(pred, n) | reachable(pred))
}
from AstNode n