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

Method extract_call

codegraph-kernel/src/ccpp/mod.rs:1665–1805  ·  view source on GitHub ↗
(&mut self, node: Node<'t>)

Source from the content-addressed store, hash-verified

1663 // --- calls / instantiation ----------------------------------------------
1664
1665 fn extract_call(&mut self, node: Node<'t>) {
1666 if self.stack.is_empty() {
1667 return;
1668 }
1669 let caller_row = self.top_row();
1670 let func = node
1671 .child_by_field_name("function")
1672 .or_else(|| node.named_child(0));
1673 let calls_kind = edge_kind_index("calls").unwrap();
1674
1675 // C++ explicit operator call `a.operator+(b)` (#1247): the
1676 // operator_name hides in an ERROR child. (has_error() defers such
1677 // files to wasm, so this scan is a faithful no-op today.)
1678 if self.variant == Variant::Cpp {
1679 if let Some(func) = func {
1680 let mut operator_name = String::new();
1681 'err: for i in 0..node.named_child_count() {
1682 let Some(child) = node.named_child(i) else { continue };
1683 if child.kind() != "ERROR" {
1684 continue;
1685 }
1686 for j in 0..child.named_child_count() {
1687 if let Some(op) = child.named_child(j) {
1688 if op.kind() == "operator_name" {
1689 operator_name = self.text(op).to_string();
1690 break 'err;
1691 }
1692 }
1693 }
1694 }
1695 if !operator_name.is_empty() {
1696 let sym = operator_name["operator".len()..].trim().to_string();
1697 if symbolic_op_re().is_match(&sym) {
1698 let compact: String = sym.chars().filter(|c| !c.is_whitespace()).collect();
1699 operator_name = format!("operator{compact}");
1700 }
1701 let receiver = arrow_dot_no_ws(self.text(func));
1702 if receiver != "this" && !operator_receiver_re().is_match(&receiver) {
1703 return;
1704 }
1705 let callee = if receiver == "this" {
1706 operator_name
1707 } else {
1708 format!("{receiver}.{operator_name}")
1709 };
1710 self.push_ref_at(caller_row, &callee, calls_kind, node);
1711 return;
1712 }
1713 }
1714 }
1715
1716 let mut callee_name = String::new();
1717 if let Some(func) = func {
1718 if func.kind() == "field_expression" {
1719 // `obj.method()` / `ptr->method()` — the `field` field.
1720 let property = func
1721 .child_by_field_name("property")
1722 .or_else(|| func.child_by_field_name("field"))

Callers 2

dispatch_nodeMethod · 0.45

Calls 15

edge_kind_indexFunction · 0.85
symbolic_op_reFunction · 0.85
arrow_dot_no_wsFunction · 0.85
operator_receiver_reFunction · 0.85
strip_cpp_template_argsFunction · 0.85
lenMethod · 0.80
mapMethod · 0.80
is_literal_receiverFunction · 0.70
simple_ident_reFunction · 0.70
textMethod · 0.65
getMethod · 0.65
unwrapMethod · 0.60

Tested by

no test coverage detected