Skip to content

Commit 238f390

Browse files
authored
Merge pull request github#13452 from michaelnebel/refactorstackprinting
Re-factor printing of summary component stacks.
2 parents 6912f7e + 243c592 commit 238f390

File tree

17 files changed

+1410
-1530
lines changed

17 files changed

+1410
-1530
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 `getMadRepresentation` instead.
115+
*
116+
* Gets a textual representation of this stack used for flow summaries.
117+
*/
118+
deprecated string getComponentStack(SummaryComponentStack s) { result = s.getMadRepresentation() }
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 MaD models. */
27+
string getMadRepresentation() {
28+
result = getMadRepresentationSpecific(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.getMadRepresentation() }
4950
}
5051

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

127-
/** Gets a textual representation of this stack. */
128-
string toString() {
128+
/** Gets a textual representation of this stack used for MaD models. */
129+
string getMadRepresentation() {
129130
exists(SummaryComponent head, SummaryComponentStack tail |
130131
head = this.head() and
131132
tail = this.tail() and
132-
result = tail + "." + head
133+
result = tail.getMadRepresentation() + "." + head.getMadRepresentation()
133134
)
134135
or
135136
exists(SummaryComponent c |
136137
this = TSingletonSummaryComponentStack(c) and
137-
result = c.toString()
138+
result = c.getMadRepresentation()
138139
)
139140
}
141+
142+
/** Gets a textual representation of this stack. */
143+
string toString() { result = this.getMadRepresentation() }
140144
}
141145

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

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

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ SummaryComponent interpretComponentSpecific(AccessPathToken c) {
186186
)
187187
}
188188

189-
/** Gets the textual representation of the content in the format used for flow summaries. */
189+
/** Gets the textual representation of the content in the format used for MaD models. */
190190
private string getContentSpecific(Content c) {
191191
c = TElementContent() and result = "Element"
192192
or
@@ -197,8 +197,8 @@ private string getContentSpecific(Content c) {
197197
exists(SyntheticField f | c = TSyntheticFieldContent(f) and result = "SyntheticField[" + f + "]")
198198
}
199199

200-
/** Gets the textual representation of a summary component in the format used for flow summaries. */
201-
string getComponentSpecific(SummaryComponent sc) {
200+
/** Gets the textual representation of a summary component in the format used for MaD models. */
201+
string getMadRepresentationSpecific(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.getMadRepresentation()
414414
}
415415
}
416416

go/ql/lib/semmle/go/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 MaD models. */
27+
string getMadRepresentation() {
28+
result = getMadRepresentationSpecific(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.getMadRepresentation() }
4950
}
5051

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

127-
/** Gets a textual representation of this stack. */
128-
string toString() {
128+
/** Gets a textual representation of this stack used for MaD models. */
129+
string getMadRepresentation() {
129130
exists(SummaryComponent head, SummaryComponentStack tail |
130131
head = this.head() and
131132
tail = this.tail() and
132-
result = tail + "." + head
133+
result = tail.getMadRepresentation() + "." + head.getMadRepresentation()
133134
)
134135
or
135136
exists(SummaryComponent c |
136137
this = TSingletonSummaryComponentStack(c) and
137-
result = c.toString()
138+
result = c.getMadRepresentation()
138139
)
139140
}
141+
142+
/** Gets a textual representation of this stack. */
143+
string toString() { result = this.getMadRepresentation() }
140144
}
141145

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

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

go/ql/lib/semmle/go/dataflow/internal/FlowSummaryImplSpecific.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ private string getContentSpecific(Content c) {
110110
c instanceof PointerContent and result = "Dereference"
111111
}
112112

113-
/** Gets the textual representation of the content in the format used for flow summaries. */
114-
string getComponentSpecific(SummaryComponent sc) {
113+
/** Gets the textual representation of the content in the format used for MaD models. */
114+
string getMadRepresentationSpecific(SummaryComponent sc) {
115115
exists(Content c | sc = TContentSummaryComponent(c) and result = getContentSpecific(c))
116116
or
117117
exists(ReturnKind rk |

0 commit comments

Comments
 (0)