2011-07-08 01:29:09 -05:00
|
|
|
// Decoding metadata from a single crate's metadata
|
2011-06-27 18:03:01 -05:00
|
|
|
|
2012-09-04 13:54:36 -05:00
|
|
|
use std::{ebml, map};
|
2012-09-10 17:38:28 -05:00
|
|
|
use std::map::{HashMap, str_hash};
|
2012-09-04 13:54:36 -05:00
|
|
|
use io::WriterUtil;
|
|
|
|
use dvec::DVec;
|
|
|
|
use syntax::{ast, ast_util};
|
|
|
|
use syntax::attr;
|
|
|
|
use middle::ty;
|
|
|
|
use syntax::ast_map;
|
|
|
|
use tydecode::{parse_ty_data, parse_def_id, parse_bounds_data,
|
2012-03-06 10:02:13 -06:00
|
|
|
parse_ident};
|
2012-09-04 13:54:36 -05:00
|
|
|
use syntax::print::pprust;
|
|
|
|
use cmd=cstore::crate_metadata;
|
|
|
|
use util::ppaux::ty_to_str;
|
|
|
|
use syntax::diagnostic::span_handler;
|
|
|
|
use common::*;
|
|
|
|
use syntax::parse::token::ident_interner;
|
2012-07-18 18:18:02 -05:00
|
|
|
|
2011-06-27 17:53:27 -05:00
|
|
|
|
2012-05-15 19:59:55 -05:00
|
|
|
export class_dtor;
|
2012-03-19 12:19:00 -05:00
|
|
|
export get_class_fields;
|
2011-06-27 17:53:27 -05:00
|
|
|
export get_symbol;
|
2012-01-25 07:34:31 -06:00
|
|
|
export get_enum_variants;
|
2011-06-27 17:53:27 -05:00
|
|
|
export get_type;
|
2012-07-11 12:28:30 -05:00
|
|
|
export get_region_param;
|
2011-06-30 05:35:19 -05:00
|
|
|
export get_type_param_count;
|
2012-07-18 19:34:59 -05:00
|
|
|
export get_impl_traits;
|
2012-03-22 20:03:12 -05:00
|
|
|
export get_class_method;
|
2012-03-08 05:15:02 -06:00
|
|
|
export get_impl_method;
|
2011-12-15 04:42:27 -06:00
|
|
|
export lookup_def;
|
|
|
|
export resolve_path;
|
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-12-11 09:23:38 -06:00
|
|
|
export get_crate_hash;
|
2012-04-07 12:59:37 -05:00
|
|
|
export get_crate_vers;
|
2011-12-16 07:41:12 -06:00
|
|
|
export get_impls_for_mod;
|
2012-07-03 18:30:42 -05:00
|
|
|
export get_trait_methods;
|
2012-07-11 17:00:40 -05:00
|
|
|
export get_method_names_if_trait;
|
2012-07-25 20:36:18 -05:00
|
|
|
export get_item_attrs;
|
2012-01-20 12:45:25 -06:00
|
|
|
export get_crate_module_paths;
|
2012-05-22 12:54:12 -05:00
|
|
|
export def_like;
|
|
|
|
export dl_def;
|
|
|
|
export dl_impl;
|
|
|
|
export dl_field;
|
|
|
|
export path_entry;
|
|
|
|
export each_path;
|
2012-02-10 08:01:32 -06:00
|
|
|
export get_item_path;
|
2012-03-19 12:19:00 -05:00
|
|
|
export maybe_find_item; // sketchy
|
|
|
|
export item_type; // sketchy
|
2012-02-14 17:21:53 -06:00
|
|
|
export maybe_get_item_ast;
|
2012-05-14 19:46:45 -05:00
|
|
|
export decode_inlined_item;
|
2012-05-17 00:46:57 -05:00
|
|
|
export method_info, _impl;
|
2012-02-14 17:21:53 -06:00
|
|
|
|
|
|
|
// Used internally by astencode:
|
|
|
|
export translate_def_id;
|
2012-01-20 12:45:25 -06:00
|
|
|
|
2011-07-08 16:53:25 -05:00
|
|
|
// 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-07-27 07:19:39 -05:00
|
|
|
|
2012-08-11 09:08:42 -05:00
|
|
|
fn lookup_hash(d: ebml::Doc, eq_fn: fn(x:&[u8]) -> bool, hash: uint) ->
|
|
|
|
Option<ebml::Doc> {
|
2011-08-12 00:58:14 -05:00
|
|
|
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;
|
2012-02-14 17:21:53 -06:00
|
|
|
let pos = io::u64_from_be_bytes(*d.data, hash_pos, 4u) as uint;
|
2012-02-10 18:38:33 -06:00
|
|
|
let {tag:_, doc:bucket} = ebml::doc_at(d.data, pos);
|
2011-06-27 17:53:27 -05:00
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
let belt = tag_index_buckets_bucket_elt;
|
2012-07-26 15:43:27 -05:00
|
|
|
for ebml::tagged_docs(bucket, belt) |elt| {
|
2012-02-14 17:21:53 -06:00
|
|
|
let pos = io::u64_from_be_bytes(*elt.data, elt.start, 4u) as uint;
|
2012-08-17 17:54:18 -05:00
|
|
|
if eq_fn(vec::view(*elt.data, elt.start + 4u, elt.end)) {
|
2012-08-20 14:23:37 -05:00
|
|
|
return Some(ebml::doc_at(d.data, pos).doc);
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
2011-10-21 05:31:48 -05:00
|
|
|
};
|
2012-08-20 14:23:37 -05:00
|
|
|
None
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
|
2012-08-11 09:08:42 -05:00
|
|
|
fn maybe_find_item(item_id: int, items: ebml::Doc) -> Option<ebml::Doc> {
|
2012-07-03 18:37:38 -05:00
|
|
|
fn eq_item(bytes: &[u8], item_id: int) -> bool {
|
2012-08-17 17:54:18 -05:00
|
|
|
return io::u64_from_be_bytes(vec::view(bytes, 0u, 4u), 0u, 4u) as int
|
2012-07-03 18:37:38 -05:00
|
|
|
== item_id;
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
2012-07-26 15:43:27 -05:00
|
|
|
lookup_hash(items,
|
|
|
|
|a| eq_item(a, item_id),
|
|
|
|
hash_node_id(item_id))
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
|
2012-08-11 09:08:42 -05:00
|
|
|
fn find_item(item_id: int, items: ebml::Doc) -> ebml::Doc {
|
2012-08-01 19:30:05 -05:00
|
|
|
return option::get(maybe_find_item(item_id, items));
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
|
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.
|
2012-08-11 09:08:42 -05:00
|
|
|
fn lookup_item(item_id: int, data: @~[u8]) -> ebml::Doc {
|
2012-08-29 16:45:25 -05:00
|
|
|
let items = ebml::get_doc(ebml::Doc(data), tag_items);
|
2012-08-06 14:34:08 -05:00
|
|
|
match maybe_find_item(item_id, items) {
|
2012-08-20 14:23:37 -05:00
|
|
|
None => fail(fmt!("lookup_item: id not found: %d", item_id)),
|
|
|
|
Some(d) => d
|
2012-03-06 10:02:13 -06:00
|
|
|
}
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:58:05 -05:00
|
|
|
enum Family {
|
|
|
|
Const, // c
|
|
|
|
Fn, // f
|
|
|
|
UnsafeFn, // u
|
|
|
|
PureFn, // p
|
|
|
|
StaticMethod, // F
|
|
|
|
UnsafeStaticMethod, // U
|
|
|
|
PureStaticMethod, // P
|
|
|
|
ForeignFn, // e
|
|
|
|
Type, // y
|
|
|
|
ForeignType, // T
|
|
|
|
Mod, // m
|
|
|
|
ForeignMod, // n
|
|
|
|
Enum, // t
|
|
|
|
Variant, // v
|
|
|
|
Impl, // i
|
|
|
|
Trait, // I
|
|
|
|
Class, // C
|
|
|
|
Struct, // S
|
|
|
|
PublicField, // g
|
|
|
|
PrivateField, // j
|
|
|
|
InheritedField // N
|
|
|
|
}
|
|
|
|
|
2012-08-27 18:26:35 -05:00
|
|
|
impl Family : cmp::Eq {
|
|
|
|
pure fn eq(&&other: Family) -> bool {
|
|
|
|
(self as uint) == (other as uint)
|
|
|
|
}
|
2012-09-07 14:06:02 -05:00
|
|
|
pure fn ne(&&other: Family) -> bool { !self.eq(other) }
|
2012-08-27 18:26:35 -05:00
|
|
|
}
|
|
|
|
|
2012-08-11 09:08:42 -05:00
|
|
|
fn item_family(item: ebml::Doc) -> Family {
|
2011-08-12 00:58:14 -05:00
|
|
|
let fam = ebml::get_doc(item, tag_items_data_item_family);
|
2012-08-22 19:58:05 -05:00
|
|
|
match ebml::doc_as_u8(fam) as char {
|
|
|
|
'c' => Const,
|
|
|
|
'f' => Fn,
|
|
|
|
'u' => UnsafeFn,
|
|
|
|
'p' => PureFn,
|
|
|
|
'F' => StaticMethod,
|
|
|
|
'U' => UnsafeStaticMethod,
|
|
|
|
'P' => PureStaticMethod,
|
|
|
|
'e' => ForeignFn,
|
|
|
|
'y' => Type,
|
|
|
|
'T' => ForeignType,
|
|
|
|
'm' => Mod,
|
|
|
|
'n' => ForeignMod,
|
|
|
|
't' => Enum,
|
|
|
|
'v' => Variant,
|
|
|
|
'i' => Impl,
|
|
|
|
'I' => Trait,
|
|
|
|
'C' => Class,
|
|
|
|
'S' => Struct,
|
|
|
|
'g' => PublicField,
|
|
|
|
'j' => PrivateField,
|
|
|
|
'N' => InheritedField,
|
|
|
|
c => fail (#fmt("unexpected family char: %c", c))
|
|
|
|
}
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
|
2012-08-11 09:08:42 -05:00
|
|
|
fn item_symbol(item: ebml::Doc) -> ~str {
|
2011-08-12 00:58:14 -05:00
|
|
|
let sym = ebml::get_doc(item, tag_items_data_item_symbol);
|
2012-08-01 19:30:05 -05:00
|
|
|
return str::from_bytes(ebml::doc_data(sym));
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
|
2012-08-11 09:08:42 -05:00
|
|
|
fn item_parent_item(d: ebml::Doc) -> Option<ast::def_id> {
|
2012-07-26 15:43:27 -05:00
|
|
|
for ebml::tagged_docs(d, tag_items_data_parent_item) |did| {
|
2012-08-20 14:23:37 -05:00
|
|
|
return Some(ebml::with_doc_data(did, |d| parse_def_id(d)));
|
2012-03-08 16:13:57 -06:00
|
|
|
}
|
2012-08-20 14:23:37 -05:00
|
|
|
None
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
|
2012-08-11 09:08:42 -05:00
|
|
|
fn item_def_id(d: ebml::Doc, cdata: cmd) -> ast::def_id {
|
2012-03-06 10:02:13 -06:00
|
|
|
let tagdoc = ebml::get_doc(d, tag_def_id);
|
2012-08-01 19:30:05 -05:00
|
|
|
return translate_def_id(cdata, ebml::with_doc_data(tagdoc,
|
2012-07-03 19:11:39 -05:00
|
|
|
|d| parse_def_id(d)));
|
2012-03-06 10:02:13 -06:00
|
|
|
}
|
|
|
|
|
2012-08-11 09:08:42 -05:00
|
|
|
fn each_reexport(d: ebml::Doc, f: fn(ebml::Doc) -> bool) {
|
2012-08-17 14:41:34 -05:00
|
|
|
for ebml::tagged_docs(d, tag_items_data_item_reexport) |reexport_doc| {
|
|
|
|
if !f(reexport_doc) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-11 09:08:42 -05:00
|
|
|
fn field_mutability(d: ebml::Doc) -> ast::class_mutability {
|
2012-03-28 00:08:48 -05:00
|
|
|
// Use maybe_get_doc in case it's a method
|
2012-06-30 18:19:07 -05:00
|
|
|
option::map_default(
|
|
|
|
ebml::maybe_get_doc(d, tag_class_mut),
|
|
|
|
ast::class_immutable,
|
|
|
|
|d| {
|
2012-08-06 14:34:08 -05:00
|
|
|
match ebml::doc_as_u8(d) as char {
|
2012-08-03 21:59:04 -05:00
|
|
|
'm' => ast::class_mutable,
|
|
|
|
_ => ast::class_immutable
|
2012-06-30 18:19:07 -05:00
|
|
|
}
|
|
|
|
})
|
2012-03-28 00:08:48 -05:00
|
|
|
}
|
|
|
|
|
2012-08-11 09:08:42 -05:00
|
|
|
fn variant_disr_val(d: ebml::Doc) -> Option<int> {
|
2012-06-30 18:19:07 -05:00
|
|
|
do option::chain(ebml::maybe_get_doc(d, tag_disr_val)) |val_doc| {
|
2012-02-22 06:18:15 -06:00
|
|
|
int::parse_buf(ebml::doc_data(val_doc), 10u)
|
2012-01-10 15:50:40 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-11 09:08:42 -05:00
|
|
|
fn doc_type(doc: ebml::Doc, tcx: ty::ctxt, cdata: cmd) -> ty::t {
|
2012-01-05 06:57:27 -06:00
|
|
|
let tp = ebml::get_doc(doc, tag_items_data_item_type);
|
2012-06-30 18:19:07 -05:00
|
|
|
parse_ty_data(tp.data, cdata.cnum, tp.start, tcx, |did| {
|
2012-01-05 09:04:59 -06:00
|
|
|
translate_def_id(cdata, did)
|
|
|
|
})
|
2012-01-05 06:57:27 -06:00
|
|
|
}
|
|
|
|
|
2012-08-11 09:08:42 -05:00
|
|
|
fn item_type(item_id: ast::def_id, item: ebml::Doc,
|
2012-02-10 12:28:35 -06:00
|
|
|
tcx: ty::ctxt, cdata: cmd) -> ty::t {
|
2012-01-05 09:04:59 -06:00
|
|
|
let t = doc_type(item, tcx, cdata);
|
2011-12-19 06:52:58 -06:00
|
|
|
if family_names_type(item_family(item)) {
|
2012-02-10 12:28:35 -06:00
|
|
|
ty::mk_with_id(tcx, t, item_id)
|
2012-01-05 06:57:27 -06:00
|
|
|
} else { t }
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
|
2012-08-11 09:08:42 -05:00
|
|
|
fn item_impl_traits(item: ebml::Doc, tcx: ty::ctxt, cdata: cmd) -> ~[ty::t] {
|
2012-07-18 19:34:59 -05:00
|
|
|
let mut results = ~[];
|
2012-07-26 15:43:27 -05:00
|
|
|
for ebml::tagged_docs(item, tag_impl_trait) |ity| {
|
2012-07-18 19:34:59 -05:00
|
|
|
vec::push(results, doc_type(ity, tcx, cdata));
|
2012-04-13 14:22:35 -05:00
|
|
|
};
|
2012-07-18 19:34:59 -05:00
|
|
|
results
|
2012-01-05 03:57:19 -06:00
|
|
|
}
|
|
|
|
|
2012-08-11 09:08:42 -05:00
|
|
|
fn item_ty_param_bounds(item: ebml::Doc, tcx: ty::ctxt, cdata: cmd)
|
2012-06-29 18:26:56 -05:00
|
|
|
-> @~[ty::param_bounds] {
|
|
|
|
let mut bounds = ~[];
|
2012-07-26 15:43:27 -05:00
|
|
|
for ebml::tagged_docs(item, tag_items_data_item_ty_param_bounds) |p| {
|
2012-06-30 18:19:07 -05:00
|
|
|
let bd = parse_bounds_data(p.data, p.start, cdata.cnum, tcx, |did| {
|
2012-01-05 09:04:59 -06:00
|
|
|
translate_def_id(cdata, did)
|
|
|
|
});
|
2012-06-26 02:39:18 -05:00
|
|
|
vec::push(bounds, bd);
|
2011-12-28 10:50:12 -06:00
|
|
|
}
|
2012-01-02 05:09:26 -06:00
|
|
|
@bounds
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
|
2012-08-11 09:08:42 -05:00
|
|
|
fn item_ty_region_param(item: ebml::Doc) -> Option<ty::region_variance> {
|
2012-08-09 11:59:50 -05:00
|
|
|
ebml::maybe_get_doc(item, tag_region_param).map(|doc| {
|
|
|
|
let d = ebml::ebml_deserializer(doc);
|
|
|
|
ty::deserialize_region_variance(d)
|
|
|
|
})
|
2012-04-18 23:26:25 -05:00
|
|
|
}
|
|
|
|
|
2012-08-11 09:08:42 -05:00
|
|
|
fn item_ty_param_count(item: ebml::Doc) -> uint {
|
2012-03-15 08:47:03 -05:00
|
|
|
let mut n = 0u;
|
2011-12-29 04:23:35 -06:00
|
|
|
ebml::tagged_docs(item, tag_items_data_item_ty_param_bounds,
|
2012-07-26 15:43:27 -05:00
|
|
|
|_p| { n += 1u; true } );
|
2011-12-16 07:41:12 -06:00
|
|
|
n
|
|
|
|
}
|
|
|
|
|
2012-08-11 09:08:42 -05:00
|
|
|
fn enum_variant_ids(item: ebml::Doc, cdata: cmd) -> ~[ast::def_id] {
|
2012-06-29 18:26:56 -05:00
|
|
|
let mut ids: ~[ast::def_id] = ~[];
|
2011-07-27 07:19:39 -05:00
|
|
|
let v = tag_items_data_item_variant;
|
2012-07-26 15:43:27 -05:00
|
|
|
for ebml::tagged_docs(item, v) |p| {
|
2012-07-03 19:11:39 -05:00
|
|
|
let ext = ebml::with_doc_data(p, |d| parse_def_id(d));
|
2012-06-26 02:39:18 -05:00
|
|
|
vec::push(ids, {crate: cdata.cnum, node: ext.node});
|
2011-10-21 05:31:48 -05:00
|
|
|
};
|
2012-08-01 19:30:05 -05:00
|
|
|
return ids;
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
|
2012-08-11 09:08:42 -05:00
|
|
|
fn item_path(intr: ident_interner, item_doc: ebml::Doc) -> ast_map::path {
|
2012-02-10 08:01:32 -06:00
|
|
|
let path_doc = ebml::get_doc(item_doc, tag_path);
|
|
|
|
|
|
|
|
let len_doc = ebml::get_doc(path_doc, tag_path_len);
|
2012-02-14 17:21:53 -06:00
|
|
|
let len = ebml::doc_as_u32(len_doc) as uint;
|
2012-02-10 08:01:32 -06:00
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
let mut result = ~[];
|
2012-02-10 08:01:32 -06:00
|
|
|
vec::reserve(result, len);
|
|
|
|
|
2012-07-26 15:43:27 -05:00
|
|
|
for ebml::docs(path_doc) |tag, elt_doc| {
|
2012-02-10 08:01:32 -06:00
|
|
|
if tag == tag_path_elt_mod {
|
2012-02-14 17:21:53 -06:00
|
|
|
let str = ebml::doc_as_str(elt_doc);
|
2012-07-18 18:18:02 -05:00
|
|
|
vec::push(result, ast_map::path_mod(intr.intern(@str)));
|
2012-02-10 08:01:32 -06:00
|
|
|
} else if tag == tag_path_elt_name {
|
2012-02-14 17:21:53 -06:00
|
|
|
let str = ebml::doc_as_str(elt_doc);
|
2012-07-18 18:18:02 -05:00
|
|
|
vec::push(result, ast_map::path_name(intr.intern(@str)));
|
2012-02-10 08:01:32 -06:00
|
|
|
} else {
|
|
|
|
// ignore tag_path_len element
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-01 19:30:05 -05:00
|
|
|
return result;
|
2012-02-10 08:01:32 -06:00
|
|
|
}
|
|
|
|
|
2012-08-11 09:08:42 -05:00
|
|
|
fn item_name(intr: ident_interner, item: ebml::Doc) -> ast::ident {
|
2011-12-16 07:41:12 -06:00
|
|
|
let name = ebml::get_doc(item, tag_paths_data_name);
|
2012-07-18 18:18:02 -05:00
|
|
|
intr.intern(@str::from_bytes(ebml::doc_data(name)))
|
2011-12-16 07:41:12 -06:00
|
|
|
}
|
|
|
|
|
2012-08-11 09:08:42 -05:00
|
|
|
fn item_to_def_like(item: ebml::Doc, did: ast::def_id, cnum: ast::crate_num)
|
2012-05-22 12:54:12 -05:00
|
|
|
-> def_like {
|
2012-08-22 19:58:05 -05:00
|
|
|
let fam = item_family(item);
|
|
|
|
match fam {
|
|
|
|
Const => dl_def(ast::def_const(did)),
|
|
|
|
Class => dl_def(ast::def_class(did, true)),
|
|
|
|
Struct => dl_def(ast::def_class(did, false)),
|
|
|
|
UnsafeFn => dl_def(ast::def_fn(did, ast::unsafe_fn)),
|
|
|
|
Fn => dl_def(ast::def_fn(did, ast::impure_fn)),
|
|
|
|
PureFn => dl_def(ast::def_fn(did, ast::pure_fn)),
|
|
|
|
ForeignFn => dl_def(ast::def_fn(did, ast::extern_fn)),
|
|
|
|
UnsafeStaticMethod => dl_def(ast::def_static_method(did,
|
|
|
|
ast::unsafe_fn)),
|
|
|
|
StaticMethod => dl_def(ast::def_static_method(did, ast::impure_fn)),
|
|
|
|
PureStaticMethod => dl_def(ast::def_static_method(did, ast::pure_fn)),
|
|
|
|
Type | ForeignType => dl_def(ast::def_ty(did)),
|
|
|
|
Mod => dl_def(ast::def_mod(did)),
|
|
|
|
ForeignMod => dl_def(ast::def_foreign_mod(did)),
|
|
|
|
Variant => {
|
|
|
|
match item_parent_item(item) {
|
2012-08-20 14:23:37 -05:00
|
|
|
Some(t) => {
|
2012-08-22 19:58:05 -05:00
|
|
|
let tid = {crate: cnum, node: t.node};
|
|
|
|
dl_def(ast::def_variant(tid, did))
|
|
|
|
}
|
2012-08-20 14:23:37 -05:00
|
|
|
None => fail ~"item_to_def_like: enum item has no parent"
|
2012-08-22 19:58:05 -05:00
|
|
|
}
|
2012-02-13 13:55:23 -06:00
|
|
|
}
|
2012-08-22 19:58:05 -05:00
|
|
|
Trait | Enum => dl_def(ast::def_ty(did)),
|
|
|
|
Impl => dl_impl(did),
|
|
|
|
PublicField | PrivateField | InheritedField => dl_field,
|
2012-02-13 13:55:23 -06:00
|
|
|
}
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
|
2012-05-22 12:54:12 -05:00
|
|
|
fn lookup_def(cnum: ast::crate_num, data: @~[u8], did_: ast::def_id) ->
|
|
|
|
ast::def {
|
|
|
|
let item = lookup_item(did_.node, data);
|
|
|
|
let did = {crate: cnum, node: did_.node};
|
|
|
|
// We treat references to enums as references to types.
|
2012-08-01 19:30:05 -05:00
|
|
|
return def_like_to_def(item_to_def_like(item, did, cnum));
|
2012-05-22 12:54:12 -05:00
|
|
|
}
|
|
|
|
|
2012-01-05 09:04:59 -06:00
|
|
|
fn get_type(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
|
|
|
|
-> ty::ty_param_bounds_and_ty {
|
2012-04-18 23:26:25 -05:00
|
|
|
|
2012-01-05 09:04:59 -06:00
|
|
|
let item = lookup_item(id, cdata.data);
|
2012-02-10 12:28:35 -06:00
|
|
|
let t = item_type({crate: cdata.cnum, node: id}, item, tcx, cdata);
|
2012-01-30 04:36:18 -06:00
|
|
|
let tp_bounds = if family_has_type_params(item_family(item)) {
|
|
|
|
item_ty_param_bounds(item, tcx, cdata)
|
2012-06-29 18:26:56 -05:00
|
|
|
} else { @~[] };
|
2012-04-18 23:26:25 -05:00
|
|
|
let rp = item_ty_region_param(item);
|
2012-08-09 11:59:50 -05:00
|
|
|
return {bounds: tp_bounds,
|
|
|
|
region_param: rp,
|
|
|
|
ty: t};
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
|
2012-08-09 11:59:50 -05:00
|
|
|
fn get_region_param(cdata: cmd, id: ast::node_id)
|
2012-08-20 14:23:37 -05:00
|
|
|
-> Option<ty::region_variance> {
|
2012-08-09 11:59:50 -05:00
|
|
|
|
2012-07-11 12:28:30 -05:00
|
|
|
let item = lookup_item(id, cdata.data);
|
2012-08-01 19:30:05 -05:00
|
|
|
return item_ty_region_param(item);
|
2012-07-11 12:28:30 -05:00
|
|
|
}
|
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
fn get_type_param_count(data: @~[u8], id: ast::node_id) -> uint {
|
2011-12-16 07:41:12 -06:00
|
|
|
item_ty_param_count(lookup_item(id, data))
|
2011-07-29 18:40:23 -05:00
|
|
|
}
|
|
|
|
|
2012-07-18 19:34:59 -05:00
|
|
|
fn get_impl_traits(cdata: cmd, id: ast::node_id, tcx: ty::ctxt) -> ~[ty::t] {
|
|
|
|
item_impl_traits(lookup_item(id, cdata.data), tcx, cdata)
|
2012-01-05 03:57:19 -06:00
|
|
|
}
|
|
|
|
|
2012-07-18 18:18:02 -05:00
|
|
|
fn get_impl_method(intr: ident_interner, cdata: cmd, id: ast::node_id,
|
2012-06-10 02:49:59 -05:00
|
|
|
name: ast::ident) -> ast::def_id {
|
2012-08-29 16:45:25 -05:00
|
|
|
let items = ebml::get_doc(ebml::Doc(cdata.data), tag_items);
|
2012-08-20 14:23:37 -05:00
|
|
|
let mut found = None;
|
2012-07-26 15:43:27 -05:00
|
|
|
for ebml::tagged_docs(find_item(id, items), tag_item_impl_method) |mid| {
|
2012-07-03 19:11:39 -05:00
|
|
|
let m_did = ebml::with_doc_data(mid, |d| parse_def_id(d));
|
2012-07-18 18:18:02 -05:00
|
|
|
if item_name(intr, find_item(m_did.node, items)) == name {
|
2012-08-20 14:23:37 -05:00
|
|
|
found = Some(translate_def_id(cdata, m_did));
|
2012-03-08 05:15:02 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
option::get(found)
|
|
|
|
}
|
|
|
|
|
2012-07-18 18:18:02 -05:00
|
|
|
fn get_class_method(intr: ident_interner, cdata: cmd, id: ast::node_id,
|
2012-06-10 02:49:59 -05:00
|
|
|
name: ast::ident) -> ast::def_id {
|
2012-08-29 16:45:25 -05:00
|
|
|
let items = ebml::get_doc(ebml::Doc(cdata.data), tag_items);
|
2012-08-20 14:23:37 -05:00
|
|
|
let mut found = None;
|
2012-08-06 14:34:08 -05:00
|
|
|
let cls_items = match maybe_find_item(id, items) {
|
2012-08-20 14:23:37 -05:00
|
|
|
Some(it) => it,
|
|
|
|
None => fail (fmt!("get_class_method: class id not found \
|
2012-08-22 19:24:52 -05:00
|
|
|
when looking up method %s", *intr.get(name)))
|
2012-08-03 21:59:04 -05:00
|
|
|
};
|
2012-07-26 15:43:27 -05:00
|
|
|
for ebml::tagged_docs(cls_items, tag_item_trait_method) |mid| {
|
2012-08-08 13:46:06 -05:00
|
|
|
let m_did = item_def_id(mid, cdata);
|
2012-07-18 18:18:02 -05:00
|
|
|
if item_name(intr, mid) == name {
|
2012-08-20 14:23:37 -05:00
|
|
|
found = Some(m_did);
|
2012-03-22 20:03:12 -05:00
|
|
|
}
|
|
|
|
}
|
2012-08-06 14:34:08 -05:00
|
|
|
match found {
|
2012-08-20 14:23:37 -05:00
|
|
|
Some(found) => found,
|
|
|
|
None => fail (fmt!("get_class_method: no method named %s",
|
2012-08-22 19:24:52 -05:00
|
|
|
*intr.get(name)))
|
2012-03-22 20:03:12 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-20 14:23:37 -05:00
|
|
|
fn class_dtor(cdata: cmd, id: ast::node_id) -> Option<ast::def_id> {
|
2012-08-29 16:45:25 -05:00
|
|
|
let items = ebml::get_doc(ebml::Doc(cdata.data), tag_items);
|
2012-08-20 14:23:37 -05:00
|
|
|
let mut found = None;
|
2012-08-06 14:34:08 -05:00
|
|
|
let cls_items = match maybe_find_item(id, items) {
|
2012-08-20 14:23:37 -05:00
|
|
|
Some(it) => it,
|
|
|
|
None => fail (fmt!("class_dtor: class id not found \
|
2012-08-22 19:24:52 -05:00
|
|
|
when looking up dtor for %d", id))
|
2012-06-12 18:25:09 -05:00
|
|
|
};
|
2012-07-26 15:43:27 -05:00
|
|
|
for ebml::tagged_docs(cls_items, tag_item_dtor) |doc| {
|
2012-06-12 18:25:09 -05:00
|
|
|
let doc1 = ebml::get_doc(doc, tag_def_id);
|
2012-07-03 19:11:39 -05:00
|
|
|
let did = ebml::with_doc_data(doc1, |d| parse_def_id(d));
|
2012-08-20 14:23:37 -05:00
|
|
|
found = Some(translate_def_id(cdata, did));
|
2012-06-12 18:25:09 -05:00
|
|
|
};
|
|
|
|
found
|
2012-05-15 19:59:55 -05:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn get_symbol(data: @~[u8], id: ast::node_id) -> ~str {
|
2012-08-01 19:30:05 -05:00
|
|
|
return item_symbol(lookup_item(id, data));
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
|
2012-05-22 12:54:12 -05:00
|
|
|
// Something that a name can resolve to.
|
|
|
|
enum def_like {
|
|
|
|
dl_def(ast::def),
|
|
|
|
dl_impl(ast::def_id),
|
|
|
|
dl_field
|
|
|
|
}
|
|
|
|
|
|
|
|
fn def_like_to_def(def_like: def_like) -> ast::def {
|
2012-08-06 14:34:08 -05:00
|
|
|
match def_like {
|
2012-08-03 21:59:04 -05:00
|
|
|
dl_def(def) => return def,
|
|
|
|
dl_impl(*) => fail ~"found impl in def_like_to_def",
|
|
|
|
dl_field => fail ~"found field in def_like_to_def"
|
2012-05-22 12:54:12 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// A path.
|
2012-08-15 20:46:55 -05:00
|
|
|
struct path_entry {
|
2012-05-22 12:54:12 -05:00
|
|
|
// The full path, separated by '::'.
|
2012-09-06 21:40:15 -05:00
|
|
|
path_string: ~str,
|
2012-05-22 12:54:12 -05:00
|
|
|
// The definition, implementation, or field that this path corresponds to.
|
2012-09-06 21:40:15 -05:00
|
|
|
def_like: def_like,
|
2012-09-05 17:58:43 -05:00
|
|
|
}
|
2012-05-22 12:54:12 -05:00
|
|
|
|
2012-09-05 17:58:43 -05:00
|
|
|
fn path_entry(path_string: ~str, def_like: def_like) -> path_entry {
|
|
|
|
path_entry {
|
|
|
|
path_string: path_string,
|
|
|
|
def_like: def_like
|
2012-05-22 12:54:12 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-04 16:53:12 -05:00
|
|
|
/// Iterates over all the paths in the given crate.
|
2012-07-18 18:18:02 -05:00
|
|
|
fn each_path(intr: ident_interner, cdata: cmd, f: fn(path_entry) -> bool) {
|
2012-08-29 16:45:25 -05:00
|
|
|
let root = ebml::Doc(cdata.data);
|
2012-05-22 12:54:12 -05:00
|
|
|
let items = ebml::get_doc(root, tag_items);
|
|
|
|
let items_data = ebml::get_doc(items, tag_items_data);
|
|
|
|
|
|
|
|
let mut broken = false;
|
|
|
|
|
|
|
|
// First, go through all the explicit items.
|
2012-07-26 15:43:27 -05:00
|
|
|
for ebml::tagged_docs(items_data, tag_items_data_item) |item_doc| {
|
2012-05-22 12:54:12 -05:00
|
|
|
if !broken {
|
2012-07-18 18:18:02 -05:00
|
|
|
let path = ast_map::path_to_str_with_sep(
|
|
|
|
item_path(intr, item_doc), ~"::", intr);
|
2012-08-17 14:41:34 -05:00
|
|
|
if path != ~"" {
|
2012-05-22 12:54:12 -05:00
|
|
|
// Extract the def ID.
|
2012-08-08 13:46:06 -05:00
|
|
|
let def_id = item_def_id(item_doc, cdata);
|
2012-05-22 12:54:12 -05:00
|
|
|
|
|
|
|
// Construct the def for this item.
|
2012-08-22 19:24:52 -05:00
|
|
|
debug!("(each_path) yielding explicit item: %s", path);
|
2012-05-22 12:54:12 -05:00
|
|
|
let def_like = item_to_def_like(item_doc, def_id, cdata.cnum);
|
|
|
|
|
|
|
|
// Hand the information off to the iteratee.
|
2012-08-17 14:41:34 -05:00
|
|
|
let this_path_entry = path_entry(path, def_like);
|
2012-05-22 12:54:12 -05:00
|
|
|
if !f(this_path_entry) {
|
|
|
|
broken = true; // XXX: This is awful.
|
|
|
|
}
|
|
|
|
}
|
2012-07-03 20:30:11 -05:00
|
|
|
|
2012-08-17 14:41:34 -05:00
|
|
|
// If this is a module, find the reexports.
|
|
|
|
for each_reexport(item_doc) |reexport_doc| {
|
|
|
|
if !broken {
|
|
|
|
let def_id_doc =
|
|
|
|
ebml::get_doc(reexport_doc,
|
|
|
|
tag_items_data_item_reexport_def_id);
|
|
|
|
let def_id =
|
|
|
|
ebml::with_doc_data(def_id_doc, |d| parse_def_id(d));
|
|
|
|
let def_id = translate_def_id(cdata, def_id);
|
|
|
|
|
|
|
|
let reexport_name_doc =
|
|
|
|
ebml::get_doc(reexport_doc,
|
|
|
|
tag_items_data_item_reexport_name);
|
|
|
|
let reexport_name = ebml::doc_as_str(reexport_name_doc);
|
|
|
|
|
|
|
|
let reexport_path;
|
|
|
|
if path == ~"" {
|
|
|
|
reexport_path = reexport_name;
|
|
|
|
} else {
|
|
|
|
reexport_path = path + ~"::" + reexport_name;
|
|
|
|
}
|
2012-05-22 12:54:12 -05:00
|
|
|
|
2012-08-17 14:41:34 -05:00
|
|
|
// Get the item.
|
|
|
|
match maybe_find_item(def_id.node, items) {
|
2012-08-20 14:23:37 -05:00
|
|
|
None => {}
|
|
|
|
Some(item_doc) => {
|
2012-08-17 14:41:34 -05:00
|
|
|
// Construct the def for this item.
|
|
|
|
let def_like = item_to_def_like(item_doc,
|
|
|
|
def_id,
|
|
|
|
cdata.cnum);
|
|
|
|
|
|
|
|
// Hand the information off to the iteratee.
|
|
|
|
debug!("(each_path) yielding reexported \
|
|
|
|
item: %s", reexport_path);
|
|
|
|
|
|
|
|
let this_path_entry =
|
|
|
|
path_entry(reexport_path, def_like);
|
|
|
|
if (!f(this_path_entry)) {
|
|
|
|
broken = true; // XXX: This is awful.
|
|
|
|
}
|
|
|
|
}
|
2012-05-22 12:54:12 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-09 19:43:36 -05:00
|
|
|
|
2012-08-17 14:41:34 -05:00
|
|
|
// If broken, stop here.
|
|
|
|
if broken {
|
|
|
|
return;
|
2012-07-09 19:43:36 -05:00
|
|
|
}
|
2012-05-22 12:54:12 -05:00
|
|
|
}
|
|
|
|
|
2012-07-18 18:18:02 -05:00
|
|
|
fn get_item_path(intr: ident_interner, cdata: cmd, id: ast::node_id)
|
|
|
|
-> ast_map::path {
|
|
|
|
item_path(intr, lookup_item(id, cdata.data))
|
2012-02-10 08:01:32 -06:00
|
|
|
}
|
|
|
|
|
2012-05-14 19:46:45 -05:00
|
|
|
type decode_inlined_item = fn(
|
|
|
|
cdata: cstore::crate_metadata,
|
|
|
|
tcx: ty::ctxt,
|
|
|
|
path: ast_map::path,
|
2012-08-11 09:08:42 -05:00
|
|
|
par_doc: ebml::Doc) -> Option<ast::inlined_item>;
|
2012-05-14 19:46:45 -05:00
|
|
|
|
2012-07-18 18:18:02 -05:00
|
|
|
fn maybe_get_item_ast(intr: ident_interner, cdata: cmd, tcx: ty::ctxt,
|
2012-05-14 19:46:45 -05:00
|
|
|
id: ast::node_id,
|
|
|
|
decode_inlined_item: decode_inlined_item
|
|
|
|
) -> csearch::found_ast {
|
2012-08-22 19:24:52 -05:00
|
|
|
debug!("Looking up item: %d", id);
|
2012-02-14 17:21:53 -06:00
|
|
|
let item_doc = lookup_item(id, cdata.data);
|
2012-07-18 18:18:02 -05:00
|
|
|
let path = vec::init(item_path(intr, item_doc));
|
2012-08-06 14:34:08 -05:00
|
|
|
match decode_inlined_item(cdata, tcx, path, item_doc) {
|
2012-08-20 14:23:37 -05:00
|
|
|
Some(ii) => csearch::found(ii),
|
|
|
|
None => {
|
2012-08-06 14:34:08 -05:00
|
|
|
match item_parent_item(item_doc) {
|
2012-08-20 14:23:37 -05:00
|
|
|
Some(did) => {
|
2012-03-08 16:13:57 -06:00
|
|
|
let did = translate_def_id(cdata, did);
|
|
|
|
let parent_item = lookup_item(did.node, cdata.data);
|
2012-08-06 14:34:08 -05:00
|
|
|
match decode_inlined_item(cdata, tcx, path,
|
2012-03-08 16:13:57 -06:00
|
|
|
parent_item) {
|
2012-08-20 14:23:37 -05:00
|
|
|
Some(ii) => csearch::found_parent(did, ii),
|
|
|
|
None => csearch::not_found
|
2012-03-08 16:13:57 -06:00
|
|
|
}
|
|
|
|
}
|
2012-08-20 14:23:37 -05:00
|
|
|
None => csearch::not_found
|
2012-03-08 16:13:57 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-14 17:21:53 -06:00
|
|
|
}
|
|
|
|
|
2012-07-18 18:18:02 -05:00
|
|
|
fn get_enum_variants(intr: ident_interner, cdata: cmd, id: ast::node_id,
|
|
|
|
tcx: ty::ctxt) -> ~[ty::variant_info] {
|
2012-01-05 09:04:59 -06:00
|
|
|
let data = cdata.data;
|
2012-08-29 16:45:25 -05:00
|
|
|
let items = ebml::get_doc(ebml::Doc(data), tag_items);
|
2012-01-05 09:04:59 -06:00
|
|
|
let item = find_item(id, items);
|
2012-06-29 18:26:56 -05:00
|
|
|
let mut infos: ~[ty::variant_info] = ~[];
|
2012-01-25 07:34:31 -06:00
|
|
|
let variant_ids = enum_variant_ids(item, cdata);
|
2012-03-15 08:47:03 -05:00
|
|
|
let mut disr_val = 0;
|
2012-06-30 18:19:07 -05:00
|
|
|
for variant_ids.each |did| {
|
2011-07-27 07:19:39 -05:00
|
|
|
let item = find_item(did.node, items);
|
2012-02-10 12:28:35 -06:00
|
|
|
let ctor_ty = item_type({crate: cdata.cnum, node: id}, item,
|
|
|
|
tcx, cdata);
|
2012-07-18 18:18:02 -05:00
|
|
|
let name = item_name(intr, item);
|
2012-06-29 18:26:56 -05:00
|
|
|
let mut arg_tys: ~[ty::t] = ~[];
|
2012-08-06 14:34:08 -05:00
|
|
|
match ty::get(ctor_ty).struct {
|
2012-08-03 21:59:04 -05:00
|
|
|
ty::ty_fn(f) => {
|
2012-09-07 09:37:19 -05:00
|
|
|
for f.sig.inputs.each |a| { vec::push(arg_tys, a.ty); }
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => { /* Nullary enum variant. */ }
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
2012-08-06 14:34:08 -05:00
|
|
|
match variant_disr_val(item) {
|
2012-08-20 14:23:37 -05:00
|
|
|
Some(val) => { disr_val = val; }
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => { /* empty */ }
|
2012-01-10 15:50:40 -06:00
|
|
|
}
|
2012-06-26 02:39:18 -05:00
|
|
|
vec::push(infos, @{args: arg_tys, ctor_ty: ctor_ty, name: name,
|
|
|
|
id: did, disr_val: disr_val});
|
2012-01-10 15:50:40 -06:00
|
|
|
disr_val += 1;
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
2012-08-01 19:30:05 -05:00
|
|
|
return infos;
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
|
2012-05-17 00:46:57 -05:00
|
|
|
// NB: These types are duplicated in resolve.rs
|
2012-07-31 18:32:37 -05:00
|
|
|
type method_info = {
|
|
|
|
did: ast::def_id,
|
|
|
|
n_tps: uint,
|
|
|
|
ident: ast::ident,
|
|
|
|
self_type: ast::self_ty_
|
|
|
|
};
|
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
type _impl = {did: ast::def_id, ident: ast::ident, methods: ~[@method_info]};
|
2012-05-17 00:46:57 -05:00
|
|
|
|
2012-08-11 09:08:42 -05:00
|
|
|
fn get_self_ty(item: ebml::Doc) -> ast::self_ty_ {
|
2012-07-31 18:32:37 -05:00
|
|
|
fn get_mutability(ch: u8) -> ast::mutability {
|
2012-08-06 14:34:08 -05:00
|
|
|
match ch as char {
|
2012-07-31 18:32:37 -05:00
|
|
|
'i' => { ast::m_imm }
|
|
|
|
'm' => { ast::m_mutbl }
|
|
|
|
'c' => { ast::m_const }
|
|
|
|
_ => {
|
2012-08-22 19:24:52 -05:00
|
|
|
fail fmt!("unknown mutability character: `%c`", ch as char)
|
2012-07-31 18:32:37 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let self_type_doc = ebml::get_doc(item, tag_item_trait_method_self_ty);
|
|
|
|
let string = ebml::doc_as_str(self_type_doc);
|
|
|
|
|
|
|
|
let self_ty_kind = string[0];
|
2012-08-06 14:34:08 -05:00
|
|
|
match self_ty_kind as char {
|
2012-08-02 18:01:38 -05:00
|
|
|
's' => { return ast::sty_static; }
|
2012-08-01 19:30:05 -05:00
|
|
|
'r' => { return ast::sty_by_ref; }
|
|
|
|
'v' => { return ast::sty_value; }
|
|
|
|
'@' => { return ast::sty_box(get_mutability(string[1])); }
|
|
|
|
'~' => { return ast::sty_uniq(get_mutability(string[1])); }
|
2012-08-13 12:17:42 -05:00
|
|
|
'&' => { return ast::sty_region(get_mutability(string[1])); }
|
2012-07-31 18:32:37 -05:00
|
|
|
_ => {
|
2012-08-22 19:24:52 -05:00
|
|
|
fail fmt!("unknown self type code: `%c`", self_ty_kind as char);
|
2012-07-31 18:32:37 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-11 09:08:42 -05:00
|
|
|
fn item_impl_methods(intr: ident_interner, cdata: cmd, item: ebml::Doc,
|
2012-07-18 18:18:02 -05:00
|
|
|
base_tps: uint) -> ~[@method_info] {
|
2012-06-29 18:26:56 -05:00
|
|
|
let mut rslt = ~[];
|
2012-07-26 15:43:27 -05:00
|
|
|
for ebml::tagged_docs(item, tag_item_impl_method) |doc| {
|
2012-07-03 19:11:39 -05:00
|
|
|
let m_did = ebml::with_doc_data(doc, |d| parse_def_id(d));
|
2012-01-11 10:11:56 -06:00
|
|
|
let mth_item = lookup_item(m_did.node, cdata.data);
|
2012-07-31 18:32:37 -05:00
|
|
|
let self_ty = get_self_ty(mth_item);
|
2012-06-26 02:39:18 -05:00
|
|
|
vec::push(rslt, @{did: translate_def_id(cdata, m_did),
|
2012-06-21 18:44:10 -05:00
|
|
|
/* FIXME (maybe #2323) tjc: take a look at this. */
|
2011-12-16 07:41:12 -06:00
|
|
|
n_tps: item_ty_param_count(mth_item) - base_tps,
|
2012-07-18 18:18:02 -05:00
|
|
|
ident: item_name(intr, mth_item),
|
2012-07-31 18:32:37 -05:00
|
|
|
self_type: self_ty});
|
2011-12-16 07:41:12 -06:00
|
|
|
}
|
|
|
|
rslt
|
|
|
|
}
|
|
|
|
|
2012-07-18 18:18:02 -05:00
|
|
|
fn get_impls_for_mod(intr: ident_interner, cdata: cmd,
|
2012-08-20 14:23:37 -05:00
|
|
|
m_id: ast::node_id, name: Option<ast::ident>,
|
2012-04-16 16:58:58 -05:00
|
|
|
get_cdata: fn(ast::crate_num) -> cmd)
|
2012-05-22 12:54:12 -05:00
|
|
|
-> @~[@_impl] {
|
|
|
|
|
2012-01-05 09:04:59 -06:00
|
|
|
let data = cdata.data;
|
2012-03-15 08:47:03 -05:00
|
|
|
let mod_item = lookup_item(m_id, data);
|
2012-06-29 18:26:56 -05:00
|
|
|
let mut result = ~[];
|
2012-07-26 15:43:27 -05:00
|
|
|
for ebml::tagged_docs(mod_item, tag_mod_impl) |doc| {
|
2012-07-03 19:11:39 -05:00
|
|
|
let did = ebml::with_doc_data(doc, |d| parse_def_id(d));
|
2012-04-16 16:58:58 -05:00
|
|
|
let local_did = translate_def_id(cdata, did);
|
2012-08-22 19:24:52 -05:00
|
|
|
debug!("(get impls for mod) getting did %? for '%?'",
|
|
|
|
local_did, name);
|
2012-04-26 14:15:46 -05:00
|
|
|
// The impl may be defined in a different crate. Ask the caller
|
|
|
|
// to give us the metadata
|
2012-04-16 16:58:58 -05:00
|
|
|
let impl_cdata = get_cdata(local_did.crate);
|
|
|
|
let impl_data = impl_cdata.data;
|
|
|
|
let item = lookup_item(local_did.node, impl_data);
|
2012-07-18 18:18:02 -05:00
|
|
|
let nm = item_name(intr, item);
|
2012-08-20 14:23:37 -05:00
|
|
|
if match name { Some(n) => { n == nm } None => { true } } {
|
2012-04-26 14:15:46 -05:00
|
|
|
let base_tps = item_ty_param_count(item);
|
2012-06-26 02:39:18 -05:00
|
|
|
vec::push(result, @{
|
2012-04-16 16:58:58 -05:00
|
|
|
did: local_did, ident: nm,
|
2012-07-18 18:18:02 -05:00
|
|
|
methods: item_impl_methods(intr, impl_cdata, item, base_tps)
|
2012-06-26 02:39:18 -05:00
|
|
|
});
|
2012-04-26 14:15:46 -05:00
|
|
|
};
|
2012-01-05 06:57:27 -06:00
|
|
|
}
|
|
|
|
@result
|
|
|
|
}
|
|
|
|
|
2012-07-03 18:30:42 -05:00
|
|
|
/* Works for both classes and traits */
|
2012-07-18 18:18:02 -05:00
|
|
|
fn get_trait_methods(intr: ident_interner, cdata: cmd, id: ast::node_id,
|
|
|
|
tcx: ty::ctxt) -> @~[ty::method] {
|
2012-01-05 09:04:59 -06:00
|
|
|
let data = cdata.data;
|
2012-03-15 08:47:03 -05:00
|
|
|
let item = lookup_item(id, data);
|
2012-06-29 18:26:56 -05:00
|
|
|
let mut result = ~[];
|
2012-07-26 15:43:27 -05:00
|
|
|
for ebml::tagged_docs(item, tag_item_trait_method) |mth| {
|
2012-01-30 04:36:18 -06:00
|
|
|
let bounds = item_ty_param_bounds(mth, tcx, cdata);
|
2012-07-18 18:18:02 -05:00
|
|
|
let name = item_name(intr, mth);
|
2012-01-05 09:04:59 -06:00
|
|
|
let ty = doc_type(mth, tcx, cdata);
|
2012-08-06 14:34:08 -05:00
|
|
|
let fty = match ty::get(ty).struct {
|
2012-08-03 21:59:04 -05:00
|
|
|
ty::ty_fn(f) => f,
|
|
|
|
_ => {
|
2012-05-14 22:41:33 -05:00
|
|
|
tcx.diag.handler().bug(
|
2012-07-14 00:57:48 -05:00
|
|
|
~"get_trait_methods: id has non-function type");
|
2012-01-30 23:00:57 -06:00
|
|
|
} };
|
2012-07-31 18:32:37 -05:00
|
|
|
let self_ty = get_self_ty(mth);
|
2012-06-26 02:39:18 -05:00
|
|
|
vec::push(result, {ident: name, tps: bounds, fty: fty,
|
2012-08-23 20:17:16 -05:00
|
|
|
self_ty: self_ty,
|
|
|
|
vis: ast::public});
|
2012-01-05 06:57:27 -06:00
|
|
|
}
|
2012-08-22 19:58:05 -05:00
|
|
|
#debug("get_trait_methods: }");
|
2012-01-05 06:57:27 -06:00
|
|
|
@result
|
|
|
|
}
|
|
|
|
|
2012-08-02 18:01:38 -05:00
|
|
|
// If the item in question is a trait, returns its set of methods and
|
|
|
|
// their self types. Otherwise, returns none. This overlaps in an
|
|
|
|
// annoying way with get_trait_methods.
|
2012-07-18 18:18:02 -05:00
|
|
|
fn get_method_names_if_trait(intr: ident_interner, cdata: cmd,
|
|
|
|
node_id: ast::node_id)
|
2012-08-20 14:23:37 -05:00
|
|
|
-> Option<@DVec<(ast::ident, ast::self_ty_)>> {
|
2012-07-11 17:00:40 -05:00
|
|
|
|
|
|
|
let item = lookup_item(node_id, cdata.data);
|
2012-08-22 19:58:05 -05:00
|
|
|
if item_family(item) != Trait {
|
2012-08-20 14:23:37 -05:00
|
|
|
return None;
|
2012-07-11 17:00:40 -05:00
|
|
|
}
|
|
|
|
|
2012-08-27 16:22:25 -05:00
|
|
|
let resulting_methods = @DVec();
|
2012-07-26 15:43:27 -05:00
|
|
|
for ebml::tagged_docs(item, tag_item_trait_method) |method| {
|
2012-08-02 18:01:38 -05:00
|
|
|
resulting_methods.push(
|
2012-07-18 18:18:02 -05:00
|
|
|
(item_name(intr, method), get_self_ty(method)));
|
2012-07-11 17:00:40 -05:00
|
|
|
}
|
2012-08-20 14:23:37 -05:00
|
|
|
return Some(resulting_methods);
|
2012-07-11 17:00:40 -05:00
|
|
|
}
|
|
|
|
|
2012-07-25 20:36:18 -05:00
|
|
|
fn get_item_attrs(cdata: cmd,
|
|
|
|
node_id: ast::node_id,
|
|
|
|
f: fn(~[@ast::meta_item])) {
|
|
|
|
|
|
|
|
let item = lookup_item(node_id, cdata.data);
|
2012-07-26 15:43:27 -05:00
|
|
|
for ebml::tagged_docs(item, tag_attributes) |attributes| {
|
|
|
|
for ebml::tagged_docs(attributes, tag_attribute) |attribute| {
|
2012-07-25 20:36:18 -05:00
|
|
|
f(get_meta_items(attribute));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-21 14:42:34 -05:00
|
|
|
// Helper function that gets either fields or methods
|
2012-07-18 18:18:02 -05:00
|
|
|
fn get_class_members(intr: ident_interner, cdata: cmd, id: ast::node_id,
|
2012-08-22 19:58:05 -05:00
|
|
|
p: fn(Family) -> bool) -> ~[ty::field_ty] {
|
2012-03-06 10:02:13 -06:00
|
|
|
let data = cdata.data;
|
2012-03-15 08:47:03 -05:00
|
|
|
let item = lookup_item(id, data);
|
2012-06-29 18:26:56 -05:00
|
|
|
let mut result = ~[];
|
2012-07-26 15:43:27 -05:00
|
|
|
for ebml::tagged_docs(item, tag_item_field) |an_item| {
|
2012-03-26 11:59:59 -05:00
|
|
|
let f = item_family(an_item);
|
|
|
|
if p(f) {
|
2012-07-18 18:18:02 -05:00
|
|
|
let name = item_name(intr, an_item);
|
2012-08-08 13:46:06 -05:00
|
|
|
let did = item_def_id(an_item, cdata);
|
2012-03-28 00:08:48 -05:00
|
|
|
let mt = field_mutability(an_item);
|
2012-06-26 02:39:18 -05:00
|
|
|
vec::push(result, {ident: name, id: did, vis:
|
|
|
|
family_to_visibility(f), mutability: mt});
|
2012-03-19 12:19:00 -05:00
|
|
|
}
|
2012-03-06 10:02:13 -06:00
|
|
|
}
|
|
|
|
result
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:58:05 -05:00
|
|
|
pure fn family_to_visibility(family: Family) -> ast::visibility {
|
2012-08-06 14:34:08 -05:00
|
|
|
match family {
|
2012-08-22 19:58:05 -05:00
|
|
|
PublicField => ast::public,
|
|
|
|
PrivateField => ast::private,
|
|
|
|
InheritedField => ast::inherited,
|
2012-08-03 15:58:14 -05:00
|
|
|
_ => fail
|
2012-03-26 11:59:59 -05:00
|
|
|
}
|
2012-03-21 14:42:34 -05:00
|
|
|
}
|
|
|
|
|
2012-07-18 18:18:02 -05:00
|
|
|
fn get_class_fields(intr: ident_interner, cdata: cmd, id: ast::node_id)
|
|
|
|
-> ~[ty::field_ty] {
|
2012-08-22 19:58:05 -05:00
|
|
|
get_class_members(intr, cdata, id, |f| f == PublicField
|
|
|
|
|| f == PrivateField || f == InheritedField)
|
2012-03-21 14:42:34 -05:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:58:05 -05:00
|
|
|
fn family_has_type_params(fam: Family) -> bool {
|
|
|
|
match fam {
|
|
|
|
Const | ForeignType | Mod | ForeignMod | PublicField | PrivateField
|
|
|
|
| ForeignFn => false,
|
|
|
|
_ => true
|
2012-01-05 06:57:27 -06:00
|
|
|
}
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:58:05 -05:00
|
|
|
fn family_names_type(fam: Family) -> bool {
|
|
|
|
match fam { Type | Mod | Trait => true, _ => false }
|
2011-12-19 06:52:58 -06:00
|
|
|
}
|
|
|
|
|
2012-08-11 09:08:42 -05:00
|
|
|
fn read_path(d: ebml::Doc) -> {path: ~str, pos: uint} {
|
2011-08-12 00:58:14 -05:00
|
|
|
let desc = ebml::doc_data(d);
|
2012-02-14 17:21:53 -06:00
|
|
|
let pos = io::u64_from_be_bytes(desc, 0u, 4u) as uint;
|
2011-08-13 02:09:25 -05:00
|
|
|
let pathbytes = vec::slice::<u8>(desc, 4u, vec::len::<u8>(desc));
|
2012-01-25 03:20:55 -06:00
|
|
|
let path = str::from_bytes(pathbytes);
|
2012-08-01 19:30:05 -05:00
|
|
|
return {path: path, pos: pos};
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
|
2012-08-11 09:08:42 -05:00
|
|
|
fn describe_def(items: ebml::Doc, id: ast::def_id) -> ~str {
|
2012-08-01 19:30:05 -05:00
|
|
|
if id.crate != ast::local_crate { return ~"external"; }
|
2012-08-06 14:34:08 -05:00
|
|
|
let it = match maybe_find_item(id.node, items) {
|
2012-08-20 14:23:37 -05:00
|
|
|
Some(it) => it,
|
|
|
|
None => fail (fmt!("describe_def: item not found %?", id))
|
2012-06-25 18:49:14 -05:00
|
|
|
};
|
2012-08-01 19:30:05 -05:00
|
|
|
return item_family_to_str(item_family(it));
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:58:05 -05:00
|
|
|
fn item_family_to_str(fam: Family) -> ~str {
|
|
|
|
match fam {
|
|
|
|
Const => ~"const",
|
|
|
|
Fn => ~"fn",
|
|
|
|
UnsafeFn => ~"unsafe fn",
|
|
|
|
PureFn => ~"pure fn",
|
|
|
|
StaticMethod => ~"static method",
|
|
|
|
UnsafeStaticMethod => ~"unsafe static method",
|
|
|
|
PureStaticMethod => ~"pure static method",
|
|
|
|
ForeignFn => ~"foreign fn",
|
|
|
|
Type => ~"type",
|
|
|
|
ForeignType => ~"foreign type",
|
|
|
|
Mod => ~"mod",
|
|
|
|
ForeignMod => ~"foreign mod",
|
|
|
|
Enum => ~"enum",
|
|
|
|
Variant => ~"variant",
|
|
|
|
Impl => ~"impl",
|
|
|
|
Trait => ~"trait",
|
|
|
|
Class => ~"class",
|
|
|
|
Struct => ~"struct",
|
|
|
|
PublicField => ~"public field",
|
|
|
|
PrivateField => ~"private field",
|
|
|
|
InheritedField => ~"inherited field",
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-11 09:08:42 -05:00
|
|
|
fn get_meta_items(md: ebml::Doc) -> ~[@ast::meta_item] {
|
2012-06-29 18:26:56 -05:00
|
|
|
let mut items: ~[@ast::meta_item] = ~[];
|
2012-07-26 15:43:27 -05:00
|
|
|
for ebml::tagged_docs(md, tag_meta_item_word) |meta_item_doc| {
|
2011-08-12 00:58:14 -05:00
|
|
|
let nd = ebml::get_doc(meta_item_doc, tag_meta_item_name);
|
2012-01-25 03:20:55 -06:00
|
|
|
let n = str::from_bytes(ebml::doc_data(nd));
|
2012-07-18 18:18:02 -05:00
|
|
|
vec::push(items, attr::mk_word_item(n));
|
2011-10-21 05:31:48 -05:00
|
|
|
};
|
2012-07-26 15:43:27 -05:00
|
|
|
for ebml::tagged_docs(md, tag_meta_item_name_value) |meta_item_doc| {
|
2011-08-12 00:58:14 -05:00
|
|
|
let nd = ebml::get_doc(meta_item_doc, tag_meta_item_name);
|
|
|
|
let vd = ebml::get_doc(meta_item_doc, tag_meta_item_value);
|
2012-01-25 03:20:55 -06:00
|
|
|
let n = str::from_bytes(ebml::doc_data(nd));
|
|
|
|
let v = str::from_bytes(ebml::doc_data(vd));
|
2012-05-17 18:17:11 -05:00
|
|
|
// FIXME (#623): Should be able to decode meta_name_value variants,
|
|
|
|
// but currently the encoder just drops them
|
2012-07-18 18:18:02 -05:00
|
|
|
vec::push(items, attr::mk_name_value_item_str(n, v));
|
2011-10-21 05:31:48 -05:00
|
|
|
};
|
2012-07-26 15:43:27 -05:00
|
|
|
for ebml::tagged_docs(md, tag_meta_item_list) |meta_item_doc| {
|
2011-08-12 00:58:14 -05:00
|
|
|
let nd = ebml::get_doc(meta_item_doc, tag_meta_item_name);
|
2012-01-25 03:20:55 -06:00
|
|
|
let n = str::from_bytes(ebml::doc_data(nd));
|
2011-07-27 07:19:39 -05:00
|
|
|
let subitems = get_meta_items(meta_item_doc);
|
2012-07-18 18:18:02 -05:00
|
|
|
vec::push(items, attr::mk_list_item(n, subitems));
|
2011-10-21 05:31:48 -05:00
|
|
|
};
|
2012-08-01 19:30:05 -05:00
|
|
|
return items;
|
2011-06-27 20:32:15 -05:00
|
|
|
}
|
|
|
|
|
2012-08-11 09:08:42 -05:00
|
|
|
fn get_attributes(md: ebml::Doc) -> ~[ast::attribute] {
|
2012-06-29 18:26:56 -05:00
|
|
|
let mut attrs: ~[ast::attribute] = ~[];
|
2012-08-06 14:34:08 -05:00
|
|
|
match ebml::maybe_get_doc(md, tag_attributes) {
|
2012-08-20 14:23:37 -05:00
|
|
|
option::Some(attrs_d) => {
|
2012-07-26 15:43:27 -05:00
|
|
|
for ebml::tagged_docs(attrs_d, tag_attribute) |attr_doc| {
|
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];
|
2012-06-28 17:00:03 -05:00
|
|
|
vec::push(attrs,
|
2012-06-30 05:54:54 -05:00
|
|
|
{node: {style: ast::attr_outer, value: *meta_item,
|
|
|
|
is_sugared_doc: false},
|
2012-06-28 17:00:03 -05:00
|
|
|
span: ast_util::dummy_sp()});
|
2011-10-21 05:31:48 -05:00
|
|
|
};
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-08-20 14:23:37 -05:00
|
|
|
option::None => ()
|
2011-06-27 21:41:48 -05:00
|
|
|
}
|
2012-08-01 19:30:05 -05:00
|
|
|
return attrs;
|
2011-06-27 21:41:48 -05:00
|
|
|
}
|
|
|
|
|
2012-07-18 18:18:02 -05:00
|
|
|
fn list_meta_items(intr: ident_interner,
|
2012-08-11 09:08:42 -05:00
|
|
|
meta_items: ebml::Doc, out: io::Writer) {
|
2012-06-30 18:19:07 -05:00
|
|
|
for get_meta_items(meta_items).each |mi| {
|
2012-08-22 19:24:52 -05:00
|
|
|
out.write_str(fmt!("%s\n", pprust::meta_item_to_str(mi, intr)));
|
2011-06-27 20:32:15 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-11 09:08:42 -05:00
|
|
|
fn list_crate_attributes(intr: ident_interner, md: ebml::Doc, hash: ~str,
|
2012-07-18 18:18:02 -05:00
|
|
|
out: io::Writer) {
|
2012-08-22 19:24:52 -05:00
|
|
|
out.write_str(fmt!("=Crate Attributes (%s)=\n", hash));
|
2011-06-27 21:41:48 -05:00
|
|
|
|
2012-06-30 18:19:07 -05:00
|
|
|
for get_attributes(md).each |attr| {
|
2012-08-22 19:24:52 -05:00
|
|
|
out.write_str(fmt!("%s\n", pprust::attribute_to_str(attr, intr)));
|
2011-06-27 21:41:48 -05:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
out.write_str(~"\n\n");
|
2011-06-27 20:32:15 -05:00
|
|
|
}
|
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
fn get_crate_attributes(data: @~[u8]) -> ~[ast::attribute] {
|
2012-08-29 16:45:25 -05:00
|
|
|
return get_attributes(ebml::Doc(data));
|
2011-06-28 13:24:24 -05:00
|
|
|
}
|
|
|
|
|
2012-04-07 12:59:37 -05:00
|
|
|
type crate_dep = {cnum: ast::crate_num, name: ast::ident,
|
2012-07-18 18:18:02 -05:00
|
|
|
vers: ~str, hash: ~str};
|
2011-07-27 07:19:39 -05:00
|
|
|
|
2012-07-18 18:18:02 -05:00
|
|
|
fn get_crate_deps(intr: ident_interner, data: @~[u8]) -> ~[crate_dep] {
|
2012-06-29 18:26:56 -05:00
|
|
|
let mut deps: ~[crate_dep] = ~[];
|
2012-08-29 16:45:25 -05:00
|
|
|
let cratedoc = ebml::Doc(data);
|
2011-08-12 00:58:14 -05:00
|
|
|
let depsdoc = ebml::get_doc(cratedoc, tag_crate_deps);
|
2012-03-15 08:47:03 -05:00
|
|
|
let mut crate_num = 1;
|
2012-08-11 09:08:42 -05:00
|
|
|
fn docstr(doc: ebml::Doc, tag_: uint) -> ~str {
|
2012-04-07 12:59:37 -05:00
|
|
|
str::from_bytes(ebml::doc_data(ebml::get_doc(doc, tag_)))
|
|
|
|
}
|
2012-07-26 15:43:27 -05:00
|
|
|
for ebml::tagged_docs(depsdoc, tag_crate_dep) |depdoc| {
|
2012-06-26 02:39:18 -05:00
|
|
|
vec::push(deps, {cnum: crate_num,
|
2012-07-18 18:18:02 -05:00
|
|
|
name: intr.intern(@docstr(depdoc, tag_crate_dep_name)),
|
|
|
|
vers: docstr(depdoc, tag_crate_dep_vers),
|
|
|
|
hash: docstr(depdoc, tag_crate_dep_hash)});
|
2011-07-08 13:29:56 -05:00
|
|
|
crate_num += 1;
|
2011-10-21 05:31:48 -05:00
|
|
|
};
|
2012-08-01 19:30:05 -05:00
|
|
|
return deps;
|
2011-07-08 13:29:56 -05:00
|
|
|
}
|
|
|
|
|
2012-07-18 18:18:02 -05:00
|
|
|
fn list_crate_deps(intr: ident_interner, data: @~[u8], out: io::Writer) {
|
2012-07-14 00:57:48 -05:00
|
|
|
out.write_str(~"=External Dependencies=\n");
|
2011-07-08 13:29:56 -05:00
|
|
|
|
2012-07-18 18:18:02 -05:00
|
|
|
for get_crate_deps(intr, data).each |dep| {
|
|
|
|
out.write_str(
|
2012-08-22 19:24:52 -05:00
|
|
|
fmt!("%d %s-%s-%s\n",
|
|
|
|
dep.cnum, *intr.get(dep.name), dep.hash, dep.vers));
|
2011-07-08 13:29:56 -05:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
out.write_str(~"\n");
|
2011-07-08 13:29:56 -05:00
|
|
|
}
|
|
|
|
|
2012-07-18 18:18:02 -05:00
|
|
|
fn get_crate_hash(data: @~[u8]) -> ~str {
|
2012-08-29 16:45:25 -05:00
|
|
|
let cratedoc = ebml::Doc(data);
|
2011-12-11 09:23:38 -06:00
|
|
|
let hashdoc = ebml::get_doc(cratedoc, tag_crate_hash);
|
2012-07-18 18:18:02 -05:00
|
|
|
return str::from_bytes(ebml::doc_data(hashdoc));
|
2011-12-11 09:23:38 -06:00
|
|
|
}
|
|
|
|
|
2012-07-18 18:18:02 -05:00
|
|
|
fn get_crate_vers(data: @~[u8]) -> ~str {
|
2012-04-07 12:59:37 -05:00
|
|
|
let attrs = decoder::get_crate_attributes(data);
|
2012-08-06 14:34:08 -05:00
|
|
|
return match attr::last_meta_item_value_str_by_name(
|
2012-07-14 00:57:48 -05:00
|
|
|
attr::find_linkage_metas(attrs), ~"vers") {
|
2012-08-20 14:23:37 -05:00
|
|
|
Some(ver) => ver,
|
|
|
|
None => ~"0.0"
|
2012-04-07 12:59:37 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2012-07-18 18:18:02 -05:00
|
|
|
fn iter_crate_items(intr: ident_interner,
|
|
|
|
cdata: cmd, proc: fn(~str, ast::def_id)) {
|
|
|
|
for each_path(intr, cdata) |path_entry| {
|
2012-08-17 16:54:28 -05:00
|
|
|
match path_entry.def_like {
|
|
|
|
dl_impl(*) | dl_field => {}
|
|
|
|
dl_def(def) => {
|
|
|
|
proc(path_entry.path_string, ast_util::def_id_of_def(def))
|
|
|
|
}
|
|
|
|
}
|
2012-01-20 12:45:25 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-18 18:18:02 -05:00
|
|
|
fn get_crate_module_paths(intr: ident_interner, cdata: cmd)
|
|
|
|
-> ~[(ast::def_id, ~str)] {
|
2012-07-14 00:57:48 -05:00
|
|
|
fn mod_of_path(p: ~str) -> ~str {
|
|
|
|
str::connect(vec::init(str::split_str(p, ~"::")), ~"::")
|
2012-01-20 12:45:25 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// find all module (path, def_ids), which are not
|
|
|
|
// fowarded path due to renamed import or reexport
|
2012-06-29 18:26:56 -05:00
|
|
|
let mut res = ~[];
|
2012-03-14 14:07:23 -05:00
|
|
|
let mods = map::str_hash();
|
2012-07-18 18:18:02 -05:00
|
|
|
do iter_crate_items(intr, cdata) |path, did| {
|
2012-01-20 12:45:25 -06:00
|
|
|
let m = mod_of_path(path);
|
|
|
|
if str::is_not_empty(m) {
|
|
|
|
// if m has a sub-item, it must be a module
|
|
|
|
mods.insert(m, true);
|
|
|
|
}
|
|
|
|
// Collect everything by now. There might be multiple
|
|
|
|
// paths pointing to the same did. Those will be
|
|
|
|
// unified later by using the mods map
|
2012-06-26 02:39:18 -05:00
|
|
|
vec::push(res, (did, path));
|
2012-01-20 12:45:25 -06:00
|
|
|
}
|
2012-08-01 19:30:05 -05:00
|
|
|
return do vec::filter(res) |x| {
|
2012-01-20 12:45:25 -06:00
|
|
|
let (_, xp) = x;
|
|
|
|
mods.contains_key(xp)
|
|
|
|
}
|
2011-06-27 20:32:15 -05:00
|
|
|
}
|
|
|
|
|
2012-07-18 18:18:02 -05:00
|
|
|
fn list_crate_metadata(intr: ident_interner, bytes: @~[u8],
|
|
|
|
out: io::Writer) {
|
2011-12-11 09:23:38 -06:00
|
|
|
let hash = get_crate_hash(bytes);
|
2012-08-29 16:45:25 -05:00
|
|
|
let md = ebml::Doc(bytes);
|
2012-07-18 18:18:02 -05:00
|
|
|
list_crate_attributes(intr, md, hash, out);
|
|
|
|
list_crate_deps(intr, bytes, out);
|
2011-06-27 17:53:27 -05:00
|
|
|
}
|
|
|
|
|
2012-01-05 09:04:59 -06:00
|
|
|
// Translates a def_id from an external crate to a def_id for the current
|
|
|
|
// compilation environment. We use this when trying to load types from
|
|
|
|
// external crates - if those types further refer to types in other crates
|
|
|
|
// then we must translate the crate number from that encoded in the external
|
|
|
|
// crate to the correct local crate number.
|
|
|
|
fn translate_def_id(cdata: cmd, did: ast::def_id) -> ast::def_id {
|
|
|
|
if did.crate == ast::local_crate {
|
2012-08-01 19:30:05 -05:00
|
|
|
return {crate: cdata.cnum, node: did.node};
|
2012-01-05 09:04:59 -06:00
|
|
|
}
|
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
match cdata.cnum_map.find(did.crate) {
|
2012-08-20 14:23:37 -05:00
|
|
|
option::Some(n) => return {crate: n, node: did.node},
|
|
|
|
option::None => fail ~"didn't find a crate in the cnum_map"
|
2012-01-05 09:04:59 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
// End:
|