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

Method maybe_capture_fn_refs

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

1646 /// init_declarator(varinit:value), initializer_list(list),
1647 /// initializer_pair(value:value).
1648 fn maybe_capture_fn_refs(&mut self, node: Node<'t>) {
1649 let mode = match node.kind() {
1650 "argument_list" => Mode::Args,
1651 "assignment_expression" => Mode::Rhs,
1652 "init_declarator" => Mode::Varinit,
1653 "initializer_list" => Mode::List,
1654 "initializer_pair" => Mode::Value,
1655 _ => return,
1656 };
1657 if self.stack.is_empty() {
1658 return;
1659 }
1660 let from = self.top_row();
1661
1662 let mut values: Vec<Node<'t>> = Vec::new();
1663 match mode {
1664 Mode::Args | Mode::List => {
1665 for i in 0..node.named_child_count() {
1666 if let Some(c) = node.named_child(i) {
1667 values.push(c);
1668 }
1669 }
1670 }
1671 Mode::Rhs => {
1672 if let Some(rhs) = node.child_by_field_name("right") {
1673 // Param-storage skip: `o->cb = cb` (LHS last name == RHS).
1674 let lhs_text = node
1675 .child_by_field_name("left")
1676 .map(|l| self.text(l))
1677 .unwrap_or("");
1678 let lhs_last = util::lhs_last_name()
1679 .captures(lhs_text)
1680 .and_then(|c| c.get(1))
1681 .map(|m| m.as_str());
1682 if !(lhs_last.is_some() && lhs_last == Some(self.text(rhs).trim())) {
1683 values.push(rhs);
1684 }
1685 }
1686 }
1687 Mode::Value => {
1688 let v = node.child_by_field_name("value").or_else(|| {
1689 if node.named_child_count() > 0 {
1690 node.named_child(node.named_child_count() - 1)
1691 } else {
1692 None
1693 }
1694 });
1695 if let Some(v) = v {
1696 values.push(v);
1697 }
1698 }
1699 Mode::Varinit => {
1700 // (init_declarator has no name/pattern field — no destructure skip)
1701 if let Some(v) = node.child_by_field_name("value") {
1702 values.push(v);
1703 }
1704 }
1705 }

Callers 3

visit_nodeMethod · 0.45
scan_fn_ref_subtreeMethod · 0.45

Calls 4

textMethod · 0.65
getMethod · 0.65
top_rowMethod · 0.45

Tested by

no test coverage detected