aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_cfg/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_cfg/src/lib.rs')
-rw-r--r--crates/ra_cfg/src/lib.rs51
1 files changed, 0 insertions, 51 deletions
diff --git a/crates/ra_cfg/src/lib.rs b/crates/ra_cfg/src/lib.rs
deleted file mode 100644
index 6fb37bf9f..000000000
--- a/crates/ra_cfg/src/lib.rs
+++ /dev/null
@@ -1,51 +0,0 @@
1//! ra_cfg defines conditional compiling options, `cfg` attibute parser and evaluator
2
3mod cfg_expr;
4
5use rustc_hash::FxHashSet;
6use tt::SmolStr;
7
8pub use cfg_expr::CfgExpr;
9
10/// Configuration options used for conditional compilition on items with `cfg` attributes.
11/// We have two kind of options in different namespaces: atomic options like `unix`, and
12/// key-value options like `target_arch="x86"`.
13///
14/// Note that for key-value options, one key can have multiple values (but not none).
15/// `feature` is an example. We have both `feature="foo"` and `feature="bar"` if features
16/// `foo` and `bar` are both enabled. And here, we store key-value options as a set of tuple
17/// of key and value in `key_values`.
18///
19/// See: https://doc.rust-lang.org/reference/conditional-compilation.html#set-configuration-options
20#[derive(Debug, Clone, PartialEq, Eq, Default)]
21pub struct CfgOptions {
22 atoms: FxHashSet<SmolStr>,
23 key_values: FxHashSet<(SmolStr, SmolStr)>,
24}
25
26impl CfgOptions {
27 pub fn check(&self, cfg: &CfgExpr) -> Option<bool> {
28 cfg.fold(&|key, value| match value {
29 None => self.atoms.contains(key),
30 Some(value) => self.key_values.contains(&(key.clone(), value.clone())),
31 })
32 }
33
34 pub fn insert_atom(&mut self, key: SmolStr) {
35 self.atoms.insert(key);
36 }
37
38 pub fn insert_key_value(&mut self, key: SmolStr, value: SmolStr) {
39 self.key_values.insert((key, value));
40 }
41
42 pub fn append(&mut self, other: &CfgOptions) {
43 for atom in &other.atoms {
44 self.atoms.insert(atom.clone());
45 }
46
47 for (key, value) in &other.key_values {
48 self.key_values.insert((key.clone(), value.clone()));
49 }
50 }
51}