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

Method visit_in_brace_scope

codegraph-kernel/src/ccpp/mod.rs:1095–1119  ·  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

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