diff --git a/misc/codegen/templates/ql_parent.mustache b/misc/codegen/templates/ql_parent.mustache index b4e73e3699e8..67b975183736 100644 --- a/misc/codegen/templates/ql_parent.mustache +++ b/misc/codegen/templates/ql_parent.mustache @@ -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() +} diff --git a/rust/ql/.generated.list b/rust/ql/.generated.list index c3cff92c6955..c016dc44dd2e 100644 --- a/rust/ql/.generated.list +++ b/rust/ql/.generated.list @@ -577,7 +577,7 @@ lib/codeql/rust/elements/internal/generated/ParamList.qll c808c9d84dd7800573832b lib/codeql/rust/elements/internal/generated/ParenExpr.qll bc0731505bfe88516205ec360582a4222d2681d11342c93e15258590ddee82f2 d4bd6e0c80cf1d63746c88d4bcb3a01d4c75732e5da09e3ebd9437ced227fb60 lib/codeql/rust/elements/internal/generated/ParenPat.qll 4f168ef5d5bb87a903251cc31b2e44a759b099ec69c90af31783fbb15778c940 0e34f94a45a13396fd57d94c245dc64d1adde2ab0e22b56946f7e94c04e297fc lib/codeql/rust/elements/internal/generated/ParenTypeRepr.qll 40ab5c592e7699c621787793743e33988de71ff42ca27599f5ab3ddb70e3f7d8 12c0a6eed2202ee3e892f61da3b3ce77ac3190854cdf3097e8d2be98aa3cb91d -lib/codeql/rust/elements/internal/generated/ParentChild.qll 9858c29b5852292e87dedc9bc9105b17915f5eb8198b6a29a2d621e26b7440ef 17c1a3e7bb344c7f9584ee2f28de622eb0f17ca4d967231f6215aa36261eeec9 +lib/codeql/rust/elements/internal/generated/ParentChild.qll eec4e7672ef5f07752044348d45882f0a849b295dfb17169e910ed0bfca3c162 29a9cc9b2870b1c6240cc53a9a70c4623381219a8f88ea1656b6828d16ef51c7 lib/codeql/rust/elements/internal/generated/ParenthesizedArgList.qll c5fa328ea60d3a3333d7c7bb3480969c1873166c7ac8ebb9d0afad7a8099d1a8 2dbbb6200d96f7db7dea4a55bdeab8d67b14d39a43e0bd54ada019f7e466f163 lib/codeql/rust/elements/internal/generated/Pat.qll 3605ac062be2f294ee73336e9669027b8b655f4ad55660e1eab35266275154ee 7f9400db2884d336dd1d21df2a8093759c2a110be9bf6482ce8e80ae0fd74ed4 lib/codeql/rust/elements/internal/generated/Path.qll 8e47e91aff3f8c60f1ee8cb3887b8e4936c38e4665d052f2c92a939a969aac29 2c28beb89cabd7c7c91a5bc65c874f414cb96bbefde37b25811b61089a8a0053 diff --git a/rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll b/rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll index 512dd91f0831..2b842a8fab9d 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll @@ -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) { diff --git a/rust/ql/lib/codeql/rust/elements/internal/generated/ParentChild.qll b/rust/ql/lib/codeql/rust/elements/internal/generated/ParentChild.qll index 7cd819ab5379..ff3883de8ce6 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/generated/ParentChild.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/generated/ParentChild.qll @@ -4403,6 +4403,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. */ @@ -4422,3 +4427,8 @@ Element getChildAndAccessor(Element e, int index, string accessor) { 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() } diff --git a/rust/ql/lib/codeql/rust/internal/AstConsistency.qll b/rust/ql/lib/codeql/rust/internal/AstConsistency.qll index f65617872cb2..c0fbeeb7842a 100644 --- a/rust/ql/lib/codeql/rust/internal/AstConsistency.qll +++ b/rust/ql/lib/codeql/rust/internal/AstConsistency.qll @@ -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 } @@ -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 } diff --git a/swift/ql/.generated.list b/swift/ql/.generated.list index 693c18c83e71..6c086a490ad9 100644 --- a/swift/ql/.generated.list +++ b/swift/ql/.generated.list @@ -709,7 +709,7 @@ lib/codeql/swift/generated/Locatable.qll 1d37fa20de71c0b9986bfd7a7c0cb82ab7bf3fd lib/codeql/swift/generated/Location.qll 5e20316c3e480ddfe632b7e88e016c19f10a67df1f6ae9c8f128755a6907d6f5 5a0af2d070bcb2ed53d6d0282bf9c60dc64c2dce89c21fdd485e9c7893c1c8fa lib/codeql/swift/generated/MacroRole.qll 0d8fa6b0b6e2045d9097a87d53888cae2ea5371b2fa7d140341cf206f575b556 ea3b8a7c0a88851809f9a5a5aa80b0d2da3c4779bb29044cdba2b60246a2722c lib/codeql/swift/generated/OtherAvailabilitySpec.qll d9feaa2a71acff3184ca389045b0a49d09156210df0e034923d715b432ad594b 046737621a8bcf69bf805afb0cff476bd15259f12f0d77fce3206dd01b31518f -lib/codeql/swift/generated/ParentChild.qll b65c29ba8c3e13baac44a32d2521a11f07aeb7d33415aa9a91a7f6255a744415 0fe73d06c96194d5a0da19c9348a46d9f8fbf630fee5de3dc96e997c595c362e +lib/codeql/swift/generated/ParentChild.qll bafa2e366c0df25d6c26c4e2e2b84f3e363524d7abcf0f6e31e42879f2bc664a 616160f5664f77346992c2ac39e3229abdf186fe707066d4895ceddd148749a9 lib/codeql/swift/generated/PlatformVersionAvailabilitySpec.qll dc17b49a90a18a8f7607adf2433bc8f0c194fa3e803aa3822f809d4d4fbd6793 be48ea9f8ae17354c8508aaed24337a9e57ce01f288fece3dcecd99776cabcec lib/codeql/swift/generated/PureSynthConstructors.qll bc31a6c4d142fa3fbdcae69d5ba6f1cec00eb9ad92b46c8d7b91ebfa7ef6c1f4 bc31a6c4d142fa3fbdcae69d5ba6f1cec00eb9ad92b46c8d7b91ebfa7ef6c1f4 lib/codeql/swift/generated/Raw.qll 4f2ddadd2ced9728aaf4595ccf85cd147468d7ad0a57a21a6cbfd04e3834b386 9653595693da55953d7743fbecce33d16910e3b6737c654311f1e34d27ad7f0b diff --git a/swift/ql/lib/codeql/swift/generated/ParentChild.qll b/swift/ql/lib/codeql/swift/generated/ParentChild.qll index 8f2d6fb53572..13e75c262398 100644 --- a/swift/ql/lib/codeql/swift/generated/ParentChild.qll +++ b/swift/ql/lib/codeql/swift/generated/ParentChild.qll @@ -5630,6 +5630,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. */ @@ -5649,3 +5654,8 @@ Element getChildAndAccessor(Element e, int index, string accessor) { 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() }