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,8 +1,18 @@
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 Type extends @type { string toString() { result = "type" } }
class ExprParent extends @exprparent { string toString() { result = "exprparent" } }
class Type extends @type {
string toString() { result = "type" }
}
class ExprParent extends @exprparent {
string toString() { result = "exprparent" }
}
// 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,
// while the LocalVariableDeclExpr, now without an initialiser, should become its 2nd child.
@@ -12,20 +22,26 @@ class ExprParent extends @exprparent { string toString() { result = "exprparent"
// \-2-> LocalVariableDeclExpr -name-> s
//
// Other children are unaffected.
ExprParent getParent(Expr e) { exprs(e, _, _, result, _) }
predicate hasNewParent(Expr e, ExprParent newParent, int newIndex) {
if (getParent(e) instanceof LocalVariableDeclExpr and getParent(getParent(e)) instanceof InstanceOfExpr)
then (newParent = getParent(getParent(e)) and newIndex = 0) // Initialiser moves to hang directly off the instanceof expression
else (
if (e instanceof LocalVariableDeclExpr and getParent(e) instanceof InstanceOfExpr)
then (newParent = getParent(e) and newIndex = 2) // Variable declaration moves to be the instanceof expression's 2nd child
else exprs(e, _, _, newParent, newIndex) // Other expressions unchanged
if
getParent(e) instanceof LocalVariableDeclExpr and
getParent(getParent(e)) instanceof InstanceOfExpr
then (
newParent = getParent(getParent(e)) and newIndex = 0
) else (
// Initialiser moves to hang directly off the instanceof expression
if e instanceof LocalVariableDeclExpr and getParent(e) instanceof InstanceOfExpr
then newParent = getParent(e) and newIndex = 2
else
// Variable declaration moves to be the instanceof expression's 2nd child
exprs(e, _, _, newParent, newIndex) // Other expressions unchanged
)
}
from Expr e, int kind, Type typeid, ExprParent parent, int index
where exprs(e, kind, typeid, _, _) and
hasNewParent(e, parent, index)
where
exprs(e, kind, typeid, _, _) and
hasNewParent(e, parent, index)
select e, kind, typeid, parent, index