Skip to content

Commit 117a1ad

Browse files
authored
Swift: DataFlow expr and parameter nodes
1 parent 47051ec commit 117a1ad

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

swift/ql/lib/codeql/swift/dataflow/internal/DataFlowPrivate.qll

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
private import swift
22
private import DataFlowPublic
33
private import DataFlowDispatch
4+
private import codeql.swift.controlflow.CfgNodes
45

56
/** Gets the callable in which this node occurs. */
67
DataFlowCallable nodeGetEnclosingCallable(NodeImpl n) { result = n.getEnclosingCallable() }
@@ -25,11 +26,19 @@ abstract class NodeImpl extends Node {
2526
abstract string toStringImpl();
2627
}
2728

29+
private class ExprNodeImpl extends ExprNode, NodeImpl {
30+
override Location getLocationImpl() { result = expr.getLocation() }
31+
32+
override string toStringImpl() { result = expr.toString() }
33+
}
34+
2835
/** A collection of cached types and predicates to be evaluated in the same stage. */
2936
cached
3037
private module Cached {
3138
cached
32-
newtype TNode = TODO_TNode()
39+
newtype TNode =
40+
TExprNode(ExprCfgNode e) or
41+
TNormalParameterNode(ParamDecl p)
3342

3443
/**
3544
* This is the local flow predicate that is used as a building block in global
@@ -58,6 +67,20 @@ private module ParameterNodes {
5867
abstract class ParameterNodeImpl extends NodeImpl {
5968
predicate isParameterOf(DataFlowCallable c, ParameterPosition pos) { none() }
6069
}
70+
71+
class NormalParameterNode extends ParameterNodeImpl, TNormalParameterNode {
72+
ParamDecl param;
73+
74+
NormalParameterNode() { this = TNormalParameterNode(param) }
75+
76+
override Location getLocationImpl() { result = param.getLocation() }
77+
78+
override string toStringImpl() { result = param.toString() }
79+
80+
override predicate isParameterOf(DataFlowCallable c, ParameterPosition pos) {
81+
none() // TODO
82+
}
83+
}
6184
}
6285

6386
import ParameterNodes
@@ -173,7 +196,9 @@ class Unit extends TUnit {
173196
*/
174197
predicate isUnreachableInCall(Node n, DataFlowCall call) { none() }
175198

176-
newtype LambdaCallKind = TODO_TLambdaCallKind()
199+
newtype LambdaCallKind =
200+
TYieldCallKind() or
201+
TLambdaCallKind()
177202

178203
/** Holds if `creation` is an expression that creates a lambda of kind `kind` for `c`. */
179204
predicate lambdaCreation(Node creation, LambdaCallKind kind, DataFlowCallable c) { none() }

swift/ql/lib/codeql/swift/dataflow/internal/DataFlowPublic.qll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ private import DataFlowDispatch
33
private import DataFlowPrivate
44
private import codeql.swift.controlflow.ControlFlowGraph
55
private import codeql.swift.controlflow.BasicBlocks
6+
private import codeql.swift.controlflow.CfgNodes
67

78
/**
89
* An element, viewed as a node in a data flow graph. Either an expression
@@ -38,7 +39,11 @@ class Node extends TNode {
3839
* to multiple `ExprNode`s, just like it may correspond to multiple
3940
* `ControlFlow::Node`s.
4041
*/
41-
class ExprNode extends Node { }
42+
class ExprNode extends Node {
43+
ExprCfgNode expr;
44+
45+
ExprNode() { this = TExprNode(expr) }
46+
}
4247

4348
/**
4449
* The value of a parameter at function entry, viewed as a node in a data

0 commit comments

Comments
 (0)