From 457bcbfd1116f0b3330f9b409395beabffe6ca18 Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Wed, 14 Apr 2021 11:51:38 -0600 Subject: keep track of sources for inference rules too --- src/makefile/macro.rs | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'src/makefile/macro.rs') diff --git a/src/makefile/macro.rs b/src/makefile/macro.rs index fc3be51..2dfd84f 100644 --- a/src/makefile/macro.rs +++ b/src/makefile/macro.rs @@ -11,18 +11,11 @@ use regex::Regex; #[cfg(feature = "full")] use super::functions; use super::token::{Token, TokenString}; - -#[derive(Debug, Clone)] -pub enum Source { - File, - CommandLineOrMakeflags, - Environment, - Builtin, -} +use super::ItemSource; #[derive(Debug, Clone)] pub struct Macro { - pub source: Source, + pub source: ItemSource, pub text: TokenString, #[cfg(feature = "full")] pub eagerly_expanded: bool, @@ -121,7 +114,7 @@ impl<'parent, 'lookup> Set<'parent, 'lookup> { self.data.insert( k.into(), Macro { - source: Source::Builtin, + source: ItemSource::Builtin, text: v, #[cfg(feature = "full")] eagerly_expanded: false, @@ -136,7 +129,7 @@ impl<'parent, 'lookup> Set<'parent, 'lookup> { self.data.insert( k, Macro { - source: Source::Environment, + source: ItemSource::Environment, text: TokenString::text(v), #[cfg(feature = "full")] eagerly_expanded: false, @@ -277,23 +270,27 @@ impl<'parent, 'lookup> Set<'parent, 'lookup> { match self.data.get(name) { None => self.parent.map_or("undefined", |p| p.origin(name)), Some(Macro { - source: Source::Builtin, + source: ItemSource::Builtin, .. }) => "default", Some(Macro { - source: Source::Environment, + source: ItemSource::Environment, .. }) => "environment", // TODO figure out when to return "environment override" Some(Macro { - source: Source::File, + source: ItemSource::File { .. }, .. }) => "file", Some(Macro { - source: Source::CommandLineOrMakeflags, + source: ItemSource::CommandLineOrMakeflags, .. }) => "command line", - // TODO handle override and automatic + // TODO handle override + Some(Macro { + source: ItemSource::FunctionCall, + .. + }) => "automatic", } } @@ -416,7 +413,7 @@ mod test { macros.set( "oof".to_owned(), Macro { - source: Source::File, + source: ItemSource::Builtin, text: TokenString::text("bruh; swag; yeet;"), #[cfg(feature = "full")] eagerly_expanded: false, -- cgit v1.2.3