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
use rowan::TextRange;
use smol_str::SmolStr;
use crate::semantic::ScopeId;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct BindingId(pub(crate) u32);
impl BindingId {
pub(crate) fn from_index(idx: usize) -> Self {
Self(idx as u32)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BindingKind {
/// A local binding via `<-`, `=`, or `:=`.
Local,
/// A function parameter.
Param,
/// A `for`-loop variable.
ForVar,
/// A binding introduced by `<<-` / `->>` (super-assignment); semantically
/// scoped to an *enclosing* scope, but tracked here for completeness.
Implicit,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Binding {
pub name: SmolStr,
pub kind: BindingKind,
pub scope: ScopeId,
/// Range of the *defining* identifier (or `for`-var, or param name).
pub def_range: TextRange,
/// Range of the innermost `for`/`while`/`repeat` whose body contains this
/// binding, if any. Because a loop body re-executes, a read anywhere in that
/// range (even textually *before* the assignment) refers to the value carried
/// from a previous iteration, so resolution treats such a read as a use.
pub loop_range: Option<TextRange>,
/// Whether any read of this binding has been observed during resolution.
pub read: bool,
}