73 lines
1.6 KiB
Rust
73 lines
1.6 KiB
Rust
use crate::source_range::SourceRange;
|
|
use std::fmt::{Debug, Formatter};
|
|
use std::hash::{Hash, Hasher};
|
|
use std::rc::Rc;
|
|
|
|
pub struct VariableSymbol {
|
|
declared_name: Rc<str>,
|
|
declared_name_source_range: SourceRange,
|
|
is_mut: bool,
|
|
scope_id: usize,
|
|
}
|
|
|
|
impl VariableSymbol {
|
|
pub fn new(
|
|
name: &Rc<str>,
|
|
declared_name_source_range: &SourceRange,
|
|
is_mut: bool,
|
|
scope_id: usize,
|
|
) -> Self {
|
|
Self {
|
|
declared_name: name.clone(),
|
|
declared_name_source_range: declared_name_source_range.clone(),
|
|
is_mut,
|
|
scope_id,
|
|
}
|
|
}
|
|
|
|
pub fn declared_name(&self) -> &str {
|
|
&self.declared_name
|
|
}
|
|
|
|
pub fn declared_name_owned(&self) -> Rc<str> {
|
|
self.declared_name.clone()
|
|
}
|
|
|
|
pub fn declared_name_source_range(&self) -> &SourceRange {
|
|
&self.declared_name_source_range
|
|
}
|
|
|
|
pub fn is_mut(&self) -> bool {
|
|
self.is_mut
|
|
}
|
|
|
|
pub fn scope_id(&self) -> usize {
|
|
self.scope_id
|
|
}
|
|
}
|
|
|
|
impl Eq for VariableSymbol {}
|
|
|
|
impl PartialEq for VariableSymbol {
|
|
fn eq(&self, other: &Self) -> bool {
|
|
self.declared_name == other.declared_name && self.scope_id == other.scope_id
|
|
}
|
|
}
|
|
|
|
impl Hash for VariableSymbol {
|
|
fn hash<H: Hasher>(&self, state: &mut H) {
|
|
self.declared_name.hash(state);
|
|
self.scope_id.hash(state);
|
|
}
|
|
}
|
|
|
|
impl Debug for VariableSymbol {
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
write!(
|
|
f,
|
|
"VariableSymbol({:?}, {})",
|
|
self.declared_name, self.scope_id
|
|
)
|
|
}
|
|
}
|