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
pub mod component;
pub mod expressions;
pub mod statements;
pub mod types;

use cranelift_entity::entity_impl;
use miette::SourceSpan;

pub type Span = SourceSpan;

pub use component::*;
pub use expressions::*;
pub use statements::*;
pub use types::*;

pub fn merge(left: &Span, right: &Span) -> Span {
    let left_most = left.offset();
    let right_most = right.offset() + right.len();
    let len = right_most - left_most;
    Span::from((left_most, len))
}

#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NameId(u32);
entity_impl!(NameId, "name");

impl ContextEq<Component> for NameId {
    fn context_eq(&self, other: &Self, context: &Component) -> bool {
        let self_str = context.get_name(*self);
        let other_str = context.get_name(*other);
        let str_eq = self_str == other_str;

        let self_span = context.name_span(*self);
        let other_span = context.name_span(*other);
        let span_eq = self_span == other_span;

        str_eq && span_eq
    }
}