diff --git a/powershell/ql/lib/semmle/code/powershell/ast/internal/If.qll b/powershell/ql/lib/semmle/code/powershell/ast/internal/If.qll index 94192397060..4aa44a2359d 100644 --- a/powershell/ql/lib/semmle/code/powershell/ast/internal/If.qll +++ b/powershell/ql/lib/semmle/code/powershell/ast/internal/If.qll @@ -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()) } } diff --git a/powershell/ql/lib/semmle/code/powershell/controlflow/CfgNodes.qll b/powershell/ql/lib/semmle/code/powershell/controlflow/CfgNodes.qll index 438ef698afe..ac3faab7c13 100644 --- a/powershell/ql/lib/semmle/code/powershell/controlflow/CfgNodes.qll +++ b/powershell/ql/lib/semmle/code/powershell/controlflow/CfgNodes.qll @@ -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 {