|
| 1 | +class Expr extends @expr { |
| 2 | + string toString() { none() } |
| 3 | +} |
| 4 | + |
| 5 | +class TypeOrRef extends @type_or_ref { |
| 6 | + string toString() { none() } |
| 7 | +} |
| 8 | + |
| 9 | +class StringLiteral extends Expr, @string_literal_expr { } |
| 10 | + |
| 11 | +class InterpolatedStringExpr extends Expr, @interpolated_string_expr { } |
| 12 | + |
| 13 | +class StringInterpolationInsert extends Expr, @element { |
| 14 | + StringInterpolationInsert() { |
| 15 | + expressions(this, _, _) and |
| 16 | + expr_parent(this, _, any(InterpolatedStringExpr x)) and |
| 17 | + not this instanceof StringLiteral |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +newtype TAddedElement = TInsert(StringInterpolationInsert e) |
| 22 | + |
| 23 | +module Fresh = QlBuiltins::NewEntity<TAddedElement>; |
| 24 | + |
| 25 | +class TNewExpr = @expr or Fresh::EntityId; |
| 26 | + |
| 27 | +class NewExpr extends TNewExpr { |
| 28 | + string toString() { none() } |
| 29 | +} |
| 30 | + |
| 31 | +query predicate new_expressions(NewExpr id, int kind, TypeOrRef t) { |
| 32 | + expressions(id, kind, t) |
| 33 | + or |
| 34 | + exists(StringInterpolationInsert e | |
| 35 | + // The type of `e` is just copied even though a null type would be preferred. |
| 36 | + expressions(e, _, t) and |
| 37 | + Fresh::map(TInsert(e)) = id and |
| 38 | + kind = 138 |
| 39 | + ) |
| 40 | +} |
| 41 | + |
| 42 | +query predicate new_expr_parent(NewExpr id, int child, NewExpr parent) { |
| 43 | + // Keep all parent child relationships except for string interpolation inserts |
| 44 | + expr_parent(id, child, parent) and not id instanceof StringInterpolationInsert |
| 45 | + or |
| 46 | + exists(StringInterpolationInsert e, int child0, NewExpr p0, NewExpr new_id | |
| 47 | + expr_parent(e, child0, p0) and new_id = Fresh::map(TInsert(e)) |
| 48 | + | |
| 49 | + id = new_id and |
| 50 | + child = child0 and |
| 51 | + parent = p0 |
| 52 | + or |
| 53 | + id = e and |
| 54 | + child = 0 and |
| 55 | + parent = new_id |
| 56 | + ) |
| 57 | +} |
0 commit comments