Skip to content

Commit 8d02bcc

Browse files
committed
Swift: change non-generated TypeDecl.ql
1 parent cf1667c commit 8d02bcc

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

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

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,53 @@ private import swift
1919
class TypeDecl extends Generated::TypeDecl {
2020
override string toString() { result = this.getName() }
2121

22+
/**
23+
* Gets the `index`th base type of this type declaration (0-based).
24+
*
25+
* This is the same as `getImmediateInheritedType`.
26+
* DEPRECATED: either use `getImmediateInheritedType` or unindexed `getABaseType`.
27+
*/
28+
deprecated Type getImmediateBaseType(int index) { result = this.getImmediateInheritedType(index) }
29+
30+
/**
31+
* Gets the `index`th base type of this type declaration (0-based).
32+
* This is the same as `getInheritedType`.
33+
* DEPRECATED: use `getInheritedType` or unindexed `getABaseType`.
34+
*/
35+
deprecated Type getBaseType(int index) { result = this.getInheritedType(index) }
36+
37+
/**
38+
* Gets any of the base types of this type declaration.
39+
*/
40+
Type getABaseType() {
41+
// TODO generalize this to resolve `TypeAliasDecl`s and consider bases added by extensions
42+
result = this.getAnInheritedType()
43+
}
44+
2245
/**
2346
* Gets the declaration of the `index`th base type of this type declaration (0-based).
47+
* DEPRECATED: The index is not very meaningful here. Use `getABaseTypeDecl`.
2448
*/
25-
TypeDecl getBaseTypeDecl(int i) { result = this.getBaseType(i).(AnyGenericType).getDeclaration() }
49+
deprecated TypeDecl getBaseTypeDecl(int i) {
50+
result = this.getBaseType(i).(AnyGenericType).getDeclaration()
51+
}
2652

2753
/**
2854
* Gets the declaration of any of the base types of this type declaration.
2955
*/
30-
TypeDecl getABaseTypeDecl() { result = this.getBaseTypeDecl(_) }
56+
TypeDecl getABaseTypeDecl() { result = this.getABaseType().(AnyGenericType).getDeclaration() }
3157

3258
/**
3359
* Gets a declaration that has this type as its `index`th base type.
3460
*
35-
* DEPRECATED: The index is not very meaningful here. Use `getADerivedTypeDecl` or `getBaseTypeDecl`.
61+
* DEPRECATED: The index is not very meaningful here. Use `getADerivedTypeDecl` or `getABaseTypeDecl`.
3662
*/
3763
deprecated TypeDecl getDerivedTypeDecl(int i) { result.getBaseTypeDecl(i) = this }
3864

3965
/**
4066
* Gets the declaration of any type derived from this type declaration.
4167
*/
42-
TypeDecl getADerivedTypeDecl() { result.getBaseTypeDecl(_) = this }
68+
TypeDecl getADerivedTypeDecl() { result.getABaseTypeDecl() = this }
4369

4470
/**
4571
* Gets the full name of this `TypeDecl`. For example in:

0 commit comments

Comments
 (0)