Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 590a146

Browse files
author
Paolo Tranquilli
committed
Rust: some basic extraction of function names (with locations!)
1 parent f40901f commit 590a146

54 files changed

Lines changed: 1875 additions & 1015 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ repos:
55
rev: v3.2.0
66
hooks:
77
- id: trailing-whitespace
8-
exclude: /test/.*$(?<!\.ql)(?<!\.qll)(?<!\.qlref)|.*\.patch
8+
exclude: /test/.*$(?<!\.qlref)|.*\.patch$|.*\.qll?$
99
- id: end-of-file-fixer
10-
exclude: /test/.*$(?<!\.ql)(?<!\.qll)(?<!\.qlref)|.*\.patch
10+
exclude: /test/.*$(?<!\.qlref)|.*\.patch$|.*\.qll?$
1111

1212
- repo: https://github.com/pre-commit/mirrors-clang-format
1313
rev: v17.0.6

misc/codegen/lib/rust.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
_field_overrides = [
6161
(
6262
re.compile(r"(start|end)_(line|column)|(.*_)?index|width|num_.*"),
63-
{"base_type": "usize"},
63+
{"base_type": "u32"},
6464
),
6565
(re.compile(r"(.*)_"), lambda m: {"field_name": m[1]}),
6666
]

misc/codegen/templates/rust_classes.mustache

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
// generated by {{generator}}
22

3-
use crate::trap::{TrapLabel, TrapEntry, quoted};
3+
use crate::trap::{TrapLabel, TrapId, TrapEntry, quoted};
44
use std::io::Write;
5-
65
{{#classes}}
6+
77
#[derive(Debug)]
88
pub struct {{name}} {
9-
pub key: Option<String>,
9+
pub id: TrapId,
1010
{{#fields}}
1111
pub {{field_name}}: {{type}},
1212
{{/fields}}
1313
}
1414

1515
impl TrapEntry for {{name}} {
16-
type Label = TrapLabel;
17-
18-
fn prefix() -> &'static str { "{{name}}_" }
19-
20-
fn key(&self) -> Option<&str> { self.key.as_ref().map(String::as_str) }
16+
fn extract_id(&mut self) -> TrapId {
17+
std::mem::replace(&mut self.id, TrapId::Star)
18+
}
2119

22-
fn emit<W: Write>(&self, id: &Self::Label, out: &mut W) -> std::io::Result<()> {
20+
fn emit<W: Write>(self, id: TrapLabel, out: &mut W) -> std::io::Result<()> {
2321
write!(out, "{{table_name}}({id}{{#single_fields}}, {}{{/single_fields}})\n"{{#single_fields}}, {{#emitter}}self.{{field_name}}{{/emitter}}{{/single_fields}})?;
2422
{{#fields}}
2523
{{#is_predicate}}
@@ -50,5 +48,4 @@ impl TrapEntry for {{name}} {
5048
Ok(())
5149
}
5250
}
53-
5451
{{/classes}}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// generated by {{generator}}
2-
32
{{#modules}}
3+
44
mod {{.}};
55
pub use {{.}}::*;
6-
76
{{/modules}}

rust/.generated.list

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/.gitattributes

Lines changed: 37 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)