11private import swift
22private import DataFlowPublic
33private import DataFlowDispatch
4+ private import codeql.swift.controlflow.CfgNodes
5+ private import codeql.swift.dataflow.Ssa
46
57/** Gets the callable in which this node occurs. */
68DataFlowCallable nodeGetEnclosingCallable ( NodeImpl n ) { result = n .getEnclosingCallable ( ) }
@@ -25,22 +27,54 @@ abstract class NodeImpl extends Node {
2527 abstract string toStringImpl ( ) ;
2628}
2729
30+ private class ExprNodeImpl extends ExprNode , NodeImpl {
31+ override Location getLocationImpl ( ) { result = expr .getLocation ( ) }
32+
33+ override string toStringImpl ( ) { result = expr .toString ( ) }
34+ }
35+
36+ private class SsaDefinitionNodeImpl extends SsaDefinitionNode , NodeImpl {
37+ override Location getLocationImpl ( ) { result = def .getLocation ( ) }
38+
39+ override string toStringImpl ( ) { result = def .toString ( ) }
40+ }
41+
2842/** A collection of cached types and predicates to be evaluated in the same stage. */
2943cached
3044private module Cached {
3145 cached
32- newtype TNode = TODO_TNode ( )
46+ newtype TNode =
47+ TExprNode ( ExprCfgNode e ) or
48+ TNormalParameterNode ( ParamDecl p ) or
49+ TSsaDefinitionNode ( Ssa:: Definition def )
50+
51+ private predicate localFlowStepCommon ( Node nodeFrom , Node nodeTo ) {
52+ exists ( Ssa:: Definition def |
53+ // Step from assignment RHS to def
54+ def .( Ssa:: WriteDefinition ) .assigns ( nodeFrom .getCfgNode ( ) ) and
55+ nodeTo .asDefinition ( ) = def
56+ or
57+ // step from def to first read
58+ nodeFrom .asDefinition ( ) = def and
59+ nodeTo .getCfgNode ( ) = def .getAFirstRead ( )
60+ or
61+ // use-use flow
62+ def .adjacentReadPair ( nodeFrom .getCfgNode ( ) , nodeTo .getCfgNode ( ) )
63+ )
64+ }
3365
3466 /**
3567 * This is the local flow predicate that is used as a building block in global
3668 * data flow.
3769 */
3870 cached
39- predicate simpleLocalFlowStep ( Node nodeFrom , Node nodeTo ) { none ( ) }
71+ predicate simpleLocalFlowStep ( Node nodeFrom , Node nodeTo ) {
72+ localFlowStepCommon ( nodeFrom , nodeTo )
73+ }
4074
4175 /** This is the local flow predicate that is exposed. */
4276 cached
43- predicate localFlowStepImpl ( Node nodeFrom , Node nodeTo ) { none ( ) }
77+ predicate localFlowStepImpl ( Node nodeFrom , Node nodeTo ) { localFlowStepCommon ( nodeFrom , nodeTo ) }
4478
4579 cached
4680 newtype TContentSet = TODO_TContentSet ( )
@@ -58,6 +92,20 @@ private module ParameterNodes {
5892 abstract class ParameterNodeImpl extends NodeImpl {
5993 predicate isParameterOf ( DataFlowCallable c , ParameterPosition pos ) { none ( ) }
6094 }
95+
96+ class NormalParameterNode extends ParameterNodeImpl , TNormalParameterNode {
97+ ParamDecl param ;
98+
99+ NormalParameterNode ( ) { this = TNormalParameterNode ( param ) }
100+
101+ override Location getLocationImpl ( ) { result = param .getLocation ( ) }
102+
103+ override string toStringImpl ( ) { result = param .toString ( ) }
104+
105+ override predicate isParameterOf ( DataFlowCallable c , ParameterPosition pos ) {
106+ none ( ) // TODO
107+ }
108+ }
61109}
62110
63111import ParameterNodes
0 commit comments