|
| 1 | +class Expr_ extends @expr { |
| 2 | + string toString() { result = "Expr" } |
| 3 | +} |
| 4 | + |
| 5 | +class ExprParent_ extends @exprparent { |
| 6 | + string toString() { result = "ExprParent" } |
| 7 | +} |
| 8 | + |
| 9 | +// The schema for exprs is: |
| 10 | +// |
| 11 | +// exprs(unique int id: @expr, |
| 12 | +// int kind: int ref, |
| 13 | +// int parent: @exprparent ref, |
| 14 | +// int idx: int ref); |
| 15 | +// |
| 16 | +// `@rangeelementexpr` (kind 55) is a synthesized node that groups the loop |
| 17 | +// variables (the key and value) of a `range` statement. To downgrade we remove |
| 18 | +// those nodes and reparent their children (the key and value expressions) |
| 19 | +// directly onto the `range` statement, at the same indices. |
| 20 | +from Expr_ id, int kind, ExprParent_ newparent, int idx |
| 21 | +where |
| 22 | + exists(ExprParent_ parent | exprs(id, kind, parent, idx) and kind != 55 | |
| 23 | + // A key or value grouped by a range element node: reparent it onto the |
| 24 | + // range statement (the range element node's own parent). |
| 25 | + exists(Expr_ pe | pe = parent and exprs(pe, 55, newparent, _)) |
| 26 | + or |
| 27 | + // Any other expression keeps its parent unchanged. |
| 28 | + not exists(Expr_ pe | pe = parent and exprs(pe, 55, _, _)) and |
| 29 | + newparent = parent |
| 30 | + ) |
| 31 | +select id, kind, newparent, idx |
0 commit comments