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