Skip to content

Commit e30fed6

Browse files
committed
C#: Improve upgrade script.
1 parent 00753a1 commit e30fed6

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
description: Add `interpolated_string_insert_expr` kind.
2-
compatibility: partial
2+
compatibility: backwards
3+
expressions.rel: run string_interpol_insert.qlo new_expressions
4+
expr_parent.rel: run string_interpol_insert.qlo new_expr_parent

0 commit comments

Comments
 (0)