C#: Improve upgrade script.

This commit is contained in:
Michael Nebel
2025-03-31 11:30:40 +02:00
parent 00753a1fe4
commit e30fed6eec
2 changed files with 60 additions and 1 deletions

View File

@@ -0,0 +1,57 @@
class Expr extends @expr {
string toString() { none() }
}
class TypeOrRef extends @type_or_ref {
string toString() { none() }
}
class StringLiteral extends Expr, @string_literal_expr { }
class InterpolatedStringExpr extends Expr, @interpolated_string_expr { }
class StringInterpolationInsert extends Expr, @element {
StringInterpolationInsert() {
expressions(this, _, _) and
expr_parent(this, _, any(InterpolatedStringExpr x)) and
not this instanceof StringLiteral
}
}
newtype TAddedElement = TInsert(StringInterpolationInsert e)
module Fresh = QlBuiltins::NewEntity<TAddedElement>;
class TNewExpr = @expr or Fresh::EntityId;
class NewExpr extends TNewExpr {
string toString() { none() }
}
query predicate new_expressions(NewExpr id, int kind, TypeOrRef t) {
expressions(id, kind, t)
or
exists(StringInterpolationInsert e |
// The type of `e` is just copied even though a null type would be preferred.
expressions(e, _, t) and
Fresh::map(TInsert(e)) = id and
kind = 138
)
}
query predicate new_expr_parent(NewExpr id, int child, NewExpr parent) {
// Keep all parent child relationships except for string interpolation inserts
expr_parent(id, child, parent) and not id instanceof StringInterpolationInsert
or
exists(StringInterpolationInsert e, int child0, NewExpr p0, NewExpr new_id |
expr_parent(e, child0, p0) and new_id = Fresh::map(TInsert(e))
|
id = new_id and
child = child0 and
parent = p0
or
id = e and
child = 0 and
parent = new_id
)
}

View File

@@ -1,2 +1,4 @@
description: Add `interpolated_string_insert_expr` kind.
compatibility: partial
compatibility: backwards
expressions.rel: run string_interpol_insert.qlo new_expressions
expr_parent.rel: run string_interpol_insert.qlo new_expr_parent