about summary refs log tree commit diff
path: root/src/comp
diff options
context:
space:
mode:
authorGraydon Hoare <graydon@mozilla.com>2011-06-10 15:54:41 -0700
committerGraydon Hoare <graydon@mozilla.com>2011-06-10 15:54:41 -0700
commit9671d214082016e61b59bd67bb6d4e295188a2a4 (patch)
tree50e22a6fac9b3bb3e60fe30909117375f5edd10e /src/comp
parent774c6d01984b608047afedb5d8c579c00d69823f (diff)
downloadrust-9671d214082016e61b59bd67bb6d4e295188a2a4.tar.gz
rust-9671d214082016e61b59bd67bb6d4e295188a2a4.zip
Implement meta tag matching in creader. Start using it in rustc.rc. Close #459. Close #457.
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/front/creader.rs50
-rw-r--r--src/comp/front/eval.rs3
-rw-r--r--src/comp/rustc.rc4
3 files changed, 51 insertions, 6 deletions
diff --git a/src/comp/front/creader.rs b/src/comp/front/creader.rs
index 6abae3c61b7..7b92a6d6641 100644
--- a/src/comp/front/creader.rs
+++ b/src/comp/front/creader.rs
@@ -505,9 +505,54 @@ fn get_metadata_section(str filename) -> option::t[vec[u8]] {
     ret option::none[vec[u8]];
 }
 
+fn get_exported_metadata(&session::session sess,
+                         &str path,
+                         &vec[u8] data) -> hashmap[str,str] {
+    auto meta_items = ebml::get_doc(ebml::new_doc(data),
+                                    metadata::tag_meta_export);
+    auto mm = common::new_str_hash[str]();
 
-fn metadata_matches(&vec[u8] data,
+    for each (ebml::doc m in ebml::tagged_docs(meta_items,
+                                               metadata::tag_meta_item)) {
+
+        auto kd = ebml::get_doc(m, metadata::tag_meta_item_key);
+        auto vd = ebml::get_doc(m, metadata::tag_meta_item_value);
+
+        auto k = str::unsafe_from_bytes(ebml::doc_data(kd));
+        auto v = str::unsafe_from_bytes(ebml::doc_data(vd));
+
+        log #fmt("metadata in %s: %s = %s", path, k, v);
+
+        if (!mm.insert(k,v)) {
+            sess.warn(#fmt("Duplicate metadata item in %s: %s", path, k));
+        }
+    }
+    ret mm;
+}
+
+fn metadata_matches(hashmap[str,str] mm,
                     &vec[@ast::meta_item] metas) -> bool {
+    log #fmt("matching %u metadata requirements against %u metadata items",
+             vec::len(metas), mm.size());
+    for (@ast::meta_item mi in metas) {
+        alt (mm.find(mi.node.key)) {
+            case (some(?v)) {
+                if (v == mi.node.value) {
+                    log #fmt("matched '%s': '%s'",
+                             mi.node.key, mi.node.value);
+                } else {
+                    log #fmt("missing '%s': '%s' (got '%s')",
+                             mi.node.key, mi.node.value, v);
+                    ret false;
+                }
+            }
+            case (none) {
+                    log #fmt("missing '%s': '%s'",
+                             mi.node.key, mi.node.value);
+                    ret false;
+            }
+        }
+    }
     ret true;
 }
 
@@ -547,7 +592,8 @@ fn find_library_crate(&session::session sess,
 
             alt (get_metadata_section(path)) {
                 case (option::some(?cvec)) {
-                    if (!metadata_matches(cvec, metas)) {
+                    auto mm = get_exported_metadata(sess, path, cvec);
+                    if (!metadata_matches(mm, metas)) {
                         log #fmt("skipping %s, metadata doesn't match", path);
                         cont;
                     }
diff --git a/src/comp/front/eval.rs b/src/comp/front/eval.rs
index 567066436e4..b311c56b884 100644
--- a/src/comp/front/eval.rs
+++ b/src/comp/front/eval.rs
@@ -419,9 +419,6 @@ fn eval_crate_directive(ctx cx,
         }
 
         case (ast::cdir_meta(?vi, ?mi)) {
-            // FIXME: we should actually record, for documentation-sake,
-            // the metadata that's not exported. It would be nice to have
-            // compiled-in to the target crate, not just in theh AST.
             if (vi == ast::export_meta) {
                 cx.sess.add_metadata(mi);
             }
diff --git a/src/comp/rustc.rc b/src/comp/rustc.rc
index ebd62b99fc3..39879894753 100644
--- a/src/comp/rustc.rc
+++ b/src/comp/rustc.rc
@@ -10,7 +10,9 @@ meta (desc = "The Rust compiler",
       license = "BSD");
 
 
-use std;
+use std (name = "std",
+         vers = "0.1",
+         url = "http://rust-lang.org/src/std");
 
 mod middle {
     mod trans;