From afd4d5635bf590bbfd364e7ac9bbb9f98d571c30 Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Thu, 5 Dec 2024 17:19:40 +0100 Subject: [PATCH 01/10] Rust: first draft of canonical paths rework --- misc/codegen/generators/rustgen.py | 23 +- misc/codegen/loaders/schemaloader.py | 9 +- rust/extractor/src/generated/.generated.list | 3 +- rust/extractor/src/generated/.gitattributes | 1 - rust/extractor/src/generated/mod.rs | 11458 +++++++++++++++- rust/extractor/src/generated/top.rs | 10600 -------------- rust/extractor/src/rust_analyzer.rs | 7 +- rust/extractor/src/translate/base.rs | 458 +- rust/extractor/src/translate/mappings.rs | 25 - rust/extractor/src/trap.rs | 20 +- rust/ql/.generated.list | 147 +- rust/ql/.gitattributes | 81 +- rust/ql/lib/codeql/rust/elements.qll | 19 + .../lib/codeql/rust/elements/Addressable.qll | 1 + .../lib/codeql/rust/elements/Resolvable.qll | 1 + .../BuiltinTypeCanonicalPath.qll | 12 + .../canonical_paths/CanonicalPath.qll | 12 + .../canonical_paths/CanonicalPathElement.qll | 12 + .../ConcreteTypeCanonicalPath.qll | 13 + .../canonical_paths/ConstGenericTypeArg.qll | 12 + .../elements/canonical_paths/CrateRoot.qll | 12 + .../DerivedTypeCanonicalPath.qll | 12 + .../canonical_paths/ImplItemCanonicalPath.qll | 14 + .../canonical_paths/LangCrateRoot.qll | 12 + .../ModuleItemCanonicalPath.qll | 13 + .../elements/canonical_paths/Namespace.qll | 13 + .../ParametrizedCanonicalPath.qll | 11 + .../PlaceholderTypeCanonicalPath.qll | 12 + .../canonical_paths/RepoCrateRoot.qll | 13 + .../canonical_paths/RustcCrateRoot.qll | 12 + .../canonical_paths/TypeCanonicalPath.qll | 12 + .../canonical_paths/TypeGenericArg.qll | 12 + .../canonical_paths/TypeGenericTypeArg.qll | 13 + .../canonical_paths/TypeItemCanonicalPath.qll | 13 + .../BuiltinTypeCanonicalPathConstructor.qll | 14 + .../internal/BuiltinTypeCanonicalPathImpl.qll | 19 + .../internal/CanonicalPathElementImpl.qll | 21 + .../internal/CanonicalPathImpl.qll | 19 + .../ConcreteTypeCanonicalPathConstructor.qll | 14 + .../ConcreteTypeCanonicalPathImpl.qll | 21 + .../ConstGenericTypeArgConstructor.qll | 14 + .../internal/ConstGenericTypeArgImpl.qll | 23 + .../internal/CrateRootImpl.qll | 21 + .../DerivedTypeCanonicalPathConstructor.qll | 14 + .../internal/DerivedTypeCanonicalPathImpl.qll | 25 + .../ImplItemCanonicalPathConstructor.qll | 14 + .../internal/ImplItemCanonicalPathImpl.qll | 30 + .../internal/LangCrateRootConstructor.qll | 14 + .../internal/LangCrateRootImpl.qll | 21 + .../ModuleItemCanonicalPathConstructor.qll | 14 + .../internal/ModuleItemCanonicalPathImpl.qll | 23 + .../internal/NamespaceConstructor.qll | 14 + .../internal/NamespaceImpl.qll | 26 + .../ParametrizedCanonicalPathConstructor.qll | 14 + .../ParametrizedCanonicalPathImpl.qll | 30 + ...laceholderTypeCanonicalPathConstructor.qll | 14 + .../PlaceholderTypeCanonicalPathImpl.qll | 23 + .../internal/RepoCrateRootConstructor.qll | 14 + .../internal/RepoCrateRootImpl.qll | 25 + .../internal/RustcCrateRootConstructor.qll | 14 + .../internal/RustcCrateRootImpl.qll | 21 + .../internal/TypeCanonicalPathImpl.qll | 19 + .../internal/TypeGenericArgImpl.qll | 19 + .../TypeGenericTypeArgConstructor.qll | 14 + .../internal/TypeGenericTypeArgImpl.qll | 21 + .../TypeItemCanonicalPathConstructor.qll | 14 + .../internal/TypeItemCanonicalPathImpl.qll | 23 + .../rust/elements/internal/StructImpl.qll | 6 +- .../rust/elements/internal/VariantImpl.qll | 7 +- .../internal/generated/Addressable.qll | 19 + .../internal/generated/ParentChild.qll | 324 + .../rust/elements/internal/generated/Raw.qll | 263 + .../internal/generated/Resolvable.qll | 19 + .../elements/internal/generated/Synth.qll | 443 +- .../internal/generated/SynthConstructors.qll | 14 + .../BuiltinTypeCanonicalPath.qll | 34 + .../canonical_paths/CanonicalPath.qll | 23 + .../canonical_paths/CanonicalPathElement.qll | 22 + .../ConcreteTypeCanonicalPath.qll | 37 + .../canonical_paths/ConstGenericTypeArg.qll | 31 + .../generated/canonical_paths/CrateRoot.qll | 22 + .../DerivedTypeCanonicalPath.qll | 57 + .../canonical_paths/ImplItemCanonicalPath.qll | 60 + .../canonical_paths/LangCrateRoot.qll | 31 + .../ModuleItemCanonicalPath.qll | 45 + .../generated/canonical_paths/Namespace.qll | 38 + .../ParametrizedCanonicalPath.qll | 57 + .../PlaceholderTypeCanonicalPath.qll | 26 + .../canonical_paths/RepoCrateRoot.qll | 56 + .../canonical_paths/RustcCrateRoot.qll | 31 + .../canonical_paths/TypeCanonicalPath.qll | 22 + .../canonical_paths/TypeGenericArg.qll | 24 + .../canonical_paths/TypeGenericTypeArg.qll | 35 + .../canonical_paths/TypeItemCanonicalPath.qll | 44 + rust/ql/lib/rust.dbscheme | 153 +- .../canonical_path/canonical_paths.expected | 197 +- .../canonical_path/canonical_paths.ql | 30 +- .../extractor-tests/canonical_path/regular.rs | 56 + .../extractor-tests/generated/Const/Const.ql | 12 +- .../generated/Const/Const_getCanonicalPath.ql | 7 + .../extractor-tests/generated/Enum/Enum.ql | 13 +- .../generated/Enum/Enum_getCanonicalPath.ql | 7 + .../generated/ExternBlock/ExternBlock.ql | 9 +- .../ExternBlock_getCanonicalPath.ql | 7 + .../generated/ExternCrate/ExternCrate.ql | 9 +- .../ExternCrate_getCanonicalPath.ql | 7 + .../generated/Function/Function.ql | 15 +- .../Function/Function_getCanonicalPath.ql | 7 + .../extractor-tests/generated/Impl/Impl.ql | 16 +- .../generated/Impl/Impl_getCanonicalPath.ql | 7 + .../generated/MacroCall/MacroCall.ql | 9 +- .../MacroCall/MacroCall_getCanonicalPath.ql | 7 + .../generated/MacroDef/MacroDef.ql | 9 +- .../MacroDef/MacroDef_getCanonicalPath.ql | 7 + .../generated/MacroRules/MacroRules.ql | 9 +- .../MacroRules/MacroRules_getCanonicalPath.ql | 7 + .../MethodCallExpr/MethodCallExpr.ql | 13 +- ...MethodCallExpr_getResolvedCanonicalPath.ql | 7 + .../generated/Module/Module.ql | 9 +- .../Module/Module_getCanonicalPath.ql | 7 + .../generated/Path/PathExpr.expected | 12 +- .../generated/Path/PathExpr.ql | 12 +- ...PathExpr_getResolvedCanonicalPath.expected | 0 .../Path/PathExpr_getResolvedCanonicalPath.ql | 7 + .../generated/Path/PathPat.expected | 2 +- .../extractor-tests/generated/Path/PathPat.ql | 11 +- .../PathPat_getResolvedCanonicalPath.expected | 0 .../Path/PathPat_getResolvedCanonicalPath.ql | 7 + .../generated/RecordExpr/RecordExpr.ql | 12 +- .../RecordExpr_getResolvedCanonicalPath.ql | 7 + .../generated/RecordPat/RecordPat.ql | 12 +- .../RecordPat_getResolvedCanonicalPath.ql | 7 + .../generated/Static/Static.ql | 12 +- .../Static/Static_getCanonicalPath.ql | 7 + .../generated/Struct/Struct.ql | 13 +- .../Struct/Struct_getCanonicalPath.ql | 7 + .../extractor-tests/generated/Trait/Trait.ql | 16 +- .../generated/Trait/Trait_getCanonicalPath.ql | 7 + .../generated/TraitAlias/TraitAlias.ql | 13 +- .../TraitAlias/TraitAlias_getCanonicalPath.ql | 7 + .../TupleStructPat/TupleStructPat.ql | 12 +- ...TupleStructPat_getResolvedCanonicalPath.ql | 7 + .../generated/TypeAlias/TypeAlias.ql | 14 +- .../TypeAlias/TypeAlias_getCanonicalPath.ql | 7 + .../extractor-tests/generated/Union/Union.ql | 13 +- .../generated/Union/Union_getCanonicalPath.ql | 7 + .../test/extractor-tests/generated/Use/Use.ql | 8 +- .../generated/Use/Use_getCanonicalPath.ql | 7 + .../generated/Variant/Variant.ql | 9 +- .../Variant/Variant_getCanonicalPath.ql | 7 + rust/schema/prelude.py | 125 +- 151 files changed, 15496 insertions(+), 11031 deletions(-) delete mode 100644 rust/extractor/src/generated/top.rs create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/BuiltinTypeCanonicalPath.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/CanonicalPath.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/CanonicalPathElement.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/ConcreteTypeCanonicalPath.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/ConstGenericTypeArg.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/CrateRoot.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/DerivedTypeCanonicalPath.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/ImplItemCanonicalPath.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/LangCrateRoot.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/ModuleItemCanonicalPath.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/Namespace.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/ParametrizedCanonicalPath.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/PlaceholderTypeCanonicalPath.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/RepoCrateRoot.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/RustcCrateRoot.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/TypeCanonicalPath.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/TypeGenericArg.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/TypeGenericTypeArg.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/TypeItemCanonicalPath.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/internal/BuiltinTypeCanonicalPathConstructor.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/internal/BuiltinTypeCanonicalPathImpl.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/internal/CanonicalPathElementImpl.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/internal/CanonicalPathImpl.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/internal/ConcreteTypeCanonicalPathConstructor.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/internal/ConcreteTypeCanonicalPathImpl.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/internal/ConstGenericTypeArgConstructor.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/internal/ConstGenericTypeArgImpl.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/internal/CrateRootImpl.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/internal/DerivedTypeCanonicalPathConstructor.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/internal/DerivedTypeCanonicalPathImpl.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/internal/ImplItemCanonicalPathConstructor.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/internal/ImplItemCanonicalPathImpl.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/internal/LangCrateRootConstructor.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/internal/LangCrateRootImpl.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/internal/ModuleItemCanonicalPathConstructor.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/internal/ModuleItemCanonicalPathImpl.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/internal/NamespaceConstructor.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/internal/NamespaceImpl.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/internal/ParametrizedCanonicalPathConstructor.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/internal/ParametrizedCanonicalPathImpl.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/internal/PlaceholderTypeCanonicalPathConstructor.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/internal/PlaceholderTypeCanonicalPathImpl.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/internal/RepoCrateRootConstructor.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/internal/RepoCrateRootImpl.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/internal/RustcCrateRootConstructor.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/internal/RustcCrateRootImpl.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/internal/TypeCanonicalPathImpl.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/internal/TypeGenericArgImpl.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/internal/TypeGenericTypeArgConstructor.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/internal/TypeGenericTypeArgImpl.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/internal/TypeItemCanonicalPathConstructor.qll create mode 100644 rust/ql/lib/codeql/rust/elements/canonical_paths/internal/TypeItemCanonicalPathImpl.qll create mode 100644 rust/ql/lib/codeql/rust/elements/internal/generated/canonical_paths/BuiltinTypeCanonicalPath.qll create mode 100644 rust/ql/lib/codeql/rust/elements/internal/generated/canonical_paths/CanonicalPath.qll create mode 100644 rust/ql/lib/codeql/rust/elements/internal/generated/canonical_paths/CanonicalPathElement.qll create mode 100644 rust/ql/lib/codeql/rust/elements/internal/generated/canonical_paths/ConcreteTypeCanonicalPath.qll create mode 100644 rust/ql/lib/codeql/rust/elements/internal/generated/canonical_paths/ConstGenericTypeArg.qll create mode 100644 rust/ql/lib/codeql/rust/elements/internal/generated/canonical_paths/CrateRoot.qll create mode 100644 rust/ql/lib/codeql/rust/elements/internal/generated/canonical_paths/DerivedTypeCanonicalPath.qll create mode 100644 rust/ql/lib/codeql/rust/elements/internal/generated/canonical_paths/ImplItemCanonicalPath.qll create mode 100644 rust/ql/lib/codeql/rust/elements/internal/generated/canonical_paths/LangCrateRoot.qll create mode 100644 rust/ql/lib/codeql/rust/elements/internal/generated/canonical_paths/ModuleItemCanonicalPath.qll create mode 100644 rust/ql/lib/codeql/rust/elements/internal/generated/canonical_paths/Namespace.qll create mode 100644 rust/ql/lib/codeql/rust/elements/internal/generated/canonical_paths/ParametrizedCanonicalPath.qll create mode 100644 rust/ql/lib/codeql/rust/elements/internal/generated/canonical_paths/PlaceholderTypeCanonicalPath.qll create mode 100644 rust/ql/lib/codeql/rust/elements/internal/generated/canonical_paths/RepoCrateRoot.qll create mode 100644 rust/ql/lib/codeql/rust/elements/internal/generated/canonical_paths/RustcCrateRoot.qll create mode 100644 rust/ql/lib/codeql/rust/elements/internal/generated/canonical_paths/TypeCanonicalPath.qll create mode 100644 rust/ql/lib/codeql/rust/elements/internal/generated/canonical_paths/TypeGenericArg.qll create mode 100644 rust/ql/lib/codeql/rust/elements/internal/generated/canonical_paths/TypeGenericTypeArg.qll create mode 100644 rust/ql/lib/codeql/rust/elements/internal/generated/canonical_paths/TypeItemCanonicalPath.qll create mode 100644 rust/ql/test/extractor-tests/generated/Const/Const_getCanonicalPath.ql create mode 100644 rust/ql/test/extractor-tests/generated/Enum/Enum_getCanonicalPath.ql create mode 100644 rust/ql/test/extractor-tests/generated/ExternBlock/ExternBlock_getCanonicalPath.ql create mode 100644 rust/ql/test/extractor-tests/generated/ExternCrate/ExternCrate_getCanonicalPath.ql create mode 100644 rust/ql/test/extractor-tests/generated/Function/Function_getCanonicalPath.ql create mode 100644 rust/ql/test/extractor-tests/generated/Impl/Impl_getCanonicalPath.ql create mode 100644 rust/ql/test/extractor-tests/generated/MacroCall/MacroCall_getCanonicalPath.ql create mode 100644 rust/ql/test/extractor-tests/generated/MacroDef/MacroDef_getCanonicalPath.ql create mode 100644 rust/ql/test/extractor-tests/generated/MacroRules/MacroRules_getCanonicalPath.ql create mode 100644 rust/ql/test/extractor-tests/generated/MethodCallExpr/MethodCallExpr_getResolvedCanonicalPath.ql create mode 100644 rust/ql/test/extractor-tests/generated/Module/Module_getCanonicalPath.ql create mode 100644 rust/ql/test/extractor-tests/generated/Path/PathExpr_getResolvedCanonicalPath.expected create mode 100644 rust/ql/test/extractor-tests/generated/Path/PathExpr_getResolvedCanonicalPath.ql create mode 100644 rust/ql/test/extractor-tests/generated/Path/PathPat_getResolvedCanonicalPath.expected create mode 100644 rust/ql/test/extractor-tests/generated/Path/PathPat_getResolvedCanonicalPath.ql create mode 100644 rust/ql/test/extractor-tests/generated/RecordExpr/RecordExpr_getResolvedCanonicalPath.ql create mode 100644 rust/ql/test/extractor-tests/generated/RecordPat/RecordPat_getResolvedCanonicalPath.ql create mode 100644 rust/ql/test/extractor-tests/generated/Static/Static_getCanonicalPath.ql create mode 100644 rust/ql/test/extractor-tests/generated/Struct/Struct_getCanonicalPath.ql create mode 100644 rust/ql/test/extractor-tests/generated/Trait/Trait_getCanonicalPath.ql create mode 100644 rust/ql/test/extractor-tests/generated/TraitAlias/TraitAlias_getCanonicalPath.ql create mode 100644 rust/ql/test/extractor-tests/generated/TupleStructPat/TupleStructPat_getResolvedCanonicalPath.ql create mode 100644 rust/ql/test/extractor-tests/generated/TypeAlias/TypeAlias_getCanonicalPath.ql create mode 100644 rust/ql/test/extractor-tests/generated/Union/Union_getCanonicalPath.ql create mode 100644 rust/ql/test/extractor-tests/generated/Use/Use_getCanonicalPath.ql create mode 100644 rust/ql/test/extractor-tests/generated/Variant/Variant_getCanonicalPath.ql diff --git a/misc/codegen/generators/rustgen.py b/misc/codegen/generators/rustgen.py index b47e5cc4bd9d..4dd6478df66b 100644 --- a/misc/codegen/generators/rustgen.py +++ b/misc/codegen/generators/rustgen.py @@ -101,12 +101,12 @@ def _get_class(self, name: str) -> rust.Class: ) def get_classes(self): - ret = {"": []} + ret = [] for k, cls in self._classmap.items(): if not cls.imported and not cls.synth: - ret.setdefault(cls.group, []).append(self._get_class(cls.name)) + ret.append(self._get_class(cls.name)) elif cls.imported: - ret[""].append(rust.Class(name=cls.name)) + ret.append(rust.Class(name=cls.name)) return ret @@ -114,25 +114,14 @@ def generate(opts, renderer): assert opts.rust_output processor = Processor(schemaloader.load_file(opts.schema)) out = opts.rust_output - groups = set() with renderer.manage(generated=out.rglob("*.rs"), stubs=(), registry=out / ".generated.list", force=opts.force) as renderer: - for group, classes in processor.get_classes().items(): - group = group or "top" - groups.add(group) - renderer.render( - rust.ClassList( - classes, - opts.schema, - ), - out / f"{group}.rs", - ) renderer.render( - rust.ModuleList( - groups, - opts.schema, + rust.ClassList( + classes=processor.get_classes(), + source=opts.schema, ), out / f"mod.rs", ) diff --git a/misc/codegen/loaders/schemaloader.py b/misc/codegen/loaders/schemaloader.py index 3b5f20cbbede..5909164502c4 100644 --- a/misc/codegen/loaders/schemaloader.py +++ b/misc/codegen/loaders/schemaloader.py @@ -121,9 +121,14 @@ def _fill_hideable_information(classes: typing.Dict[str, schema.Class]): def _check_test_with(classes: typing.Dict[str, schema.Class]): + pragma = "qlest_test_with" for cls in classes.values(): - test_with = typing.cast(str, cls.pragmas.get("qltest_test_with")) - transitive_test_with = test_with and classes[test_with].pragmas.get("qltest_test_with") + if cls.name == cls.pragmas.get(pragma): + # this is already implicit + del cls.pragmas[pragma] + for cls in classes.values(): + test_with = typing.cast(str, cls.pragmas.get(pragma)) + transitive_test_with = test_with and classes[test_with].pragmas.get(pragma) if test_with and transitive_test_with: raise schema.Error(f"{cls.name} has test_with {test_with} which in turn " f"has test_with {transitive_test_with}, use that directly") diff --git a/rust/extractor/src/generated/.generated.list b/rust/extractor/src/generated/.generated.list index cbc2dd7c6573..6bd3437cfabd 100644 --- a/rust/extractor/src/generated/.generated.list +++ b/rust/extractor/src/generated/.generated.list @@ -1,2 +1 @@ -mod.rs 4bcb9def847469aae9d8649461546b7c21ec97cf6e63d3cf394e339915ce65d7 4bcb9def847469aae9d8649461546b7c21ec97cf6e63d3cf394e339915ce65d7 -top.rs d09cf25daa06fc9bc802e438231e0f038443d2ede3972a0dd829f322b390c4e4 d09cf25daa06fc9bc802e438231e0f038443d2ede3972a0dd829f322b390c4e4 +mod.rs f28f770a937d79fa8a02058ecdb5a8898b43da3d4d785c7abd90af32e5d8ef23 f28f770a937d79fa8a02058ecdb5a8898b43da3d4d785c7abd90af32e5d8ef23 diff --git a/rust/extractor/src/generated/.gitattributes b/rust/extractor/src/generated/.gitattributes index 25bb20a99113..e8bb2bee7bc5 100644 --- a/rust/extractor/src/generated/.gitattributes +++ b/rust/extractor/src/generated/.gitattributes @@ -1,4 +1,3 @@ /.generated.list linguist-generated /.gitattributes linguist-generated /mod.rs linguist-generated -/top.rs linguist-generated diff --git a/rust/extractor/src/generated/mod.rs b/rust/extractor/src/generated/mod.rs index 0f95afeeff20..510ea80a5f09 100644 --- a/rust/extractor/src/generated/mod.rs +++ b/rust/extractor/src/generated/mod.rs @@ -1,4 +1,11458 @@ // generated by codegen, do not edit -mod top; -pub use top::*; +#![cfg_attr(any(), rustfmt::skip)] + +use crate::trap; + +#[derive(Debug)] +pub struct File { + _unused: () +} + +impl trap::TrapClass for File { + fn class_name() -> &'static str { "File" } +} + +#[derive(Debug)] +pub struct Element { + _unused: () +} + +impl trap::TrapClass for Element { + fn class_name() -> &'static str { "Element" } +} + +#[derive(Debug)] +pub struct ExtractorStep { + pub id: trap::TrapId, + pub action: String, + pub file: trap::Label, + pub duration_ms: usize, +} + +impl trap::TrapEntry for ExtractorStep { + fn extract_id(&mut self) -> trap::TrapId { + std::mem::replace(&mut self.id, trap::TrapId::Star) + } + + fn emit(self, id: trap::Label, out: &mut trap::Writer) { + out.add_tuple("extractor_steps", vec![id.into(), self.action.into(), self.file.into(), self.duration_ms.into()]); + } +} + +impl trap::TrapClass for ExtractorStep { + fn class_name() -> &'static str { "ExtractorStep" } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme ExtractorStep is a subclass of Element + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +#[derive(Debug)] +pub struct Locatable { + _unused: () +} + +impl trap::TrapClass for Locatable { + fn class_name() -> &'static str { "Locatable" } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme Locatable is a subclass of Element + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +#[derive(Debug)] +pub struct Unextracted { + _unused: () +} + +impl trap::TrapClass for Unextracted { + fn class_name() -> &'static str { "Unextracted" } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme Unextracted is a subclass of Element + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +#[derive(Debug)] +pub struct AstNode { + _unused: () +} + +impl trap::TrapClass for AstNode { + fn class_name() -> &'static str { "AstNode" } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme AstNode is a subclass of Element + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme AstNode is a subclass of Locatable + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +#[derive(Debug)] +pub struct Missing { + pub id: trap::TrapId, +} + +impl trap::TrapEntry for Missing { + fn extract_id(&mut self) -> trap::TrapId { + std::mem::replace(&mut self.id, trap::TrapId::Star) + } + + fn emit(self, id: trap::Label, out: &mut trap::Writer) { + out.add_tuple("missings", vec![id.into()]); + } +} + +impl trap::TrapClass for Missing { + fn class_name() -> &'static str { "Missing" } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme Missing is a subclass of Element + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme Missing is a subclass of Unextracted + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +#[derive(Debug)] +pub struct Unimplemented { + pub id: trap::TrapId, +} + +impl trap::TrapEntry for Unimplemented { + fn extract_id(&mut self) -> trap::TrapId { + std::mem::replace(&mut self.id, trap::TrapId::Star) + } + + fn emit(self, id: trap::Label, out: &mut trap::Writer) { + out.add_tuple("unimplementeds", vec![id.into()]); + } +} + +impl trap::TrapClass for Unimplemented { + fn class_name() -> &'static str { "Unimplemented" } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme Unimplemented is a subclass of Element + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme Unimplemented is a subclass of Unextracted + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +#[derive(Debug)] +pub struct Abi { + pub id: trap::TrapId, + pub abi_string: Option, +} + +impl trap::TrapEntry for Abi { + fn extract_id(&mut self) -> trap::TrapId { + std::mem::replace(&mut self.id, trap::TrapId::Star) + } + + fn emit(self, id: trap::Label, out: &mut trap::Writer) { + out.add_tuple("abis", vec![id.into()]); + if let Some(v) = self.abi_string { + out.add_tuple("abi_abi_strings", vec![id.into(), v.into()]); + } + } +} + +impl trap::TrapClass for Abi { + fn class_name() -> &'static str { "Abi" } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme Abi is a subclass of AstNode + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme Abi is a subclass of Element + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme Abi is a subclass of Locatable + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +#[derive(Debug)] +pub struct Addressable { + _unused: () +} + +impl Addressable { + pub fn emit_extended_canonical_path(id: trap::Label, value: String, out: &mut trap::Writer) { + out.add_tuple("addressable_extended_canonical_paths", vec![id.into(), value.into()]); + } + pub fn emit_crate_origin(id: trap::Label, value: String, out: &mut trap::Writer) { + out.add_tuple("addressable_crate_origins", vec![id.into(), value.into()]); + } + pub fn emit_canonical_path(id: trap::Label, value: trap::Label, out: &mut trap::Writer) { + out.add_tuple("addressable_canonical_paths", vec![id.into(), value.into()]); + } +} + +impl trap::TrapClass for Addressable { + fn class_name() -> &'static str { "Addressable" } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme Addressable is a subclass of AstNode + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme Addressable is a subclass of Element + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme Addressable is a subclass of Locatable + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +#[derive(Debug)] +pub struct ArgList { + pub id: trap::TrapId, + pub args: Vec>, +} + +impl trap::TrapEntry for ArgList { + fn extract_id(&mut self) -> trap::TrapId { + std::mem::replace(&mut self.id, trap::TrapId::Star) + } + + fn emit(self, id: trap::Label, out: &mut trap::Writer) { + out.add_tuple("arg_lists", vec![id.into()]); + for (i, v) in self.args.into_iter().enumerate() { + out.add_tuple("arg_list_args", vec![id.into(), i.into(), v.into()]); + } + } +} + +impl trap::TrapClass for ArgList { + fn class_name() -> &'static str { "ArgList" } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme ArgList is a subclass of AstNode + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme ArgList is a subclass of Element + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme ArgList is a subclass of Locatable + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +#[derive(Debug)] +pub struct AssocItem { + _unused: () +} + +impl trap::TrapClass for AssocItem { + fn class_name() -> &'static str { "AssocItem" } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme AssocItem is a subclass of AstNode + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme AssocItem is a subclass of Element + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme AssocItem is a subclass of Locatable + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +#[derive(Debug)] +pub struct AssocItemList { + pub id: trap::TrapId, + pub assoc_items: Vec>, + pub attrs: Vec>, +} + +impl trap::TrapEntry for AssocItemList { + fn extract_id(&mut self) -> trap::TrapId { + std::mem::replace(&mut self.id, trap::TrapId::Star) + } + + fn emit(self, id: trap::Label, out: &mut trap::Writer) { + out.add_tuple("assoc_item_lists", vec![id.into()]); + for (i, v) in self.assoc_items.into_iter().enumerate() { + out.add_tuple("assoc_item_list_assoc_items", vec![id.into(), i.into(), v.into()]); + } + for (i, v) in self.attrs.into_iter().enumerate() { + out.add_tuple("assoc_item_list_attrs", vec![id.into(), i.into(), v.into()]); + } + } +} + +impl trap::TrapClass for AssocItemList { + fn class_name() -> &'static str { "AssocItemList" } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme AssocItemList is a subclass of AstNode + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme AssocItemList is a subclass of Element + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme AssocItemList is a subclass of Locatable + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +#[derive(Debug)] +pub struct Attr { + pub id: trap::TrapId, + pub meta: Option>, +} + +impl trap::TrapEntry for Attr { + fn extract_id(&mut self) -> trap::TrapId { + std::mem::replace(&mut self.id, trap::TrapId::Star) + } + + fn emit(self, id: trap::Label, out: &mut trap::Writer) { + out.add_tuple("attrs", vec![id.into()]); + if let Some(v) = self.meta { + out.add_tuple("attr_meta", vec![id.into(), v.into()]); + } + } +} + +impl trap::TrapClass for Attr { + fn class_name() -> &'static str { "Attr" } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme Attr is a subclass of AstNode + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme Attr is a subclass of Element + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme Attr is a subclass of Locatable + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +#[derive(Debug)] +pub struct Callable { + _unused: () +} + +impl trap::TrapClass for Callable { + fn class_name() -> &'static str { "Callable" } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme Callable is a subclass of AstNode + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme Callable is a subclass of Element + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme Callable is a subclass of Locatable + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +#[derive(Debug)] +pub struct ClosureBinder { + pub id: trap::TrapId, + pub generic_param_list: Option>, +} + +impl trap::TrapEntry for ClosureBinder { + fn extract_id(&mut self) -> trap::TrapId { + std::mem::replace(&mut self.id, trap::TrapId::Star) + } + + fn emit(self, id: trap::Label, out: &mut trap::Writer) { + out.add_tuple("closure_binders", vec![id.into()]); + if let Some(v) = self.generic_param_list { + out.add_tuple("closure_binder_generic_param_lists", vec![id.into(), v.into()]); + } + } +} + +impl trap::TrapClass for ClosureBinder { + fn class_name() -> &'static str { "ClosureBinder" } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme ClosureBinder is a subclass of AstNode + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme ClosureBinder is a subclass of Element + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme ClosureBinder is a subclass of Locatable + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +#[derive(Debug)] +pub struct Expr { + _unused: () +} + +impl trap::TrapClass for Expr { + fn class_name() -> &'static str { "Expr" } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme Expr is a subclass of AstNode + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme Expr is a subclass of Element + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme Expr is a subclass of Locatable + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +#[derive(Debug)] +pub struct ExternItem { + _unused: () +} + +impl trap::TrapClass for ExternItem { + fn class_name() -> &'static str { "ExternItem" } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme ExternItem is a subclass of AstNode + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme ExternItem is a subclass of Element + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme ExternItem is a subclass of Locatable + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +#[derive(Debug)] +pub struct ExternItemList { + pub id: trap::TrapId, + pub attrs: Vec>, + pub extern_items: Vec>, +} + +impl trap::TrapEntry for ExternItemList { + fn extract_id(&mut self) -> trap::TrapId { + std::mem::replace(&mut self.id, trap::TrapId::Star) + } + + fn emit(self, id: trap::Label, out: &mut trap::Writer) { + out.add_tuple("extern_item_lists", vec![id.into()]); + for (i, v) in self.attrs.into_iter().enumerate() { + out.add_tuple("extern_item_list_attrs", vec![id.into(), i.into(), v.into()]); + } + for (i, v) in self.extern_items.into_iter().enumerate() { + out.add_tuple("extern_item_list_extern_items", vec![id.into(), i.into(), v.into()]); + } + } +} + +impl trap::TrapClass for ExternItemList { + fn class_name() -> &'static str { "ExternItemList" } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme ExternItemList is a subclass of AstNode + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme ExternItemList is a subclass of Element + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme ExternItemList is a subclass of Locatable + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +#[derive(Debug)] +pub struct FieldList { + _unused: () +} + +impl trap::TrapClass for FieldList { + fn class_name() -> &'static str { "FieldList" } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme FieldList is a subclass of AstNode + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme FieldList is a subclass of Element + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme FieldList is a subclass of Locatable + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +#[derive(Debug)] +pub struct FormatArgsArg { + pub id: trap::TrapId, + pub expr: Option>, + pub name: Option>, +} + +impl trap::TrapEntry for FormatArgsArg { + fn extract_id(&mut self) -> trap::TrapId { + std::mem::replace(&mut self.id, trap::TrapId::Star) + } + + fn emit(self, id: trap::Label, out: &mut trap::Writer) { + out.add_tuple("format_args_args", vec![id.into()]); + if let Some(v) = self.expr { + out.add_tuple("format_args_arg_exprs", vec![id.into(), v.into()]); + } + if let Some(v) = self.name { + out.add_tuple("format_args_arg_names", vec![id.into(), v.into()]); + } + } +} + +impl trap::TrapClass for FormatArgsArg { + fn class_name() -> &'static str { "FormatArgsArg" } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme FormatArgsArg is a subclass of AstNode + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme FormatArgsArg is a subclass of Element + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme FormatArgsArg is a subclass of Locatable + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +#[derive(Debug)] +pub struct GenericArg { + _unused: () +} + +impl trap::TrapClass for GenericArg { + fn class_name() -> &'static str { "GenericArg" } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme GenericArg is a subclass of AstNode + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme GenericArg is a subclass of Element + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme GenericArg is a subclass of Locatable + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +#[derive(Debug)] +pub struct GenericArgList { + pub id: trap::TrapId, + pub generic_args: Vec>, +} + +impl trap::TrapEntry for GenericArgList { + fn extract_id(&mut self) -> trap::TrapId { + std::mem::replace(&mut self.id, trap::TrapId::Star) + } + + fn emit(self, id: trap::Label, out: &mut trap::Writer) { + out.add_tuple("generic_arg_lists", vec![id.into()]); + for (i, v) in self.generic_args.into_iter().enumerate() { + out.add_tuple("generic_arg_list_generic_args", vec![id.into(), i.into(), v.into()]); + } + } +} + +impl trap::TrapClass for GenericArgList { + fn class_name() -> &'static str { "GenericArgList" } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme GenericArgList is a subclass of AstNode + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme GenericArgList is a subclass of Element + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme GenericArgList is a subclass of Locatable + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +#[derive(Debug)] +pub struct GenericParam { + _unused: () +} + +impl trap::TrapClass for GenericParam { + fn class_name() -> &'static str { "GenericParam" } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme GenericParam is a subclass of AstNode + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme GenericParam is a subclass of Element + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme GenericParam is a subclass of Locatable + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +#[derive(Debug)] +pub struct GenericParamList { + pub id: trap::TrapId, + pub generic_params: Vec>, +} + +impl trap::TrapEntry for GenericParamList { + fn extract_id(&mut self) -> trap::TrapId { + std::mem::replace(&mut self.id, trap::TrapId::Star) + } + + fn emit(self, id: trap::Label, out: &mut trap::Writer) { + out.add_tuple("generic_param_lists", vec![id.into()]); + for (i, v) in self.generic_params.into_iter().enumerate() { + out.add_tuple("generic_param_list_generic_params", vec![id.into(), i.into(), v.into()]); + } + } +} + +impl trap::TrapClass for GenericParamList { + fn class_name() -> &'static str { "GenericParamList" } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme GenericParamList is a subclass of AstNode + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme GenericParamList is a subclass of Element + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme GenericParamList is a subclass of Locatable + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +#[derive(Debug)] +pub struct ItemList { + pub id: trap::TrapId, + pub attrs: Vec>, + pub items: Vec>, +} + +impl trap::TrapEntry for ItemList { + fn extract_id(&mut self) -> trap::TrapId { + std::mem::replace(&mut self.id, trap::TrapId::Star) + } + + fn emit(self, id: trap::Label, out: &mut trap::Writer) { + out.add_tuple("item_lists", vec![id.into()]); + for (i, v) in self.attrs.into_iter().enumerate() { + out.add_tuple("item_list_attrs", vec![id.into(), i.into(), v.into()]); + } + for (i, v) in self.items.into_iter().enumerate() { + out.add_tuple("item_list_items", vec![id.into(), i.into(), v.into()]); + } + } +} + +impl trap::TrapClass for ItemList { + fn class_name() -> &'static str { "ItemList" } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme ItemList is a subclass of AstNode + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme ItemList is a subclass of Element + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme ItemList is a subclass of Locatable + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +#[derive(Debug)] +pub struct Label { + pub id: trap::TrapId