From 0cf8ee2dc22569fac2115c41b85d5df23af3ce5a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 23 Jul 2020 15:57:25 +0200 Subject: Remove dead code --- crates/ra_cfg/src/lib.rs | 4 ---- 1 file changed, 4 deletions(-) (limited to 'crates/ra_cfg') diff --git a/crates/ra_cfg/src/lib.rs b/crates/ra_cfg/src/lib.rs index f9c73ece1..cd097f2a0 100644 --- a/crates/ra_cfg/src/lib.rs +++ b/crates/ra_cfg/src/lib.rs @@ -39,10 +39,6 @@ impl CfgOptions { self.atoms.insert(key); } - pub fn remove_atom(&mut self, name: &str) { - self.atoms.remove(name); - } - pub fn insert_key_value(&mut self, key: SmolStr, value: SmolStr) { self.key_values.insert((key, value)); } -- cgit v1.2.3 From 38e38d9b290ff90973c25a06962b81dbbb5d3d9e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 23 Jul 2020 16:22:17 +0200 Subject: Cleanup CFG API --- crates/ra_cfg/src/cfg_expr.rs | 21 ++++++++++----------- crates/ra_cfg/src/lib.rs | 6 +----- 2 files changed, 11 insertions(+), 16 deletions(-) (limited to 'crates/ra_cfg') diff --git a/crates/ra_cfg/src/cfg_expr.rs b/crates/ra_cfg/src/cfg_expr.rs index 85b100c6a..f48928aee 100644 --- a/crates/ra_cfg/src/cfg_expr.rs +++ b/crates/ra_cfg/src/cfg_expr.rs @@ -5,7 +5,6 @@ use std::slice::Iter as SliceIter; use ra_syntax::SmolStr; -use tt::{Leaf, Subtree, TokenTree}; #[derive(Debug, Clone, PartialEq, Eq)] pub enum CfgExpr { @@ -18,6 +17,9 @@ pub enum CfgExpr { } impl CfgExpr { + pub fn parse(tt: &tt::Subtree) -> CfgExpr { + next_cfg_expr(&mut tt.token_trees.iter()).unwrap_or(CfgExpr::Invalid) + } /// Fold the cfg by querying all basic `Atom` and `KeyValue` predicates. pub fn fold(&self, query: &dyn Fn(&SmolStr, Option<&SmolStr>) -> bool) -> Option { match self { @@ -35,22 +37,18 @@ impl CfgExpr { } } -pub fn parse_cfg(tt: &Subtree) -> CfgExpr { - next_cfg_expr(&mut tt.token_trees.iter()).unwrap_or(CfgExpr::Invalid) -} - fn next_cfg_expr(it: &mut SliceIter) -> Option { let name = match it.next() { None => return None, - Some(TokenTree::Leaf(Leaf::Ident(ident))) => ident.text.clone(), + Some(tt::TokenTree::Leaf(tt::Leaf::Ident(ident))) => ident.text.clone(), Some(_) => return Some(CfgExpr::Invalid), }; // Peek let ret = match it.as_slice().first() { - Some(TokenTree::Leaf(Leaf::Punct(punct))) if punct.char == '=' => { + Some(tt::TokenTree::Leaf(tt::Leaf::Punct(punct))) if punct.char == '=' => { match it.as_slice().get(1) { - Some(TokenTree::Leaf(Leaf::Literal(literal))) => { + Some(tt::TokenTree::Leaf(tt::Leaf::Literal(literal))) => { it.next(); it.next(); // FIXME: escape? raw string? @@ -61,7 +59,7 @@ fn next_cfg_expr(it: &mut SliceIter) -> Option { _ => return Some(CfgExpr::Invalid), } } - Some(TokenTree::Subtree(subtree)) => { + Some(tt::TokenTree::Subtree(subtree)) => { it.next(); let mut sub_it = subtree.token_trees.iter(); let mut subs = std::iter::from_fn(|| next_cfg_expr(&mut sub_it)).collect(); @@ -76,7 +74,7 @@ fn next_cfg_expr(it: &mut SliceIter) -> Option { }; // Eat comma separator - if let Some(TokenTree::Leaf(Leaf::Punct(punct))) = it.as_slice().first() { + if let Some(tt::TokenTree::Leaf(tt::Leaf::Punct(punct))) = it.as_slice().first() { if punct.char == ',' { it.next(); } @@ -99,7 +97,8 @@ mod tests { fn assert_parse_result(input: &str, expected: CfgExpr) { let (tt, _) = get_token_tree_generated(input); - assert_eq!(parse_cfg(&tt), expected); + let cfg = CfgExpr::parse(&tt); + assert_eq!(cfg, expected); } #[test] diff --git a/crates/ra_cfg/src/lib.rs b/crates/ra_cfg/src/lib.rs index cd097f2a0..cd5a0a7b6 100644 --- a/crates/ra_cfg/src/lib.rs +++ b/crates/ra_cfg/src/lib.rs @@ -5,7 +5,7 @@ mod cfg_expr; use ra_syntax::SmolStr; use rustc_hash::FxHashSet; -pub use cfg_expr::{parse_cfg, CfgExpr}; +pub use cfg_expr::CfgExpr; /// Configuration options used for conditional compilition on items with `cfg` attributes. /// We have two kind of options in different namespaces: atomic options like `unix`, and @@ -31,10 +31,6 @@ impl CfgOptions { }) } - pub fn is_cfg_enabled(&self, attr: &tt::Subtree) -> Option { - self.check(&parse_cfg(attr)) - } - pub fn insert_atom(&mut self, key: SmolStr) { self.atoms.insert(key); } -- cgit v1.2.3