|
2 | 2 |
|
3 | 3 | #![cfg_attr(any(), rustfmt::skip)] |
4 | 4 |
|
5 | | -use crate::trap::{TrapId, TrapEntry}; |
6 | | -use codeql_extractor::trap; |
| 5 | +use crate::trap; |
7 | 6 | {{#classes}} |
8 | 7 |
|
| 8 | +{{#is_entry}} |
9 | 9 | #[derive(Debug)] |
10 | 10 | pub struct {{name}} { |
11 | | - pub id: TrapId, |
| 11 | + pub id: trap::TrapId<{{name}}>, |
12 | 12 | {{#fields}} |
13 | 13 | pub {{field_name}}: {{type}}, |
14 | 14 | {{/fields}} |
15 | 15 | } |
16 | 16 |
|
17 | | -impl TrapEntry for {{name}} { |
18 | | - fn extract_id(&mut self) -> TrapId { |
19 | | - std::mem::replace(&mut self.id, TrapId::Star) |
| 17 | +impl trap::TrapEntry for {{name}} { |
| 18 | + fn extract_id(&mut self) -> trap::TrapId<Self> { |
| 19 | + std::mem::replace(&mut self.id, trap::TrapId::Star) |
20 | 20 | } |
21 | 21 |
|
22 | | - fn emit(self, id: trap::Label, out: &mut trap::Writer) { |
| 22 | + fn emit(self, id: trap::Label<Self>, out: &mut trap::Writer) { |
23 | 23 | {{#single_field_entries}} |
24 | | - out.add_tuple("{{table_name}}", vec![trap::Arg::Label(id){{#fields}}, self.{{field_name}}.into(){{/fields}}]); |
| 24 | + out.add_tuple("{{entry_table}}", vec![id.into(){{#fields}}, self.{{field_name}}.into(){{/fields}}]); |
25 | 25 | {{/single_field_entries}} |
26 | 26 | {{#fields}} |
27 | 27 | {{#is_predicate}} |
28 | 28 | if self.{{field_name}} { |
29 | | - out.add_tuple("{{table_name}}", vec![trap::Arg::Label(id)]); |
| 29 | + out.add_tuple("{{table_name}}", vec![id.into()]); |
30 | 30 | } |
31 | 31 | {{/is_predicate}} |
32 | 32 | {{#is_optional}} |
33 | 33 | {{^is_repeated}} |
34 | 34 | if let Some(v) = self.{{field_name}} { |
35 | | - out.add_tuple("{{table_name}}", vec![trap::Arg::Label(id), v.into()]); |
| 35 | + out.add_tuple("{{table_name}}", vec![id.into(), v.into()]); |
36 | 36 | } |
37 | 37 | {{/is_repeated}} |
38 | 38 | {{/is_optional}} |
39 | 39 | {{#is_repeated}} |
40 | 40 | for (i, v) in self.{{field_name}}.into_iter().enumerate() { |
41 | 41 | {{^is_optional}} |
42 | | - out.add_tuple("{{table_name}}", vec![trap::Arg::Label(id){{^is_unordered}}, i.into(){{/is_unordered}}, v.into()]); |
| 42 | + out.add_tuple("{{table_name}}", vec![id.into(){{^is_unordered}}, i.into(){{/is_unordered}}, v.into()]); |
43 | 43 | {{/is_optional}} |
44 | 44 | {{#is_optional}} |
45 | 45 | if let Some(v) = v { |
46 | | - out.add_tuple("{{table_name}}", vec![trap::Arg::Label(id){{^is_unordered}}, i.into(){{/is_unordered}}, v.into()]); |
| 46 | + out.add_tuple("{{table_name}}", vec![id.into(){{^is_unordered}}, i.into(){{/is_unordered}}, v.into()]); |
47 | 47 | } |
48 | 48 | {{/is_optional}} |
49 | 49 | } |
50 | 50 | {{/is_repeated}} |
51 | 51 | {{/fields}} |
52 | 52 | } |
53 | 53 | } |
| 54 | +{{/is_entry}} |
| 55 | +{{^is_entry}} |
| 56 | +{{! virtual class, make it unbuildable }} |
| 57 | +#[derive(Debug)] |
| 58 | +pub struct {{name}} { |
| 59 | + _unused: () |
| 60 | +} |
| 61 | +{{/is_entry}} |
| 62 | + |
| 63 | +impl trap::TrapClass for {{name}} { |
| 64 | + fn class_name() -> &'static str { "{{name}}" } |
| 65 | +} |
| 66 | +{{#ancestors}} |
| 67 | +
|
| 68 | +impl From<trap::Label<{{name}}>> for trap::Label<{{.}}> { |
| 69 | + fn from(value: trap::Label<{{name}}>) -> Self { |
| 70 | + // SAFETY: this is safe because in the dbscheme {{name}} is a subclass of {{.}} |
| 71 | + unsafe { |
| 72 | + Self::from_untyped(value.as_untyped()) |
| 73 | + } |
| 74 | + } |
| 75 | +} |
| 76 | +{{/ancestors}} |
54 | 77 | {{/classes}} |
0 commit comments