mirror of
https://github.com/github/codeql.git
synced 2026-04-26 17:25:19 +02:00
Swift: Add named predicates for known KeyPathComponent kinds.
This commit is contained in:
@@ -7,7 +7,6 @@ ql/lib/codeql/swift/elements/DbLocation.qll 2b07fe465cc6ea0e876892d8312bedca35d2
|
||||
ql/lib/codeql/swift/elements/DbLocationConstructor.qll 88366e22ba40eaaee097f413130117925dda488f1bcbd3989e301e86dd394df3 c61b32994d403a8c4f85c26251e24ffb8c6ea34dbbe935872d868ccbfb6c1ff6
|
||||
ql/lib/codeql/swift/elements/DiagnosticsConstructor.qll 6a3e312f3ed57465747c672cbb6d615eca89f42586519221d2973ac3e2ab052c a010ef546f9ed2a75b812ee47db00110056b3076b1f939efa2addb000c327427
|
||||
ql/lib/codeql/swift/elements/ErrorElement.qll e054242b883bcc7fe1e2ee844268325a0a0b83486d5c7b4e334c73a5f8bd1d9f ab0028bab8a9ed14c6b4bfe0f8a10e4768ea1e21f86b495258021ab9b8e65aeb
|
||||
ql/lib/codeql/swift/elements/KeyPathComponent.qll bf568c6502ce9950a5a5e783abc60de47dd9b55e99e04b69142c587092fb1cad 17ca53568580cee53230d70f825261acfa5b2c433cc35cdd8f5db8837176c8ae
|
||||
ql/lib/codeql/swift/elements/KeyPathComponentConstructor.qll fa5fdff92a996add9aa79c320df011bf40ed50f83166c3c745bdb6c45bd22bb3 7afdff6d42b73c6968c486697daa0bc8dacb11815544c65c32f7fe9be3b05d2f
|
||||
ql/lib/codeql/swift/elements/OtherAvailabilitySpecConstructor.qll fe03628ffbad9369e4b6bf325a58a3013b621090eecd9e01a76710e0d234d66a 0b7ffc7ed88d2b0da9aad86d83272daf124a4597c0fee1184f7d2f3511063afd
|
||||
ql/lib/codeql/swift/elements/PlatformVersionAvailabilitySpecConstructor.qll ce9cc9b15eff28cf0f9ef94f1d7a9dbfbbb2fb64c0053c2b537046784fcd6ee6 8b776cb89ec44704babbce7ac69efb534bf0925ca43f04e7a7dc795435404393
|
||||
@@ -380,14 +379,14 @@ ql/lib/codeql/swift/generated/Diagnostics.qll d2ee2db55e932dcaee95fcc1164a51ffbe
|
||||
ql/lib/codeql/swift/generated/Element.qll 9caf84a1da2509f5b01a22d6597126c573ae63ec3e8c6af6fd6fcc7ead0b4e82 70deb2238509d5ed660369bf763c796065d92efd732469088cdf67f68bacd796
|
||||
ql/lib/codeql/swift/generated/ErrorElement.qll 4b032abe8ffb71376a29c63e470a52943ace2527bf7b433c97a8bf716f9ad102 4f2b1be162a5c275e3264dbc51bf98bce8846d251be8490a0d4b16cbc85f630f
|
||||
ql/lib/codeql/swift/generated/File.qll f88c485883dd9b2b4a366080e098372912e03fb3177e5cae58aa4449c2b03399 0333c49e3a11c48e6146a7f492ee31ac022d80150fc3f8bfafc3c8f94d66ff76
|
||||
ql/lib/codeql/swift/generated/KeyPathComponent.qll 8b6efa9859c817cafc89f06b5ccf9c6e9762940ac45a40a15ffd5eff79b558c9 295a2acb65fadf9216bf8c032f3183dbe74afadb69b413947cd31ebe2f2269dd
|
||||
ql/lib/codeql/swift/generated/KeyPathComponent.qll f8d62b8021936dc152538b52278a320d7e151cd24fcb602dab4d0169b328e0d4 aa0580990a97cf733bb90a2d68368ea10802213b2471425a82d7ea945a6595f4
|
||||
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 3998d73048297cf2df42176b0060c025e57d409d56f3fbfab9c202bd46c07b5e 425b01328baf38bd5e46403e11b25b0e17cd5bc40731dbf64a46e01604611e15
|
||||
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 50c6dbe929161332d75450aa347d95936d61007e278638191162a8d8be01cb26 f09d782d996e3c43c5afd1997fddc35d96ee0615c2327df62101572134f067c4
|
||||
ql/lib/codeql/swift/generated/Raw.qll 16ef0c379f1b3ceb73df393a34b8d2c5c4fb180e337fb3b8f33078fa9d827b7e 4b608cd9fc3f425fc568322ae17036e6407a54d0a6a30ff03fe04942f4ef897f
|
||||
ql/lib/codeql/swift/generated/Synth.qll 1b60c8eab214c8f9a3a1fb39a8785979bc3d86f2615ba0a580c35e17fd496851 052940a87ffb32214b1b3c774bc643aa5d4f31c484d3121b4da384c2839cb10b
|
||||
ql/lib/codeql/swift/generated/SynthConstructors.qll bb0c69cea79a06ec3cc0e176fc6e63cfe125107a45373e41083fc4de056133b8 bb0c69cea79a06ec3cc0e176fc6e63cfe125107a45373e41083fc4de056133b8
|
||||
ql/lib/codeql/swift/generated/UnknownFile.qll 0fcf9beb8de79440bcdfff4bb6ab3dd139bd273e6c32754e05e6a632651e85f6 0fcf9beb8de79440bcdfff4bb6ab3dd139bd273e6c32754e05e6a632651e85f6
|
||||
|
||||
@@ -1,4 +1,38 @@
|
||||
// generated by codegen/codegen.py, remove this comment if you wish to edit this file
|
||||
private import codeql.swift.generated.KeyPathComponent
|
||||
|
||||
class KeyPathComponent extends Generated::KeyPathComponent { }
|
||||
class KeyPathComponent extends Generated::KeyPathComponent {
|
||||
/**
|
||||
* Property access like `.bar` in `\Foo.bar`.
|
||||
*/
|
||||
predicate is_property() { getKind() = 3 }
|
||||
|
||||
/**
|
||||
* Array or dictionary subscript like `[1]` or `["a", "b"]`.
|
||||
*/
|
||||
predicate is_subscript() { getKind() = 4 }
|
||||
|
||||
/**
|
||||
* Optional forcing `!`.
|
||||
*/
|
||||
predicate is_optional_forcing() { getKind() = 5 }
|
||||
|
||||
/**
|
||||
* Optional chaining `?`.
|
||||
*/
|
||||
predicate is_optional_chaining() { getKind() = 6 }
|
||||
|
||||
/**
|
||||
* Implicit optional wrapping component inserted by the compiler when an optional chain ends in a non-optional value.
|
||||
*/
|
||||
predicate is_optional_wrapping() { getKind() = 7 }
|
||||
|
||||
/**
|
||||
* Reference to the entire object; the `self` in `\Foo.self`.
|
||||
*/
|
||||
predicate is_self() { getKind() = 8 }
|
||||
|
||||
/**
|
||||
* Tuple indexing like `.1`.
|
||||
*/
|
||||
predicate is_tuple_indexing() { getKind() = 9 }
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ module Generated {
|
||||
/**
|
||||
* Gets the kind of key path component.
|
||||
*
|
||||
* INTERNAL: Do not use.
|
||||
*
|
||||
* This is 3 for properties, 4 for array and dictionary subscripts, 5 for optional forcing
|
||||
* (`!`), 6 for optional chaining (`?`), 7 for implicit optional wrapping, 8 for `self`,
|
||||
* and 9 for tuple element indexing.
|
||||
|
||||
@@ -140,6 +140,8 @@ module Raw {
|
||||
/**
|
||||
* Gets the kind of key path component.
|
||||
*
|
||||
* INTERNAL: Do not use.
|
||||
*
|
||||
* This is 3 for properties, 4 for array and dictionary subscripts, 5 for optional forcing
|
||||
* (`!`), 6 for optional chaining (`?`), 7 for implicit optional wrapping, 8 for `self`,
|
||||
* and 9 for tuple element indexing.
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
| file://:0:0:0:0 | KeyPathComponent | getKind: | 7 | | | | | optional wrapping | | |
|
||||
| key_path_expr.swift:11:17:11:17 | KeyPathComponent | getKind: | 3 | property | | | | | | |
|
||||
| key_path_expr.swift:12:24:12:26 | KeyPathComponent | getKind: | 4 | | subscript | | | | | |
|
||||
| key_path_expr.swift:13:34:13:38 | KeyPathComponent | getKind: | 4 | | subscript | | | | | |
|
||||
| key_path_expr.swift:14:31:14:31 | KeyPathComponent | getKind: | 5 | | | optional forcing | | | | |
|
||||
| key_path_expr.swift:14:31:14:31 | KeyPathComponent | getKind: | 8 | | | | | | self | |
|
||||
| key_path_expr.swift:15:21:15:21 | KeyPathComponent | getKind: | 3 | property | | | | | | |
|
||||
| key_path_expr.swift:15:24:15:24 | KeyPathComponent | getKind: | 6 | | | | optional chaining | | | |
|
||||
| key_path_expr.swift:15:26:15:26 | KeyPathComponent | getKind: | 3 | property | | | | | | |
|
||||
| key_path_expr.swift:16:25:16:25 | KeyPathComponent | getKind: | 3 | property | | | | | | |
|
||||
| key_path_expr.swift:16:28:16:28 | KeyPathComponent | getKind: | 6 | | | | optional chaining | | | |
|
||||
| key_path_expr.swift:16:30:16:30 | KeyPathComponent | getKind: | 3 | property | | | | | | |
|
||||
| key_path_expr.swift:17:16:17:16 | KeyPathComponent | getKind: | 8 | | | | | | self | |
|
||||
| key_path_expr.swift:18:32:18:32 | KeyPathComponent | getKind: | 9 | | | | | | | tuple indexing |
|
||||
@@ -0,0 +1,18 @@
|
||||
import codeql.swift.elements
|
||||
import TestUtils
|
||||
|
||||
from
|
||||
KeyPathComponent x, string property, string subscript, string opt_forcing, string opt_chaining,
|
||||
string opt_wrapping, string self, string tuple_indexing
|
||||
where
|
||||
toBeTested(x) and
|
||||
not x.isUnknown() and
|
||||
(if x.is_property() then property = "property" else property = "") and
|
||||
(if x.is_subscript() then subscript = "subscript" else subscript = "") and
|
||||
(if x.is_optional_forcing() then opt_forcing = "optional forcing" else opt_forcing = "") and
|
||||
(if x.is_optional_chaining() then opt_chaining = "optional chaining" else opt_chaining = "") and
|
||||
(if x.is_optional_wrapping() then opt_wrapping = "optional wrapping" else opt_wrapping = "") and
|
||||
(if x.is_self() then self = "self" else self = "") and
|
||||
if x.is_tuple_indexing() then tuple_indexing = "tuple indexing" else tuple_indexing = ""
|
||||
select x, "getKind:", x.getKind(), property, subscript, opt_forcing, opt_chaining, opt_wrapping,
|
||||
self, tuple_indexing
|
||||
@@ -0,0 +1,18 @@
|
||||
struct Bar {
|
||||
var value : Int
|
||||
var opt : Int?
|
||||
}
|
||||
|
||||
struct Foo {
|
||||
var value : Int
|
||||
var opt : Bar?
|
||||
}
|
||||
|
||||
let prop = \Foo.value
|
||||
let arrElement = \[Int][0]
|
||||
let dictElement = \[String : Int]["a"]
|
||||
let optForce = \Optional<Int>.self!
|
||||
let optChain = \Foo.opt?.opt
|
||||
let optChainWrap = \Foo.opt?.value
|
||||
let slf = \Int.self
|
||||
let tupleElement = \(Int, Int).0
|
||||
@@ -454,6 +454,8 @@ class KeyPathComponent(AstNode):
|
||||
A component of a `KeyPathExpr`.
|
||||
"""
|
||||
kind: int | doc("kind of key path component") | desc("""
|
||||
INTERNAL: Do not use.
|
||||
|
||||
This is 3 for properties, 4 for array and dictionary subscripts, 5 for optional forcing
|
||||
(`!`), 6 for optional chaining (`?`), 7 for implicit optional wrapping, 8 for `self`,
|
||||
and 9 for tuple element indexing.
|
||||
|
||||
Reference in New Issue
Block a user