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

Method maybe_capture_fn_refs

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

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

Callers 3

dispatch_nodeMethod · 0.45
scan_fn_ref_subtreeMethod · 0.45

Calls 7

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

Tested by

no test coverage detected