Skip to content

Commit 4ee2d62

Browse files
committed
C#: Re-factor printing of summary component stacks.
1 parent d90ddf1 commit 4ee2d62

File tree

4 files changed

+32
-60
lines changed

4 files changed

+32
-60
lines changed

csharp/ql/lib/semmle/code/csharp/dataflow/FlowSummary.qll

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,12 @@ module SummaryComponentStack {
110110
result = singleton(SummaryComponent::syntheticGlobal(synthetic))
111111
}
112112

113-
/** Gets a textual representation of this stack used for flow summaries. */
114-
string getComponentStack(SummaryComponentStack s) { result = Impl::Public::getComponentStack(s) }
113+
/**
114+
* DEPRECATED: Use the member predicate `getAccessPath` instead.
115+
*
116+
* Gets a textual representation of this stack used for flow summaries.
117+
*/
118+
deprecated string getComponentStack(SummaryComponentStack s) { result = s.getAccessPath() }
115119
}
116120

117121
class SummarizedCallable = Impl::Public::SummarizedCallable;

csharp/ql/lib/semmle/code/csharp/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 24 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,30 @@ module Public {
2323
* content type, or a return kind.
2424
*/
2525
class SummaryComponent extends TSummaryComponent {
26-
/** Gets a textual representation of this summary component. */
27-
string toString() {
28-
exists(ContentSet c | this = TContentSummaryComponent(c) and result = c.toString())
29-
or
30-
exists(ContentSet c | this = TWithoutContentSummaryComponent(c) and result = "without " + c)
31-
or
32-
exists(ContentSet c | this = TWithContentSummaryComponent(c) and result = "with " + c)
26+
/** Gets a textual representation of this component used for flow summaries. */
27+
string getAccessStep() {
28+
result = getAccessStepSpecific(this)
3329
or
3430
exists(ArgumentPosition pos |
35-
this = TParameterSummaryComponent(pos) and result = "parameter " + pos
31+
this = TParameterSummaryComponent(pos) and
32+
result = "Parameter[" + getArgumentPosition(pos) + "]"
3633
)
3734
or
3835
exists(ParameterPosition pos |
39-
this = TArgumentSummaryComponent(pos) and result = "argument " + pos
36+
this = TArgumentSummaryComponent(pos) and
37+
result = "Argument[" + getParameterPosition(pos) + "]"
4038
)
4139
or
42-
exists(ReturnKind rk | this = TReturnSummaryComponent(rk) and result = "return (" + rk + ")")
43-
or
44-
exists(SummaryComponent::SyntheticGlobal sg |
45-
this = TSyntheticGlobalSummaryComponent(sg) and
46-
result = "synthetic global (" + sg + ")"
40+
exists(string synthetic |
41+
this = TSyntheticGlobalSummaryComponent(synthetic) and
42+
result = "SyntheticGlobal[" + synthetic + "]"
4743
)
44+
or
45+
this = TReturnSummaryComponent(getReturnValueKind()) and result = "ReturnValue"
4846
}
47+
48+
/** Gets a textual representation of this summary component. */
49+
string toString() { result = this.getAccessStep() }
4950
}
5051

5152
/** Provides predicates for constructing summary components. */
@@ -125,19 +126,22 @@ module Public {
125126
this = TSingletonSummaryComponentStack(result) or result = this.tail().bottom()
126127
}
127128

128-
/** Gets a textual representation of this stack. */
129-
string toString() {
129+
/** Gets a textual representation of this stack used for MaD models. */
130+
string getAccessPath() {
130131
exists(SummaryComponent head, SummaryComponentStack tail |
131132
head = this.head() and
132133
tail = this.tail() and
133-
result = tail + "." + head
134+
result = tail.getAccessPath() + "." + head.getAccessStep()
134135
)
135136
or
136137
exists(SummaryComponent c |
137138
this = TSingletonSummaryComponentStack(c) and
138-
result = c.toString()
139+
result = c.getAccessStep()
139140
)
140141
}
142+
143+
/** Gets a textual representation of this stack. */
144+
string toString() { result = this.getAccessPath() }
141145
}
142146

143147
/** Provides predicates for constructing stacks of summary components. */
@@ -166,42 +170,6 @@ module Public {
166170
SummaryComponentStack return(ReturnKind rk) { result = singleton(SummaryComponent::return(rk)) }
167171
}
168172

169-
/** Gets a textual representation of this component used for flow summaries. */
170-
private string getComponent(SummaryComponent sc) {
171-
result = getComponentSpecific(sc)
172-
or
173-
exists(ArgumentPosition pos |
174-
sc = TParameterSummaryComponent(pos) and
175-
result = "Parameter[" + getArgumentPosition(pos) + "]"
176-
)
177-
or
178-
exists(ParameterPosition pos |
179-
sc = TArgumentSummaryComponent(pos) and
180-
result = "Argument[" + getParameterPosition(pos) + "]"
181-
)
182-
or
183-
exists(string synthetic |
184-
sc = TSyntheticGlobalSummaryComponent(synthetic) and
185-
result = "SyntheticGlobal[" + synthetic + "]"
186-
)
187-
or
188-
sc = TReturnSummaryComponent(getReturnValueKind()) and result = "ReturnValue"
189-
}
190-
191-
/** Gets a textual representation of this stack used for flow summaries. */
192-
string getComponentStack(SummaryComponentStack stack) {
193-
exists(SummaryComponent head, SummaryComponentStack tail |
194-
head = stack.head() and
195-
tail = stack.tail() and
196-
result = getComponentStack(tail) + "." + getComponent(head)
197-
)
198-
or
199-
exists(SummaryComponent c |
200-
stack = TSingletonSummaryComponentStack(c) and
201-
result = getComponent(c)
202-
)
203-
}
204-
205173
/**
206174
* A class that exists for QL technical reasons only (the IPA type used
207175
* to represent component stacks needs to be bounded).
@@ -1382,8 +1350,8 @@ module Private {
13821350
c.relevantSummary(input, output, preservesValue) and
13831351
csv =
13841352
c.getCallableCsv() // Callable information
1385-
+ getComponentStack(input) + ";" // input
1386-
+ getComponentStack(output) + ";" // output
1353+
+ input.getAccessPath() + ";" // input
1354+
+ output.getAccessPath() + ";" // output
13871355
+ renderKind(preservesValue) + ";" // kind
13881356
+ renderProvenance(c) // provenance
13891357
)

csharp/ql/lib/semmle/code/csharp/dataflow/internal/FlowSummaryImplSpecific.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ private string getContentSpecific(Content c) {
198198
}
199199

200200
/** Gets the textual representation of a summary component in the format used for flow summaries. */
201-
string getComponentSpecific(SummaryComponent sc) {
201+
string getAccessStepSpecific(SummaryComponent sc) {
202202
exists(Content c | sc = TContentSummaryComponent(c) and result = getContentSpecific(c))
203203
or
204204
sc = TWithoutContentSummaryComponent(_) and result = "WithoutElement"

csharp/ql/lib/semmle/code/csharp/frameworks/EntityFramework.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ module EntityFramework {
410410
) {
411411
this = dbSet.getDbContextClass() and
412412
this.output(output, mapped, dbSet) and
413-
result = dbSet.getFullName() + "#" + SummaryComponentStack::getComponentStack(output)
413+
result = dbSet.getFullName() + "#" + output.getAccessPath()
414414
}
415415
}
416416

0 commit comments

Comments
 (0)