use std::{
hash::{Hash, Hasher},
sync::Arc,
};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CalcitSymbolInfo {
pub at_ns: Arc<str>,
pub at_def: Arc<str>,
}
#[derive(Debug, Clone, PartialOrd, Ord)]
pub enum ImportInfo {
NsAs {
at_ns: Arc<str>,
at_def: Arc<str>,
alias: Arc<str>,
},
NsReferDef { at_ns: Arc<str>, at_def: Arc<str> },
Core { at_ns: Arc<str> },
JsDefault {
alias: Arc<str>,
at_ns: Arc<str>,
at_def: Arc<str>,
},
SameFile { at_def: Arc<str> },
}
impl Hash for ImportInfo {
fn hash<H: Hasher>(&self, state: &mut H) {
match self {
ImportInfo::NsAs { at_ns, alias, .. } => {
"as".hash(state);
at_ns.hash(state);
alias.hash(state);
}
ImportInfo::NsReferDef { at_ns, .. } => {
"refer".hash(state);
at_ns.hash(state);
}
ImportInfo::Core { at_ns } => {
"core".hash(state);
at_ns.hash(state);
}
ImportInfo::JsDefault { at_ns, alias, .. } => {
"js-default".hash(state);
at_ns.hash(state);
alias.hash(state);
}
ImportInfo::SameFile { .. } => {
"same-file".hash(state);
}
}
}
}
impl PartialEq for ImportInfo {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(ImportInfo::NsAs { at_ns: a, alias: b, .. }, ImportInfo::NsAs { at_ns: c, alias: d, .. }) => a == c && b == d,
(ImportInfo::NsReferDef { at_ns: a, .. }, ImportInfo::NsReferDef { at_ns: b, .. }) => a == b,
(ImportInfo::Core { at_ns: a }, ImportInfo::Core { at_ns: b }) => a == b,
(ImportInfo::JsDefault { at_ns: a, alias: b, .. }, ImportInfo::JsDefault { at_ns: c, alias: d, .. }) => a == c && b == d,
(ImportInfo::SameFile { .. }, ImportInfo::SameFile { .. }) => true,
_ => false,
}
}
}
impl Eq for ImportInfo {}
#[derive(Debug, Clone, PartialOrd, Ord)]
pub struct CalcitImport {
pub ns: Arc<str>,
pub def: Arc<str>,
pub info: Arc<ImportInfo>,
pub def_id: Option<u32>,
}
impl PartialEq for CalcitImport {
fn eq(&self, other: &Self) -> bool {
match (&*self.info, &*other.info) {
(ImportInfo::NsAs { alias, .. }, ImportInfo::NsAs { alias: a2, .. }) => alias == a2 && self.ns == other.ns,
_ => self.ns == other.ns && self.info == other.info && self.def == other.def,
}
}
}
impl Eq for CalcitImport {}
impl Hash for CalcitImport {
fn hash<H: Hasher>(&self, state: &mut H) {
match &*self.info {
ImportInfo::NsAs { alias, .. } => {
self.ns.hash(state);
alias.hash(state);
}
_ => {
self.ns.hash(state);
self.info.hash(state);
}
}
}
}