(&mut self)
| 1572 | // --- value references ------------------------------------------------------------ |
| 1573 | |
| 1574 | fn flush_value_refs(&mut self) { |
| 1575 | let scopes = std::mem::take(&mut self.value_scopes); |
| 1576 | let targets = std::mem::take(&mut self.fs_values); |
| 1577 | let _counts = std::mem::take(&mut self.fs_value_counts); |
| 1578 | if std::env::var("CODEGRAPH_VALUE_REFS").as_deref() == Ok("0") { |
| 1579 | return; |
| 1580 | } |
| 1581 | if targets.is_empty() || scopes.is_empty() || util::is_generated_file(self.file_path) { |
| 1582 | return; |
| 1583 | } |
| 1584 | |
| 1585 | // Shadow prune: the per-grammar declarator switch has NO resolving php |
| 1586 | // cases (`assignment` is python's node; property_declaration's |
| 1587 | // Kotlin/Swift path yields null) → declCounts stays empty → no php |
| 1588 | // target is ever pruned. Skipping the scan is byte-identical. |
| 1589 | |
| 1590 | let refs_kind = edge_kind_index("references").unwrap(); |
| 1591 | for scope in &scopes { |
| 1592 | let mut seen: HashSet<&str> = HashSet::new(); |
| 1593 | let mut stack: Vec<Node> = vec![scope.node]; |
| 1594 | let mut visited = 0usize; |
| 1595 | while let Some(n) = stack.pop() { |
| 1596 | if visited >= MAX_VALUE_REF_NODES { |
| 1597 | break; |
| 1598 | } |
| 1599 | visited += 1; |
| 1600 | // `name` is the php-live reader kind — ANY textual occurrence |
| 1601 | // of a target name in a reader's subtree emits (const reads, |
| 1602 | // `self::MAX`, `$MAX` variable names, interpolated `$MAX`). |
| 1603 | if matches!(n.kind(), "identifier" | "constant" | "name" | "simple_identifier") { |
| 1604 | let ref_name = self.text(n); |
| 1605 | if let Some(&target_row) = targets.get(ref_name) { |
| 1606 | let target_id = self.node_ids[target_row as usize].as_str(); |
| 1607 | if target_id != self.node_ids[scope.row as usize] |
| 1608 | && ref_name != scope.name |
| 1609 | && !seen.contains(&target_id) |
| 1610 | { |
| 1611 | seen.insert(target_id); |
| 1612 | let meta = self.arena.put(r#"{"valueRef":true}"#); |
| 1613 | self.tables.push_edge(&EdgeRow { |
| 1614 | source_idx: scope.row, |
| 1615 | target_idx: target_row, |
| 1616 | kind: refs_kind, |
| 1617 | provenance: 0, |
| 1618 | line: NONE, |
| 1619 | column: NONE, |
| 1620 | metadata_json: meta, |
| 1621 | source_id_str: NONE_STR, |
| 1622 | target_id_str: NONE_STR, |
| 1623 | }); |
| 1624 | } |
| 1625 | } |
| 1626 | } |
| 1627 | for i in 0..n.named_child_count() { |
| 1628 | if let Some(c) = n.named_child(i) { |
| 1629 | stack.push(c); |
| 1630 | } |
| 1631 | } |
no test coverage detected