| 72 | } |
| 73 | |
| 74 | fn generate(entries: &[SymbolEntry]) -> TokenStream { |
| 75 | let mut output = TokenStream::new(); |
| 76 | |
| 77 | // 1. SYMBOLS array |
| 78 | let mut symbol_values = Vec::new(); |
| 79 | for entry in entries { |
| 80 | collect_symbol_values(entry, &mut symbol_values); |
| 81 | } |
| 82 | output.extend(quote! { |
| 83 | pub(crate) static SYMBOLS: &[&str] = &[ |
| 84 | #(#symbol_values),* |
| 85 | ]; |
| 86 | }); |
| 87 | |
| 88 | // 2. Constants and modules |
| 89 | let mut counter = 0; |
| 90 | for entry in entries { |
| 91 | generate_entry_constants(entry, &mut counter, &mut output); |
| 92 | } |
| 93 | |
| 94 | // 3. LOOKUP |
| 95 | let mut lookup_entries = Vec::new(); |
| 96 | let mut module_path = Vec::new(); |
| 97 | for entry in entries { |
| 98 | generate_lookup_entry(entry, &mut module_path, &mut lookup_entries); |
| 99 | } |
| 100 | output.extend(quote! { |
| 101 | pub(crate) static LOOKUP: &[(&'static str, super::repr::Repr)] = &[ |
| 102 | #(#lookup_entries),* |
| 103 | ]; |
| 104 | }); |
| 105 | |
| 106 | output |
| 107 | } |
| 108 | |
| 109 | fn collect_symbol_values(entry: &SymbolEntry, values: &mut Vec<TokenStream>) { |
| 110 | match entry { |