|
1 | 1 | // generated by {{generator}}
|
2 | 2 |
|
3 |
| -{{#imports}} |
4 |
| -import {{.}} |
5 |
| -{{/imports}} |
6 |
| - |
7 |
| -// we are defining this class mainly to leverage existing generation machinery |
8 |
| -// when we generate getters in classes we use the db predicate with `this`. In order to reuse that we need a class here |
9 |
| -// as well |
10 |
| -private class ElementWithChildAccessor extends Element { |
11 |
| - // why does this look more complicated than it should? |
12 |
| - // * the none() simplifies generation, as we can append `or ...` without a special case for the first item |
13 |
| - // * the `exists` and the `x` variables are there to reuse the same generation done in classes (where the variables |
14 |
| - // are used to hide nodes via resolution) |
15 |
| - Element getAnImmediateChild() { |
16 |
| - none() |
17 |
| - {{#classes}} |
18 |
| - {{#properties}} |
19 |
| - {{#is_child}} |
20 |
| - or |
21 |
| - exists({{type}} {{local_var}}{{#is_repeated}}, int index{{/is_repeated}} | {{tablename}}({{#tableparams}}{{^first}}, {{/first}}{{param}}{{/tableparams}}) and result = {{local_var}}) |
22 |
| - {{/is_child}} |
23 |
| - {{/properties}} |
24 |
| - {{/classes}} |
25 |
| - } |
26 |
| -} |
| 3 | +import codeql.swift.elements.Element |
27 | 4 |
|
28 | 5 | /**
|
29 | 6 | * Gets any of the "immediate" children of `e`. "Immediate" means not taking into account node resolution: for example
|
30 | 7 | * if the AST child is the first of a series of conversions that would normally be hidden away, this will select the
|
31 | 8 | * next conversion down the hidden AST tree instead of the corresponding fully uncoverted node at the bottom.
|
32 |
| - * This predicate is mainly intended to be used to test uniqueness of parents. |
| 9 | + * Outside this module this file is mainly intended to be used to test uniqueness of parents. |
33 | 10 | */
|
34 | 11 | cached
|
35 | 12 | Element getAnImmediateChild(Element e) {
|
36 |
| - result = e.(ElementWithChildAccessor).getAnImmediateChild() |
| 13 | + // why does this look more complicated than it should? |
| 14 | + // * `exists` and the `x` variable are there to reuse the same generation done in classes (where `x` is used to hide |
| 15 | + // nodes via resolution) |
| 16 | + // * none() simplifies generation, as we can append `or ...` without a special case for the first item |
| 17 | + exists(Element x | result = x and ( |
| 18 | + none() |
| 19 | + {{#classes}} |
| 20 | + {{#properties}} |
| 21 | + {{#is_child}} |
| 22 | + or |
| 23 | + {{#is_repeated}} |
| 24 | + {{tablename}}(e, _, x) |
| 25 | + {{/is_repeated}} |
| 26 | + {{^is_repeated}} |
| 27 | + {{tablename}}(e{{#tableparams}}{{^first}}, {{param}}{{/first}}{{/tableparams}}) |
| 28 | + {{/is_repeated}} |
| 29 | + {{/is_child}} |
| 30 | + {{/properties}} |
| 31 | + {{/classes}} |
| 32 | + )) |
37 | 33 | }
|
38 | 34 |
|
39 | 35 | /**
|
|
0 commit comments