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

Method cpp_stack_constructions

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

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