diff --git a/swift/ql/.generated.list b/swift/ql/.generated.list index cf1df940b70..f4b04500820 100644 --- a/swift/ql/.generated.list +++ b/swift/ql/.generated.list @@ -394,7 +394,7 @@ lib/codeql/swift/elements.qll bb863ff140bfaa0bf887708f421a16c85816886f4d061bbc5a lib/codeql/swift/generated/AstNode.qll 68877daa9e14b462247ac6b7b724f5e683288e39953a8ebb02a362b7d1df8e4c 54d3512744738e1ee15645f3af116437053cb5209687f4106361a1943b38b666 lib/codeql/swift/generated/AvailabilityInfo.qll e74e218a1ab00416cb8823610ff93642101aa784aa61cbc2b4deef61471a5bac e2c6c19860dc3e6e211041c95d8e6d52c3505ccff7018b80a849735cc98141af lib/codeql/swift/generated/AvailabilitySpec.qll a8afc5071887a67b4e0dec27356ab8cbf3e176b5358cb34c785e3015b2cad5a2 c7f88b0d701612c821359c983b3102f31b23edc211c3dcfe97de5adec61af386 -lib/codeql/swift/generated/Callable.qll 967fcb4f24a31754ef3bfdd1ea1e585ee8dc7fca02c8f6a2db451df22b156e38 d2e2824119e1b01964851a58099e19f787d12402de8ebce278731433325a76e9 +lib/codeql/swift/generated/Callable.qll d1a674575ec2edfeada622a5b34133101927b40714bdd6106f5f8b0708119c16 177e44bab51c105bc34925b06b18564b71a2c112e6fb700e47f1cc62fa03b483 lib/codeql/swift/generated/Comment.qll fea1b1eb97adcb9a1e5eee0a516240de7b0f0ffef55068c91dc13d29acd3a9a1 f2c8cf8ab5cd5daa67aae51bad4cd34a80a81c00220950476b2e91fd0808628d lib/codeql/swift/generated/DbFile.qll fc2f1cd370a6e67d0e0aeeb9ccd585ce6875064101a1385c2e456021728cfd53 fc2f1cd370a6e67d0e0aeeb9ccd585ce6875064101a1385c2e456021728cfd53 lib/codeql/swift/generated/DbLocation.qll 929f015202c9c5a8062c913c38ef069482e4f459606ce4e917d021c643cfc11d 929f015202c9c5a8062c913c38ef069482e4f459606ce4e917d021c643cfc11d @@ -407,11 +407,11 @@ lib/codeql/swift/generated/Locatable.qll 6cb437dd7ff7331429ec6586b0af50b1af15e4f lib/codeql/swift/generated/Location.qll 3f3bad413be87d05a596fe7b8004f415c2caa98cb759021a6aad20b589b7d700 ed30ed646962b3ffb6b47c97c6434fe47a6b1ea8e3f2e0589577bea5cf96c88e lib/codeql/swift/generated/MacroRole.qll aaf5631c49de81e046854955341202d6d3516713cd09bc2e7b870e40c261cc9f 6cd17d40cbf1d8fa4ef01dfb8b3462b7cee902e6058fb76417c2035be12481d1 lib/codeql/swift/generated/OtherAvailabilitySpec.qll 06393a08e8da36106c5ec6efb9f1bd56a5c7b3d3f3d0bcefc6fa07fa96860c31 06393a08e8da36106c5ec6efb9f1bd56a5c7b3d3f3d0bcefc6fa07fa96860c31 -lib/codeql/swift/generated/ParentChild.qll eae164aa8a78e883e707fba6c671ff2cd0ddab1084b0871fc5ae27c44cded4c5 3af88b63e21d58090f9702e6e4716a5b8a5a65897b8c92362b6e3c0fba60ddc2 +lib/codeql/swift/generated/ParentChild.qll 9c93c47197f4d510dc0e6a619e15938dc9b31907a300fde2fc27906448422e08 b153266ec86d64414c0c5c6a8f051209937594d40964715e2145982173ef6854 lib/codeql/swift/generated/PlatformVersionAvailabilitySpec.qll 5355be9da8b778d1d8ae60d25d9c3394477da24f94e8a6ab4484c6a16d07cd7c 075438c1762ec0a7775004b39032dcf85aada038a4269e6f428c34b8282786e9 lib/codeql/swift/generated/PureSynthConstructors.qll 40f5c0c573ce12f16322d9efb12306750f672254cbc36a200c298cb08e504229 40f5c0c573ce12f16322d9efb12306750f672254cbc36a200c298cb08e504229 -lib/codeql/swift/generated/Raw.qll 10633b948918d315b98b6ff6733d4c368e082c5afd78334c0862291f9d883216 66abde4c9a2283773033d90a4633c1203d6563fc238ddbd48fdf1b910f90021a -lib/codeql/swift/generated/Synth.qll 848284b2ae9854c5be74e5ef50a51090e248e5c9c02289a6bc63455e440122da e2607f46a4830e81718ca1636fa65bc29420a18539443d109fafd7f1af1591ce +lib/codeql/swift/generated/Raw.qll 118b43fedd4265b5aa15c33ef01a2f5a5db6e5597f95bef1078a01c3ff8da983 075aec2c8b232f0361ebf63f07ae9b66163f3975e6023583fb0fa2e40b979a33 +lib/codeql/swift/generated/Synth.qll 221f40afbc2bed0f5de1961877fd39dd025574bc72622af0e9f47f278a8324b7 05b8aaa9ac6236b0c08d6afc7a13e58361b90524cff6520a1ac6d422eea4fe40 lib/codeql/swift/generated/SynthConstructors.qll 7edffc30d3dddc4d73241f4e0d3df4501a99eb38d056f82043ed69e481404342 7edffc30d3dddc4d73241f4e0d3df4501a99eb38d056f82043ed69e481404342 lib/codeql/swift/generated/UnknownFile.qll 5325944cf96a72d5d224597745e15960fb6a9448b96b6644ececd6344dfd9d74 5325944cf96a72d5d224597745e15960fb6a9448b96b6644ececd6344dfd9d74 lib/codeql/swift/generated/UnknownLocation.qll dfdeb8eedb2564eccaac416695784ea04fe9754a3e109e8484c695021af4e554 dfdeb8eedb2564eccaac416695784ea04fe9754a3e109e8484c695021af4e554 diff --git a/swift/ql/lib/codeql/swift/elements/Callable.qll b/swift/ql/lib/codeql/swift/elements/Callable.qll index 367741ecd7c..b74b530683d 100644 --- a/swift/ql/lib/codeql/swift/elements/Callable.qll +++ b/swift/ql/lib/codeql/swift/elements/Callable.qll @@ -2,7 +2,7 @@ private import codeql.swift.generated.Callable private import codeql.swift.elements.AstNode private import codeql.swift.elements.decl.Decl -class Callable extends Generated::Callable, AstNode { +class Callable extends Generated::Callable { /** * Holds if this Callable is a function named `funcName`. */ diff --git a/swift/ql/lib/codeql/swift/generated/Callable.qll b/swift/ql/lib/codeql/swift/generated/Callable.qll index 71cfede9e92..4ad169e81c0 100644 --- a/swift/ql/lib/codeql/swift/generated/Callable.qll +++ b/swift/ql/lib/codeql/swift/generated/Callable.qll @@ -6,9 +6,9 @@ private import codeql.swift.generated.Synth private import codeql.swift.generated.Raw +import codeql.swift.elements.AstNode import codeql.swift.elements.stmt.BraceStmt import codeql.swift.elements.decl.CapturedDecl -import codeql.swift.elements.Element import codeql.swift.elements.decl.ParamDecl /** @@ -20,7 +20,7 @@ module Generated { * INTERNAL: Do not reference the `Generated::Callable` class directly. * Use the subclass `Callable`, where the following predicates are available. */ - class Callable extends Synth::TCallable, Element { + class Callable extends Synth::TCallable, AstNode { /** * Gets the name of this callable, if it exists. * diff --git a/swift/ql/lib/codeql/swift/generated/ParentChild.qll b/swift/ql/lib/codeql/swift/generated/ParentChild.qll index 1578315af7d..058d02bfcb5 100644 --- a/swift/ql/lib/codeql/swift/generated/ParentChild.qll +++ b/swift/ql/lib/codeql/swift/generated/ParentChild.qll @@ -14,33 +14,6 @@ private module Impl { none() } - private Element getImmediateChildOfCallable(Callable e, int index, string partialPredicateCall) { - exists(int b, int bElement, int n, int nSelfParam, int nParam, int nBody, int nCapture | - b = 0 and - bElement = b + 1 + max(int i | i = -1 or exists(getImmediateChildOfElement(e, i, _)) | i) and - n = bElement and - nSelfParam = n + 1 and - nParam = nSelfParam + 1 + max(int i | i = -1 or exists(e.getParam(i)) | i) and - nBody = nParam + 1 and - nCapture = nBody + 1 + max(int i | i = -1 or exists(e.getCapture(i)) | i) and - ( - none() - or - result = getImmediateChildOfElement(e, index - b, partialPredicateCall) - or - index = n and result = e.getSelfParam() and partialPredicateCall = "SelfParam()" - or - result = e.getParam(index - nSelfParam) and - partialPredicateCall = "Param(" + (index - nSelfParam).toString() + ")" - or - index = nParam and result = e.getBody() and partialPredicateCall = "Body()" - or - result = e.getCapture(index - nBody) and - partialPredicateCall = "Capture(" + (index - nBody).toString() + ")" - ) - ) - } - private Element getImmediateChildOfFile(File e, int index, string partialPredicateCall) { exists(int b, int bElement, int n | b = 0 and @@ -226,6 +199,33 @@ private module Impl { ) } + private Element getImmediateChildOfCallable(Callable e, int index, string partialPredicateCall) { + exists(int b, int bAstNode, int n, int nSelfParam, int nParam, int nBody, int nCapture | + b = 0 and + bAstNode = b + 1 + max(int i | i = -1 or exists(getImmediateChildOfAstNode(e, i, _)) | i) and + n = bAstNode and + nSelfParam = n + 1 and + nParam = nSelfParam + 1 + max(int i | i = -1 or exists(e.getParam(i)) | i) and + nBody = nParam + 1 and + nCapture = nBody + 1 + max(int i | i = -1 or exists(e.getCapture(i)) | i) and + ( + none() + or + result = getImmediateChildOfAstNode(e, index - b, partialPredicateCall) + or + index = n and result = e.getSelfParam() and partialPredicateCall = "SelfParam()" + or + result = e.getParam(index - nSelfParam) and + partialPredicateCall = "Param(" + (index - nSelfParam).toString() + ")" + or + index = nParam and result = e.getBody() and partialPredicateCall = "Body()" + or + result = e.getCapture(index - nBody) and + partialPredicateCall = "Capture(" + (index - nBody).toString() + ")" + ) + ) + } + private Element getImmediateChildOfKeyPathComponent( KeyPathComponent e, int index, string partialPredicateCall ) { diff --git a/swift/ql/lib/codeql/swift/generated/Raw.qll b/swift/ql/lib/codeql/swift/generated/Raw.qll index 69168ddd0a7..69b72a2b06b 100644 --- a/swift/ql/lib/codeql/swift/generated/Raw.qll +++ b/swift/ql/lib/codeql/swift/generated/Raw.qll @@ -15,40 +15,6 @@ module Raw { predicate isUnknown() { element_is_unknown(this) } } - /** - * INTERNAL: Do not use. - */ - class Callable extends @callable, Element { - /** - * Gets the name of this callable, if it exists. - * - * The name includes argument labels of the callable, for example `myFunction(arg:)`. - */ - string getName() { callable_names(this, result) } - - /** - * Gets the self parameter of this callable, if it exists. - */ - ParamDecl getSelfParam() { callable_self_params(this, result) } - - /** - * Gets the `index`th parameter of this callable (0-based). - */ - ParamDecl getParam(int index) { callable_params(this, index, result) } - - /** - * Gets the body of this callable, if it exists. - * - * The body is absent within protocol declarations. - */ - BraceStmt getBody() { callable_bodies(this, result) } - - /** - * Gets the `index`th capture of this callable (0-based). - */ - CapturedDecl getCapture(int index) { callable_captures(this, index, result) } - } - /** * INTERNAL: Do not use. */ @@ -197,6 +163,40 @@ module Raw { */ class AvailabilitySpec extends @availability_spec, AstNode { } + /** + * INTERNAL: Do not use. + */ + class Callable extends @callable, AstNode { + /** + * Gets the name of this callable, if it exists. + * + * The name includes argument labels of the callable, for example `myFunction(arg:)`. + */ + string getName() { callable_names(this, result) } + + /** + * Gets the self parameter of this callable, if it exists. + */ + ParamDecl getSelfParam() { callable_self_params(this, result) } + + /** + * Gets the `index`th parameter of this callable (0-based). + */ + ParamDecl getParam(int index) { callable_params(this, index, result) } + + /** + * Gets the body of this callable, if it exists. + * + * The body is absent within protocol declarations. + */ + BraceStmt getBody() { callable_bodies(this, result) } + + /** + * Gets the `index`th capture of this callable (0-based). + */ + CapturedDecl getCapture(int index) { callable_captures(this, index, result) } + } + /** * INTERNAL: Do not use. * A component of a `KeyPathExpr`. diff --git a/swift/ql/lib/codeql/swift/generated/Synth.qll b/swift/ql/lib/codeql/swift/generated/Synth.qll index 778eb6462cf..7d8c69f779d 100644 --- a/swift/ql/lib/codeql/swift/generated/Synth.qll +++ b/swift/ql/lib/codeql/swift/generated/Synth.qll @@ -1080,8 +1080,9 @@ module Synth { * INTERNAL: Do not use. */ class TAstNode = - TAvailabilityInfo or TAvailabilitySpec or TCaseLabelItem or TConditionElement or TDecl or - TExpr or TKeyPathComponent or TMacroRole or TPattern or TStmt or TStmtCondition or TTypeRepr; + TAvailabilityInfo or TAvailabilitySpec or TCallable or TCaseLabelItem or TConditionElement or + TDecl or TExpr or TKeyPathComponent or TMacroRole or TPattern or TStmt or TStmtCondition or + TTypeRepr; /** * INTERNAL: Do not use. @@ -3369,6 +3370,8 @@ module Synth { or result = convertAvailabilitySpecFromRaw(e) or + result = convertCallableFromRaw(e) + or result = convertCaseLabelItemFromRaw(e) or result = convertConditionElementFromRaw(e) @@ -3418,8 +3421,6 @@ module Synth { */ cached TElement convertElementFromRaw(Raw::Element e) { - result = convertCallableFromRaw(e) - or result = convertFileFromRaw(e) or result = convertGenericContextFromRaw(e) @@ -6341,6 +6342,8 @@ module Synth { or result = convertAvailabilitySpecToRaw(e) or + result = convertCallableToRaw(e) + or result = convertCaseLabelItemToRaw(e) or result = convertConditionElementToRaw(e) @@ -6390,8 +6393,6 @@ module Synth { */ cached Raw::Element convertElementToRaw(TElement e) { - result = convertCallableToRaw(e) - or result = convertFileToRaw(e) or result = convertGenericContextToRaw(e) diff --git a/swift/ql/lib/swift.dbscheme b/swift/ql/lib/swift.dbscheme index 15a630f68e1..1a24fefd78b 100644 --- a/swift/ql/lib/swift.dbscheme +++ b/swift/ql/lib/swift.dbscheme @@ -12,8 +12,7 @@ sourceLocationPrefix( // from schema.py @element = - @callable -| @file + @file | @generic_context | @locatable | @location @@ -25,43 +24,6 @@ element_is_unknown( int id: @element ref ); -@callable = - @closure_expr -| @function -; - -#keyset[id] -callable_names( - int id: @callable ref, - string name: string ref -); - -#keyset[id] -callable_self_params( - int id: @callable ref, - int self_param: @param_decl_or_none ref -); - -#keyset[id, index] -callable_params( - int id: @callable ref, - int index: int ref, - int param: @param_decl_or_none ref -); - -#keyset[id] -callable_bodies( - int id: @callable ref, - int body: @brace_stmt_or_none ref -); - -#keyset[id, index] -callable_captures( - int id: @callable ref, - int index: int ref, - int capture: @captured_decl_or_none ref -); - @file = @db_file ; @@ -108,6 +70,7 @@ locations( @ast_node = @availability_info | @availability_spec +| @callable | @case_label_item | @condition_element | @decl @@ -175,6 +138,43 @@ availability_info_specs( | @platform_version_availability_spec ; +@callable = + @closure_expr +| @function +; + +#keyset[id] +callable_names( + int id: @callable ref, + string name: string ref +); + +#keyset[id] +callable_self_params( + int id: @callable ref, + int self_param: @param_decl_or_none ref +); + +#keyset[id, index] +callable_params( + int id: @callable ref, + int index: int ref, + int param: @param_decl_or_none ref +); + +#keyset[id] +callable_bodies( + int id: @callable ref, + int body: @brace_stmt_or_none ref +); + +#keyset[id, index] +callable_captures( + int id: @callable ref, + int index: int ref, + int capture: @captured_decl_or_none ref +); + key_path_components( unique int id: @key_path_component, int kind: int ref, diff --git a/swift/schema.py b/swift/schema.py index 66fe693a8bc..e1deb0a2778 100644 --- a/swift/schema.py +++ b/swift/schema.py @@ -242,7 +242,7 @@ class ParamDecl(VarDecl): has a property wrapper. """) -class Callable(Element): +class Callable(AstNode): name: optional[string] | doc("name of this callable") | desc("The name includes argument " "labels of the callable, for example `myFunction(arg:)`.") self_param: optional[ParamDecl] | child