@@ -145,44 +145,26 @@ class BlockExprTree extends StandardPostOrderTree, BlockExpr {
145
145
result = super .getStmtList ( ) .getTailExpr ( )
146
146
}
147
147
148
- override predicate propagatesAbnormal ( AstNode child ) { none ( ) }
149
-
150
- /** Holds if this block captures the break completion `c`. */
151
- private predicate capturesBreakCompletion ( LoopJumpCompletion c ) {
152
- c .isBreak ( ) and
153
- c .getLabelName ( ) = this .getLabel ( ) .getLifetime ( ) .getText ( )
154
- }
155
-
156
- override predicate succ ( AstNode pred , AstNode succ , Completion c ) {
157
- super .succ ( pred , succ , c )
158
- or
159
- // Edge for exiting the block with a break expressions
160
- last ( this .getChildNode ( _) , pred , c ) and
161
- this .capturesBreakCompletion ( c ) and
162
- succ = this
163
- }
164
-
165
- override predicate last ( AstNode last , Completion c ) {
166
- super .last ( last , c )
167
- or
168
- // Any abnormal completions that this block does not capture should propagate
169
- last ( this .getChildNode ( _) , last , c ) and
170
- not completionIsNormal ( c ) and
171
- not this .capturesBreakCompletion ( c )
172
- }
148
+ override predicate propagatesAbnormal ( AstNode child ) { child = this .getChildNode ( _) }
173
149
}
174
150
175
- class BreakExprTree extends PostOrderTree instanceof BreakExpr {
176
- override predicate propagatesAbnormal ( AstNode child ) { child = super .getExpr ( ) }
151
+ class BreakExprTree extends PostOrderTree , BreakExpr {
152
+ override predicate propagatesAbnormal ( AstNode child ) { child = this .getExpr ( ) }
177
153
178
154
override predicate first ( AstNode node ) {
179
- first ( super .getExpr ( ) , node )
155
+ first ( this .getExpr ( ) , node )
180
156
or
181
- not super .hasExpr ( ) and node = this
157
+ not this .hasExpr ( ) and node = this
182
158
}
183
159
160
+ override predicate last ( AstNode last , Completion c ) { none ( ) }
161
+
184
162
override predicate succ ( AstNode pred , AstNode succ , Completion c ) {
185
163
last ( super .getExpr ( ) , pred , c ) and succ = this
164
+ or
165
+ pred = this and
166
+ c .isValidFor ( pred ) and
167
+ succ = this .getTarget ( )
186
168
}
187
169
}
188
170
@@ -200,7 +182,18 @@ class CastExprTree extends StandardPostOrderTree instanceof CastExpr {
200
182
201
183
class ClosureExprTree extends LeafTree instanceof ClosureExpr { }
202
184
203
- class ContinueExprTree extends LeafTree instanceof ContinueExpr { }
185
+ class ContinueExprTree extends LeafTree , ContinueExpr {
186
+ override predicate last ( AstNode last , Completion c ) { none ( ) }
187
+
188
+ override predicate succ ( AstNode pred , AstNode succ , Completion c ) {
189
+ exists ( Expr target |
190
+ pred = this and
191
+ c .isValidFor ( pred ) and
192
+ target = this .getTarget ( ) and
193
+ first ( target .( LoopingExprTree ) .getLoopContinue ( ) , succ )
194
+ )
195
+ }
196
+ }
204
197
205
198
class ExprStmtTree extends StandardPreOrderTree instanceof ExprStmt {
206
199
override AstNode getChildNode ( int i ) { i = 0 and result = super .getExpr ( ) }
@@ -310,57 +303,27 @@ class LetStmtTree extends PreOrderTree instanceof LetStmt {
310
303
class LiteralExprTree extends LeafTree instanceof LiteralExpr { }
311
304
312
305
abstract class LoopingExprTree extends PostOrderTree {
313
- override predicate propagatesAbnormal ( AstNode child ) { none ( ) }
306
+ override predicate propagatesAbnormal ( AstNode child ) { child = this . getLoopBody ( ) }
314
307
315
308
abstract BlockExpr getLoopBody ( ) ;
316
309
317
- abstract Label getLabel ( ) ;
318
-
319
310
/**
320
311
* Gets the node to execute when continuing the loop; either after
321
312
* executing the last node in the body or after an explicit `continue`.
322
313
*/
323
314
abstract AstNode getLoopContinue ( ) ;
324
315
325
- /** Holds if this loop captures the `c` completion. */
326
- private predicate capturesLoopJumpCompletion ( LoopJumpCompletion c ) {
327
- not c .hasLabel ( )
328
- or
329
- c .getLabelName ( ) = this .getLabel ( ) .getLifetime ( ) .getText ( )
330
- }
331
-
332
316
override predicate succ ( AstNode pred , AstNode succ , Completion c ) {
333
- // Edge for exiting the loop with a break expressions
334
- last ( this .getLoopBody ( ) , pred , c ) and
335
- c .( LoopJumpCompletion ) .isBreak ( ) and
336
- this .capturesLoopJumpCompletion ( c ) and
337
- succ = this
338
- or
339
317
// Edge back to the start for final expression and continue expressions
340
318
last ( this .getLoopBody ( ) , pred , c ) and
341
- (
342
- completionIsNormal ( c )
343
- or
344
- c .( LoopJumpCompletion ) .isContinue ( ) and this .capturesLoopJumpCompletion ( c )
345
- ) and
319
+ completionIsNormal ( c ) and
346
320
first ( this .getLoopContinue ( ) , succ )
347
321
}
348
-
349
- override predicate last ( AstNode last , Completion c ) {
350
- super .last ( last , c )
351
- or
352
- // Any abnormal completions that this loop does not capture should propagate
353
- last ( this .getLoopBody ( ) , last , c ) and
354
- not completionIsNormal ( c ) and
355
- not this .capturesLoopJumpCompletion ( c )
356
- }
357
322
}
358
323
359
324
class LoopExprTree extends LoopingExprTree instanceof LoopExpr {
360
325
override BlockExpr getLoopBody ( ) { result = LoopExpr .super .getLoopBody ( ) }
361
326
362
- override Label getLabel ( ) { result = LoopExpr .super .getLabel ( ) }
363
-
364
327
override AstNode getLoopContinue ( ) { result = this .getLoopBody ( ) }
365
328
366
329
override predicate first ( AstNode node ) { first ( this .getLoopBody ( ) , node ) }
@@ -369,11 +332,13 @@ class LoopExprTree extends LoopingExprTree instanceof LoopExpr {
369
332
class WhileExprTree extends LoopingExprTree instanceof WhileExpr {
370
333
override BlockExpr getLoopBody ( ) { result = WhileExpr .super .getLoopBody ( ) }
371
334
372
- override Label getLabel ( ) { result = WhileExpr .super .getLabel ( ) }
373
-
374
335
override AstNode getLoopContinue ( ) { result = super .getCondition ( ) }
375
336
376
- override predicate propagatesAbnormal ( AstNode child ) { child = super .getCondition ( ) }
337
+ override predicate propagatesAbnormal ( AstNode child ) {
338
+ super .propagatesAbnormal ( child )
339
+ or
340
+ child = super .getCondition ( )
341
+ }
377
342
378
343
override predicate first ( AstNode node ) { first ( super .getCondition ( ) , node ) }
379
344
@@ -399,11 +364,13 @@ class WhileExprTree extends LoopingExprTree instanceof WhileExpr {
399
364
class ForExprTree extends LoopingExprTree instanceof ForExpr {
400
365
override BlockExpr getLoopBody ( ) { result = ForExpr .super .getLoopBody ( ) }
401
366
402
- override Label getLabel ( ) { result = ForExpr .super .getLabel ( ) }
403
-
404
367
override AstNode getLoopContinue ( ) { result = super .getPat ( ) }
405
368
406
- override predicate propagatesAbnormal ( AstNode child ) { child = super .getIterable ( ) }
369
+ override predicate propagatesAbnormal ( AstNode child ) {
370
+ super .propagatesAbnormal ( child )
371
+ or
372
+ child = super .getIterable ( )
373
+ }
407
374
408
375
override predicate first ( AstNode node ) { first ( super .getIterable ( ) , node ) }
409
376
0 commit comments