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

Method maybe_capture_fn_refs

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

1623 /// init_declarator(varinit:value), initializer_list(list),
1624 /// initializer_pair(value:value).
1625 fn maybe_capture_fn_refs(&mut self, node: Node<'t>) {
1626 let mode = match node.kind() {
1627 "argument_list" => Mode::Args,
1628 "assignment_expression" => Mode::Rhs,
1629 "init_declarator" => Mode::Varinit,
1630 "initializer_list" => Mode::List,
1631 "initializer_pair" => Mode::Value,
1632 _ => return,
1633 };
1634 if self.stack.is_empty() {
1635 return;
1636 }
1637 let from = self.top_row();
1638
1639 let mut values: Vec<Node<'t>> = Vec::new();
1640 match mode {
1641 Mode::Args | Mode::List => {
1642 for i in 0..node.named_child_count() {
1643 if let Some(c) = node.named_child(i) {
1644 values.push(c);
1645 }
1646 }
1647 }
1648 Mode::Rhs => {
1649 if let Some(rhs) = node.child_by_field_name("right") {
1650 // Param-storage skip: `o->cb = cb` (LHS last name == RHS).
1651 let lhs_text = node
1652 .child_by_field_name("left")
1653 .map(|l| self.text(l))
1654 .unwrap_or("");
1655 let lhs_last = util::lhs_last_name()
1656 .captures(lhs_text)
1657 .and_then(|c| c.get(1))
1658 .map(|m| m.as_str());
1659 if !(lhs_last.is_some() && lhs_last == Some(self.text(rhs).trim())) {
1660 values.push(rhs);
1661 }
1662 }
1663 }
1664 Mode::Value => {
1665 let v = node.child_by_field_name("value").or_else(|| {
1666 if node.named_child_count() > 0 {
1667 node.named_child(node.named_child_count() - 1)
1668 } else {
1669 None
1670 }
1671 });
1672 if let Some(v) = v {
1673 values.push(v);
1674 }
1675 }
1676 Mode::Varinit => {
1677 // (init_declarator has no name/pattern field — no destructure skip)
1678 if let Some(v) = node.child_by_field_name("value") {
1679 values.push(v);
1680 }
1681 }
1682 }

Callers 3

visit_nodeMethod · 0.45
scan_fn_ref_subtreeMethod · 0.45

Calls 4

getMethod · 0.65
top_rowMethod · 0.45
textMethod · 0.45

Tested by

no test coverage detected