Add export alias and export extern (#4878)

* export alias

* export extern
This commit is contained in:
JT
2022-03-20 07:58:01 +13:00
committed by GitHub
parent 285f91e67a
commit f3bb1d11d3
10 changed files with 292 additions and 15 deletions

View File

@ -770,6 +770,19 @@ impl<'a> StateWorkingSet<'a> {
}
}
pub fn use_aliases(&mut self, aliases: Vec<(Vec<u8>, AliasId)>) {
let scope_frame = self
.delta
.scope
.last_mut()
.expect("internal error: missing required scope frame");
for (name, alias_id) in aliases {
scope_frame.aliases.insert(name, alias_id);
scope_frame.visibility.use_decl_id(&alias_id);
}
}
pub fn add_predecl(&mut self, decl: Box<dyn Command>) -> Option<DeclId> {
let name = decl.name().as_bytes().to_vec();

View File

@ -1,6 +1,7 @@
use crate::{BlockId, DeclId};
use crate::{AliasId, BlockId, DeclId};
pub enum Exportable {
Decl(DeclId),
Alias(AliasId),
EnvVar(BlockId),
}

View File

@ -116,6 +116,18 @@ impl Overlay {
.collect()
}
pub fn aliases_with_head(&self, head: &[u8]) -> Vec<(Vec<u8>, AliasId)> {
self.aliases
.iter()
.map(|(name, id)| {
let mut new_name = head.to_vec();
new_name.push(b' ');
new_name.extend(name);
(new_name, *id)
})
.collect()
}
pub fn alias_names_with_head(&self, head: &[u8]) -> Vec<Vec<u8>> {
self.aliases
.keys()