Repository navigation
Commit 52b35ef
authored
Commit 2: Adapt Ruby regex library to compile against C++
Changes from verbatim Ruby baseline (Commit 1) to compilable C++:
ParseRegExp.qll:
- Remove: private import codeql.ruby.AST as Ast
- Remove: private import codeql.Locations
- Add: private import semmle.code.cpp.exprs.Literal
- Change RegExp base: Ast::StringlikeLiteral -> StringLiteral
- Replace getText(): removes getConstantValue() Ruby accessor, uses getValue()
(C++ StringLiteral.getValue() returns the string content, analogous to
Ruby's getConstantValue().getString())
RegexTreeView.qll:
- Remove Ruby-specific imports (codeql.ruby.AST, codeql.Locations,
codeql.regex.nfa.NfaUtils)
- Add: private import semmle.code.cpp.exprs.Literal
- Keep: codeql.util.Numbers (for parseHexInt in RegExpEscape.getUnicode())
- Keep: codeql.regex.RegexTreeView (satisfies RegexTreeViewSig)
- Change getParsedRegExp: Ast::RegExpLiteral -> StringLiteral
- Simplify hasLocationInfo to use re.getLocation() directly with +1 offset
for opening quote (approximate; fixed in commits 8-9)
- Replace isExcluded: remove hasFreeSpacingFlag(), use none()
- Ruby dialect features preserved unchanged (\\A, \\z, \\G, \\h, etc.);
dialect shift is commit 5
Test queries:
- parse.ql, regexp.ql: replace codeql.ruby.Regexp with
semmle.code.cpp.regex.RegexTreeView
- .expected cleared (no test.cpp until commit 3)
Verified: both queries compile successfully with codeql query compile.1 parent 90a14d8 commit 52b35ef
6 files changed
Lines changed: 33 additions & 812 deletions
File tree
- cpp/ql
- lib/semmle/code/cpp/regex
- internal
- test/library-tests/regex
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | 3 | | |
7 | 4 | | |
8 | 5 | | |
9 | 6 | | |
10 | | - | |
11 | | - | |
12 | | - | |
| 7 | + | |
13 | 8 | | |
14 | 9 | | |
15 | 10 | | |
16 | 11 | | |
17 | 12 | | |
18 | 13 | | |
19 | | - | |
| 14 | + | |
20 | 15 | | |
21 | 16 | | |
22 | 17 | | |
| |||
60 | 55 | | |
61 | 56 | | |
62 | 57 | | |
63 | | - | |
| 58 | + | |
64 | 59 | | |
65 | 60 | | |
66 | 61 | | |
| |||
216 | 211 | | |
217 | 212 | | |
218 | 213 | | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
229 | 219 | | |
230 | 220 | | |
231 | 221 | | |
232 | 222 | | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
237 | 226 | | |
238 | 227 | | |
239 | 228 | | |
| |||
317 | 306 | | |
318 | 307 | | |
319 | 308 | | |
320 | | - | |
| 309 | + | |
321 | 310 | | |
322 | 311 | | |
323 | 312 | | |
| |||
665 | 654 | | |
666 | 655 | | |
667 | 656 | | |
668 | | - | |
669 | | - | |
670 | | - | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
671 | 660 | | |
672 | 661 | | |
673 | 662 | | |
| |||
1119 | 1108 | | |
1120 | 1109 | | |
1121 | 1110 | | |
1122 | | - | |
| 1111 | + | |
1123 | 1112 | | |
1124 | 1113 | | |
1125 | 1114 | | |
| |||
1200 | 1189 | | |
1201 | 1190 | | |
1202 | 1191 | | |
1203 | | - | |
1204 | | - | |
1205 | | - | |
| 1192 | + | |
1206 | 1193 | | |
1207 | 1194 | | |
1208 | 1195 | | |
| |||
1212 | 1199 | | |
1213 | 1200 | | |
1214 | 1201 | | |
1215 | | - | |
| 1202 | + | |
1216 | 1203 | | |
1217 | 1204 | | |
1218 | 1205 | | |
1219 | 1206 | | |
1220 | 1207 | | |
1221 | | - | |
| 1208 | + | |
1222 | 1209 | | |
1223 | 1210 | | |
1224 | 1211 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | 6 | | |
10 | 7 | | |
11 | | - | |
12 | | - | |
| 8 | + | |
13 | 9 | | |
14 | 10 | | |
15 | | - | |
| 11 | + | |
16 | 12 | | |
17 | | - | |
| 13 | + | |
18 | 14 | | |
19 | | - | |
| 15 | + | |
20 | 16 | | |
21 | 17 | | |
22 | 18 | | |
| |||
256 | 252 | | |
257 | 253 | | |
258 | 254 | | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
| 255 | + | |
| 256 | + | |
265 | 257 | | |
266 | 258 | | |
267 | 259 | | |
| |||
0 commit comments