Skip to content

Commit 9cff065

Browse files
committed
C#: use AccessPathSyntax library
1 parent 5cab737 commit 9cff065

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

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

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -124,21 +124,26 @@ predicate sinkElement(Element e, string input, string kind) {
124124

125125
/** Gets the summary component for specification component `c`, if any. */
126126
bindingset[c]
127-
SummaryComponent interpretComponentSpecific(string c) {
127+
SummaryComponent interpretComponentSpecific(AccessPathToken c) {
128128
c = "Element" and result = SummaryComponent::content(any(ElementContent ec))
129129
or
130+
// Qualified names may contain commas,such as in `Tuple<,>`, so get the entire argument list
131+
// rather than an individual argument.
130132
exists(Field f |
131-
c.regexpCapture("Field\\[(.+)\\]", 1) = f.getQualifiedName() and
133+
c.getName() = "Field" and
134+
c.getArgumentList() = f.getQualifiedName() and
132135
result = SummaryComponent::content(any(FieldContent fc | fc.getField() = f))
133136
)
134137
or
135138
exists(Property p |
136-
c.regexpCapture("Property\\[(.+)\\]", 1) = p.getQualifiedName() and
139+
c.getName() = "Property" and
140+
c.getArgumentList() = p.getQualifiedName() and
137141
result = SummaryComponent::content(any(PropertyContent pc | pc.getProperty() = p))
138142
)
139143
or
140144
exists(SyntheticField f |
141-
c.regexpCapture("SyntheticField\\[(.+)\\]", 1) = f and
145+
c.getName() = "SyntheticField" and
146+
c.getArgumentList() = f and
142147
result = SummaryComponent::content(any(SyntheticFieldContent sfc | sfc.getField() = f))
143148
)
144149
}
@@ -253,21 +258,10 @@ predicate interpretInputSpecific(string c, InterpretNode mid, InterpretNode n) {
253258
)
254259
}
255260

256-
bindingset[s]
257-
private int parseIntegerPosition(string s) {
258-
result = s.regexpCapture("([0-9]+)", 1).toInt()
259-
or
260-
exists(int n1, int n2 |
261-
s.regexpCapture("([0-9]+)\\.\\.([0-9]+)", 1).toInt() = n1 and
262-
s.regexpCapture("([0-9]+)\\.\\.([0-9]+)", 2).toInt() = n2 and
263-
result in [n1 .. n2]
264-
)
265-
}
266-
267261
/** Gets the argument position obtained by parsing `X` in `Parameter[X]`. */
268262
bindingset[s]
269263
ArgumentPosition parseParamBody(string s) {
270-
result.getPosition() = parseIntegerPosition(s)
264+
result.getPosition() = AccessPath::parseInt(s)
271265
or
272266
s = "This" and
273267
result.isQualifier()
@@ -276,7 +270,7 @@ ArgumentPosition parseParamBody(string s) {
276270
/** Gets the parameter position obtained by parsing `X` in `Argument[X]`. */
277271
bindingset[s]
278272
ParameterPosition parseArgBody(string s) {
279-
result.getPosition() = parseIntegerPosition(s)
273+
result.getPosition() = AccessPath::parseInt(s)
280274
or
281275
s = "Qualifier" and
282276
result.isThisParameter()

0 commit comments

Comments
 (0)