Skip to content

Commit 15244e0

Browse files
committed
Swift: Expand NominalType.getFullName to Type.getFullName (so it is a suitble substitute for the old Type.getName behaviour).
1 parent e2740fe commit 15244e0

File tree

4 files changed

+29
-27
lines changed

4 files changed

+29
-27
lines changed

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,4 @@ class NominalType extends Generated::NominalType {
66
override Type getABaseType() { result = this.getDeclaration().(NominalTypeDecl).getABaseType() }
77

88
NominalType getADerivedType() { result.getABaseType() = this }
9-
10-
/**
11-
* Gets the full name of this `NominalType`. For example in:
12-
* ```swift
13-
* struct A {
14-
* struct B {
15-
* // ...
16-
* }
17-
* }
18-
* ```
19-
* The name and full name of `A` is `A`. The name of `B` is `B`, but the
20-
* full name of `B` is `A.B`.
21-
*/
22-
string getFullName() { result = this.getDeclaration().(NominalTypeDecl).getFullName() }
239
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@ class Type extends Generated::Type {
2121
)
2222
}
2323

24+
/**
25+
* Gets the full name of this `Type`. For example in:
26+
* ```swift
27+
* struct A {
28+
* struct B {
29+
* // ...
30+
* }
31+
* }
32+
* ```
33+
* The name and full name of `A` is `A`. The name of `B` is `B`, but the
34+
* full name of `B` is `A.B`.
35+
*/
36+
string getFullName() {
37+
result = super.getName()
38+
}
39+
2440
/**
2541
* Gets this type after any type aliases have been resolved. For example in
2642
* the following code, the underlying type of `MyInt` is `Int`:
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
| nominaltype.swift:54:6:54:6 | a | A | getFullName:A, getName:A, getUnderlyingType:A |
2-
| nominaltype.swift:55:6:55:6 | a_alias | A_alias | getAliasedType:A, getName:A_alias, getUnderlyingType:A |
3-
| nominaltype.swift:56:6:56:6 | a_optional_alias | A_optional_alias | getAliasedType:A?, getName:A_optional_alias, getUnderlyingType:A? |
2+
| nominaltype.swift:55:6:55:6 | a_alias | A_alias | getAliasedType:A, getFullName:A_alias, getName:A_alias, getUnderlyingType:A |
3+
| nominaltype.swift:56:6:56:6 | a_optional_alias | A_optional_alias | getAliasedType:A?, getFullName:A_optional_alias, getName:A_optional_alias, getUnderlyingType:A? |
44
| nominaltype.swift:57:6:57:6 | b1 | B1 | getABaseType:A, getFullName:B1, getName:B1, getUnderlyingType:B1 |
55
| nominaltype.swift:58:6:58:6 | b2 | B2 | getABaseType:A_alias, getFullName:B2, getName:B2, getUnderlyingType:B2 |
6-
| nominaltype.swift:59:6:59:6 | b1_alias | B1_alias | getABaseType:A, getAliasedType:B1, getName:B1_alias, getUnderlyingType:B1 |
7-
| nominaltype.swift:60:6:60:6 | b2_alias | B2_alias | getABaseType:A_alias, getAliasedType:B2, getName:B2_alias, getUnderlyingType:B2 |
8-
| nominaltype.swift:61:6:61:6 | p | P | getName:P, getUnderlyingType:P |
9-
| nominaltype.swift:62:6:62:6 | p_alias | P_alias | getName:P_alias, getUnderlyingType:P_alias |
6+
| nominaltype.swift:59:6:59:6 | b1_alias | B1_alias | getABaseType:A, getAliasedType:B1, getFullName:B1_alias, getName:B1_alias, getUnderlyingType:B1 |
7+
| nominaltype.swift:60:6:60:6 | b2_alias | B2_alias | getABaseType:A_alias, getAliasedType:B2, getFullName:B2_alias, getName:B2_alias, getUnderlyingType:B2 |
8+
| nominaltype.swift:61:6:61:6 | p | P | getFullName:P, getName:P, getUnderlyingType:P |
9+
| nominaltype.swift:62:6:62:6 | p_alias | P_alias | getFullName:P_alias, getName:P_alias, getUnderlyingType:P_alias |
1010
| nominaltype.swift:63:6:63:6 | c1 | C1 | getABaseType:P, getFullName:C1, getName:C1, getUnderlyingType:C1 |
1111
| nominaltype.swift:64:6:64:6 | c2 | C2 | getABaseType:P_alias, getFullName:C2, getName:C2, getUnderlyingType:C2 |
12-
| nominaltype.swift:65:6:65:6 | c1_alias | C1_alias | getABaseType:P, getAliasedType:C1, getName:C1_alias, getUnderlyingType:C1 |
13-
| nominaltype.swift:66:6:66:6 | c2_alias | C2_alias | getABaseType:P_alias, getAliasedType:C2, getName:C2_alias, getUnderlyingType:C2 |
12+
| nominaltype.swift:65:6:65:6 | c1_alias | C1_alias | getABaseType:P, getAliasedType:C1, getFullName:C1_alias, getName:C1_alias, getUnderlyingType:C1 |
13+
| nominaltype.swift:66:6:66:6 | c2_alias | C2_alias | getABaseType:P_alias, getAliasedType:C2, getFullName:C2_alias, getName:C2_alias, getUnderlyingType:C2 |
1414
| nominaltype.swift:67:6:67:6 | o | Outer | getFullName:Outer, getName:Outer, getUnderlyingType:Outer |
1515
| nominaltype.swift:68:6:68:6 | oi | Inner | getFullName:Outer.Inner, getName:Inner, getUnderlyingType:Inner |
16-
| nominaltype.swift:69:6:69:6 | oia | InnerAlias | getABaseType:FixedWidthInteger, getABaseType:SignedInteger, getABaseType:_ExpressibleByBuiltinIntegerLiteral, getAliasedType:Int, getName:InnerAlias, getUnderlyingType:Int |
17-
| nominaltype.swift:70:6:70:6 | aa | Any? | getName:Any?, getUnderlyingType:Any? |
18-
| nominaltype.swift:71:6:71:6 | p1p2 | P1P2 | getName:P1P2, getUnderlyingType:P1P2 |
19-
| nominaltype.swift:72:6:72:6 | boxInt | Box<Int> | getName:Box<Int>, getUnderlyingType:Box<Int> |
16+
| nominaltype.swift:69:6:69:6 | oia | InnerAlias | getABaseType:FixedWidthInteger, getABaseType:SignedInteger, getABaseType:_ExpressibleByBuiltinIntegerLiteral, getAliasedType:Int, getFullName:Outer.Inner.InnerAlias, getName:InnerAlias, getUnderlyingType:Int |
17+
| nominaltype.swift:70:6:70:6 | aa | Any? | getFullName:Any?, getName:Any?, getUnderlyingType:Any? |
18+
| nominaltype.swift:71:6:71:6 | p1p2 | P1P2 | getFullName:P1P2, getName:P1P2, getUnderlyingType:P1P2 |
19+
| nominaltype.swift:72:6:72:6 | boxInt | Box<Int> | getFullName:Box<Int>, getName:Box<Int>, getUnderlyingType:Box<Int> |

swift/ql/test/library-tests/elements/type/nominaltype/nominaltype.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import swift
33
string describe(Type t) {
44
result = "getName:" + t.getName()
55
or
6-
result = "getFullName:" + t.(NominalType).getFullName()
6+
result = "getFullName:" + t.getFullName()
77
or
88
result = "getUnderlyingType:" + t.getUnderlyingType().toString()
99
or

0 commit comments

Comments
 (0)