"""
Schema description
This file should be kept simple:
* no flow control
* no aliases
* only class definitions with annotations and `include` calls
For how documentation of generated QL code works, please read schema_documentation.md.
"""
from misc.codegen.lib.schemadefs import *
include("prefix.dbscheme")
@qltest.skip
class Element:
is_unknown: predicate | cpp.skip
@qltest.collapse_hierarchy
class File(Element):
name: string
is_successfully_extracted: predicate | cpp.skip
@qltest.skip
@qltest.collapse_hierarchy
class Location(Element):
file: File
start_line: int
start_column: int
end_line: int
end_column: int
@qltest.skip
class Locatable(Element):
location: optional[Location] | cpp.skip | doc("location associated with this element in the code")
@qltest.collapse_hierarchy
@qltest.skip
class ErrorElement(Locatable):
"""The superclass of all elements indicating some kind of error."""
pass
@use_for_null
class UnspecifiedElement(ErrorElement):
parent: optional[Element]
property: string
index: optional[int]
error: string
children: list["AstNode"] | child | desc("These will be present only in certain downgraded databases.")
class Comment(Locatable):
text: string
class Diagnostics(Locatable):
text: string
kind: int
class DbFile(File):
pass
class DbLocation(Location):
pass
@synth.on_arguments()
class UnknownFile(File):
pass
@synth.on_arguments()
class UnknownLocation(Location):
pass
class AstNode(Locatable):
pass
@group("type")
@ql.hideable
class Type(Element):
name: string
canonical_type: "Type" | desc("""
This is the unique type we get after resolving aliases and desugaring. For example, given
```
typealias MyInt = Int
```
then `[MyInt?]` has the canonical type `Array`.
""")
@group("decl")
class Decl(AstNode):
module: "ModuleDecl"
members: list["Decl"] | child | desc("""
Prefer to use more specific methods (such as `EnumDecl.getEnumElement`) rather than relying
on the order of members given by `getMember`. In some cases the order of members may not
align with expectations, and could change in future releases.
""")
@group("expr")
@ql.hideable
class Expr(AstNode):
"""The base class for all expressions in Swift."""
type: optional[Type]
@group("pattern")
@ql.hideable
class Pattern(AstNode):
type: optional[Type]
@group("stmt")
class Stmt(AstNode):
pass
@group("decl")
class GenericContext(Element):
generic_type_params: list["GenericTypeParamDecl"] | child
@qltest.test_with("EnumDecl")
class EnumCaseDecl(Decl):
elements: list["EnumElementDecl"]
class ExtensionDecl(GenericContext, Decl):
extended_type_decl: "NominalTypeDecl"
protocols: list["ProtocolDecl"]
class IfConfigDecl(Decl):
active_elements: list[AstNode]
class ImportDecl(Decl):
is_exported: predicate
imported_module: optional["ModuleDecl"]
declarations: list["ValueDecl"]
@qltest.skip
class MissingMemberDecl(Decl):
"""A placeholder for missing declarations that can arise on object deserialization."""
name: string
class OperatorDecl(Decl):
name: string
class PatternBindingDecl(Decl):
inits: list[optional[Expr]] | child
patterns: list[Pattern] | child
class PoundDiagnosticDecl(Decl):
""" A diagnostic directive, which is either `#error` or `#warning`."""
kind: int | desc("""This is 1 for `#error` and 2 for `#warning`.""") | ql.internal
message: "StringLiteralExpr" | child
class PrecedenceGroupDecl(Decl):
pass
class TopLevelCodeDecl(Decl):
body: "BraceStmt" | child
class ValueDecl(Decl):
interface_type: Type
class AbstractStorageDecl(ValueDecl):
accessors: list["Accessor"] | child
class VarDecl(AbstractStorageDecl):
"""
A declaration of a variable such as
* a local variable in a function:
```
func foo() {
var x = 42 // Int {
return x.foo()
}
`x.foo()` is actually wrapped in an `OpenExistentialExpr` that "opens" `x` replacing it in its subexpression with
an `OpaqueValueExpr`.
```
"""
sub_expr: Expr | child | desc("""
This wrapped subexpression is where the opaque value and the dynamic type under the protocol type may be used.""")
existential: Expr | child | doc("protocol-typed expression opened by this expression")
opaque_expr: OpaqueValueExpr | doc("opaque value expression embedded within `getSubExpr()`")
class OptionalEvaluationExpr(Expr):
sub_expr: Expr | child
class OtherInitializerRefExpr(Expr):
initializer: Initializer
class PropertyWrapperValuePlaceholderExpr(Expr):
"""
A placeholder substituting property initializations with `=` when the property has a property
wrapper with an initializer.
"""
wrapped_value: optional[Expr]
placeholder: OpaqueValueExpr
class RebindSelfInInitializerExpr(Expr):
sub_expr: Expr | child
self: VarDecl
@qltest.skip
class SequenceExpr(Expr):
elements: list[Expr] | child
class SuperRefExpr(Expr):
self: VarDecl
class TapExpr(Expr):
sub_expr: optional[Expr] | child
body: "BraceStmt" | child
var: VarDecl
class TupleElementExpr(Expr):
sub_expr: Expr | child
index: int
class TupleExpr(Expr):
elements: list[Expr] | child
class TypeExpr(Expr):
type_repr: optional["TypeRepr"] | child
class UnresolvedDeclRefExpr(Expr, ErrorElement):
name: optional[string]
class UnresolvedDotExpr(Expr, ErrorElement):
base: Expr | child
name: string
class UnresolvedMemberExpr(Expr, ErrorElement):
name: string
class UnresolvedPatternExpr(Expr, ErrorElement):
sub_pattern: Pattern | child
class UnresolvedSpecializeExpr(Expr, ErrorElement):
sub_expr: Expr | child
class VarargExpansionExpr(Expr):
sub_expr: Expr | child
class AnyHashableErasureExpr(ImplicitConversionExpr):
pass
class ArchetypeToSuperExpr(ImplicitConversionExpr):
pass
class ArrayExpr(CollectionExpr):
elements: list[Expr] | child
class ArrayToPointerExpr(ImplicitConversionExpr):
pass
class AutoClosureExpr(ClosureExpr):
pass
class AwaitExpr(IdentityExpr):
pass
class BinaryExpr(ApplyExpr):
pass
@qltest.skip
class BridgeFromObjCExpr(ImplicitConversionExpr):
pass
@qltest.skip
class BridgeToObjCExpr(ImplicitConversionExpr):
pass
class BuiltinLiteralExpr(LiteralExpr):
pass
class CallExpr(ApplyExpr):
pass
class CheckedCastExpr(ExplicitCastExpr):
pass
class ClassMetatypeToObjectExpr(ImplicitConversionExpr):
pass
class ExplicitClosureExpr(ClosureExpr):
pass
class CoerceExpr(ExplicitCastExpr):
pass
class CollectionUpcastConversionExpr(ImplicitConversionExpr):
pass
@qltest.skip
class ConditionalBridgeFromObjCExpr(ImplicitConversionExpr):
pass
class CovariantFunctionConversionExpr(ImplicitConversionExpr):
pass
class CovariantReturnConversionExpr(ImplicitConversionExpr):
pass
class DerivedToBaseExpr(ImplicitConversionExpr):
pass
class DestructureTupleExpr(ImplicitConversionExpr):
pass
class DictionaryExpr(CollectionExpr):
elements: list[Expr] | child
class DifferentiableFunctionExpr(ImplicitConversionExpr):
pass
class DifferentiableFunctionExtractOriginalExpr(ImplicitConversionExpr):
pass
class DotSelfExpr(IdentityExpr):
pass
@qltest.collapse_hierarchy
class DynamicLookupExpr(LookupExpr):
pass
class ErasureExpr(ImplicitConversionExpr):
pass
class ExistentialMetatypeToObjectExpr(ImplicitConversionExpr):
pass
class ForceTryExpr(AnyTryExpr):
pass
class ForeignObjectConversionExpr(ImplicitConversionExpr):
pass
class FunctionConversionExpr(ImplicitConversionExpr):
pass
class InOutToPointerExpr(ImplicitConversionExpr):
pass
class InjectIntoOptionalExpr(ImplicitConversionExpr):
pass
class InterpolatedStringLiteralExpr(LiteralExpr):
interpolation_expr: optional[OpaqueValueExpr]
appending_expr: optional[TapExpr] | child
class LinearFunctionExpr(ImplicitConversionExpr):
pass
class LinearFunctionExtractOriginalExpr(ImplicitConversionExpr):
pass
class LinearToDifferentiableFunctionExpr(ImplicitConversionExpr):
pass
class LoadExpr(ImplicitConversionExpr):
pass
class MemberRefExpr(LookupExpr):
has_direct_to_storage_semantics: predicate
has_direct_to_implementation_semantics: predicate
has_ordinary_semantics: predicate
has_distributed_thunk_semantics: predicate
class MetatypeConversionExpr(ImplicitConversionExpr):
pass
class NilLiteralExpr(LiteralExpr):
pass
class ObjectLiteralExpr(LiteralExpr):
"""
An instance of `#fileLiteral`, `#imageLiteral` or `#colorLiteral` expressions, which are used in playgrounds.
"""
kind: int | desc("""This is 0 for `#fileLiteral`, 1 for `#imageLiteral` and 2 for `#colorLiteral`.""")
arguments: list[Argument] | child
class OptionalTryExpr(AnyTryExpr):
pass
class OverloadedDeclRefExpr(Expr, ErrorElement):
"""
An ambiguous expression that might refer to multiple declarations. This will be present only
for failing compilations.
"""
possible_declarations: list[ValueDecl]
class ParenExpr(IdentityExpr):
pass
class PointerToPointerExpr(ImplicitConversionExpr):
pass
class PostfixUnaryExpr(ApplyExpr):
pass
class PrefixUnaryExpr(ApplyExpr):
pass
class ProtocolMetatypeToObjectExpr(ImplicitConversionExpr):
pass
@ql.default_doc_name("regular expression")
class RegexLiteralExpr(LiteralExpr):
"""A regular expression literal which is checked at compile time, for example `/a(a|b)*b/`."""
pattern: string
version: int | doc(
"version of the internal regular expression language being used by Swift")
@ql.internal
class SelfApplyExpr(ApplyExpr):
"""
An internal raw instance of method lookups like `x.foo` in `x.foo()`.
This is completely replaced by the synthesized type `MethodLookupExpr`.
"""
base: Expr
class StringToPointerExpr(ImplicitConversionExpr):
pass
class SubscriptExpr(LookupExpr):
arguments: list[Argument] | child
has_direct_to_storage_semantics: predicate
has_direct_to_implementation_semantics: predicate
has_ordinary_semantics: predicate
has_distributed_thunk_semantics: predicate
class TryExpr(AnyTryExpr):
pass
class UnderlyingToOpaqueExpr(ImplicitConversionExpr):
pass
class UnevaluatedInstanceExpr(ImplicitConversionExpr):
pass
class UnresolvedMemberChainResultExpr(IdentityExpr, ErrorElement):
pass
class UnresolvedTypeConversionExpr(ImplicitConversionExpr, ErrorElement):
pass
class BooleanLiteralExpr(BuiltinLiteralExpr):
value: boolean
class ConditionalCheckedCastExpr(CheckedCastExpr):
pass
@ql.internal
class InitializerRefCallExpr(SelfApplyExpr):
pass
@ql.internal
class DotSyntaxCallExpr(SelfApplyExpr):
pass
@synth.from_class(SelfApplyExpr)
class MethodLookupExpr(LookupExpr):
method_ref: Expr | child | doc("the underlying method declaration reference expression")
class DynamicMemberRefExpr(DynamicLookupExpr):
pass
class DynamicSubscriptExpr(DynamicLookupExpr):
pass
class ForcedCheckedCastExpr(CheckedCastExpr):
pass
class IsExpr(CheckedCastExpr):
pass
class MagicIdentifierLiteralExpr(BuiltinLiteralExpr):
kind: string
class NumberLiteralExpr(BuiltinLiteralExpr):
pass
class StringLiteralExpr(BuiltinLiteralExpr):
value: string
class FloatLiteralExpr(NumberLiteralExpr):
string_value: string
class IntegerLiteralExpr(NumberLiteralExpr):
string_value: string
class AnyPattern(Pattern):
pass
class BindingPattern(Pattern):
sub_pattern: Pattern | child
class BoolPattern(Pattern):
value: boolean
class EnumElementPattern(Pattern):
element: EnumElementDecl
sub_pattern: optional[Pattern] | child
class ExprPattern(Pattern):
sub_expr: Expr | child
class IsPattern(Pattern):
cast_type_repr: optional["TypeRepr"] | child
sub_pattern: optional[Pattern] | child
class NamedPattern(Pattern):
var_decl: VarDecl
class OptionalSomePattern(Pattern):
sub_pattern: Pattern | child
class ParenPattern(Pattern):
sub_pattern: Pattern | child
class TuplePattern(Pattern):
elements: list[Pattern] | child
class TypedPattern(Pattern):
sub_pattern: Pattern | child
type_repr: optional["TypeRepr"] | child
@group("stmt")
@qltest.test_with("SwitchStmt")
class CaseLabelItem(AstNode):
pattern: Pattern | child
guard: optional[Expr] | child
class AvailabilitySpec(AstNode):
"""
An availability spec, that is, part of an `AvailabilityInfo` condition. For example `iOS 12` and `*` in:
```
if #available(iOS 12, *)
```
"""
pass
class PlatformVersionAvailabilitySpec(AvailabilitySpec):
"""
An availability spec based on platform and version, for example `macOS 12` or `watchOS 14`
"""
platform: string
version: string
class OtherAvailabilitySpec(AvailabilitySpec):
"""
A wildcard availability spec `*`
"""
pass
class AvailabilityInfo(AstNode):
"""
An availability condition of an `if`, `while`, or `guard` statements.
Examples:
```
if #available(iOS 12, *) {
// Runs on iOS 12 and above
} else {
// Runs only anything below iOS 12
}
if #unavailable(macOS 10.14, *) {
// Runs only on macOS 10 and below
}
```
"""
is_unavailable: predicate | doc("it is #unavailable as opposed to #available")
specs: list[AvailabilitySpec] | child
@group("stmt")
class ConditionElement(AstNode):
boolean: optional[Expr] | child
pattern: optional[Pattern] | child
initializer: optional[Expr] | child
availability: optional[AvailabilityInfo] | child
@group("stmt")
class StmtCondition(AstNode):
elements: list[ConditionElement] | child
class BraceStmt(Stmt):
variables: list[VarDecl] | synth | child | doc("variable declared in the scope of this brace statement")
elements: list[AstNode] | child
class BreakStmt(Stmt):
target_name: optional[string]
target: optional[Stmt]
@qltest.test_with("SwitchStmt")
class CaseStmt(Stmt):
labels: list[CaseLabelItem] | child
variables: list[VarDecl] | child
body: Stmt | child
class ContinueStmt(Stmt):
target_name: optional[string]
target: optional[Stmt]
class DeferStmt(Stmt):
body: BraceStmt | child
class FailStmt(Stmt):
pass
class FallthroughStmt(Stmt):
fallthrough_source: CaseStmt
fallthrough_dest: CaseStmt
class LabeledStmt(Stmt):
label: optional[string]
class PoundAssertStmt(Stmt):
condition: Expr
message: string
class ReturnStmt(Stmt):
result: optional[Expr] | child
class ThrowStmt(Stmt):
sub_expr: Expr | child
class YieldStmt(Stmt):
results: list[Expr] | child
@qltest.test_with('SingleValueStmtExpr')
class ThenStmt(Stmt):
""" A statement implicitly wrapping values to be used in branches of if/switch expressions. For example in:
```
let rank = switch value {
case 0.. (repeat each T) {
return (repeat each t)
}
```
More details:
https://github.com/apple/swift-evolution/blob/main/proposals/0393-parameter-packs.md
"""
pattern_expr: Expr | child
@qltest.test_with(PackExpansionExpr)
class PackElementExpr(Expr):
"""
A pack element expression is a child of PackExpansionExpr.
In the following example, `each t` on the second line is the pack element expression:
```
func makeTuple(_ t: repeat each T) -> (repeat each T) {
return (repeat each t)
}
```
More details:
https://github.com/apple/swift-evolution/blob/main/proposals/0393-parameter-packs.md
"""
sub_expr: Expr | child
@qltest.test_with(PackExpansionExpr)
class MaterializePackExpr(Expr):
"""
An expression that materializes a pack during expansion. Appears around PackExpansionExpr.
More details:
https://github.com/apple/swift-evolution/blob/main/proposals/0393-parameter-packs.md
"""
sub_expr: Expr | child
class CopyExpr(Expr):
"""
An expression that forces value to be copied. In the example below, `copy` marks the copy expression:
```
let y = ...
let x = copy y
```
"""
sub_expr: Expr | child
@qltest.test_with(CopyExpr)
class ConsumeExpr(Expr):
"""
An expression that forces value to be moved. In the example below, `consume` marks the move expression:
```
let y = ...
let x = consume y
```
"""
sub_expr: Expr | child
class BorrowExpr(IdentityExpr):
"""
An expression that marks value as borrowed. In the example below, `_borrow` marks the borrow expression:
```
let y = ...
let x = _borrow y
```
"""
pass
@qltest.test_with('MacroDecl')
class MacroRole(AstNode):
"""
The role of a macro, for example #freestanding(declaration) or @attached(member).
"""
kind: int | doc("kind of this macro role (declaration, expression, member, etc.)") | ql.internal
macro_syntax: int | doc("#freestanding or @attached") | ql.internal
conformances: list[TypeExpr] | doc("conformances of this macro role")
names: list[string] | doc("names of this macro role")
class MacroDecl(GenericContext, ValueDecl):
"""
A declaration of a macro. Some examples:
```
@freestanding(declaration)
macro A() = #externalMacro(module: "A", type: "A")
@freestanding(expression)
macro B() = Builtin.B
@attached(member)
macro C() = C.C
```
"""
name: string | doc("name of this macro")
parameters: list[ParamDecl] | doc("parameters of this macro")
roles: list[MacroRole] | doc("roles of this macro")
pass
class DiscardStmt(Stmt):
"""
A statement that takes a non-copyable value and destructs its members/fields.
The only valid syntax:
```
destruct self
```
"""
sub_expr: Expr | child