Debian Codegraph @

src/generator/tables.rs

raw symbols SCIP
1 use craterust-analyzer cargo logos-codegen 0.15.1 crate/::utilrust-analyzer cargo logos-codegen 0.15.1 util/::ToIdentrust-analyzer cargo logos-codegen 0.15.1 util/ToIdent#;
2 use proc_macro2rust-analyzer cargo proc-macro2 1.0.95 crate/::{Literalrust-analyzer cargo proc-macro2 1.0.95 Literal#, TokenStreamrust-analyzer cargo proc-macro2 1.0.95 TokenStream#};
3 use quoterust-analyzer cargo quote 1.0.40 crate/::{quoterust-analyzer cargo quote 1.0.40 quote!, ToTokensrust-analyzer cargo quote 1.0.40 to_tokens/ToTokens#};
4 use synrust-analyzer cargo syn 2.0.101 crate/::Identrust-analyzer cargo proc-macro2 1.0.95 Ident#;
5
6 pub struct TableStackrust-analyzer cargo logos-codegen 0.15.1 generator/tables/TableStack# {
7 tablesrust-analyzer cargo logos-codegen 0.15.1 generator/tables/TableStack#tables.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<(Identrust-analyzer cargo proc-macro2 1.0.95 Ident#, [u8; 256])>,
8 shiftrust-analyzer cargo logos-codegen 0.15.1 generator/tables/TableStack#shift.: u8,
9 }
10
11 pub struct TableViewrust-analyzer cargo logos-codegen 0.15.1 generator/tables/TableView#<'a> {
12 identrust-analyzer cargo logos-codegen 0.15.1 generator/tables/TableView#ident.: &'a Identrust-analyzer cargo proc-macro2 1.0.95 Ident#,
13 tablerust-analyzer cargo logos-codegen 0.15.1 generator/tables/TableView#table.: &'a mut [u8; 256],
14 maskrust-analyzer cargo logos-codegen 0.15.1 generator/tables/TableView#mask.: u8,
15 }
16
17 impl TableStackrust-analyzer cargo logos-codegen 0.15.1 generator/tables/TableStack# {
18 pub fn newrust-analyzer cargo logos-codegen 0.15.1 generator/tables/impl#[TableStack]new().() -> Selfrust-analyzer cargo logos-codegen 0.15.1 generator/tables/impl#[TableStack] {
19 TableStackrust-analyzer cargo logos-codegen 0.15.1 generator/tables/TableStack# {
20 tablesrust-analyzer cargo logos-codegen 0.15.1 generator/tables/TableStack#tables.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![("COMPACT_TABLE_0".to_identrust-analyzer cargo logos-codegen 0.15.1 util/impl#[str][ToIdent]to_ident().(), [0; 256])],
21 shiftrust-analyzer cargo logos-codegen 0.15.1 generator/tables/TableStack#shift.: 0,
22 }
23 }
24
25 pub fn viewrust-analyzer cargo logos-codegen 0.15.1 generator/tables/impl#[TableStack]view().(&mut self) -> TableViewrust-analyzer cargo logos-codegen 0.15.1 generator/tables/TableView#<'_> {
26 let mask = if self.shiftrust-analyzer cargo logos-codegen 0.15.1 generator/tables/TableStack#shift. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]lt().8 {
27 // Reusing existing table with a shifted mask
28 let mask = 1u8 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`Shl<Self>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`Shl<Self>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`Shl<Self>`]shl().self.shiftrust-analyzer cargo logos-codegen 0.15.1 generator/tables/TableStack#shift.;
29
30 self.shiftrust-analyzer cargo logos-codegen 0.15.1 generator/tables/TableStack#shift. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`AddAssign<Self>`]add_assign().1;
31
32 mask
33 } else {
34 // Need to create a new table
35 let ident = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("COMPACT_TABLE_{}", self.tablesrust-analyzer cargo logos-codegen 0.15.1 generator/tables/TableStack#tables..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()).to_identrust-analyzer cargo logos-codegen 0.15.1 util/impl#[str][ToIdent]to_ident().();
36
37 self.tablesrust-analyzer cargo logos-codegen 0.15.1 generator/tables/TableStack#tables..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().((ident, [0; 256]));
38 self.shiftrust-analyzer cargo logos-codegen 0.15.1 generator/tables/TableStack#shift. = 1;
39
40 1
41 };
42
43 let (ref ident, ref mut table) = self.tablesrust-analyzer cargo logos-codegen 0.15.1 generator/tables/TableStack#tables..last_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last_mut().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
44
45 TableViewrust-analyzer cargo logos-codegen 0.15.1 generator/tables/TableView# { identrust-analyzer cargo logos-codegen 0.15.1 generator/tables/TableView#ident., tablerust-analyzer cargo logos-codegen 0.15.1 generator/tables/TableView#table., maskrust-analyzer cargo logos-codegen 0.15.1 generator/tables/TableView#mask. }
46 }
47 }
48
49 impl<'a> TableViewrust-analyzer cargo logos-codegen 0.15.1 generator/tables/TableView#<'a> {
50 pub fn identrust-analyzer cargo logos-codegen 0.15.1 generator/tables/impl#[`TableView<'a>`]ident().(&self) -> &'a Identrust-analyzer cargo proc-macro2 1.0.95 Ident# {
51 self.identrust-analyzer cargo logos-codegen 0.15.1 generator/tables/TableView#ident.
52 }
53
54 pub fn flagrust-analyzer cargo logos-codegen 0.15.1 generator/tables/impl#[`TableView<'a>`]flag().(&mut self, byte: u8) {
55 self.tablerust-analyzer cargo logos-codegen 0.15.1 generator/tables/TableView#table.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().byte as usize]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOrAssign<Self>`]bitor_assign().|=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOrAssign<Self>`]bitor_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOrAssign<Self>`]bitor_assign().self.maskrust-analyzer cargo logos-codegen 0.15.1 generator/tables/TableView#mask.;
56 }
57
58 pub fn maskrust-analyzer cargo logos-codegen 0.15.1 generator/tables/impl#[`TableView<'a>`]mask().(&self) -> Literalrust-analyzer cargo proc-macro2 1.0.95 Literal# {
59 Literalrust-analyzer cargo proc-macro2 1.0.95 Literal#::u8_unsuffixedrust-analyzer cargo proc-macro2 1.0.95 impl#[Literal]u8_unsuffixed().(self.maskrust-analyzer cargo logos-codegen 0.15.1 generator/tables/TableView#mask.)
60 }
61 }
62
63 impl ToTokensrust-analyzer cargo quote 1.0.40 to_tokens/ToTokens# for TableStackrust-analyzer cargo logos-codegen 0.15.1 generator/tables/TableStack# {
64 fn to_tokensrust-analyzer cargo logos-codegen 0.15.1 generator/tables/impl#[TableStack][ToTokens]to_tokens().(&self, out: &mut TokenStreamrust-analyzer cargo proc-macro2 1.0.95 TokenStream#) {
65 if self.shiftrust-analyzer cargo logos-codegen 0.15.1 generator/tables/TableStack#shift. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().0 {
66 return;
67 }
68
69 for (ident, table) in self.tablesrust-analyzer cargo logos-codegen 0.15.1 generator/tables/TableStack#tables..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() {
70 let bytes = table.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().copiedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#copied().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(Literalrust-analyzer cargo proc-macro2 1.0.95 Literal#::u8_unsuffixedrust-analyzer cargo proc-macro2 1.0.95 impl#[Literal]u8_unsuffixed().);
71
72 out.extendrust-analyzer cargo proc-macro2 1.0.95 impl#[TokenStream][`Extend<TokenTree>`]extend().(quoterust-analyzer cargo quote 1.0.40 quote!! {
73 static #ident: [u8; 256] = [#(#bytes),*];
74 });
75 }
76 }
77 }