Skip to content

Swift: switch to shared, parameterized CFG library #15219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions swift/ql/lib/codeql/swift/controlflow/BasicBlocks.qll
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

private import swift
private import ControlFlowGraph
private import internal.ControlFlowGraphImpl
private import internal.ControlFlowGraphImpl as Impl
private import internal.ControlFlowElements
private import CfgNodes
private import SuccessorTypes
Expand Down Expand Up @@ -133,7 +133,7 @@ private module Cached {
private predicate predBB(BasicBlock succ, BasicBlock pred) { succBB(pred, succ) }

/** Holds if `bb` is an exit basic block that represents normal exit. */
private predicate normalExitBB(BasicBlock bb) { bb.getANode().(AnnotatedExitNode).isNormal() }
private predicate normalExitBB(BasicBlock bb) { bb.getANode().(Impl::AnnotatedExitNode).isNormal() }

/** Holds if `dom` is an immediate post-dominator of `bb`. */
cached
Expand Down Expand Up @@ -178,7 +178,7 @@ class AnnotatedExitBasicBlock extends BasicBlock {
private boolean normal;

AnnotatedExitBasicBlock() {
exists(AnnotatedExitNode n |
exists(Impl::AnnotatedExitNode n |
n = this.getANode() and
if n.isNormal() then normal = true else normal = false
)
Expand Down
8 changes: 6 additions & 2 deletions swift/ql/lib/codeql/swift/controlflow/CfgNodes.qll
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
private import swift
private import BasicBlocks
private import ControlFlowGraph
private import internal.ControlFlowGraphImpl
private import internal.ControlFlowGraphImpl as Impl
private import internal.ControlFlowElements
private import internal.Splitting

Expand All @@ -14,7 +14,7 @@ private import internal.Splitting
* (dead) code or not important for control flow, and multiple when there are different
* splits for the AST node.
*/
class CfgNode extends ControlFlowNode instanceof AstCfgNode {
class CfgNode extends ControlFlowNode instanceof Impl::AstCfgNode {
final override ControlFlowElement getNode() { result = this.getAstNode() }

/** Gets a split for this control flow node, if any. */
Expand Down Expand Up @@ -142,3 +142,7 @@ class KeyPathApplicationExprCfgNode extends ExprCfgNode {
class KeyPathExprCfgNode extends ExprCfgNode {
override KeyPathExpr e;
}

class EntryNode = Impl::EntryNode;

class ExitNode = Impl::ExitNode;
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ module Stmts {
private class DiscardStmtTree extends AstStandardPostOrderTree {
override DiscardStmt ast;

final override ControlFlowElement getChildElement(int i) {
final override ControlFlowElement getChildNode(int i) {
i = 0 and result.asAstNode() = ast.getSubExpr().getFullyUnresolved()
}
}
Expand Down Expand Up @@ -1429,7 +1429,7 @@ module Exprs {
private class SingleValueStmtExprTree extends AstStandardPostOrderTree {
override SingleValueStmtExpr ast;

final override ControlFlowElement getChildElement(int i) {
final override ControlFlowElement getChildNode(int i) {
i = 0 and result.asAstNode() = ast.getStmt()
}
}
Expand All @@ -1438,7 +1438,7 @@ module Exprs {
private class PackExpansionExprTree extends AstStandardPostOrderTree {
override PackExpansionExpr ast;

final override ControlFlowElement getChildElement(int i) {
final override ControlFlowElement getChildNode(int i) {
i = 0 and result.asAstNode() = ast.getPatternExpr().getFullyConverted()
}
}
Expand All @@ -1447,15 +1447,15 @@ module Exprs {
private class PackElementExprTree extends AstStandardPostOrderTree {
override PackElementExpr ast;

final override ControlFlowElement getChildElement(int i) {
final override ControlFlowElement getChildNode(int i) {
i = 0 and result.asAstNode() = ast.getSubExpr().getFullyUnresolved()
}
}

private class MaterializePackExprTree extends AstStandardPostOrderTree {
override MaterializePackExpr ast;

final override ControlFlowElement getChildElement(int i) {
final override ControlFlowElement getChildNode(int i) {
i = 0 and result.asAstNode() = ast.getSubExpr().getFullyUnresolved()
}
}
Expand All @@ -1464,7 +1464,7 @@ module Exprs {
private class CopyExprTree extends AstStandardPostOrderTree {
override CopyExpr ast;

final override ControlFlowElement getChildElement(int i) {
final override ControlFlowElement getChildNode(int i) {
i = 0 and result.asAstNode() = ast.getSubExpr().getFullyUnresolved()
}
}
Expand All @@ -1473,7 +1473,7 @@ module Exprs {
private class ConsumeExprTree extends AstStandardPostOrderTree {
override ConsumeExpr ast;

final override ControlFlowElement getChildElement(int i) {
final override ControlFlowElement getChildNode(int i) {
i = 0 and result.asAstNode() = ast.getSubExpr().getFullyUnresolved()
}
}
Expand Down
2 changes: 1 addition & 1 deletion swift/ql/test/library-tests/controlflow/graph/Cfg.ql
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import codeql.swift.controlflow.internal.ControlFlowGraphImpl::TestOutput
class MyRelevantNode extends RelevantNode {
MyRelevantNode() { this.getScope().getLocation().getFile().getName().matches("%swift/ql/test%") }

private AstNode asAstNode() { result = this.getNode().asAstNode() }
private AstNode asAstNode() { result = this.getAstNode().asAstNode() }

override string getOrderDisambiguation() {
result = this.asAstNode().getPrimaryQlClasses()
Expand Down