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

Method extract_call

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

Source from the content-addressed store, hash-verified

1223 // --- calls / instantiation ----------------------------------------------
1224
1225 fn extract_call(&mut self, node: Node<'t>) {
1226 if self.stack.is_empty() {
1227 return;
1228 }
1229 let caller_row = self.top_row();
1230 let func = node
1231 .child_by_field_name("function")
1232 .or_else(|| node.named_child(0));
1233 let calls_kind = edge_kind_index("calls").unwrap();
1234
1235 // C++ explicit operator call `a.operator+(b)` (#1247): the
1236 // operator_name hides in an ERROR child. (has_error() defers such
1237 // files to wasm, so this scan is a faithful no-op today.)
1238 if self.variant == Variant::Cpp {
1239 if let Some(func) = func {
1240 let mut operator_name = String::new();
1241 'err: for i in 0..node.named_child_count() {
1242 let Some(child) = node.named_child(i) else { continue };
1243 if child.kind() != "ERROR" {
1244 continue;
1245 }
1246 for j in 0..child.named_child_count() {
1247 if let Some(op) = child.named_child(j) {
1248 if op.kind() == "operator_name" {
1249 operator_name = self.text(op).to_string();
1250 break 'err;
1251 }
1252 }
1253 }
1254 }
1255 if !operator_name.is_empty() {
1256 let sym = operator_name["operator".len()..].trim().to_string();
1257 if symbolic_op_re().is_match(&sym) {
1258 let compact: String = sym.chars().filter(|c| !c.is_whitespace()).collect();
1259 operator_name = format!("operator{compact}");
1260 }
1261 let receiver = arrow_dot_no_ws(self.text(func));
1262 if receiver != "this" && !operator_receiver_re().is_match(&receiver) {
1263 return;
1264 }
1265 let callee = if receiver == "this" {
1266 operator_name
1267 } else {
1268 format!("{receiver}.{operator_name}")
1269 };
1270 self.push_ref_at(caller_row, &callee, calls_kind, node);
1271 return;
1272 }
1273 }
1274 }
1275
1276 let mut callee_name = String::new();
1277 if let Some(func) = func {
1278 if func.kind() == "field_expression" {
1279 // `obj.method()` / `ptr->method()` — the `field` field.
1280 let property = func
1281 .child_by_field_name("property")
1282 .or_else(|| func.child_by_field_name("field"))

Callers 2

visit_nodeMethod · 0.45

Calls 14

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
is_literal_receiverFunction · 0.70
simple_ident_reFunction · 0.70
textMethod · 0.65
getMethod · 0.65
unwrapMethod · 0.60
top_rowMethod · 0.45

Tested by

no test coverage detected