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

Method flush_value_refs

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

Source from the content-addressed store, hash-verified

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

Callers 1

extractFunction · 0.45

Calls 12

is_generated_fileFunction · 0.85
c_declarator_identifierFunction · 0.85
edge_kind_indexFunction · 0.85
pushMethod · 0.80
mapMethod · 0.80
push_edgeMethod · 0.80
textMethod · 0.65
getMethod · 0.65
putMethod · 0.65
unwrapMethod · 0.60
takeFunction · 0.50
collectMethod · 0.45

Tested by

no test coverage detected