Skip to content

Commit 2da8da0

Browse files
committed
PS: Add helper predicates for if statements.
1 parent ee0a21e commit 2da8da0

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

powershell/ql/lib/semmle/code/powershell/ast/internal/If.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,13 @@ class If extends Expr, TIf {
5353
)
5454
}
5555

56+
StmtBlock getABranch(boolean b) {
57+
b = true and result = this.getAThen()
58+
or
59+
b = false and result = this.getElse()
60+
}
61+
62+
StmtBlock getABranch() { result = this.getAThen() or result = this.getElse() }
63+
5664
predicate hasElse() { exists(this.getElse()) }
5765
}

powershell/ql/lib/semmle/code/powershell/controlflow/CfgNodes.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,16 @@ module ExprNodes {
900900
StmtCfgNode getAThen() { result = this.getThen(_) }
901901

902902
StmtCfgNode getElse() { e.hasCfgChild(e.getElse(), this, result) }
903+
904+
StmtCfgNode getABranch(boolean b) {
905+
b = true and
906+
result = this.getAThen()
907+
or
908+
b = false and
909+
result = this.getElse()
910+
}
911+
912+
StmtCfgNode getABranch() { result = this.getABranch(_) }
903913
}
904914

905915
private class LiteralChildMapping extends ExprChildMapping, Literal {

0 commit comments

Comments
 (0)