aboutsummaryrefslogtreecommitdiff
path: root/src/makefile/mod.rs
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2024-11-11 00:07:33 -0700
committerMelody Horn <melody@boringcactus.com>2024-11-11 00:07:33 -0700
commitec2c18171cd316a8b1f69baf92f67980820dfc9a (patch)
tree007add1cd59aec07098134b018efededee463d97 /src/makefile/mod.rs
parent825ff799a2154ffb94ef21bbc14e2afe2afa2006 (diff)
downloadmakers-ec2c18171cd316a8b1f69baf92f67980820dfc9a.tar.gz
makers-ec2c18171cd316a8b1f69baf92f67980820dfc9a.zip
overhaul macro inheritance
i was really proud of the lifetimes i had going on in the previous code. i should not have been.
Diffstat (limited to 'src/makefile/mod.rs')
-rw-r--r--src/makefile/mod.rs16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/makefile/mod.rs b/src/makefile/mod.rs
index 9255ebf..ddfac6f 100644
--- a/src/makefile/mod.rs
+++ b/src/makefile/mod.rs
@@ -12,7 +12,9 @@ use inference_rules::InferenceRule;
use input::FinishedMakefileReader;
pub use input::MakefileReader;
use lookup_internal::LookupInternal;
-use r#macro::{Macro, Set as MacroSet};
+pub use macro_scope::MacroScopeStack;
+use r#macro::Macro;
+pub use r#macro::Set as MacroSet;
use target::{DynamicTargetSet, Target};
use token::TokenString;
@@ -31,6 +33,7 @@ mod inference_rules;
mod input;
mod lookup_internal;
mod r#macro;
+mod macro_scope;
mod pattern;
mod target;
mod token;
@@ -51,7 +54,7 @@ pub enum ItemSource {
pub struct Makefile<'a> {
inference_rules: Vec<InferenceRule>,
builtin_inference_rules: Vec<InferenceRule>,
- pub macros: MacroSet<'static, 'static>,
+ pub macros: MacroSet,
targets: DynamicTargetSet,
pub first_non_special_target: Option<String>,
args: &'a Args,
@@ -157,9 +160,9 @@ impl<'a> Makefile<'a> {
self.update_target(&failed_include).wrap_err_with(|| {
format!("while building missing included file {}", &failed_include)
})?;
- let macros = self.macros.with_overlay();
+ let stack = MacroScopeStack::default().with_scope(&self.macros);
let file =
- MakefileReader::read_file(self.args, macros, failed_include, Default::default())?
+ MakefileReader::read_file(self.args, stack, failed_include, Default::default())?
.finish();
self.extend(file)?;
}
@@ -349,8 +352,9 @@ impl<'a> Makefile<'a> {
}
fn expand_macros(&self, text: &TokenString, target: Option<&Target>) -> Result<String> {
- self.macros
- .with_lookup(LookupInternal::new(target, &|name| self.get_target(name)))
+ MacroScopeStack::default()
+ .with_scope(&self.macros)
+ .with_scope(&LookupInternal::new(target, &|name| self.get_target(name)))
.expand(
text,
#[cfg(feature = "full")]