mirror of
https://github.com/github/codeql.git
synced 2026-04-29 10:45:15 +02:00
Merge pull request #12509 from geoffw0/typealiasimpl
Swift: Extract type aliases
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,6 @@
|
||||
class TypeAliasDecl extends @type_alias_decl {
|
||||
string toString() { result = "TypeAliasDecl" }
|
||||
}
|
||||
|
||||
from TypeAliasDecl id
|
||||
select id
|
||||
@@ -0,0 +1,3 @@
|
||||
description: Revert adding TypeAliasDecl.getAliasedType()
|
||||
compatibility: full
|
||||
type_alias_decls.rel: run type_alias_decls.qlo
|
||||
@@ -206,6 +206,7 @@ std::optional<codeql::AssociatedTypeDecl> DeclTranslator::translateAssociatedTyp
|
||||
std::optional<codeql::TypeAliasDecl> DeclTranslator::translateTypeAliasDecl(
|
||||
const swift::TypeAliasDecl& decl) {
|
||||
if (auto entry = createNamedEntry(decl)) {
|
||||
entry->aliased_type = dispatcher.fetchLabel(decl.getUnderlyingType());
|
||||
fillTypeDecl(decl, *entry);
|
||||
return entry;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
| Builtin.NativeObject | BuiltinNativeObjectType |
|
||||
| Builtin.RawPointer | BuiltinRawPointerType |
|
||||
| Builtin.RawUnsafeContinuation | BuiltinRawUnsafeContinuationType |
|
||||
| Builtin.UnsafeValueBuffer | BuiltinUnsafeValueBufferType |
|
||||
| Builtin.Vec2xFPIEEE32 | BuiltinVectorType |
|
||||
| Builtin.Vec2xFPIEEE64 | BuiltinVectorType |
|
||||
| Builtin.Vec2xInt8 | BuiltinVectorType |
|
||||
|
||||
@@ -381,10 +381,10 @@ ql/lib/codeql/swift/generated/File.qll f88c485883dd9b2b4a366080e098372912e03fb31
|
||||
ql/lib/codeql/swift/generated/Locatable.qll bdc98b9fb7788f44a4bf7e487ee5bd329473409950a8e9f116d61995615ad849 0b36b4fe45e2aa195e4bb70c50ea95f32f141b8e01e5f23466c6427dd9ab88fb
|
||||
ql/lib/codeql/swift/generated/Location.qll 851766e474cdfdfa67da42e0031fc42dd60196ff5edd39d82f08d3e32deb84c1 b29b2c37672f5acff15f1d3c5727d902f193e51122327b31bd27ec5f877bca3b
|
||||
ql/lib/codeql/swift/generated/OtherAvailabilitySpec.qll 0e26a203b26ff0581b7396b0c6d1606feec5cc32477f676585cdec4911af91c5 0e26a203b26ff0581b7396b0c6d1606feec5cc32477f676585cdec4911af91c5
|
||||
ql/lib/codeql/swift/generated/ParentChild.qll 0ac2139b8b2e172858262d80950a0212b21fe46bf6af7259d9058fb7193f8242 6f7464ecd8ca04b6aa261139b36a162e5b0636237d514b8431ef4f97a1c603dc
|
||||
ql/lib/codeql/swift/generated/ParentChild.qll 7d45d4e872e769f37a5b157ba422c48afe482552e44d94ff5f6a5a6449d672e7 6f7464ecd8ca04b6aa261139b36a162e5b0636237d514b8431ef4f97a1c603dc
|
||||
ql/lib/codeql/swift/generated/PlatformVersionAvailabilitySpec.qll f82d9ca416fe8bd59b5531b65b1c74c9f317b3297a6101544a11339a1cffce38 7f5c6d3309e66c134107afe55bae76dfc9a72cb7cdd6d4c3706b6b34cee09fa0
|
||||
ql/lib/codeql/swift/generated/PureSynthConstructors.qll 173c0dd59396a1de26fe870e3bc2766c46de689da2a4d8807cb62023bbce1a98 173c0dd59396a1de26fe870e3bc2766c46de689da2a4d8807cb62023bbce1a98
|
||||
ql/lib/codeql/swift/generated/Raw.qll efe60f045f8a4aecedd7bfe8110c0c10539bcdcb9f17f342cf560c8d065e6aff 261825907250bb4ddeba8ccce0df29b45f13c6fb338eb41a06ea6b43e7aa9788
|
||||
ql/lib/codeql/swift/generated/Raw.qll b1ad09374cf2d5556e0a409a59eea723a7280882ae144f68fd2dae362cb147b7 587433583a7e93c9a8534cb59409fd802e4b6587faf1367df9447d06be191c73
|
||||
ql/lib/codeql/swift/generated/Synth.qll af02e0b49fe7b488592687996cc74d9525d4e3fbc9d324820b310b356f4d2612 5c740a660721173e9e4e45eb701d373ca19ff14d61cdaea309b65871e0deea90
|
||||
ql/lib/codeql/swift/generated/SynthConstructors.qll a1b3ca33017f82124286ccad317a05484fee144fb9c3cdd2e500ce38e5efcec4 a1b3ca33017f82124286ccad317a05484fee144fb9c3cdd2e500ce38e5efcec4
|
||||
ql/lib/codeql/swift/generated/UnknownFile.qll 0fcf9beb8de79440bcdfff4bb6ab3dd139bd273e6c32754e05e6a632651e85f6 0fcf9beb8de79440bcdfff4bb6ab3dd139bd273e6c32754e05e6a632651e85f6
|
||||
@@ -428,7 +428,7 @@ ql/lib/codeql/swift/generated/decl/ProtocolDecl.qll 4b03e3c2a7af66e66e8abc40bd2e
|
||||
ql/lib/codeql/swift/generated/decl/StructDecl.qll 9343b001dfeec83a6b41e88dc1ec75744d39c397e8e48441aa4d01493f10026a 9343b001dfeec83a6b41e88dc1ec75744d39c397e8e48441aa4d01493f10026a
|
||||
ql/lib/codeql/swift/generated/decl/SubscriptDecl.qll 31cb1f90d4c60060f64c432850821969953f1a46e36ce772456c67dfff375ff5 1d0098518c56aed96039b0b660b2cce5ea0db7ac4c9a550af07d758e282d4f61
|
||||
ql/lib/codeql/swift/generated/decl/TopLevelCodeDecl.qll aececf62fda517bd90b1c56bb112bb3ee2eecac3bb2358a889dc8c4de898346e d8c69935ac88f0343a03f17ea155653b97e9b9feff40586cfa8452ac5232700d
|
||||
ql/lib/codeql/swift/generated/decl/TypeAliasDecl.qll 15cb5bdbe9d722c403874f744bfb3da85f532e33638a64a593acbbdee2f6095e 15cb5bdbe9d722c403874f744bfb3da85f532e33638a64a593acbbdee2f6095e
|
||||
ql/lib/codeql/swift/generated/decl/TypeAliasDecl.qll 640912badc9d2278b6d14a746d85ed71b17c52cd1f2006aef46d5a4aeaa544f2 a6cbe000ea9d5d1ccd37eb50c23072e19ee0234d53dcb943fef20e3f553fcf4e
|
||||
ql/lib/codeql/swift/generated/decl/TypeDecl.qll 74bb5f0fe2648d95c84fdce804740f2bba5c7671e15cbea671d8509456bf5c2b 32bc7154c8585c25f27a3587bb4ba039c8d69f09d945725e45d730de44f7a5ae
|
||||
ql/lib/codeql/swift/generated/decl/ValueDecl.qll 7b4e4c9334be676f242857c77099306d8a0a4357b253f8bc68f71328cedf1f58 f18938c47f670f2e0c27ffd7e31e55f291f88fb50d8e576fcea116d5f9e5c66d
|
||||
ql/lib/codeql/swift/generated/decl/VarDecl.qll bdea76fe6c8f721bae52bbc26a2fc1cbd665a19a6920b36097822839158d9d3b 9c91d8159fd7a53cba479d8c8f31f49ad2b1e2617b8cd9e7d1a2cb4796dfa2da
|
||||
|
||||
@@ -10,7 +10,7 @@ class TypeAliasType extends Generated::TypeAliasType {
|
||||
* typealias MyInt = Int
|
||||
* ```
|
||||
*/
|
||||
Type getAliasedType() { none() } // TODO: not yet implemented.
|
||||
Type getAliasedType() { result = this.getDecl().getAliasedType() }
|
||||
|
||||
override Type getUnderlyingType() { result = this } // TODO: not yet implemented.
|
||||
override Type getUnderlyingType() { result = this.getAliasedType().getUnderlyingType() }
|
||||
}
|
||||
|
||||
@@ -660,6 +660,16 @@ module Raw {
|
||||
|
||||
class TypeAliasDecl extends @type_alias_decl, GenericTypeDecl {
|
||||
override string toString() { result = "TypeAliasDecl" }
|
||||
|
||||
/**
|
||||
* Gets the aliased type on the right-hand side of this type alias declaration.
|
||||
*
|
||||
* For example the aliased type of `MyInt` in the following code is `Int`:
|
||||
* ```
|
||||
* typealias MyInt = Int
|
||||
* ```
|
||||
*/
|
||||
Type getAliasedType() { type_alias_decls(this, result) }
|
||||
}
|
||||
|
||||
class ClassDecl extends @class_decl, NominalTypeDecl {
|
||||
|
||||
@@ -2,9 +2,39 @@
|
||||
private import codeql.swift.generated.Synth
|
||||
private import codeql.swift.generated.Raw
|
||||
import codeql.swift.elements.decl.GenericTypeDecl
|
||||
import codeql.swift.elements.type.Type
|
||||
|
||||
module Generated {
|
||||
/**
|
||||
* A declaration of a type alias to another type. For example:
|
||||
* ```
|
||||
* typealias MyInt = Int
|
||||
* ```
|
||||
*/
|
||||
class TypeAliasDecl extends Synth::TTypeAliasDecl, GenericTypeDecl {
|
||||
override string getAPrimaryQlClass() { result = "TypeAliasDecl" }
|
||||
|
||||
/**
|
||||
* Gets the aliased type on the right-hand side of this type alias declaration.
|
||||
*
|
||||
* This includes nodes from the "hidden" AST. It can be overridden in subclasses to change the
|
||||
* behavior of both the `Immediate` and non-`Immediate` versions.
|
||||
*/
|
||||
Type getImmediateAliasedType() {
|
||||
result =
|
||||
Synth::convertTypeFromRaw(Synth::convertTypeAliasDeclToRaw(this)
|
||||
.(Raw::TypeAliasDecl)
|
||||
.getAliasedType())
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the aliased type on the right-hand side of this type alias declaration.
|
||||
*
|
||||
* For example the aliased type of `MyInt` in the following code is `Int`:
|
||||
* ```
|
||||
* typealias MyInt = Int
|
||||
* ```
|
||||
*/
|
||||
final Type getAliasedType() { result = getImmediateAliasedType().resolve() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -670,7 +670,8 @@ param_decl_property_wrapper_local_wrapped_vars( //dir=decl
|
||||
);
|
||||
|
||||
type_alias_decls( //dir=decl
|
||||
unique int id: @type_alias_decl
|
||||
unique int id: @type_alias_decl,
|
||||
int aliased_type: @type_or_none ref
|
||||
);
|
||||
|
||||
class_decls( //dir=decl
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,14 @@
|
||||
class TypeAliasDecl extends @type_alias_decl {
|
||||
string toString() { result = "TypeAliasDecl" }
|
||||
}
|
||||
|
||||
class Type extends @type_or_none {
|
||||
string toString() { result = "Type" }
|
||||
}
|
||||
|
||||
// use the canonical type as an approximation of the aliased type
|
||||
from TypeAliasDecl td, Type t, Type canonical
|
||||
where
|
||||
type_alias_types(t, td) and // td is the declaration of t
|
||||
types(t, _, canonical) // canonical is the canonical type of t
|
||||
select td, canonical
|
||||
@@ -0,0 +1,3 @@
|
||||
description: Add TypeAliasDecl.getAliasedType()
|
||||
compatibility: backwards
|
||||
type_alias_decls.rel: run type_alias_decls.qlo
|
||||
@@ -272,5 +272,5 @@
|
||||
| declarations.swift:182:7:182:7 | B.init() | |
|
||||
| declarations.swift:182:7:182:7 | self | |
|
||||
| declarations.swift:182:7:182:7 | self | |
|
||||
| declarations.swift:183:1:183:15 | A | |
|
||||
| declarations.swift:184:1:184:18 | C | |
|
||||
| declarations.swift:183:1:183:15 | A | getAliasedType:B |
|
||||
| declarations.swift:184:1:184:18 | C | getAliasedType:Int? |
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import swift
|
||||
|
||||
string describe(Decl decl) {
|
||||
//result = "getAliasedType:" + decl.(TypeAliasDecl).getAliasedType().toString() TODO: not yet implemented
|
||||
none()
|
||||
result = "getAliasedType:" + decl.(TypeAliasDecl).getAliasedType().toString()
|
||||
}
|
||||
|
||||
from Decl decl
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
| nominaltype.swift:35:6:35:6 | a | A | A | |
|
||||
| nominaltype.swift:36:6:36:6 | a_alias | A_alias | A_alias | |
|
||||
| nominaltype.swift:37:6:37:6 | a_optional_alias | A_optional_alias | A_optional_alias | |
|
||||
| nominaltype.swift:36:6:36:6 | a_alias | A_alias | A | getAliasedType:A |
|
||||
| nominaltype.swift:37:6:37:6 | a_optional_alias | A_optional_alias | A? | getAliasedType:A? |
|
||||
| nominaltype.swift:38:6:38:6 | b1 | B1 | B1 | getABaseType:A |
|
||||
| nominaltype.swift:39:6:39:6 | b2 | B2 | B2 | getABaseType:A_alias |
|
||||
| nominaltype.swift:40:6:40:6 | b1_alias | B1_alias | B1_alias | |
|
||||
| nominaltype.swift:41:6:41:6 | b2_alias | B2_alias | B2_alias | |
|
||||
| nominaltype.swift:40:6:40:6 | b1_alias | B1_alias | B1 | getAliasedType:B1 |
|
||||
| nominaltype.swift:41:6:41:6 | b2_alias | B2_alias | B2 | getAliasedType:B2 |
|
||||
| nominaltype.swift:42:6:42:6 | p | P | P | |
|
||||
| nominaltype.swift:43:6:43:6 | p_alias | P_alias | P_alias | |
|
||||
| nominaltype.swift:44:6:44:6 | c1 | C1 | C1 | getABaseType:P |
|
||||
| nominaltype.swift:45:6:45:6 | c2 | C2 | C2 | getABaseType:P_alias |
|
||||
| nominaltype.swift:46:6:46:6 | c1_alias | C1_alias | C1_alias | |
|
||||
| nominaltype.swift:47:6:47:6 | c2_alias | C2_alias | C2_alias | |
|
||||
| nominaltype.swift:46:6:46:6 | c1_alias | C1_alias | C1 | getAliasedType:C1 |
|
||||
| nominaltype.swift:47:6:47:6 | c2_alias | C2_alias | C2 | getAliasedType:C2 |
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
| nominaltype.swift:35:6:35:6 | a | A | |
|
||||
| nominaltype.swift:36:6:36:6 | a_alias | A_alias | |
|
||||
| nominaltype.swift:37:6:37:6 | a_optional_alias | A_optional_alias | |
|
||||
| nominaltype.swift:36:6:36:6 | a_alias | A_alias | getAliasedType:A |
|
||||
| nominaltype.swift:37:6:37:6 | a_optional_alias | A_optional_alias | getAliasedType:A? |
|
||||
| nominaltype.swift:38:6:38:6 | b1 | B1 | getABaseType:A |
|
||||
| nominaltype.swift:39:6:39:6 | b2 | B2 | getABaseType:A_alias |
|
||||
| nominaltype.swift:40:6:40:6 | b1_alias | B1_alias | |
|
||||
| nominaltype.swift:41:6:41:6 | b2_alias | B2_alias | |
|
||||
| nominaltype.swift:40:6:40:6 | b1_alias | B1_alias | getAliasedType:B1 |
|
||||
| nominaltype.swift:41:6:41:6 | b2_alias | B2_alias | getAliasedType:B2 |
|
||||
| nominaltype.swift:44:6:44:6 | c1 | C1 | getABaseType:P |
|
||||
| nominaltype.swift:45:6:45:6 | c2 | C2 | getABaseType:P_alias |
|
||||
| nominaltype.swift:46:6:46:6 | c1_alias | C1_alias | |
|
||||
| nominaltype.swift:47:6:47:6 | c2_alias | C2_alias | |
|
||||
| nominaltype.swift:46:6:46:6 | c1_alias | C1_alias | getAliasedType:C1 |
|
||||
| nominaltype.swift:47:6:47:6 | c2_alias | C2_alias | getAliasedType:C2 |
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import swift
|
||||
|
||||
string describe(TypeDecl td) {
|
||||
//result = "getAliasedType:" + td.(TypeAliasDecl).getAliasedType() TODO: not yet implemented.
|
||||
//or
|
||||
result = "getAliasedType:" + td.(TypeAliasDecl).getAliasedType()
|
||||
or
|
||||
result = "getABaseType:" + td.(NominalTypeDecl).getABaseType()
|
||||
}
|
||||
|
||||
|
||||
@@ -324,7 +324,18 @@ class OpaqueTypeDecl(GenericTypeDecl):
|
||||
opaque_generic_params: list["GenericTypeParamType"]
|
||||
|
||||
class TypeAliasDecl(GenericTypeDecl):
|
||||
pass
|
||||
"""
|
||||
A declaration of a type alias to another type. For example:
|
||||
```
|
||||
typealias MyInt = Int
|
||||
```
|
||||
"""
|
||||
aliased_type: Type | doc("aliased type on the right-hand side of this type alias declaration") | desc("""
|
||||
For example the aliased type of `MyInt` in the following code is `Int`:
|
||||
```
|
||||
typealias MyInt = Int
|
||||
```
|
||||
""")
|
||||
|
||||
class ClassDecl(NominalTypeDecl):
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user