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

Method flush_value_refs

codegraph-kernel/src/php.rs:1544–1602  ·  view source on GitHub ↗
(&mut self)

Source from the content-addressed store, hash-verified

1542 // --- value references ------------------------------------------------------------
1543
1544 fn flush_value_refs(&mut self) {
1545 let scopes = std::mem::take(&mut self.value_scopes);
1546 let targets = std::mem::take(&mut self.fs_values);
1547 let _counts = std::mem::take(&mut self.fs_value_counts);
1548 if std::env::var("CODEGRAPH_VALUE_REFS").as_deref() == Ok("0") {
1549 return;
1550 }
1551 if targets.is_empty() || scopes.is_empty() || util::is_generated_file(self.file_path) {
1552 return;
1553 }
1554
1555 // Shadow prune: the per-grammar declarator switch has NO resolving php
1556 // cases (`assignment` is python's node; property_declaration's
1557 // Kotlin/Swift path yields null) → declCounts stays empty → no php
1558 // target is ever pruned. Skipping the scan is byte-identical.
1559
1560 let refs_kind = edge_kind_index("references").unwrap();
1561 for scope in &scopes {
1562 let mut seen: HashSet<&str> = HashSet::new();
1563 let mut stack: Vec<Node> = vec![scope.node];
1564 let mut visited = 0usize;
1565 while let Some(n) = stack.pop() {
1566 if visited >= MAX_VALUE_REF_NODES {
1567 break;
1568 }
1569 visited += 1;
1570 // `name` is the php-live reader kind — ANY textual occurrence
1571 // of a target name in a reader's subtree emits (const reads,
1572 // `self::MAX`, `$MAX` variable names, interpolated `$MAX`).
1573 if matches!(n.kind(), "identifier" | "constant" | "name" | "simple_identifier") {
1574 let ref_name = self.text(n);
1575 if let Some(&target_row) = targets.get(ref_name) {
1576 let target_id = self.node_ids[target_row as usize].as_str();
1577 if target_id != self.node_ids[scope.row as usize]
1578 && ref_name != scope.name
1579 && !seen.contains(&target_id)
1580 {
1581 seen.insert(target_id);
1582 let meta = self.arena.put(r#"{"valueRef":true}"#);
1583 self.tables.push_edge(&EdgeRow {
1584 source_idx: scope.row,
1585 target_idx: target_row,
1586 kind: refs_kind,
1587 provenance: 0,
1588 line: NONE,
1589 column: NONE,
1590 metadata_json: meta,
1591 source_id_str: NONE_STR,
1592 target_id_str: NONE_STR,
1593 });
1594 }
1595 }
1596 }
1597 for c in n.named_children(&mut n.walk()) {
1598 stack.push(c);
1599 }
1600 }
1601 }

Callers 1

extractFunction · 0.45

Calls 10

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

Tested by

no test coverage detected