MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / macro_binds_code

Function macro_binds_code

codegraph-kernel/src/rustlang.rs:2151–2180  ·  view source on GitHub ↗

bindsCode: whether a rule's matcher binds only code fragments; its `tt` bindings go into `tts`.

(pattern: Node, src: &'s str, tts: &mut HashSet<&'s str>, depth: u32)

Source from the content-addressed store, hash-verified

2149
2150/// bindsCode: whether a rule's matcher binds only code fragments; its `tt` bindings go into `tts`.
2151fn macro_binds_code<'s>(pattern: Node, src: &'s str, tts: &mut HashSet<&'s str>, depth: u32) -> bool {
2152 if depth > 32 {
2153 return false;
2154 }
2155 for i in 0..pattern.child_count() {
2156 let Some(t) = pattern.child(i) else { continue };
2157 match t.kind() {
2158 "token_binding_pattern" => {
2159 let (Some(name), Some(fragment)) = (t.child_by_field_name("name"), t.child_by_field_name("type")) else {
2160 return false;
2161 };
2162 let kind = macro_tok_text(fragment, src);
2163 if kind == "tt" {
2164 tts.insert(macro_tok_text(name, src));
2165 } else if !MACRO_CODE_FRAGMENTS.contains(&kind) {
2166 return false;
2167 }
2168 }
2169 "token_tree_pattern" | "token_repetition_pattern" => {
2170 if !macro_binds_code(t, src, tts, depth + 1) {
2171 return false;
2172 }
2173 }
2174 // A binding with no fragment written: not one this reads.
2175 "metavariable" => return false,
2176 _ => {}
2177 }
2178 }
2179 true
2180}
2181
2182/// writesBackAsCode: whether a rule's expansion writes none of `tts` in the
2183/// arguments of a macro other than an expression macro. Those it writes as

Callers 1

Calls 1

macro_tok_textFunction · 0.85

Tested by

no test coverage detected