2011-07-08 01:29:09 -05:00
|
|
|
// Decoding metadata from a single crate's metadata
|
2011-06-27 18:03:01 -05:00
|
|
|
|
2011-08-12 00:58:14 -05:00
|
|
|
import std::ebml;
|
2011-08-15 18:38:23 -05:00
|
|
|
import std::vec;
|
2011-06-27 17:53:27 -05:00
|
|
|
import std::option;
|
|
|
|
import std::str;
|
2011-08-11 21:14:38 -05:00
|
|
|
import std::io;
|
2011-06-27 20:32:15 -05:00
|
|
|
import std::map::hashmap;
|
2011-07-05 04:48:19 -05:00
|
|
|
import syntax::ast;
|
2011-06-30 19:03:08 -05:00
|
|
|
import front::attr;
|
2011-06-27 17:53:27 -05:00
|
|
|
import middle::ty;
|
2011-07-07 14:22:39 -05:00
|
|
|
import common::*;
|
2011-06-27 17:53:27 -05:00
|
|
|
import tydecode::parse_def_id;
|
|
|
|
import tydecode::parse_ty_data;
|
|
|
|
import driver::session;
|
2011-07-05 04:48:19 -05:00
|
|
|
import syntax::print::pprust;
|
2011-07-07 20:13:24 -05:00
|
|
|
import cstore;
|
2011-06-27 17:53:27 -05:00
|
|
|
|
|
|
|
export get_symbol;
|
|
|
|
export get_tag_variants;
|
|
|
|
export get_type;
|
2011-06-30 05:35:19 -05:00
|
|
|
export get_type_param_count;
|
2011-07-29 18:40:23 -05:00
|
|
|
export get_type_param_kinds;
|
2011-06-27 17:53:27 -05:00
|
|
|
export lookup_defs;
|
2011-06-28 14:53:59 -05:00
|
|
|
export get_crate_attributes;
|
2011-06-27 17:53:27 -05:00
|
|
|
export list_crate_metadata;
|
2011-07-08 14:55:38 -05:00
|
|
|
export crate_dep;
|
|
|
|
export get_crate_deps;
|
2011-07-08 16:53:25 -05:00
|
|
|
export external_resolver;
|
|
|
|
|
|
|
|
// A function that takes a def_id relative to the crate being searched and
|
|
|
|
// returns a def_id relative to the compilation environment, i.e. if we hit a
|
|
|
|
// def_id for an item defined in another crate, somebody needs to figure out
|
|
|
|
// what crate that's in and give us a def_id that makes sense for the current
|
|
|
|
// build.
|
2011-08-19 17:16:48 -05:00
|
|
|
type external_resolver = fn(&ast::def_id) -> ast::def_id;
|
2011-07-27 07:19:39 -05:00
|
|
|
|
2011-08-19 17:16:48 -05:00
|
|
|
fn lookup_hash(d: &ebml::doc, eq_fn: fn(&[u8]) -> bool, hash: uint) ->
|
2011-08-12 00:58:14 -05:00
|
|
|
[ebml::doc] {
|
|
|
|
let index = ebml::get_doc(d, tag_index);
|
|
|
|
let table = ebml::get_doc(index, tag_index_table);
|
2011-07-27 07:19:39 -05:00
|
|
|
let hash_pos = table.start + hash % 256u * 4u;
|
2011-08-12 00:58:14 -05:00
|
|
|
let pos = ebml::be_uint_from_bytes(d.data, hash_pos, 4u);
|
|
|
|
let bucket = ebml::doc_at(d.data, pos);
|
2011-06-27 17:53:27 -05:00
|
|
|
// Awkward logic because we can't ret from foreach yet
|
|
|
|
|
2011-08-19 17:16:48 -05:00
|
|
|
let result: [ebml::doc] = [];
|
2011-07-27 07:19:39 -05:00
|
|
|
let belt = tag_index_buckets_bucket_elt;
|
2011-08-15 23:54:52 -05:00
|
|
|
for each elt: ebml::doc in ebml::tagged_docs(bucket, belt) {
|
2011-08-12 00:58:14 -05:00
|
|
|
let pos = ebml::be_uint_from_bytes(elt.data, elt.start, 4u);
|
2011-08-13 02:09:25 -05:00
|
|
|
if eq_fn(vec::slice::<u8>(*elt.data, elt.start + 4u, elt.end)) {
|
2011-08-19 17:16:48 -05:00
|
|
|
result += [ebml::doc_at(d.data, pos)];
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ret result;
|
|
|
|
}
|
|
|
|
|
2011-08-19 17:16:48 -05:00
|
|
|
fn maybe_find_item(item_id: int, items: &ebml::doc) -> option::t<ebml::doc> {
|
2011-08-04 18:20:09 -05:00
|
|
|
fn eq_item(bytes: &[u8], item_id: int) -> bool {
|
2011-08-12 00:58:14 -05:00
|
|
|
ret ebml::be_uint_from_bytes(@bytes, 0u, 4u) as int == item_id;
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
let eqer = bind eq_item(_, item_id);
|
|
|
|
let found = lookup_hash(items, eqer, hash_node_id(item_id));
|
2011-08-15 18:38:23 -05:00
|
|
|
if vec::len(found) == 0u {
|
2011-08-13 02:09:25 -05:00
|
|
|
ret option::none::<ebml::doc>;
|
2011-08-19 17:16:48 -05:00
|
|
|
} else { ret option::some::<ebml::doc>(found[0]); }
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
|
2011-08-12 00:58:14 -05:00
|
|
|
fn find_item(item_id: int, items: &ebml::doc) -> ebml::doc {
|
2011-06-27 17:53:27 -05:00
|
|
|
ret option::get(maybe_find_item(item_id, items));
|
|
|
|
}
|
|
|
|
|
2011-08-12 00:58:14 -05:00
|
|
|
// Looks up an item in the given metadata and returns an ebml doc pointing
|
2011-06-27 17:53:27 -05:00
|
|
|
// to the item data.
|
2011-08-12 00:58:14 -05:00
|
|
|
fn lookup_item(item_id: int, data: &@[u8]) -> ebml::doc {
|
|
|
|
let items = ebml::get_doc(ebml::new_doc(data), tag_items);
|
2011-06-27 17:53:27 -05:00
|
|
|
ret find_item(item_id, items);
|
|
|
|
}
|
|
|
|
|
2011-08-12 00:58:14 -05:00
|
|
|
fn item_family(item: &ebml::doc) -> u8 {
|
|
|
|
let fam = ebml::get_doc(item, tag_items_data_item_family);
|
|
|
|
ret ebml::doc_as_uint(fam) as u8;
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
|
2011-08-12 00:58:14 -05:00
|
|
|
fn item_symbol(item: &ebml::doc) -> str {
|
|
|
|
let sym = ebml::get_doc(item, tag_items_data_item_symbol);
|
|
|
|
ret str::unsafe_from_bytes(ebml::doc_data(sym));
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
|
2011-08-12 00:58:14 -05:00
|
|
|
fn variant_tag_id(d: &ebml::doc) -> ast::def_id {
|
|
|
|
let tagdoc = ebml::get_doc(d, tag_items_data_item_tag_id);
|
|
|
|
ret parse_def_id(ebml::doc_data(tagdoc));
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
|
2011-08-12 00:58:14 -05:00
|
|
|
fn item_type(item: &ebml::doc, this_cnum: ast::crate_num, tcx: ty::ctxt,
|
2011-07-27 07:19:39 -05:00
|
|
|
extres: &external_resolver) -> ty::t {
|
|
|
|
fn parse_external_def_id(this_cnum: ast::crate_num,
|
|
|
|
extres: &external_resolver, s: str) ->
|
|
|
|
ast::def_id {
|
2011-08-11 18:36:20 -05:00
|
|
|
let buf = str::bytes(s);
|
2011-07-27 07:19:39 -05:00
|
|
|
let external_def_id = parse_def_id(buf);
|
|
|
|
|
2011-07-08 01:29:09 -05:00
|
|
|
|
|
|
|
// This item was defined in the crate we're searching if it's has the
|
|
|
|
// local crate number, otherwise we need to search a different crate
|
2011-07-27 07:19:39 -05:00
|
|
|
if external_def_id.crate == ast::local_crate {
|
|
|
|
ret {crate: this_cnum, node: external_def_id.node};
|
|
|
|
} else { ret extres(external_def_id); }
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
2011-08-12 00:58:14 -05:00
|
|
|
let tp = ebml::get_doc(item, tag_items_data_item_type);
|
2011-07-27 07:19:39 -05:00
|
|
|
let def_parser = bind parse_external_def_id(this_cnum, extres, _);
|
2011-06-27 17:53:27 -05:00
|
|
|
ret parse_ty_data(item.data, this_cnum, tp.start, tp.end - tp.start,
|
2011-07-08 16:53:25 -05:00
|
|
|
def_parser, tcx);
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
|
2011-08-12 00:58:14 -05:00
|
|
|
fn item_ty_param_kinds(item: &ebml::doc) -> [ast::kind] {
|
2011-08-19 17:16:48 -05:00
|
|
|
let ks: [ast::kind] = [];
|
2011-07-29 18:40:23 -05:00
|
|
|
let tp = tag_items_data_item_ty_param_kinds;
|
2011-08-12 00:58:14 -05:00
|
|
|
for each p: ebml::doc in ebml::tagged_docs(item, tp) {
|
2011-08-19 17:16:48 -05:00
|
|
|
let dat: [u8] = ebml::doc_data(p);
|
2011-08-12 00:58:14 -05:00
|
|
|
let vi = ebml::vint_at(dat, 0u);
|
2011-07-29 18:40:23 -05:00
|
|
|
let i = 0u;
|
|
|
|
while i < vi.val {
|
2011-08-19 17:16:48 -05:00
|
|
|
let k =
|
|
|
|
alt dat[vi.next + i] as char {
|
|
|
|
'u' { ast::kind_unique }
|
|
|
|
's' { ast::kind_shared }
|
|
|
|
'p' { ast::kind_pinned }
|
|
|
|
};
|
|
|
|
ks += [k];
|
2011-07-29 18:40:23 -05:00
|
|
|
i += 1u;
|
|
|
|
}
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
2011-07-29 18:40:23 -05:00
|
|
|
ret ks;
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
|
2011-08-12 00:58:14 -05:00
|
|
|
fn tag_variant_ids(item: &ebml::doc, this_cnum: ast::crate_num) ->
|
2011-08-04 18:20:09 -05:00
|
|
|
[ast::def_id] {
|
2011-08-19 17:16:48 -05:00
|
|
|
let ids: [ast::def_id] = [];
|
2011-07-27 07:19:39 -05:00
|
|
|
let v = tag_items_data_item_variant;
|
2011-08-15 23:54:52 -05:00
|
|
|
for each p: ebml::doc in ebml::tagged_docs(item, v) {
|
2011-08-12 00:58:14 -05:00
|
|
|
let ext = parse_def_id(ebml::doc_data(p));
|
2011-08-19 17:16:48 -05:00
|
|
|
ids += [{crate: this_cnum, node: ext.node}];
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
ret ids;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Given a path and serialized crate metadata, returns the ID of the
|
|
|
|
// definition the path refers to.
|
2011-08-04 18:20:09 -05:00
|
|
|
fn resolve_path(path: &[ast::ident], data: @[u8]) -> [ast::def_id] {
|
|
|
|
fn eq_item(data: &[u8], s: str) -> bool {
|
2011-08-11 19:13:53 -05:00
|
|
|
ret str::eq(str::unsafe_from_bytes(data), s);
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
2011-08-11 19:56:57 -05:00
|
|
|
let s = str::connect(path, "::");
|
2011-08-12 00:58:14 -05:00
|
|
|
let md = ebml::new_doc(data);
|
|
|
|
let paths = ebml::get_doc(md, tag_paths);
|
2011-07-27 07:19:39 -05:00
|
|
|
let eqer = bind eq_item(_, s);
|
2011-08-19 17:16:48 -05:00
|
|
|
let result: [ast::def_id] = [];
|
2011-08-15 23:54:52 -05:00
|
|
|
for doc: ebml::doc in lookup_hash(paths, eqer, hash_path(s)) {
|
2011-08-12 00:58:14 -05:00
|
|
|
let did_doc = ebml::get_doc(doc, tag_def_id);
|
2011-08-19 17:16:48 -05:00
|
|
|
result += [parse_def_id(ebml::doc_data(did_doc))];
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
ret result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Crate metadata queries
|
2011-08-04 18:20:09 -05:00
|
|
|
fn lookup_defs(data: &@[u8], cnum: ast::crate_num, path: &[ast::ident]) ->
|
|
|
|
[ast::def] {
|
2011-08-15 18:38:23 -05:00
|
|
|
ret vec::map(bind lookup_def(cnum, data, _), resolve_path(path, data));
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// FIXME doesn't yet handle re-exported externals
|
2011-08-04 18:20:09 -05:00
|
|
|
fn lookup_def(cnum: ast::crate_num, data: @[u8], did_: &ast::def_id) ->
|
2011-07-27 07:19:39 -05:00
|
|
|
ast::def {
|
|
|
|
let item = lookup_item(did_.node, data);
|
2011-07-29 18:40:23 -05:00
|
|
|
let fam_ch = item_family(item);
|
2011-07-27 07:19:39 -05:00
|
|
|
let did = {crate: cnum, node: did_.node};
|
2011-07-27 07:48:34 -05:00
|
|
|
// We treat references to tags as references to types.
|
|
|
|
let def =
|
2011-07-29 18:40:23 -05:00
|
|
|
alt fam_ch as char {
|
2011-07-27 07:19:39 -05:00
|
|
|
'c' { ast::def_const(did) }
|
|
|
|
'f' { ast::def_fn(did, ast::impure_fn) }
|
|
|
|
'p' { ast::def_fn(did, ast::pure_fn) }
|
|
|
|
'F' { ast::def_native_fn(did) }
|
|
|
|
'y' { ast::def_ty(did) }
|
|
|
|
'T' { ast::def_native_ty(did) }
|
|
|
|
't' { ast::def_ty(did) }
|
|
|
|
'm' { ast::def_mod(did) }
|
|
|
|
'n' { ast::def_native_mod(did) }
|
|
|
|
'v' {
|
|
|
|
let tid = variant_tag_id(item);
|
|
|
|
tid = {crate: cnum, node: tid.node};
|
|
|
|
ast::def_variant(tid, did)
|
|
|
|
}
|
2011-06-27 17:53:27 -05:00
|
|
|
};
|
|
|
|
ret def;
|
|
|
|
}
|
|
|
|
|
2011-08-04 18:20:09 -05:00
|
|
|
fn get_type(data: @[u8], def: ast::def_id, tcx: &ty::ctxt,
|
2011-07-29 18:40:23 -05:00
|
|
|
extres: &external_resolver) -> ty::ty_param_kinds_and_ty {
|
2011-07-27 07:19:39 -05:00
|
|
|
let this_cnum = def.crate;
|
|
|
|
let node_id = def.node;
|
|
|
|
let item = lookup_item(node_id, data);
|
|
|
|
let t = item_type(item, this_cnum, tcx, extres);
|
2011-08-19 17:16:48 -05:00
|
|
|
let tp_kinds: [ast::kind];
|
2011-07-29 18:40:23 -05:00
|
|
|
let fam_ch = item_family(item);
|
|
|
|
let has_ty_params = family_has_type_params(fam_ch);
|
2011-07-27 07:19:39 -05:00
|
|
|
if has_ty_params {
|
2011-07-29 18:40:23 -05:00
|
|
|
tp_kinds = item_ty_param_kinds(item);
|
2011-08-19 17:16:48 -05:00
|
|
|
} else { tp_kinds = []; }
|
2011-07-29 18:40:23 -05:00
|
|
|
ret {kinds: tp_kinds, ty: t};
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
|
2011-08-04 18:20:09 -05:00
|
|
|
fn get_type_param_count(data: @[u8], id: ast::node_id) -> uint {
|
2011-08-15 18:38:23 -05:00
|
|
|
ret vec::len(get_type_param_kinds(data, id));
|
2011-07-29 18:40:23 -05:00
|
|
|
}
|
|
|
|
|
2011-08-04 18:20:09 -05:00
|
|
|
fn get_type_param_kinds(data: @[u8], id: ast::node_id) -> [ast::kind] {
|
2011-07-29 18:40:23 -05:00
|
|
|
ret item_ty_param_kinds(lookup_item(id, data));
|
2011-06-30 05:35:19 -05:00
|
|
|
}
|
|
|
|
|
2011-08-04 18:20:09 -05:00
|
|
|
fn get_symbol(data: @[u8], id: ast::node_id) -> str {
|
2011-07-08 00:30:07 -05:00
|
|
|
ret item_symbol(lookup_item(id, data));
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
|
2011-08-18 03:01:39 -05:00
|
|
|
fn get_tag_variants(_data: &@[u8], def: ast::def_id, tcx: &ty::ctxt,
|
2011-08-04 18:20:09 -05:00
|
|
|
extres: &external_resolver) -> [ty::variant_info] {
|
2011-07-27 07:19:39 -05:00
|
|
|
let external_crate_id = def.crate;
|
|
|
|
let data =
|
|
|
|
cstore::get_crate_data(tcx.sess.get_cstore(), external_crate_id).data;
|
2011-08-12 00:58:14 -05:00
|
|
|
let items = ebml::get_doc(ebml::new_doc(data), tag_items);
|
2011-07-27 07:19:39 -05:00
|
|
|
let item = find_item(def.node, items);
|
2011-08-19 17:16:48 -05:00
|
|
|
let infos: [ty::variant_info] = [];
|
2011-07-27 07:19:39 -05:00
|
|
|
let variant_ids = tag_variant_ids(item, external_crate_id);
|
2011-08-15 23:54:52 -05:00
|
|
|
for did: ast::def_id in variant_ids {
|
2011-07-27 07:19:39 -05:00
|
|
|
let item = find_item(did.node, items);
|
|
|
|
let ctor_ty = item_type(item, external_crate_id, tcx, extres);
|
2011-08-19 17:16:48 -05:00
|
|
|
let arg_tys: [ty::t] = [];
|
2011-07-27 07:19:39 -05:00
|
|
|
alt ty::struct(tcx, ctor_ty) {
|
|
|
|
ty::ty_fn(_, args, _, _, _) {
|
2011-08-19 17:16:48 -05:00
|
|
|
for a: ty::arg in args { arg_tys += [a.ty]; }
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
_ {
|
|
|
|
// Nullary tag variant.
|
|
|
|
|
|
|
|
}
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
2011-08-19 17:16:48 -05:00
|
|
|
infos += [{args: arg_tys, ctor_ty: ctor_ty, id: did}];
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
ret infos;
|
|
|
|
}
|
|
|
|
|
2011-07-29 18:40:23 -05:00
|
|
|
fn family_has_type_params(fam_ch: u8) -> bool {
|
|
|
|
ret alt fam_ch as char {
|
2011-07-27 07:19:39 -05:00
|
|
|
'c' { false }
|
|
|
|
'f' { true }
|
|
|
|
'p' { true }
|
|
|
|
'F' { true }
|
|
|
|
'y' { true }
|
|
|
|
't' { true }
|
|
|
|
'T' { false }
|
|
|
|
'm' { false }
|
|
|
|
'n' { false }
|
|
|
|
'v' { true }
|
2011-06-27 17:53:27 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2011-08-12 00:58:14 -05:00
|
|
|
fn read_path(d: &ebml::doc) -> {path: str, pos: uint} {
|
|
|
|
let desc = ebml::doc_data(d);
|
|
|
|
let pos = ebml::be_uint_from_bytes(@desc, 0u, 4u);
|
2011-08-13 02:09:25 -05:00
|
|
|
let pathbytes = vec::slice::<u8>(desc, 4u, vec::len::<u8>(desc));
|
2011-08-11 19:13:53 -05:00
|
|
|
let path = str::unsafe_from_bytes(pathbytes);
|
2011-07-27 07:19:39 -05:00
|
|
|
ret {path: path, pos: pos};
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
|
2011-08-12 00:58:14 -05:00
|
|
|
fn describe_def(items: &ebml::doc, id: ast::def_id) -> str {
|
2011-07-27 07:19:39 -05:00
|
|
|
if id.crate != ast::local_crate { ret "external"; }
|
2011-07-29 18:40:23 -05:00
|
|
|
ret item_family_to_str(item_family(find_item(id.node, items)));
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
|
2011-07-29 18:40:23 -05:00
|
|
|
fn item_family_to_str(fam: u8) -> str {
|
|
|
|
alt fam as char {
|
2011-07-27 07:19:39 -05:00
|
|
|
'c' { ret "const"; }
|
|
|
|
'f' { ret "fn"; }
|
|
|
|
'p' { ret "pred"; }
|
|
|
|
'F' { ret "native fn"; }
|
|
|
|
'y' { ret "type"; }
|
|
|
|
'T' { ret "native type"; }
|
|
|
|
't' { ret "type"; }
|
|
|
|
'm' { ret "mod"; }
|
|
|
|
'n' { ret "native mod"; }
|
|
|
|
'v' { ret "tag"; }
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-12 00:58:14 -05:00
|
|
|
fn get_meta_items(md: &ebml::doc) -> [@ast::meta_item] {
|
2011-08-19 17:16:48 -05:00
|
|
|
let items: [@ast::meta_item] = [];
|
|
|
|
for each meta_item_doc: ebml::doc in
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::tagged_docs(md, tag_meta_item_word) {
|
|
|
|
let nd = ebml::get_doc(meta_item_doc, tag_meta_item_name);
|
|
|
|
let n = str::unsafe_from_bytes(ebml::doc_data(nd));
|
2011-08-19 17:16:48 -05:00
|
|
|
items += [attr::mk_word_item(n)];
|
2011-06-28 01:02:02 -05:00
|
|
|
}
|
2011-08-19 17:16:48 -05:00
|
|
|
for each meta_item_doc: ebml::doc in
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::tagged_docs(md, tag_meta_item_name_value) {
|
|
|
|
let nd = ebml::get_doc(meta_item_doc, tag_meta_item_name);
|
|
|
|
let vd = ebml::get_doc(meta_item_doc, tag_meta_item_value);
|
|
|
|
let n = str::unsafe_from_bytes(ebml::doc_data(nd));
|
|
|
|
let v = str::unsafe_from_bytes(ebml::doc_data(vd));
|
2011-07-05 19:01:23 -05:00
|
|
|
// FIXME (#611): Should be able to decode meta_name_value variants,
|
|
|
|
// but currently they can't be encoded
|
2011-08-19 17:16:48 -05:00
|
|
|
items += [attr::mk_name_value_item_str(n, v)];
|
2011-06-28 01:02:02 -05:00
|
|
|
}
|
2011-08-19 17:16:48 -05:00
|
|
|
for each meta_item_doc: ebml::doc in
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::tagged_docs(md, tag_meta_item_list) {
|
|
|
|
let nd = ebml::get_doc(meta_item_doc, tag_meta_item_name);
|
|
|
|
let n = str::unsafe_from_bytes(ebml::doc_data(nd));
|
2011-07-27 07:19:39 -05:00
|
|
|
let subitems = get_meta_items(meta_item_doc);
|
2011-08-19 17:16:48 -05:00
|
|
|
items += [attr::mk_list_item(n, subitems)];
|
2011-06-27 20:32:15 -05:00
|
|
|
}
|
|
|
|
ret items;
|
|
|
|
}
|
|
|
|
|
2011-08-12 00:58:14 -05:00
|
|
|
fn get_attributes(md: &ebml::doc) -> [ast::attribute] {
|
2011-08-19 17:16:48 -05:00
|
|
|
let attrs: [ast::attribute] = [];
|
2011-08-12 00:58:14 -05:00
|
|
|
alt ebml::maybe_get_doc(md, tag_attributes) {
|
2011-07-27 07:19:39 -05:00
|
|
|
option::some(attrs_d) {
|
2011-08-19 17:16:48 -05:00
|
|
|
for each attr_doc: ebml::doc in
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::tagged_docs(attrs_d, tag_attribute) {
|
2011-07-27 07:19:39 -05:00
|
|
|
let meta_items = get_meta_items(attr_doc);
|
|
|
|
// Currently it's only possible to have a single meta item on
|
|
|
|
// an attribute
|
2011-08-15 18:38:23 -05:00
|
|
|
assert (vec::len(meta_items) == 1u);
|
2011-08-19 17:16:48 -05:00
|
|
|
let meta_item = meta_items[0];
|
2011-07-27 07:19:39 -05:00
|
|
|
attrs +=
|
2011-08-19 17:16:48 -05:00
|
|
|
[{node: {style: ast::attr_outer, value: *meta_item},
|
|
|
|
span: ast::dummy_sp()}];
|
2011-06-27 21:41:48 -05:00
|
|
|
}
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
option::none. { }
|
2011-06-27 21:41:48 -05:00
|
|
|
}
|
|
|
|
ret attrs;
|
|
|
|
}
|
|
|
|
|
2011-08-12 00:58:14 -05:00
|
|
|
fn list_meta_items(meta_items: &ebml::doc, out: io::writer) {
|
2011-08-15 23:54:52 -05:00
|
|
|
for mi: @ast::meta_item in get_meta_items(meta_items) {
|
2011-08-19 17:16:48 -05:00
|
|
|
out.write_str(#fmt["%s\n", pprust::meta_item_to_str(*mi)]);
|
2011-06-27 20:32:15 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-12 00:58:14 -05:00
|
|
|
fn list_crate_attributes(md: &ebml::doc, out: io::writer) {
|
2011-07-08 13:33:51 -05:00
|
|
|
out.write_str("=Crate Attributes=\n");
|
2011-06-27 21:41:48 -05:00
|
|
|
|
2011-08-15 23:54:52 -05:00
|
|
|
for attr: ast::attribute in get_attributes(md) {
|
2011-08-19 17:16:48 -05:00
|
|
|
out.write_str(#fmt["%s\n", pprust::attribute_to_str(attr)]);
|
2011-06-27 21:41:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
out.write_str("\n\n");
|
2011-06-27 20:32:15 -05:00
|
|
|
}
|
|
|
|
|
2011-08-04 18:20:09 -05:00
|
|
|
fn get_crate_attributes(data: @[u8]) -> [ast::attribute] {
|
2011-08-12 00:58:14 -05:00
|
|
|
ret get_attributes(ebml::new_doc(data));
|
2011-06-28 13:24:24 -05:00
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
type crate_dep = {cnum: ast::crate_num, ident: str};
|
|
|
|
|
2011-08-04 18:20:09 -05:00
|
|
|
fn get_crate_deps(data: @[u8]) -> [crate_dep] {
|
2011-08-19 17:16:48 -05:00
|
|
|
let deps: [crate_dep] = [];
|
2011-08-12 00:58:14 -05:00
|
|
|
let cratedoc = ebml::new_doc(data);
|
|
|
|
let depsdoc = ebml::get_doc(cratedoc, tag_crate_deps);
|
2011-07-27 07:19:39 -05:00
|
|
|
let crate_num = 1;
|
2011-08-19 17:16:48 -05:00
|
|
|
for each depdoc: ebml::doc in ebml::tagged_docs(depsdoc, tag_crate_dep) {
|
2011-08-12 00:58:14 -05:00
|
|
|
let depname = str::unsafe_from_bytes(ebml::doc_data(depdoc));
|
2011-08-19 17:16:48 -05:00
|
|
|
deps += [{cnum: crate_num, ident: depname}];
|
2011-07-08 13:29:56 -05:00
|
|
|
crate_num += 1;
|
|
|
|
}
|
|
|
|
ret deps;
|
|
|
|
}
|
|
|
|
|
2011-08-11 21:14:38 -05:00
|
|
|
fn list_crate_deps(data: @[u8], out: io::writer) {
|
2011-07-08 13:29:56 -05:00
|
|
|
out.write_str("=External Dependencies=\n");
|
|
|
|
|
2011-08-15 23:54:52 -05:00
|
|
|
for dep: crate_dep in get_crate_deps(data) {
|
2011-08-19 17:16:48 -05:00
|
|
|
out.write_str(#fmt["%d %s\n", dep.cnum, dep.ident]);
|
2011-07-08 13:29:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
out.write_str("\n");
|
|
|
|
}
|
|
|
|
|
2011-08-12 00:58:14 -05:00
|
|
|
fn list_crate_items(bytes: &@[u8], md: &ebml::doc, out: io::writer) {
|
2011-06-27 20:32:15 -05:00
|
|
|
out.write_str("=Items=\n");
|
2011-08-12 00:58:14 -05:00
|
|
|
let paths = ebml::get_doc(md, tag_paths);
|
|
|
|
let items = ebml::get_doc(md, tag_items);
|
|
|
|
let index = ebml::get_doc(paths, tag_index);
|
|
|
|
let bs = ebml::get_doc(index, tag_index_buckets);
|
2011-08-19 17:16:48 -05:00
|
|
|
for each bucket: ebml::doc in
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::tagged_docs(bs, tag_index_buckets_bucket) {
|
2011-07-27 07:19:39 -05:00
|
|
|
let et = tag_index_buckets_bucket_elt;
|
2011-08-15 23:54:52 -05:00
|
|
|
for each elt: ebml::doc in ebml::tagged_docs(bucket, et) {
|
2011-07-27 07:19:39 -05:00
|
|
|
let data = read_path(elt);
|
2011-08-12 00:58:14 -05:00
|
|
|
let def = ebml::doc_at(bytes, data.pos);
|
|
|
|
let did_doc = ebml::get_doc(def, tag_def_id);
|
|
|
|
let did = parse_def_id(ebml::doc_data(did_doc));
|
2011-08-19 17:16:48 -05:00
|
|
|
out.write_str(#fmt["%s (%s)\n", data.path,
|
|
|
|
describe_def(items, did)]);
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
}
|
2011-06-27 20:32:15 -05:00
|
|
|
out.write_str("\n");
|
|
|
|
}
|
|
|
|
|
2011-08-11 21:14:38 -05:00
|
|
|
fn list_crate_metadata(bytes: &@[u8], out: io::writer) {
|
2011-08-12 00:58:14 -05:00
|
|
|
let md = ebml::new_doc(bytes);
|
2011-06-27 20:32:15 -05:00
|
|
|
list_crate_attributes(md, out);
|
2011-07-08 13:29:56 -05:00
|
|
|
list_crate_deps(bytes, out);
|
2011-06-27 20:32:15 -05:00
|
|
|
list_crate_items(bytes, md, out);
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Local Variables:
|
|
|
|
// mode: rust
|
|
|
|
// fill-column: 78;
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
// c-basic-offset: 4
|
|
|
|
// buffer-file-coding-system: utf-8-unix
|
|
|
|
// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
|
|
|
|
// End:
|