Skip to content

Commit 2056473

Browse files
authored
Merge pull request github#12955 from geoffw0/swiftoddsends
Swift: Odds and ends
2 parents d18be93 + 9590dde commit 2056473

File tree

3 files changed

+38
-12
lines changed

3 files changed

+38
-12
lines changed

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

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,9 @@ class Method extends Function {
3232
cached
3333
predicate hasQualifiedName(string typeName, string funcName) {
3434
this.getName() = funcName and
35-
(
36-
exists(NominalTypeDecl c |
37-
c.getFullName() = typeName and
38-
c.getAMember() = this
39-
)
40-
or
41-
exists(ExtensionDecl e |
42-
e.getExtendedTypeDecl().getFullName() = typeName and
43-
e.getAMember() = this
44-
)
35+
exists(Decl d |
36+
d.asNominalTypeDecl().getFullName() = typeName and
37+
d.getAMember() = this
4538
)
4639
}
4740

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

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,44 @@ private import codeql.swift.generated.decl.TypeDecl
22
private import codeql.swift.elements.type.AnyGenericType
33
private import swift
44

5+
/**
6+
* A Swift type declaration, for example a class, struct, enum or protocol
7+
* declaration.
8+
*
9+
* Type declarations are distinct from types. A type declaration represents
10+
* the code that declares a type, for example:
11+
* ```
12+
* class MyClass {
13+
* ...
14+
* }
15+
* ```
16+
* Not all types have type declarations, for example built-in types do not
17+
* have type declarations.
18+
*/
519
class TypeDecl extends Generated::TypeDecl {
620
override string toString() { result = this.getName() }
721

22+
/**
23+
* Gets the declaration of the `index`th base type of this type declaration (0-based).
24+
*/
825
TypeDecl getBaseTypeDecl(int i) { result = this.getBaseType(i).(AnyGenericType).getDeclaration() }
926

27+
/**
28+
* Gets the declaration of any of the base types of this type declaration.
29+
*/
1030
TypeDecl getABaseTypeDecl() { result = this.getBaseTypeDecl(_) }
1131

12-
TypeDecl getDerivedTypeDecl(int i) { result.getBaseTypeDecl(i) = this }
32+
/**
33+
* Gets a declaration that has this type as its `index`th base type.
34+
*
35+
* DEPRECATED: The index is not very meaningful here. Use `getADerivedTypeDecl` or `getBaseTypeDecl`.
36+
*/
37+
deprecated TypeDecl getDerivedTypeDecl(int i) { result.getBaseTypeDecl(i) = this }
1338

14-
TypeDecl getADerivedTypeDecl() { result = this.getDerivedTypeDecl(_) }
39+
/**
40+
* Gets the declaration of any type derived from this type declaration.
41+
*/
42+
TypeDecl getADerivedTypeDecl() { result.getBaseTypeDecl(_) = this }
1543

1644
/**
1745
* Gets the full name of this `TypeDecl`. For example in:

swift/ql/lib/codeql/swift/elements/type/Type.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
private import codeql.swift.generated.type.Type
22

3+
/**
4+
* A Swift type.
5+
*
6+
* This QL class is the root of the Swift type hierarchy.
7+
*/
38
class Type extends Generated::Type {
49
override string toString() { result = this.getName() }
510

0 commit comments

Comments
 (0)