@@ -469,8 +469,9 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
469469 * Gets the `index`th part of the body of `c` in context `ctx`. The indices do not
470470 * need to be consecutive nor start from a specific index.
471471 *
472- * `callableGetBodyPart(c, _, _)` and `callableGetBody(c)` must never both hold
473- * for a given callable `c`.
472+ * This overrides the default CFG for a `Callable` with sequential evaluation
473+ * of the body parts, in case a singleton `callableGetBody(c)` is inadequate
474+ * to describe the child nodes of `c`.
474475 */
475476 default AstNode callableGetBodyPart ( Callable c , CallableBodyPartContext ctx , int index ) {
476477 none ( )
@@ -682,7 +683,7 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
682683 * not step to it, since "after" represents normal termination).
683684 */
684685
685- private predicate isCallableBodyPart ( Callable c , AstNode n ) {
686+ private predicate callableHasBodyPart ( Callable c , AstNode n ) {
686687 n = callableGetBody ( c ) or n = Input1:: callableGetBodyPart ( c , _, _)
687688 }
688689
@@ -696,13 +697,15 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
696697 }
697698
698699 private AstNode getBodyEntry ( Callable c ) {
699- result = callableGetBody ( c )
700+ result = callableGetBody ( c ) and
701+ not exists ( getRankedBodyPart ( c , _, _) )
700702 or
701703 result = getRankedBodyPart ( c , _, 1 )
702704 }
703705
704706 private AstNode getBodyExit ( Callable c ) {
705- result = callableGetBody ( c )
707+ result = callableGetBody ( c ) and
708+ not exists ( getRankedBodyPart ( c , _, _) )
706709 or
707710 exists ( Input1:: CallableBodyPartContext ctx , int last |
708711 result = getRankedBodyPart ( c , ctx , last ) and
@@ -726,9 +729,9 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
726729 TAdditionalNode ( AstNode n , string tag ) {
727730 additionalNode ( n , tag , _) and exists ( getEnclosingCallable ( n ) )
728731 } or
729- TEntryNode ( Callable c ) { isCallableBodyPart ( c , _) } or
730- TAnnotatedExitNode ( Callable c , Boolean normal ) { isCallableBodyPart ( c , _) } or
731- TExitNode ( Callable c ) { isCallableBodyPart ( c , _) }
732+ TEntryNode ( Callable c ) { callableHasBodyPart ( c , _) } or
733+ TAnnotatedExitNode ( Callable c , Boolean normal ) { callableHasBodyPart ( c , _) } or
734+ TExitNode ( Callable c ) { callableHasBodyPart ( c , _) }
732735
733736 private class NodeImpl extends TNode {
734737 /**
@@ -1146,7 +1149,7 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
11461149 private predicate endAbruptCompletion ( AstNode ast , PreControlFlowNode n , AbruptCompletion c ) {
11471150 Input2:: endAbruptCompletion ( ast , n , c )
11481151 or
1149- exists ( Callable callable | isCallableBodyPart ( callable , ast ) |
1152+ exists ( Callable callable | callableHasBodyPart ( callable , ast ) |
11501153 c .getSuccessorType ( ) instanceof ReturnSuccessor and
11511154 n .( NormalExitNodeImpl ) .getEnclosingCallable ( ) = callable
11521155 or
@@ -1312,6 +1315,11 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
13121315 n1 .( EntryNodeImpl ) .getEnclosingCallable ( ) = c and
13131316 n2 .isBefore ( getBodyEntry ( c ) )
13141317 or
1318+ exists ( Input1:: CallableBodyPartContext ctx , int i |
1319+ n1 .isAfter ( getRankedBodyPart ( c , ctx , i ) ) and
1320+ n2 .isBefore ( getRankedBodyPart ( c , ctx , i + 1 ) )
1321+ )
1322+ or
13151323 n1 .isAfter ( getBodyExit ( c ) ) and
13161324 n2 .( NormalExitNodeImpl ) .getEnclosingCallable ( ) = c
13171325 or
@@ -1692,17 +1700,9 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
16921700 n1 .isBefore ( ast ) and
16931701 n2 .isBefore ( getRankedChild ( ast , 1 ) )
16941702 or
1695- exists ( int i , AstNode prev , AstNode next |
1696- n1 .isAfter ( prev ) and
1697- n2 .isBefore ( next )
1698- |
1699- prev = getRankedChild ( ast , i ) and
1700- next = getRankedChild ( ast , i + 1 )
1701- or
1702- exists ( Input1:: CallableBodyPartContext ctx |
1703- prev = getRankedBodyPart ( ast , ctx , i ) and
1704- next = getRankedBodyPart ( ast , ctx , i + 1 )
1705- )
1703+ exists ( int i |
1704+ n1 .isAfter ( getRankedChild ( ast , i ) ) and
1705+ n2 .isBefore ( getRankedChild ( ast , i + 1 ) )
17061706 )
17071707 or
17081708 (
@@ -2180,11 +2180,12 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
21802180 }
21812181
21822182 /**
2183- * Holds if `c` is included in both `callableGetBody` and `callableGetBodyPart`.
2183+ * Holds if `c` does not include `callableGetBody` in a non-empty `callableGetBodyPart`.
21842184 */
21852185 query predicate bodyPartOverlap ( Callable c ) {
21862186 exists ( callableGetBody ( c ) ) and
2187- exists ( Input1:: callableGetBodyPart ( c , _, _) )
2187+ exists ( Input1:: callableGetBodyPart ( c , _, _) ) and
2188+ not Input1:: callableGetBodyPart ( c , _, _) = callableGetBody ( c )
21882189 }
21892190 }
21902191 }
0 commit comments