mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
75 lines
2.1 KiB
Plaintext
75 lines
2.1 KiB
Plaintext
// generated by {{generator}}
|
|
|
|
#![cfg_attr(any(), rustfmt::skip)]
|
|
|
|
use crate::trap;
|
|
{{#classes}}
|
|
|
|
{{#table_name}}
|
|
#[derive(Debug)]
|
|
pub struct {{name}} {
|
|
pub id: trap::TrapId<{{name}}>,
|
|
{{#fields}}
|
|
pub {{field_name}}: {{type}},
|
|
{{/fields}}
|
|
}
|
|
|
|
impl trap::TrapEntry for {{name}} {
|
|
fn class_name() -> &'static str { "{{name}}" }
|
|
|
|
fn extract_id(&mut self) -> trap::TrapId<Self> {
|
|
std::mem::replace(&mut self.id, trap::TrapId::Star)
|
|
}
|
|
|
|
fn emit(self, id: trap::Label<Self>, out: &mut trap::Writer) {
|
|
{{#single_field_entries}}
|
|
out.add_tuple("{{table_name}}", vec![id.into(){{#fields}}, self.{{field_name}}.into(){{/fields}}]);
|
|
{{/single_field_entries}}
|
|
{{#fields}}
|
|
{{#is_predicate}}
|
|
if self.{{field_name}} {
|
|
out.add_tuple("{{table_name}}", vec![id.into()]);
|
|
}
|
|
{{/is_predicate}}
|
|
{{#is_optional}}
|
|
{{^is_repeated}}
|
|
if let Some(v) = self.{{field_name}} {
|
|
out.add_tuple("{{table_name}}", vec![id.into(), v.into()]);
|
|
}
|
|
{{/is_repeated}}
|
|
{{/is_optional}}
|
|
{{#is_repeated}}
|
|
for (i, v) in self.{{field_name}}.into_iter().enumerate() {
|
|
{{^is_optional}}
|
|
out.add_tuple("{{table_name}}", vec![id.into(){{^is_unordered}}, i.into(){{/is_unordered}}, v.into()]);
|
|
{{/is_optional}}
|
|
{{#is_optional}}
|
|
if let Some(v) = v {
|
|
out.add_tuple("{{table_name}}", vec![id.into(){{^is_unordered}}, i.into(){{/is_unordered}}, v.into()]);
|
|
}
|
|
{{/is_optional}}
|
|
}
|
|
{{/is_repeated}}
|
|
{{/fields}}
|
|
}
|
|
}
|
|
{{/table_name}}
|
|
{{^table_name}}
|
|
{{! virtual class, make it unbuildable }}
|
|
pub struct {{name}} {
|
|
unused: ()
|
|
}
|
|
{{/table_name}}
|
|
{{#ancestors}}
|
|
|
|
impl From<trap::Label<{{name}}>> for trap::Label<{{.}}> {
|
|
fn from(value: trap::Label<{{name}}>) -> Self {
|
|
// SAFETY: this is safe because in the dbscheme {{name}} is a subclass of {{.}}
|
|
unsafe {
|
|
Self::from_untyped(value.as_untyped())
|
|
}
|
|
}
|
|
}
|
|
{{/ancestors}}
|
|
{{/classes}}
|