|
1 | 1 | /** Provides classes and predicates for defining flow summaries. */ |
2 | 2 |
|
3 | 3 | import csharp |
4 | | -private import dotnet |
5 | 4 | private import internal.FlowSummaryImpl as Impl |
6 | 5 | private import internal.DataFlowDispatch as DataFlowDispatch |
7 | | -private import Impl::Public::SummaryComponent as SummaryComponentInternal |
8 | 6 |
|
9 | | -class ParameterPosition = DataFlowDispatch::ParameterPosition; |
| 7 | +deprecated class ParameterPosition = DataFlowDispatch::ParameterPosition; |
10 | 8 |
|
11 | | -class ArgumentPosition = DataFlowDispatch::ArgumentPosition; |
| 9 | +deprecated class ArgumentPosition = DataFlowDispatch::ArgumentPosition; |
12 | 10 |
|
13 | | -// import all instances below |
14 | | -private module Summaries { |
15 | | - private import semmle.code.csharp.frameworks.EntityFramework |
16 | | -} |
| 11 | +deprecated class SummaryComponent = Impl::Private::SummaryComponent; |
17 | 12 |
|
18 | | -class SummaryComponent = Impl::Public::SummaryComponent; |
| 13 | +deprecated module SummaryComponent = Impl::Private::SummaryComponent; |
19 | 14 |
|
20 | | -/** Provides predicates for constructing summary components. */ |
21 | | -module SummaryComponent { |
22 | | - predicate content = SummaryComponentInternal::content/1; |
| 15 | +deprecated class SummaryComponentStack = Impl::Private::SummaryComponentStack; |
23 | 16 |
|
24 | | - /** Gets a summary component for parameter `i`. */ |
25 | | - SummaryComponent parameter(int i) { |
26 | | - exists(ArgumentPosition pos | |
27 | | - result = SummaryComponentInternal::parameter(pos) and |
28 | | - i = pos.getPosition() |
29 | | - ) |
30 | | - } |
| 17 | +deprecated module SummaryComponentStack = Impl::Private::SummaryComponentStack; |
31 | 18 |
|
32 | | - /** Gets a summary component for argument `i`. */ |
33 | | - SummaryComponent argument(int i) { |
34 | | - exists(ParameterPosition pos | |
35 | | - result = SummaryComponentInternal::argument(pos) and |
36 | | - i = pos.getPosition() |
37 | | - ) |
38 | | - } |
39 | | - |
40 | | - predicate return = SummaryComponentInternal::return/1; |
41 | | - |
42 | | - /** Gets a summary component that represents a qualifier. */ |
43 | | - SummaryComponent qualifier() { |
44 | | - exists(ParameterPosition pos | |
45 | | - result = SummaryComponentInternal::argument(pos) and |
46 | | - pos.isThisParameter() |
47 | | - ) |
48 | | - } |
49 | | - |
50 | | - /** Gets a summary component that represents an element in a collection. */ |
51 | | - SummaryComponent element() { result = content(any(DataFlow::ElementContent c)) } |
52 | | - |
53 | | - /** Gets a summary component for property `p`. */ |
54 | | - SummaryComponent property(Property p) { |
55 | | - result = content(any(DataFlow::PropertyContent c | c.getProperty() = p.getUnboundDeclaration())) |
56 | | - } |
57 | | - |
58 | | - /** Gets a summary component for field `f`. */ |
59 | | - SummaryComponent field(Field f) { |
60 | | - result = content(any(DataFlow::FieldContent c | c.getField() = f.getUnboundDeclaration())) |
61 | | - } |
62 | | - |
63 | | - /** Gets a summary component that represents the return value of a call. */ |
64 | | - SummaryComponent return() { result = return(any(DataFlowDispatch::NormalReturnKind rk)) } |
65 | | - |
66 | | - predicate syntheticGlobal = SummaryComponentInternal::syntheticGlobal/1; |
67 | | - |
68 | | - class SyntheticGlobal = SummaryComponentInternal::SyntheticGlobal; |
69 | | -} |
70 | | - |
71 | | -class SummaryComponentStack = Impl::Public::SummaryComponentStack; |
72 | | - |
73 | | -/** Provides predicates for constructing stacks of summary components. */ |
74 | | -module SummaryComponentStack { |
75 | | - private import Impl::Public::SummaryComponentStack as SummaryComponentStackInternal |
76 | | - |
77 | | - predicate singleton = SummaryComponentStackInternal::singleton/1; |
78 | | - |
79 | | - predicate push = SummaryComponentStackInternal::push/2; |
80 | | - |
81 | | - /** Gets a singleton stack for argument `i`. */ |
82 | | - SummaryComponentStack argument(int i) { result = singleton(SummaryComponent::argument(i)) } |
83 | | - |
84 | | - predicate return = SummaryComponentStackInternal::return/1; |
85 | | - |
86 | | - /** Gets a singleton stack representing a qualifier. */ |
87 | | - SummaryComponentStack qualifier() { result = singleton(SummaryComponent::qualifier()) } |
88 | | - |
89 | | - /** Gets a stack representing an element of `container`. */ |
90 | | - SummaryComponentStack elementOf(SummaryComponentStack container) { |
91 | | - result = push(SummaryComponent::element(), container) |
92 | | - } |
93 | | - |
94 | | - /** Gets a stack representing a property `p` of `object`. */ |
95 | | - SummaryComponentStack propertyOf(Property p, SummaryComponentStack object) { |
96 | | - result = push(SummaryComponent::property(p), object) |
97 | | - } |
98 | | - |
99 | | - /** Gets a stack representing a field `f` of `object`. */ |
100 | | - SummaryComponentStack fieldOf(Field f, SummaryComponentStack object) { |
101 | | - result = push(SummaryComponent::field(f), object) |
102 | | - } |
103 | | - |
104 | | - /** Gets a singleton stack representing the return value of a call. */ |
105 | | - SummaryComponentStack return() { result = singleton(SummaryComponent::return()) } |
106 | | - |
107 | | - /** Gets a singleton stack representing a synthetic global with name `name`. */ |
108 | | - SummaryComponentStack syntheticGlobal(string synthetic) { |
109 | | - result = singleton(SummaryComponent::syntheticGlobal(synthetic)) |
110 | | - } |
111 | | - |
112 | | - /** |
113 | | - * DEPRECATED: Use the member predicate `getMadRepresentation` instead. |
114 | | - * |
115 | | - * Gets a textual representation of this stack used for flow summaries. |
116 | | - */ |
117 | | - deprecated string getComponentStack(SummaryComponentStack s) { result = s.getMadRepresentation() } |
118 | | -} |
| 19 | +deprecated class RequiredSummaryComponentStack = Impl::Private::RequiredSummaryComponentStack; |
119 | 20 |
|
120 | 21 | class SummarizedCallable = Impl::Public::SummarizedCallable; |
121 | 22 |
|
122 | | -private predicate recordConstructorFlow(Constructor c, int i, Property p) { |
123 | | - c = any(RecordType r).getAMember() and |
124 | | - exists(string name | |
125 | | - c.getParameter(i).getName() = name and |
126 | | - c.getDeclaringType().getAMember(name) = p |
127 | | - ) |
128 | | -} |
129 | | - |
130 | | -private class RecordConstructorFlow extends SummarizedCallable { |
131 | | - RecordConstructorFlow() { recordConstructorFlow(this, _, _) } |
132 | | - |
133 | | - override predicate propagatesFlow( |
134 | | - SummaryComponentStack input, SummaryComponentStack output, boolean preservesValue |
135 | | - ) { |
136 | | - exists(int i, Property p | |
137 | | - recordConstructorFlow(this, i, p) and |
138 | | - input = SummaryComponentStack::argument(i) and |
139 | | - output = SummaryComponentStack::propertyOf(p, SummaryComponentStack::return()) and |
140 | | - preservesValue = true |
141 | | - ) |
142 | | - } |
143 | | -} |
144 | | - |
145 | | -class RequiredSummaryComponentStack = Impl::Public::RequiredSummaryComponentStack; |
146 | | - |
147 | | -private class RecordConstructorFlowRequiredSummaryComponentStack extends RequiredSummaryComponentStack |
148 | | -{ |
149 | | - override predicate required(SummaryComponent head, SummaryComponentStack tail) { |
150 | | - exists(Property p | |
151 | | - recordConstructorFlow(_, _, p) and |
152 | | - head = SummaryComponent::property(p) and |
153 | | - tail = SummaryComponentStack::return() |
154 | | - ) |
155 | | - } |
156 | | -} |
157 | | - |
158 | 23 | class Provenance = Impl::Public::Provenance; |
159 | | - |
160 | | -private import semmle.code.csharp.frameworks.system.linq.Expressions |
161 | | - |
162 | | -private SummaryComponent delegateSelf() { |
163 | | - exists(ArgumentPosition pos | |
164 | | - result = SummaryComponentInternal::parameter(pos) and |
165 | | - pos.isDelegateSelf() |
166 | | - ) |
167 | | -} |
168 | | - |
169 | | -private predicate mayInvokeCallback(Callable c, int n) { |
170 | | - c.getParameter(n).getType() instanceof SystemLinqExpressions::DelegateExtType and |
171 | | - not c.hasBody() and |
172 | | - (if c instanceof Accessor then not c.fromSource() else any()) |
173 | | -} |
174 | | - |
175 | | -private class SummarizedCallableWithCallback extends SummarizedCallable { |
176 | | - private int pos; |
177 | | - |
178 | | - SummarizedCallableWithCallback() { mayInvokeCallback(this, pos) } |
179 | | - |
180 | | - override predicate propagatesFlow( |
181 | | - SummaryComponentStack input, SummaryComponentStack output, boolean preservesValue |
182 | | - ) { |
183 | | - input = SummaryComponentStack::argument(pos) and |
184 | | - output = SummaryComponentStack::push(delegateSelf(), input) and |
185 | | - preservesValue = true |
186 | | - } |
187 | | - |
188 | | - override predicate hasProvenance(Provenance provenance) { provenance = "hq-generated" } |
189 | | -} |
190 | | - |
191 | | -private class RequiredComponentStackForCallback extends RequiredSummaryComponentStack { |
192 | | - override predicate required(SummaryComponent head, SummaryComponentStack tail) { |
193 | | - exists(int pos | |
194 | | - mayInvokeCallback(_, pos) and |
195 | | - head = delegateSelf() and |
196 | | - tail = SummaryComponentStack::argument(pos) |
197 | | - ) |
198 | | - } |
199 | | -} |
0 commit comments