diff --git a/swift/README.md b/swift/README.md index ef805a8273b..8faafd30683 100644 --- a/swift/README.md +++ b/swift/README.md @@ -4,6 +4,32 @@ The Swift codeql package is an experimental and unsupported work in progress. ## Usage -Run `bazel run //swift:create-extractor-pack`, which will install `swift/extractor-pack`. +Run + +```bash +bazel run //swift:create-extractor-pack +``` + +which will install `swift/extractor-pack`. + Using `--search-path=swift/extractor-pack` will then pick up the Swift extractor. You can also use `--search-path=swift`, as the extractor pack is mentioned in `swift/.codeqlmanifest.json`. + +Notice you can run `bazel run :create-extractor-pack` if you already are in the `swift` directory. + +## Code generation + +Make sure to install the [pip requirements](./codegen/requirements.txt) via + +```bash +python3 -m pip install -r codegen/requirements.txt +``` + +Run + +```bash +bazel run //swift/codegen +``` + +to update generated files. This can be shortened to +`bazel run codegen` if you are in the `swift` directory. diff --git a/swift/codegen/BUILD.bazel b/swift/codegen/BUILD.bazel new file mode 100644 index 00000000000..db1b27a4e15 --- /dev/null +++ b/swift/codegen/BUILD.bazel @@ -0,0 +1,8 @@ +py_binary( + name = "codegen", + srcs = glob(["**/*.py"]), + data = glob(["**/*.mustache"]) + [ + "schema.yml", + "prefix.dbscheme", + ], +) diff --git a/swift/codegen/codegen.py b/swift/codegen/codegen.py new file mode 100755 index 00000000000..223d5cb1bb7 --- /dev/null +++ b/swift/codegen/codegen.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python3 + +from lib import generator +import dbschemegen + +if __name__ == "__main__": + generator.run(dbschemegen.generate) diff --git a/swift/codegen/dbschemegen.py b/swift/codegen/dbschemegen.py new file mode 100755 index 00000000000..355e232ad10 --- /dev/null +++ b/swift/codegen/dbschemegen.py @@ -0,0 +1,76 @@ +#!/usr/bin/env python3 + +import inflection + +from lib.renderer import Renderer +from lib.dbscheme import * +from lib import paths, schema, generator + +log = logging.getLogger(__name__) + + +def dbtype(typename): + if typename[0].isupper(): + return "@" + inflection.underscore(typename) + return typename + + +def cls_to_dbscheme(cls: schema.Class): + if cls.derived: + yield DbUnion(dbtype(cls.name), (dbtype(c) for c in cls.derived)) + if not cls.derived or any(f.is_single() for f in cls.fields): + binding = not cls.derived + keyset = DbKeySet(["id"]) if cls.derived else None + yield DbTable( + keyset=keyset, + name=inflection.tableize(cls.name), + columns=[ + DbColumn("id", type=dbtype(cls.name), binding=binding), + ] + [ + DbColumn(f.name, dbtype(f.type)) for f in cls.fields if f.is_single() + ] + ) + for f in cls.fields: + if f.is_optional(): + yield DbTable( + keyset=DbKeySet(["id"]), + name=inflection.tableize(f"{cls.name}_{f.name}"), + columns=[ + DbColumn("id", type=dbtype(cls.name)), + DbColumn(f.name, dbtype(f.type)), + ], + ) + elif f.is_repeated(): + yield DbTable( + keyset=DbKeySet(["id", "index"]), + name=inflection.tableize(f"{cls.name}_{f.name}"), + columns=[ + DbColumn("id", type=dbtype(cls.name)), + DbColumn("index", type="int"), + DbColumn(inflection.singularize(f.name), dbtype(f.type)), + ] + ) + + +def generate(opts): + input = opts.schema.resolve() + out = opts.dbscheme.resolve() + renderer = Renderer(opts.check) + + with open(input) as src: + data = schema.load(src) + + declarations = [d for cls in data.classes.values() for d in cls_to_dbscheme(cls)] + + includes = [] + for inc in data.includes: + inc = input.parent / inc + with open(inc) as inclusion: + includes.append({"src": inc.relative_to(paths.swift_dir), "data": inclusion.read()}) + renderer.render("dbscheme", out, includes=includes, src=input.relative_to(paths.swift_dir), + declarations=declarations) + return renderer.written + + +if __name__ == "__main__": + generator.run(generate, tags=["schema", "dbscheme"]) diff --git a/swift/codegen/lib/dbscheme.py b/swift/codegen/lib/dbscheme.py new file mode 100644 index 00000000000..528ae9e3490 --- /dev/null +++ b/swift/codegen/lib/dbscheme.py @@ -0,0 +1,85 @@ +import logging +import re +from dataclasses import dataclass +from typing import ClassVar, List + +log = logging.getLogger(__name__) + +dbscheme_keywords = {"case", "boolean", "int", "string", "type"} + + +@dataclass +class DbColumn: + schema_name: str + type: str + binding: bool = False + first: bool = False + + def name(self): + if self.schema_name in dbscheme_keywords: + return self.schema_name + "_" + return self.schema_name + + def lhstype(self): + if self.type[0] == "@": + return "unique int" if self.binding else "int" + return self.type + + def rhstype(self): + if self.type[0] == "@" and self.binding: + return self.type + return self.type + " ref" + + +@dataclass +class DbKeySetId: + id: str + first: bool = False + + +@dataclass +class DbKeySet: + ids: List[DbKeySetId] + + def __post_init__(self): + assert self.ids + self.ids = [DbKeySetId(x) for x in self.ids] + self.ids[0].first = True + + +class DbDecl: + is_table = False + is_union = False + + +@dataclass +class DbTable(DbDecl): + is_table: ClassVar = True + + name: str + columns: List[DbColumn] + keyset: DbKeySet = None + + def __post_init__(self): + if self.columns: + self.columns[0].first = True + + +@dataclass +class DbUnionCase: + type: str + first: bool = False + + +@dataclass +class DbUnion(DbDecl): + is_union: ClassVar = True + + lhs: str + rhs: List[DbUnionCase] + + def __post_init__(self): + assert self.rhs + self.rhs = [DbUnionCase(x) for x in self.rhs] + self.rhs.sort(key=lambda c: c.type) + self.rhs[0].first = True diff --git a/swift/codegen/lib/generator.py b/swift/codegen/lib/generator.py new file mode 100644 index 00000000000..b03e446ae76 --- /dev/null +++ b/swift/codegen/lib/generator.py @@ -0,0 +1,55 @@ +import argparse +import collections +import logging +import pathlib +import sys + +from . import paths + +options = collections.defaultdict(list) + + +class Option: + def __init__(self, *args, tags=None, **kwargs): + tags = tags or [] + self.args = args + self.kwargs = kwargs + if tags: + for t in tags: + options[t].append(self) + else: + options["*"].append(self) + + def add_to(self, parser: argparse.ArgumentParser): + parser.add_argument(*self.args, **self.kwargs) + + +Option("--check", "-c", action="store_true") +Option("--verbose", "-v", action="store_true") +Option("--schema", tags=["schema"], type=pathlib.Path, default=paths.swift_dir / "codegen/schema.yml") +Option("--dbscheme", tags=["dbscheme"], type=pathlib.Path, default=paths.swift_dir / "ql/lib/swift.dbscheme") + + +def _parse(*tags): + parser = argparse.ArgumentParser() + if not tags: + opts = [o for os in options.values() for o in os] + else: + opts = options["*"] + for t in tags: + opts.extend(options[t]) + for opt in opts: + opt.add_to(parser) + ret = parser.parse_args() + log_level = logging.DEBUG if ret.verbose else logging.INFO + logging.basicConfig(format="{levelname} {message}", style='{', level=log_level) + return ret + + +def run(*generate, tags=()): + opts = _parse(*tags) + done_something = False + for g in generate: + if g(opts): + done_something = True + sys.exit(1 if opts.check and done_something else 0) diff --git a/swift/codegen/lib/paths.py b/swift/codegen/lib/paths.py new file mode 100644 index 00000000000..7e5892b938f --- /dev/null +++ b/swift/codegen/lib/paths.py @@ -0,0 +1,15 @@ +import pathlib +import sys +import os + +try: + _workspace_dir = pathlib.Path(os.environ['BUILD_WORKSPACE_DIRECTORY']) + swift_dir = _workspace_dir / 'swift' + lib_dir = swift_dir / 'codegen' / 'lib' +except KeyError: + _this_file = pathlib.Path(__file__).resolve() + swift_dir = _this_file.parents[2] + lib_dir = _this_file.parent + + +exe_file = pathlib.Path(sys.argv[0]).resolve() diff --git a/swift/codegen/lib/renderer.py b/swift/codegen/lib/renderer.py new file mode 100644 index 00000000000..53a4288fbe0 --- /dev/null +++ b/swift/codegen/lib/renderer.py @@ -0,0 +1,59 @@ +import hashlib +import logging + +import pystache + +from . import paths + +log = logging.getLogger(__name__) + + +def md5(data): + return hashlib.md5(data).digest() + + +class Renderer: + def __init__(self, check=False): + self.r = pystache.Renderer(search_dirs=str(paths.lib_dir / "templates"), escape=lambda u: u) + self.generator = paths.exe_file.relative_to(paths.swift_dir) + self.check = check + self.written = set() + self.skipped = set() + self.erased = set() + + @property + def done_something(self): + return bool(self.written or self.erased) + + @property + def rendered(self): + return self.written | self.skipped + + def render(self, name, output, **data): + mnemonic, _, _ = name.lower().partition(".") + output.parent.mkdir(parents=True, exist_ok=True) + data["generator"] = self.generator + data = self.r.render_name(name, data) + if output.is_file(): + with open(output, "rb") as file: + if md5(data.encode()) == md5(file.read()): + log.debug(f"skipped {output.name}") + self.skipped.add(output) + return + if self.check: + log.error(f"would have generated {mnemonic} {output.name}") + else: + with open(output, "w") as out: + out.write(data) + log.info(f"generated {mnemonic} {output.name}") + self.written.add(output) + + def cleanup(self, existing): + for f in existing - self.written - self.skipped: + if f.is_file(): + if self.check: + log.error(f"would have removed {f.name}") + else: + f.unlink() + log.info(f"removed {f.name}") + self.erased.add(f) diff --git a/swift/codegen/lib/schema.py b/swift/codegen/lib/schema.py new file mode 100644 index 00000000000..b7113daa800 --- /dev/null +++ b/swift/codegen/lib/schema.py @@ -0,0 +1,98 @@ +import pathlib +from dataclasses import dataclass, field +from enum import Enum, auto +from typing import List, Set, Dict +import re + +import yaml + + +class Cardinality(Enum): + ONE = auto() + OPTIONAL = auto() + MANY = auto() + + +@dataclass +class Field: + name: str + type: str + cardinality: Cardinality = Cardinality.ONE + + def is_single(self): + return self.cardinality == Cardinality.ONE + + def is_optional(self): + return self.cardinality == Cardinality.OPTIONAL + + def is_repeated(self): + return self.cardinality == Cardinality.MANY + + +@dataclass +class Class: + name: str + bases: Set[str] = field(default_factory=set) + derived: Set[str] = field(default_factory=set) + fields: List[Field] = field(default_factory=list) + dir: pathlib.Path = pathlib.Path() + + +@dataclass +class Schema: + classes: Dict[str, Class] + includes: Set[str] = field(default_factory=set) + + +def _parse_field(name, type): + if type.endswith("*"): + cardinality = Cardinality.MANY + type = type[:-1] + elif type.endswith("?"): + cardinality = Cardinality.OPTIONAL + type = type[:-1] + else: + cardinality = Cardinality.ONE + return Field(name, type, cardinality) + + +root_class_name = "Element" + + +class DirSelector: + def __init__(self, dir_to_patterns): + self.selector = [(re.compile(p), pathlib.Path(d)) for d, p in dir_to_patterns] + self.selector.append((re.compile(""), pathlib.Path())) + + def get(self, name): + return next(d for p, d in self.selector if p.search(name)) + + +def load(file): + data = yaml.load(file, Loader=yaml.SafeLoader) + grouper = DirSelector(data.get("_directories", {}).items()) + ret = Schema(classes={cls: Class(cls, dir=grouper.get(cls)) for cls in data if not cls.startswith("_")}, + includes=set(data.get("_includes", []))) + assert root_class_name not in ret.classes + ret.classes[root_class_name] = Class(root_class_name) + for name, info in data.items(): + if name.startswith("_"): + continue + assert name[0].isupper() + cls = ret.classes[name] + for k, v in info.items(): + if not k.startswith("_"): + cls.fields.append(_parse_field(k, v)) + elif k == "_extends": + if not isinstance(v, list): + v = [v] + for base in v: + cls.bases.add(base) + ret.classes[base].derived.add(name) + elif k == "_dir": + cls.dir = pathlib.Path(v) + if not cls.bases: + cls.bases.add(root_class_name) + ret.classes[root_class_name].derived.add(name) + + return ret diff --git a/swift/codegen/lib/templates/dbscheme.mustache b/swift/codegen/lib/templates/dbscheme.mustache new file mode 100644 index 00000000000..257e61e3748 --- /dev/null +++ b/swift/codegen/lib/templates/dbscheme.mustache @@ -0,0 +1,25 @@ +// generated by {{generator}} +{{#includes}} + +// from {{src}} +{{data}} +{{/includes}} + +// from {{src}} +{{#declarations}} + +{{#is_union}} +{{lhs}} = +{{#rhs}} +{{#first}} {{/first}}{{^first}}| {{/first}}{{type}} +{{/rhs}}; +{{/is_union}} +{{#is_table}} +{{#keyset}} +#keyset[{{#ids}}{{^first}}, {{/first}}{{id}}{{/ids}}] +{{/keyset}} +{{name}}({{#columns}}{{^first}},{{/first}} + {{lhstype}} {{name}}: {{rhstype}}{{/columns}} +); +{{/is_table}} +{{/declarations}} diff --git a/swift/codegen/prefix.dbscheme b/swift/codegen/prefix.dbscheme new file mode 100644 index 00000000000..b422464bb90 --- /dev/null +++ b/swift/codegen/prefix.dbscheme @@ -0,0 +1,6 @@ +/** + * The source location of the snapshot. + */ +sourceLocationPrefix( + string prefix: string ref +); diff --git a/swift/codegen/requirements.txt b/swift/codegen/requirements.txt new file mode 100644 index 00000000000..df5110f6535 --- /dev/null +++ b/swift/codegen/requirements.txt @@ -0,0 +1,3 @@ +pystache +pyyaml +inflection diff --git a/swift/codegen/schema.yml b/swift/codegen/schema.yml new file mode 100644 index 00000000000..64e1df269e3 --- /dev/null +++ b/swift/codegen/schema.yml @@ -0,0 +1,997 @@ +# add dbscheme files to be added verbatim +_includes: + - prefix.dbscheme + +# organize generated class files in subdirectories according to these regexp rules +# a class can override this specifying `_dir` +_directories: + decl: Decl$|Context$ + pattern: Pattern$ + type: Type$ + typerepr: TypeRepr$ + expr: Expr$ + stmt: Stmt$ + +File: + name: string + +IterableDeclContext: + members: Decl* + +Locatable: + location: Location + +Location: + file: File + begin_line: int + begin_column: int + end_line: int + end_column: int + +Type: + diagnostics_name: string + canonical_type: Type + +ExtensionDecl: + _extends: + - GenericContext + - IterableDeclContext + - Decl + +NominalTypeDecl: + _extends: + - IterableDeclContext + - GenericTypeDecl + type: Type + +AstNode: + _extends: Locatable + +ConditionElement: + _extends: Locatable + boolean: Expr? + pattern: Pattern? + initializer: Expr? + _dir: stmt + +AnyFunctionType: + _extends: Type + result: Type + param_types: Type* + param_labels: string* + +AnyGenericType: + _extends: Type + parent: Type? + declaration: Decl + +AnyMetatypeType: + _extends: Type + +BuiltinType: + _extends: Type + +DependentMemberType: + _extends: Type + +DynamicSelfType: + _extends: Type + +ErrorType: + _extends: Type + +InOutType: + _extends: Type + +LValueType: + _extends: Type + object_type: Type + +ModuleType: + _extends: Type + +PlaceholderType: + _extends: Type + +ProtocolCompositionType: + _extends: Type + +ExistentialType: + _extends: Type + +ReferenceStorageType: + _extends: Type + +SilBlockStorageType: + _extends: Type + +SilBoxType: + _extends: Type + +SilFunctionType: + _extends: Type + +SilTokenType: + _extends: Type + +SubstitutableType: + _extends: Type + +SugarType: + _extends: Type + +TupleType: + _extends: Type + +TypeVariableType: + _extends: Type + +UnknownType: + _extends: Type + name: string + +UnresolvedType: + _extends: Type + +ClassDecl: + _extends: NominalTypeDecl + +EnumDecl: + _extends: NominalTypeDecl + +ProtocolDecl: + _extends: NominalTypeDecl + +StructDecl: + _extends: NominalTypeDecl + +Decl: + _extends: AstNode + +Expr: + _extends: AstNode + type: Type? + +Pattern: + _extends: AstNode + +Stmt: + _extends: AstNode + +TypeRepr: + _extends: AstNode + +FunctionType: + _extends: AnyFunctionType + +GenericFunctionType: + _extends: AnyFunctionType + generic_params: GenericTypeParamType* + +NominalOrBoundGenericNominalType: + _extends: AnyGenericType + +UnboundGenericType: + _extends: AnyGenericType + +ExistentialMetatypeType: + _extends: AnyMetatypeType + +MetatypeType: + _extends: AnyMetatypeType + +AnyBuiltinIntegerType: + _extends: BuiltinType + +BuiltinBridgeObjectType: + _extends: BuiltinType + +BuiltinDefaultActorStorageType: + _extends: BuiltinType + +BuiltinExecutorType: + _extends: BuiltinType + +BuiltinFloatType: + _extends: BuiltinType + +BuiltinJobType: + _extends: BuiltinType + +BuiltinNativeObjectType: + _extends: BuiltinType + +BuiltinRawPointerType: + _extends: BuiltinType + +BuiltinRawUnsafeContinuationType: + _extends: BuiltinType + +BuiltinUnsafeValueBufferType: + _extends: BuiltinType + +BuiltinVectorType: + _extends: BuiltinType + +UnmanagedStorageType: + _extends: ReferenceStorageType + +UnownedStorageType: + _extends: ReferenceStorageType + +WeakStorageType: + _extends: ReferenceStorageType + +ArchetypeType: + _extends: SubstitutableType + +GenericTypeParamType: + _extends: SubstitutableType + name: string + +ParenType: + _extends: SugarType + +SyntaxSugarType: + _extends: SugarType + +TypeAliasType: + _extends: SugarType + +EnumCaseDecl: + _extends: Decl + elements: EnumElementDecl* + +IfConfigDecl: + _extends: Decl + +ImportDecl: + _extends: Decl + +MissingMemberDecl: + _extends: Decl + +OperatorDecl: + _extends: Decl + +PatternBindingDecl: + _extends: Decl + inits: Expr* + patterns: Pattern* + +PoundDiagnosticDecl: + _extends: Decl + +PrecedenceGroupDecl: + _extends: Decl + +TopLevelCodeDecl: + _extends: Decl + body: BraceStmt + +UnknownAstNode: + _extends: + - Decl + - Expr + - Pattern + - Stmt + - TypeRepr + name: string + +ValueDecl: + _extends: Decl + interface_type: Type + +AbstractClosureExpr: + _extends: Expr + +AnyTryExpr: + _extends: Expr + sub_expr: Expr + +AppliedPropertyWrapperExpr: + _extends: Expr + +Argument: + label: string + expr: Expr + _dir: expr + +ApplyExpr: + _extends: Expr + function: Expr + arguments: Argument* + +ArrowExpr: + _extends: Expr + +AssignExpr: + _extends: Expr + dest: Expr + src: Expr + +BindOptionalExpr: + _extends: Expr + +CaptureListExpr: + _extends: Expr + +CodeCompletionExpr: + _extends: Expr + +CollectionExpr: + _extends: Expr + +DeclRefExpr: + _extends: Expr + decl: Decl + replacement_types: Type* + +DefaultArgumentExpr: + _extends: Expr + param_decl: ParamDecl + param_index: int + caller_side_default: Expr? + +DiscardAssignmentExpr: + _extends: Expr + +DotSyntaxBaseIgnoredExpr: + _extends: Expr + +DynamicTypeExpr: + _extends: Expr + +EditorPlaceholderExpr: + _extends: Expr + +EnumIsCaseExpr: + _extends: Expr + +ErrorExpr: + _extends: Expr + +ExplicitCastExpr: + _extends: Expr + sub_expr: Expr + +ForceValueExpr: + _extends: Expr + sub_expr: Expr + +IdentityExpr: + _extends: Expr + sub_expr: Expr + +IfExpr: + _extends: Expr + +ImplicitConversionExpr: + _extends: Expr + sub_expr: Expr + +InOutExpr: + _extends: Expr + sub_expr: Expr + +KeyPathApplicationExpr: + _extends: Expr + +KeyPathDotExpr: + _extends: Expr + +KeyPathExpr: + _extends: Expr + parsed_root: Expr? + parsed_path: Expr? + +LazyInitializerExpr: + _extends: Expr + +LiteralExpr: + _extends: Expr + +LookupExpr: + _extends: Expr + +MakeTemporarilyEscapableExpr: + _extends: Expr + +ObjCSelectorExpr: + _extends: Expr + +OneWayExpr: + _extends: Expr + +OpaqueValueExpr: + _extends: Expr + +OpenExistentialExpr: + _extends: Expr + +OptionalEvaluationExpr: + _extends: Expr + +OtherConstructorDeclRefExpr: + _extends: Expr + +OverloadSetRefExpr: + _extends: Expr + +PropertyWrapperValuePlaceholderExpr: + _extends: Expr + +RebindSelfInConstructorExpr: + _extends: Expr + +SequenceExpr: + _extends: Expr + +SuperRefExpr: + _extends: Expr + +TapExpr: + _extends: Expr + sub_expr: Expr? + var: VarDecl + body: BraceStmt + +TupleElementExpr: + _extends: Expr + +TupleExpr: + _extends: Expr + elements: Expr* + +TypeExpr: + _extends: Expr + type_repr: UnknownAstNode? + +UnresolvedDeclRefExpr: + _extends: Expr + +UnresolvedDotExpr: + _extends: Expr + +UnresolvedMemberExpr: + _extends: Expr + +UnresolvedPatternExpr: + _extends: Expr + +UnresolvedSpecializeExpr: + _extends: Expr + +VarargExpansionExpr: + _extends: Expr + sub_expr: Expr + +AnyPattern: + _extends: Pattern + +BindingPattern: + _extends: Pattern + sub_pattern: Pattern + +BoolPattern: + _extends: Pattern + value: boolean + +EnumElementPattern: + _extends: Pattern + element: EnumElementDecl + sub_pattern: Pattern? + +ExprPattern: + _extends: Pattern + sub_expr: Expr + +IsPattern: + _extends: Pattern + cast_type_repr: TypeRepr + sub_pattern: Pattern? + +NamedPattern: + _extends: Pattern + name: string + +OptionalSomePattern: + _extends: Pattern + sub_pattern: Pattern + +ParenPattern: + _extends: Pattern + sub_pattern: Pattern + +TuplePattern: + _extends: Pattern + elements: Pattern* + +TypedPattern: + _extends: Pattern + sub_pattern: Pattern + type_repr: TypeRepr? + +BraceStmt: + _extends: Stmt + elements: AstNode* + +BreakStmt: + _extends: Stmt + target_name: string? + target: Stmt? + +CaseStmt: + _extends: Stmt + body: Stmt + labels: CaseLabelItem* + variables: VarDecl* + +CaseLabelItem: + _extends: AstNode + pattern: Pattern + guard: Expr? + _dir: stmt + +ContinueStmt: + _extends: Stmt + target_name: string? + target: Stmt? + +DeferStmt: + _extends: Stmt + body: BraceStmt + +FailStmt: + _extends: Stmt + +FallthroughStmt: + _extends: Stmt + fallthrough_source: CaseStmt + fallthrough_dest: CaseStmt + +LabeledStmt: + _extends: Stmt + label: string? + +PoundAssertStmt: + _extends: Stmt + +ReturnStmt: + _extends: Stmt + result: Expr? + +ThrowStmt: + _extends: Stmt + sub_expr: Expr + +YieldStmt: + _extends: Stmt + +BoundGenericType: + _extends: NominalOrBoundGenericNominalType + +NominalType: + _extends: NominalOrBoundGenericNominalType + +BuiltinIntegerLiteralType: + _extends: AnyBuiltinIntegerType + +BuiltinIntegerType: + _extends: AnyBuiltinIntegerType + +NestedArchetypeType: + _extends: ArchetypeType + +SequenceArchetypeType: + _extends: ArchetypeType + +OpaqueTypeArchetypeType: + _extends: ArchetypeType + +OpenedArchetypeType: + _extends: ArchetypeType + +PrimaryArchetypeType: + _extends: ArchetypeType + interface_type: GenericTypeParamType + +DictionaryType: + _extends: SyntaxSugarType + +UnarySyntaxSugarType: + _extends: SyntaxSugarType + +InfixOperatorDecl: + _extends: OperatorDecl + +PostfixOperatorDecl: + _extends: OperatorDecl + +PrefixOperatorDecl: + _extends: OperatorDecl + +AbstractFunctionDecl: + _extends: + - GenericContext + - ValueDecl + name: string + body: BraceStmt? + params: ParamDecl* + +AbstractStorageDecl: + _extends: ValueDecl + +EnumElementDecl: + _extends: ValueDecl + name: string + params: ParamDecl* + +TypeDecl: + _extends: ValueDecl + name: string + +AutoClosureExpr: + _extends: AbstractClosureExpr + +ClosureExpr: + _extends: AbstractClosureExpr + body: BraceStmt + +ForceTryExpr: + _extends: AnyTryExpr + +OptionalTryExpr: + _extends: AnyTryExpr + +TryExpr: + _extends: AnyTryExpr + +BinaryExpr: + _extends: ApplyExpr + +CallExpr: + _extends: ApplyExpr + +PostfixUnaryExpr: + _extends: ApplyExpr + +PrefixUnaryExpr: + _extends: ApplyExpr + +SelfApplyExpr: + _extends: ApplyExpr + base: Expr + +ArrayExpr: + _extends: CollectionExpr + elements: Expr* + +DictionaryExpr: + _extends: CollectionExpr + elements: Expr* + +CheckedCastExpr: + _extends: ExplicitCastExpr + +CoerceExpr: + _extends: ExplicitCastExpr + +AwaitExpr: + _extends: IdentityExpr + +DotSelfExpr: + _extends: IdentityExpr + +ParenExpr: + _extends: IdentityExpr + +UnresolvedMemberChainResultExpr: + _extends: IdentityExpr + +AnyHashableErasureExpr: + _extends: ImplicitConversionExpr + +ArchetypeToSuperExpr: + _extends: ImplicitConversionExpr + +ArrayToPointerExpr: + _extends: ImplicitConversionExpr + +BridgeFromObjCExpr: + _extends: ImplicitConversionExpr + +BridgeToObjCExpr: + _extends: ImplicitConversionExpr + +ClassMetatypeToObjectExpr: + _extends: ImplicitConversionExpr + +CollectionUpcastConversionExpr: + _extends: ImplicitConversionExpr + +ConditionalBridgeFromObjCExpr: + _extends: ImplicitConversionExpr + +CovariantFunctionConversionExpr: + _extends: ImplicitConversionExpr + +CovariantReturnConversionExpr: + _extends: ImplicitConversionExpr + +DerivedToBaseExpr: + _extends: ImplicitConversionExpr + +DestructureTupleExpr: + _extends: ImplicitConversionExpr + +DifferentiableFunctionExpr: + _extends: ImplicitConversionExpr + +DifferentiableFunctionExtractOriginalExpr: + _extends: ImplicitConversionExpr + +ErasureExpr: + _extends: ImplicitConversionExpr + +ExistentialMetatypeToObjectExpr: + _extends: ImplicitConversionExpr + +ForeignObjectConversionExpr: + _extends: ImplicitConversionExpr + +FunctionConversionExpr: + _extends: ImplicitConversionExpr + +InOutToPointerExpr: + _extends: ImplicitConversionExpr + +InjectIntoOptionalExpr: + _extends: ImplicitConversionExpr + +LinearFunctionExpr: + _extends: ImplicitConversionExpr + +LinearFunctionExtractOriginalExpr: + _extends: ImplicitConversionExpr + +LinearToDifferentiableFunctionExpr: + _extends: ImplicitConversionExpr + +LoadExpr: + _extends: ImplicitConversionExpr + +MetatypeConversionExpr: + _extends: ImplicitConversionExpr + +PointerToPointerExpr: + _extends: ImplicitConversionExpr + +ProtocolMetatypeToObjectExpr: + _extends: ImplicitConversionExpr + +StringToPointerExpr: + _extends: ImplicitConversionExpr + +UnderlyingToOpaqueExpr: + _extends: ImplicitConversionExpr + +UnevaluatedInstanceExpr: + _extends: ImplicitConversionExpr + +UnresolvedTypeConversionExpr: + _extends: ImplicitConversionExpr + +BuiltinLiteralExpr: + _extends: LiteralExpr + +InterpolatedStringLiteralExpr: + _extends: LiteralExpr + interpolation_expr: OpaqueValueExpr? + interpolation_count_expr: Expr? + literal_capacity_expr: Expr? + appending_expr: TapExpr? + +RegexLiteralExpr: + _extends: LiteralExpr + +NilLiteralExpr: + _extends: LiteralExpr + +ObjectLiteralExpr: + _extends: LiteralExpr + +DynamicLookupExpr: + _extends: LookupExpr + +MemberRefExpr: + _extends: LookupExpr + base_expr: Expr + +SubscriptExpr: + _extends: + - GenericContext + - LookupExpr + base_expr: Expr + arguments: Argument* + +OverloadedDeclRefExpr: + _extends: OverloadSetRefExpr + +DoCatchStmt: + _extends: LabeledStmt + body: Stmt + catches: CaseStmt* + +DoStmt: + _extends: LabeledStmt + body: BraceStmt + +ForEachStmt: + _extends: LabeledStmt + body: BraceStmt + where: Expr? + +LabeledConditionalStmt: + _extends: LabeledStmt + condition: StmtCondition + +StmtCondition: + _extends: AstNode + elements: ConditionElement* + _dir: stmt + +RepeatWhileStmt: + _extends: LabeledStmt + cond: Expr + body: Stmt + +SwitchStmt: + _extends: LabeledStmt + subject_expr: Expr + cases: CaseStmt* + +BoundGenericClassType: + _extends: BoundGenericType + +BoundGenericEnumType: + _extends: BoundGenericType + +BoundGenericStructType: + _extends: BoundGenericType + +ClassType: + _extends: NominalType + decl: ClassDecl + +EnumType: + _extends: NominalType + +ProtocolType: + _extends: NominalType + +StructType: + _extends: NominalType + decl: StructDecl + +ArraySliceType: + _extends: UnarySyntaxSugarType + +OptionalType: + _extends: UnarySyntaxSugarType + +VariadicSequenceType: + _extends: UnarySyntaxSugarType + +ConstructorDecl: + _extends: AbstractFunctionDecl + +DestructorDecl: + _extends: AbstractFunctionDecl + +FuncDecl: + _extends: AbstractFunctionDecl + +SubscriptDecl: + _extends: AbstractStorageDecl + +VarDecl: + _extends: AbstractStorageDecl + name: string + type: Type + +AbstractTypeParamDecl: + _extends: TypeDecl + +GenericContext: + generic_type_params: GenericTypeParamDecl* + +GenericTypeDecl: + _extends: + - GenericContext + - TypeDecl + +ModuleDecl: + _extends: TypeDecl + +ConstructorRefCallExpr: + _extends: SelfApplyExpr + +DotSyntaxCallExpr: + _extends: SelfApplyExpr + +ConditionalCheckedCastExpr: + _extends: CheckedCastExpr + +ForcedCheckedCastExpr: + _extends: CheckedCastExpr + +IsExpr: + _extends: CheckedCastExpr + +BooleanLiteralExpr: + _extends: BuiltinLiteralExpr + value: boolean + +MagicIdentifierLiteralExpr: + _extends: BuiltinLiteralExpr + kind: string + +NumberLiteralExpr: + _extends: BuiltinLiteralExpr + +StringLiteralExpr: + _extends: BuiltinLiteralExpr + value: string + +DynamicMemberRefExpr: + _extends: DynamicLookupExpr + +DynamicSubscriptExpr: + _extends: DynamicLookupExpr + +GuardStmt: + _extends: LabeledConditionalStmt + body: BraceStmt + +IfStmt: + _extends: LabeledConditionalStmt + then: Stmt + else: Stmt? + +WhileStmt: + _extends: LabeledConditionalStmt + body: Stmt + +AccessorDecl: + _extends: FuncDecl + +ConcreteFuncDecl: + _extends: FuncDecl + +ConcreteVarDecl: + _extends: VarDecl + introducer_int: int + +ParamDecl: + _extends: VarDecl + +AssociatedTypeDecl: + _extends: AbstractTypeParamDecl + +GenericTypeParamDecl: + _extends: AbstractTypeParamDecl + +OpaqueTypeDecl: + _extends: GenericTypeDecl + +TypeAliasDecl: + _extends: GenericTypeDecl + +FloatLiteralExpr: + _extends: NumberLiteralExpr + string_value: string + +IntegerLiteralExpr: + _extends: NumberLiteralExpr + string_value: string diff --git a/swift/ql/lib/swift.dbscheme b/swift/ql/lib/swift.dbscheme index 3022d88cce0..994523f8c94 100644 --- a/swift/ql/lib/swift.dbscheme +++ b/swift/ql/lib/swift.dbscheme @@ -1,7 +1,1860 @@ +// generated by codegen/codegen.py + +// from codegen/prefix.dbscheme +/** + * The source location of the snapshot. + */ sourceLocationPrefix( - string prefix: string ref + string prefix: string ref ); -answer_to_life_the_universe_and_everything( - int answer: int ref -) + +// from codegen/schema.yml + +files( + unique int id: @file, + string name: string ref +); + +@iterable_decl_context = + @extension_decl +| @nominal_type_decl +; + +#keyset[id, index] +iterable_decl_context_members( + int id: @iterable_decl_context ref, + int index: int ref, + int member: @decl ref +); + +@locatable = + @ast_node +| @condition_element +; + +#keyset[id] +locatables( + int id: @locatable ref, + int location: @location ref +); + +locations( + unique int id: @location, + int file: @file ref, + int begin_line: int ref, + int begin_column: int ref, + int end_line: int ref, + int end_column: int ref +); + +@type = + @any_function_type +| @any_generic_type +| @any_metatype_type +| @builtin_type +| @dependent_member_type +| @dynamic_self_type +| @error_type +| @existential_type +| @in_out_type +| @l_value_type +| @module_type +| @placeholder_type +| @protocol_composition_type +| @reference_storage_type +| @sil_block_storage_type +| @sil_box_type +| @sil_function_type +| @sil_token_type +| @substitutable_type +| @sugar_type +| @tuple_type +| @type_variable_type +| @unknown_type +| @unresolved_type +; + +#keyset[id] +types( + int id: @type ref, + string diagnostics_name: string ref, + int canonical_type: @type ref +); + +extension_decls( + unique int id: @extension_decl +); + +@nominal_type_decl = + @class_decl +| @enum_decl +| @protocol_decl +| @struct_decl +; + +#keyset[id] +nominal_type_decls( + int id: @nominal_type_decl ref, + int type_: @type ref +); + +@ast_node = + @case_label_item +| @decl +| @expr +| @pattern +| @stmt +| @stmt_condition +| @type_repr +; + +condition_elements( + unique int id: @condition_element +); + +#keyset[id] +condition_element_booleans( + int id: @condition_element ref, + int boolean_: @expr ref +); + +#keyset[id] +condition_element_patterns( + int id: @condition_element ref, + int pattern: @pattern ref +); + +#keyset[id] +condition_element_initializers( + int id: @condition_element ref, + int initializer: @expr ref +); + +@any_function_type = + @function_type +| @generic_function_type +; + +#keyset[id] +any_function_types( + int id: @any_function_type ref, + int result: @type ref +); + +#keyset[id, index] +any_function_type_param_types( + int id: @any_function_type ref, + int index: int ref, + int param_type: @type ref +); + +#keyset[id, index] +any_function_type_param_labels( + int id: @any_function_type ref, + int index: int ref, + string param_label: string ref +); + +@any_generic_type = + @nominal_or_bound_generic_nominal_type +| @unbound_generic_type +; + +#keyset[id] +any_generic_types( + int id: @any_generic_type ref, + int declaration: @decl ref +); + +#keyset[id] +any_generic_type_parents( + int id: @any_generic_type ref, + int parent: @type ref +); + +@any_metatype_type = + @existential_metatype_type +| @metatype_type +; + +@builtin_type = + @any_builtin_integer_type +| @builtin_bridge_object_type +| @builtin_default_actor_storage_type +| @builtin_executor_type +| @builtin_float_type +| @builtin_job_type +| @builtin_native_object_type +| @builtin_raw_pointer_type +| @builtin_raw_unsafe_continuation_type +| @builtin_unsafe_value_buffer_type +| @builtin_vector_type +; + +dependent_member_types( + unique int id: @dependent_member_type +); + +dynamic_self_types( + unique int id: @dynamic_self_type +); + +error_types( + unique int id: @error_type +); + +in_out_types( + unique int id: @in_out_type +); + +l_value_types( + unique int id: @l_value_type, + int object_type: @type ref +); + +module_types( + unique int id: @module_type +); + +placeholder_types( + unique int id: @placeholder_type +); + +protocol_composition_types( + unique int id: @protocol_composition_type +); + +existential_types( + unique int id: @existential_type +); + +@reference_storage_type = + @unmanaged_storage_type +| @unowned_storage_type +| @weak_storage_type +; + +sil_block_storage_types( + unique int id: @sil_block_storage_type +); + +sil_box_types( + unique int id: @sil_box_type +); + +sil_function_types( + unique int id: @sil_function_type +); + +sil_token_types( + unique int id: @sil_token_type +); + +@substitutable_type = + @archetype_type +| @generic_type_param_type +; + +@sugar_type = + @paren_type +| @syntax_sugar_type +| @type_alias_type +; + +tuple_types( + unique int id: @tuple_type +); + +type_variable_types( + unique int id: @type_variable_type +); + +unknown_types( + unique int id: @unknown_type, + string name: string ref +); + +unresolved_types( + unique int id: @unresolved_type +); + +class_decls( + unique int id: @class_decl +); + +enum_decls( + unique int id: @enum_decl +); + +protocol_decls( + unique int id: @protocol_decl +); + +struct_decls( + unique int id: @struct_decl +); + +@decl = + @enum_case_decl +| @extension_decl +| @if_config_decl +| @import_decl +| @missing_member_decl +| @operator_decl +| @pattern_binding_decl +| @pound_diagnostic_decl +| @precedence_group_decl +| @top_level_code_decl +| @unknown_ast_node +| @value_decl +; + +@expr = + @abstract_closure_expr +| @any_try_expr +| @applied_property_wrapper_expr +| @apply_expr +| @arrow_expr +| @assign_expr +| @bind_optional_expr +| @capture_list_expr +| @code_completion_expr +| @collection_expr +| @decl_ref_expr +| @default_argument_expr +| @discard_assignment_expr +| @dot_syntax_base_ignored_expr +| @dynamic_type_expr +| @editor_placeholder_expr +| @enum_is_case_expr +| @error_expr +| @explicit_cast_expr +| @force_value_expr +| @identity_expr +| @if_expr +| @implicit_conversion_expr +| @in_out_expr +| @key_path_application_expr +| @key_path_dot_expr +| @key_path_expr +| @lazy_initializer_expr +| @literal_expr +| @lookup_expr +| @make_temporarily_escapable_expr +| @obj_c_selector_expr +| @one_way_expr +| @opaque_value_expr +| @open_existential_expr +| @optional_evaluation_expr +| @other_constructor_decl_ref_expr +| @overload_set_ref_expr +| @property_wrapper_value_placeholder_expr +| @rebind_self_in_constructor_expr +| @sequence_expr +| @super_ref_expr +| @tap_expr +| @tuple_element_expr +| @tuple_expr +| @type_expr +| @unknown_ast_node +| @unresolved_decl_ref_expr +| @unresolved_dot_expr +| @unresolved_member_expr +| @unresolved_pattern_expr +| @unresolved_specialize_expr +| @vararg_expansion_expr +; + +#keyset[id] +expr_types( + int id: @expr ref, + int type_: @type ref +); + +@pattern = + @any_pattern +| @binding_pattern +| @bool_pattern +| @enum_element_pattern +| @expr_pattern +| @is_pattern +| @named_pattern +| @optional_some_pattern +| @paren_pattern +| @tuple_pattern +| @typed_pattern +| @unknown_ast_node +; + +@stmt = + @brace_stmt +| @break_stmt +| @case_stmt +| @continue_stmt +| @defer_stmt +| @fail_stmt +| @fallthrough_stmt +| @labeled_stmt +| @pound_assert_stmt +| @return_stmt +| @throw_stmt +| @unknown_ast_node +| @yield_stmt +; + +@type_repr = + @unknown_ast_node +; + +function_types( + unique int id: @function_type +); + +generic_function_types( + unique int id: @generic_function_type +); + +#keyset[id, index] +generic_function_type_generic_params( + int id: @generic_function_type ref, + int index: int ref, + int generic_param: @generic_type_param_type ref +); + +@nominal_or_bound_generic_nominal_type = + @bound_generic_type +| @nominal_type +; + +unbound_generic_types( + unique int id: @unbound_generic_type +); + +existential_metatype_types( + unique int id: @existential_metatype_type +); + +metatype_types( + unique int id: @metatype_type +); + +@any_builtin_integer_type = + @builtin_integer_literal_type +| @builtin_integer_type +; + +builtin_bridge_object_types( + unique int id: @builtin_bridge_object_type +); + +builtin_default_actor_storage_types( + unique int id: @builtin_default_actor_storage_type +); + +builtin_executor_types( + unique int id: @builtin_executor_type +); + +builtin_float_types( + unique int id: @builtin_float_type +); + +builtin_job_types( + unique int id: @builtin_job_type +); + +builtin_native_object_types( + unique int id: @builtin_native_object_type +); + +builtin_raw_pointer_types( + unique int id: @builtin_raw_pointer_type +); + +builtin_raw_unsafe_continuation_types( + unique int id: @builtin_raw_unsafe_continuation_type +); + +builtin_unsafe_value_buffer_types( + unique int id: @builtin_unsafe_value_buffer_type +); + +builtin_vector_types( + unique int id: @builtin_vector_type +); + +unmanaged_storage_types( + unique int id: @unmanaged_storage_type +); + +unowned_storage_types( + unique int id: @unowned_storage_type +); + +weak_storage_types( + unique int id: @weak_storage_type +); + +@archetype_type = + @nested_archetype_type +| @opaque_type_archetype_type +| @opened_archetype_type +| @primary_archetype_type +| @sequence_archetype_type +; + +generic_type_param_types( + unique int id: @generic_type_param_type, + string name: string ref +); + +paren_types( + unique int id: @paren_type +); + +@syntax_sugar_type = + @dictionary_type +| @unary_syntax_sugar_type +; + +type_alias_types( + unique int id: @type_alias_type +); + +enum_case_decls( + unique int id: @enum_case_decl +); + +#keyset[id, index] +enum_case_decl_elements( + int id: @enum_case_decl ref, + int index: int ref, + int element: @enum_element_decl ref +); + +if_config_decls( + unique int id: @if_config_decl +); + +import_decls( + unique int id: @import_decl +); + +missing_member_decls( + unique int id: @missing_member_decl +); + +@operator_decl = + @infix_operator_decl +| @postfix_operator_decl +| @prefix_operator_decl +; + +pattern_binding_decls( + unique int id: @pattern_binding_decl +); + +#keyset[id, index] +pattern_binding_decl_inits( + int id: @pattern_binding_decl ref, + int index: int ref, + int init: @expr ref +); + +#keyset[id, index] +pattern_binding_decl_patterns( + int id: @pattern_binding_decl ref, + int index: int ref, + int pattern: @pattern ref +); + +pound_diagnostic_decls( + unique int id: @pound_diagnostic_decl +); + +precedence_group_decls( + unique int id: @precedence_group_decl +); + +top_level_code_decls( + unique int id: @top_level_code_decl, + int body: @brace_stmt ref +); + +unknown_ast_nodes( + unique int id: @unknown_ast_node, + string name: string ref +); + +@value_decl = + @abstract_function_decl +| @abstract_storage_decl +| @enum_element_decl +| @type_decl +; + +#keyset[id] +value_decls( + int id: @value_decl ref, + int interface_type: @type ref +); + +@abstract_closure_expr = + @auto_closure_expr +| @closure_expr +; + +@any_try_expr = + @force_try_expr +| @optional_try_expr +| @try_expr +; + +#keyset[id] +any_try_exprs( + int id: @any_try_expr ref, + int sub_expr: @expr ref +); + +applied_property_wrapper_exprs( + unique int id: @applied_property_wrapper_expr +); + +arguments( + unique int id: @argument, + string label: string ref, + int expr: @expr ref +); + +@apply_expr = + @binary_expr +| @call_expr +| @postfix_unary_expr +| @prefix_unary_expr +| @self_apply_expr +; + +#keyset[id] +apply_exprs( + int id: @apply_expr ref, + int function: @expr ref +); + +#keyset[id, index] +apply_expr_arguments( + int id: @apply_expr ref, + int index: int ref, + int argument: @argument ref +); + +arrow_exprs( + unique int id: @arrow_expr +); + +assign_exprs( + unique int id: @assign_expr, + int dest: @expr ref, + int src: @expr ref +); + +bind_optional_exprs( + unique int id: @bind_optional_expr +); + +capture_list_exprs( + unique int id: @capture_list_expr +); + +code_completion_exprs( + unique int id: @code_completion_expr +); + +@collection_expr = + @array_expr +| @dictionary_expr +; + +decl_ref_exprs( + unique int id: @decl_ref_expr, + int decl: @decl ref +); + +#keyset[id, index] +decl_ref_expr_replacement_types( + int id: @decl_ref_expr ref, + int index: int ref, + int replacement_type: @type ref +); + +default_argument_exprs( + unique int id: @default_argument_expr, + int param_decl: @param_decl ref, + int param_index: int ref +); + +#keyset[id] +default_argument_expr_caller_side_defaults( + int id: @default_argument_expr ref, + int caller_side_default: @expr ref +); + +discard_assignment_exprs( + unique int id: @discard_assignment_expr +); + +dot_syntax_base_ignored_exprs( + unique int id: @dot_syntax_base_ignored_expr +); + +dynamic_type_exprs( + unique int id: @dynamic_type_expr +); + +editor_placeholder_exprs( + unique int id: @editor_placeholder_expr +); + +enum_is_case_exprs( + unique int id: @enum_is_case_expr +); + +error_exprs( + unique int id: @error_expr +); + +@explicit_cast_expr = + @checked_cast_expr +| @coerce_expr +; + +#keyset[id] +explicit_cast_exprs( + int id: @explicit_cast_expr ref, + int sub_expr: @expr ref +); + +force_value_exprs( + unique int id: @force_value_expr, + int sub_expr: @expr ref +); + +@identity_expr = + @await_expr +| @dot_self_expr +| @paren_expr +| @unresolved_member_chain_result_expr +; + +#keyset[id] +identity_exprs( + int id: @identity_expr ref, + int sub_expr: @expr ref +); + +if_exprs( + unique int id: @if_expr +); + +@implicit_conversion_expr = + @any_hashable_erasure_expr +| @archetype_to_super_expr +| @array_to_pointer_expr +| @bridge_from_obj_c_expr +| @bridge_to_obj_c_expr +| @class_metatype_to_object_expr +| @collection_upcast_conversion_expr +| @conditional_bridge_from_obj_c_expr +| @covariant_function_conversion_expr +| @covariant_return_conversion_expr +| @derived_to_base_expr +| @destructure_tuple_expr +| @differentiable_function_expr +| @differentiable_function_extract_original_expr +| @erasure_expr +| @existential_metatype_to_object_expr +| @foreign_object_conversion_expr +| @function_conversion_expr +| @in_out_to_pointer_expr +| @inject_into_optional_expr +| @linear_function_expr +| @linear_function_extract_original_expr +| @linear_to_differentiable_function_expr +| @load_expr +| @metatype_conversion_expr +| @pointer_to_pointer_expr +| @protocol_metatype_to_object_expr +| @string_to_pointer_expr +| @underlying_to_opaque_expr +| @unevaluated_instance_expr +| @unresolved_type_conversion_expr +; + +#keyset[id] +implicit_conversion_exprs( + int id: @implicit_conversion_expr ref, + int sub_expr: @expr ref +); + +in_out_exprs( + unique int id: @in_out_expr, + int sub_expr: @expr ref +); + +key_path_application_exprs( + unique int id: @key_path_application_expr +); + +key_path_dot_exprs( + unique int id: @key_path_dot_expr +); + +key_path_exprs( + unique int id: @key_path_expr +); + +#keyset[id] +key_path_expr_parsed_roots( + int id: @key_path_expr ref, + int parsed_root: @expr ref +); + +#keyset[id] +key_path_expr_parsed_paths( + int id: @key_path_expr ref, + int parsed_path: @expr ref +); + +lazy_initializer_exprs( + unique int id: @lazy_initializer_expr +); + +@literal_expr = + @builtin_literal_expr +| @interpolated_string_literal_expr +| @nil_literal_expr +| @object_literal_expr +| @regex_literal_expr +; + +@lookup_expr = + @dynamic_lookup_expr +| @member_ref_expr +| @subscript_expr +; + +make_temporarily_escapable_exprs( + unique int id: @make_temporarily_escapable_expr +); + +obj_c_selector_exprs( + unique int id: @obj_c_selector_expr +); + +one_way_exprs( + unique int id: @one_way_expr +); + +opaque_value_exprs( + unique int id: @opaque_value_expr +); + +open_existential_exprs( + unique int id: @open_existential_expr +); + +optional_evaluation_exprs( + unique int id: @optional_evaluation_expr +); + +other_constructor_decl_ref_exprs( + unique int id: @other_constructor_decl_ref_expr +); + +@overload_set_ref_expr = + @overloaded_decl_ref_expr +; + +property_wrapper_value_placeholder_exprs( + unique int id: @property_wrapper_value_placeholder_expr +); + +rebind_self_in_constructor_exprs( + unique int id: @rebind_self_in_constructor_expr +); + +sequence_exprs( + unique int id: @sequence_expr +); + +super_ref_exprs( + unique int id: @super_ref_expr +); + +tap_exprs( + unique int id: @tap_expr, + int var: @var_decl ref, + int body: @brace_stmt ref +); + +#keyset[id] +tap_expr_sub_exprs( + int id: @tap_expr ref, + int sub_expr: @expr ref +); + +tuple_element_exprs( + unique int id: @tuple_element_expr +); + +tuple_exprs( + unique int id: @tuple_expr +); + +#keyset[id, index] +tuple_expr_elements( + int id: @tuple_expr ref, + int index: int ref, + int element: @expr ref +); + +type_exprs( + unique int id: @type_expr +); + +#keyset[id] +type_expr_type_reprs( + int id: @type_expr ref, + int type_repr: @unknown_ast_node ref +); + +unresolved_decl_ref_exprs( + unique int id: @unresolved_decl_ref_expr +); + +unresolved_dot_exprs( + unique int id: @unresolved_dot_expr +); + +unresolved_member_exprs( + unique int id: @unresolved_member_expr +); + +unresolved_pattern_exprs( + unique int id: @unresolved_pattern_expr +); + +unresolved_specialize_exprs( + unique int id: @unresolved_specialize_expr +); + +vararg_expansion_exprs( + unique int id: @vararg_expansion_expr, + int sub_expr: @expr ref +); + +any_patterns( + unique int id: @any_pattern +); + +binding_patterns( + unique int id: @binding_pattern, + int sub_pattern: @pattern ref +); + +bool_patterns( + unique int id: @bool_pattern, + boolean value: boolean ref +); + +enum_element_patterns( + unique int id: @enum_element_pattern, + int element: @enum_element_decl ref +); + +#keyset[id] +enum_element_pattern_sub_patterns( + int id: @enum_element_pattern ref, + int sub_pattern: @pattern ref +); + +expr_patterns( + unique int id: @expr_pattern, + int sub_expr: @expr ref +); + +is_patterns( + unique int id: @is_pattern, + int cast_type_repr: @type_repr ref +); + +#keyset[id] +is_pattern_sub_patterns( + int id: @is_pattern ref, + int sub_pattern: @pattern ref +); + +named_patterns( + unique int id: @named_pattern, + string name: string ref +); + +optional_some_patterns( + unique int id: @optional_some_pattern, + int sub_pattern: @pattern ref +); + +paren_patterns( + unique int id: @paren_pattern, + int sub_pattern: @pattern ref +); + +tuple_patterns( + unique int id: @tuple_pattern +); + +#keyset[id, index] +tuple_pattern_elements( + int id: @tuple_pattern ref, + int index: int ref, + int element: @pattern ref +); + +typed_patterns( + unique int id: @typed_pattern, + int sub_pattern: @pattern ref +); + +#keyset[id] +typed_pattern_type_reprs( + int id: @typed_pattern ref, + int type_repr: @type_repr ref +); + +brace_stmts( + unique int id: @brace_stmt +); + +#keyset[id, index] +brace_stmt_elements( + int id: @brace_stmt ref, + int index: int ref, + int element: @ast_node ref +); + +break_stmts( + unique int id: @break_stmt +); + +#keyset[id] +break_stmt_target_names( + int id: @break_stmt ref, + string target_name: string ref +); + +#keyset[id] +break_stmt_targets( + int id: @break_stmt ref, + int target: @stmt ref +); + +case_stmts( + unique int id: @case_stmt, + int body: @stmt ref +); + +#keyset[id, index] +case_stmt_labels( + int id: @case_stmt ref, + int index: int ref, + int label: @case_label_item ref +); + +#keyset[id, index] +case_stmt_variables( + int id: @case_stmt ref, + int index: int ref, + int variable: @var_decl ref +); + +case_label_items( + unique int id: @case_label_item, + int pattern: @pattern ref +); + +#keyset[id] +case_label_item_guards( + int id: @case_label_item ref, + int guard: @expr ref +); + +continue_stmts( + unique int id: @continue_stmt +); + +#keyset[id] +continue_stmt_target_names( + int id: @continue_stmt ref, + string target_name: string ref +); + +#keyset[id] +continue_stmt_targets( + int id: @continue_stmt ref, + int target: @stmt ref +); + +defer_stmts( + unique int id: @defer_stmt, + int body: @brace_stmt ref +); + +fail_stmts( + unique int id: @fail_stmt +); + +fallthrough_stmts( + unique int id: @fallthrough_stmt, + int fallthrough_source: @case_stmt ref, + int fallthrough_dest: @case_stmt ref +); + +@labeled_stmt = + @do_catch_stmt +| @do_stmt +| @for_each_stmt +| @labeled_conditional_stmt +| @repeat_while_stmt +| @switch_stmt +; + +#keyset[id] +labeled_stmt_labels( + int id: @labeled_stmt ref, + string label: string ref +); + +pound_assert_stmts( + unique int id: @pound_assert_stmt +); + +return_stmts( + unique int id: @return_stmt +); + +#keyset[id] +return_stmt_results( + int id: @return_stmt ref, + int result: @expr ref +); + +throw_stmts( + unique int id: @throw_stmt, + int sub_expr: @expr ref +); + +yield_stmts( + unique int id: @yield_stmt +); + +@bound_generic_type = + @bound_generic_class_type +| @bound_generic_enum_type +| @bound_generic_struct_type +; + +@nominal_type = + @class_type +| @enum_type +| @protocol_type +| @struct_type +; + +builtin_integer_literal_types( + unique int id: @builtin_integer_literal_type +); + +builtin_integer_types( + unique int id: @builtin_integer_type +); + +nested_archetype_types( + unique int id: @nested_archetype_type +); + +sequence_archetype_types( + unique int id: @sequence_archetype_type +); + +opaque_type_archetype_types( + unique int id: @opaque_type_archetype_type +); + +opened_archetype_types( + unique int id: @opened_archetype_type +); + +primary_archetype_types( + unique int id: @primary_archetype_type, + int interface_type: @generic_type_param_type ref +); + +dictionary_types( + unique int id: @dictionary_type +); + +@unary_syntax_sugar_type = + @array_slice_type +| @optional_type +| @variadic_sequence_type +; + +infix_operator_decls( + unique int id: @infix_operator_decl +); + +postfix_operator_decls( + unique int id: @postfix_operator_decl +); + +prefix_operator_decls( + unique int id: @prefix_operator_decl +); + +@abstract_function_decl = + @constructor_decl +| @destructor_decl +| @func_decl +; + +#keyset[id] +abstract_function_decls( + int id: @abstract_function_decl ref, + string name: string ref +); + +#keyset[id] +abstract_function_decl_bodies( + int id: @abstract_function_decl ref, + int body: @brace_stmt ref +); + +#keyset[id, index] +abstract_function_decl_params( + int id: @abstract_function_decl ref, + int index: int ref, + int param: @param_decl ref +); + +@abstract_storage_decl = + @subscript_decl +| @var_decl +; + +enum_element_decls( + unique int id: @enum_element_decl, + string name: string ref +); + +#keyset[id, index] +enum_element_decl_params( + int id: @enum_element_decl ref, + int index: int ref, + int param: @param_decl ref +); + +@type_decl = + @abstract_type_param_decl +| @generic_type_decl +| @module_decl +; + +#keyset[id] +type_decls( + int id: @type_decl ref, + string name: string ref +); + +auto_closure_exprs( + unique int id: @auto_closure_expr +); + +closure_exprs( + unique int id: @closure_expr, + int body: @brace_stmt ref +); + +force_try_exprs( + unique int id: @force_try_expr +); + +optional_try_exprs( + unique int id: @optional_try_expr +); + +try_exprs( + unique int id: @try_expr +); + +binary_exprs( + unique int id: @binary_expr +); + +call_exprs( + unique int id: @call_expr +); + +postfix_unary_exprs( + unique int id: @postfix_unary_expr +); + +prefix_unary_exprs( + unique int id: @prefix_unary_expr +); + +@self_apply_expr = + @constructor_ref_call_expr +| @dot_syntax_call_expr +; + +#keyset[id] +self_apply_exprs( + int id: @self_apply_expr ref, + int base: @expr ref +); + +array_exprs( + unique int id: @array_expr +); + +#keyset[id, index] +array_expr_elements( + int id: @array_expr ref, + int index: int ref, + int element: @expr ref +); + +dictionary_exprs( + unique int id: @dictionary_expr +); + +#keyset[id, index] +dictionary_expr_elements( + int id: @dictionary_expr ref, + int index: int ref, + int element: @expr ref +); + +@checked_cast_expr = + @conditional_checked_cast_expr +| @forced_checked_cast_expr +| @is_expr +; + +coerce_exprs( + unique int id: @coerce_expr +); + +await_exprs( + unique int id: @await_expr +); + +dot_self_exprs( + unique int id: @dot_self_expr +); + +paren_exprs( + unique int id: @paren_expr +); + +unresolved_member_chain_result_exprs( + unique int id: @unresolved_member_chain_result_expr +); + +any_hashable_erasure_exprs( + unique int id: @any_hashable_erasure_expr +); + +archetype_to_super_exprs( + unique int id: @archetype_to_super_expr +); + +array_to_pointer_exprs( + unique int id: @array_to_pointer_expr +); + +bridge_from_obj_c_exprs( + unique int id: @bridge_from_obj_c_expr +); + +bridge_to_obj_c_exprs( + unique int id: @bridge_to_obj_c_expr +); + +class_metatype_to_object_exprs( + unique int id: @class_metatype_to_object_expr +); + +collection_upcast_conversion_exprs( + unique int id: @collection_upcast_conversion_expr +); + +conditional_bridge_from_obj_c_exprs( + unique int id: @conditional_bridge_from_obj_c_expr +); + +covariant_function_conversion_exprs( + unique int id: @covariant_function_conversion_expr +); + +covariant_return_conversion_exprs( + unique int id: @covariant_return_conversion_expr +); + +derived_to_base_exprs( + unique int id: @derived_to_base_expr +); + +destructure_tuple_exprs( + unique int id: @destructure_tuple_expr +); + +differentiable_function_exprs( + unique int id: @differentiable_function_expr +); + +differentiable_function_extract_original_exprs( + unique int id: @differentiable_function_extract_original_expr +); + +erasure_exprs( + unique int id: @erasure_expr +); + +existential_metatype_to_object_exprs( + unique int id: @existential_metatype_to_object_expr +); + +foreign_object_conversion_exprs( + unique int id: @foreign_object_conversion_expr +); + +function_conversion_exprs( + unique int id: @function_conversion_expr +); + +in_out_to_pointer_exprs( + unique int id: @in_out_to_pointer_expr +); + +inject_into_optional_exprs( + unique int id: @inject_into_optional_expr +); + +linear_function_exprs( + unique int id: @linear_function_expr +); + +linear_function_extract_original_exprs( + unique int id: @linear_function_extract_original_expr +); + +linear_to_differentiable_function_exprs( + unique int id: @linear_to_differentiable_function_expr +); + +load_exprs( + unique int id: @load_expr +); + +metatype_conversion_exprs( + unique int id: @metatype_conversion_expr +); + +pointer_to_pointer_exprs( + unique int id: @pointer_to_pointer_expr +); + +protocol_metatype_to_object_exprs( + unique int id: @protocol_metatype_to_object_expr +); + +string_to_pointer_exprs( + unique int id: @string_to_pointer_expr +); + +underlying_to_opaque_exprs( + unique int id: @underlying_to_opaque_expr +); + +unevaluated_instance_exprs( + unique int id: @unevaluated_instance_expr +); + +unresolved_type_conversion_exprs( + unique int id: @unresolved_type_conversion_expr +); + +@builtin_literal_expr = + @boolean_literal_expr +| @magic_identifier_literal_expr +| @number_literal_expr +| @string_literal_expr +; + +interpolated_string_literal_exprs( + unique int id: @interpolated_string_literal_expr +); + +#keyset[id] +interpolated_string_literal_expr_interpolation_exprs( + int id: @interpolated_string_literal_expr ref, + int interpolation_expr: @opaque_value_expr ref +); + +#keyset[id] +interpolated_string_literal_expr_interpolation_count_exprs( + int id: @interpolated_string_literal_expr ref, + int interpolation_count_expr: @expr ref +); + +#keyset[id] +interpolated_string_literal_expr_literal_capacity_exprs( + int id: @interpolated_string_literal_expr ref, + int literal_capacity_expr: @expr ref +); + +#keyset[id] +interpolated_string_literal_expr_appending_exprs( + int id: @interpolated_string_literal_expr ref, + int appending_expr: @tap_expr ref +); + +regex_literal_exprs( + unique int id: @regex_literal_expr +); + +nil_literal_exprs( + unique int id: @nil_literal_expr +); + +object_literal_exprs( + unique int id: @object_literal_expr +); + +@dynamic_lookup_expr = + @dynamic_member_ref_expr +| @dynamic_subscript_expr +; + +member_ref_exprs( + unique int id: @member_ref_expr, + int base_expr: @expr ref +); + +subscript_exprs( + unique int id: @subscript_expr, + int base_expr: @expr ref +); + +#keyset[id, index] +subscript_expr_arguments( + int id: @subscript_expr ref, + int index: int ref, + int argument: @argument ref +); + +overloaded_decl_ref_exprs( + unique int id: @overloaded_decl_ref_expr +); + +do_catch_stmts( + unique int id: @do_catch_stmt, + int body: @stmt ref +); + +#keyset[id, index] +do_catch_stmt_catches( + int id: @do_catch_stmt ref, + int index: int ref, + int catch: @case_stmt ref +); + +do_stmts( + unique int id: @do_stmt, + int body: @brace_stmt ref +); + +for_each_stmts( + unique int id: @for_each_stmt, + int body: @brace_stmt ref +); + +#keyset[id] +for_each_stmt_wheres( + int id: @for_each_stmt ref, + int where: @expr ref +); + +@labeled_conditional_stmt = + @guard_stmt +| @if_stmt +| @while_stmt +; + +#keyset[id] +labeled_conditional_stmts( + int id: @labeled_conditional_stmt ref, + int condition: @stmt_condition ref +); + +stmt_conditions( + unique int id: @stmt_condition +); + +#keyset[id, index] +stmt_condition_elements( + int id: @stmt_condition ref, + int index: int ref, + int element: @condition_element ref +); + +repeat_while_stmts( + unique int id: @repeat_while_stmt, + int cond: @expr ref, + int body: @stmt ref +); + +switch_stmts( + unique int id: @switch_stmt, + int subject_expr: @expr ref +); + +#keyset[id, index] +switch_stmt_cases( + int id: @switch_stmt ref, + int index: int ref, + int case_: @case_stmt ref +); + +bound_generic_class_types( + unique int id: @bound_generic_class_type +); + +bound_generic_enum_types( + unique int id: @bound_generic_enum_type +); + +bound_generic_struct_types( + unique int id: @bound_generic_struct_type +); + +class_types( + unique int id: @class_type, + int decl: @class_decl ref +); + +enum_types( + unique int id: @enum_type +); + +protocol_types( + unique int id: @protocol_type +); + +struct_types( + unique int id: @struct_type, + int decl: @struct_decl ref +); + +array_slice_types( + unique int id: @array_slice_type +); + +optional_types( + unique int id: @optional_type +); + +variadic_sequence_types( + unique int id: @variadic_sequence_type +); + +constructor_decls( + unique int id: @constructor_decl +); + +destructor_decls( + unique int id: @destructor_decl +); + +@func_decl = + @accessor_decl +| @concrete_func_decl +; + +subscript_decls( + unique int id: @subscript_decl +); + +@var_decl = + @concrete_var_decl +| @param_decl +; + +#keyset[id] +var_decls( + int id: @var_decl ref, + string name: string ref, + int type_: @type ref +); + +@abstract_type_param_decl = + @associated_type_decl +| @generic_type_param_decl +; + +@generic_context = + @abstract_function_decl +| @extension_decl +| @generic_type_decl +| @subscript_expr +; + +#keyset[id, index] +generic_context_generic_type_params( + int id: @generic_context ref, + int index: int ref, + int generic_type_param: @generic_type_param_decl ref +); + +@generic_type_decl = + @nominal_type_decl +| @opaque_type_decl +| @type_alias_decl +; + +module_decls( + unique int id: @module_decl +); + +constructor_ref_call_exprs( + unique int id: @constructor_ref_call_expr +); + +dot_syntax_call_exprs( + unique int id: @dot_syntax_call_expr +); + +conditional_checked_cast_exprs( + unique int id: @conditional_checked_cast_expr +); + +forced_checked_cast_exprs( + unique int id: @forced_checked_cast_expr +); + +is_exprs( + unique int id: @is_expr +); + +boolean_literal_exprs( + unique int id: @boolean_literal_expr, + boolean value: boolean ref +); + +magic_identifier_literal_exprs( + unique int id: @magic_identifier_literal_expr, + string kind: string ref +); + +@number_literal_expr = + @float_literal_expr +| @integer_literal_expr +; + +string_literal_exprs( + unique int id: @string_literal_expr, + string value: string ref +); + +dynamic_member_ref_exprs( + unique int id: @dynamic_member_ref_expr +); + +dynamic_subscript_exprs( + unique int id: @dynamic_subscript_expr +); + +guard_stmts( + unique int id: @guard_stmt, + int body: @brace_stmt ref +); + +if_stmts( + unique int id: @if_stmt, + int then: @stmt ref +); + +#keyset[id] +if_stmt_elses( + int id: @if_stmt ref, + int else: @stmt ref +); + +while_stmts( + unique int id: @while_stmt, + int body: @stmt ref +); + +accessor_decls( + unique int id: @accessor_decl +); + +concrete_func_decls( + unique int id: @concrete_func_decl +); + +concrete_var_decls( + unique int id: @concrete_var_decl, + int introducer_int: int ref +); + +param_decls( + unique int id: @param_decl +); + +associated_type_decls( + unique int id: @associated_type_decl +); + +generic_type_param_decls( + unique int id: @generic_type_param_decl +); + +opaque_type_decls( + unique int id: @opaque_type_decl +); + +type_alias_decls( + unique int id: @type_alias_decl +); + +float_literal_exprs( + unique int id: @float_literal_expr, + string string_value: string ref +); + +integer_literal_exprs( + unique int id: @integer_literal_expr, + string string_value: string ref +); + +@element = + @argument +| @file +| @generic_context +| @iterable_decl_context +| @locatable +| @location +| @type +;