mirror of
https://github.com/github/codeql.git
synced 2026-04-29 10:45:15 +02:00
44 lines
1.7 KiB
Plaintext
44 lines
1.7 KiB
Plaintext
// generated by {{generator}}
|
|
|
|
import codeql.swift.elements.Element
|
|
|
|
/**
|
|
* Gets any of the "immediate" children of `e`. "Immediate" means not taking into account node resolution: for example
|
|
* if the AST child is the first of a series of conversions that would normally be hidden away, this will select the
|
|
* next conversion down the hidden AST tree instead of the corresponding fully uncoverted node at the bottom.
|
|
* Outside this module this file is mainly intended to be used to test uniqueness of parents.
|
|
*/
|
|
cached
|
|
Element getAnImmediateChild(Element e) {
|
|
// why does this look more complicated than it should?
|
|
// * `exists` and the `x` variable are there to reuse the same generation done in classes (where `x` is used to hide
|
|
// nodes via resolution)
|
|
// * none() simplifies generation, as we can append `or ...` without a special case for the first item
|
|
exists(Element x | result = x and (
|
|
none()
|
|
{{#classes}}
|
|
{{#properties}}
|
|
{{#is_child}}
|
|
or
|
|
{{#is_repeated}}
|
|
{{tablename}}(e, _, x)
|
|
{{/is_repeated}}
|
|
{{^is_repeated}}
|
|
{{tablename}}(e{{#tableparams}}{{^first}}, {{param}}{{/first}}{{/tableparams}})
|
|
{{/is_repeated}}
|
|
{{/is_child}}
|
|
{{/properties}}
|
|
{{/classes}}
|
|
))
|
|
}
|
|
|
|
/**
|
|
* Gets the "immediate" parent of `e`. "Immediate" means not taking into account node resolution: for example
|
|
* if `e` has conversions, `getImmediateParent(e)` will give the bottom conversion in the hidden AST.
|
|
*/
|
|
Element getImmediateParent(Element e) {
|
|
// `unique` is used here to tell the optimizer that there is in fact only one result
|
|
// this is tested by the `library-tests/parent/no_double_parents.ql` test
|
|
result = unique(Element x | e = getAnImmediateChild(x) | x)
|
|
}
|