Swift: Trivial changes to get it compiling.

This commit is contained in:
Geoffrey White
2023-06-07 11:43:13 +01:00
parent 8ec377997d
commit 5f85b7419f
2 changed files with 25 additions and 25 deletions

View File

@@ -1,20 +1,16 @@
/** Provides a class hierarchy corresponding to a parse tree of regular expressions. */
/**
* Provides a class hierarchy corresponding to a parse tree of regular expressions.
*/
private import internal.ParseRegExp
import swift
private import internal.ParseRegex
private import codeql.util.Numbers
private import codeql.ruby.ast.Literal as Ast
private import codeql.Locations
private import codeql.regex.nfa.NfaUtils as NfaUtils
private import codeql.regex.RegexTreeView
// exporting as RegexTreeView, and in the top-level scope.
import Impl as RegexTreeView
import Impl
/** Gets the parse tree resulting from parsing `re`, if such has been constructed. */
RegExpTerm getParsedRegExp(Ast::RegExpLiteral re) {
result.getRegExp() = re and result.isRootTerm()
}
/**
* An element containing a regular expression term, that is, either
* a string literal (parsed as a regular expression)
@@ -211,25 +207,30 @@ private module Impl implements RegexTreeViewSig {
*/
Location getLocation() { result = re.getLocation() }
pragma[noinline]
/*pragma[noinline]
private predicate componentHasLocationInfo(
int i, string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
re.getComponent(i)
.getLocation()
.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
}
}*/
/** Holds if this term is found at the specified location offsets. */
predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
exists(int re_start |
/*exists(int re_start |
this.componentHasLocationInfo(0, filepath, startline, re_start, _, _) and
this.componentHasLocationInfo(re.getNumberOfComponents() - 1, filepath, _, _, endline, _) and
startcolumn = re_start + start and
endcolumn = re_start + end - 1
)
)*/
filepath = re.getFile().getAbsolutePath() and
startline = re.getLocation().getStartLine() and
startcolumn = re.getLocation().getStartColumn() and
endline = re.getLocation().getEndLine() and
endcolumn = re.getLocation().getEndColumn()
}
/** Gets the file in which this term is found. */
@@ -1196,7 +1197,7 @@ private module Impl implements RegexTreeViewSig {
* Holds if the regular expression should not be considered.
*/
predicate isExcluded(RegExpParent parent) {
parent.(RegExpTerm).getRegExp().(Ast::RegExpLiteral).hasFreeSpacingFlag() // exclude free-spacing mode regexes
none()//parent.(RegExpTerm).getRegExp().(Ast::RegExpLiteral).hasFreeSpacingFlag() // exclude free-spacing mode regexes
}
/**
@@ -1207,13 +1208,13 @@ private module Impl implements RegexTreeViewSig {
/**
* Holds if the regex that `term` is part of is used in a way that ignores any leading prefix of the input it's matched against.
* Not yet implemented for Ruby.
* Not yet implemented for Swift.
*/
predicate matchesAnyPrefix(RegExpTerm term) { any() }
/**
* Holds if the regex that `term` is part of is used in a way that ignores any trailing suffix of the input it's matched against.
* Not yet implemented for Ruby.
* Not yet implemented for Swift.
*/
predicate matchesAnySuffix(RegExpTerm term) { any() }

View File

@@ -1,19 +1,18 @@
/**
* Library for parsing for Ruby regular expressions.
* Library for parsing Swift regular expressions.
*
* N.B. does not yet handle stripping whitespace and comments in regexes with
* the `x` (free-spacing) flag.
*/
private import codeql.ruby.AST as Ast
private import codeql.Locations
import swift
/**
* A `StringlikeLiteral` containing a regular expression term, that is, either
* A `Expr` containing a regular expression term, that is, either
* a regular expression literal, or a string literal used in a context where
* it is parsed as regular expression.
*/
abstract class RegExp extends Ast::StringlikeLiteral {
abstract class RegExp extends Expr {
/**
* Holds if this `RegExp` has the `s` flag for multi-line matching.
*/
@@ -253,11 +252,11 @@ abstract class RegExp extends Ast::StringlikeLiteral {
this.getChar(pos) != "\\" and result = false
}
/** Gets the text of this regex */
/**
* Gets the text of this regex.
*/
string getText() {
exists(Ast::ConstantValue c | c = this.getConstantValue() |
result = [this.getConstantValue().getString(), this.getConstantValue().getRegExp()]
)
result = this.(StringLiteralExpr).getValue()
}
/** Gets the `i`th character of this regex */