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-07-12 12:59:18 -05:00
|
|
|
import std::ebmlivec;
|
2011-07-05 19:57:34 -05:00
|
|
|
import std::ivec;
|
2011-06-27 17:53:27 -05:00
|
|
|
import std::option;
|
|
|
|
import std::str;
|
2011-07-12 12:59:18 -05:00
|
|
|
import std::ioivec;
|
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-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.
|
|
|
|
type external_resolver = fn(&ast::def_id def_id) -> ast::def_id;
|
2011-06-27 17:53:27 -05:00
|
|
|
|
2011-07-12 12:59:18 -05:00
|
|
|
fn lookup_hash(&ebmlivec::doc d, fn(&u8[]) -> bool eq_fn, uint hash) ->
|
|
|
|
(ebmlivec::doc)[] {
|
|
|
|
auto index = ebmlivec::get_doc(d, tag_index);
|
|
|
|
auto table = ebmlivec::get_doc(index, tag_index_table);
|
2011-06-27 17:53:27 -05:00
|
|
|
auto hash_pos = table.start + hash % 256u * 4u;
|
2011-07-12 12:59:18 -05:00
|
|
|
auto pos = ebmlivec::be_uint_from_bytes(d.data, hash_pos, 4u);
|
|
|
|
auto bucket = ebmlivec::doc_at(d.data, pos);
|
2011-06-27 17:53:27 -05:00
|
|
|
// Awkward logic because we can't ret from foreach yet
|
|
|
|
|
2011-07-12 12:59:18 -05:00
|
|
|
let (ebmlivec::doc)[] result = ~[];
|
2011-06-27 17:53:27 -05:00
|
|
|
auto belt = tag_index_buckets_bucket_elt;
|
2011-07-12 12:59:18 -05:00
|
|
|
for each (ebmlivec::doc elt in ebmlivec::tagged_docs(bucket, belt)) {
|
|
|
|
auto pos = ebmlivec::be_uint_from_bytes(elt.data, elt.start, 4u);
|
|
|
|
if (eq_fn(ivec::slice[u8](*elt.data, elt.start + 4u, elt.end))) {
|
|
|
|
result += ~[ebmlivec::doc_at(d.data, pos)];
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ret result;
|
|
|
|
}
|
|
|
|
|
2011-07-14 14:55:17 -05:00
|
|
|
fn maybe_find_item(int item_id, &ebmlivec::doc items)
|
|
|
|
-> option::t[ebmlivec::doc] {
|
2011-07-12 12:59:18 -05:00
|
|
|
fn eq_item(&u8[] bytes, int item_id) -> bool {
|
|
|
|
ret ebmlivec::be_uint_from_bytes(@bytes, 0u, 4u) as int == item_id;
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
auto eqer = bind eq_item(_, item_id);
|
2011-07-07 14:22:39 -05:00
|
|
|
auto found = lookup_hash(items, eqer, hash_node_id(item_id));
|
2011-07-12 12:59:18 -05:00
|
|
|
if (ivec::len(found) == 0u) {
|
|
|
|
ret option::none[ebmlivec::doc];
|
|
|
|
} else { ret option::some[ebmlivec::doc](found.(0)); }
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
|
2011-07-12 12:59:18 -05:00
|
|
|
fn find_item(int item_id, &ebmlivec::doc items) -> ebmlivec::doc {
|
2011-06-27 17:53:27 -05:00
|
|
|
ret option::get(maybe_find_item(item_id, items));
|
|
|
|
}
|
|
|
|
|
2011-07-12 12:59:18 -05:00
|
|
|
// Looks up an item in the given metadata and returns an ebmlivec doc pointing
|
2011-06-27 17:53:27 -05:00
|
|
|
// to the item data.
|
2011-07-12 12:59:18 -05:00
|
|
|
fn lookup_item(int item_id, &@u8[] data) -> ebmlivec::doc {
|
|
|
|
auto items = ebmlivec::get_doc(ebmlivec::new_doc(data), tag_items);
|
2011-06-27 17:53:27 -05:00
|
|
|
ret find_item(item_id, items);
|
|
|
|
}
|
|
|
|
|
2011-07-12 12:59:18 -05:00
|
|
|
fn item_kind(&ebmlivec::doc item) -> u8 {
|
|
|
|
auto kind = ebmlivec::get_doc(item, tag_items_data_item_kind);
|
|
|
|
ret ebmlivec::doc_as_uint(kind) as u8;
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
|
2011-07-12 12:59:18 -05:00
|
|
|
fn item_symbol(&ebmlivec::doc item) -> str {
|
|
|
|
auto sym = ebmlivec::get_doc(item, tag_items_data_item_symbol);
|
|
|
|
ret str::unsafe_from_bytes_ivec(ebmlivec::doc_data(sym));
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
|
2011-07-12 12:59:18 -05:00
|
|
|
fn variant_tag_id(&ebmlivec::doc d) -> ast::def_id {
|
|
|
|
auto tagdoc = ebmlivec::get_doc(d, tag_items_data_item_tag_id);
|
|
|
|
ret parse_def_id(ebmlivec::doc_data(tagdoc));
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
|
2011-07-12 12:59:18 -05:00
|
|
|
fn item_type(&ebmlivec::doc item, ast::crate_num this_cnum,
|
2011-07-08 16:53:25 -05:00
|
|
|
ty::ctxt tcx, &external_resolver extres) -> ty::t {
|
|
|
|
fn parse_external_def_id(ast::crate_num this_cnum,
|
|
|
|
&external_resolver extres,
|
|
|
|
str s) -> ast::def_id {
|
2011-07-12 12:59:18 -05:00
|
|
|
auto buf = str::bytes_ivec(s);
|
2011-06-27 17:53:27 -05:00
|
|
|
auto 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-26 07:06:02 -05:00
|
|
|
if (external_def_id.crate == ast::local_crate) {
|
|
|
|
ret rec(crate=this_cnum, node=external_def_id.node);
|
2011-07-08 01:29:09 -05:00
|
|
|
} else {
|
2011-07-08 16:53:25 -05:00
|
|
|
ret extres(external_def_id);
|
2011-07-08 01:29:09 -05:00
|
|
|
}
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
2011-07-12 12:59:18 -05:00
|
|
|
auto tp = ebmlivec::get_doc(item, tag_items_data_item_type);
|
2011-07-08 16:53:25 -05:00
|
|
|
auto 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-07-12 12:59:18 -05:00
|
|
|
fn item_ty_param_count(&ebmlivec::doc item) -> uint {
|
2011-06-27 17:53:27 -05:00
|
|
|
let uint ty_param_count = 0u;
|
|
|
|
auto tp = tag_items_data_item_ty_param_count;
|
2011-07-12 12:59:18 -05:00
|
|
|
for each (ebmlivec::doc p in ebmlivec::tagged_docs(item, tp)) {
|
2011-07-26 07:06:02 -05:00
|
|
|
ty_param_count = ebmlivec::vint_at(ebmlivec::doc_data(p), 0u).val;
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
ret ty_param_count;
|
|
|
|
}
|
|
|
|
|
2011-07-12 12:59:18 -05:00
|
|
|
fn tag_variant_ids(&ebmlivec::doc item,
|
2011-07-14 19:26:10 -05:00
|
|
|
ast::crate_num this_cnum) -> ast::def_id[] {
|
|
|
|
let ast::def_id[] ids = ~[];
|
2011-06-27 17:53:27 -05:00
|
|
|
auto v = tag_items_data_item_variant;
|
2011-07-12 12:59:18 -05:00
|
|
|
for each (ebmlivec::doc p in ebmlivec::tagged_docs(item, v)) {
|
|
|
|
auto ext = parse_def_id(ebmlivec::doc_data(p));
|
2011-07-26 07:06:02 -05:00
|
|
|
ids += ~[rec(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-07-14 19:26:10 -05:00
|
|
|
fn resolve_path(&ast::ident[] path, @u8[] data) -> ast::def_id[] {
|
2011-07-12 12:59:18 -05:00
|
|
|
fn eq_item(&u8[] data, str s) -> bool {
|
|
|
|
ret str::eq(str::unsafe_from_bytes_ivec(data), s);
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
2011-07-14 19:26:10 -05:00
|
|
|
auto s = str::connect_ivec(path, "::");
|
2011-07-12 12:59:18 -05:00
|
|
|
auto md = ebmlivec::new_doc(data);
|
|
|
|
auto paths = ebmlivec::get_doc(md, tag_paths);
|
2011-06-27 17:53:27 -05:00
|
|
|
auto eqer = bind eq_item(_, s);
|
2011-07-14 19:26:10 -05:00
|
|
|
let ast::def_id[] result = ~[];
|
2011-07-12 12:59:18 -05:00
|
|
|
for (ebmlivec::doc doc in lookup_hash(paths, eqer, hash_path(s))) {
|
|
|
|
auto did_doc = ebmlivec::get_doc(doc, tag_def_id);
|
2011-07-14 19:26:10 -05:00
|
|
|
result += ~[parse_def_id(ebmlivec::doc_data(did_doc))];
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
ret result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Crate metadata queries
|
2011-07-14 19:26:10 -05:00
|
|
|
fn lookup_defs(&@u8[] data, ast::crate_num cnum, &ast::ident[] path)
|
|
|
|
-> ast::def[] {
|
|
|
|
ret ivec::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-07-12 12:59:18 -05:00
|
|
|
fn lookup_def(ast::crate_num cnum, @u8[] data, &ast::def_id did_)
|
|
|
|
-> ast::def {
|
2011-07-26 07:06:02 -05:00
|
|
|
auto item = lookup_item(did_.node, data);
|
2011-06-27 17:53:27 -05:00
|
|
|
auto kind_ch = item_kind(item);
|
2011-07-26 07:06:02 -05:00
|
|
|
auto did = rec(crate=cnum, node=did_.node);
|
2011-06-27 17:53:27 -05:00
|
|
|
auto def =
|
|
|
|
alt (kind_ch as char) {
|
|
|
|
case ('c') { ast::def_const(did) }
|
|
|
|
case ('f') { ast::def_fn(did, ast::impure_fn) }
|
|
|
|
case ('p') { ast::def_fn(did, ast::pure_fn) }
|
|
|
|
case ('F') { ast::def_native_fn(did) }
|
|
|
|
case ('y') { ast::def_ty(did) }
|
|
|
|
case ('T') { ast::def_native_ty(did) }
|
|
|
|
// We treat references to tags as references to types.
|
|
|
|
case ('t') { ast::def_ty(did) }
|
|
|
|
case ('m') { ast::def_mod(did) }
|
|
|
|
case ('n') { ast::def_native_mod(did) }
|
|
|
|
case ('v') {
|
|
|
|
auto tid = variant_tag_id(item);
|
2011-07-26 07:06:02 -05:00
|
|
|
tid = rec(crate=cnum, node=tid.node);
|
2011-06-27 17:53:27 -05:00
|
|
|
ast::def_variant(tid, did)
|
|
|
|
}
|
|
|
|
};
|
|
|
|
ret def;
|
|
|
|
}
|
|
|
|
|
2011-07-12 12:59:18 -05:00
|
|
|
fn get_type(@u8[] data, ast::def_id def, &ty::ctxt tcx,
|
2011-07-08 16:53:25 -05:00
|
|
|
&external_resolver extres) -> ty::ty_param_count_and_ty {
|
2011-07-26 07:06:02 -05:00
|
|
|
auto this_cnum = def.crate;
|
|
|
|
auto node_id = def.node;
|
2011-07-08 00:57:09 -05:00
|
|
|
auto item = lookup_item(node_id, data);
|
2011-07-08 16:53:25 -05:00
|
|
|
auto t = item_type(item, this_cnum, tcx, extres);
|
2011-06-27 17:53:27 -05:00
|
|
|
auto tp_count;
|
|
|
|
auto kind_ch = item_kind(item);
|
|
|
|
auto has_ty_params = kind_has_type_params(kind_ch);
|
|
|
|
if (has_ty_params) {
|
2011-06-30 05:35:19 -05:00
|
|
|
tp_count = item_ty_param_count(item);
|
2011-06-27 17:53:27 -05:00
|
|
|
} else { tp_count = 0u; }
|
2011-07-26 07:06:02 -05:00
|
|
|
ret rec(count=tp_count, ty=t);
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
|
2011-07-12 12:59:18 -05:00
|
|
|
fn get_type_param_count(@u8[] data, ast::node_id id) -> uint {
|
2011-07-08 00:30:07 -05:00
|
|
|
ret item_ty_param_count(lookup_item(id, data));
|
2011-06-30 05:35:19 -05:00
|
|
|
}
|
|
|
|
|
2011-07-12 12:59:18 -05:00
|
|
|
fn get_symbol(@u8[] data, ast::node_id 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-07-12 12:59:18 -05:00
|
|
|
fn get_tag_variants(&@u8[] data, ast::def_id def,
|
2011-07-08 16:53:25 -05:00
|
|
|
&ty::ctxt tcx,
|
|
|
|
&external_resolver extres) -> ty::variant_info[] {
|
2011-07-26 07:06:02 -05:00
|
|
|
auto external_crate_id = def.crate;
|
2011-07-07 20:13:24 -05:00
|
|
|
auto data = cstore::get_crate_data(tcx.sess.get_cstore(),
|
|
|
|
external_crate_id).data;
|
2011-07-12 12:59:18 -05:00
|
|
|
auto items = ebmlivec::get_doc(ebmlivec::new_doc(data), tag_items);
|
2011-07-26 07:06:02 -05:00
|
|
|
auto item = find_item(def.node, items);
|
2011-07-04 22:37:23 -05:00
|
|
|
let ty::variant_info[] infos = ~[];
|
2011-06-27 17:53:27 -05:00
|
|
|
auto variant_ids = tag_variant_ids(item, external_crate_id);
|
|
|
|
for (ast::def_id did in variant_ids) {
|
2011-07-26 07:06:02 -05:00
|
|
|
auto item = find_item(did.node, items);
|
2011-07-08 16:53:25 -05:00
|
|
|
auto ctor_ty = item_type(item, external_crate_id, tcx, extres);
|
2011-07-04 22:37:23 -05:00
|
|
|
let ty::t[] arg_tys = ~[];
|
2011-06-27 17:53:27 -05:00
|
|
|
alt (ty::struct(tcx, ctor_ty)) {
|
|
|
|
case (ty::ty_fn(_, ?args, _, _, _)) {
|
2011-07-04 22:37:23 -05:00
|
|
|
for (ty::arg a in args) { arg_tys += ~[a.ty]; }
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
case (_) {
|
|
|
|
// Nullary tag variant.
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2011-07-04 22:37:23 -05:00
|
|
|
infos += ~[rec(args=arg_tys, ctor_ty=ctor_ty, id=did)];
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
ret infos;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn kind_has_type_params(u8 kind_ch) -> bool {
|
|
|
|
ret alt (kind_ch as char) {
|
|
|
|
case ('c') { false }
|
|
|
|
case ('f') { true }
|
|
|
|
case ('p') { true }
|
|
|
|
case ('F') { true }
|
|
|
|
case ('y') { true }
|
|
|
|
case ('t') { true }
|
|
|
|
case ('T') { false }
|
|
|
|
case ('m') { false }
|
|
|
|
case ('n') { false }
|
|
|
|
case ('v') { true }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2011-07-26 07:06:02 -05:00
|
|
|
fn read_path(&ebmlivec::doc d) -> rec(str path, uint pos) {
|
2011-07-12 12:59:18 -05:00
|
|
|
auto desc = ebmlivec::doc_data(d);
|
|
|
|
auto pos = ebmlivec::be_uint_from_bytes(@desc, 0u, 4u);
|
|
|
|
auto pathbytes = ivec::slice[u8](desc, 4u, ivec::len[u8](desc));
|
|
|
|
auto path = str::unsafe_from_bytes_ivec(pathbytes);
|
2011-07-26 07:06:02 -05:00
|
|
|
ret rec(path=path, pos=pos);
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
|
2011-07-12 12:59:18 -05:00
|
|
|
fn describe_def(&ebmlivec::doc items, ast::def_id id) -> str {
|
2011-07-26 07:06:02 -05:00
|
|
|
if (id.crate != ast::local_crate) { ret "external"; }
|
|
|
|
ret item_kind_to_str(item_kind(find_item(id.node, items)));
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn item_kind_to_str(u8 kind) -> str {
|
|
|
|
alt (kind as char) {
|
|
|
|
case ('c') { ret "const"; }
|
|
|
|
case ('f') { ret "fn"; }
|
|
|
|
case ('p') { ret "pred"; }
|
|
|
|
case ('F') { ret "native fn"; }
|
|
|
|
case ('y') { ret "type"; }
|
|
|
|
case ('T') { ret "native type"; }
|
|
|
|
case ('t') { ret "type"; }
|
|
|
|
case ('m') { ret "mod"; }
|
|
|
|
case ('n') { ret "native mod"; }
|
|
|
|
case ('v') { ret "tag"; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-12 12:59:18 -05:00
|
|
|
fn get_meta_items(&ebmlivec::doc md) -> (@ast::meta_item)[] {
|
2011-07-05 19:57:34 -05:00
|
|
|
let (@ast::meta_item)[] items = ~[];
|
2011-07-12 12:59:18 -05:00
|
|
|
for each (ebmlivec::doc meta_item_doc in
|
|
|
|
ebmlivec::tagged_docs(md, tag_meta_item_word)) {
|
|
|
|
auto nd = ebmlivec::get_doc(meta_item_doc, tag_meta_item_name);
|
|
|
|
auto n = str::unsafe_from_bytes_ivec(ebmlivec::doc_data(nd));
|
2011-07-05 19:57:34 -05:00
|
|
|
items += ~[attr::mk_word_item(n)];
|
2011-06-28 01:02:02 -05:00
|
|
|
}
|
2011-07-12 12:59:18 -05:00
|
|
|
for each (ebmlivec::doc meta_item_doc in
|
|
|
|
ebmlivec::tagged_docs(md, tag_meta_item_name_value)) {
|
|
|
|
auto nd = ebmlivec::get_doc(meta_item_doc, tag_meta_item_name);
|
|
|
|
auto vd = ebmlivec::get_doc(meta_item_doc, tag_meta_item_value);
|
|
|
|
auto n = str::unsafe_from_bytes_ivec(ebmlivec::doc_data(nd));
|
|
|
|
auto v = str::unsafe_from_bytes_ivec(ebmlivec::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-07-05 19:57:34 -05:00
|
|
|
items += ~[attr::mk_name_value_item_str(n, v)];
|
2011-06-28 01:02:02 -05:00
|
|
|
}
|
2011-07-12 12:59:18 -05:00
|
|
|
for each (ebmlivec::doc meta_item_doc in
|
|
|
|
ebmlivec::tagged_docs(md, tag_meta_item_list)) {
|
|
|
|
auto nd = ebmlivec::get_doc(meta_item_doc, tag_meta_item_name);
|
|
|
|
auto n = str::unsafe_from_bytes_ivec(ebmlivec::doc_data(nd));
|
2011-06-28 01:02:02 -05:00
|
|
|
auto subitems = get_meta_items(meta_item_doc);
|
2011-07-05 19:57:34 -05:00
|
|
|
items += ~[attr::mk_list_item(n, subitems)];
|
2011-06-27 20:32:15 -05:00
|
|
|
}
|
|
|
|
ret items;
|
|
|
|
}
|
|
|
|
|
2011-07-12 12:59:18 -05:00
|
|
|
fn get_attributes(&ebmlivec::doc md) -> ast::attribute[] {
|
2011-07-05 19:02:51 -05:00
|
|
|
let ast::attribute[] attrs = ~[];
|
2011-07-12 12:59:18 -05:00
|
|
|
alt (ebmlivec::maybe_get_doc(md, tag_attributes)) {
|
2011-06-27 21:41:48 -05:00
|
|
|
case (option::some(?attrs_d)) {
|
2011-07-12 12:59:18 -05:00
|
|
|
for each (ebmlivec::doc attr_doc in
|
|
|
|
ebmlivec::tagged_docs(attrs_d, tag_attribute)) {
|
2011-06-27 21:41:48 -05:00
|
|
|
auto meta_items = get_meta_items(attr_doc);
|
|
|
|
// Currently it's only possible to have a single meta item on
|
|
|
|
// an attribute
|
2011-07-05 19:57:34 -05:00
|
|
|
assert (ivec::len(meta_items) == 1u);
|
2011-06-27 21:41:48 -05:00
|
|
|
auto meta_item = meta_items.(0);
|
2011-07-05 19:02:51 -05:00
|
|
|
attrs += ~[rec(node=rec(style=ast::attr_outer,
|
|
|
|
value=*meta_item),
|
|
|
|
span=rec(lo=0u, hi=0u))];
|
2011-06-27 21:41:48 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
case (option::none) { }
|
|
|
|
}
|
|
|
|
ret attrs;
|
|
|
|
}
|
|
|
|
|
2011-07-12 12:59:18 -05:00
|
|
|
fn list_meta_items(&ebmlivec::doc meta_items, ioivec::writer out) {
|
2011-06-28 01:02:02 -05:00
|
|
|
for (@ast::meta_item mi in get_meta_items(meta_items)) {
|
|
|
|
out.write_str(#fmt("%s\n", pprust::meta_item_to_str(*mi)));
|
2011-06-27 20:32:15 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-12 12:59:18 -05:00
|
|
|
fn list_crate_attributes(&ebmlivec::doc md, ioivec::writer out) {
|
2011-07-08 13:33:51 -05:00
|
|
|
out.write_str("=Crate Attributes=\n");
|
2011-06-27 21:41:48 -05:00
|
|
|
|
|
|
|
for (ast::attribute attr in get_attributes(md)) {
|
2011-07-08 13:33:51 -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-07-12 12:59:18 -05:00
|
|
|
fn get_crate_attributes(@u8[] data) -> ast::attribute[] {
|
|
|
|
ret get_attributes(ebmlivec::new_doc(data));
|
2011-06-28 13:24:24 -05:00
|
|
|
}
|
|
|
|
|
2011-07-26 07:06:02 -05:00
|
|
|
type crate_dep = rec(ast::crate_num cnum, str ident);
|
2011-07-08 13:29:56 -05:00
|
|
|
|
2011-07-14 19:26:10 -05:00
|
|
|
fn get_crate_deps(@u8[] data) -> crate_dep[] {
|
|
|
|
let crate_dep[] deps = ~[];
|
2011-07-12 12:59:18 -05:00
|
|
|
auto cratedoc = ebmlivec::new_doc(data);
|
|
|
|
auto depsdoc = ebmlivec::get_doc(cratedoc, tag_crate_deps);
|
2011-07-08 13:29:56 -05:00
|
|
|
auto crate_num = 1;
|
2011-07-12 12:59:18 -05:00
|
|
|
for each (ebmlivec::doc depdoc in
|
|
|
|
ebmlivec::tagged_docs(depsdoc, tag_crate_dep)) {
|
|
|
|
auto depname =
|
|
|
|
str::unsafe_from_bytes_ivec(ebmlivec::doc_data(depdoc));
|
2011-07-26 07:06:02 -05:00
|
|
|
deps += ~[rec(cnum=crate_num, ident=depname)];
|
2011-07-08 13:29:56 -05:00
|
|
|
crate_num += 1;
|
|
|
|
}
|
|
|
|
ret deps;
|
|
|
|
}
|
|
|
|
|
2011-07-12 12:59:18 -05:00
|
|
|
fn list_crate_deps(@u8[] data, ioivec::writer out) {
|
2011-07-08 13:29:56 -05:00
|
|
|
out.write_str("=External Dependencies=\n");
|
|
|
|
|
|
|
|
for (crate_dep dep in get_crate_deps(data)) {
|
2011-07-26 07:06:02 -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-07-12 12:59:18 -05:00
|
|
|
fn list_crate_items(&@u8[] bytes, &ebmlivec::doc md, ioivec::writer out) {
|
2011-06-27 20:32:15 -05:00
|
|
|
out.write_str("=Items=\n");
|
2011-07-12 12:59:18 -05:00
|
|
|
auto paths = ebmlivec::get_doc(md, tag_paths);
|
|
|
|
auto items = ebmlivec::get_doc(md, tag_items);
|
|
|
|
auto index = ebmlivec::get_doc(paths, tag_index);
|
|
|
|
auto bs = ebmlivec::get_doc(index, tag_index_buckets);
|
|
|
|
for each (ebmlivec::doc bucket in
|
|
|
|
ebmlivec::tagged_docs(bs, tag_index_buckets_bucket)) {
|
2011-06-27 17:53:27 -05:00
|
|
|
auto et = tag_index_buckets_bucket_elt;
|
2011-07-12 12:59:18 -05:00
|
|
|
for each (ebmlivec::doc elt in ebmlivec::tagged_docs(bucket, et)) {
|
2011-06-27 17:53:27 -05:00
|
|
|
auto data = read_path(elt);
|
2011-07-26 07:06:02 -05:00
|
|
|
auto def = ebmlivec::doc_at(bytes, data.pos);
|
2011-07-12 12:59:18 -05:00
|
|
|
auto did_doc = ebmlivec::get_doc(def, tag_def_id);
|
|
|
|
auto did = parse_def_id(ebmlivec::doc_data(did_doc));
|
2011-07-26 07:06:02 -05:00
|
|
|
out.write_str(#fmt("%s (%s)\n", data.path,
|
2011-06-27 17:53:27 -05:00
|
|
|
describe_def(items, did)));
|
|
|
|
}
|
|
|
|
}
|
2011-06-27 20:32:15 -05:00
|
|
|
out.write_str("\n");
|
|
|
|
}
|
|
|
|
|
2011-07-12 12:59:18 -05:00
|
|
|
fn list_crate_metadata(&@u8[] bytes, ioivec::writer out) {
|
|
|
|
auto md = ebmlivec::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:
|