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

Method extract_instantiation

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

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