@@ -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,15 @@ 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
+ pred = this and
190
+ c .isValidFor ( pred ) and
191
+ first ( this .getTarget ( ) .( LoopingExprTree ) .getLoopContinue ( ) , succ )
192
+ }
193
+ }
204
194
205
195
class ExprStmtTree extends StandardPreOrderTree instanceof ExprStmt {
206
196
override AstNode getChildNode ( int i ) { i = 0 and result = super .getExpr ( ) }
@@ -310,57 +300,27 @@ class LetStmtTree extends PreOrderTree instanceof LetStmt {
310
300
class LiteralExprTree extends LeafTree instanceof LiteralExpr { }
311
301
312
302
abstract class LoopingExprTree extends PostOrderTree {
313
- override predicate propagatesAbnormal ( AstNode child ) { none ( ) }
303
+ override predicate propagatesAbnormal ( AstNode child ) { child = this . getLoopBody ( ) }
314
304
315
305
abstract BlockExpr getLoopBody ( ) ;
316
306
317
- abstract Label getLabel ( ) ;
318
-
319
307
/**
320
308
* Gets the node to execute when continuing the loop; either after
321
309
* executing the last node in the body or after an explicit `continue`.
322
310
*/
323
311
abstract AstNode getLoopContinue ( ) ;
324
312
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
313
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
314
// Edge back to the start for final expression and continue expressions
340
315
last ( this .getLoopBody ( ) , pred , c ) and
341
- (
342
- completionIsNormal ( c )
343
- or
344
- c .( LoopJumpCompletion ) .isContinue ( ) and this .capturesLoopJumpCompletion ( c )
345
- ) and
316
+ completionIsNormal ( c ) and
346
317
first ( this .getLoopContinue ( ) , succ )
347
318
}
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
319
}
358
320
359
321
class LoopExprTree extends LoopingExprTree instanceof LoopExpr {
360
322
override BlockExpr getLoopBody ( ) { result = LoopExpr .super .getLoopBody ( ) }
361
323
362
- override Label getLabel ( ) { result = LoopExpr .super .getLabel ( ) }
363
-
364
324
override AstNode getLoopContinue ( ) { result = this .getLoopBody ( ) }
365
325
366
326
override predicate first ( AstNode node ) { first ( this .getLoopBody ( ) , node ) }
@@ -369,11 +329,13 @@ class LoopExprTree extends LoopingExprTree instanceof LoopExpr {
369
329
class WhileExprTree extends LoopingExprTree instanceof WhileExpr {
370
330
override BlockExpr getLoopBody ( ) { result = WhileExpr .super .getLoopBody ( ) }
371
331
372
- override Label getLabel ( ) { result = WhileExpr .super .getLabel ( ) }
373
-
374
332
override AstNode getLoopContinue ( ) { result = super .getCondition ( ) }
375
333
376
- override predicate propagatesAbnormal ( AstNode child ) { child = super .getCondition ( ) }
334
+ override predicate propagatesAbnormal ( AstNode child ) {
335
+ super .propagatesAbnormal ( child )
336
+ or
337
+ child = super .getCondition ( )
338
+ }
377
339
378
340
override predicate first ( AstNode node ) { first ( super .getCondition ( ) , node ) }
379
341
@@ -399,11 +361,13 @@ class WhileExprTree extends LoopingExprTree instanceof WhileExpr {
399
361
class ForExprTree extends LoopingExprTree instanceof ForExpr {
400
362
override BlockExpr getLoopBody ( ) { result = ForExpr .super .getLoopBody ( ) }
401
363
402
- override Label getLabel ( ) { result = ForExpr .super .getLabel ( ) }
403
-
404
364
override AstNode getLoopContinue ( ) { result = super .getPat ( ) }
405
365
406
- override predicate propagatesAbnormal ( AstNode child ) { child = super .getIterable ( ) }
366
+ override predicate propagatesAbnormal ( AstNode child ) {
367
+ super .propagatesAbnormal ( child )
368
+ or
369
+ child = super .getIterable ( )
370
+ }
407
371
408
372
override predicate first ( AstNode node ) { first ( super .getIterable ( ) , node ) }
409
373
0 commit comments