Swift: Handle InlineArrayTypes

This commit is contained in:
Jeroen Ketema
2025-10-31 10:15:07 +01:00
parent 72e8ec3951
commit f4d1e1c034
19 changed files with 220 additions and 7 deletions

View File

@@ -275,6 +275,7 @@ import codeql.swift.elements.type.FunctionType
import codeql.swift.elements.type.GenericFunctionType
import codeql.swift.elements.type.GenericTypeParamType
import codeql.swift.elements.type.InOutType
import codeql.swift.elements.type.InlineArrayType
import codeql.swift.elements.type.IntegerType
import codeql.swift.elements.type.LValueType
import codeql.swift.elements.type.LocalArchetypeType

View File

@@ -0,0 +1,10 @@
// generated by codegen/codegen.py, do not edit
/**
* This module provides the public class `InlineArrayType`.
*/
private import internal.InlineArrayTypeImpl
import codeql.swift.elements.type.SyntaxSugarType
import codeql.swift.elements.type.Type
final class InlineArrayType = Impl::InlineArrayType;

View File

@@ -0,0 +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
* `InlineArrayType` synthesized instances.
* INTERNAL: Do not use.
*/
private import codeql.swift.generated.Raw
/**
* The characteristic predicate of `InlineArrayType` synthesized instances.
* INTERNAL: Do not use.
*/
predicate constructInlineArrayType(Raw::InlineArrayType id) { any() }

View File

@@ -0,0 +1,16 @@
// 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 `InlineArrayType`.
*
* INTERNAL: Do not use.
*/
private import codeql.swift.generated.type.InlineArrayType
/**
* INTERNAL: This module contains the customizable definition of `InlineArrayType` and should not
* be referenced directly.
*/
module Impl {
class InlineArrayType extends Generated::InlineArrayType { }
}

View File

@@ -3103,6 +3103,12 @@ private module Impl {
none()
}
private Element getImmediateChildOfInlineArrayType(
InlineArrayType e, int index, string partialPredicateCall
) {
none()
}
private Element getImmediateChildOfOpaqueTypeArchetypeType(
OpaqueTypeArchetypeType e, int index, string partialPredicateCall
) {
@@ -3675,6 +3681,8 @@ private module Impl {
or
result = getImmediateChildOfDictionaryType(e, index, partialAccessor)
or
result = getImmediateChildOfInlineArrayType(e, index, partialAccessor)
or
result = getImmediateChildOfOpaqueTypeArchetypeType(e, index, partialAccessor)
or
result = getImmediateChildOfPackArchetypeType(e, index, partialAccessor)

View File

@@ -3789,6 +3789,23 @@ module Raw {
Type getValueType() { dictionary_types(this, _, result) }
}
/**
* INTERNAL: Do not use.
*/
class InlineArrayType extends @inline_array_type, SyntaxSugarType {
override string toString() { result = "InlineArrayType" }
/**
* Gets the count type of this inline array type.
*/
Type getCountType() { inline_array_types(this, result, _) }
/**
* Gets the element type of this inline array type.
*/
Type getElementType() { inline_array_types(this, _, result) }
}
/**
* INTERNAL: Do not use.
*/

View File

@@ -1010,6 +1010,10 @@ module Synth {
* INTERNAL: Do not use.
*/
TInOutType(Raw::InOutType id) { constructInOutType(id) } or
/**
* INTERNAL: Do not use.
*/
TInlineArrayType(Raw::InlineArrayType id) { constructInlineArrayType(id) } or
/**
* INTERNAL: Do not use.
*/
@@ -1430,7 +1434,7 @@ module Synth {
/**
* INTERNAL: Do not use.
*/
class TSyntaxSugarType = TDictionaryType or TUnarySyntaxSugarType;
class TSyntaxSugarType = TDictionaryType or TInlineArrayType or TUnarySyntaxSugarType;
/**
* INTERNAL: Do not use.
@@ -3039,6 +3043,12 @@ module Synth {
*/
TInOutType convertInOutTypeFromRaw(Raw::Element e) { result = TInOutType(e) }
/**
* INTERNAL: Do not use.
* Converts a raw element to a synthesized `TInlineArrayType`, if possible.
*/
TInlineArrayType convertInlineArrayTypeFromRaw(Raw::Element e) { result = TInlineArrayType(e) }
/**
* INTERNAL: Do not use.
* Converts a raw element to a synthesized `TIntegerType`, if possible.
@@ -4122,6 +4132,8 @@ module Synth {
TSyntaxSugarType convertSyntaxSugarTypeFromRaw(Raw::Element e) {
result = convertDictionaryTypeFromRaw(e)
or
result = convertInlineArrayTypeFromRaw(e)
or
result = convertUnarySyntaxSugarTypeFromRaw(e)
}
@@ -5777,6 +5789,12 @@ module Synth {
*/
Raw::Element convertInOutTypeToRaw(TInOutType e) { e = TInOutType(result) }
/**
* INTERNAL: Do not use.
* Converts a synthesized `TInlineArrayType` to a raw DB element, if possible.
*/
Raw::Element convertInlineArrayTypeToRaw(TInlineArrayType e) { e = TInlineArrayType(result) }
/**
* INTERNAL: Do not use.
* Converts a synthesized `TIntegerType` to a raw DB element, if possible.
@@ -6860,6 +6878,8 @@ module Synth {
Raw::Element convertSyntaxSugarTypeToRaw(TSyntaxSugarType e) {
result = convertDictionaryTypeToRaw(e)
or
result = convertInlineArrayTypeToRaw(e)
or
result = convertUnarySyntaxSugarTypeToRaw(e)
}

View File

@@ -232,6 +232,7 @@ import codeql.swift.elements.type.internal.FunctionTypeConstructor
import codeql.swift.elements.type.internal.GenericFunctionTypeConstructor
import codeql.swift.elements.type.internal.GenericTypeParamTypeConstructor
import codeql.swift.elements.type.internal.InOutTypeConstructor
import codeql.swift.elements.type.internal.InlineArrayTypeConstructor
import codeql.swift.elements.type.internal.IntegerTypeConstructor
import codeql.swift.elements.type.internal.LValueTypeConstructor
import codeql.swift.elements.type.internal.MetatypeTypeConstructor

View File

@@ -0,0 +1,70 @@
// generated by codegen/codegen.py, do not edit
/**
* This module provides the generated definition of `InlineArrayType`.
* INTERNAL: Do not import directly.
*/
private import codeql.swift.generated.Synth
private import codeql.swift.generated.Raw
import codeql.swift.elements.type.internal.SyntaxSugarTypeImpl::Impl as SyntaxSugarTypeImpl
import codeql.swift.elements.type.Type
/**
* INTERNAL: This module contains the fully generated definition of `InlineArrayType` and should not
* be referenced directly.
*/
module Generated {
/**
* INTERNAL: Do not reference the `Generated::InlineArrayType` class directly.
* Use the subclass `InlineArrayType`, where the following predicates are available.
*/
class InlineArrayType extends Synth::TInlineArrayType, SyntaxSugarTypeImpl::SyntaxSugarType {
override string getAPrimaryQlClass() { result = "InlineArrayType" }
/**
* Gets the count type of this inline array type.
*
* This includes nodes from the "hidden" AST. It can be overridden in subclasses to change the
* behavior of both the `Immediate` and non-`Immediate` versions.
*/
Type getImmediateCountType() {
result =
Synth::convertTypeFromRaw(Synth::convertInlineArrayTypeToRaw(this)
.(Raw::InlineArrayType)
.getCountType())
}
/**
* Gets the count type of this inline array type.
*/
final Type getCountType() {
exists(Type immediate |
immediate = this.getImmediateCountType() and
if exists(this.getResolveStep()) then result = immediate else result = immediate.resolve()
)
}
/**
* Gets the element type of this inline array type.
*
* This includes nodes from the "hidden" AST. It can be overridden in subclasses to change the
* behavior of both the `Immediate` and non-`Immediate` versions.
*/
Type getImmediateElementType() {
result =
Synth::convertTypeFromRaw(Synth::convertInlineArrayTypeToRaw(this)
.(Raw::InlineArrayType)
.getElementType())
}
/**
* Gets the element type of this inline array type.
*/
final Type getElementType() {
exists(Type immediate |
immediate = this.getImmediateElementType() and
if exists(this.getResolveStep()) then result = immediate else result = immediate.resolve()
)
}
}
}