mirror of
https://github.com/github/codeql.git
synced 2026-04-24 08:15:14 +02:00
Swift: introduce Node.asPattern()
This commit is contained in:
@@ -118,6 +118,16 @@ class ExprCfgNode extends CfgNode {
|
||||
Expr getExpr() { result = e }
|
||||
}
|
||||
|
||||
/** A control-flow node that wraps a pattern. */
|
||||
class PatternCfgNode extends CfgNode {
|
||||
Pattern p;
|
||||
|
||||
PatternCfgNode() { p = this.getNode().asAstNode() }
|
||||
|
||||
/** Gets the underlying pattern. */
|
||||
Pattern getPattern() { result = p }
|
||||
}
|
||||
|
||||
/** A control-flow node that wraps a property getter. */
|
||||
class PropertyGetterCfgNode extends CfgNode {
|
||||
override PropertyGetterElement n;
|
||||
|
||||
@@ -40,6 +40,14 @@ private class ExprNodeImpl extends ExprNode, NodeImpl {
|
||||
override DataFlowCallable getEnclosingCallable() { result = TDataFlowFunc(n.getScope()) }
|
||||
}
|
||||
|
||||
private class PatternNodeImpl extends PatternNode, NodeImpl {
|
||||
override Location getLocationImpl() { result = pattern.getLocation() }
|
||||
|
||||
override string toStringImpl() { result = pattern.toString() }
|
||||
|
||||
override DataFlowCallable getEnclosingCallable() { result = TDataFlowFunc(n.getScope()) }
|
||||
}
|
||||
|
||||
private class SsaDefinitionNodeImpl extends SsaDefinitionNode, NodeImpl {
|
||||
override Location getLocationImpl() { result = def.getLocation() }
|
||||
|
||||
@@ -63,6 +71,7 @@ private module Cached {
|
||||
cached
|
||||
newtype TNode =
|
||||
TExprNode(CfgNode n, Expr e) { hasExprNode(n, e) } or
|
||||
TPatternNode(CfgNode n, Pattern p) { hasPatternNode(n, p) } or
|
||||
TSsaDefinitionNode(Ssa::Definition def) or
|
||||
TInoutReturnNode(ParamDecl param) { modifiableParam(param) } or
|
||||
TSummaryNode(FlowSummary::SummarizedCallable c, FlowSummaryImpl::Private::SummaryNodeState state) {
|
||||
@@ -231,6 +240,11 @@ private predicate hasExprNode(CfgNode n, Expr e) {
|
||||
n.(PropertyObserverCfgNode).getAssignExpr() = e
|
||||
}
|
||||
|
||||
private predicate hasPatternNode(PatternCfgNode n, Pattern p) {
|
||||
n.getPattern() = p and
|
||||
p = p.resolve() // no need to turn hidden-AST patterns (`let`s, parens) into data flow nodes
|
||||
}
|
||||
|
||||
import Cached
|
||||
|
||||
/** Holds if `n` should be hidden from path explanations. */
|
||||
|
||||
@@ -37,6 +37,11 @@ class Node extends TNode {
|
||||
*/
|
||||
Expr asExpr() { none() }
|
||||
|
||||
/**
|
||||
* Gets this node's underlying pattern, if any.
|
||||
*/
|
||||
Pattern asPattern() { none() }
|
||||
|
||||
/**
|
||||
* Gets this data flow node's corresponding control flow node.
|
||||
*/
|
||||
@@ -66,6 +71,20 @@ class ExprNode extends Node, TExprNode {
|
||||
override ControlFlowNode getCfgNode() { result = n }
|
||||
}
|
||||
|
||||
/**
|
||||
* A pattern, viewed as a node in a data flow graph.
|
||||
*/
|
||||
class PatternNode extends Node, TPatternNode {
|
||||
CfgNode n;
|
||||
Pattern pattern;
|
||||
|
||||
PatternNode() { this = TPatternNode(n, pattern) }
|
||||
|
||||
override Pattern asPattern() { result = pattern }
|
||||
|
||||
override ControlFlowNode getCfgNode() { result = n }
|
||||
}
|
||||
|
||||
/**
|
||||
* The value of a parameter at function entry, viewed as a node in a data
|
||||
* flow graph.
|
||||
|
||||
Reference in New Issue
Block a user