-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathexprs.ql
More file actions
38 lines (33 loc) · 968 Bytes
/
exprs.ql
File metadata and controls
38 lines (33 loc) · 968 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class ExprParent extends @exprparent {
string toString() { result = "exprparent" }
}
class Expr extends ExprParent, @expr {
override string toString() { result = "expr" }
}
class ParExpr extends Expr, @parexpr {
override string toString() { result = "(...)" }
}
class Type extends @type {
string toString() { result = "type" }
}
predicate astlink(ExprParent parent, Expr e, int idx, int parens) {
exprs(e, _, _, parent, idx) and
parens = 0 and
not parent instanceof ParExpr and
e instanceof ParExpr
or
exists(ParExpr pe |
exprs(e, _, _, pe, _) and
astlink(parent, pe, idx, parens - 1)
)
}
from Expr id, int kind, Type typeid, ExprParent oldparent, ExprParent parent, int oldidx, int idx
where
exprs(id, kind, typeid, oldparent, oldidx) and
not id instanceof ParExpr and
if oldparent instanceof ParExpr
then astlink(parent, id, idx, _)
else (
parent = oldparent and idx = oldidx
)
select id, kind, typeid, parent, idx