mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Autoformat upgrade/downgrade scripts
This commit is contained in:
@@ -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 LocalVariableDeclExpr extends @localvariabledeclexpr, Expr { }
|
||||||
|
|
||||||
class InstanceOfExpr extends @instanceofexpr, 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 SimplePatternInstanceOfExpr extends InstanceOfExpr {
|
||||||
class ExprParent extends @exprparent { string toString() { result = "exprparent" } }
|
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) }
|
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.
|
// 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.
|
// 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
|
// This reverts a reorganisation of the representation of "o instanceof String s", which used to be InstanceOfExpr -0-> LocalVariableDeclExpr --init-> o
|
||||||
// \-name-> s
|
// \-name-> s
|
||||||
// It is now InstanceOfExpr --0-> o
|
// It is now InstanceOfExpr --0-> o
|
||||||
// \-2-> LocalVariableDeclExpr -name-> s
|
// \-2-> LocalVariableDeclExpr -name-> s
|
||||||
//
|
//
|
||||||
// Other children are unaffected.
|
// Other children are unaffected.
|
||||||
|
|
||||||
|
|
||||||
predicate hasNewParent(Expr e, ExprParent newParent, int newIndex) {
|
predicate hasNewParent(Expr e, ExprParent newParent, int newIndex) {
|
||||||
|
|
||||||
exists(SimplePatternInstanceOfExpr oldParent, int oldIndex |
|
exists(SimplePatternInstanceOfExpr oldParent, int oldIndex |
|
||||||
e = getNthChild(oldParent, oldIndex) |
|
e = getNthChild(oldParent, oldIndex)
|
||||||
|
|
|
||||||
oldIndex = 0 and newParent = getNthChild(oldParent, 2) and newIndex = 0
|
oldIndex = 0 and newParent = getNthChild(oldParent, 2) and newIndex = 0
|
||||||
or
|
or
|
||||||
oldIndex = 1 and newParent = oldParent and newIndex = oldIndex
|
oldIndex = 1 and newParent = oldParent and newIndex = oldIndex
|
||||||
@@ -31,11 +41,15 @@ predicate hasNewParent(Expr e, ExprParent newParent, int newIndex) {
|
|||||||
or
|
or
|
||||||
not exists(SimplePatternInstanceOfExpr oldParent | e = getNthChild(oldParent, _)) and
|
not exists(SimplePatternInstanceOfExpr oldParent | e = getNthChild(oldParent, _)) and
|
||||||
exprs(e, _, _, newParent, newIndex)
|
exprs(e, _, _, newParent, newIndex)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
from Expr e, int oldKind, int newKind, Type typeid, ExprParent parent, int index
|
from Expr e, int oldKind, int newKind, Type typeid, ExprParent parent, int index
|
||||||
where exprs(e, oldKind, typeid, _, _) and
|
where
|
||||||
hasNewParent(e, parent, index) and
|
exprs(e, oldKind, typeid, _, _) and
|
||||||
(if oldKind = 89 /* record pattern */ then newKind = 74 /* error expression */ else oldKind = newKind)
|
hasNewParent(e, parent, index) and
|
||||||
|
(
|
||||||
|
if oldKind = 89
|
||||||
|
then /* record pattern */ newKind = 74
|
||||||
|
else /* error expression */ oldKind = newKind
|
||||||
|
)
|
||||||
select e, newKind, typeid, parent, index
|
select e, newKind, typeid, parent, index
|
||||||
|
|||||||
@@ -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 LocalVariableDeclExpr extends @localvariabledeclexpr, Expr { }
|
||||||
|
|
||||||
class InstanceOfExpr extends @instanceofexpr, 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,
|
// 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.
|
// 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
|
// \-2-> LocalVariableDeclExpr -name-> s
|
||||||
//
|
//
|
||||||
// Other children are unaffected.
|
// Other children are unaffected.
|
||||||
|
|
||||||
ExprParent getParent(Expr e) { exprs(e, _, _, result, _) }
|
ExprParent getParent(Expr e) { exprs(e, _, _, result, _) }
|
||||||
|
|
||||||
predicate hasNewParent(Expr e, ExprParent newParent, int newIndex) {
|
predicate hasNewParent(Expr e, ExprParent newParent, int newIndex) {
|
||||||
if (getParent(e) instanceof LocalVariableDeclExpr and getParent(getParent(e)) instanceof InstanceOfExpr)
|
if
|
||||||
then (newParent = getParent(getParent(e)) and newIndex = 0) // Initialiser moves to hang directly off the instanceof expression
|
getParent(e) instanceof LocalVariableDeclExpr and
|
||||||
else (
|
getParent(getParent(e)) instanceof InstanceOfExpr
|
||||||
if (e instanceof LocalVariableDeclExpr and getParent(e) instanceof InstanceOfExpr)
|
then (
|
||||||
then (newParent = getParent(e) and newIndex = 2) // Variable declaration moves to be the instanceof expression's 2nd child
|
newParent = getParent(getParent(e)) and newIndex = 0
|
||||||
else exprs(e, _, _, newParent, newIndex) // Other expressions unchanged
|
) 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
|
from Expr e, int kind, Type typeid, ExprParent parent, int index
|
||||||
where exprs(e, kind, typeid, _, _) and
|
where
|
||||||
hasNewParent(e, parent, index)
|
exprs(e, kind, typeid, _, _) and
|
||||||
|
hasNewParent(e, parent, index)
|
||||||
select e, kind, typeid, parent, index
|
select e, kind, typeid, parent, index
|
||||||
|
|||||||
Reference in New Issue
Block a user