Skip to content

Commit

Permalink
hls feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
BrettMayson committed Oct 15, 2023
1 parent 7f3cfd5 commit f0c8ff0
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
3 changes: 3 additions & 0 deletions libs/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ thiserror = "1.0.49"
toml = { workspace = true }
tracing = { workspace = true }
vfs = { workspace = true }

[features]
hls = []
9 changes: 7 additions & 2 deletions libs/common/src/reporting/processed.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(feature = "hls")]
use std::collections::HashMap;

use crate::{
Expand All @@ -20,10 +21,12 @@ pub struct Processed {
/// string offset(start, stop), source, source position
mappings: Vec<Mapping>,

#[cfg(feature = "hls")]
/// Map of token usage to definition
/// (token, definition)
declarations: HashMap<Position, Position>,

#[cfg(feature = "hls")]
/// Map of token definition to usage
/// (definition, usages)
usage: HashMap<Position, Vec<Position>>,
Expand Down Expand Up @@ -168,12 +171,14 @@ impl Processed {
/// [`Error::Workspace`] if a workspace path could not be read
pub fn new(
output: Vec<Output>,
usage: HashMap<Position, Vec<Position>>,
declarations: HashMap<Position, Position>,
#[cfg(feature = "hls")] usage: HashMap<Position, Vec<Position>>,
#[cfg(feature = "hls")] declarations: HashMap<Position, Position>,
warnings: Vec<Box<dyn Code>>,
) -> Result<Self, Error> {
let mut processed = Self {
#[cfg(feature = "hls")]
declarations,
#[cfg(feature = "hls")]
usage,
warnings,
..Default::default()
Expand Down
6 changes: 5 additions & 1 deletion libs/preprocessor/src/processor/defines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down Expand Up @@ -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()),
Expand All @@ -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());
Expand All @@ -261,6 +264,7 @@ impl Processor {
usage.push(ident.position().clone());
},
);
#[cfg(feature = "hls")]
self.declarations
.insert(ident.position().clone(), source.position().clone());
Ok(())
Expand Down
1 change: 1 addition & 0 deletions libs/preprocessor/src/processor/directives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
5 changes: 5 additions & 0 deletions libs/preprocessor/src/processor/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(feature = "hls")]
use std::collections::HashMap;

use hemtt_common::position::Position;
Expand Down Expand Up @@ -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<Position, Position>,

#[cfg(feature = "hls")]
/// Map of token definition to usage
/// (definition, usages)
pub(crate) usage: HashMap<Position, Vec<Position>>,
Expand Down Expand Up @@ -75,7 +78,9 @@ impl Processor {

Processed::new(
buffer,
#[cfg(feature = "hls")]
processor.usage,
#[cfg(feature = "hls")]
processor.declarations,
processor.warnings,
)
Expand Down

0 comments on commit f0c8ff0

Please sign in to comment.