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

Method extract_instantiation

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

1800 /// extractInstantiation: `new Foo(...)` and stack constructions (both
1801 /// read the type from the `type` field; template args + qualifiers strip).
1802 fn extract_instantiation(&mut self, node: Node<'t>) {
1803 if self.stack.is_empty() {
1804 return;
1805 }
1806 let from = self.top_row();
1807 let ctor = node
1808 .child_by_field_name("constructor")
1809 .or_else(|| node.child_by_field_name("type"))
1810 .or_else(|| node.child_by_field_name("name"))
1811 .or_else(|| node.named_child(0));
1812 let Some(ctor) = ctor else { return };
1813
1814 let mut class_name = self.text(ctor).to_string();
1815 if let Some(lt) = class_name.find('<') {
1816 if lt > 0 {
1817 class_name.truncate(lt);
1818 }
1819 }
1820 // Keep the trailing identifier of `ns::Foo` / `a.Foo`.
1821 let last_dot = class_name.rfind('.').map(|i| i as isize).unwrap_or(-1);
1822 let last_colons = class_name.rfind("::").map(|i| i as isize).unwrap_or(-1);
1823 let cut = last_dot.max(last_colons);
1824 if cut >= 0 {
1825 class_name = class_name[(cut as usize + 1)..].to_string();
1826 if class_name.starts_with(':') || class_name.starts_with('.') {
1827 class_name.remove(0);
1828 }
1829 }
1830 let class_name = class_name.trim().to_string();
1831 if !class_name.is_empty() {
1832 self.push_ref_at(from, &class_name, edge_kind_index("instantiates").unwrap(), node);
1833 }
1834 }
1835
1836 fn is_cpp_constructor_declaration(&self, node: Node<'t>) -> bool {
1837 if self.variant != Variant::Cpp || node.kind() != "declaration" || node.child_by_field_name("type").is_some() {

Callers 2

dispatch_nodeMethod · 0.45

Calls 6

edge_kind_indexFunction · 0.85
mapMethod · 0.80
textMethod · 0.65
unwrapMethod · 0.60
top_rowMethod · 0.45
push_ref_atMethod · 0.45

Tested by

no test coverage detected