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

Method visit_in_brace_scope

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

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