Skip to content

Commit 4383aef

Browse files
authored
Merge pull request #9328 from MathiasVP/swift-to-string
Swift: Improve `toString` implementations for Ast classes
2 parents 57b9e6e + 795c011 commit 4383aef

File tree

140 files changed

+4530
-4164
lines changed

Some content is hidden

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

140 files changed

+4530
-4164
lines changed
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// generated by codegen/codegen.py, remove this comment if you wish to edit this file
21
private import codeql.swift.generated.decl.AbstractFunctionDecl
32

4-
class AbstractFunctionDecl extends AbstractFunctionDeclBase { }
3+
class AbstractFunctionDecl extends AbstractFunctionDeclBase {
4+
override string toString() { result = this.getName() }
5+
}

swift/ql/lib/codeql/swift/elements/decl/AccessorDecl.qll

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
11
private import codeql.swift.generated.decl.AccessorDecl
22

3+
private predicate isKnownAccessorKind(AccessorDecl decl, string kind) {
4+
decl.isGetter() and kind = "get"
5+
or
6+
decl.isSetter() and kind = "set"
7+
or
8+
decl.isWillSet() and kind = "willSet"
9+
or
10+
decl.isDidSet() and kind = "didSet"
11+
}
12+
313
class AccessorDecl extends AccessorDeclBase {
414
predicate isPropertyObserver() {
515
this instanceof WillSetObserver or this instanceof DidSetObserver
616
}
17+
18+
override string toString() {
19+
isKnownAccessorKind(this, result)
20+
or
21+
not isKnownAccessorKind(this, _) and
22+
result = super.toString()
23+
}
724
}
825

926
class WillSetObserver extends AccessorDecl {
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// generated by codegen/codegen.py, remove this comment if you wish to edit this file
21
private import codeql.swift.generated.decl.ConstructorDecl
32

4-
class ConstructorDecl extends ConstructorDeclBase { }
3+
class ConstructorDecl extends ConstructorDeclBase {
4+
override string toString() { result = "deinit" }
5+
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// generated by codegen/codegen.py, remove this comment if you wish to edit this file
21
private import codeql.swift.generated.decl.DestructorDecl
32

4-
class DestructorDecl extends DestructorDeclBase { }
3+
class DestructorDecl extends DestructorDeclBase {
4+
override string toString() { result = "init" }
5+
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// generated by codegen/codegen.py, remove this comment if you wish to edit this file
21
private import codeql.swift.generated.decl.EnumCaseDecl
32

4-
class EnumCaseDecl extends EnumCaseDeclBase { }
3+
class EnumCaseDecl extends EnumCaseDeclBase {
4+
override string toString() { result = "case ..." }
5+
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// generated by codegen/codegen.py, remove this comment if you wish to edit this file
21
private import codeql.swift.generated.decl.EnumElementDecl
32

4-
class EnumElementDecl extends EnumElementDeclBase { }
3+
class EnumElementDecl extends EnumElementDeclBase {
4+
override string toString() { result = this.getName() }
5+
}
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
// generated by codegen/codegen.py, remove this comment if you wish to edit this file
21
private import codeql.swift.generated.decl.ExtensionDecl
32

4-
class ExtensionDecl extends ExtensionDeclBase { }
3+
class ExtensionDecl extends ExtensionDeclBase {
4+
override string toString() {
5+
result = "extension" // TODO: Once we extract the name of this one we can provide a better `toString`.
6+
}
7+
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// generated by codegen/codegen.py, remove this comment if you wish to edit this file
21
private import codeql.swift.generated.decl.IfConfigDecl
32

4-
class IfConfigDecl extends IfConfigDeclBase { }
3+
class IfConfigDecl extends IfConfigDeclBase {
4+
override string toString() { result = "#if ..." }
5+
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// generated by codegen/codegen.py, remove this comment if you wish to edit this file
21
private import codeql.swift.generated.decl.ImportDecl
32

4-
class ImportDecl extends ImportDeclBase { }
3+
class ImportDecl extends ImportDeclBase {
4+
override string toString() { result = "import ..." }
5+
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// generated by codegen/codegen.py, remove this comment if you wish to edit this file
21
private import codeql.swift.generated.decl.OperatorDecl
32

4-
class OperatorDecl extends OperatorDeclBase { }
3+
class OperatorDecl extends OperatorDeclBase {
4+
override string toString() { result = this.getName() }
5+
}

0 commit comments

Comments
 (0)