(&mut self)
| 1415 | // --- value references ------------------------------------------------------------ |
| 1416 | |
| 1417 | fn flush_value_refs(&mut self) { |
| 1418 | let scopes = std::mem::take(&mut self.value_scopes); |
| 1419 | let targets = std::mem::take(&mut self.fs_values); |
| 1420 | let _counts = std::mem::take(&mut self.fs_value_counts); |
| 1421 | if std::env::var("CODEGRAPH_VALUE_REFS").as_deref() == Ok("0") { |
| 1422 | return; |
| 1423 | } |
| 1424 | if targets.is_empty() || scopes.is_empty() || util::is_generated_file(self.file_path) { |
| 1425 | return; |
| 1426 | } |
| 1427 | |
| 1428 | // Shadow prune: the per-grammar declarator switch has NO resolving php |
| 1429 | // cases (`assignment` is python's node; property_declaration's |
| 1430 | // Kotlin/Swift path yields null) → declCounts stays empty → no php |
| 1431 | // target is ever pruned. Skipping the scan is byte-identical. |
| 1432 | |
| 1433 | let refs_kind = edge_kind_index("references").unwrap(); |
| 1434 | for scope in &scopes { |
| 1435 | let mut seen: HashSet<&str> = HashSet::new(); |
| 1436 | let mut stack: Vec<Node> = vec![scope.node]; |
| 1437 | let mut visited = 0usize; |
| 1438 | while let Some(n) = stack.pop() { |
| 1439 | if visited >= MAX_VALUE_REF_NODES { |
| 1440 | break; |
| 1441 | } |
| 1442 | visited += 1; |
| 1443 | // `name` is the php-live reader kind — ANY textual occurrence |
| 1444 | // of a target name in a reader's subtree emits (const reads, |
| 1445 | // `self::MAX`, `$MAX` variable names, interpolated `$MAX`). |
| 1446 | if matches!(n.kind(), "identifier" | "constant" | "name" | "simple_identifier") { |
| 1447 | let ref_name = self.text(n); |
| 1448 | if let Some(&target_row) = targets.get(ref_name) { |
| 1449 | let target_id = self.node_ids[target_row as usize].as_str(); |
| 1450 | if target_id != self.node_ids[scope.row as usize] |
| 1451 | && ref_name != scope.name |
| 1452 | && !seen.contains(&target_id) |
| 1453 | { |
| 1454 | seen.insert(target_id); |
| 1455 | let meta = self.arena.put(r#"{"valueRef":true}"#); |
| 1456 | self.tables.push_edge(&EdgeRow { |
| 1457 | source_idx: scope.row, |
| 1458 | target_idx: target_row, |
| 1459 | kind: refs_kind, |
| 1460 | provenance: 0, |
| 1461 | line: NONE, |
| 1462 | column: NONE, |
| 1463 | metadata_json: meta, |
| 1464 | source_id_str: NONE_STR, |
| 1465 | target_id_str: NONE_STR, |
| 1466 | }); |
| 1467 | } |
| 1468 | } |
| 1469 | } |
| 1470 | for i in 0..n.named_child_count() { |
| 1471 | if let Some(c) = n.named_child(i) { |
| 1472 | stack.push(c); |
| 1473 | } |
| 1474 | } |
no test coverage detected