@@ -145,44 +145,26 @@ class BlockExprTree extends StandardPostOrderTree, BlockExpr {
145145 result = super .getStmtList ( ) .getTailExpr ( )
146146 }
147147
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 ( _) }
173149}
174150
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 ( ) }
177153
178154 override predicate first ( AstNode node ) {
179- first ( super .getExpr ( ) , node )
155+ first ( this .getExpr ( ) , node )
180156 or
181- not super .hasExpr ( ) and node = this
157+ not this .hasExpr ( ) and node = this
182158 }
183159
160+ override predicate last ( AstNode last , Completion c ) { none ( ) }
161+
184162 override predicate succ ( AstNode pred , AstNode succ , Completion c ) {
185163 last ( super .getExpr ( ) , pred , c ) and succ = this
164+ or
165+ pred = this and
166+ c .isValidFor ( pred ) and
167+ succ = this .getTarget ( )
186168 }
187169}
188170
@@ -200,7 +182,15 @@ class CastExprTree extends StandardPostOrderTree instanceof CastExpr {
200182
201183class ClosureExprTree extends LeafTree instanceof ClosureExpr { }
202184
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+ }
204194
205195class ExprStmtTree extends StandardPreOrderTree instanceof ExprStmt {
206196 override AstNode getChildNode ( int i ) { i = 0 and result = super .getExpr ( ) }
@@ -310,57 +300,27 @@ class LetStmtTree extends PreOrderTree instanceof LetStmt {
310300class LiteralExprTree extends LeafTree instanceof LiteralExpr { }
311301
312302abstract class LoopingExprTree extends PostOrderTree {
313- override predicate propagatesAbnormal ( AstNode child ) { none ( ) }
303+ override predicate propagatesAbnormal ( AstNode child ) { child = this . getLoopBody ( ) }
314304
315305 abstract BlockExpr getLoopBody ( ) ;
316306
317- abstract Label getLabel ( ) ;
318-
319307 /**
320308 * Gets the node to execute when continuing the loop; either after
321309 * executing the last node in the body or after an explicit `continue`.
322310 */
323311 abstract AstNode getLoopContinue ( ) ;
324312
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-
332313 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
339314 // Edge back to the start for final expression and continue expressions
340315 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
346317 first ( this .getLoopContinue ( ) , succ )
347318 }
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- }
357319}
358320
359321class LoopExprTree extends LoopingExprTree instanceof LoopExpr {
360322 override BlockExpr getLoopBody ( ) { result = LoopExpr .super .getLoopBody ( ) }
361323
362- override Label getLabel ( ) { result = LoopExpr .super .getLabel ( ) }
363-
364324 override AstNode getLoopContinue ( ) { result = this .getLoopBody ( ) }
365325
366326 override predicate first ( AstNode node ) { first ( this .getLoopBody ( ) , node ) }
@@ -369,11 +329,13 @@ class LoopExprTree extends LoopingExprTree instanceof LoopExpr {
369329class WhileExprTree extends LoopingExprTree instanceof WhileExpr {
370330 override BlockExpr getLoopBody ( ) { result = WhileExpr .super .getLoopBody ( ) }
371331
372- override Label getLabel ( ) { result = WhileExpr .super .getLabel ( ) }
373-
374332 override AstNode getLoopContinue ( ) { result = super .getCondition ( ) }
375333
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+ }
377339
378340 override predicate first ( AstNode node ) { first ( super .getCondition ( ) , node ) }
379341
@@ -399,11 +361,13 @@ class WhileExprTree extends LoopingExprTree instanceof WhileExpr {
399361class ForExprTree extends LoopingExprTree instanceof ForExpr {
400362 override BlockExpr getLoopBody ( ) { result = ForExpr .super .getLoopBody ( ) }
401363
402- override Label getLabel ( ) { result = ForExpr .super .getLabel ( ) }
403-
404364 override AstNode getLoopContinue ( ) { result = super .getPat ( ) }
405365
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+ }
407371
408372 override predicate first ( AstNode node ) { first ( super .getIterable ( ) , node ) }
409373
0 commit comments