diff --git a/misc/codegen/lib/schemadefs.py b/misc/codegen/lib/schemadefs.py index 7152c32d12b..ea8d6cf09ce 100644 --- a/misc/codegen/lib/schemadefs.py +++ b/misc/codegen/lib/schemadefs.py @@ -1,4 +1,8 @@ -from typing import Callable as _Callable, Dict as _Dict, ClassVar as _ClassVar +from typing import ( + Callable as _Callable, + Dict as _Dict, + ClassVar as _ClassVar, +) from misc.codegen.lib import schema as _schema import inspect as _inspect from dataclasses import dataclass as _dataclass @@ -271,14 +275,16 @@ class _PropertyAnnotation: _ = _PropertyAnnotation() +drop = object() -def annotate(annotated_cls: type) -> _Callable[[type], _PropertyAnnotation]: + +def annotate(annotated_cls: type, replace_bases: _Dict[type, type] | None = None) -> _Callable[[type], _PropertyAnnotation]: """ - Add or modify schema annotations after a class has been defined - For the moment, only docstring annotation is supported. In the future, any kind of - modification will be allowed. + Add or modify schema annotations after a class has been defined previously. - The name of the class used for annotation must be `_` + The name of the class used for annotation must be `_`. + + `replace_bases` can be used to replace bases on the annotated class. """ def decorator(cls: type) -> _PropertyAnnotation: if cls.__name__ != "_": @@ -287,11 +293,15 @@ def annotate(annotated_cls: type) -> _Callable[[type], _PropertyAnnotation]: annotated_cls.__doc__ = cls.__doc__ for p, v in cls.__dict__.get("_pragmas", {}).items(): _ClassPragma(p, value=v)(annotated_cls) + if replace_bases: + annotated_cls.__bases__ = tuple(replace_bases.get(b, b) for b in annotated_cls.__bases__) for a in dir(cls): if a.startswith(_schema.inheritable_pragma_prefix): setattr(annotated_cls, a, getattr(cls, a)) for p, a in cls.__annotations__.items(): - if p in annotated_cls.__annotations__: + if a is drop: + del annotated_cls.__annotations__[p] + elif p in annotated_cls.__annotations__: annotated_cls.__annotations__[p] |= a elif isinstance(a, (_PropertyAnnotation, _PropertyModifierList)): raise _schema.Error(f"annotated property {p} not present in annotated class " diff --git a/misc/codegen/test/test_schemaloader.py b/misc/codegen/test/test_schemaloader.py index 4d1aa06ecd0..0c9128c7272 100644 --- a/misc/codegen/test/test_schemaloader.py +++ b/misc/codegen/test/test_schemaloader.py @@ -884,6 +884,56 @@ def test_annotate_not_underscore(): """ +def test_annotate_replace_bases(): + @load + class data: + class Root: + pass + + class A(Root): + pass + + class B(Root): + pass + + class C(B): + pass + + class Derived(A, B): + pass + + @defs.annotate(Derived, replace_bases={B: C}) + class _: + pass + assert data.classes == { + "Root": schema.Class("Root", derived={"A", "B"}), + "A": schema.Class("A", bases=["Root"], derived={"Derived"}), + "B": schema.Class("B", bases=["Root"], derived={"C"}), + "C": schema.Class("C", bases=["B"], derived={"Derived"}), + "Derived": schema.Class("Derived", bases=["A", "C"]), + } + + +def test_annotate_drop_field(): + @load + class data: + class Root: + x: defs.int + y: defs.string + z: defs.boolean + + @defs.annotate(Root) + class _: + y: defs.drop + + assert data.classes == { + "Root": schema.Class("Root", properties=[ + schema.SingleProperty("x", "int"), + schema.SingleProperty("z", "boolean"), + ]), + } + + def test_test_with_unknown_string(): with pytest.raises(schema.Error): @load diff --git a/rust/extractor/src/generated/.generated.list b/rust/extractor/src/generated/.generated.list index 1e9f2055823..0f2bb009eeb 100644 --- a/rust/extractor/src/generated/.generated.list +++ b/rust/extractor/src/generated/.generated.list @@ -1,2 +1,2 @@ mod.rs 4bcb9def847469aae9d8649461546b7c21ec97cf6e63d3cf394e339915ce65d7 4bcb9def847469aae9d8649461546b7c21ec97cf6e63d3cf394e339915ce65d7 -top.rs f8cc230aca9a7696686bee1efe499c679fb4760e09187075c803016e7b83433c f8cc230aca9a7696686bee1efe499c679fb4760e09187075c803016e7b83433c +top.rs 170c3892b5cbb8be28ae420a92ebab3b96b354c3b7ea2ba96edec64e639e8455 170c3892b5cbb8be28ae420a92ebab3b96b354c3b7ea2ba96edec64e639e8455 diff --git a/rust/extractor/src/generated/top.rs b/rust/extractor/src/generated/top.rs index fd008b106c7..33f321246d4 100644 --- a/rust/extractor/src/generated/top.rs +++ b/rust/extractor/src/generated/top.rs @@ -3655,66 +3655,44 @@ impl From> for trap::Label { } #[derive(Debug)] -pub struct CallExpr { - pub id: trap::TrapId, - pub arg_list: Option>, - pub attrs: Vec>, - pub expr: Option>, +pub struct CallExprBase { + _unused: () } -impl trap::TrapEntry for CallExpr { - 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("call_exprs", vec![id.into()]); - if let Some(v) = self.arg_list { - out.add_tuple("call_expr_arg_lists", vec![id.into(), v.into()]); - } - for (i, v) in self.attrs.into_iter().enumerate() { - out.add_tuple("call_expr_attrs", vec![id.into(), i.into(), v.into()]); - } - if let Some(v) = self.expr { - out.add_tuple("call_expr_exprs", vec![id.into(), v.into()]); - } - } +impl trap::TrapClass for CallExprBase { + fn class_name() -> &'static str { "CallExprBase" } } -impl trap::TrapClass for CallExpr { - fn class_name() -> &'static str { "CallExpr" } -} - -impl From> for trap::Label { - fn from(value: trap::Label) -> Self { - // SAFETY: this is safe because in the dbscheme CallExpr is a subclass of AstNode +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme CallExprBase 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 CallExpr is a subclass of Element +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme CallExprBase 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 CallExpr is a subclass of Expr +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme CallExprBase is a subclass of Expr 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 CallExpr is a subclass of Locatable +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme CallExprBase is a subclass of Locatable unsafe { Self::from_untyped(value.as_untyped()) } @@ -5742,81 +5720,6 @@ impl From> for trap::Label { } } -#[derive(Debug)] -pub struct MethodCallExpr { - pub id: trap::TrapId, - pub arg_list: Option>, - pub attrs: Vec>, - pub generic_arg_list: Option>, - pub name_ref: Option>, - pub receiver: Option>, -} - -impl trap::TrapEntry for MethodCallExpr { - 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("method_call_exprs", vec![id.into()]); - if let Some(v) = self.arg_list { - out.add_tuple("method_call_expr_arg_lists", vec![id.into(), v.into()]); - } - for (i, v) in self.attrs.into_iter().enumerate() { - out.add_tuple("method_call_expr_attrs", vec![id.into(), i.into(), v.into()]); - } - if let Some(v) = self.generic_arg_list { - out.add_tuple("method_call_expr_generic_arg_lists", vec![id.into(), v.into()]); - } - if let Some(v) = self.name_ref { - out.add_tuple("method_call_expr_name_refs", vec![id.into(), v.into()]); - } - if let Some(v) = self.receiver { - out.add_tuple("method_call_expr_receivers", vec![id.into(), v.into()]); - } - } -} - -impl trap::TrapClass for MethodCallExpr { - fn class_name() -> &'static str { "MethodCallExpr" } -} - -impl From> for trap::Label { - fn from(value: trap::Label) -> Self { - // SAFETY: this is safe because in the dbscheme MethodCallExpr 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 MethodCallExpr 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 MethodCallExpr is a subclass of Expr - 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 MethodCallExpr is a subclass of Locatable - unsafe { - Self::from_untyped(value.as_untyped()) - } - } -} - #[derive(Debug)] pub struct NeverType { pub id: trap::TrapId, @@ -8069,6 +7972,82 @@ impl From> for trap::Label { } } +#[derive(Debug)] +pub struct CallExpr { + pub id: trap::TrapId, + pub arg_list: Option>, + pub attrs: Vec>, + pub expr: Option>, +} + +impl trap::TrapEntry for CallExpr { + 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("call_exprs", vec![id.into()]); + if let Some(v) = self.arg_list { + out.add_tuple("call_expr_base_arg_lists", vec![id.into(), v.into()]); + } + for (i, v) in self.attrs.into_iter().enumerate() { + out.add_tuple("call_expr_base_attrs", vec![id.into(), i.into(), v.into()]); + } + if let Some(v) = self.expr { + out.add_tuple("call_expr_exprs", vec![id.into(), v.into()]); + } + } +} + +impl trap::TrapClass for CallExpr { + fn class_name() -> &'static str { "CallExpr" } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme CallExpr 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 CallExpr is a subclass of CallExprBase + 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 CallExpr 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 CallExpr is a subclass of Expr + 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 CallExpr is a subclass of Locatable + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + #[derive(Debug)] pub struct Const { pub id: trap::TrapId, @@ -8918,6 +8897,90 @@ impl From> for trap::Label { } } +#[derive(Debug)] +pub struct MethodCallExpr { + pub id: trap::TrapId, + pub arg_list: Option>, + pub attrs: Vec>, + pub generic_arg_list: Option>, + pub name_ref: Option>, + pub receiver: Option>, +} + +impl trap::TrapEntry for MethodCallExpr { + 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("method_call_exprs", vec![id.into()]); + if let Some(v) = self.arg_list { + out.add_tuple("call_expr_base_arg_lists", vec![id.into(), v.into()]); + } + for (i, v) in self.attrs.into_iter().enumerate() { + out.add_tuple("call_expr_base_attrs", vec![id.into(), i.into(), v.into()]); + } + if let Some(v) = self.generic_arg_list { + out.add_tuple("method_call_expr_generic_arg_lists", vec![id.into(), v.into()]); + } + if let Some(v) = self.name_ref { + out.add_tuple("method_call_expr_name_refs", vec![id.into(), v.into()]); + } + if let Some(v) = self.receiver { + out.add_tuple("method_call_expr_receivers", vec![id.into(), v.into()]); + } + } +} + +impl trap::TrapClass for MethodCallExpr { + fn class_name() -> &'static str { "MethodCallExpr" } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme MethodCallExpr 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 MethodCallExpr is a subclass of CallExprBase + 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 MethodCallExpr 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 MethodCallExpr is a subclass of Expr + 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 MethodCallExpr is a subclass of Locatable + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + #[derive(Debug)] pub struct Module { pub id: trap::TrapId, diff --git a/rust/ql/.generated.list b/rust/ql/.generated.list index 9e49fc3893e..5938d23a7b5 100644 --- a/rust/ql/.generated.list +++ b/rust/ql/.generated.list @@ -14,7 +14,8 @@ lib/codeql/rust/elements/BinaryExpr.qll 394522da3bc3a716fc7bc40c3560143ca840f5d2 lib/codeql/rust/elements/BlockExpr.qll b952fd44b89de248931d4089834d2c9406f6f2fc1a3f5c2365156be4e55157cf daccc07ab11ac696679b9fadc99f40b1bf579c90bf6c7cca6e82eaa313932ede lib/codeql/rust/elements/BoxPat.qll 1b2c3fff171aa6aa238c9460b122f26c79e04577cea67fa856de99842ba873d4 0caf8d23ed6e0997a6b8751def27641582151fba6e24fccf798712a4690b42f1 lib/codeql/rust/elements/BreakExpr.qll 7ca3807a20e9a9a988d1fd7abebf240325ed422fcb45c719ba46272f031f94db dffb7379d3f3ba220acfbd05eb7bb6cfd9cfda211e9c8b1f5240ca5fa61be3fc -lib/codeql/rust/elements/CallExpr.qll 6760ef2753fcaa9f02860bfeadfd1b1603d0d5b35f5dd72b33a474c206f51a29 55afe003eb51ef28b382af368429930d858d291bb7d76d71149eee1c805731f1 +lib/codeql/rust/elements/CallExpr.qll f336500ca7a611b164d48b90e80edb0c0d3816792b0ececce659ac1ff1ffeb3e f99a9c55466418ef53860c44d9f2d6161af4b492178ddd9e5870dff742b70ae5 +lib/codeql/rust/elements/CallExprBase.qll 2846202b5208b541977500286951d96487bf555838c6c16cdd006a71e383745a c789d412bf099c624329379e0c7d94fa0d23ae2edea7a25a2ea0f3c0042ccf62 lib/codeql/rust/elements/CastExpr.qll ba281bde130f43c486c4ad889539b77fba9e41afdf7980e50b6a8696a1ec7527 61257003d395896ec60729d0bc01da36697615bb725d07141255fbb5c44e50a0 lib/codeql/rust/elements/ClosureBinder.qll 977df800f97cc9b03fffb5e5e1fc6acd08a2938e04cb6ad91108784a15b0d510 f6fad4127226fe1dff2f16416d8a7fde5d8ab4a88f30e443ac5e5ff618de3e05 lib/codeql/rust/elements/ClosureExpr.qll 8f06357ae134e42c073eef994c83c04b8cf294fe33b286dbd75c0e705ce29d05 9d9e282d965fed723965376801d4afa49444d1d9be9b093d02e276729a2cf7ad @@ -75,7 +76,7 @@ lib/codeql/rust/elements/MatchArmList.qll e6c48fd7419d88e996b82eb45e4aa2686dfd07 lib/codeql/rust/elements/MatchExpr.qll e9ef1664f020823b6f4bb72d906a9dc0c1ee6432d4a9a13f7dbdbab2b2b1ee4d 38d71e5c487abcb5682293c573343be66e499a6e131bb630604c120d34b7777b lib/codeql/rust/elements/MatchGuard.qll 20754ab2009a7d40b50feece496ff7f38650586d79190ed2a372308594693694 471f8f118317efcf112f4ddfd60125ca2a9d9b3b08e6ee331c430961de7885ff lib/codeql/rust/elements/Meta.qll 9fa3216c86fa55ed5c0c4671708110a6ffc7c0f5d6cda8dda31aaff17f87534d c44ee2754dd71776ffd0a8a7d6c1ae8737c47e998e6bdb8efab5283625807cf4 -lib/codeql/rust/elements/MethodCallExpr.qll 0a5cab9f21741f6a38956e6de4f6beb143db5d85ee590f9908dab3da300a6b72 df21eba9cf2823a7b06eb6672dd8249225e7c16d5b6c1c37c1f2a175d9513272 +lib/codeql/rust/elements/MethodCallExpr.qll 91b411e0fb1a0547dcad8726db460dccc61bed972741598d5cb3740593fe75a7 538d23b6db115bb699389d29a1829bb0449c08424a1fff80377828eb7ceb2563 lib/codeql/rust/elements/Missing.qll 70e6ac9790314752849c9888443c98223ccfc93a193998b7ce350b2c6ebe8ea4 e2f0623511acaa76b091f748d417714137a8b94f1f2bdbbd177f1c682c786dad lib/codeql/rust/elements/Module.qll 0bc85019177709256f8078d9de2a36f62f848d476225bff7bba1e35f249875c7 3fbb70e0c417a644dd0cada2c364c6e6876cfa16f37960e219c87e49c966c94e lib/codeql/rust/elements/Name.qll 3d7ed16c232912e30e5a075f5087ad344a8f76dcc27bc8f71a80c133802b89d7 036dc3ba0c20eb0907ef6dcc532214aa5de8e0de0fa819eca1fce0355b3741a3 @@ -183,6 +184,7 @@ lib/codeql/rust/elements/internal/BlockExprImpl.qll 36ac09e4a6eeeec22919b62b1d00 lib/codeql/rust/elements/internal/BoxPatConstructor.qll 153f110ba25fd6c889092bfd16f73bb610fa60d6e0c8965d5f44d2446fcd48a2 9324cf0d8aa29945551bf8ab64801d598f57aab8cd4e19bcd4e9ef8a4a4e06eb lib/codeql/rust/elements/internal/BoxPatImpl.qll d62a3cc1d5bab6bd258f702ec731ec57f0e5ef2672ab9de4b6f3b558078629eb 26b4fabb676adbbdb0d7f81449e493ee49380ea04d131f779714ac2434bb323a lib/codeql/rust/elements/internal/BreakExprConstructor.qll 356be043c28e0b34fdf925a119c945632ee883c6f5ebb9a27003c6a8d250afd9 bb77e66b04bb9489340e7506931559b94285c6904b6f9d2f83b214cba4f3cfd5 +lib/codeql/rust/elements/internal/CallExprBaseImpl.qll d2749cc1a9d7ee8bf7f34b6c3e0238a576a68e439a8c10a503c164ff45ffcbeb ffc7b0a8841945fe6736b0e1aed7d9ed69185db03dee2b16da121325b39397c7 lib/codeql/rust/elements/internal/CallExprConstructor.qll 742b38e862e2cf82fd1ecc4d4fc5b4782a9c7c07f031452b2bae7aa59d5aa13a cad6e0a8be21d91b20ac2ec16cab9c30eae810b452c0f1992ed87d5c7f4144dc lib/codeql/rust/elements/internal/CallExprImpl.qll 7e48610680ba6f2876a1a005ab0743496dd2364b9c44aca441bd33e11317e2d7 bb12c3c28156b40796fe3ba112760f87bb5abb323aab3c5b7bb3e0facaef8d35 lib/codeql/rust/elements/internal/CastExprConstructor.qll f3d6e10c4731f38a384675aeab3fba47d17b9e15648293787092bb3247ed808d d738a7751dbadb70aa1dcffcf8af7fa61d4cf8029798369a7e8620013afff4ed @@ -459,7 +461,8 @@ lib/codeql/rust/elements/internal/generated/BinaryExpr.qll 64e9bd9c571edd6e5f3e7 lib/codeql/rust/elements/internal/generated/BlockExpr.qll ccfbdc7bd268735a0424ff08dcf37d0e1fed61d5fe0520593c23f2490d400438 0facad59f6aba13ee0c069b691c99f52c04b723a2bfad4da226190c3c42dcabf lib/codeql/rust/elements/internal/generated/BoxPat.qll ec946a3e671ab7417e04b0207967adad004df512c570c4f0780ca5816d12d75f b0e64860855c4e85914042b1a51034899ff7cd1b2c6857188de89310a2726ea3 lib/codeql/rust/elements/internal/generated/BreakExpr.qll 0f428a8b2f4209b134c2ffc3e1c93c30bc6b0e9c9172f140cefa88c1f77d8690 957b39f38ff6befe9061f55bc0b403c2f1c366dd0cf63b874bae6f8216576d76 -lib/codeql/rust/elements/internal/generated/CallExpr.qll c2700dbd9c33dcc14de10dc72ff49abafdf0952257864d4435cf8ac46849a2ee 7932f725f97ffbe1b050c2622a61a0d56f18c9264a3293466cba9915313495b5 +lib/codeql/rust/elements/internal/generated/CallExpr.qll 23ee64e3bf643cd5e6ff705181d2bb31e1aeaffecb5bdce73836172dbf15f12f 34b280139b1f8f70d78e1432392f03c971be392e8cb68d014eb325d0c101bddd +lib/codeql/rust/elements/internal/generated/CallExprBase.qll cce796e36847249f416629bacf3ea146313084de3374587412e66c10d2917b83 c219aa2174321c161a4a742ca0605521687ca9a5ca32db453a5c62db6f7784cc lib/codeql/rust/elements/internal/generated/CastExpr.qll d6fbf02e9e202254666082a9116634d0eb933177866ac4c0a57b5e9c4bb4b383 477f67773492e3b82695461d56327c9db05a7d1a67e8d192406265f2ce369670 lib/codeql/rust/elements/internal/generated/ClosureBinder.qll 94c0dcdd4cd87d115659d496c88a98354bc7d4ddc0fa27028003bf7688b99987 d59d713b426dbbdb775df9092d176eea031dac1f14e468810f2fc8591399cd19 lib/codeql/rust/elements/internal/generated/ClosureExpr.qll a10596deeb7b9799f0c0d9e9dfe43f5ff58ba03a9a444d581a240a99ca06a949 e94c2f6cd0190d108d0b91340227d45fb6b8c8c2c6a0476358fe75ea7f7a7760 @@ -520,7 +523,7 @@ lib/codeql/rust/elements/internal/generated/MatchArmList.qll 13362680c037fe83fef lib/codeql/rust/elements/internal/generated/MatchExpr.qll 689d65f690fe05bc262d0a5bfe69bb4f8a142db387c5765fcc4958a9b49989f8 2979cd2017d0538870d17b2b7592c75cc05b706bd36c9de3e5dc38fa3a957e5b lib/codeql/rust/elements/internal/generated/MatchGuard.qll 521a507883963106780f1782084c581fbcf1179863c7c15438c4db79e30e78dd 6226feffaaa8d828a42ece0c693e616cd375672eb987c3b7ff1ca15fa23c116a lib/codeql/rust/elements/internal/generated/Meta.qll 38fca2c9958b4179de311546fe0850319010aca9cd17c97d57e12b521c5d0947 740f99c9d41044ceebfcc9d29baaa22f59c11a40f45502a34aa587d423c018f8 -lib/codeql/rust/elements/internal/generated/MethodCallExpr.qll c2d6faf1f840628dbc5aa59c90dbd8b244f6bd4a7dba25e410047fcde11ff378 2d0251b095bf15b0275d493efdd1f9ce0926a3cff6671bb550a7a672aaf62a30 +lib/codeql/rust/elements/internal/generated/MethodCallExpr.qll 0966b268c9d71a8007044d608935e0c07d2144eaafef4812ef259d68b00a06f4 b3a5ab7ec79a6cfa55f671288b8c7c946883fd2edc0b3fac68221ab742cf8604 lib/codeql/rust/elements/internal/generated/Missing.qll 16735d91df04a4e1ae52fae25db5f59a044e540755734bbab46b5fbb0fe6b0bd 28ca4e49fb7e6b4734be2f2f69e7c224c570344cc160ef80c5a5cd413e750dad lib/codeql/rust/elements/internal/generated/Module.qll ebae5d8963c9fd569c0fbad1d7770abd3fd2479437f236cbce0505ba9f9af52c fa3c382115fed18a26f1a755d8749a201b9489f82c09448a88fb8e9e1435fe5f lib/codeql/rust/elements/internal/generated/Name.qll 12aad57744b7d1b04454159536409244c47319aedd580acb58ee93ef9d7f837d 63fc67ccc085db22f82576a53489f15216a7c29d5b941b14a965eab481534e2e @@ -533,7 +536,7 @@ lib/codeql/rust/elements/internal/generated/ParamList.qll c808c9d84dd7800573832b lib/codeql/rust/elements/internal/generated/ParenExpr.qll bc0731505bfe88516205ec360582a4222d2681d11342c93e15258590ddee82f2 d4bd6e0c80cf1d63746c88d4bcb3a01d4c75732e5da09e3ebd9437ced227fb60 lib/codeql/rust/elements/internal/generated/ParenPat.qll ce24b8f8ecbf0f204af200317405724063887257460c80cf250c39b2fdf37185 e7c87d37e1a0ca7ea03840017e1aa9ddb7f927f1f3b6396c0305b46aeee33db6 lib/codeql/rust/elements/internal/generated/ParenType.qll 9cc954d73f8330dcac7b475f97748b63af5c8766dee9d2f2872c0a7e4c903537 c07534c8a9c683c4a9b11d490095647e420de0a0bfc23273eaf6f31b00244273 -lib/codeql/rust/elements/internal/generated/ParentChild.qll 665db548af6857d2cd5c859237b9ec08fc611bccafa1fd6dad703e247b43bf7f 64c6406626a14ed3052d3996cc47fc91e435175bd982440d948416cf878400fd +lib/codeql/rust/elements/internal/generated/ParentChild.qll 9c600678b3616c3c263fa317753a9ca8ad4ed7efd0e5195dd7eade054c513692 8000db77bab203447063283adb8d0835731c802bc17ef4ffb39cbdb855cef993 lib/codeql/rust/elements/internal/generated/Pat.qll 3605ac062be2f294ee73336e9669027b8b655f4ad55660e1eab35266275154ee 7f9400db2884d336dd1d21df2a8093759c2a110be9bf6482ce8e80ae0fd74ed4 lib/codeql/rust/elements/internal/generated/Path.qll 299abce24762a5ab023f3cf1ab9718b83047e171aed42a8092e7a155914b1657 db1a23d18640c548f08c9f94823838b5e019ac85877c7b15df2d1493d1846572 lib/codeql/rust/elements/internal/generated/PathExpr.qll 17cdb0a7393258a207450f08e37178fc9d35d167f064ba6015be94246f3dc933 a75fdd280aff6d87e083a92030e041c2eb52b57cf7151d4a6989fcd31d6a64bf @@ -545,7 +548,7 @@ lib/codeql/rust/elements/internal/generated/PtrType.qll 40099c5a4041314b66932dfd lib/codeql/rust/elements/internal/generated/PureSynthConstructors.qll dc03515d678ba052c2ff2dd9f0883e0bce54cac740ba9a15e5173f292c1b6971 dc03515d678ba052c2ff2dd9f0883e0bce54cac740ba9a15e5173f292c1b6971 lib/codeql/rust/elements/internal/generated/RangeExpr.qll 23cca03bf43535f33b22a38894f70d669787be4e4f5b8fe5c8f7b964d30e9027 18624cef6c6b679eeace2a98737e472432e0ead354cca02192b4d45330f047c9 lib/codeql/rust/elements/internal/generated/RangePat.qll efd93730de217cf50dcba5875595263a5eadf9f7e4e1272401342a094d158614 229b251b3d118932e31e78ac4dfb75f48b766f240f20d436062785606d44467b -lib/codeql/rust/elements/internal/generated/Raw.qll 1936bd8e75e09639d148321d88a6ba930ccc3e7c8458f052699cbddee43ff448 03c591c9f8333e9490224672df26d4cbbc2b9ff5916e36d2a7ee3d5fd9b8c3ed +lib/codeql/rust/elements/internal/generated/Raw.qll 632497608201b6c7bafcb093c0a1e115cec75a648b06e831c2116d88fd29a435 7c8736dfdd22fdbfce8ee8858144da538c4327e8ca880bd92a6e7feaa1199d7d lib/codeql/rust/elements/internal/generated/RecordExpr.qll eb6cb662e463f9260efae1a6ce874fa781172063b916ef1963f861e9942d308d 1a21cbccc8f3799ff13281e822818ebfb21d81591720a427cac3625512cb9d40 lib/codeql/rust/elements/internal/generated/RecordExprField.qll 7e9f8663d3b74ebbc9603b10c9912f082febba6bd73d344b100bbd3edf837802 fbe6b578e7fd5d5a6f21bbb8c388957ab7210a6a249ec71510a50fb35b319ea1 lib/codeql/rust/elements/internal/generated/RecordExprFieldList.qll 179a97211fe7aa6265085d4d54115cdbc0e1cd7c9b2135591e8f36d6432f13d3 dd44bbbc1e83a1ed3a587afb729d7debf7aeb7b63245de181726af13090e50c0 @@ -570,7 +573,7 @@ lib/codeql/rust/elements/internal/generated/Static.qll 5fbd6879858cf356d4bdaa6da lib/codeql/rust/elements/internal/generated/Stmt.qll 8473ff532dd5cc9d7decaddcd174b94d610f6ca0aec8e473cc051dad9f3db917 6ef7d2b5237c2dbdcacbf7d8b39109d4dc100229f2b28b5c9e3e4fbf673ba72b lib/codeql/rust/elements/internal/generated/StmtList.qll a667193e32341e17400867c6e359878c4e645ef9f5f4d97676afc0283a33a026 a320ed678ee359302e2fc1b70a9476705cd616fcfa44a499d32f0c7715627f73 lib/codeql/rust/elements/internal/generated/Struct.qll 4d57f0db12dc7ad3e31e750a24172ef1505406b4dab16386af0674bd18bf8f4b 1a73c83df926b996f629316f74c61ea775be04532ab61b56af904223354f033e -lib/codeql/rust/elements/internal/generated/Synth.qll 99fa143232f2cfb1ef3f6ed6a51afa634c336361105e37719ce11ca6c74de8ee b3b77e1bdea36022b3be7cef000e7113059eb8b2b1afec26ae1d62e84259143b +lib/codeql/rust/elements/internal/generated/Synth.qll a87bb2f82978d4baf9234627d2c7769f2395ab6d164b12b72011f96a95096ce4 0342246219252dd29608e07398f4036d99d9b88d9b2e8e9873a93e9bb6d9535c lib/codeql/rust/elements/internal/generated/SynthConstructors.qll 518b68ccf6d0791bc0c141486261108bb1723e37743fc7f8e4167a1d61660531 518b68ccf6d0791bc0c141486261108bb1723e37743fc7f8e4167a1d61660531 lib/codeql/rust/elements/internal/generated/Token.qll 77a91a25ca5669703cf3a4353b591cef4d72caa6b0b9db07bb9e005d69c848d1 2fdffc4882ed3a6ca9ac6d1fb5f1ac5a471ca703e2ffdc642885fa558d6e373b lib/codeql/rust/elements/internal/generated/TokenTree.qll 8577c2b097c1be2f0f7daa5acfcf146f78674a424d99563e08a84dd3e6d91b46 d2f30764e84dbfc0a6a5d3d8a5f935cd432413688cb32da9c94e420fbc10665c @@ -605,7 +608,7 @@ lib/codeql/rust/elements/internal/generated/WhileExpr.qll fec8a9211b82a80601bf73 lib/codeql/rust/elements/internal/generated/WildcardPat.qll d74b70b57a0a66bfae017a329352a5b27a6b9e73dd5521d627f680e810c6c59e 4b913b548ba27ff3c82fcd32cf996ff329cb57d176d3bebd0fcef394486ea499 lib/codeql/rust/elements/internal/generated/YeetExpr.qll cac328200872a35337b4bcb15c851afb4743f82c080f9738d295571eb01d7392 94af734eea08129b587fed849b643e7572800e8330c0b57d727d41abda47930b lib/codeql/rust/elements/internal/generated/YieldExpr.qll 37e5f0c1e373a22bbc53d8b7f2c0e1f476e5be5080b8437c5e964f4e83fad79a 4a9a68643401637bf48e5c2b2f74a6bf0ddcb4ff76f6bffb61d436b685621e85 -lib/codeql/rust/elements.qll 926e6e5f994ef7fcd04854c4d69004d7bfd81950e132c9d3d501b4b2420db222 926e6e5f994ef7fcd04854c4d69004d7bfd81950e132c9d3d501b4b2420db222 +lib/codeql/rust/elements.qll 78908ca1e1988b47323eb47fa58bcceeb984022fa40f89fb0af4f7219d2dd77b 78908ca1e1988b47323eb47fa58bcceeb984022fa40f89fb0af4f7219d2dd77b test/extractor-tests/generated/Abi/Abi.ql 7f6e7dc4af86eca3ebdc79b10373988cd0871bd78b51997d3cffd969105e5fdd 2f936b6ca005c6157c755121584410c03e4a3949c23bee302fbe05ee10ce118f test/extractor-tests/generated/Abi/Abi_getAbiString.ql a496762fcec5a0887b87023bbf93e9b650f02e20113e25c44d6e4281ae8f5335 14109c7ce11ba25e3cd6e7f1b3fcb4cb00622f2a4eac91bfe43145c5f366bc52 test/extractor-tests/generated/ArgList/ArgList.ql e412927756e72165d0e7c5c9bd3fca89d08197bbf760db8fb7683c64bb2229bc 043dba8506946fbb87753e22c387987d7eded6ddb963aa067f9e60ef9024d684 diff --git a/rust/ql/.gitattributes b/rust/ql/.gitattributes index e69d7ea5791..6069457be45 100644 --- a/rust/ql/.gitattributes +++ b/rust/ql/.gitattributes @@ -17,6 +17,7 @@ /lib/codeql/rust/elements/BoxPat.qll linguist-generated /lib/codeql/rust/elements/BreakExpr.qll linguist-generated /lib/codeql/rust/elements/CallExpr.qll linguist-generated +/lib/codeql/rust/elements/CallExprBase.qll linguist-generated /lib/codeql/rust/elements/CastExpr.qll linguist-generated /lib/codeql/rust/elements/ClosureBinder.qll linguist-generated /lib/codeql/rust/elements/ClosureExpr.qll linguist-generated @@ -185,6 +186,7 @@ /lib/codeql/rust/elements/internal/BoxPatConstructor.qll linguist-generated /lib/codeql/rust/elements/internal/BoxPatImpl.qll linguist-generated /lib/codeql/rust/elements/internal/BreakExprConstructor.qll linguist-generated +/lib/codeql/rust/elements/internal/CallExprBaseImpl.qll linguist-generated /lib/codeql/rust/elements/internal/CallExprConstructor.qll linguist-generated /lib/codeql/rust/elements/internal/CallExprImpl.qll linguist-generated /lib/codeql/rust/elements/internal/CastExprConstructor.qll linguist-generated @@ -462,6 +464,7 @@ /lib/codeql/rust/elements/internal/generated/BoxPat.qll linguist-generated /lib/codeql/rust/elements/internal/generated/BreakExpr.qll linguist-generated /lib/codeql/rust/elements/internal/generated/CallExpr.qll linguist-generated +/lib/codeql/rust/elements/internal/generated/CallExprBase.qll linguist-generated /lib/codeql/rust/elements/internal/generated/CastExpr.qll linguist-generated /lib/codeql/rust/elements/internal/generated/ClosureBinder.qll linguist-generated /lib/codeql/rust/elements/internal/generated/ClosureExpr.qll linguist-generated diff --git a/rust/ql/lib/codeql/rust/elements.qll b/rust/ql/lib/codeql/rust/elements.qll index 4abbb0b4148..77aad9315c1 100644 --- a/rust/ql/lib/codeql/rust/elements.qll +++ b/rust/ql/lib/codeql/rust/elements.qll @@ -20,6 +20,7 @@ import codeql.rust.elements.BlockExpr import codeql.rust.elements.BoxPat import codeql.rust.elements.BreakExpr import codeql.rust.elements.CallExpr +import codeql.rust.elements.CallExprBase import codeql.rust.elements.CastExpr import codeql.rust.elements.ClosureBinder import codeql.rust.elements.ClosureExpr diff --git a/rust/ql/lib/codeql/rust/elements/CallExpr.qll b/rust/ql/lib/codeql/rust/elements/CallExpr.qll index 7047d6a8c3c..ab5631b07ca 100644 --- a/rust/ql/lib/codeql/rust/elements/CallExpr.qll +++ b/rust/ql/lib/codeql/rust/elements/CallExpr.qll @@ -4,8 +4,7 @@ */ private import internal.CallExprImpl -import codeql.rust.elements.ArgList -import codeql.rust.elements.Attr +import codeql.rust.elements.CallExprBase import codeql.rust.elements.Expr /** diff --git a/rust/ql/lib/codeql/rust/elements/CallExprBase.qll b/rust/ql/lib/codeql/rust/elements/CallExprBase.qll new file mode 100644 index 00000000000..d59c4c705f7 --- /dev/null +++ b/rust/ql/lib/codeql/rust/elements/CallExprBase.qll @@ -0,0 +1,14 @@ +// generated by codegen, do not edit +/** + * This module provides the public class `CallExprBase`. + */ + +private import internal.CallExprBaseImpl +import codeql.rust.elements.ArgList +import codeql.rust.elements.Attr +import codeql.rust.elements.Expr + +/** + * A function or method call expression. See `CallExpr` and `MethodCallExpr` for further details. + */ +final class CallExprBase = Impl::CallExprBase; diff --git a/rust/ql/lib/codeql/rust/elements/MethodCallExpr.qll b/rust/ql/lib/codeql/rust/elements/MethodCallExpr.qll index ec3d305f63c..fca8b086134 100644 --- a/rust/ql/lib/codeql/rust/elements/MethodCallExpr.qll +++ b/rust/ql/lib/codeql/rust/elements/MethodCallExpr.qll @@ -4,8 +4,7 @@ */ private import internal.MethodCallExprImpl -import codeql.rust.elements.ArgList -import codeql.rust.elements.Attr +import codeql.rust.elements.CallExprBase import codeql.rust.elements.Expr import codeql.rust.elements.GenericArgList import codeql.rust.elements.NameRef diff --git a/rust/ql/lib/codeql/rust/elements/internal/CallExprBaseImpl.qll b/rust/ql/lib/codeql/rust/elements/internal/CallExprBaseImpl.qll new file mode 100644 index 00000000000..332ba0fb6b3 --- /dev/null +++ b/rust/ql/lib/codeql/rust/elements/internal/CallExprBaseImpl.qll @@ -0,0 +1,19 @@ +// generated by codegen, remove this comment if you wish to edit this file +/** + * This module provides a hand-modifiable wrapper around the generated class `CallExprBase`. + * + * INTERNAL: Do not use. + */ + +private import codeql.rust.elements.internal.generated.CallExprBase + +/** + * INTERNAL: This module contains the customizable definition of `CallExprBase` and should not + * be referenced directly. + */ +module Impl { + /** + * A function or method call expression. See `CallExpr` and `MethodCallExpr` for further details. + */ + class CallExprBase extends Generated::CallExprBase { } +} diff --git a/rust/ql/lib/codeql/rust/elements/internal/generated/CallExpr.qll b/rust/ql/lib/codeql/rust/elements/internal/generated/CallExpr.qll index f7b27e6e2a8..2e41b664a4e 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/generated/CallExpr.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/generated/CallExpr.qll @@ -6,10 +6,8 @@ private import codeql.rust.elements.internal.generated.Synth private import codeql.rust.elements.internal.generated.Raw -import codeql.rust.elements.ArgList -import codeql.rust.elements.Attr +import codeql.rust.elements.internal.CallExprBaseImpl::Impl as CallExprBaseImpl import codeql.rust.elements.Expr -import codeql.rust.elements.internal.ExprImpl::Impl as ExprImpl /** * INTERNAL: This module contains the fully generated definition of `CallExpr` and should not @@ -27,40 +25,9 @@ module Generated { * INTERNAL: Do not reference the `Generated::CallExpr` class directly. * Use the subclass `CallExpr`, where the following predicates are available. */ - class CallExpr extends Synth::TCallExpr, ExprImpl::Expr { + class CallExpr extends Synth::TCallExpr, CallExprBaseImpl::CallExprBase { override string getAPrimaryQlClass() { result = "CallExpr" } - /** - * Gets the argument list of this call expression, if it exists. - */ - ArgList getArgList() { - result = - Synth::convertArgListFromRaw(Synth::convertCallExprToRaw(this).(Raw::CallExpr).getArgList()) - } - - /** - * Holds if `getArgList()` exists. - */ - final predicate hasArgList() { exists(this.getArgList()) } - - /** - * Gets the `index`th attr of this call expression (0-based). - */ - Attr getAttr(int index) { - result = - Synth::convertAttrFromRaw(Synth::convertCallExprToRaw(this).(Raw::CallExpr).getAttr(index)) - } - - /** - * Gets any of the attrs of this call expression. - */ - final Attr getAnAttr() { result = this.getAttr(_) } - - /** - * Gets the number of attrs of this call expression. - */ - final int getNumberOfAttrs() { result = count(int i | exists(this.getAttr(i))) } - /** * Gets the expression of this call expression, if it exists. */ diff --git a/rust/ql/lib/codeql/rust/elements/internal/generated/CallExprBase.qll b/rust/ql/lib/codeql/rust/elements/internal/generated/CallExprBase.qll new file mode 100644 index 00000000000..046558c356d --- /dev/null +++ b/rust/ql/lib/codeql/rust/elements/internal/generated/CallExprBase.qll @@ -0,0 +1,59 @@ +// generated by codegen, do not edit +/** + * This module provides the generated definition of `CallExprBase`. + * INTERNAL: Do not import directly. + */ + +private import codeql.rust.elements.internal.generated.Synth +private import codeql.rust.elements.internal.generated.Raw +import codeql.rust.elements.ArgList +import codeql.rust.elements.Attr +import codeql.rust.elements.internal.ExprImpl::Impl as ExprImpl + +/** + * INTERNAL: This module contains the fully generated definition of `CallExprBase` and should not + * be referenced directly. + */ +module Generated { + /** + * A function or method call expression. See `CallExpr` and `MethodCallExpr` for further details. + * INTERNAL: Do not reference the `Generated::CallExprBase` class directly. + * Use the subclass `CallExprBase`, where the following predicates are available. + */ + class CallExprBase extends Synth::TCallExprBase, ExprImpl::Expr { + /** + * Gets the argument list of this call expression base, if it exists. + */ + ArgList getArgList() { + result = + Synth::convertArgListFromRaw(Synth::convertCallExprBaseToRaw(this) + .(Raw::CallExprBase) + .getArgList()) + } + + /** + * Holds if `getArgList()` exists. + */ + final predicate hasArgList() { exists(this.getArgList()) } + + /** + * Gets the `index`th attr of this call expression base (0-based). + */ + Attr getAttr(int index) { + result = + Synth::convertAttrFromRaw(Synth::convertCallExprBaseToRaw(this) + .(Raw::CallExprBase) + .getAttr(index)) + } + + /** + * Gets any of the attrs of this call expression base. + */ + final Attr getAnAttr() { result = this.getAttr(_) } + + /** + * Gets the number of attrs of this call expression base. + */ + final int getNumberOfAttrs() { result = count(int i | exists(this.getAttr(i))) } + } +} diff --git a/rust/ql/lib/codeql/rust/elements/internal/generated/MethodCallExpr.qll b/rust/ql/lib/codeql/rust/elements/internal/generated/MethodCallExpr.qll index 0cc8f243706..4aeb89e8e85 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/generated/MethodCallExpr.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/generated/MethodCallExpr.qll @@ -6,10 +6,8 @@ private import codeql.rust.elements.internal.generated.Synth private import codeql.rust.elements.internal.generated.Raw -import codeql.rust.elements.ArgList -import codeql.rust.elements.Attr +import codeql.rust.elements.internal.CallExprBaseImpl::Impl as CallExprBaseImpl import codeql.rust.elements.Expr -import codeql.rust.elements.internal.ExprImpl::Impl as ExprImpl import codeql.rust.elements.GenericArgList import codeql.rust.elements.NameRef @@ -27,44 +25,9 @@ module Generated { * INTERNAL: Do not reference the `Generated::MethodCallExpr` class directly. * Use the subclass `MethodCallExpr`, where the following predicates are available. */ - class MethodCallExpr extends Synth::TMethodCallExpr, ExprImpl::Expr { + class MethodCallExpr extends Synth::TMethodCallExpr, CallExprBaseImpl::CallExprBase { override string getAPrimaryQlClass() { result = "MethodCallExpr" } - /** - * Gets the argument list of this method call expression, if it exists. - */ - ArgList getArgList() { - result = - Synth::convertArgListFromRaw(Synth::convertMethodCallExprToRaw(this) - .(Raw::MethodCallExpr) - .getArgList()) - } - - /** - * Holds if `getArgList()` exists. - */ - final predicate hasArgList() { exists(this.getArgList()) } - - /** - * Gets the `index`th attr of this method call expression (0-based). - */ - Attr getAttr(int index) { - result = - Synth::convertAttrFromRaw(Synth::convertMethodCallExprToRaw(this) - .(Raw::MethodCallExpr) - .getAttr(index)) - } - - /** - * Gets any of the attrs of this method call expression. - */ - final Attr getAnAttr() { result = this.getAttr(_) } - - /** - * Gets the number of attrs of this method call expression. - */ - final int getNumberOfAttrs() { result = count(int i | exists(this.getAttr(i))) } - /** * Gets the generic argument list of this method call expression, if it exists. */ diff --git a/rust/ql/lib/codeql/rust/elements/internal/generated/ParentChild.qll b/rust/ql/lib/codeql/rust/elements/internal/generated/ParentChild.qll index a5c77c02914..5a895eff78b 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/generated/ParentChild.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/generated/ParentChild.qll @@ -1380,14 +1380,15 @@ private module Impl { ) } - private Element getImmediateChildOfCallExpr(CallExpr e, int index, string partialPredicateCall) { - exists(int b, int bExpr, int n, int nArgList, int nAttr, int nExpr | + private Element getImmediateChildOfCallExprBase( + CallExprBase e, int index, string partialPredicateCall + ) { + exists(int b, int bExpr, int n, int nArgList, int nAttr | b = 0 and bExpr = b + 1 + max(int i | i = -1 or exists(getImmediateChildOfExpr(e, i, _)) | i) and n = bExpr and nArgList = n + 1 and nAttr = nArgList + 1 + max(int i | i = -1 or exists(e.getAttr(i)) | i) and - nExpr = nAttr + 1 and ( none() or @@ -1397,8 +1398,6 @@ private module Impl { or result = e.getAttr(index - nArgList) and partialPredicateCall = "Attr(" + (index - nArgList).toString() + ")" - or - index = nAttr and result = e.getExpr() and partialPredicateCall = "Expr()" ) ) } @@ -2058,42 +2057,6 @@ private module Impl { ) } - private Element getImmediateChildOfMethodCallExpr( - MethodCallExpr e, int index, string partialPredicateCall - ) { - exists( - int b, int bExpr, int n, int nArgList, int nAttr, int nGenericArgList, int nNameRef, - int nReceiver - | - b = 0 and - bExpr = b + 1 + max(int i | i = -1 or exists(getImmediateChildOfExpr(e, i, _)) | i) and - n = bExpr and - nArgList = n + 1 and - nAttr = nArgList + 1 + max(int i | i = -1 or exists(e.getAttr(i)) | i) and - nGenericArgList = nAttr + 1 and - nNameRef = nGenericArgList + 1 and - nReceiver = nNameRef + 1 and - ( - none() - or - result = getImmediateChildOfExpr(e, index - b, partialPredicateCall) - or - index = n and result = e.getArgList() and partialPredicateCall = "ArgList()" - or - result = e.getAttr(index - nArgList) and - partialPredicateCall = "Attr(" + (index - nArgList).toString() + ")" - or - index = nAttr and - result = e.getGenericArgList() and - partialPredicateCall = "GenericArgList()" - or - index = nGenericArgList and result = e.getNameRef() and partialPredicateCall = "NameRef()" - or - index = nNameRef and result = e.getReceiver() and partialPredicateCall = "Receiver()" - ) - ) - } - private Element getImmediateChildOfNeverType(NeverType e, int index, string partialPredicateCall) { exists(int b, int bTypeRef, int n | b = 0 and @@ -2780,6 +2743,23 @@ private module Impl { ) } + private Element getImmediateChildOfCallExpr(CallExpr e, int index, string partialPredicateCall) { + exists(int b, int bCallExprBase, int n, int nExpr | + b = 0 and + bCallExprBase = + b + 1 + max(int i | i = -1 or exists(getImmediateChildOfCallExprBase(e, i, _)) | i) and + n = bCallExprBase and + nExpr = n + 1 and + ( + none() + or + result = getImmediateChildOfCallExprBase(e, index - b, partialPredicateCall) + or + index = n and result = e.getExpr() and partialPredicateCall = "Expr()" + ) + ) + } + private Element getImmediateChildOfConst(Const e, int index, string partialPredicateCall) { exists( int b, int bAssocItem, int bItem, int n, int nAttr, int nBody, int nName, int nTy, @@ -3096,6 +3076,31 @@ private module Impl { ) } + private Element getImmediateChildOfMethodCallExpr( + MethodCallExpr e, int index, string partialPredicateCall + ) { + exists(int b, int bCallExprBase, int n, int nGenericArgList, int nNameRef, int nReceiver | + b = 0 and + bCallExprBase = + b + 1 + max(int i | i = -1 or exists(getImmediateChildOfCallExprBase(e, i, _)) | i) and + n = bCallExprBase and + nGenericArgList = n + 1 and + nNameRef = nGenericArgList + 1 and + nReceiver = nNameRef + 1 and + ( + none() + or + result = getImmediateChildOfCallExprBase(e, index - b, partialPredicateCall) + or + index = n and result = e.getGenericArgList() and partialPredicateCall = "GenericArgList()" + or + index = nGenericArgList and result = e.getNameRef() and partialPredicateCall = "NameRef()" + or + index = nNameRef and result = e.getReceiver() and partialPredicateCall = "Receiver()" + ) + ) + } + private Element getImmediateChildOfModule(Module e, int index, string partialPredicateCall) { exists(int b, int bItem, int n, int nAttr, int nItemList, int nName, int nVisibility | b = 0 and @@ -3519,8 +3524,6 @@ private module Impl { or result = getImmediateChildOfBreakExpr(e, index, partialAccessor) or - result = getImmediateChildOfCallExpr(e, index, partialAccessor) - or result = getImmediateChildOfCastExpr(e, index, partialAccessor) or result = getImmediateChildOfClosureExpr(e, index, partialAccessor) @@ -3581,8 +3584,6 @@ private module Impl { or result = getImmediateChildOfMatchExpr(e, index, partialAccessor) or - result = getImmediateChildOfMethodCallExpr(e, index, partialAccessor) - or result = getImmediateChildOfNeverType(e, index, partialAccessor) or result = getImmediateChildOfOffsetOfExpr(e, index, partialAccessor) @@ -3655,6 +3656,8 @@ private module Impl { or result = getImmediateChildOfYieldExpr(e, index, partialAccessor) or + result = getImmediateChildOfCallExpr(e, index, partialAccessor) + or result = getImmediateChildOfConst(e, index, partialAccessor) or result = getImmediateChildOfEnum(e, index, partialAccessor) @@ -3673,6 +3676,8 @@ private module Impl { or result = getImmediateChildOfMacroRules(e, index, partialAccessor) or + result = getImmediateChildOfMethodCallExpr(e, index, partialAccessor) + or result = getImmediateChildOfModule(e, index, partialAccessor) or result = getImmediateChildOfStatic(e, index, partialAccessor) diff --git a/rust/ql/lib/codeql/rust/elements/internal/generated/Raw.qll b/rust/ql/lib/codeql/rust/elements/internal/generated/Raw.qll index 26330df6831..04c3e68d5ba 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/generated/Raw.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/generated/Raw.qll @@ -1447,31 +1447,18 @@ module Raw { /** * INTERNAL: Do not use. - * A function call expression. For example: - * ```rust - * foo(42); - * foo::(42); - * foo[0](42); - * foo(1) = 4; - * ``` + * A function or method call expression. See `CallExpr` and `MethodCallExpr` for further details. */ - class CallExpr extends @call_expr, Expr { - override string toString() { result = "CallExpr" } + class CallExprBase extends @call_expr_base, Expr { + /** + * Gets the argument list of this call expression base, if it exists. + */ + ArgList getArgList() { call_expr_base_arg_lists(this, result) } /** - * Gets the argument list of this call expression, if it exists. + * Gets the `index`th attr of this call expression base (0-based). */ - ArgList getArgList() { call_expr_arg_lists(this, result) } - - /** - * Gets the `index`th attr of this call expression (0-based). - */ - Attr getAttr(int index) { call_expr_attrs(this, index, result) } - - /** - * Gets the expression of this call expression, if it exists. - */ - Expr getExpr() { call_expr_exprs(this, result) } + Attr getAttr(int index) { call_expr_base_attrs(this, index, result) } } /** @@ -2316,43 +2303,6 @@ module Raw { MatchArmList getMatchArmList() { match_expr_match_arm_lists(this, result) } } - /** - * INTERNAL: Do not use. - * A method call expression. For example: - * ```rust - * x.foo(42); - * x.foo::(42); - * ``` - */ - class MethodCallExpr extends @method_call_expr, Expr { - override string toString() { result = "MethodCallExpr" } - - /** - * Gets the argument list of this method call expression, if it exists. - */ - ArgList getArgList() { method_call_expr_arg_lists(this, result) } - - /** - * Gets the `index`th attr of this method call expression (0-based). - */ - Attr getAttr(int index) { method_call_expr_attrs(this, index, result) } - - /** - * Gets the generic argument list of this method call expression, if it exists. - */ - GenericArgList getGenericArgList() { method_call_expr_generic_arg_lists(this, result) } - - /** - * Gets the name reference of this method call expression, if it exists. - */ - NameRef getNameRef() { method_call_expr_name_refs(this, result) } - - /** - * Gets the receiver of this method call expression, if it exists. - */ - Expr getReceiver() { method_call_expr_receivers(this, result) } - } - /** * INTERNAL: Do not use. * A NeverType. For example: @@ -3144,6 +3094,25 @@ module Raw { Expr getExpr() { yield_expr_exprs(this, result) } } + /** + * INTERNAL: Do not use. + * A function call expression. For example: + * ```rust + * foo(42); + * foo::(42); + * foo[0](42); + * foo(1) = 4; + * ``` + */ + class CallExpr extends @call_expr, CallExprBase { + override string toString() { result = "CallExpr" } + + /** + * Gets the expression of this call expression, if it exists. + */ + Expr getExpr() { call_expr_exprs(this, result) } + } + /** * INTERNAL: Do not use. * A Const. For example: @@ -3534,6 +3503,33 @@ module Raw { Visibility getVisibility() { macro_rules_visibilities(this, result) } } + /** + * INTERNAL: Do not use. + * A method call expression. For example: + * ```rust + * x.foo(42); + * x.foo::(42); + * ``` + */ + class MethodCallExpr extends @method_call_expr, CallExprBase { + override string toString() { result = "MethodCallExpr" } + + /** + * Gets the generic argument list of this method call expression, if it exists. + */ + GenericArgList getGenericArgList() { method_call_expr_generic_arg_lists(this, result) } + + /** + * Gets the name reference of this method call expression, if it exists. + */ + NameRef getNameRef() { method_call_expr_name_refs(this, result) } + + /** + * Gets the receiver of this method call expression, if it exists. + */ + Expr getReceiver() { method_call_expr_receivers(this, result) } + } + /** * INTERNAL: Do not use. * A module declaration. For example: diff --git a/rust/ql/lib/codeql/rust/elements/internal/generated/Synth.qll b/rust/ql/lib/codeql/rust/elements/internal/generated/Synth.qll index 891da3025db..bd3ddf9feb4 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/generated/Synth.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/generated/Synth.qll @@ -603,16 +603,21 @@ module Synth { TUseTree or TUseTreeList or TVariant or TVariantList or TVisibility or TWhereClause or TWherePred; + /** + * INTERNAL: Do not use. + */ + class TCallExprBase = TCallExpr or TMethodCallExpr; + /** * INTERNAL: Do not use. */ class TExpr = TArrayExpr or TAsmExpr or TAwaitExpr or TBecomeExpr or TBinaryExpr or TBlockExpr or - TBreakExpr or TCallExpr or TCastExpr or TClosureExpr or TContinueExpr or TFieldExpr or + TBreakExpr or TCallExprBase or TCastExpr or TClosureExpr or TContinueExpr or TFieldExpr or TForExpr or TFormatArgsExpr or TIfExpr or TIndexExpr or TLetExpr or TLiteralExpr or - TLoopExpr or TMacroExpr or TMatchExpr or TMethodCallExpr or TOffsetOfExpr or TParenExpr or - TPathExpr or TPrefixExpr or TRangeExpr or TRecordExpr or TRefExpr or TReturnExpr or - TTryExpr or TTupleExpr or TUnderscoreExpr or TWhileExpr or TYeetExpr or TYieldExpr; + TLoopExpr or TMacroExpr or TMatchExpr or TOffsetOfExpr or TParenExpr or TPathExpr or + TPrefixExpr or TRangeExpr or TRecordExpr or TRefExpr or TReturnExpr or TTryExpr or + TTupleExpr or TUnderscoreExpr or TWhileExpr or TYeetExpr or TYieldExpr; /** * INTERNAL: Do not use. @@ -1664,6 +1669,16 @@ module Synth { result = convertWherePredFromRaw(e) } + /** + * INTERNAL: Do not use. + * Converts a raw DB element to a synthesized `TCallExprBase`, if possible. + */ + TCallExprBase convertCallExprBaseFromRaw(Raw::Element e) { + result = convertCallExprFromRaw(e) + or + result = convertMethodCallExprFromRaw(e) + } + /** * INTERNAL: Do not use. * Converts a raw DB element to a synthesized `TElement`, if possible. @@ -1693,7 +1708,7 @@ module Synth { or result = convertBreakExprFromRaw(e) or - result = convertCallExprFromRaw(e) + result = convertCallExprBaseFromRaw(e) or result = convertCastExprFromRaw(e) or @@ -1721,8 +1736,6 @@ module Synth { or result = convertMatchExprFromRaw(e) or - result = convertMethodCallExprFromRaw(e) - or result = convertOffsetOfExprFromRaw(e) or result = convertParenExprFromRaw(e) @@ -2934,6 +2947,16 @@ module Synth { result = convertWherePredToRaw(e) } + /** + * INTERNAL: Do not use. + * Converts a synthesized `TCallExprBase` to a raw DB element, if possible. + */ + Raw::Element convertCallExprBaseToRaw(TCallExprBase e) { + result = convertCallExprToRaw(e) + or + result = convertMethodCallExprToRaw(e) + } + /** * INTERNAL: Do not use. * Converts a synthesized `TElement` to a raw DB element, if possible. @@ -2963,7 +2986,7 @@ module Synth { or result = convertBreakExprToRaw(e) or - result = convertCallExprToRaw(e) + result = convertCallExprBaseToRaw(e) or result = convertCastExprToRaw(e) or @@ -2991,8 +3014,6 @@ module Synth { or result = convertMatchExprToRaw(e) or - result = convertMethodCallExprToRaw(e) - or result = convertOffsetOfExprToRaw(e) or result = convertParenExprToRaw(e) diff --git a/rust/ql/lib/rust.dbscheme b/rust/ql/lib/rust.dbscheme index 029fff99f4d..811d90f148d 100644 --- a/rust/ql/lib/rust.dbscheme +++ b/rust/ql/lib/rust.dbscheme @@ -273,7 +273,7 @@ closure_binder_generic_param_lists( | @binary_expr | @block_expr | @break_expr -| @call_expr +| @call_expr_base | @cast_expr | @closure_expr | @continue_expr @@ -287,7 +287,6 @@ closure_binder_generic_param_lists( | @loop_expr | @macro_expr | @match_expr -| @method_call_expr | @offset_of_expr | @paren_expr | @path_expr @@ -1351,29 +1350,24 @@ break_expr_lifetimes( int lifetime: @lifetime ref ); -call_exprs( - unique int id: @call_expr -); +@call_expr_base = + @call_expr +| @method_call_expr +; #keyset[id] -call_expr_arg_lists( - int id: @call_expr ref, +call_expr_base_arg_lists( + int id: @call_expr_base ref, int arg_list: @arg_list ref ); #keyset[id, index] -call_expr_attrs( - int id: @call_expr ref, +call_expr_base_attrs( + int id: @call_expr_base ref, int index: int ref, int attr: @attr ref ); -#keyset[id] -call_expr_exprs( - int id: @call_expr ref, - int expr: @expr ref -); - cast_exprs( unique int id: @cast_expr ); @@ -2007,41 +2001,6 @@ match_expr_match_arm_lists( int match_arm_list: @match_arm_list ref ); -method_call_exprs( - unique int id: @method_call_expr -); - -#keyset[id] -method_call_expr_arg_lists( - int id: @method_call_expr ref, - int arg_list: @arg_list ref -); - -#keyset[id, index] -method_call_expr_attrs( - int id: @method_call_expr ref, - int index: int ref, - int attr: @attr ref -); - -#keyset[id] -method_call_expr_generic_arg_lists( - int id: @method_call_expr ref, - int generic_arg_list: @generic_arg_list ref -); - -#keyset[id] -method_call_expr_name_refs( - int id: @method_call_expr ref, - int name_ref: @name_ref ref -); - -#keyset[id] -method_call_expr_receivers( - int id: @method_call_expr ref, - int receiver: @expr ref -); - never_types( unique int id: @never_type ); @@ -2611,6 +2570,16 @@ yield_expr_exprs( int expr: @expr ref ); +call_exprs( + unique int id: @call_expr +); + +#keyset[id] +call_expr_exprs( + int id: @call_expr ref, + int expr: @expr ref +); + consts( unique int id: @const ); @@ -2987,6 +2956,28 @@ macro_rules_visibilities( int visibility: @visibility ref ); +method_call_exprs( + unique int id: @method_call_expr +); + +#keyset[id] +method_call_expr_generic_arg_lists( + int id: @method_call_expr ref, + int generic_arg_list: @generic_arg_list ref +); + +#keyset[id] +method_call_expr_name_refs( + int id: @method_call_expr ref, + int name_ref: @name_ref ref +); + +#keyset[id] +method_call_expr_receivers( + int id: @method_call_expr ref, + int receiver: @expr ref +); + modules( unique int id: @module ); diff --git a/rust/schema/annotations.py b/rust/schema/annotations.py index b4c647f2654..5dcd085e405 100644 --- a/rust/schema/annotations.py +++ b/rust/schema/annotations.py @@ -185,8 +185,15 @@ class _: ``` """ +class CallExprBase(Expr): + """ + A function or method call expression. See `CallExpr` and `MethodCallExpr` for further details. + """ + arg_list: optional["ArgList"] | child + attrs: list["Attr"] | child -@annotate(CallExpr) + +@annotate(CallExpr, replace_bases={Expr: CallExprBase}) class _: """ A function call expression. For example: @@ -197,9 +204,10 @@ class _: foo(1) = 4; ``` """ + arg_list: drop + attrs: drop - -@annotate(MethodCallExpr) +@annotate(MethodCallExpr, replace_bases={Expr: CallExprBase}) class _: """ A method call expression. For example: @@ -208,6 +216,8 @@ class _: x.foo::(42); ``` """ + arg_list: drop + attrs: drop @annotate(MatchArm)