Skip to content

Commit 2a29eaf

Browse files
authored
Merge pull request #22783 from owen-mc/go/fix/range-stmt-upgrade-script
Go: Fix database upgrade script
2 parents 1874e77 + cf9d757 commit 2a29eaf

2 files changed

Lines changed: 73 additions & 1 deletion

File tree

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
description: Add @rangeelementexpr, grouping the loop variables of a range statement
2-
compatibility: partial
2+
compatibility: full
3+
4+
exprs.rel: run upgrade.qlo new_exprs
5+
has_location.rel: run upgrade.qlo new_has_location
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
class Expr extends @expr {
2+
string toString() { none() }
3+
}
4+
5+
class ExprParent extends @exprparent {
6+
string toString() { none() }
7+
}
8+
9+
class RangeStmt extends @rangestmt {
10+
string toString() { none() }
11+
}
12+
13+
class Location extends @location {
14+
string toString() { none() }
15+
}
16+
17+
newtype TAddedExpr = TRangeElement(RangeStmt stmt)
18+
19+
module Fresh = QlBuiltins::NewEntity<TAddedExpr>;
20+
21+
class TNewExpr = @expr or Fresh::EntityId;
22+
23+
class NewExpr extends TNewExpr {
24+
string toString() { none() }
25+
}
26+
27+
class TNewExprParent = @exprparent or Fresh::EntityId;
28+
29+
class NewExprParent extends TNewExprParent {
30+
string toString() { none() }
31+
}
32+
33+
class TNewLocatable = @locatable or Fresh::EntityId;
34+
35+
class NewLocatable extends TNewLocatable {
36+
string toString() { none() }
37+
}
38+
39+
predicate isRangeElementChild(ExprParent parent, int idx, RangeStmt range) {
40+
parent = range and
41+
idx in [0 .. 1]
42+
}
43+
44+
query predicate new_exprs(NewExpr id, int kind, NewExprParent parent, int idx) {
45+
exists(RangeStmt range |
46+
id = Fresh::map(TRangeElement(range)) and
47+
kind = 55 and
48+
parent = range and
49+
idx = 0
50+
)
51+
or
52+
exists(ExprParent oldParent | exprs(id, kind, oldParent, idx) |
53+
exists(RangeStmt range | isRangeElementChild(oldParent, idx, range) |
54+
parent = Fresh::map(TRangeElement(range))
55+
)
56+
or
57+
not isRangeElementChild(oldParent, idx, _) and
58+
parent = oldParent
59+
)
60+
}
61+
62+
query predicate new_has_location(NewLocatable locatable, Location location) {
63+
has_location(locatable, location)
64+
or
65+
exists(RangeStmt range |
66+
locatable = Fresh::map(TRangeElement(range)) and
67+
has_location(range, location)
68+
)
69+
}

0 commit comments

Comments
 (0)