Swift: Fix AvailabilitySpec trap generation

This commit is contained in:
Jeroen Ketema
2025-09-16 17:18:46 +02:00
parent 300b5b15e7
commit 626bc55caf
22 changed files with 130 additions and 321 deletions

View File

@@ -18,8 +18,6 @@ import codeql.swift.elements.KeyPathComponent
import codeql.swift.elements.Locatable
import codeql.swift.elements.Location
import codeql.swift.elements.MacroRole
import codeql.swift.elements.OtherAvailabilitySpec
import codeql.swift.elements.PlatformVersionAvailabilitySpec
import codeql.swift.elements.UnknownFile
import codeql.swift.elements.UnknownLocation
import codeql.swift.elements.UnspecifiedElement

View File

@@ -1,12 +0,0 @@
// generated by codegen/codegen.py, do not edit
/**
* This module provides the public class `OtherAvailabilitySpec`.
*/
private import internal.OtherAvailabilitySpecImpl
import codeql.swift.elements.AvailabilitySpec
/**
* A wildcard availability spec `*`
*/
final class OtherAvailabilitySpec = Impl::OtherAvailabilitySpec;

View File

@@ -1,12 +0,0 @@
// generated by codegen/codegen.py, do not edit
/**
* This module provides the public class `PlatformVersionAvailabilitySpec`.
*/
private import internal.PlatformVersionAvailabilitySpecImpl
import codeql.swift.elements.AvailabilitySpec
/**
* An availability spec based on platform and version, for example `macOS 12` or `watchOS 14`
*/
final class PlatformVersionAvailabilitySpec = Impl::PlatformVersionAvailabilitySpec;

View File

@@ -1,14 +1,14 @@
// generated by codegen/codegen.py, remove this comment if you wish to edit this file
/**
* This module defines the hook used internally to tweak the characteristic predicate of
* `OtherAvailabilitySpec` synthesized instances.
* `AvailabilitySpec` synthesized instances.
* INTERNAL: Do not use.
*/
private import codeql.swift.generated.Raw
/**
* The characteristic predicate of `OtherAvailabilitySpec` synthesized instances.
* The characteristic predicate of `AvailabilitySpec` synthesized instances.
* INTERNAL: Do not use.
*/
predicate constructOtherAvailabilitySpec(Raw::OtherAvailabilitySpec id) { any() }
predicate constructAvailabilitySpec(Raw::AvailabilitySpec id) { any() }

View File

@@ -1,10 +1,3 @@
// generated by codegen/codegen.py, remove this comment if you wish to edit this file
/**
* This module provides a hand-modifiable wrapper around the generated class `AvailabilitySpec`.
*
* INTERNAL: Do not use.
*/
private import codeql.swift.generated.AvailabilitySpec
/**
@@ -12,11 +5,18 @@ private import codeql.swift.generated.AvailabilitySpec
* be referenced directly.
*/
module Impl {
// the following QLdoc is generated: if you need to edit it, do it in the schema file
/**
* An availability spec, that is, part of an `AvailabilityInfo` condition. For example `iOS 12` and `*` in:
* ```
* if #available(iOS 12, *)
* ```
*/
class AvailabilitySpec extends Generated::AvailabilitySpec { }
class AvailabilitySpec extends Generated::AvailabilitySpec {
override string toStringImpl() {
if this.isWildcard()
then result = "*"
else result = this.getPlatform() + " " + this.getVersion()
}
}
}

View File

@@ -1,11 +0,0 @@
private import codeql.swift.generated.OtherAvailabilitySpec
module Impl {
// the following QLdoc is generated: if you need to edit it, do it in the schema file
/**
* A wildcard availability spec `*`
*/
class OtherAvailabilitySpec extends Generated::OtherAvailabilitySpec {
override string toStringImpl() { result = "*" }
}
}

View File

@@ -1,16 +0,0 @@
// generated by codegen/codegen.py, remove this comment if you wish to edit this file
/**
* This module defines the hook used internally to tweak the characteristic predicate of
* `PlatformVersionAvailabilitySpec` synthesized instances.
* INTERNAL: Do not use.
*/
private import codeql.swift.generated.Raw
/**
* The characteristic predicate of `PlatformVersionAvailabilitySpec` synthesized instances.
* INTERNAL: Do not use.
*/
predicate constructPlatformVersionAvailabilitySpec(Raw::PlatformVersionAvailabilitySpec id) {
any()
}

View File

@@ -1,11 +0,0 @@
private import codeql.swift.generated.PlatformVersionAvailabilitySpec
module Impl {
// the following QLdoc is generated: if you need to edit it, do it in the schema file
/**
* An availability spec based on platform and version, for example `macOS 12` or `watchOS 14`
*/
class PlatformVersionAvailabilitySpec extends Generated::PlatformVersionAvailabilitySpec {
override string toStringImpl() { result = this.getPlatform() + " " + this.getVersion() }
}
}

View File

@@ -21,5 +21,38 @@ module Generated {
* INTERNAL: Do not reference the `Generated::AvailabilitySpec` class directly.
* Use the subclass `AvailabilitySpec`, where the following predicates are available.
*/
class AvailabilitySpec extends Synth::TAvailabilitySpec, AstNodeImpl::AstNode { }
class AvailabilitySpec extends Synth::TAvailabilitySpec, AstNodeImpl::AstNode {
override string getAPrimaryQlClass() { result = "AvailabilitySpec" }
/**
* Gets the platform of this availability spec, if it exists.
*/
string getPlatform() {
result = Synth::convertAvailabilitySpecToRaw(this).(Raw::AvailabilitySpec).getPlatform()
}
/**
* Holds if `getPlatform()` exists.
*/
final predicate hasPlatform() { exists(this.getPlatform()) }
/**
* Gets the version of this availability spec, if it exists.
*/
string getVersion() {
result = Synth::convertAvailabilitySpecToRaw(this).(Raw::AvailabilitySpec).getVersion()
}
/**
* Holds if `getVersion()` exists.
*/
final predicate hasVersion() { exists(this.getVersion()) }
/**
* Holds if this availability spec is wildcard.
*/
predicate isWildcard() {
Synth::convertAvailabilitySpecToRaw(this).(Raw::AvailabilitySpec).isWildcard()
}
}
}

View File

@@ -1,26 +0,0 @@
// generated by codegen/codegen.py, do not edit
/**
* This module provides the generated definition of `OtherAvailabilitySpec`.
* INTERNAL: Do not import directly.
*/
private import codeql.swift.generated.Synth
private import codeql.swift.generated.Raw
import codeql.swift.elements.internal.AvailabilitySpecImpl::Impl as AvailabilitySpecImpl
/**
* INTERNAL: This module contains the fully generated definition of `OtherAvailabilitySpec` and should not
* be referenced directly.
*/
module Generated {
/**
* A wildcard availability spec `*`
* INTERNAL: Do not reference the `Generated::OtherAvailabilitySpec` class directly.
* Use the subclass `OtherAvailabilitySpec`, where the following predicates are available.
*/
class OtherAvailabilitySpec extends Synth::TOtherAvailabilitySpec,
AvailabilitySpecImpl::AvailabilitySpec
{
override string getAPrimaryQlClass() { result = "OtherAvailabilitySpec" }
}
}

View File

@@ -55,6 +55,12 @@ private module Impl {
)
}
private Element getImmediateChildOfAvailabilitySpec(
AvailabilitySpec e, int index, string partialPredicateCall
) {
none()
}
private Element getImmediateChildOfKeyPathComponent(
KeyPathComponent e, int index, string partialPredicateCall
) {
@@ -89,18 +95,6 @@ private module Impl {
)
}
private Element getImmediateChildOfOtherAvailabilitySpec(
OtherAvailabilitySpec e, int index, string partialPredicateCall
) {
none()
}
private Element getImmediateChildOfPlatformVersionAvailabilitySpec(
PlatformVersionAvailabilitySpec e, int index, string partialPredicateCall
) {
none()
}
private Element getImmediateChildOfCapturedDecl(
CapturedDecl e, int index, string partialPredicateCall
) {
@@ -3188,16 +3182,14 @@ private module Impl {
or
result = getImmediateChildOfAvailabilityInfo(e, index, partialAccessor)
or
result = getImmediateChildOfAvailabilitySpec(e, index, partialAccessor)
or
result = getImmediateChildOfKeyPathComponent(e, index, partialAccessor)
or
result = getImmediateChildOfMacroRole(e, index, partialAccessor)
or
result = getImmediateChildOfUnspecifiedElement(e, index, partialAccessor)
or
result = getImmediateChildOfOtherAvailabilitySpec(e, index, partialAccessor)
or
result = getImmediateChildOfPlatformVersionAvailabilitySpec(e, index, partialAccessor)
or
result = getImmediateChildOfCapturedDecl(e, index, partialAccessor)
or
result = getImmediateChildOfEnumCaseDecl(e, index, partialAccessor)

View File

@@ -1,46 +0,0 @@
// generated by codegen/codegen.py, do not edit
/**
* This module provides the generated definition of `PlatformVersionAvailabilitySpec`.
* INTERNAL: Do not import directly.
*/
private import codeql.swift.generated.Synth
private import codeql.swift.generated.Raw
import codeql.swift.elements.internal.AvailabilitySpecImpl::Impl as AvailabilitySpecImpl
/**
* INTERNAL: This module contains the fully generated definition of `PlatformVersionAvailabilitySpec` and should not
* be referenced directly.
*/
module Generated {
/**
* An availability spec based on platform and version, for example `macOS 12` or `watchOS 14`
* INTERNAL: Do not reference the `Generated::PlatformVersionAvailabilitySpec` class directly.
* Use the subclass `PlatformVersionAvailabilitySpec`, where the following predicates are available.
*/
class PlatformVersionAvailabilitySpec extends Synth::TPlatformVersionAvailabilitySpec,
AvailabilitySpecImpl::AvailabilitySpec
{
override string getAPrimaryQlClass() { result = "PlatformVersionAvailabilitySpec" }
/**
* Gets the platform of this platform version availability spec.
*/
string getPlatform() {
result =
Synth::convertPlatformVersionAvailabilitySpecToRaw(this)
.(Raw::PlatformVersionAvailabilitySpec)
.getPlatform()
}
/**
* Gets the version of this platform version availability spec.
*/
string getVersion() {
result =
Synth::convertPlatformVersionAvailabilitySpecToRaw(this)
.(Raw::PlatformVersionAvailabilitySpec)
.getVersion()
}
}
}

View File

@@ -161,7 +161,24 @@ module Raw {
* if #available(iOS 12, *)
* ```
*/
class AvailabilitySpec extends @availability_spec, AstNode { }
class AvailabilitySpec extends @availability_spec, AstNode {
override string toString() { result = "AvailabilitySpec" }
/**
* Gets the platform of this availability spec, if it exists.
*/
string getPlatform() { availability_spec_platforms(this, result) }
/**
* Gets the version of this availability spec, if it exists.
*/
string getVersion() { availability_spec_versions(this, result) }
/**
* Holds if this availability spec is wildcard.
*/
predicate isWildcard() { availability_spec_is_wildcard(this) }
}
/**
* INTERNAL: Do not use.
@@ -308,34 +325,6 @@ module Raw {
AstNode getChild(int index) { unspecified_element_children(this, index, result) }
}
/**
* INTERNAL: Do not use.
* A wildcard availability spec `*`
*/
class OtherAvailabilitySpec extends @other_availability_spec, AvailabilitySpec {
override string toString() { result = "OtherAvailabilitySpec" }
}
/**
* INTERNAL: Do not use.
* An availability spec based on platform and version, for example `macOS 12` or `watchOS 14`
*/
class PlatformVersionAvailabilitySpec extends @platform_version_availability_spec,
AvailabilitySpec
{
override string toString() { result = "PlatformVersionAvailabilitySpec" }
/**
* Gets the platform of this platform version availability spec.
*/
string getPlatform() { platform_version_availability_specs(this, result, _) }
/**
* Gets the version of this platform version availability spec.
*/
string getVersion() { platform_version_availability_specs(this, _, result) }
}
/**
* INTERNAL: Do not use.
*/

View File

@@ -18,6 +18,10 @@ module Synth {
* INTERNAL: Do not use.
*/
TAvailabilityInfo(Raw::AvailabilityInfo id) { constructAvailabilityInfo(id) } or
/**
* INTERNAL: Do not use.
*/
TAvailabilitySpec(Raw::AvailabilitySpec id) { constructAvailabilitySpec(id) } or
/**
* INTERNAL: Do not use.
*/
@@ -42,16 +46,6 @@ module Synth {
* INTERNAL: Do not use.
*/
TMacroRole(Raw::MacroRole id) { constructMacroRole(id) } or
/**
* INTERNAL: Do not use.
*/
TOtherAvailabilitySpec(Raw::OtherAvailabilitySpec id) { constructOtherAvailabilitySpec(id) } or
/**
* INTERNAL: Do not use.
*/
TPlatformVersionAvailabilitySpec(Raw::PlatformVersionAvailabilitySpec id) {
constructPlatformVersionAvailabilitySpec(id)
} or
/**
* INTERNAL: Do not use.
*/
@@ -1123,11 +1117,6 @@ module Synth {
TDecl or TExpr or TKeyPathComponent or TMacroRole or TPattern or TStmt or TStmtCondition or
TTypeRepr;
/**
* INTERNAL: Do not use.
*/
class TAvailabilitySpec = TOtherAvailabilitySpec or TPlatformVersionAvailabilitySpec;
/**
* INTERNAL: Do not use.
*/
@@ -1455,6 +1444,12 @@ module Synth {
*/
TAvailabilityInfo convertAvailabilityInfoFromRaw(Raw::Element e) { result = TAvailabilityInfo(e) }
/**
* INTERNAL: Do not use.
* Converts a raw element to a synthesized `TAvailabilitySpec`, if possible.
*/
TAvailabilitySpec convertAvailabilitySpecFromRaw(Raw::Element e) { result = TAvailabilitySpec(e) }
/**
* INTERNAL: Do not use.
* Converts a raw element to a synthesized `TComment`, if possible.
@@ -1491,22 +1486,6 @@ module Synth {
*/
TMacroRole convertMacroRoleFromRaw(Raw::Element e) { result = TMacroRole(e) }
/**
* INTERNAL: Do not use.
* Converts a raw element to a synthesized `TOtherAvailabilitySpec`, if possible.
*/
TOtherAvailabilitySpec convertOtherAvailabilitySpecFromRaw(Raw::Element e) {
result = TOtherAvailabilitySpec(e)
}
/**
* INTERNAL: Do not use.
* Converts a raw element to a synthesized `TPlatformVersionAvailabilitySpec`, if possible.
*/
TPlatformVersionAvailabilitySpec convertPlatformVersionAvailabilitySpecFromRaw(Raw::Element e) {
result = TPlatformVersionAvailabilitySpec(e)
}
/**
* INTERNAL: Do not use.
* Converts a raw element to a synthesized `TUnknownFile`, if possible.
@@ -3241,16 +3220,6 @@ module Synth {
result = convertTypeReprFromRaw(e)
}
/**
* INTERNAL: Do not use.
* Converts a raw DB element to a synthesized `TAvailabilitySpec`, if possible.
*/
TAvailabilitySpec convertAvailabilitySpecFromRaw(Raw::Element e) {
result = convertOtherAvailabilitySpecFromRaw(e)
or
result = convertPlatformVersionAvailabilitySpecFromRaw(e)
}
/**
* INTERNAL: Do not use.
* Converts a raw DB element to a synthesized `TCallable`, if possible.
@@ -4199,6 +4168,12 @@ module Synth {
*/
Raw::Element convertAvailabilityInfoToRaw(TAvailabilityInfo e) { e = TAvailabilityInfo(result) }
/**
* INTERNAL: Do not use.
* Converts a synthesized `TAvailabilitySpec` to a raw DB element, if possible.
*/
Raw::Element convertAvailabilitySpecToRaw(TAvailabilitySpec e) { e = TAvailabilitySpec(result) }
/**
* INTERNAL: Do not use.
* Converts a synthesized `TComment` to a raw DB element, if possible.
@@ -4235,22 +4210,6 @@ module Synth {
*/
Raw::Element convertMacroRoleToRaw(TMacroRole e) { e = TMacroRole(result) }
/**
* INTERNAL: Do not use.
* Converts a synthesized `TOtherAvailabilitySpec` to a raw DB element, if possible.
*/
Raw::Element convertOtherAvailabilitySpecToRaw(TOtherAvailabilitySpec e) {
e = TOtherAvailabilitySpec(result)
}
/**
* INTERNAL: Do not use.
* Converts a synthesized `TPlatformVersionAvailabilitySpec` to a raw DB element, if possible.
*/
Raw::Element convertPlatformVersionAvailabilitySpecToRaw(TPlatformVersionAvailabilitySpec e) {
e = TPlatformVersionAvailabilitySpec(result)
}
/**
* INTERNAL: Do not use.
* Converts a synthesized `TUnknownFile` to a raw DB element, if possible.
@@ -5983,16 +5942,6 @@ module Synth {
result = convertTypeReprToRaw(e)
}
/**
* INTERNAL: Do not use.
* Converts a synthesized `TAvailabilitySpec` to a raw DB element, if possible.
*/
Raw::Element convertAvailabilitySpecToRaw(TAvailabilitySpec e) {
result = convertOtherAvailabilitySpecToRaw(e)
or
result = convertPlatformVersionAvailabilitySpecToRaw(e)
}
/**
* INTERNAL: Do not use.
* Converts a synthesized `TCallable` to a raw DB element, if possible.

View File

@@ -4,14 +4,13 @@
*/
import codeql.swift.elements.internal.AvailabilityInfoConstructor
import codeql.swift.elements.internal.AvailabilitySpecConstructor
import codeql.swift.elements.internal.CommentConstructor
import codeql.swift.elements.internal.DbFileConstructor
import codeql.swift.elements.internal.DbLocationConstructor
import codeql.swift.elements.internal.DiagnosticsConstructor
import codeql.swift.elements.internal.KeyPathComponentConstructor
import codeql.swift.elements.internal.MacroRoleConstructor
import codeql.swift.elements.internal.OtherAvailabilitySpecConstructor
import codeql.swift.elements.internal.PlatformVersionAvailabilitySpecConstructor
import codeql.swift.elements.internal.UnspecifiedElementConstructor
import codeql.swift.elements.decl.internal.AccessorConstructor
import codeql.swift.elements.decl.internal.AssociatedTypeDeclConstructor