Skip to content

Commit 7c0101a

Browse files
committed
Shared: Add some helper predicates to the AccessPath class in content flow.
1 parent e165fc7 commit 7c0101a

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

shared/dataflow/codeql/dataflow/internal/ContentDataFlowImpl.qll

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,38 @@ module MakeImplContentDataFlow<LocationSig Location, InputSig<Location> Lang> {
271271
result = head + "." + tail
272272
)
273273
}
274+
275+
private ContentSet getAtIndex(int i) {
276+
i = 0 and
277+
result = this.getHead()
278+
or
279+
i > 0 and
280+
result = this.getTail().getAtIndex(i - 1)
281+
}
282+
283+
private AccessPath reverse0(int i) {
284+
i = -1 and result = TAccessPathNil()
285+
or
286+
i >= 0 and
287+
result = TAccessPathCons(this.getAtIndex(i), this.reverse0(i - 1))
288+
}
289+
290+
/**
291+
* Gets the length of this access path.
292+
*/
293+
private int length() {
294+
result = 0 and this = TAccessPathNil()
295+
or
296+
result = 1 + this.getTail().length()
297+
}
298+
299+
/**
300+
* Gets the reversed access path, if any.
301+
*
302+
* Note that not all access paths have a reverse as these are not
303+
* included by default in the IPA type.
304+
*/
305+
AccessPath reverse() { result = this.reverse0(this.length() - 1) }
274306
}
275307

276308
/**

0 commit comments

Comments
 (0)