Skip to content

Commit d2f633b

Browse files
committed
Swift: Manual changes after running code generator
1 parent c785cd9 commit d2f633b

File tree

164 files changed

+2292
-1904
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

164 files changed

+2292
-1904
lines changed

swift/ql/lib/codeql/swift/elements/AstNodeImpl.qll

Lines changed: 66 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -5,80 +5,82 @@ private import codeql.swift.elements.expr.ClosureExpr
55
private import codeql.swift.elements.Callable
66
private import codeql.swift.generated.ParentChild
77

8-
private module Cached {
9-
private Element getEnclosingDeclStep(Element e) {
10-
not e instanceof Decl and
11-
result = getImmediateParent(e)
12-
}
8+
module Impl {
9+
private module Cached {
10+
private Element getEnclosingDeclStep(Element e) {
11+
not e instanceof Decl and
12+
result = getImmediateParent(e)
13+
}
1314

14-
cached
15-
Decl getEnclosingDecl(AstNode ast) { result = getEnclosingDeclStep*(getImmediateParent(ast)) }
15+
cached
16+
Decl getEnclosingDecl(AstNode ast) { result = getEnclosingDeclStep*(getImmediateParent(ast)) }
1617

17-
private Element getEnclosingFunctionStep(Element e) {
18-
not e instanceof Function and
19-
result = getEnclosingDecl(e)
20-
}
18+
private Element getEnclosingFunctionStep(Element e) {
19+
not e instanceof Function and
20+
result = getEnclosingDecl(e)
21+
}
2122

22-
cached
23-
Function getEnclosingFunction(AstNode ast) {
24-
result = getEnclosingFunctionStep*(getEnclosingDecl(ast))
25-
}
23+
cached
24+
Function getEnclosingFunction(AstNode ast) {
25+
result = getEnclosingFunctionStep*(getEnclosingDecl(ast))
26+
}
2627

27-
private Element getEnclosingClosureStep(Element e) {
28-
not e instanceof Callable and
29-
result = getImmediateParent(e)
30-
}
28+
private Element getEnclosingClosureStep(Element e) {
29+
not e instanceof Callable and
30+
result = getImmediateParent(e)
31+
}
3132

32-
cached
33-
ClosureExpr getEnclosingClosure(AstNode ast) {
34-
result = getEnclosingClosureStep*(getImmediateParent(ast))
33+
cached
34+
ClosureExpr getEnclosingClosure(AstNode ast) {
35+
result = getEnclosingClosureStep*(getImmediateParent(ast))
36+
}
3537
}
36-
}
3738

38-
/**
39-
* A node in the abstract syntax tree.
40-
*/
41-
class AstNode extends Generated::AstNode {
4239
/**
43-
* Gets the nearest function definition that contains this AST node, if any.
44-
* This includes functions, methods, (de)initializers, and accessors, but not closures.
45-
*
46-
* For example, in the following code, the AST node for `n + 1` has `foo` as its
47-
* enclosing function (via `getEnclosingFunction`), whereas its enclosing callable is
48-
* the closure `{(n : Int) in n + 1 }` (via `getEnclosingCallable`):
49-
*
50-
* ```swift
51-
* func foo() {
52-
* var f = { (n : Int) in n + 1 }
53-
* }
54-
* ```
40+
* A node in the abstract syntax tree.
5541
*/
56-
final Function getEnclosingFunction() { result = Cached::getEnclosingFunction(this) }
42+
class AstNode extends Generated::AstNode {
43+
/**
44+
* Gets the nearest function definition that contains this AST node, if any.
45+
* This includes functions, methods, (de)initializers, and accessors, but not closures.
46+
*
47+
* For example, in the following code, the AST node for `n + 1` has `foo` as its
48+
* enclosing function (via `getEnclosingFunction`), whereas its enclosing callable is
49+
* the closure `{(n : Int) in n + 1 }` (via `getEnclosingCallable`):
50+
*
51+
* ```swift
52+
* func foo() {
53+
* var f = { (n : Int) in n + 1 }
54+
* }
55+
* ```
56+
*/
57+
final Function getEnclosingFunction() { result = Cached::getEnclosingFunction(this) }
5758

58-
/**
59-
* Gets the nearest declaration that contains this AST node, if any.
60-
*
61-
* Note that the nearest declaration may be an extension of a type declaration. If you always
62-
* want the type declaration and not the extension, use `getEnclosingDecl().asNominalTypeDecl()`.
63-
*/
64-
final Decl getEnclosingDecl() { result = Cached::getEnclosingDecl(this) }
59+
/**
60+
* Gets the nearest declaration that contains this AST node, if any.
61+
*
62+
* Note that the nearest declaration may be an extension of a type declaration. If you always
63+
* want the type declaration and not the extension, use `getEnclosingDecl().asNominalTypeDecl()`.
64+
*/
65+
final Decl getEnclosingDecl() { result = Cached::getEnclosingDecl(this) }
6566

66-
/**
67-
* Gets the nearest `Callable` that contains this AST node, if any.
68-
* This includes (auto)closures, functions, methods, (de)initializers, and accessors.
69-
*
70-
* For example, in the following code, the AST node for `n + 1` has the closure
71-
* `{(n : Int) in n + 1 }` as its enclosing callable.
72-
*
73-
* ```swift
74-
* func foo() {
75-
* var f = { (n : Int) in n + 1 }
76-
* }
77-
* ```
78-
*/
79-
final Callable getEnclosingCallable() {
80-
if exists(Cached::getEnclosingClosure(this))
81-
then result = Cached::getEnclosingClosure(this)
82-
else result = Cached::getEnclosingFunction(this)
67+
/**
68+
* Gets the nearest `Callable` that contains this AST node, if any.
69+
* This includes (auto)closures, functions, methods, (de)initializers, and accessors.
70+
*
71+
* For example, in the following code, the AST node for `n + 1` has the closure
72+
* `{(n : Int) in n + 1 }` as its enclosing callable.
73+
*
74+
* ```swift
75+
* func foo() {
76+
* var f = { (n : Int) in n + 1 }
77+
* }
78+
* ```
79+
*/
80+
final Callable getEnclosingCallable() {
81+
if exists(Cached::getEnclosingClosure(this))
82+
then result = Cached::getEnclosingClosure(this)
83+
else result = Cached::getEnclosingFunction(this)
84+
}
8385
}
8486
}
Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
private import codeql.swift.generated.AvailabilityInfo
22

3-
// the following QLdoc is generated: if you need to edit it, do it in the schema file
4-
/**
5-
* An availability condition of an `if`, `while`, or `guard` statements.
6-
*
7-
* Examples:
8-
* ```
9-
* if #available(iOS 12, *) {
10-
* // Runs on iOS 12 and above
11-
* } else {
12-
* // Runs only anything below iOS 12
13-
* }
14-
* if #unavailable(macOS 10.14, *) {
15-
* // Runs only on macOS 10 and below
16-
* }
17-
* ```
18-
*/
19-
class AvailabilityInfo extends Generated::AvailabilityInfo {
20-
override string toString() {
21-
result = "#available" and not this.isUnavailable()
22-
or
23-
result = "#unavailable" and this.isUnavailable()
3+
module Impl {
4+
// the following QLdoc is generated: if you need to edit it, do it in the schema file
5+
/**
6+
* An availability condition of an `if`, `while`, or `guard` statements.
7+
*
8+
* Examples:
9+
* ```
10+
* if #available(iOS 12, *) {
11+
* // Runs on iOS 12 and above
12+
* } else {
13+
* // Runs only anything below iOS 12
14+
* }
15+
* if #unavailable(macOS 10.14, *) {
16+
* // Runs only on macOS 10 and below
17+
* }
18+
* ```
19+
*/
20+
class AvailabilityInfo extends Generated::AvailabilityInfo {
21+
override string toString() {
22+
result = "#available" and not this.isUnavailable()
23+
or
24+
result = "#unavailable" and this.isUnavailable()
25+
}
2426
}
2527
}

swift/ql/lib/codeql/swift/elements/CallableImpl.qll

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@ private import codeql.swift.generated.Callable
22
private import codeql.swift.elements.AstNode
33
private import codeql.swift.elements.decl.Decl
44

5-
class Callable extends Generated::Callable {
6-
/**
7-
* Holds if this Callable is a function named `funcName`.
8-
*/
9-
predicate hasName(string funcName) { this.getName() = funcName }
5+
module Impl {
6+
class Callable extends Generated::Callable {
7+
/**
8+
* Holds if this Callable is a function named `funcName`.
9+
*/
10+
predicate hasName(string funcName) { this.getName() = funcName }
1011

11-
/**
12-
* Holds if this Callable is a function named `funcName` defined in a module
13-
* called `moduleName`.
14-
*/
15-
predicate hasName(string moduleName, string funcName) {
16-
this.hasName(funcName) and
17-
this.(Decl).getModule().getFullName() = moduleName
12+
/**
13+
* Holds if this Callable is a function named `funcName` defined in a module
14+
* called `moduleName`.
15+
*/
16+
predicate hasName(string moduleName, string funcName) {
17+
this.hasName(funcName) and
18+
this.(Decl).getModule().getFullName() = moduleName
19+
}
1820
}
1921
}
Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,8 @@
11
private import codeql.swift.generated.Comment
22

3-
class Comment extends Generated::Comment {
4-
/** toString */
5-
override string toString() { result = this.getText() }
6-
}
7-
8-
class SingleLineComment extends Comment {
9-
SingleLineComment() {
10-
this.getText().matches("//%") and
11-
not this instanceof SingleLineDocComment
12-
}
13-
}
14-
15-
class MultiLineComment extends Comment {
16-
MultiLineComment() {
17-
this.getText().matches("/*%") and
18-
not this instanceof MultiLineDocComment
19-
}
20-
}
21-
22-
class DocComment extends Comment {
23-
DocComment() {
24-
this instanceof SingleLineDocComment or
25-
this instanceof MultiLineDocComment
3+
module Impl {
4+
class Comment extends Generated::Comment {
5+
/** toString */
6+
override string toString() { result = this.getText() }
267
}
278
}
28-
29-
class SingleLineDocComment extends Comment {
30-
SingleLineDocComment() { this.getText().matches("///%") }
31-
}
32-
33-
class MultiLineDocComment extends Comment {
34-
MultiLineDocComment() { this.getText().matches("/**%") }
35-
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import Comment
2+
3+
final class SingleLineComment extends Comment {
4+
SingleLineComment() {
5+
this.getText().matches("//%") and
6+
not this instanceof SingleLineDocComment
7+
}
8+
}
9+
10+
final class MultiLineComment extends Comment {
11+
MultiLineComment() {
12+
this.getText().matches("/*%") and
13+
not this instanceof MultiLineDocComment
14+
}
15+
}
16+
17+
abstract private class DocCommentImpl extends Comment { }
18+
19+
final class DocComment = DocCommentImpl;
20+
21+
final class SingleLineDocComment extends DocCommentImpl {
22+
SingleLineDocComment() { this.getText().matches("///%") }
23+
}
24+
25+
final class MultiLineDocComment extends DocCommentImpl {
26+
MultiLineDocComment() { this.getText().matches("/**%") }
27+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import Diagnostics
2+
3+
/**
4+
* A compiler error message.
5+
*/
6+
final class CompilerError extends Diagnostics {
7+
CompilerError() { this.getSeverity() = "error" }
8+
}
9+
10+
/**
11+
* A compiler-generated warning.
12+
*/
13+
final class CompilerWarning extends Diagnostics {
14+
CompilerWarning() { this.getSeverity() = "warning" }
15+
}
16+
17+
/**
18+
* A compiler-generated note (typically attached to an error or warning).
19+
*/
20+
final class CompilerNote extends Diagnostics {
21+
CompilerNote() { this.getSeverity() = "note" }
22+
}
23+
24+
/**
25+
* A compiler-generated remark (milder than a warning, this does not indicate an issue).
26+
*/
27+
final class CompilerRemark extends Diagnostics {
28+
CompilerRemark() { this.getSeverity() = "remark" }
29+
}
Lines changed: 17 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,23 @@
11
private import codeql.swift.generated.Diagnostics
22

3-
/**
4-
* A compiler-generated error, warning, note or remark.
5-
*/
6-
class Diagnostics extends Generated::Diagnostics {
7-
override string toString() { result = this.getSeverity() + ": " + this.getText() }
8-
3+
module Impl {
94
/**
10-
* Gets a string representing the severity of this compiler diagnostic.
5+
* A compiler-generated error, warning, note or remark.
116
*/
12-
string getSeverity() {
13-
this.getKind() = 1 and result = "error"
14-
or
15-
this.getKind() = 2 and result = "warning"
16-
or
17-
this.getKind() = 3 and result = "note"
18-
or
19-
this.getKind() = 4 and result = "remark"
20-
}
21-
}
22-
23-
/**
24-
* A compiler error message.
25-
*/
26-
class CompilerError extends Diagnostics {
27-
CompilerError() { this.getSeverity() = "error" }
28-
}
7+
class Diagnostics extends Generated::Diagnostics {
8+
override string toString() { result = this.getSeverity() + ": " + this.getText() }
299

30-
/**
31-
* A compiler-generated warning.
32-
*/
33-
class CompilerWarning extends Diagnostics {
34-
CompilerWarning() { this.getSeverity() = "warning" }
35-
}
36-
37-
/**
38-
* A compiler-generated note (typically attached to an error or warning).
39-
*/
40-
class CompilerNote extends Diagnostics {
41-
CompilerNote() { this.getSeverity() = "note" }
42-
}
43-
44-
/**
45-
* A compiler-generated remark (milder than a warning, this does not indicate an issue).
46-
*/
47-
class CompilerRemark extends Diagnostics {
48-
CompilerRemark() { this.getSeverity() = "remark" }
10+
/**
11+
* Gets a string representing the severity of this compiler diagnostic.
12+
*/
13+
string getSeverity() {
14+
this.getKind() = 1 and result = "error"
15+
or
16+
this.getKind() = 2 and result = "warning"
17+
or
18+
this.getKind() = 3 and result = "note"
19+
or
20+
this.getKind() = 4 and result = "remark"
21+
}
22+
}
4923
}

0 commit comments

Comments
 (0)