Skip to content

Commit f7e9049

Browse files
committed
Shared: Implement getScope in BB module instead of CFG module
1 parent 62a459d commit f7e9049

File tree

2 files changed

+16
-78
lines changed

2 files changed

+16
-78
lines changed

shared/controlflow/codeql/controlflow/BasicBlock.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ signature module InputSig<LocationSig Location> {
1515
/** Hold if `t` represents a conditional successor type. */
1616
predicate successorTypeIsCondition(SuccessorType t);
1717

18+
/** Represents a delineated part of the AST with its own CFG. */
19+
class CfgScope;
20+
1821
/** The class of control flow nodes. */
1922
class Node {
2023
string toString();
@@ -23,6 +26,9 @@ signature module InputSig<LocationSig Location> {
2326
Location getLocation();
2427
}
2528

29+
/** Gets the CFG scope in which this node occurs. */
30+
CfgScope nodeGetCfgScope(Node node);
31+
2632
/** Gets an immediate successor of this node. */
2733
Node nodeGetASuccessor(Node node, SuccessorType t);
2834

@@ -62,6 +68,9 @@ module Make<LocationSig Location, InputSig<Location> Input> {
6268
* without branches or joins.
6369
*/
6470
private class BasicBlockImpl extends TBasicBlockStart {
71+
/** Gets the CFG scope of this basic block. */
72+
CfgScope getScope() { result = nodeGetCfgScope(this.getFirstNode()) }
73+
6574
/** Gets the location of this basic block. */
6675
Location getLocation() { result = this.getFirstNode().getLocation() }
6776

shared/controlflow/codeql/controlflow/Cfg.qll

Lines changed: 7 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,15 +1568,21 @@ module MakeWithSplitting<
15681568
module BasicBlocks {
15691569
private import codeql.controlflow.BasicBlock as BB
15701570

1571+
private class CfgScopeAlias = CfgScope;
1572+
15711573
private class NodeAlias = Node;
15721574

15731575
private module BasicBlockInputSig implements BB::InputSig<Location> {
15741576
class SuccessorType = Input::SuccessorType;
15751577

15761578
predicate successorTypeIsCondition = Input::successorTypeIsCondition/1;
15771579

1580+
class CfgScope = CfgScopeAlias;
1581+
15781582
class Node = NodeAlias;
15791583

1584+
CfgScope nodeGetCfgScope(Node node) { result = node.getScope() }
1585+
15801586
Node nodeGetASuccessor(Node node, SuccessorType t) { result = node.getASuccessor(t) }
15811587

15821588
predicate nodeIsDominanceEntry(Node node) { node instanceof EntryNode }
@@ -1586,84 +1592,7 @@ module MakeWithSplitting<
15861592

15871593
private module BasicBlockImpl = BB::Make<Location, BasicBlockInputSig>;
15881594

1589-
/**
1590-
* A basic block, that is, a maximal straight-line sequence of control flow nodes
1591-
* without branches or joins.
1592-
*/
1593-
final class BasicBlock extends BasicBlockImpl::BasicBlock {
1594-
/** Gets the scope of this basic block. */
1595-
CfgScope getScope() { result = this.getFirstNode().getScope() }
1596-
1597-
/** Gets an immediate successor of this basic block, if any. */
1598-
BasicBlock getASuccessor() { result = super.getASuccessor() }
1599-
1600-
/** Gets an immediate successor of this basic block of a given type, if any. */
1601-
BasicBlock getASuccessor(SuccessorType t) { result = super.getASuccessor(t) }
1602-
1603-
/** Gets an immediate predecessor of this basic block, if any. */
1604-
BasicBlock getAPredecessor() { result = super.getAPredecessor() }
1605-
1606-
/** Gets an immediate predecessor of this basic block of a given type, if any. */
1607-
BasicBlock getAPredecessor(SuccessorType t) { result = super.getAPredecessor(t) }
1608-
1609-
/**
1610-
* Holds if this basic block immediately dominates basic block `bb`.
1611-
*
1612-
* That is, `bb` is an immediate successor of this basic block and all
1613-
* paths reaching basic block `bb` from some entry point basic block must
1614-
* go through this basic block.
1615-
*/
1616-
predicate immediatelyDominates(BasicBlock bb) { super.immediatelyDominates(bb) }
1617-
1618-
/**
1619-
* Holds if this basic block strictly dominates basic block `bb`.
1620-
*
1621-
* That is, all paths reaching `bb` from some entry point basic block must
1622-
* go through this basic block and this basic block is different from `bb`.
1623-
*/
1624-
predicate strictlyDominates(BasicBlock bb) { super.strictlyDominates(bb) }
1625-
1626-
/**
1627-
* Holds if this basic block dominates basic block `bb`.
1628-
*
1629-
* That is, all paths reaching `bb` from some entry point basic block must
1630-
* go through this basic block.
1631-
*/
1632-
predicate dominates(BasicBlock bb) { super.dominates(bb) }
1633-
1634-
/**
1635-
* Holds if `df` is in the dominance frontier of this basic block. That is,
1636-
* this basic block dominates a predecessor of `df`, but does not dominate
1637-
* `df` itself.
1638-
*/
1639-
predicate inDominanceFrontier(BasicBlock df) { super.inDominanceFrontier(df) }
1640-
1641-
/**
1642-
* Gets the basic block that immediately dominates this basic block, if any.
1643-
*
1644-
* That is, all paths reaching this basic block from some entry point
1645-
* basic block must go through the result, which is an immediate basic block
1646-
* predecessor of this basic block.
1647-
*/
1648-
BasicBlock getImmediateDominator() { result = super.getImmediateDominator() }
1649-
1650-
/**
1651-
* Holds if this basic block strictly post-dominates basic block `bb`.
1652-
*
1653-
* That is, all paths reaching a normal exit point basic block from basic
1654-
* block `bb` must go through this basic block and this basic block is
1655-
* different from `bb`.
1656-
*/
1657-
predicate strictlyPostDominates(BasicBlock bb) { super.strictlyPostDominates(bb) }
1658-
1659-
/**
1660-
* Holds if this basic block post-dominates basic block `bb`.
1661-
*
1662-
* That is, all paths reaching a normal exit point basic block from basic
1663-
* block `bb` must go through this basic block.
1664-
*/
1665-
predicate postDominates(BasicBlock bb) { super.postDominates(bb) }
1666-
}
1595+
final class BasicBlock = BasicBlockImpl::BasicBlock;
16671596

16681597
/**
16691598
* An entry basic block, that is, a basic block whose first node is

0 commit comments

Comments
 (0)