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

Method visit_in_brace_scope

codegraph-kernel/src/ccpp/mod.rs:1097–1121  ·  view source on GitHub ↗

visitInCppBraceScope: walk `node` in the namespaces and classes its source braces put it in (see brace_scopes.rs). The namespaces apply everywhere; the enclosing classes only at declaration level, where the stack above the file node holds nothing but class scopes.

(&mut self, node: Node<'t>)

Source from the content-addressed store, hash-verified

1095 /// everywhere; the enclosing classes only at declaration level, where the
1096 /// stack above the file node holds nothing but class scopes.
1097 fn visit_in_brace_scope(&mut self, node: Node<'t>) {
1098 let at = node.start_byte();
1099 let namespaces = self.brace_scopes.as_ref().map(|s| s.namespaces_at(at)).unwrap_or_default();
1100 let saved = std::mem::replace(&mut self.namespace_prefix, namespaces);
1101 let mut base = self.stack.len();
1102 while base > 1 && self.class_scope_rows.contains(&self.stack[base - 1].row) {
1103 base -= 1;
1104 }
1105 let mut walked: Option<Vec<Scope>> = None;
1106 if base == 1 {
1107 let classes = self.class_scopes.at(at);
1108 let same = classes.len() == self.stack.len() - base
1109 && classes.iter().zip(&self.stack[base..]).all(|(c, s)| c.row == s.row);
1110 if !same {
1111 walked = Some(self.stack.split_off(base));
1112 self.stack.extend(classes);
1113 }
1114 }
1115 self.dispatch_node(node);
1116 if let Some(walked) = walked {
1117 self.stack.truncate(base);
1118 self.stack.extend(walked);
1119 }
1120 self.namespace_prefix = saved;
1121 }
1122
1123 /// cppBodyEnd: where a class-like node ends in brace scopes — the `}`
1124 /// that closes its body — or None to keep the tree's.

Callers 1

visit_nodeMethod · 0.80

Calls 6

mapMethod · 0.80
namespaces_atMethod · 0.80
lenMethod · 0.80
dispatch_nodeMethod · 0.80
allMethod · 0.65
atMethod · 0.45

Tested by

no test coverage detected