PS: Add helper predicates for if statements.

This commit is contained in:
Mathias Vorreiter Pedersen
2025-03-28 19:30:16 +00:00
parent ee0a21e67f
commit 2da8da0777
2 changed files with 18 additions and 0 deletions

View File

@@ -53,5 +53,13 @@ class If extends Expr, TIf {
)
}
StmtBlock getABranch(boolean b) {
b = true and result = this.getAThen()
or
b = false and result = this.getElse()
}
StmtBlock getABranch() { result = this.getAThen() or result = this.getElse() }
predicate hasElse() { exists(this.getElse()) }
}

View File

@@ -900,6 +900,16 @@ module ExprNodes {
StmtCfgNode getAThen() { result = this.getThen(_) }
StmtCfgNode getElse() { e.hasCfgChild(e.getElse(), this, result) }
StmtCfgNode getABranch(boolean b) {
b = true and
result = this.getAThen()
or
b = false and
result = this.getElse()
}
StmtCfgNode getABranch() { result = this.getABranch(_) }
}
private class LiteralChildMapping extends ExprChildMapping, Literal {