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

Method cpp_stack_constructions

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

cppStackConstructions (tree-sitter.ts, #1035 / #1839): whether the declaration constructs with arguments (→ `instantiates`), and one arity per constructed object (→ `calls T::T/arity`). `extern`, pointer / reference / function declarators construct nothing; an array's braces hold elements, not constructor arguments.

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

Source from the content-addressed store, hash-verified

1873 /// pointer / reference / function declarators construct nothing; an
1874 /// array's braces hold elements, not constructor arguments.
1875 fn cpp_stack_constructions(&self, node: Node<'t>) -> (bool, Vec<usize>) {
1876 let none = (false, Vec::new());
1877 let Some(type_node) = node.child_by_field_name("type") else { return none };
1878 if !matches!(
1879 type_node.kind(),
1880 "type_identifier" | "template_type" | "qualified_identifier"
1881 ) {
1882 return none;
1883 }
1884 let mut instantiates = false;
1885 let mut arities = Vec::new();
1886 for i in 0..node.named_child_count() {
1887 let Some(child) = node.named_child(i) else { continue };
1888 if child.kind() == "storage_class_specifier" && self.text(child) == "extern" {
1889 return none;
1890 }
1891 if matches!(child.kind(), "identifier" | "array_declarator") {
1892 if child.kind() == "array_declarator" && !self.cpp_object_array(child) { continue; }
1893 arities.push(0);
1894 continue;
1895 }
1896 if child.kind() != "init_declarator" {
1897 continue;
1898 }
1899 let Some(declarator) = child.child_by_field_name("declarator") else { continue };
1900 if !matches!(declarator.kind(), "identifier" | "array_declarator") {
1901 continue;
1902 }
1903 let Some(value) = child.child_by_field_name("value") else { continue };
1904 if !matches!(value.kind(), "argument_list" | "initializer_list") {
1905 continue;
1906 }
1907 instantiates = true;
1908 if declarator.kind() == "identifier" {
1909 let count = (0..value.named_child_count())
1910 .filter(|&j| value.named_child(j).map(|n| n.kind() != "comment").unwrap_or(false))
1911 .count();
1912 arities.push(count);
1913 } else if self.cpp_object_array(declarator) {
1914 let mut dimensions = Vec::new();
1915 let mut array = Some(declarator);
1916 while let Some(n) = array.filter(|n| n.kind() == "array_declarator") {
1917 dimensions.insert(0, n.child_by_field_name("size").map(|s| self.text(s))
1918 .filter(|s| s.bytes().all(|b| b.is_ascii_digit()))
1919 .and_then(|s| s.parse::<usize>().ok()).filter(|&n| n <= 9_007_199_254_740_991));
1920 array = n.child_by_field_name("declarator");
1921 }
1922 Self::cpp_array_arities(value, &dimensions, &mut arities);
1923 }
1924 }
1925 (instantiates, arities)
1926 }
1927
1928 fn cpp_array_arities(list: Node<'t>, dimensions: &[Option<usize>], arities: &mut Vec<usize>) {
1929 let entries: Vec<_> = (0..list.named_child_count()).filter_map(|j| list.named_child(j))

Callers 1

Calls 6

cpp_object_arrayMethod · 0.80
pushMethod · 0.80
mapMethod · 0.80
bytesMethod · 0.80
textMethod · 0.65
allMethod · 0.65

Tested by

no test coverage detected