Skip to content

Commit 94a740f

Browse files
committed
PS: Add continue completion and successor.
1 parent 2d8a8c0 commit 94a740f

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ module SuccessorTypes {
9090
final override string toString() { result = "break" }
9191
}
9292

93+
class ContinueSuccessor extends SuccessorType, CfgImpl::TContinueSuccessor {
94+
final override string toString() { result = "continue" }
95+
}
96+
9397
class RaiseSuccessor extends SuccessorType, CfgImpl::TRaiseSuccessor {
9498
final override string toString() { result = "raise" }
9599
}

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

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,18 @@ private newtype TCompletion =
1515
TBooleanCompletion(boolean b) { b in [false, true] } or
1616
TReturnCompletion() or
1717
TBreakCompletion() or
18+
TContinueCompletion() or
1819
TRaiseCompletion() or
1920
TExitCompletion()
2021

2122
pragma[noinline]
22-
private predicate completionIsValidForStmt(Ast n, Completion c) { none() }
23+
private predicate completionIsValidForStmt(Ast n, Completion c) {
24+
n instanceof BreakStmt and
25+
c instanceof BreakCompletion
26+
or
27+
n instanceof ContinueStmt and
28+
c instanceof ContinueCompletion
29+
}
2330

2431
/** A completion of a statement or an expression. */
2532
abstract class Completion extends TCompletion {
@@ -49,19 +56,10 @@ abstract class Completion extends TCompletion {
4956
* Holds if this completion will continue a loop when it is the completion
5057
* of a loop body.
5158
*/
52-
predicate continuesLoop() { this instanceof NormalCompletion }
53-
54-
/**
55-
* Gets the inner completion. This is either the inner completion,
56-
* when the completion is nested, or the completion itself.
57-
*/
58-
Completion getInnerCompletion() { result = this }
59-
60-
/**
61-
* Gets the outer completion. This is either the outer completion,
62-
* when the completion is nested, or the completion itself.
63-
*/
64-
Completion getOuterCompletion() { result = this }
59+
predicate continuesLoop() {
60+
this instanceof NormalCompletion or
61+
this instanceof ContinueCompletion
62+
}
6563

6664
/** Gets a successor type that matches this completion. */
6765
abstract SuccessorType getAMatchingSuccessorType();
@@ -159,6 +157,16 @@ class BreakCompletion extends Completion, TBreakCompletion {
159157
override string toString() { result = "break" }
160158
}
161159

160+
/**
161+
* A completion that represents evaluation of a statement or an
162+
* expression resulting in a continuation of a loop.
163+
*/
164+
class ContinueCompletion extends Completion, TContinueCompletion {
165+
override ContinueSuccessor getAMatchingSuccessorType() { any() }
166+
167+
override string toString() { result = "continue" }
168+
}
169+
162170
/**
163171
* A completion that represents evaluation of a statement or an
164172
* expression resulting in a thrown exception.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ private module Cached {
188188
TBooleanSuccessor(boolean b) { b in [false, true] } or
189189
TReturnSuccessor() or
190190
TBreakSuccessor() or
191+
TContinueSuccessor() or
191192
TRaiseSuccessor() or
192193
TExitSuccessor()
193194
}

0 commit comments

Comments
 (0)