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

Method maybe_capture_fn_refs

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

maybeCaptureFnRefs + captureFnRefCandidates for the cFamily dispatch: argument_list(args), assignment_expression(rhs:right), init_declarator(varinit:value), initializer_list(list), initializer_pair(value:value).

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

Source from the content-addressed store, hash-verified

2318 /// init_declarator(varinit:value), initializer_list(list),
2319 /// initializer_pair(value:value).
2320 fn maybe_capture_fn_refs(&mut self, node: Node<'t>) {
2321 let mode = match node.kind() {
2322 "argument_list" => Mode::Args,
2323 "assignment_expression" => Mode::Rhs,
2324 "init_declarator" => Mode::Varinit,
2325 "initializer_list" => Mode::List,
2326 "initializer_pair" => Mode::Value,
2327 _ => return,
2328 };
2329 if self.stack.is_empty() {
2330 return;
2331 }
2332 let from = self.top_row();
2333
2334 let mut values: Vec<Node<'t>> = Vec::new();
2335 match mode {
2336 Mode::Args | Mode::List => {
2337 for i in 0..node.named_child_count() {
2338 if let Some(c) = node.named_child(i) {
2339 values.push(c);
2340 }
2341 }
2342 }
2343 Mode::Rhs => {
2344 if let Some(rhs) = node.child_by_field_name("right") {
2345 // Param-storage skip: `o->cb = cb` (LHS last name == RHS).
2346 let lhs_text = node
2347 .child_by_field_name("left")
2348 .map(|l| self.text(l))
2349 .unwrap_or("");
2350 let lhs_last = util::lhs_last_name()
2351 .captures(lhs_text)
2352 .and_then(|c| c.get(1))
2353 .map(|m| m.as_str());
2354 if !(lhs_last.is_some() && lhs_last == Some(self.text(rhs).trim())) {
2355 values.push(rhs);
2356 }
2357 }
2358 }
2359 Mode::Value => {
2360 let v = node.child_by_field_name("value").or_else(|| {
2361 if node.named_child_count() > 0 {
2362 node.named_child(node.named_child_count() - 1)
2363 } else {
2364 None
2365 }
2366 });
2367 if let Some(v) = v {
2368 values.push(v);
2369 }
2370 }
2371 Mode::Varinit => {
2372 // (init_declarator has no name/pattern field — no destructure skip)
2373 if let Some(v) = node.child_by_field_name("value") {
2374 values.push(v);
2375 }
2376 }
2377 }

Callers 3

dispatch_nodeMethod · 0.45
scan_fn_ref_subtreeMethod · 0.45

Calls 6

pushMethod · 0.80
mapMethod · 0.80
textMethod · 0.65
getMethod · 0.65
top_rowMethod · 0.45

Tested by

no test coverage detected