(&mut self, root: Node<'t>)
| 2502 | // --- value refs (C only: VALUE_REF_LANGS has 'c', not 'cpp') ------------- |
| 2503 | |
| 2504 | fn flush_value_refs(&mut self, root: Node<'t>) { |
| 2505 | let scopes = std::mem::take(&mut self.value_scopes); |
| 2506 | let mut targets = std::mem::take(&mut self.fs_values); |
| 2507 | let counts = std::mem::take(&mut self.fs_value_counts); |
| 2508 | if self.variant != Variant::C { |
| 2509 | return; |
| 2510 | } |
| 2511 | if std::env::var("CODEGRAPH_VALUE_REFS").as_deref() == Ok("0") { |
| 2512 | return; |
| 2513 | } |
| 2514 | if targets.is_empty() || scopes.is_empty() || util::is_generated_file(self.file_path) { |
| 2515 | return; |
| 2516 | } |
| 2517 | |
| 2518 | // Shadow prune — the C declarator shape is init_declarator (a |
| 2519 | // file-scope const AND the local that shadows it both count). |
| 2520 | let mut decl_counts: HashMap<&str, u32> = HashMap::new(); |
| 2521 | let mut dstack: Vec<Node> = vec![root]; |
| 2522 | let mut dvisited = 0usize; |
| 2523 | while let Some(n) = dstack.pop() { |
| 2524 | if dvisited >= MAX_VALUE_REF_NODES { |
| 2525 | break; |
| 2526 | } |
| 2527 | dvisited += 1; |
| 2528 | if n.kind() == "init_declarator" { |
| 2529 | if let Some(name_node) = c_declarator_identifier(n) { |
| 2530 | if matches!(name_node.kind(), "identifier" | "simple_identifier") { |
| 2531 | let nm = self.text(name_node); |
| 2532 | if targets.contains_key(nm) { |
| 2533 | *decl_counts.entry(nm).or_insert(0) += 1; |
| 2534 | } |
| 2535 | } |
| 2536 | } |
| 2537 | } |
| 2538 | for i in 0..n.named_child_count() { |
| 2539 | if let Some(c) = n.named_child(i) { |
| 2540 | dstack.push(c); |
| 2541 | } |
| 2542 | } |
| 2543 | } |
| 2544 | let shadowed: Vec<String> = decl_counts |
| 2545 | .iter() |
| 2546 | .filter(|(nm, c)| **c > counts.get(**nm).copied().unwrap_or(1)) |
| 2547 | .map(|(nm, _)| nm.to_string()) |
| 2548 | .collect(); |
| 2549 | for nm in shadowed { |
| 2550 | targets.remove(&nm); |
| 2551 | } |
| 2552 | if targets.is_empty() { |
| 2553 | return; |
| 2554 | } |
| 2555 | |
| 2556 | let refs_kind = edge_kind_index("references").unwrap(); |
| 2557 | for scope in &scopes { |
| 2558 | let mut seen: HashSet<&str> = HashSet::new(); |
| 2559 | let mut stack: Vec<Node> = vec![scope.node]; |
| 2560 | // (No Dart/Pascal sibling-body pull-in: c/cpp bodies are children.) |
| 2561 | let mut visited = 0usize; |
no test coverage detected