@@ -5,66 +5,27 @@ overlay[local]
55module ;
66
77import go
8- private import ControlFlowGraphImpl
9- private import codeql.controlflow.BasicBlock as BB
10- private import codeql.controlflow.SuccessorType
8+ private import ControlFlowGraphShared
119
12- private module Input implements BB:: InputSig< Location > {
13- /** A delineated part of the AST with its own CFG. */
14- class CfgScope = ControlFlow:: Root ;
10+ /** A basic block in the control-flow graph. */
11+ class BasicBlock = GoCfg:: Cfg:: BasicBlock ;
1512
16- /** The class of control flow nodes. */
17- class Node = ControlFlowNode ;
18-
19- /** Gets the CFG scope in which this node occurs. */
20- CfgScope nodeGetCfgScope ( Node node ) { node .getRoot ( ) = result }
21-
22- /** Gets an immediate successor of this node. */
23- Node nodeGetASuccessor ( Node node , SuccessorType t ) {
24- result = node .getASuccessor ( ) and
25- (
26- not result instanceof ControlFlow:: ConditionGuardNode and t instanceof DirectSuccessor
27- or
28- t .( BooleanSuccessor ) .getValue ( ) = result .( ControlFlow:: ConditionGuardNode ) .getOutcome ( )
29- )
30- }
31-
32- /**
33- * Holds if `node` represents an entry node to be used when calculating
34- * dominance.
35- */
36- predicate nodeIsDominanceEntry ( Node node ) { node instanceof EntryNode }
37-
38- /**
39- * Holds if `node` represents an exit node to be used when calculating
40- * post dominance.
41- */
42- predicate nodeIsPostDominanceExit ( Node node ) { node instanceof ExitNode }
43- }
44-
45- module Cfg = BB:: Make< Location , Input > ;
46-
47- class BasicBlock = Cfg:: BasicBlock ;
48-
49- class EntryBasicBlock = Cfg:: EntryBasicBlock ;
50-
51- cached
52- private predicate reachableBB ( BasicBlock bb ) {
53- bb instanceof EntryBasicBlock
54- or
55- exists ( BasicBlock predBB | predBB .getASuccessor ( _) = bb | reachableBB ( predBB ) )
56- }
13+ /** An entry basic block. */
14+ class EntryBasicBlock = GoCfg:: Cfg:: EntryBasicBlock ;
5715
5816/**
5917 * A basic block that is reachable from an entry basic block.
18+ *
19+ * Since the shared CFG library only creates nodes for reachable code,
20+ * all basic blocks are reachable by construction.
6021 */
6122class ReachableBasicBlock extends BasicBlock {
62- ReachableBasicBlock ( ) { reachableBB ( this ) }
23+ ReachableBasicBlock ( ) { any ( ) }
6324}
6425
6526/**
6627 * A reachable basic block with more than one predecessor.
6728 */
6829class ReachableJoinBlock extends ReachableBasicBlock {
69- ReachableJoinBlock ( ) { this .getFirstNode ( ) .isJoin ( ) }
30+ ReachableJoinBlock ( ) { this .getFirstNode ( ) .( ControlFlow :: Node ) . isJoin ( ) }
7031}
0 commit comments