Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions misc/codegen/templates/ql_parent.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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()
}
2 changes: 1 addition & 1 deletion rust/ql/.generated.list

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,11 @@ module Impl {
this instanceof VariableScope or
this instanceof VariableAccessCand or
this instanceof LetStmt or
getImmediateChildAndAccessor(this, _, _) instanceof RelevantElement
getImmediateChild(this, _) instanceof RelevantElement
}

pragma[nomagic]
private RelevantElement getChild(int index) {
result = getImmediateChildAndAccessor(this, index, _)
}
private RelevantElement getChild(int index) { result = getImmediateChild(this, index) }

pragma[nomagic]
private RelevantElement getImmediateChildMin(int index) {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions rust/ql/lib/codeql/rust/internal/AstConsistency.qll
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ query predicate multiplePrimaryQlClasses(Element e, string s) {
s = strictconcat(e.getPrimaryQlClasses(), ", ")
}

private Element getParent(Element child) { child = getChildAndAccessor(result, _, _) }
private Element getParent(Element child) { child = getChild(result, _) }

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

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

/** Holds if `parent` has multiple children at the same index. */
query predicate multipleChildren(Element parent, int index, Element child1, Element child2) {
child1 = getChildAndAccessor(parent, index, _) and
child2 = getChildAndAccessor(parent, index, _) and
child1 = getChild(parent, index) and
child2 = getChild(parent, index) and
child1 != child2
}

Expand Down
2 changes: 1 addition & 1 deletion swift/ql/.generated.list

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions swift/ql/lib/codeql/swift/generated/ParentChild.qll

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.