@@ -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,18 @@ 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+ 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+ }
204197
205198class ExprStmtTree extends StandardPreOrderTree instanceof ExprStmt {
206199 override AstNode getChildNode ( int i ) { i = 0 and result = super .getExpr ( ) }
@@ -310,57 +303,27 @@ class LetStmtTree extends PreOrderTree instanceof LetStmt {
310303class LiteralExprTree extends LeafTree instanceof LiteralExpr { }
311304
312305abstract class LoopingExprTree extends PostOrderTree {
313- override predicate propagatesAbnormal ( AstNode child ) { none ( ) }
306+ override predicate propagatesAbnormal ( AstNode child ) { child = this . getLoopBody ( ) }
314307
315308 abstract BlockExpr getLoopBody ( ) ;
316309
317- abstract Label getLabel ( ) ;
318-
319310 /**
320311 * Gets the node to execute when continuing the loop; either after
321312 * executing the last node in the body or after an explicit `continue`.
322313 */
323314 abstract AstNode getLoopContinue ( ) ;
324315
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-
332316 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
339317 // Edge back to the start for final expression and continue expressions
340318 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
346320 first ( this .getLoopContinue ( ) , succ )
347321 }
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- }
357322}
358323
359324class LoopExprTree extends LoopingExprTree instanceof LoopExpr {
360325 override BlockExpr getLoopBody ( ) { result = LoopExpr .super .getLoopBody ( ) }
361326
362- override Label getLabel ( ) { result = LoopExpr .super .getLabel ( ) }
363-
364327 override AstNode getLoopContinue ( ) { result = this .getLoopBody ( ) }
365328
366329 override predicate first ( AstNode node ) { first ( this .getLoopBody ( ) , node ) }
@@ -369,11 +332,13 @@ class LoopExprTree extends LoopingExprTree instanceof LoopExpr {
369332class WhileExprTree extends LoopingExprTree instanceof WhileExpr {
370333 override BlockExpr getLoopBody ( ) { result = WhileExpr .super .getLoopBody ( ) }
371334
372- override Label getLabel ( ) { result = WhileExpr .super .getLabel ( ) }
373-
374335 override AstNode getLoopContinue ( ) { result = super .getCondition ( ) }
375336
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+ }
377342
378343 override predicate first ( AstNode node ) { first ( super .getCondition ( ) , node ) }
379344
@@ -399,11 +364,13 @@ class WhileExprTree extends LoopingExprTree instanceof WhileExpr {
399364class ForExprTree extends LoopingExprTree instanceof ForExpr {
400365 override BlockExpr getLoopBody ( ) { result = ForExpr .super .getLoopBody ( ) }
401366
402- override Label getLabel ( ) { result = ForExpr .super .getLabel ( ) }
403-
404367 override AstNode getLoopContinue ( ) { result = super .getPat ( ) }
405368
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+ }
407374
408375 override predicate first ( AstNode node ) { first ( super .getIterable ( ) , node ) }
409376
0 commit comments