Skip to content

Commit 1636abb

Browse files
authored
Merge pull request #18985 from hvitved/rust/immediate-child
Rust/Swift: Add `get(Immediate)Child` predicate
2 parents 1aa2236 + dd21dab commit 1636abb

File tree

7 files changed

+39
-9
lines changed

7 files changed

+39
-9
lines changed

misc/codegen/templates/ql_parent.mustache

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ Element getImmediateParent(Element e) {
7979
result = unique(Element x | e = Impl::getImmediateChild(x, _, _) | x)
8080
}
8181

82+
/**
83+
* Gets the immediate child indexed at `index`. Indexes are not guaranteed to be contiguous, but are guaranteed to be distinct.
84+
*/
85+
Element getImmediateChild(Element e, int index) { result = Impl::getImmediateChild(e, index, _) }
86+
8287
/**
8388
* 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.
8489
*/
@@ -92,3 +97,10 @@ Element getImmediateChildAndAccessor(Element e, int index, string accessor) {
9297
Element getChildAndAccessor(Element e, int index, string accessor) {
9398
exists(string partialAccessor | result = Impl::getImmediateChild(e, index, partialAccessor).resolve() and accessor = "get" + partialAccessor)
9499
}
100+
101+
/**
102+
* 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.
103+
*/
104+
Element getChild(Element e, int index) {
105+
result = Impl::getImmediateChild(e, index, _).resolve()
106+
}

rust/ql/.generated.list

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,11 @@ module Impl {
236236
this instanceof VariableScope or
237237
this instanceof VariableAccessCand or
238238
this instanceof LetStmt or
239-
getImmediateChildAndAccessor(this, _, _) instanceof RelevantElement
239+
getImmediateChild(this, _) instanceof RelevantElement
240240
}
241241

242242
pragma[nomagic]
243-
private RelevantElement getChild(int index) {
244-
result = getImmediateChildAndAccessor(this, index, _)
245-
}
243+
private RelevantElement getChild(int index) { result = getImmediateChild(this, index) }
246244

247245
pragma[nomagic]
248246
private RelevantElement getImmediateChildMin(int index) {

rust/ql/lib/codeql/rust/elements/internal/generated/ParentChild.qll

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/ql/lib/codeql/rust/internal/AstConsistency.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ query predicate multiplePrimaryQlClasses(Element e, string s) {
4040
s = strictconcat(e.getPrimaryQlClasses(), ", ")
4141
}
4242

43-
private Element getParent(Element child) { child = getChildAndAccessor(result, _, _) }
43+
private Element getParent(Element child) { child = getChild(result, _) }
4444

4545
private predicate multipleParents(Element child) { strictcount(getParent(child)) > 1 }
4646

@@ -56,8 +56,8 @@ query predicate multipleParents(Element child, string childClass, Element parent
5656

5757
/** Holds if `parent` has multiple children at the same index. */
5858
query predicate multipleChildren(Element parent, int index, Element child1, Element child2) {
59-
child1 = getChildAndAccessor(parent, index, _) and
60-
child2 = getChildAndAccessor(parent, index, _) and
59+
child1 = getChild(parent, index) and
60+
child2 = getChild(parent, index) and
6161
child1 != child2
6262
}
6363

swift/ql/.generated.list

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swift/ql/lib/codeql/swift/generated/ParentChild.qll

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)