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

Method cpp_stack_constructions

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

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

Callers 1

Calls 7

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

Tested by

no test coverage detected