|
2 | 2 | private import codeql.swift.generated.Synth |
3 | 3 | private import codeql.swift.generated.Raw |
4 | 4 | import codeql.swift.elements.decl.GenericTypeDecl |
| 5 | +import codeql.swift.elements.type.GenericTypeParamType |
| 6 | +import codeql.swift.elements.decl.ValueDecl |
5 | 7 |
|
6 | 8 | module Generated { |
| 9 | + /** |
| 10 | + * A declaration of an opaque type, that is formally equivalent to a given type but abstracts it |
| 11 | + * away. |
| 12 | + * |
| 13 | + * Such a declaration is implicitly given when a declaration is written with an opaque result type, |
| 14 | + * for example |
| 15 | + * ``` |
| 16 | + * func opaque() -> some SignedInteger { return 1 } |
| 17 | + * ``` |
| 18 | + * See https://docs.swift.org/swift-book/LanguageGuide/OpaqueTypes.html. |
| 19 | + */ |
7 | 20 | class OpaqueTypeDecl extends Synth::TOpaqueTypeDecl, GenericTypeDecl { |
8 | 21 | override string getAPrimaryQlClass() { result = "OpaqueTypeDecl" } |
| 22 | + |
| 23 | + /** |
| 24 | + * Gets the naming declaration of this opaque type declaration. |
| 25 | + * |
| 26 | + * This includes nodes from the "hidden" AST. It can be overridden in subclasses to change the |
| 27 | + * behavior of both the `Immediate` and non-`Immediate` versions. |
| 28 | + */ |
| 29 | + ValueDecl getImmediateNamingDeclaration() { |
| 30 | + result = |
| 31 | + Synth::convertValueDeclFromRaw(Synth::convertOpaqueTypeDeclToRaw(this) |
| 32 | + .(Raw::OpaqueTypeDecl) |
| 33 | + .getNamingDeclaration()) |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * Gets the naming declaration of this opaque type declaration. |
| 38 | + */ |
| 39 | + final ValueDecl getNamingDeclaration() { result = getImmediateNamingDeclaration().resolve() } |
| 40 | + |
| 41 | + /** |
| 42 | + * Gets the `index`th opaque generic parameter of this opaque type declaration (0-based). |
| 43 | + * |
| 44 | + * This includes nodes from the "hidden" AST. It can be overridden in subclasses to change the |
| 45 | + * behavior of both the `Immediate` and non-`Immediate` versions. |
| 46 | + */ |
| 47 | + GenericTypeParamType getImmediateOpaqueGenericParam(int index) { |
| 48 | + result = |
| 49 | + Synth::convertGenericTypeParamTypeFromRaw(Synth::convertOpaqueTypeDeclToRaw(this) |
| 50 | + .(Raw::OpaqueTypeDecl) |
| 51 | + .getOpaqueGenericParam(index)) |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * Gets the `index`th opaque generic parameter of this opaque type declaration (0-based). |
| 56 | + */ |
| 57 | + final GenericTypeParamType getOpaqueGenericParam(int index) { |
| 58 | + result = getImmediateOpaqueGenericParam(index).resolve() |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * Gets any of the opaque generic parameters of this opaque type declaration. |
| 63 | + */ |
| 64 | + final GenericTypeParamType getAnOpaqueGenericParam() { result = getOpaqueGenericParam(_) } |
| 65 | + |
| 66 | + /** |
| 67 | + * Gets the number of opaque generic parameters of this opaque type declaration. |
| 68 | + */ |
| 69 | + final int getNumberOfOpaqueGenericParams() { result = count(getAnOpaqueGenericParam()) } |
9 | 70 | } |
10 | 71 | } |
0 commit comments