(&mut self, root: Node<'t>)
| 1803 | // --- value refs (C only: VALUE_REF_LANGS has 'c', not 'cpp') ------------- |
| 1804 | |
| 1805 | fn flush_value_refs(&mut self, root: Node<'t>) { |
| 1806 | let scopes = std::mem::take(&mut self.value_scopes); |
| 1807 | let mut targets = std::mem::take(&mut self.fs_values); |
| 1808 | let counts = std::mem::take(&mut self.fs_value_counts); |
| 1809 | if self.variant != Variant::C { |
| 1810 | return; |
| 1811 | } |
| 1812 | if std::env::var("CODEGRAPH_VALUE_REFS").as_deref() == Ok("0") { |
| 1813 | return; |
| 1814 | } |
| 1815 | if targets.is_empty() || scopes.is_empty() || util::is_generated_file(self.file_path) { |
| 1816 | return; |
| 1817 | } |
| 1818 | |
| 1819 | // Shadow prune — the C declarator shape is init_declarator (a |
| 1820 | // file-scope const AND the local that shadows it both count). |
| 1821 | let mut decl_counts: HashMap<&str, u32> = HashMap::new(); |
| 1822 | let mut dstack: Vec<Node> = vec![root]; |
| 1823 | let mut dvisited = 0usize; |
| 1824 | while let Some(n) = dstack.pop() { |
| 1825 | if dvisited >= MAX_VALUE_REF_NODES { |
| 1826 | break; |
| 1827 | } |
| 1828 | dvisited += 1; |
| 1829 | if n.kind() == "init_declarator" { |
| 1830 | if let Some(name_node) = c_declarator_identifier(n) { |
| 1831 | if matches!(name_node.kind(), "identifier" | "simple_identifier") { |
| 1832 | let nm = self.text(name_node); |
| 1833 | if targets.contains_key(nm) { |
| 1834 | *decl_counts.entry(nm).or_insert(0) += 1; |
| 1835 | } |
| 1836 | } |
| 1837 | } |
| 1838 | } |
| 1839 | for i in 0..n.named_child_count() { |
| 1840 | if let Some(c) = n.named_child(i) { |
| 1841 | dstack.push(c); |
| 1842 | } |
| 1843 | } |
| 1844 | } |
| 1845 | let shadowed: Vec<String> = decl_counts |
| 1846 | .iter() |
| 1847 | .filter(|(nm, c)| **c > counts.get(**nm).copied().unwrap_or(1)) |
| 1848 | .map(|(nm, _)| nm.to_string()) |
| 1849 | .collect(); |
| 1850 | for nm in shadowed { |
| 1851 | targets.remove(&nm); |
| 1852 | } |
| 1853 | if targets.is_empty() { |
| 1854 | return; |
| 1855 | } |
| 1856 | |
| 1857 | let refs_kind = edge_kind_index("references").unwrap(); |
| 1858 | for scope in &scopes { |
| 1859 | let mut seen: HashSet<&str> = HashSet::new(); |
| 1860 | let mut stack: Vec<Node> = vec![scope.node]; |
| 1861 | // (No Dart/Pascal sibling-body pull-in: c/cpp bodies are children.) |
| 1862 | let mut visited = 0usize; |
no test coverage detected