Skip to content

Commit 7f47e31

Browse files
committed
C++: Add upgrade and downgrade scripts
1 parent b4caba7 commit 7f47e31

File tree

8 files changed

+10160
-0
lines changed

8 files changed

+10160
-0
lines changed
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
class Accessible extends @accessible {
2+
string toString() { none() }
3+
}
4+
5+
class Container extends @container {
6+
string toString() { none() }
7+
}
8+
9+
class Expr extends @expr {
10+
string toString() { none() }
11+
}
12+
13+
class Initialiser extends @initialiser {
14+
string toString() { none() }
15+
}
16+
17+
class Location extends @location_default {
18+
string toString() { none() }
19+
}
20+
21+
class Stmt extends @stmt {
22+
string toString() { none() }
23+
}
24+
25+
predicate isLocationDefault(Location l) {
26+
diagnostics(_, _, _, _, _, l)
27+
or
28+
macroinvocations(_, _, l, _)
29+
or
30+
fun_decls(_, _, _, _, l)
31+
or
32+
var_decls(_, _, _, _, l)
33+
or
34+
type_decls(_, _, l)
35+
or
36+
namespace_decls(_, _, l, _)
37+
or
38+
namespace_decls(_, _, _, l)
39+
or
40+
usings(_, _, l, _)
41+
or
42+
static_asserts(_, _, _, l, _)
43+
or
44+
enumconstants(_, _, _, _, _, l)
45+
or
46+
concept_templates(_, _, l)
47+
or
48+
attributes(_, _, _, _, l)
49+
or
50+
attribute_args(_, _, _, _, l)
51+
or
52+
derivations(_, _, _, _, l)
53+
or
54+
frienddecls(_, _, _, l)
55+
or
56+
comments(_, _, l)
57+
or
58+
namequalifiers(_, _, _, l)
59+
or
60+
lambda_capture(_, _, _, _, _, _, l)
61+
or
62+
preprocdirects(_, _, l)
63+
or
64+
xmllocations(_, l)
65+
or
66+
locations_default(l, _, 0, 0, 0, 0) // For containers.
67+
}
68+
69+
predicate isLocationExpr(Location l) {
70+
initialisers(_, _, _, l)
71+
or
72+
exprs(_, _, l)
73+
}
74+
75+
predicate isLocationStmt(Location l) { stmts(_, _, l) }
76+
77+
newtype TExprOrStmtLocation =
78+
TExprLocation(Location l, Container c, int startLine, int startColumn, int endLine, int endColumn) {
79+
isLocationExpr(l) and
80+
(isLocationDefault(l) or isLocationStmt(l)) and
81+
locations_default(l, c, startLine, startColumn, endLine, endColumn)
82+
} or
83+
TStmtLocation(Location l, Container c, int startLine, int startColumn, int endLine, int endColumn) {
84+
isLocationStmt(l) and
85+
(isLocationDefault(l) or isLocationExpr(l)) and
86+
locations_default(l, c, startLine, startColumn, endLine, endColumn)
87+
}
88+
89+
module Fresh = QlBuiltins::NewEntity<TExprOrStmtLocation>;
90+
91+
class NewLocationBase = @location_default or Fresh::EntityId;
92+
93+
class NewLocation extends NewLocationBase {
94+
string toString() { none() }
95+
}
96+
97+
query predicate new_locations_default(
98+
NewLocation l, Container c, int startLine, int startColumn, int endLine, int endColumn
99+
) {
100+
isLocationDefault(l) and
101+
locations_default(l, c, startLine, startColumn, endLine, endColumn)
102+
}
103+
104+
query predicate new_locations_expr(
105+
NewLocation l, Container c, int startLine, int startColumn, int endLine, int endColumn
106+
) {
107+
exists(Location l_old |
108+
isLocationExpr(l_old) and
109+
locations_default(l_old, c, startLine, startColumn, endLine, endColumn)
110+
|
111+
if not isLocationDefault(l_old) and not isLocationStmt(l)
112+
then l = l_old
113+
else l = Fresh::map(TExprLocation(l_old, c, startLine, startColumn, endLine, endColumn))
114+
)
115+
}
116+
117+
query predicate new_locations_stmt(
118+
NewLocation l, Container c, int startLine, int startColumn, int endLine, int endColumn
119+
) {
120+
exists(Location l_old |
121+
isLocationStmt(l_old) and
122+
locations_default(l_old, c, startLine, startColumn, endLine, endColumn)
123+
|
124+
if not isLocationDefault(l_old) and not isLocationExpr(l)
125+
then l = l_old
126+
else l = Fresh::map(TStmtLocation(l_old, c, startLine, startColumn, endLine, endColumn))
127+
)
128+
}
129+
130+
query predicate new_exprs(Expr e, int kind, NewLocation l) {
131+
exists(Location l_old, Container c, int startLine, int startColumn, int endLine, int endColumn |
132+
exprs(e, kind, l_old) and
133+
locations_default(l_old, c, startLine, startColumn, endLine, endColumn)
134+
|
135+
if not isLocationDefault(l_old) and not isLocationStmt(l)
136+
then l = l_old
137+
else l = Fresh::map(TExprLocation(l_old, c, startLine, startColumn, endLine, endColumn))
138+
)
139+
}
140+
141+
query predicate new_initialisers(Initialiser i, Accessible v, Expr e, NewLocation l) {
142+
exists(Location l_old, Container c, int startLine, int startColumn, int endLine, int endColumn |
143+
initialisers(i, v, e, l_old) and
144+
locations_default(l_old, c, startLine, startColumn, endLine, endColumn)
145+
|
146+
if not isLocationDefault(l_old) and not isLocationStmt(l)
147+
then l = l_old
148+
else l = Fresh::map(TExprLocation(l_old, c, startLine, startColumn, endLine, endColumn))
149+
)
150+
}
151+
152+
query predicate new_stmts(Stmt s, int kind, NewLocation l) {
153+
exists(Location l_old, Container c, int startLine, int startColumn, int endLine, int endColumn |
154+
stmts(s, kind, l_old) and
155+
locations_default(l_old, c, startLine, startColumn, endLine, endColumn)
156+
|
157+
if not isLocationDefault(l_old) and not isLocationExpr(l)
158+
then l = l_old
159+
else l = Fresh::map(TStmtLocation(l_old, c, startLine, startColumn, endLine, endColumn))
160+
)
161+
}

0 commit comments

Comments
 (0)