From f0c8ff01b14817e6c45ba679ab2a5f81d4ac36c2 Mon Sep 17 00:00:00 2001 From: BrettMayson Date: Sun, 15 Oct 2023 12:45:13 -0600 Subject: [PATCH] hls feature flag --- libs/common/Cargo.toml | 3 +++ libs/common/src/reporting/processed.rs | 9 +++++++-- libs/preprocessor/src/processor/defines.rs | 6 +++++- libs/preprocessor/src/processor/directives.rs | 1 + libs/preprocessor/src/processor/mod.rs | 5 +++++ 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/libs/common/Cargo.toml b/libs/common/Cargo.toml index 28bdcd24..35e2031d 100644 --- a/libs/common/Cargo.toml +++ b/libs/common/Cargo.toml @@ -13,3 +13,6 @@ thiserror = "1.0.49" toml = { workspace = true } tracing = { workspace = true } vfs = { workspace = true } + +[features] +hls = [] diff --git a/libs/common/src/reporting/processed.rs b/libs/common/src/reporting/processed.rs index 909827d0..ceebec91 100644 --- a/libs/common/src/reporting/processed.rs +++ b/libs/common/src/reporting/processed.rs @@ -1,3 +1,4 @@ +#[cfg(feature = "hls")] use std::collections::HashMap; use crate::{ @@ -20,10 +21,12 @@ pub struct Processed { /// string offset(start, stop), source, source position mappings: Vec, + #[cfg(feature = "hls")] /// Map of token usage to definition /// (token, definition) declarations: HashMap, + #[cfg(feature = "hls")] /// Map of token definition to usage /// (definition, usages) usage: HashMap>, @@ -168,12 +171,14 @@ impl Processed { /// [`Error::Workspace`] if a workspace path could not be read pub fn new( output: Vec, - usage: HashMap>, - declarations: HashMap, + #[cfg(feature = "hls")] usage: HashMap>, + #[cfg(feature = "hls")] declarations: HashMap, warnings: Vec>, ) -> Result { let mut processed = Self { + #[cfg(feature = "hls")] declarations, + #[cfg(feature = "hls")] usage, warnings, ..Default::default() diff --git a/libs/preprocessor/src/processor/defines.rs b/libs/preprocessor/src/processor/defines.rs index 3e4df4f1..5128a6d6 100644 --- a/libs/preprocessor/src/processor/defines.rs +++ b/libs/preprocessor/src/processor/defines.rs @@ -197,6 +197,7 @@ impl Processor { match body { Definition::Function(function) => { let Some(args) = self.call_read_args(callsite, stream)? else { + #[allow(clippy::redundant_clone)] // behind hls feature flag return Err(Error::Code(Box::new(FunctionAsValue { token: Box::new(ident.clone()), source: Box::new(source.clone()), @@ -242,6 +243,7 @@ impl Processor { } Definition::Void => return Ok(()), Definition::Unit => { + #[allow(clippy::redundant_clone)] // behind hls feature flag return Err(Error::Code(Box::new(ExpectedFunctionOrValue { token: Box::new(ident.clone()), source: Box::new(source.clone()), @@ -250,9 +252,10 @@ impl Processor { .expect("peeked by caller") .symbol() .is_left_paren(), - }))) + }))); } }; + #[cfg(feature = "hls")] self.usage.get_mut(source.position()).map_or_else( || { // println!("missing {:?}", ident.position()); @@ -261,6 +264,7 @@ impl Processor { usage.push(ident.position().clone()); }, ); + #[cfg(feature = "hls")] self.declarations .insert(ident.position().clone(), source.position().clone()); Ok(()) diff --git a/libs/preprocessor/src/processor/directives.rs b/libs/preprocessor/src/processor/directives.rs index b054aff4..18374308 100644 --- a/libs/preprocessor/src/processor/directives.rs +++ b/libs/preprocessor/src/processor/directives.rs @@ -206,6 +206,7 @@ impl Processor { Symbol::Newline | Symbol::Eoi => Definition::Unit, _ => Definition::Value(self.define_read_body(stream)), }; + #[cfg(feature = "hls")] self.usage.insert(ident.position().clone(), Vec::new()); self.defines.insert(&ident_string, (ident, definition)); Ok(()) diff --git a/libs/preprocessor/src/processor/mod.rs b/libs/preprocessor/src/processor/mod.rs index afb8e4ec..cd47b080 100644 --- a/libs/preprocessor/src/processor/mod.rs +++ b/libs/preprocessor/src/processor/mod.rs @@ -1,3 +1,4 @@ +#[cfg(feature = "hls")] use std::collections::HashMap; use hemtt_common::position::Position; @@ -27,10 +28,12 @@ pub struct Processor { pub(crate) token_count: usize, + #[cfg(feature = "hls")] /// Map of token usage to definition /// (token, definition) pub(crate) declarations: HashMap, + #[cfg(feature = "hls")] /// Map of token definition to usage /// (definition, usages) pub(crate) usage: HashMap>, @@ -75,7 +78,9 @@ impl Processor { Processed::new( buffer, + #[cfg(feature = "hls")] processor.usage, + #[cfg(feature = "hls")] processor.declarations, processor.warnings, )