Autoformat upgrade/downgrade scripts

This commit is contained in:
Chris Smowton
2023-11-03 16:26:40 +00:00
parent 1d82756dc8
commit db5979f1ac
2 changed files with 55 additions and 25 deletions

View File

@@ -1,27 +1,37 @@
class Expr extends @expr { string toString() { result = "expr" } }
class Expr extends @expr {
string toString() { result = "expr" }
}
class LocalVariableDeclExpr extends @localvariabledeclexpr, Expr { }
class InstanceOfExpr extends @instanceofexpr, Expr { }
class SimplePatternInstanceOfExpr extends InstanceOfExpr { SimplePatternInstanceOfExpr() { getNthChild(this, 2) instanceof LocalVariableDeclExpr } }
class Type extends @type { string toString() { result = "type" } }
class ExprParent extends @exprparent { string toString() { result = "exprparent" } }
class SimplePatternInstanceOfExpr extends InstanceOfExpr {
SimplePatternInstanceOfExpr() { getNthChild(this, 2) instanceof LocalVariableDeclExpr }
}
class Type extends @type {
string toString() { result = "type" }
}
class ExprParent extends @exprparent {
string toString() { result = "exprparent" }
}
Expr getNthChild(ExprParent parent, int i) { exprs(result, _, _, parent, i) }
// 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.
// Any RecordPatternExpr should be replaced with an error expression, as it can't be represented in the downgraded dbscheme.
// This reverts a reorganisation of the representation of "o instanceof String s", which used to be InstanceOfExpr -0-> LocalVariableDeclExpr --init-> o
// \-name-> s
// It is now InstanceOfExpr --0-> o
// \-2-> LocalVariableDeclExpr -name-> s
//
// Other children are unaffected.
predicate hasNewParent(Expr e, ExprParent newParent, int newIndex) {
exists(SimplePatternInstanceOfExpr oldParent, int oldIndex |
e = getNthChild(oldParent, oldIndex) |
e = getNthChild(oldParent, oldIndex)
|
oldIndex = 0 and newParent = getNthChild(oldParent, 2) and newIndex = 0
or
oldIndex = 1 and newParent = oldParent and newIndex = oldIndex
@@ -31,11 +41,15 @@ predicate hasNewParent(Expr e, ExprParent newParent, int newIndex) {
or
not exists(SimplePatternInstanceOfExpr oldParent | e = getNthChild(oldParent, _)) and
exprs(e, _, _, newParent, newIndex)
}
from Expr e, int oldKind, int newKind, Type typeid, ExprParent parent, int index
where exprs(e, oldKind, typeid, _, _) and
hasNewParent(e, parent, index) and
(if oldKind = 89 /* record pattern */ then newKind = 74 /* error expression */ else oldKind = newKind)
where
exprs(e, oldKind, typeid, _, _) and
hasNewParent(e, parent, index) and
(
if oldKind = 89
then /* record pattern */ newKind = 74
else /* error expression */ oldKind = newKind
)
select e, newKind, typeid, parent, index