2022-06-18 21:56:31 -07:00
|
|
|
use super::*;
|
2019-04-11 12:30:29 -07:00
|
|
|
|
2019-11-07 10:55:15 -08:00
|
|
|
/// An alias, e.g. `name := target`
|
2021-11-17 00:07:48 -08:00
|
|
|
#[derive(Debug, PartialEq, Clone, Serialize)]
|
2019-11-21 07:39:32 -08:00
|
|
|
pub(crate) struct Alias<'src, T = Rc<Recipe<'src>>> {
|
2024-01-12 18:44:13 -08:00
|
|
|
pub(crate) attributes: BTreeSet<Attribute<'src>>,
|
2021-09-16 06:44:40 -07:00
|
|
|
pub(crate) name: Name<'src>,
|
2021-11-17 00:07:48 -08:00
|
|
|
#[serde(
|
|
|
|
bound(serialize = "T: Keyed<'src>"),
|
|
|
|
serialize_with = "keyed::serialize"
|
|
|
|
)]
|
2019-11-21 07:39:32 -08:00
|
|
|
pub(crate) target: T,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'src> Alias<'src, Name<'src>> {
|
|
|
|
pub(crate) fn resolve(self, target: Rc<Recipe<'src>>) -> Alias<'src> {
|
|
|
|
assert_eq!(self.target.lexeme(), target.name.lexeme());
|
|
|
|
|
|
|
|
Alias {
|
2022-12-20 00:44:19 -08:00
|
|
|
attributes: self.attributes,
|
2019-11-21 07:39:32 -08:00
|
|
|
name: self.name,
|
|
|
|
target,
|
|
|
|
}
|
|
|
|
}
|
2019-11-07 10:55:15 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Alias<'_> {
|
|
|
|
pub(crate) fn is_private(&self) -> bool {
|
2022-12-20 00:44:19 -08:00
|
|
|
self.name.lexeme().starts_with('_') || self.attributes.contains(&Attribute::Private)
|
2019-11-07 10:55:15 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|