Skip to content

Commit abb98be

Browse files
committed
Swift: QLDoc Type.qll, TypeDecl.qll, and deprecate one of the predicates.
1 parent fc65160 commit abb98be

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

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)