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

Method flush_value_refs

codegraph-kernel/src/ccpp/mod.rs:1830–1924  ·  view source on GitHub ↗
(&mut self, root: Node<'t>)

Source from the content-addressed store, hash-verified

1828 // --- value refs (C only: VALUE_REF_LANGS has 'c', not 'cpp') -------------
1829
1830 fn flush_value_refs(&mut self, root: Node<'t>) {
1831 let scopes = std::mem::take(&mut self.value_scopes);
1832 let mut targets = std::mem::take(&mut self.fs_values);
1833 let counts = std::mem::take(&mut self.fs_value_counts);
1834 if self.variant != Variant::C {
1835 return;
1836 }
1837 if std::env::var("CODEGRAPH_VALUE_REFS").as_deref() == Ok("0") {
1838 return;
1839 }
1840 if targets.is_empty() || scopes.is_empty() || util::is_generated_file(self.file_path) {
1841 return;
1842 }
1843
1844 // Shadow prune — the C declarator shape is init_declarator (a
1845 // file-scope const AND the local that shadows it both count).
1846 let mut decl_counts: HashMap<&str, u32> = HashMap::new();
1847 let mut dstack: Vec<Node> = vec![root];
1848 let mut dvisited = 0usize;
1849 while let Some(n) = dstack.pop() {
1850 if dvisited >= MAX_VALUE_REF_NODES {
1851 break;
1852 }
1853 dvisited += 1;
1854 if n.kind() == "init_declarator" {
1855 if let Some(name_node) = c_declarator_identifier(n) {
1856 if matches!(name_node.kind(), "identifier" | "simple_identifier") {
1857 let nm = self.text(name_node);
1858 if targets.contains_key(nm) {
1859 *decl_counts.entry(nm).or_insert(0) += 1;
1860 }
1861 }
1862 }
1863 }
1864 for i in 0..n.named_child_count() {
1865 if let Some(c) = n.named_child(i) {
1866 dstack.push(c);
1867 }
1868 }
1869 }
1870 let shadowed: Vec<String> = decl_counts
1871 .iter()
1872 .filter(|(nm, c)| **c > counts.get(**nm).copied().unwrap_or(1))
1873 .map(|(nm, _)| nm.to_string())
1874 .collect();
1875 for nm in shadowed {
1876 targets.remove(&nm);
1877 }
1878 if targets.is_empty() {
1879 return;
1880 }
1881
1882 let refs_kind = edge_kind_index("references").unwrap();
1883 for scope in &scopes {
1884 let mut seen: HashSet<&str> = HashSet::new();
1885 let mut stack: Vec<Node> = vec![scope.node];
1886 // (No Dart/Pascal sibling-body pull-in: c/cpp bodies are children.)
1887 let mut visited = 0usize;

Callers 1

extractFunction · 0.45

Calls 9

is_generated_fileFunction · 0.85
c_declarator_identifierFunction · 0.85
edge_kind_indexFunction · 0.85
push_edgeMethod · 0.80
textMethod · 0.65
getMethod · 0.65
putMethod · 0.65
unwrapMethod · 0.60
collectMethod · 0.45

Tested by

no test coverage detected