forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring_interpol_insert.ql
More file actions
39 lines (34 loc) · 979 Bytes
/
string_interpol_insert.ql
File metadata and controls
39 lines (34 loc) · 979 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
39
class Expr extends @expr {
string toString() { none() }
}
class TypeOrRef extends @type_or_ref {
string toString() { none() }
}
class InterpolatedStringInsertExpr extends Expr, @interpolated_string_insert_expr { }
private predicate remove_expr(Expr e) {
exists(InterpolatedStringInsertExpr ie |
e = ie
or
// Alignment
expr_parent(e, 1, ie)
or
// Format
expr_parent(e, 2, ie)
)
}
query predicate new_expressions(Expr e, int kind, TypeOrRef t) {
expressions(e, kind, t) and
// Remove the syntheetic intert expression and previously un-extracted children
not remove_expr(e)
}
query predicate new_expr_parent(Expr e, int child, Expr parent) {
expr_parent(e, child, parent) and
not remove_expr(e) and
not remove_expr(parent)
or
// Use the string interpolation as parent instead of the synthetic insert expression
exists(InterpolatedStringInsertExpr ie |
expr_parent(e, 0, ie) and
expr_parent(ie, child, parent)
)
}