Skip to content

Commit 41ba97b

Browse files
committed
PS: Specify when a completion should be a boolan completion.
1 parent 5dee69b commit 41ba97b

File tree

1 file changed

+44
-1
lines changed
  • powershell/ql/lib/semmle/code/powershell/controlflow/internal

1 file changed

+44
-1
lines changed

powershell/ql/lib/semmle/code/powershell/controlflow/internal/Completion.qll

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,50 @@ private predicate mustHaveBooleanCompletion(Ast n) { inBooleanContext(n) }
8383
* Holds if `n` is used in a Boolean context. That is, the value
8484
* that `n` evaluates to determines a true/false branch successor.
8585
*/
86-
private predicate inBooleanContext(Ast n) { none() }
86+
private predicate inBooleanContext(Ast n) {
87+
n = any(IfStmt ifStmt).getACondition()
88+
or
89+
n = any(WhileStmt whileStmt).getCondition()
90+
or
91+
n = any(DoWhileStmt doWhileStmt).getCondition()
92+
or
93+
n = any(ForStmt forStmt).getCondition()
94+
or
95+
n = any(DoUntilStmt doUntilStmt).getCondition()
96+
or
97+
exists(ConditionalExpr cond |
98+
n = cond.getCondition()
99+
or
100+
inBooleanContext(cond) and
101+
n = cond.getABranch()
102+
)
103+
or
104+
exists(LogicalAndExpr parent |
105+
n = parent.getLeft()
106+
or
107+
inBooleanContext(parent) and
108+
n = parent.getRight()
109+
)
110+
or
111+
exists(LogicalOrExpr parent |
112+
n = parent.getLeft()
113+
or
114+
inBooleanContext(parent) and
115+
n = parent.getRight()
116+
)
117+
or
118+
n = any(NotExpr parent | inBooleanContext(parent)).getOperand()
119+
or
120+
exists(Pipeline pipeline |
121+
inBooleanContext(pipeline) and
122+
n = pipeline.getComponent(pipeline.getNumberOfComponents() - 1)
123+
)
124+
or
125+
exists(CmdExpr cmdExpr |
126+
inBooleanContext(cmdExpr) and
127+
n = cmdExpr.getExpr()
128+
)
129+
}
87130

88131
/**
89132
* A completion that represents normal evaluation of a statement or an

0 commit comments

Comments
 (0)