Refactor a few things in the metadata module
Rename metadata::tags to metadata::common. Move some utility functions from metadata::encoder to metadata::common.
This commit is contained in:
parent
b723082cdb
commit
e29ef1bec2
@ -1,4 +1,6 @@
|
||||
// EBML tag definitions shared by the encoder and decoder
|
||||
// EBML tag definitions and utils shared by the encoder and decoder
|
||||
|
||||
import std::str;
|
||||
|
||||
const uint tag_paths = 0x01u;
|
||||
|
||||
@ -52,4 +54,14 @@ const uint tag_attribute = 0x22u;
|
||||
|
||||
const uint tag_meta_item_word = 0x23u;
|
||||
|
||||
const uint tag_meta_item_list = 0x24u;
|
||||
const uint tag_meta_item_list = 0x24u;
|
||||
|
||||
// djb's cdb hashes.
|
||||
fn hash_node_id(&int node_id) -> uint { ret 177573u ^ (node_id as uint); }
|
||||
|
||||
fn hash_path(&str s) -> uint {
|
||||
auto h = 5381u;
|
||||
for (u8 ch in str::bytes(s)) { h = (h << 5u) + h ^ (ch as uint); }
|
||||
ret h;
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ import std::option::none;
|
||||
import std::option::some;
|
||||
import std::map::hashmap;
|
||||
import syntax::print::pprust;
|
||||
import tags::*;
|
||||
import common::*;
|
||||
|
||||
export read_crates;
|
||||
export list_file_metadata;
|
||||
|
@ -10,11 +10,10 @@ import std::map::hashmap;
|
||||
import syntax::ast;
|
||||
import front::attr;
|
||||
import middle::ty;
|
||||
import tags::*;
|
||||
import common::*;
|
||||
import tydecode::parse_def_id;
|
||||
import tydecode::parse_ty_data;
|
||||
import driver::session;
|
||||
import util::common;
|
||||
import syntax::print::pprust;
|
||||
|
||||
export get_symbol;
|
||||
@ -51,7 +50,7 @@ fn maybe_find_item(int item_id, &ebml::doc items) -> option::t[ebml::doc] {
|
||||
ret ebml::be_uint_from_bytes(bytes, 0u, 4u) as int == item_id;
|
||||
}
|
||||
auto eqer = bind eq_item(_, item_id);
|
||||
auto found = lookup_hash(items, eqer, encoder::hash_node_id(item_id));
|
||||
auto found = lookup_hash(items, eqer, hash_node_id(item_id));
|
||||
if (vec::len(found) == 0u) {
|
||||
ret option::none[ebml::doc];
|
||||
} else { ret option::some[ebml::doc](found.(0)); }
|
||||
@ -129,7 +128,7 @@ fn resolve_path(vec[ast::ident] path, vec[u8] data) -> vec[ast::def_id] {
|
||||
auto paths = ebml::get_doc(md, tag_paths);
|
||||
auto eqer = bind eq_item(_, s);
|
||||
let vec[ast::def_id] result = [];
|
||||
for (ebml::doc doc in lookup_hash(paths, eqer, encoder::hash_path(s))) {
|
||||
for (ebml::doc doc in lookup_hash(paths, eqer, hash_path(s))) {
|
||||
auto did_doc = ebml::get_doc(doc, tag_def_id);
|
||||
vec::push(result, parse_def_id(ebml::doc_data(did_doc)));
|
||||
}
|
||||
|
@ -10,15 +10,13 @@ import std::option::some;
|
||||
import std::option::none;
|
||||
import std::ebml;
|
||||
import syntax::ast::*;
|
||||
import tags::*;
|
||||
import common::*;
|
||||
import middle::trans::crate_ctxt;
|
||||
import middle::ty;
|
||||
import middle::ty::node_id_to_monotype;
|
||||
import front::attr;
|
||||
|
||||
export def_to_str;
|
||||
export hash_path;
|
||||
export hash_node_id;
|
||||
export encode_metadata;
|
||||
|
||||
// Path table encoding
|
||||
@ -370,15 +368,6 @@ fn encode_info_for_items(&@crate_ctxt cx, &ebml::writer ebml_w) ->
|
||||
|
||||
// Path and definition ID indexing
|
||||
|
||||
// djb's cdb hashes.
|
||||
fn hash_node_id(&int node_id) -> uint { ret 177573u ^ (node_id as uint); }
|
||||
|
||||
fn hash_path(&str s) -> uint {
|
||||
auto h = 5381u;
|
||||
for (u8 ch in str::bytes(s)) { h = (h << 5u) + h ^ (ch as uint); }
|
||||
ret h;
|
||||
}
|
||||
|
||||
fn create_index[T](&vec[tup(T, uint)] index, fn(&T) -> uint hash_fn) ->
|
||||
vec[vec[tup(T, uint)]] {
|
||||
let vec[mutable vec[tup(T, uint)]] buckets = vec::empty_mut();
|
||||
|
@ -82,7 +82,7 @@ mod metadata {
|
||||
export decoder;
|
||||
export creader;
|
||||
|
||||
mod tags;
|
||||
mod common;
|
||||
mod tyencode;
|
||||
mod tydecode;
|
||||
mod encoder;
|
||||
|
Loading…
x
Reference in New Issue
Block a user