Skip to content

Commit db5979f

Browse files
committed
Autoformat upgrade/downgrade scripts
1 parent 1d82756 commit db5979f

File tree

2 files changed

+55
-25
lines changed
  • java
    • downgrades/dee651b58d1e5455ca2d07eca37775a21d772fcc
    • ql/lib/upgrades/ecfcf050952e54b1155fc89525db84af6ad34aaf

2 files changed

+55
-25
lines changed
Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,37 @@
1-
class Expr extends @expr { string toString() { result = "expr" } }
1+
class Expr extends @expr {
2+
string toString() { result = "expr" }
3+
}
4+
25
class LocalVariableDeclExpr extends @localvariabledeclexpr, Expr { }
6+
37
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" } }
8+
9+
class SimplePatternInstanceOfExpr extends InstanceOfExpr {
10+
SimplePatternInstanceOfExpr() { getNthChild(this, 2) instanceof LocalVariableDeclExpr }
11+
}
12+
13+
class Type extends @type {
14+
string toString() { result = "type" }
15+
}
16+
17+
class ExprParent extends @exprparent {
18+
string toString() { result = "exprparent" }
19+
}
720

821
Expr getNthChild(ExprParent parent, int i) { exprs(result, _, _, parent, i) }
922

1023
// 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.
1124
// Any RecordPatternExpr should be replaced with an error expression, as it can't be represented in the downgraded dbscheme.
12-
1325
// This reverts a reorganisation of the representation of "o instanceof String s", which used to be InstanceOfExpr -0-> LocalVariableDeclExpr --init-> o
1426
// \-name-> s
1527
// It is now InstanceOfExpr --0-> o
1628
// \-2-> LocalVariableDeclExpr -name-> s
1729
//
1830
// Other children are unaffected.
19-
20-
2131
predicate hasNewParent(Expr e, ExprParent newParent, int newIndex) {
22-
2332
exists(SimplePatternInstanceOfExpr oldParent, int oldIndex |
24-
e = getNthChild(oldParent, oldIndex) |
33+
e = getNthChild(oldParent, oldIndex)
34+
|
2535
oldIndex = 0 and newParent = getNthChild(oldParent, 2) and newIndex = 0
2636
or
2737
oldIndex = 1 and newParent = oldParent and newIndex = oldIndex
@@ -31,11 +41,15 @@ predicate hasNewParent(Expr e, ExprParent newParent, int newIndex) {
3141
or
3242
not exists(SimplePatternInstanceOfExpr oldParent | e = getNthChild(oldParent, _)) and
3343
exprs(e, _, _, newParent, newIndex)
34-
3544
}
3645

3746
from Expr e, int oldKind, int newKind, Type typeid, ExprParent parent, int index
38-
where exprs(e, oldKind, typeid, _, _) and
39-
hasNewParent(e, parent, index) and
40-
(if oldKind = 89 /* record pattern */ then newKind = 74 /* error expression */ else oldKind = newKind)
47+
where
48+
exprs(e, oldKind, typeid, _, _) and
49+
hasNewParent(e, parent, index) and
50+
(
51+
if oldKind = 89
52+
then /* record pattern */ newKind = 74
53+
else /* error expression */ oldKind = newKind
54+
)
4155
select e, newKind, typeid, parent, index
Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1-
class Expr extends @expr { string toString() { result = "expr" } }
1+
class Expr extends @expr {
2+
string toString() { result = "expr" }
3+
}
4+
25
class LocalVariableDeclExpr extends @localvariabledeclexpr, Expr { }
6+
37
class InstanceOfExpr extends @instanceofexpr, Expr { }
4-
class Type extends @type { string toString() { result = "type" } }
5-
class ExprParent extends @exprparent { string toString() { result = "exprparent" } }
8+
9+
class Type extends @type {
10+
string toString() { result = "type" }
11+
}
12+
13+
class ExprParent extends @exprparent {
14+
string toString() { result = "exprparent" }
15+
}
616

717
// Initialisers of local variable declarations that occur as the 0th child of an instanceof expression should be reparented to be the 0th child of the instanceof itself,
818
// while the LocalVariableDeclExpr, now without an initialiser, should become its 2nd child.
@@ -12,20 +22,26 @@ class ExprParent extends @exprparent { string toString() { result = "exprparent"
1222
// \-2-> LocalVariableDeclExpr -name-> s
1323
//
1424
// Other children are unaffected.
15-
1625
ExprParent getParent(Expr e) { exprs(e, _, _, result, _) }
1726

1827
predicate hasNewParent(Expr e, ExprParent newParent, int newIndex) {
19-
if (getParent(e) instanceof LocalVariableDeclExpr and getParent(getParent(e)) instanceof InstanceOfExpr)
20-
then (newParent = getParent(getParent(e)) and newIndex = 0) // Initialiser moves to hang directly off the instanceof expression
21-
else (
22-
if (e instanceof LocalVariableDeclExpr and getParent(e) instanceof InstanceOfExpr)
23-
then (newParent = getParent(e) and newIndex = 2) // Variable declaration moves to be the instanceof expression's 2nd child
24-
else exprs(e, _, _, newParent, newIndex) // Other expressions unchanged
28+
if
29+
getParent(e) instanceof LocalVariableDeclExpr and
30+
getParent(getParent(e)) instanceof InstanceOfExpr
31+
then (
32+
newParent = getParent(getParent(e)) and newIndex = 0
33+
) else (
34+
// Initialiser moves to hang directly off the instanceof expression
35+
if e instanceof LocalVariableDeclExpr and getParent(e) instanceof InstanceOfExpr
36+
then newParent = getParent(e) and newIndex = 2
37+
else
38+
// Variable declaration moves to be the instanceof expression's 2nd child
39+
exprs(e, _, _, newParent, newIndex) // Other expressions unchanged
2540
)
2641
}
2742

2843
from Expr e, int kind, Type typeid, ExprParent parent, int index
29-
where exprs(e, kind, typeid, _, _) and
30-
hasNewParent(e, parent, index)
44+
where
45+
exprs(e, kind, typeid, _, _) and
46+
hasNewParent(e, parent, index)
3147
select e, kind, typeid, parent, index

0 commit comments

Comments
 (0)