22 * Provides classes and predicates for defining flow summaries.
33 */
44
5- private import swift
5+ private import cpp
66private import codeql.dataflow.internal.FlowSummaryImpl
77private import codeql.dataflow.internal.AccessPathSyntax as AccessPath
8- private import DataFlowImplSpecific as DataFlowImplSpecific
9- private import DataFlowImplSpecific:: Private
10- private import DataFlowImplSpecific:: Public
11- private import DataFlowImplCommon
12- private import codeql.swift.dataflow.ExternalFlow
8+ private import semmle.code.cpp.ir.dataflow.internal.DataFlowPrivate
9+ private import semmle.code.cpp.ir.dataflow.internal.DataFlowUtil
10+ private import semmle.code.cpp.ir.dataflow.internal.DataFlowImplSpecific as DataFlowImplSpecific
11+ private import semmle.code.cpp.dataflow.ExternalFlow
1312
14- module Input implements InputSig< DataFlowImplSpecific:: SwiftDataFlow > {
13+ module Input implements InputSig< DataFlowImplSpecific:: CppDataFlow > {
1514 class SummarizedCallableBase = Function ;
1615
17- ArgumentPosition callbackSelfParameterPosition ( ) { result instanceof ThisArgumentPosition }
16+ ArgumentPosition callbackSelfParameterPosition ( ) { result = TDirectPosition ( - 1 ) }
1817
19- ReturnKind getStandardReturnValueKind ( ) { result instanceof NormalReturnKind }
18+ ReturnKind getStandardReturnValueKind ( ) { result . ( NormalReturnKind ) . getIndirectionIndex ( ) = 0 }
2019
2120 string encodeParameterPosition ( ParameterPosition pos ) { result = pos .toString ( ) }
2221
@@ -29,63 +28,54 @@ module Input implements InputSig<DataFlowImplSpecific::SwiftDataFlow> {
2928 }
3029
3130 string encodeContent ( ContentSet cs , string arg ) {
32- exists ( Content :: FieldContent c |
31+ exists ( FieldContent c |
3332 cs .isSingleton ( c ) and
3433 result = "Field" and
3534 arg = c .getField ( ) .getName ( )
3635 )
37- or
38- exists ( Content:: TupleContent c |
39- cs .isSingleton ( c ) and
40- result = "TupleElement" and
41- arg = c .getIndex ( ) .toString ( )
42- )
43- or
44- exists ( Content:: EnumContent c , string sig |
45- cs .isSingleton ( c ) and
46- sig = c .getSignature ( )
47- |
48- if sig = "some:0"
49- then
50- result = "OptionalSome" and
51- arg = ""
52- else (
53- result = "EnumElement" and
54- arg = sig
55- )
56- )
57- or
58- exists ( Content:: CollectionContent c |
59- cs .isSingleton ( c ) and
60- result = "CollectionElement" and
61- arg = ""
62- )
63- }
36+ /*
37+ * or
38+ * exists(Content::TupleContent c |
39+ * cs.isSingleton(c) and
40+ * result = "TupleElement" and
41+ * arg = c.getIndex().toString()
42+ * )
43+ * or
44+ * exists(Content::EnumContent c, string sig |
45+ * cs.isSingleton(c) and
46+ * sig = c.getSignature()
47+ * |
48+ * if sig = "some:0"
49+ * then
50+ * result = "OptionalSome" and
51+ * arg = ""
52+ * else (
53+ * result = "EnumElement" and
54+ * arg = sig
55+ * )
56+ * )
57+ * or
58+ * exists(Content::CollectionContent c |
59+ * cs.isSingleton(c) and
60+ * result = "CollectionElement" and
61+ * arg = ""
62+ * )
63+ */
64+
65+ }
6466
6567 string encodeWithoutContent ( ContentSet c , string arg ) {
6668 result = "WithoutContent" + c and arg = ""
6769 }
6870
6971 string encodeWithContent ( ContentSet c , string arg ) { result = "WithContent" + c and arg = "" }
7072
71- bindingset [ token]
72- ContentSet decodeUnknownContent ( AccessPath:: AccessPathTokenBase token ) {
73- // map legacy "ArrayElement" specification components to `CollectionContent`
74- token .getName ( ) = "ArrayElement" and
75- result .isSingleton ( any ( Content:: CollectionContent c ) )
76- or
77- token .getName ( ) = "CollectionElement" and
78- result .isSingleton ( any ( Content:: CollectionContent c ) )
79- }
80-
8173 bindingset [ token]
8274 ParameterPosition decodeUnknownParameterPosition ( AccessPath:: AccessPathTokenBase token ) {
8375 // needed to support `Argument[x..y]` ranges and `Argument[-1]`
8476 token .getName ( ) = "Argument" and
8577 exists ( int pos | pos = AccessPath:: parseInt ( token .getAnArgument ( ) ) |
86- result .( PositionalParameterPosition ) .getIndex ( ) = pos
87- or
88- pos = - 1 and result instanceof ThisParameterPosition
78+ result = TDirectPosition ( pos )
8979 )
9080 }
9181
@@ -94,24 +84,21 @@ module Input implements InputSig<DataFlowImplSpecific::SwiftDataFlow> {
9484 // needed to support `Parameter[x..y]` ranges and `Parameter[-1]`
9585 token .getName ( ) = "Parameter" and
9686 exists ( int pos | pos = AccessPath:: parseInt ( token .getAnArgument ( ) ) |
97- result .( PositionalArgumentPosition ) .getIndex ( ) = pos
98- or
99- pos = - 1 and
100- result instanceof ThisArgumentPosition
87+ result = TDirectPosition ( pos )
10188 )
10289 }
10390}
10491
105- private import Make< DataFlowImplSpecific:: SwiftDataFlow , Input > as Impl
92+ /* private*/ import Make< DataFlowImplSpecific:: CppDataFlow , Input > as Impl
10693
10794private module StepsInput implements Impl:: Private:: StepsInputSig {
108- DataFlowCall getACall ( Public:: SummarizedCallable sc ) { result .asCall ( ) . getStaticTarget ( ) = sc }
95+ DataFlowCall getACall ( Public:: SummarizedCallable sc ) { result .getStaticCallTarget ( ) = sc }
10996}
11097
11198module SourceSinkInterpretationInput implements
11299 Impl:: Private:: External:: SourceSinkInterpretationInputSig< Location >
113100{
114- class Element = AstNode ;
101+ class Element = Element ;
115102
116103 class SourceOrSinkElement = Element ;
117104
@@ -158,10 +145,12 @@ module SourceSinkInterpretationInput implements
158145 DataFlowCall asCall ( ) { this = TDataFlowCall_ ( result ) }
159146
160147 /** Gets the callable that this node corresponds to, if any. */
161- DataFlowCallable asCallable ( ) { result .getUnderlyingCallable ( ) = this .asElement ( ) }
148+ DataFlowCallable asCallable ( ) { result .( Function ) = this .asElement ( ) }
162149
163150 /** Gets the target of this call, if any. */
164- Element getCallTarget ( ) { result = this .asCall ( ) .asCall ( ) .getStaticTarget ( ) }
151+ Element getCallTarget ( ) {
152+ result = this .asNode ( ) .asExpr ( ) .( Call ) .getTarget ( )
153+ }
165154
166155 /** Gets a textual representation of this node. */
167156 string toString ( ) {
@@ -186,31 +175,31 @@ module SourceSinkInterpretationInput implements
186175 bindingset [ c]
187176 predicate interpretOutput ( string c , InterpretNode mid , InterpretNode node ) {
188177 // Allow fields to be picked as output nodes.
189- exists ( Node n , AstNode ast |
178+ exists ( Node n , Element ast |
190179 n = node .asNode ( ) and
191180 ast = mid .asElement ( )
192181 |
193182 c = "" and
194- n .asExpr ( ) .( MemberRefExpr ) . getMember ( ) = ast
183+ n .asExpr ( ) .( VariableAccess ) . getTarget ( ) = ast
195184 )
196185 }
197186
198187 /** Provides additional source specification logic. */
199188 bindingset [ c]
200189 predicate interpretInput ( string c , InterpretNode mid , InterpretNode node ) {
201- exists ( Node n , AstNode ast , MemberRefExpr e |
190+ exists ( Node n , Element ast , VariableAccess e |
202191 n = node .asNode ( ) and
203192 ast = mid .asElement ( ) and
204- e .getMember ( ) = ast
193+ e .getTarget ( ) = ast
205194 |
206195 // Allow fields to be picked as input nodes.
207196 c = "" and
208- e .getBase ( ) = n .asExpr ( )
197+ e .getQualifier ( ) = n .asExpr ( )
209198 or
210199 // Allow post update nodes to be picked as input nodes when the `input` column
211200 // of the row is `PostUpdate`.
212201 c = "PostUpdate" and
213- e .getBase ( ) = n .( PostUpdateNode ) .getPreUpdateNode ( ) .asExpr ( )
202+ e .getQualifier ( ) = n .( PostUpdateNode ) .getPreUpdateNode ( ) .asExpr ( )
214203 )
215204 }
216205}
0 commit comments