Files
codeql/cpp/ql/test/library-tests/regex/parse.ql
copilot-swe-agent[bot] 52b35ef08e 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.
2026-07-21 10:08:22 +00:00

28 lines
736 B
Plaintext

/**
* @kind graph
*/
import cpp
import semmle.code.cpp.regex.RegexTreeView as RE
query predicate nodes(RE::RegExpTerm n, string attr, string val) {
attr = "semmle.label" and
val = "[" + concat(n.getAPrimaryQlClass(), ", ") + "] " + n.toString()
or
attr = "semmle.order" and
val =
any(int i |
n =
rank[i](RE::RegExpTerm t, string fp, int sl, int sc, int el, int ec |
t.hasLocationInfo(fp, sl, sc, el, ec)
|
t order by fp, sl, sc, el, ec, t.toString()
)
).toString()
}
query predicate edges(RE::RegExpTerm pred, RE::RegExpTerm succ, string attr, string val) {
attr in ["semmle.label", "semmle.order"] and
val = any(int i | succ = pred.getChild(i)).toString()
}