2019-04-11 15:23:14 -07:00
|
|
|
use crate::common::*;
|
2019-04-11 12:30:29 -07:00
|
|
|
|
2019-11-07 10:55:15 -08:00
|
|
|
/// An alias, e.g. `name := target`
|
2021-06-08 01:01:27 -07:00
|
|
|
#[derive(Debug, PartialEq, Clone)]
|
2019-11-21 07:39:32 -08:00
|
|
|
pub(crate) struct Alias<'src, T = Rc<Recipe<'src>>> {
|
2020-02-10 20:07:06 -08:00
|
|
|
pub(crate) name: Name<'src>,
|
2019-11-21 07:39:32 -08:00
|
|
|
pub(crate) target: T,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'src> Alias<'src, Name<'src>> {
|
|
|
|
pub(crate) fn line_number(&self) -> usize {
|
|
|
|
self.name.line
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn resolve(self, target: Rc<Recipe<'src>>) -> Alias<'src> {
|
|
|
|
assert_eq!(self.target.lexeme(), target.name.lexeme());
|
|
|
|
|
|
|
|
Alias {
|
|
|
|
name: self.name,
|
|
|
|
target,
|
|
|
|
}
|
|
|
|
}
|
2019-11-07 10:55:15 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Alias<'_> {
|
|
|
|
pub(crate) fn is_private(&self) -> bool {
|
|
|
|
self.name.lexeme().starts_with('_')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-21 07:39:32 -08:00
|
|
|
impl<'src, T> Keyed<'src> for Alias<'src, T> {
|
2019-11-07 10:55:15 -08:00
|
|
|
fn key(&self) -> &'src str {
|
|
|
|
self.name.lexeme()
|
|
|
|
}
|
2019-04-11 12:30:29 -07:00
|
|
|
}
|
|
|
|
|
2019-11-21 07:39:32 -08:00
|
|
|
impl<'src> Display for Alias<'src, Name<'src>> {
|
2019-04-11 15:23:14 -07:00
|
|
|
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
2019-11-07 10:55:15 -08:00
|
|
|
write!(
|
|
|
|
f,
|
|
|
|
"alias {} := {}",
|
|
|
|
self.name.lexeme(),
|
|
|
|
self.target.lexeme()
|
|
|
|
)
|
2019-04-11 12:30:29 -07:00
|
|
|
}
|
|
|
|
}
|
2019-11-21 07:39:32 -08:00
|
|
|
|
|
|
|
impl<'src> Display for Alias<'src> {
|
|
|
|
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
|
|
|
write!(
|
|
|
|
f,
|
|
|
|
"alias {} := {}",
|
|
|
|
self.name.lexeme(),
|
|
|
|
self.target.name.lexeme()
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|