1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use formualizer_parse::ASTNode;
#[cfg(any(test, feature = "legacy_oracle"))]
use rustc_hash::FxHashSet;
use formualizer_common::LiteralValue;
use crate::{CellRef, RangeRef, SheetId, engine::VertexId, reference::SharedRangeRef};
/// Scope of a named range
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum NameScope {
/// Available throughout workbook
Workbook,
/// Only available in specific sheet
Sheet(SheetId),
}
/// Definition of what a name refers to
#[derive(Debug, Clone, PartialEq)]
#[allow(clippy::large_enum_variant)]
pub enum NamedDefinition {
/// Direct reference to a single cell
Cell(CellRef),
/// Reference to a range of cells
Range(RangeRef),
/// Constant literal value
Literal(LiteralValue),
/// Named formula (evaluates to value/range)
Formula {
ast: ASTNode,
/// Cached dependencies from last parse
dependencies: Vec<VertexId>,
/// Cached range dependencies
range_deps: Vec<SharedRangeRef<'static>>,
},
}
/// Complete named range entry
#[derive(Debug, Clone)]
pub struct NamedRange {
pub definition: NamedDefinition,
pub scope: NameScope,
/// Formulas that reference this name: legacy's name link map, kept
/// only by the test oracle (Program 1 M5). Normal builds have no public
/// equivalent: inspection (`Engine::dependents`) excludes name-mediated
/// readers, as legacy's inspection did.
#[cfg(any(test, feature = "legacy_oracle"))]
pub dependents: FxHashSet<VertexId>,
/// Vertex representing this named range within the dependency graph
pub vertex: VertexId,
}
/// Cloned, binding-friendly snapshot of a named range entry.
#[derive(Debug, Clone, PartialEq)]
pub struct NamedRangeSnapshot {
pub name: String,
pub scope: NameScope,
pub definition: NamedDefinition,
}