mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Swift: Handle method and initializer key path components in QL
Note that it does not seem to be possible to write test that exercise this code. Passing `-enable-experimental-feature KeyPathWithMethodMembers` to the extractor results in: ``` error: experimental feature 'KeyPathWithMethodMembers' cannot be enabled in production compiler ```
This commit is contained in:
4
swift/ql/.generated.list
generated
4
swift/ql/.generated.list
generated
@@ -724,13 +724,13 @@ lib/codeql/swift/generated/Diagnostics.qll 03ea201db80d33b18f7f6c71267044c695c25
|
||||
lib/codeql/swift/generated/Element.qll bf8f688e05f44f18384067c3cab7f05796764e2b4cce7ff24da419c3dae26194 820390ffbb1012f73267668626f7d0ccd368500331c91bbc276fcb1c25037e41
|
||||
lib/codeql/swift/generated/ErrorElement.qll b39bd7c8b4e2011f4a6889e073ebf5b628db32f36f50b067250ae730d9f26561 fd859ec969ba434049e7ba4e78271cc8cebc8b058d2e96e4d47a22064cbb5a21
|
||||
lib/codeql/swift/generated/File.qll 476ac95566ef0080e0ad8c3da144b1be1d945d2f33a24f0864d85ff7c56a09b1 3134018bb50166cbf2690f64bba551cace350e4a7e6e25bcded18f997ad1835b
|
||||
lib/codeql/swift/generated/KeyPathComponent.qll 99d1699394bb7f9ff904e2d44149f20d3e08e35df171a6141f111c9ac9138b62 d8f62f60cc2c1e73146af79e5567c04cd273b73bfb5202bda964ec15032cb040
|
||||
lib/codeql/swift/generated/KeyPathComponent.qll e11dcf952045b5e6062e24c23515cff9eae0b61e5ddf16d29f2c58e2a79a6aa6 3371ae8f26dd5168ac1593bc92a4acd5105905a10a2d696d9ff5478370e6b055
|
||||
lib/codeql/swift/generated/Locatable.qll 1d37fa20de71c0b9986bfd7a7c0cb82ab7bf3fda2d2008700f955ad82ce109a7 e97d4d4fb8a4800e0008cc00f60c8ed9b1ebd5f1140fd85e68b034616178d721
|
||||
lib/codeql/swift/generated/Location.qll 5e20316c3e480ddfe632b7e88e016c19f10a67df1f6ae9c8f128755a6907d6f5 5a0af2d070bcb2ed53d6d0282bf9c60dc64c2dce89c21fdd485e9c7893c1c8fa
|
||||
lib/codeql/swift/generated/MacroRole.qll facf907e75490d69cd401c491215e4719324d751f40ea46c86ccf24cf3663c1f 969d8d4b44e3f1a9c193a152a4d83a303e56d2dbb871fc920c47a33f699cf018
|
||||
lib/codeql/swift/generated/ParentChild.qll 88a8941821b1f511925eb8955ff25065a6004c61aa866854ee941d7556b1eb6d 6e32b4902cea8a78a9b2775826d64300987932c406212d841deeab7c48a5ef8b
|
||||
lib/codeql/swift/generated/PureSynthConstructors.qll bc31a6c4d142fa3fbdcae69d5ba6f1cec00eb9ad92b46c8d7b91ebfa7ef6c1f4 bc31a6c4d142fa3fbdcae69d5ba6f1cec00eb9ad92b46c8d7b91ebfa7ef6c1f4
|
||||
lib/codeql/swift/generated/Raw.qll f64459f6113f9b568cb876b4a896d29e519b5ac2c89322614f52e981ab4aedc1 66440d5f6927641b4ffb38d2930af0dd6d5428fcdc4bd1a67868b2304a6b0ea8
|
||||
lib/codeql/swift/generated/Raw.qll 9cbbea49cef2a47eb3414a14f42571c7bef60fa816a4cec0e3f34206b7ceafa1 86cc2bf1675dfccacf6041ad343b0642650dd38f2956a9e7bd2bb3d0f2cd90d1
|
||||
lib/codeql/swift/generated/Synth.qll a472fca73084eedab9ca8bb2fb82e7573d525444bb8d3729a3d18e06647fd96d b19984583774e30dae481d3d5cc95ebf2843c04dd952eb16cbf8a702ae52bbd8
|
||||
lib/codeql/swift/generated/SynthConstructors.qll f3687a56d2fd9bc38d95d9ca335f558a91c865bd0bd1c7c73affedefd7514183 f3687a56d2fd9bc38d95d9ca335f558a91c865bd0bd1c7c73affedefd7514183
|
||||
lib/codeql/swift/generated/UnknownFile.qll 247ddf2ebb49ce5ed4bf7bf91a969ddff37de6c78d43d8affccaf7eb586e06f2 452b29f0465ef45e978ef8b647b75e5a2a1e53f2a568fc003bc8f52f73b3fa4d
|
||||
|
||||
@@ -7,6 +7,11 @@ module Impl {
|
||||
* A component of a `KeyPathExpr`.
|
||||
*/
|
||||
class KeyPathComponent extends Generated::KeyPathComponent {
|
||||
/**
|
||||
* Method or initializer application like `.bar` in `\Foo.bar` with `bar` a method.
|
||||
*/
|
||||
predicate isApply() { this.getKind() = 4 }
|
||||
|
||||
/**
|
||||
* Property access like `.bar` in `\Foo.bar`.
|
||||
*/
|
||||
|
||||
@@ -29,15 +29,13 @@ module Generated {
|
||||
*
|
||||
* INTERNAL: Do not use.
|
||||
*
|
||||
* TODO: Swift 6.2 update with UnresolvedApply and Apply
|
||||
* This is 4 for method or initializer application, 5 for members, 6 for array and dictionary
|
||||
* subscripts, 7 for optional forcing (`!`), 8 for optional chaining (`?`), 9 for implicit
|
||||
* optional wrapping, 10 for `self`, and 11 for tuple element indexing.
|
||||
*
|
||||
* This is 5 for properties, 6 for array and dictionary subscripts, 7 for optional forcing
|
||||
* (`!`), 8 for optional chaining (`?`), 9 for implicit optional wrapping, 10 for `self`,
|
||||
* and 11 for tuple element indexing.
|
||||
*
|
||||
* The following values should not appear: 0 for invalid components, 2 for unresolved
|
||||
* properties, 3 for unresolved subscripts, 12 for #keyPath dictionary keys, and 13 for
|
||||
* implicit IDE code completion data.
|
||||
* The following values should not appear: 0 for invalid components, 1 for unresolved
|
||||
* method or initializer applications, 2 for unresolved members, 3 for unresolved subscripts,
|
||||
* 12 for #keyPath dictionary keys, and 13 for implicit IDE code completion data.
|
||||
*/
|
||||
int getKind() {
|
||||
result = Synth::convertKeyPathComponentToRaw(this).(Raw::KeyPathComponent).getKind()
|
||||
|
||||
14
swift/ql/lib/codeql/swift/generated/Raw.qll
generated
14
swift/ql/lib/codeql/swift/generated/Raw.qll
generated
@@ -226,15 +226,13 @@ module Raw {
|
||||
*
|
||||
* INTERNAL: Do not use.
|
||||
*
|
||||
* TODO: Swift 6.2 update with UnresolvedApply and Apply
|
||||
* This is 4 for method or initializer application, 5 for members, 6 for array and dictionary
|
||||
* subscripts, 7 for optional forcing (`!`), 8 for optional chaining (`?`), 9 for implicit
|
||||
* optional wrapping, 10 for `self`, and 11 for tuple element indexing.
|
||||
*
|
||||
* This is 5 for properties, 6 for array and dictionary subscripts, 7 for optional forcing
|
||||
* (`!`), 8 for optional chaining (`?`), 9 for implicit optional wrapping, 10 for `self`,
|
||||
* and 11 for tuple element indexing.
|
||||
*
|
||||
* The following values should not appear: 0 for invalid components, 2 for unresolved
|
||||
* properties, 3 for unresolved subscripts, 12 for #keyPath dictionary keys, and 13 for
|
||||
* implicit IDE code completion data.
|
||||
* The following values should not appear: 0 for invalid components, 1 for unresolved
|
||||
* method or initializer applications, 2 for unresolved members, 3 for unresolved subscripts,
|
||||
* 12 for #keyPath dictionary keys, and 13 for implicit IDE code completion data.
|
||||
*/
|
||||
int getKind() { key_path_components(this, result, _) }
|
||||
|
||||
|
||||
@@ -2,11 +2,12 @@ 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
|
||||
KeyPathComponent x, string apply, 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.isApply() then apply = "apply" else apply = "") and
|
||||
(if x.isProperty() then property = "property" else property = "") and
|
||||
(if x.isSubscript() then subscript = "subscript" else subscript = "") and
|
||||
(if x.isOptionalForcing() then opt_forcing = "optional forcing" else opt_forcing = "") and
|
||||
@@ -14,5 +15,5 @@ where
|
||||
(if x.isOptionalWrapping() then opt_wrapping = "optional wrapping" else opt_wrapping = "") and
|
||||
(if x.isSelf() then self = "self" else self = "") and
|
||||
if x.isTupleIndexing() then tuple_indexing = "tuple indexing" else tuple_indexing = ""
|
||||
select x, "getKind:", x.getKind(), property, subscript, opt_forcing, opt_chaining, opt_wrapping,
|
||||
self, tuple_indexing
|
||||
select x, "getKind:", x.getKind(), apply, property, subscript, opt_forcing, opt_chaining,
|
||||
opt_wrapping, self, tuple_indexing
|
||||
|
||||
@@ -490,15 +490,13 @@ class KeyPathComponent(AstNode):
|
||||
kind: int | doc("kind of key path component") | desc("""
|
||||
INTERNAL: Do not use.
|
||||
|
||||
TODO: Swift 6.2 update with UnresolvedApply and Apply
|
||||
This is 4 for method or initializer application, 5 for members, 6 for array and dictionary
|
||||
subscripts, 7 for optional forcing (`!`), 8 for optional chaining (`?`), 9 for implicit
|
||||
optional wrapping, 10 for `self`, and 11 for tuple element indexing.
|
||||
|
||||
This is 5 for properties, 6 for array and dictionary subscripts, 7 for optional forcing
|
||||
(`!`), 8 for optional chaining (`?`), 9 for implicit optional wrapping, 10 for `self`,
|
||||
and 11 for tuple element indexing.
|
||||
|
||||
The following values should not appear: 0 for invalid components, 2 for unresolved
|
||||
properties, 3 for unresolved subscripts, 12 for #keyPath dictionary keys, and 13 for
|
||||
implicit IDE code completion data.
|
||||
The following values should not appear: 0 for invalid components, 1 for unresolved
|
||||
method or initializer applications, 2 for unresolved members, 3 for unresolved subscripts,
|
||||
12 for #keyPath dictionary keys, and 13 for implicit IDE code completion data.
|
||||
""")
|
||||
subscript_arguments : list[Argument] | child | doc(
|
||||
"arguments to an array or dictionary subscript expression")
|
||||
|
||||
Reference in New Issue
Block a user