Skip to content

Commit 64443df

Browse files
committed
Swift: Add named predicates for known KeyPathComponent kinds.
1 parent b900185 commit 64443df

File tree

8 files changed

+94
-5
lines changed

8 files changed

+94
-5
lines changed

swift/ql/.generated.list

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ ql/lib/codeql/swift/elements/DbLocation.qll 2b07fe465cc6ea0e876892d8312bedca35d2
77
ql/lib/codeql/swift/elements/DbLocationConstructor.qll 88366e22ba40eaaee097f413130117925dda488f1bcbd3989e301e86dd394df3 c61b32994d403a8c4f85c26251e24ffb8c6ea34dbbe935872d868ccbfb6c1ff6
88
ql/lib/codeql/swift/elements/DiagnosticsConstructor.qll 6a3e312f3ed57465747c672cbb6d615eca89f42586519221d2973ac3e2ab052c a010ef546f9ed2a75b812ee47db00110056b3076b1f939efa2addb000c327427
99
ql/lib/codeql/swift/elements/ErrorElement.qll e054242b883bcc7fe1e2ee844268325a0a0b83486d5c7b4e334c73a5f8bd1d9f ab0028bab8a9ed14c6b4bfe0f8a10e4768ea1e21f86b495258021ab9b8e65aeb
10-
ql/lib/codeql/swift/elements/KeyPathComponent.qll bf568c6502ce9950a5a5e783abc60de47dd9b55e99e04b69142c587092fb1cad 17ca53568580cee53230d70f825261acfa5b2c433cc35cdd8f5db8837176c8ae
1110
ql/lib/codeql/swift/elements/KeyPathComponentConstructor.qll fa5fdff92a996add9aa79c320df011bf40ed50f83166c3c745bdb6c45bd22bb3 7afdff6d42b73c6968c486697daa0bc8dacb11815544c65c32f7fe9be3b05d2f
1211
ql/lib/codeql/swift/elements/OtherAvailabilitySpecConstructor.qll fe03628ffbad9369e4b6bf325a58a3013b621090eecd9e01a76710e0d234d66a 0b7ffc7ed88d2b0da9aad86d83272daf124a4597c0fee1184f7d2f3511063afd
1312
ql/lib/codeql/swift/elements/PlatformVersionAvailabilitySpecConstructor.qll ce9cc9b15eff28cf0f9ef94f1d7a9dbfbbb2fb64c0053c2b537046784fcd6ee6 8b776cb89ec44704babbce7ac69efb534bf0925ca43f04e7a7dc795435404393
@@ -380,14 +379,14 @@ ql/lib/codeql/swift/generated/Diagnostics.qll d2ee2db55e932dcaee95fcc1164a51ffbe
380379
ql/lib/codeql/swift/generated/Element.qll 9caf84a1da2509f5b01a22d6597126c573ae63ec3e8c6af6fd6fcc7ead0b4e82 70deb2238509d5ed660369bf763c796065d92efd732469088cdf67f68bacd796
381380
ql/lib/codeql/swift/generated/ErrorElement.qll 4b032abe8ffb71376a29c63e470a52943ace2527bf7b433c97a8bf716f9ad102 4f2b1be162a5c275e3264dbc51bf98bce8846d251be8490a0d4b16cbc85f630f
382381
ql/lib/codeql/swift/generated/File.qll f88c485883dd9b2b4a366080e098372912e03fb3177e5cae58aa4449c2b03399 0333c49e3a11c48e6146a7f492ee31ac022d80150fc3f8bfafc3c8f94d66ff76
383-
ql/lib/codeql/swift/generated/KeyPathComponent.qll 8b6efa9859c817cafc89f06b5ccf9c6e9762940ac45a40a15ffd5eff79b558c9 295a2acb65fadf9216bf8c032f3183dbe74afadb69b413947cd31ebe2f2269dd
382+
ql/lib/codeql/swift/generated/KeyPathComponent.qll f8d62b8021936dc152538b52278a320d7e151cd24fcb602dab4d0169b328e0d4 aa0580990a97cf733bb90a2d68368ea10802213b2471425a82d7ea945a6595f4
384383
ql/lib/codeql/swift/generated/Locatable.qll bdc98b9fb7788f44a4bf7e487ee5bd329473409950a8e9f116d61995615ad849 0b36b4fe45e2aa195e4bb70c50ea95f32f141b8e01e5f23466c6427dd9ab88fb
385384
ql/lib/codeql/swift/generated/Location.qll 851766e474cdfdfa67da42e0031fc42dd60196ff5edd39d82f08d3e32deb84c1 b29b2c37672f5acff15f1d3c5727d902f193e51122327b31bd27ec5f877bca3b
386385
ql/lib/codeql/swift/generated/OtherAvailabilitySpec.qll 0e26a203b26ff0581b7396b0c6d1606feec5cc32477f676585cdec4911af91c5 0e26a203b26ff0581b7396b0c6d1606feec5cc32477f676585cdec4911af91c5
387386
ql/lib/codeql/swift/generated/ParentChild.qll 3998d73048297cf2df42176b0060c025e57d409d56f3fbfab9c202bd46c07b5e 425b01328baf38bd5e46403e11b25b0e17cd5bc40731dbf64a46e01604611e15
388387
ql/lib/codeql/swift/generated/PlatformVersionAvailabilitySpec.qll f82d9ca416fe8bd59b5531b65b1c74c9f317b3297a6101544a11339a1cffce38 7f5c6d3309e66c134107afe55bae76dfc9a72cb7cdd6d4c3706b6b34cee09fa0
389388
ql/lib/codeql/swift/generated/PureSynthConstructors.qll 173c0dd59396a1de26fe870e3bc2766c46de689da2a4d8807cb62023bbce1a98 173c0dd59396a1de26fe870e3bc2766c46de689da2a4d8807cb62023bbce1a98
390-
ql/lib/codeql/swift/generated/Raw.qll 50c6dbe929161332d75450aa347d95936d61007e278638191162a8d8be01cb26 f09d782d996e3c43c5afd1997fddc35d96ee0615c2327df62101572134f067c4
389+
ql/lib/codeql/swift/generated/Raw.qll 16ef0c379f1b3ceb73df393a34b8d2c5c4fb180e337fb3b8f33078fa9d827b7e 4b608cd9fc3f425fc568322ae17036e6407a54d0a6a30ff03fe04942f4ef897f
391390
ql/lib/codeql/swift/generated/Synth.qll 1b60c8eab214c8f9a3a1fb39a8785979bc3d86f2615ba0a580c35e17fd496851 052940a87ffb32214b1b3c774bc643aa5d4f31c484d3121b4da384c2839cb10b
392391
ql/lib/codeql/swift/generated/SynthConstructors.qll bb0c69cea79a06ec3cc0e176fc6e63cfe125107a45373e41083fc4de056133b8 bb0c69cea79a06ec3cc0e176fc6e63cfe125107a45373e41083fc4de056133b8
393392
ql/lib/codeql/swift/generated/UnknownFile.qll 0fcf9beb8de79440bcdfff4bb6ab3dd139bd273e6c32754e05e6a632651e85f6 0fcf9beb8de79440bcdfff4bb6ab3dd139bd273e6c32754e05e6a632651e85f6
Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,38 @@
1-
// generated by codegen/codegen.py, remove this comment if you wish to edit this file
21
private import codeql.swift.generated.KeyPathComponent
32

4-
class KeyPathComponent extends Generated::KeyPathComponent { }
3+
class KeyPathComponent extends Generated::KeyPathComponent {
4+
/**
5+
* Property access like `.bar` in `\Foo.bar`.
6+
*/
7+
predicate is_property() { getKind() = 3 }
8+
9+
/**
10+
* Array or dictionary subscript like `[1]` or `["a", "b"]`.
11+
*/
12+
predicate is_subscript() { getKind() = 4 }
13+
14+
/**
15+
* Optional forcing `!`.
16+
*/
17+
predicate is_optional_forcing() { getKind() = 5 }
18+
19+
/**
20+
* Optional chaining `?`.
21+
*/
22+
predicate is_optional_chaining() { getKind() = 6 }
23+
24+
/**
25+
* Implicit optional wrapping component inserted by the compiler when an optional chain ends in a non-optional value.
26+
*/
27+
predicate is_optional_wrapping() { getKind() = 7 }
28+
29+
/**
30+
* Reference to the entire object; the `self` in `\Foo.self`.
31+
*/
32+
predicate is_self() { getKind() = 8 }
33+
34+
/**
35+
* Tuple indexing like `.1`.
36+
*/
37+
predicate is_tuple_indexing() { getKind() = 9 }
38+
}

swift/ql/lib/codeql/swift/generated/KeyPathComponent.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ module Generated {
1616
/**
1717
* Gets the kind of key path component.
1818
*
19+
* INTERNAL: Do not use.
20+
*
1921
* This is 3 for properties, 4 for array and dictionary subscripts, 5 for optional forcing
2022
* (`!`), 6 for optional chaining (`?`), 7 for implicit optional wrapping, 8 for `self`,
2123
* and 9 for tuple element indexing.

swift/ql/lib/codeql/swift/generated/Raw.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ module Raw {
140140
/**
141141
* Gets the kind of key path component.
142142
*
143+
* INTERNAL: Do not use.
144+
*
143145
* This is 3 for properties, 4 for array and dictionary subscripts, 5 for optional forcing
144146
* (`!`), 6 for optional chaining (`?`), 7 for implicit optional wrapping, 8 for `self`,
145147
* and 9 for tuple element indexing.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
| file://:0:0:0:0 | KeyPathComponent | getKind: | 7 | | | | | optional wrapping | | |
2+
| key_path_expr.swift:11:17:11:17 | KeyPathComponent | getKind: | 3 | property | | | | | | |
3+
| key_path_expr.swift:12:24:12:26 | KeyPathComponent | getKind: | 4 | | subscript | | | | | |
4+
| key_path_expr.swift:13:34:13:38 | KeyPathComponent | getKind: | 4 | | subscript | | | | | |
5+
| key_path_expr.swift:14:31:14:31 | KeyPathComponent | getKind: | 5 | | | optional forcing | | | | |
6+
| key_path_expr.swift:14:31:14:31 | KeyPathComponent | getKind: | 8 | | | | | | self | |
7+
| key_path_expr.swift:15:21:15:21 | KeyPathComponent | getKind: | 3 | property | | | | | | |
8+
| key_path_expr.swift:15:24:15:24 | KeyPathComponent | getKind: | 6 | | | | optional chaining | | | |
9+
| key_path_expr.swift:15:26:15:26 | KeyPathComponent | getKind: | 3 | property | | | | | | |
10+
| key_path_expr.swift:16:25:16:25 | KeyPathComponent | getKind: | 3 | property | | | | | | |
11+
| key_path_expr.swift:16:28:16:28 | KeyPathComponent | getKind: | 6 | | | | optional chaining | | | |
12+
| key_path_expr.swift:16:30:16:30 | KeyPathComponent | getKind: | 3 | property | | | | | | |
13+
| key_path_expr.swift:17:16:17:16 | KeyPathComponent | getKind: | 8 | | | | | | self | |
14+
| key_path_expr.swift:18:32:18:32 | KeyPathComponent | getKind: | 9 | | | | | | | tuple indexing |
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import codeql.swift.elements
2+
import TestUtils
3+
4+
from
5+
KeyPathComponent x, string property, string subscript, string opt_forcing, string opt_chaining,
6+
string opt_wrapping, string self, string tuple_indexing
7+
where
8+
toBeTested(x) and
9+
not x.isUnknown() and
10+
(if x.is_property() then property = "property" else property = "") and
11+
(if x.is_subscript() then subscript = "subscript" else subscript = "") and
12+
(if x.is_optional_forcing() then opt_forcing = "optional forcing" else opt_forcing = "") and
13+
(if x.is_optional_chaining() then opt_chaining = "optional chaining" else opt_chaining = "") and
14+
(if x.is_optional_wrapping() then opt_wrapping = "optional wrapping" else opt_wrapping = "") and
15+
(if x.is_self() then self = "self" else self = "") and
16+
if x.is_tuple_indexing() then tuple_indexing = "tuple indexing" else tuple_indexing = ""
17+
select x, "getKind:", x.getKind(), property, subscript, opt_forcing, opt_chaining, opt_wrapping,
18+
self, tuple_indexing
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
struct Bar {
2+
var value : Int
3+
var opt : Int?
4+
}
5+
6+
struct Foo {
7+
var value : Int
8+
var opt : Bar?
9+
}
10+
11+
let prop = \Foo.value
12+
let arrElement = \[Int][0]
13+
let dictElement = \[String : Int]["a"]
14+
let optForce = \Optional<Int>.self!
15+
let optChain = \Foo.opt?.opt
16+
let optChainWrap = \Foo.opt?.value
17+
let slf = \Int.self
18+
let tupleElement = \(Int, Int).0

swift/schema.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,8 @@ class KeyPathComponent(AstNode):
454454
A component of a `KeyPathExpr`.
455455
"""
456456
kind: int | doc("kind of key path component") | desc("""
457+
INTERNAL: Do not use.
458+
457459
This is 3 for properties, 4 for array and dictionary subscripts, 5 for optional forcing
458460
(`!`), 6 for optional chaining (`?`), 7 for implicit optional wrapping, 8 for `self`,
459461
and 9 for tuple element indexing.

0 commit comments

Comments
 (0)