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

Method extract_instantiation

codegraph-kernel/src/ccpp/mod.rs:1353–1385  ·  view source on GitHub ↗

extractInstantiation: `new Foo(...)` and stack constructions (both read the type from the `type` field; template args + qualifiers strip).

(&mut self, node: Node<'t>)

Source from the content-addressed store, hash-verified

1351 /// extractInstantiation: `new Foo(...)` and stack constructions (both
1352 /// read the type from the `type` field; template args + qualifiers strip).
1353 fn extract_instantiation(&mut self, node: Node<'t>) {
1354 if self.stack.is_empty() {
1355 return;
1356 }
1357 let from = self.top_row();
1358 let ctor = node
1359 .child_by_field_name("constructor")
1360 .or_else(|| node.child_by_field_name("type"))
1361 .or_else(|| node.child_by_field_name("name"))
1362 .or_else(|| node.named_child(0));
1363 let Some(ctor) = ctor else { return };
1364
1365 let mut class_name = self.text(ctor).to_string();
1366 if let Some(lt) = class_name.find('<') {
1367 if lt > 0 {
1368 class_name.truncate(lt);
1369 }
1370 }
1371 // Keep the trailing identifier of `ns::Foo` / `a.Foo`.
1372 let last_dot = class_name.rfind('.').map(|i| i as isize).unwrap_or(-1);
1373 let last_colons = class_name.rfind("::").map(|i| i as isize).unwrap_or(-1);
1374 let cut = last_dot.max(last_colons);
1375 if cut >= 0 {
1376 class_name = class_name[(cut as usize + 1)..].to_string();
1377 if class_name.starts_with(':') || class_name.starts_with('.') {
1378 class_name.remove(0);
1379 }
1380 }
1381 let class_name = class_name.trim().to_string();
1382 if !class_name.is_empty() {
1383 self.push_ref_at(from, &class_name, edge_kind_index("instantiates").unwrap(), node);
1384 }
1385 }
1386
1387 /// isCppStackConstruction (#1035).
1388 fn is_cpp_stack_construction(&self, node: Node) -> bool {

Callers 2

visit_nodeMethod · 0.45

Calls 5

edge_kind_indexFunction · 0.85
unwrapMethod · 0.60
top_rowMethod · 0.45
textMethod · 0.45
push_ref_atMethod · 0.45

Tested by

no test coverage detected