Skip to content

Commit 5811a3c

Browse files
committed
Port getMadStringFromContentSet -> encodeContent
1 parent 8c4e5e8 commit 5811a3c

File tree

1 file changed

+36
-45
lines changed

1 file changed

+36
-45
lines changed

javascript/ql/lib/semmle/javascript/dataflow/internal/FlowSummaryPrivate.qll

Lines changed: 36 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -221,63 +221,62 @@ Private::SummaryComponent interpretComponentSpecific(Private::AccessPathToken c)
221221
result = Private::SummaryComponent::content(MkArrayElementDeep())
222222
}
223223

224-
private string getMadStringFromContentSetAux(ContentSet cs) {
224+
private string encodeContentAux(ContentSet cs, string arg) {
225225
cs = ContentSet::arrayElement() and
226-
result = "ArrayElement"
226+
result = "ArrayElement" and
227+
arg = ""
227228
or
228229
cs = ContentSet::arrayElementUnknown() and
229-
result = "ArrayElement[?]"
230+
result = "ArrayElement" and
231+
arg = "?"
230232
or
231233
exists(int n |
232234
cs = ContentSet::arrayElementLowerBound(n) and
233-
result = "ArrayElement[" + n + "..]" and
235+
result = "ArrayElement" and
236+
arg = n + ".." and
234237
n > 0 // n=0 is just 'ArrayElement'
235238
or
236239
cs = ContentSet::arrayElementKnown(n) and
237-
result = "ArrayElement[" + n + "]"
240+
result = "ArrayElement" and
241+
arg = n.toString()
238242
or
239243
n = cs.asPropertyName().toInt() and
240244
n >= 0 and
241-
result = "ArrayElement[" + n + "!]"
245+
result = "ArrayElement" and
246+
arg = n + "!"
242247
)
243248
or
244-
cs = ContentSet::mapValueAll() and result = "MapValue"
245-
or
246-
cs = ContentSet::mapKey() and result = "MapKey"
247-
or
248-
cs = ContentSet::setElement() and result = "SetElement"
249-
or
250-
cs = ContentSet::iteratorElement() and result = "IteratorElement"
251-
or
252-
cs = ContentSet::iteratorError() and result = "IteratorError"
253-
or
254-
exists(string awaitedArg |
255-
cs = getPromiseContent(awaitedArg) and
256-
result = "Awaited[" + awaitedArg + "]"
249+
arg = "" and
250+
(
251+
cs = ContentSet::mapValueAll() and result = "MapValue"
252+
or
253+
cs = ContentSet::mapKey() and result = "MapKey"
254+
or
255+
cs = ContentSet::setElement() and result = "SetElement"
256+
or
257+
cs = ContentSet::iteratorElement() and result = "IteratorElement"
258+
or
259+
cs = ContentSet::iteratorError() and result = "IteratorError"
257260
)
258261
or
259-
cs = MkAwaited() and result = "Awaited"
260-
}
261-
262-
private string getMadStringFromContentSet(ContentSet cs) {
263-
result = getMadStringFromContentSetAux(cs)
262+
cs = getPromiseContent(arg) and
263+
result = "Awaited"
264264
or
265-
not exists(getMadStringFromContentSetAux(cs)) and
266-
result = "Member[" + cs.asSingleton() + "]"
265+
cs = MkAwaited() and result = "Awaited" and arg = ""
267266
}
268267

269-
/** Gets the textual representation of a summary component in the format used for MaD models. */
270-
string getMadRepresentationSpecific(Private::SummaryComponent sc) {
271-
exists(ContentSet cs |
272-
sc = Private::SummaryComponent::content(cs) and
273-
result = getMadStringFromContentSet(cs)
274-
)
268+
/**
269+
* Gets the textual representation of content `cs` used in MaD.
270+
*
271+
* `arg` will be printed in square brackets (`[]`) after the result, unless
272+
* `arg` is the empty string.
273+
*/
274+
string encodeContent(ContentSet cs, string arg) {
275+
result = encodeContentAux(cs, arg)
275276
or
276-
exists(ReturnKind rk |
277-
sc = Private::SummaryComponent::return(rk) and
278-
not rk = getReturnValueKind() and
279-
result = "ReturnValue[" + rk + "]"
280-
)
277+
not exists(encodeContentAux(cs, _)) and
278+
result = "Member" and
279+
arg = cs.asSingleton().toString()
281280
}
282281

283282
/** Gets the textual representation of a parameter position in the format used for flow summaries. */
@@ -375,14 +374,6 @@ private module FlowSummaryStepInput implements Private::StepsInputSig {
375374

376375
module Steps = Private::Steps<FlowSummaryStepInput>;
377376

378-
/**
379-
* Gets the textual representation of content `c` used in MaD.
380-
*
381-
* `arg` will be printed in square brackets (`[]`) after the result, unless
382-
* `arg` is the empty string.
383-
*/
384-
string encodeContent(ContentSet c, string arg) { none() }
385-
386377
/**
387378
* Gets the textual representation of return kind `rk` used in MaD.
388379
*

0 commit comments

Comments
 (0)