Skip to content

Commit 3cdb1d2

Browse files
committed
Add upgrade and downgrade scripts for latest dbscheme
1 parent 330a5b8 commit 3cdb1d2

File tree

8 files changed

+5122
-0
lines changed

8 files changed

+5122
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
class Expr extends @expr { string toString() { result = "expr" } }
2+
class LocalVariableDeclExpr extends @localvariabledeclexpr, Expr { }
3+
class InstanceOfExpr extends @instanceofexpr, Expr { }
4+
class SimplePatternInstanceOfExpr extends InstanceOfExpr { SimplePatternInstanceOfExpr() { getNthChild(this, 2) instanceof LocalVariableDeclExpr } }
5+
class Type extends @type { string toString() { result = "type" } }
6+
class ExprParent extends @exprparent { string toString() { result = "exprparent" } }
7+
8+
Expr getNthChild(ExprParent parent, int i) { exprs(result, _, _, parent, i) }
9+
10+
// Where an InstanceOfExpr has a 2nd child that is a LocalVariableDeclExpr, that expression should becomes its 0th child and the existing 0th child should become its initialiser.
11+
// Any RecordPatternExpr should be replaced with an error expression, as it can't be represented in the downgraded dbscheme.
12+
13+
// This reverts a reorganisation of the representation of "o instanceof String s", which used to be InstanceOfExpr -0-> LocalVariableDeclExpr --init-> o
14+
// \-name-> s
15+
// It is now InstanceOfExpr --0-> o
16+
// \-2-> LocalVariableDeclExpr -name-> s
17+
//
18+
// Other children are unaffected.
19+
20+
21+
predicate hasNewParent(Expr e, ExprParent newParent, int newIndex) {
22+
23+
exists(SimplePatternInstanceOfExpr oldParent, int oldIndex |
24+
e = getNthChild(oldParent, oldIndex) |
25+
oldIndex = 0 and newParent = getNthChild(oldParent, 2) and newIndex = 0
26+
or
27+
oldIndex = 1 and newParent = oldParent and newIndex = oldIndex
28+
or
29+
oldIndex = 2 and newParent = oldParent and newIndex = 0
30+
)
31+
or
32+
not exists(SimplePatternInstanceOfExpr oldParent | e = getNthChild(oldParent, _)) and
33+
exprs(e, _, _, newParent, newIndex)
34+
35+
}
36+
37+
from Expr e, int oldKind, int newKind, Type typeid, ExprParent parent, int index
38+
where exprs(e, kind, typeid, _, _) and
39+
hasNewParent(e, parent, index) and
40+
(if oldKind = 89 /* record pattern */ then newKind = 74 /* error expression */ else oldKind = newKind)
41+
select e, newKind, typeid, parent, index

0 commit comments

Comments
 (0)