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