diff options
Diffstat (limited to 'src/makefile/macro.rs')
-rw-r--r-- | src/makefile/macro.rs | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/src/makefile/macro.rs b/src/makefile/macro.rs index 0b7a27d..f18060f 100644 --- a/src/makefile/macro.rs +++ b/src/makefile/macro.rs @@ -9,7 +9,7 @@ use super::functions; use super::token::{Token, TokenString}; #[derive(Debug, Clone)] -pub enum MacroSource { +pub enum Source { File, CommandLineOrMakeflags, Environment, @@ -21,13 +21,13 @@ pub trait LookupInternal: for<'a> Fn(&'a str) -> anyhow::Result<String> {} impl<F: for<'a> Fn(&'a str) -> anyhow::Result<String>> LookupInternal for F {} #[derive(Clone)] -pub struct MacroSet<'parent, 'lookup> { - parent: Option<&'parent MacroSet<'parent, 'lookup>>, - data: HashMap<String, (MacroSource, TokenString)>, +pub struct Set<'parent, 'lookup> { + parent: Option<&'parent Set<'parent, 'lookup>>, + data: HashMap<String, (Source, TokenString)>, lookup_internal: Option<&'lookup dyn LookupInternal>, } -impl<'parent, 'lookup> MacroSet<'parent, 'lookup> { +impl<'parent, 'lookup> Set<'parent, 'lookup> { pub fn new() -> Self { Self { parent: None, @@ -38,7 +38,7 @@ impl<'parent, 'lookup> MacroSet<'parent, 'lookup> { pub fn add_builtins(&mut self) { for (k, v) in builtins() { - self.data.insert(k.into(), (MacroSource::Builtin, v)); + self.data.insert(k.into(), (Source::Builtin, v)); } } @@ -46,7 +46,7 @@ impl<'parent, 'lookup> MacroSet<'parent, 'lookup> { for (k, v) in env::vars() { if k != "MAKEFLAGS" && k != "SHELL" { self.data - .insert(k, (MacroSource::Environment, TokenString::text(v))); + .insert(k, (Source::Environment, TokenString::text(v))); } } } @@ -61,13 +61,13 @@ impl<'parent, 'lookup> MacroSet<'parent, 'lookup> { } } - pub fn get(&self, name: &str) -> Option<&(MacroSource, TokenString)> { + pub fn get(&self, name: &str) -> Option<&(Source, TokenString)> { self.data .get(name) .or_else(|| self.parent.and_then(|parent| parent.get(name))) } - pub fn set(&mut self, name: String, source: MacroSource, text: TokenString) { + pub fn set(&mut self, name: String, source: Source, text: TokenString) { self.data.insert(name, (source, text)); } @@ -76,7 +76,7 @@ impl<'parent, 'lookup> MacroSet<'parent, 'lookup> { } // `remove` is fine, but I think for "remove-and-return" `pop` is better - pub fn pop(&mut self, name: &str) -> Option<(MacroSource, TokenString)> { + pub fn pop(&mut self, name: &str) -> Option<(Source, TokenString)> { self.data.remove(name) } @@ -121,16 +121,16 @@ impl<'parent, 'lookup> MacroSet<'parent, 'lookup> { Ok(result) } - pub fn with_lookup<'l, 's: 'l>(&'s self, lookup: &'l dyn LookupInternal) -> MacroSet<'s, 'l> { - MacroSet { + pub fn with_lookup<'l, 's: 'l>(&'s self, lookup: &'l dyn LookupInternal) -> Set<'s, 'l> { + Set { parent: Some(self), data: HashMap::new(), lookup_internal: Some(lookup), } } - pub fn with_overlay<'s>(&'s self) -> MacroSet<'s, 'lookup> { - MacroSet { + pub fn with_overlay<'s>(&'s self) -> Set<'s, 'lookup> { + Set { parent: Some(self), data: HashMap::new(), lookup_internal: None, @@ -138,7 +138,7 @@ impl<'parent, 'lookup> MacroSet<'parent, 'lookup> { } } -impl fmt::Display for MacroSet<'_, '_> { +impl fmt::Display for Set<'_, '_> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let pieces = self .data |