about summary refs log tree commit diff
path: root/src/comp
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2011-06-30 14:12:11 -0700
committerBrian Anderson <banderson@mozilla.com>2011-06-30 14:13:49 -0700
commit64d60814292d75a4aa370012eebb299b0be01c45 (patch)
tree838482d298d24e75e583383d1e520183ca41697f /src/comp
parentdf8161d44cf8eb9d17a626879e4f5cbc954b4b88 (diff)
downloadrust-64d60814292d75a4aa370012eebb299b0be01c45.tar.gz
rust-64d60814292d75a4aa370012eebb299b0be01c45.zip
Use attributes for conditional compilation in std.rc
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/front/attr.rs4
-rw-r--r--src/comp/front/config.rs22
2 files changed, 24 insertions, 2 deletions
diff --git a/src/comp/front/attr.rs b/src/comp/front/attr.rs
index 152f81c5b7a..4fe0b814165 100644
--- a/src/comp/front/attr.rs
+++ b/src/comp/front/attr.rs
@@ -99,11 +99,15 @@ fn eq(@ast::meta_item a, @ast::meta_item b) -> bool {
 }
 
 fn contains(&vec[@ast::meta_item] haystack, @ast::meta_item needle) -> bool {
+    log #fmt("looking for %s", pretty::pprust::meta_item_to_str(*needle));
     for (@ast::meta_item item in haystack) {
+        log #fmt("looking in %s", pretty::pprust::meta_item_to_str(*item));
         if (eq(item, needle)) {
+            log "found it!";
             ret true;
         }
     }
+    log "found it not :(";
     ret false;
 }
 
diff --git a/src/comp/front/config.rs b/src/comp/front/config.rs
index 5d10ea05816..bbfc9001572 100644
--- a/src/comp/front/config.rs
+++ b/src/comp/front/config.rs
@@ -71,12 +71,30 @@ fn fold_block(&ast::crate_cfg cfg, &ast::block_ b,
 // configuration based on the item's attributes
 fn in_cfg(&ast::crate_cfg cfg, &@ast::item item) -> bool {
 
+    // The "cfg" attributes on the item
     auto item_cfg_attrs = attr::find_attrs_by_name(item.attrs, "cfg");
-
     auto item_has_cfg_attrs = vec::len(item_cfg_attrs) > 0u;
     if (!item_has_cfg_attrs) { ret true; }
 
-    auto item_cfg_metas = attr::attr_metas(item_cfg_attrs);
+    // Pull the inner meta_items from the #[cfg(meta_item, ...)]  attributes,
+    // so we can match against them. This is the list of configurations for
+    // which the item is valid
+    auto item_cfg_metas = {
+        fn extract_metas(&vec[@ast::meta_item] inner_items,
+                         &@ast::meta_item cfg_item)
+        -> vec[@ast::meta_item] {
+
+            alt (cfg_item.node) {
+                case (ast::meta_list(?name, ?items)) {
+                    assert name == "cfg";
+                    inner_items + items
+                }
+                case (_) { inner_items }
+            }
+        }
+        auto cfg_metas = attr::attr_metas(item_cfg_attrs);
+        vec::foldl(extract_metas, [], cfg_metas)
+    };
 
     for (@ast::meta_item cfg_mi in item_cfg_metas) {
         if (attr::contains(cfg, cfg_mi)) {