44
55import java
66private import internal.FlowSummaryImpl as Impl
7- private import internal.DataFlowDispatch
87private import internal.DataFlowUtil
98
109// import all instances of SummarizedCallable below
@@ -24,6 +23,12 @@ module SummaryComponent {
2423 /** Gets a summary component for field `f`. */
2524 SummaryComponent field ( Field f ) { result = content ( any ( FieldContent c | c .getField ( ) = f ) ) }
2625
26+ /** Gets a summary component for `Element`. */
27+ SummaryComponent element ( ) { result = content ( any ( CollectionContent c ) ) }
28+
29+ /** Gets a summary component for `MapValue`. */
30+ SummaryComponent mapValue ( ) { result = content ( any ( MapValueContent c ) ) }
31+
2732 /** Gets a summary component that represents the return value of a call. */
2833 SummaryComponent return ( ) { result = return ( _) }
2934}
@@ -42,10 +47,129 @@ module SummaryComponentStack {
4247 result = push ( SummaryComponent:: field ( f ) , object )
4348 }
4449
50+ /** Gets a stack representing `Element` of `object`. */
51+ SummaryComponentStack elementOf ( SummaryComponentStack object ) {
52+ result = push ( SummaryComponent:: element ( ) , object )
53+ }
54+
55+ /** Gets a stack representing `MapValue` of `object`. */
56+ SummaryComponentStack mapValueOf ( SummaryComponentStack object ) {
57+ result = push ( SummaryComponent:: mapValue ( ) , object )
58+ }
59+
4560 /** Gets a singleton stack representing a (normal) return. */
4661 SummaryComponentStack return ( ) { result = singleton ( SummaryComponent:: return ( ) ) }
4762}
4863
64+ /** A synthetic callable with a set of concrete call sites and a flow summary. */
65+ abstract class SyntheticCallable extends string {
66+ bindingset [ this ]
67+ SyntheticCallable ( ) { any ( ) }
68+
69+ /** Gets a call that targets this callable. */
70+ abstract Call getACall ( ) ;
71+
72+ /**
73+ * Holds if data may flow from `input` to `output` through this callable.
74+ *
75+ * See `SummarizedCallable::propagatesFlow` for details.
76+ */
77+ predicate propagatesFlow (
78+ SummaryComponentStack input , SummaryComponentStack output , boolean preservesValue
79+ ) {
80+ none ( )
81+ }
82+
83+ /**
84+ * Gets the type of the parameter at the specified position with -1 indicating
85+ * the instance parameter. If no types are provided then the types default to
86+ * `Object`.
87+ */
88+ Type getParameterType ( int pos ) { none ( ) }
89+
90+ /**
91+ * Gets the return type of this callable. If no type is provided then the type
92+ * defaults to `Object`.
93+ */
94+ Type getReturnType ( ) { none ( ) }
95+ }
96+
97+ private newtype TSummarizedCallableBase =
98+ TSimpleCallable ( Callable c ) { c .isSourceDeclaration ( ) } or
99+ TSyntheticCallable ( SyntheticCallable c )
100+
101+ /**
102+ * A callable that may have a flow summary. This is either a regular `Callable`
103+ * or a `SyntheticCallable`.
104+ */
105+ class SummarizedCallableBase extends TSummarizedCallableBase {
106+ /** Gets a textual representation of this callable. */
107+ string toString ( ) { result = this .asCallable ( ) .toString ( ) or result = this .asSyntheticCallable ( ) }
108+
109+ /** Gets the source location for this callable. */
110+ Location getLocation ( ) {
111+ result = this .asCallable ( ) .getLocation ( )
112+ or
113+ result .hasLocationInfo ( "" , 0 , 0 , 0 , 0 ) and
114+ this instanceof TSyntheticCallable
115+ }
116+
117+ /** Gets this callable cast as a `Callable`. */
118+ Callable asCallable ( ) { this = TSimpleCallable ( result ) }
119+
120+ /** Gets this callable cast as a `SyntheticCallable`. */
121+ SyntheticCallable asSyntheticCallable ( ) { this = TSyntheticCallable ( result ) }
122+
123+ /** Gets a call that targets this callable. */
124+ Call getACall ( ) {
125+ result .getCallee ( ) .getSourceDeclaration ( ) = this .asCallable ( )
126+ or
127+ result = this .asSyntheticCallable ( ) .getACall ( )
128+ }
129+
130+ /**
131+ * Gets the type of the parameter at the specified position with -1 indicating
132+ * the instance parameter.
133+ */
134+ Type getParameterType ( int pos ) {
135+ result = this .asCallable ( ) .getParameterType ( pos )
136+ or
137+ pos = - 1 and result = this .asCallable ( ) .getDeclaringType ( )
138+ or
139+ result = this .asSyntheticCallable ( ) .getParameterType ( pos )
140+ or
141+ exists ( SyntheticCallable sc | sc = this .asSyntheticCallable ( ) |
142+ Impl:: Private:: summaryParameterNodeRange ( this , pos ) and
143+ not exists ( sc .getParameterType ( pos ) ) and
144+ result instanceof TypeObject
145+ )
146+ }
147+
148+ /** Gets the return type of this callable. */
149+ Type getReturnType ( ) {
150+ result = this .asCallable ( ) .getReturnType ( )
151+ or
152+ exists ( SyntheticCallable sc | sc = this .asSyntheticCallable ( ) |
153+ result = sc .getReturnType ( )
154+ or
155+ not exists ( sc .getReturnType ( ) ) and
156+ result instanceof TypeObject
157+ )
158+ }
159+ }
160+
49161class SummarizedCallable = Impl:: Public:: SummarizedCallable ;
50162
163+ /**
164+ * An adapter class to add the flow summaries specified on `SyntheticCallable`
165+ * to `SummarizedCallable`.
166+ */
167+ private class SummarizedSyntheticCallableAdapter extends SummarizedCallable , TSyntheticCallable {
168+ override predicate propagatesFlow (
169+ SummaryComponentStack input , SummaryComponentStack output , boolean preservesValue
170+ ) {
171+ this .asSyntheticCallable ( ) .propagatesFlow ( input , output , preservesValue )
172+ }
173+ }
174+
51175class RequiredSummaryComponentStack = Impl:: Public:: RequiredSummaryComponentStack ;
0 commit comments