Rust: Add get(Immediate)Child predicate

This commit is contained in:
Tom Hvitved
2025-03-12 10:04:16 +01:00
parent 72c7024c8b
commit 8777bc42c7
5 changed files with 28 additions and 8 deletions

View File

@@ -79,6 +79,11 @@ Element getImmediateParent(Element e) {
result = unique(Element x | e = Impl::getImmediateChild(x, _, _) | x)
}
/**
* Gets the immediate child indexed at `index`. Indexes are not guaranteed to be contiguous, but are guaranteed to be distinct.
*/
Element getImmediateChild(Element e, int index) { result = Impl::getImmediateChild(e, index, _) }
/**
* Gets the immediate child indexed at `index`. Indexes are not guaranteed to be contiguous, but are guaranteed to be distinct. `accessor` is bound the member predicate call resulting in the given child.
*/
@@ -92,3 +97,10 @@ Element getImmediateChildAndAccessor(Element e, int index, string accessor) {
Element getChildAndAccessor(Element e, int index, string accessor) {
exists(string partialAccessor | result = Impl::getImmediateChild(e, index, partialAccessor).resolve() and accessor = "get" + partialAccessor)
}
/**
* Gets the child indexed at `index`. Indexes are not guaranteed to be contiguous, but are guaranteed to be distinct. `accessor` is bound the member predicate call resulting in the given child.
*/
Element getChild(Element e, int index) {
result = Impl::getImmediateChild(e, index, _).resolve()
}