Skip to content

Commit 5f85b74

Browse files
committed
Swift: Trivial changes to get it compiling.
1 parent 8ec3779 commit 5f85b74

2 files changed

Lines changed: 25 additions & 25 deletions

File tree

swift/ql/lib/codeql/swift/regex/RegexTreeView.qll

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
1-
/** Provides a class hierarchy corresponding to a parse tree of regular expressions. */
1+
/**
2+
* Provides a class hierarchy corresponding to a parse tree of regular expressions.
3+
*/
24

3-
private import internal.ParseRegExp
5+
import swift
6+
private import internal.ParseRegex
47
private import codeql.util.Numbers
5-
private import codeql.ruby.ast.Literal as Ast
6-
private import codeql.Locations
78
private import codeql.regex.nfa.NfaUtils as NfaUtils
89
private import codeql.regex.RegexTreeView
910
// exporting as RegexTreeView, and in the top-level scope.
1011
import Impl as RegexTreeView
1112
import Impl
1213

13-
/** Gets the parse tree resulting from parsing `re`, if such has been constructed. */
14-
RegExpTerm getParsedRegExp(Ast::RegExpLiteral re) {
15-
result.getRegExp() = re and result.isRootTerm()
16-
}
17-
1814
/**
1915
* An element containing a regular expression term, that is, either
2016
* a string literal (parsed as a regular expression)
@@ -211,25 +207,30 @@ private module Impl implements RegexTreeViewSig {
211207
*/
212208
Location getLocation() { result = re.getLocation() }
213209

214-
pragma[noinline]
210+
/*pragma[noinline]
215211
private predicate componentHasLocationInfo(
216212
int i, string filepath, int startline, int startcolumn, int endline, int endcolumn
217213
) {
218214
re.getComponent(i)
219215
.getLocation()
220216
.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
221-
}
217+
}*/
222218

223219
/** Holds if this term is found at the specified location offsets. */
224220
predicate hasLocationInfo(
225221
string filepath, int startline, int startcolumn, int endline, int endcolumn
226222
) {
227-
exists(int re_start |
223+
/*exists(int re_start |
228224
this.componentHasLocationInfo(0, filepath, startline, re_start, _, _) and
229225
this.componentHasLocationInfo(re.getNumberOfComponents() - 1, filepath, _, _, endline, _) and
230226
startcolumn = re_start + start and
231227
endcolumn = re_start + end - 1
232-
)
228+
)*/
229+
filepath = re.getFile().getAbsolutePath() and
230+
startline = re.getLocation().getStartLine() and
231+
startcolumn = re.getLocation().getStartColumn() and
232+
endline = re.getLocation().getEndLine() and
233+
endcolumn = re.getLocation().getEndColumn()
233234
}
234235

235236
/** Gets the file in which this term is found. */
@@ -1196,7 +1197,7 @@ private module Impl implements RegexTreeViewSig {
11961197
* Holds if the regular expression should not be considered.
11971198
*/
11981199
predicate isExcluded(RegExpParent parent) {
1199-
parent.(RegExpTerm).getRegExp().(Ast::RegExpLiteral).hasFreeSpacingFlag() // exclude free-spacing mode regexes
1200+
none()//parent.(RegExpTerm).getRegExp().(Ast::RegExpLiteral).hasFreeSpacingFlag() // exclude free-spacing mode regexes
12001201
}
12011202

12021203
/**
@@ -1207,13 +1208,13 @@ private module Impl implements RegexTreeViewSig {
12071208

12081209
/**
12091210
* 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.
1210-
* Not yet implemented for Ruby.
1211+
* Not yet implemented for Swift.
12111212
*/
12121213
predicate matchesAnyPrefix(RegExpTerm term) { any() }
12131214

12141215
/**
12151216
* 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.
1216-
* Not yet implemented for Ruby.
1217+
* Not yet implemented for Swift.
12171218
*/
12181219
predicate matchesAnySuffix(RegExpTerm term) { any() }
12191220

swift/ql/lib/codeql/swift/regex/internal/ParseRegex.qll

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
/**
2-
* Library for parsing for Ruby regular expressions.
2+
* Library for parsing Swift regular expressions.
33
*
44
* N.B. does not yet handle stripping whitespace and comments in regexes with
55
* the `x` (free-spacing) flag.
66
*/
77

8-
private import codeql.ruby.AST as Ast
9-
private import codeql.Locations
8+
import swift
109

1110
/**
12-
* A `StringlikeLiteral` containing a regular expression term, that is, either
11+
* A `Expr` containing a regular expression term, that is, either
1312
* a regular expression literal, or a string literal used in a context where
1413
* it is parsed as regular expression.
1514
*/
16-
abstract class RegExp extends Ast::StringlikeLiteral {
15+
abstract class RegExp extends Expr {
1716
/**
1817
* Holds if this `RegExp` has the `s` flag for multi-line matching.
1918
*/
@@ -253,11 +252,11 @@ abstract class RegExp extends Ast::StringlikeLiteral {
253252
this.getChar(pos) != "\\" and result = false
254253
}
255254

256-
/** Gets the text of this regex */
255+
/**
256+
* Gets the text of this regex.
257+
*/
257258
string getText() {
258-
exists(Ast::ConstantValue c | c = this.getConstantValue() |
259-
result = [this.getConstantValue().getString(), this.getConstantValue().getRegExp()]
260-
)
259+
result = this.(StringLiteralExpr).getValue()
261260
}
262261

263262
/** Gets the `i`th character of this regex */

0 commit comments

Comments
 (0)