2011-07-07 23:29:09 -07:00
|
|
|
// Searching for information from the cstore
|
|
|
|
|
2011-07-07 22:18:38 -07:00
|
|
|
import syntax::ast;
|
|
|
|
import middle::ty;
|
2011-07-08 14:53:25 -07:00
|
|
|
import std::option;
|
|
|
|
import driver::session;
|
|
|
|
|
|
|
|
export get_symbol;
|
|
|
|
export get_type_param_count;
|
|
|
|
export lookup_defs;
|
|
|
|
export get_tag_variants;
|
|
|
|
export get_type;
|
2011-07-07 22:18:38 -07:00
|
|
|
|
2011-07-27 14:19:39 +02:00
|
|
|
fn get_symbol(cstore: &cstore::cstore, def: ast::def_id) -> str {
|
|
|
|
let cdata = cstore::get_crate_data(cstore, def.crate).data;
|
2011-07-26 14:06:02 +02:00
|
|
|
ret decoder::get_symbol(cdata, def.node);
|
2011-07-07 22:18:38 -07:00
|
|
|
}
|
|
|
|
|
2011-07-27 14:19:39 +02:00
|
|
|
fn get_type_param_count(cstore: &cstore::cstore, def: &ast::def_id) -> uint {
|
|
|
|
let cdata = cstore::get_crate_data(cstore, def.crate).data;
|
2011-07-26 14:06:02 +02:00
|
|
|
ret decoder::get_type_param_count(cdata, def.node);
|
2011-07-07 22:18:38 -07:00
|
|
|
}
|
|
|
|
|
2011-07-27 14:19:39 +02:00
|
|
|
fn lookup_defs(cstore: &cstore::cstore, cnum: ast::crate_num,
|
2011-08-04 16:20:09 -07:00
|
|
|
path: &[ast::ident]) -> [ast::def] {
|
2011-07-27 14:19:39 +02:00
|
|
|
let cdata = cstore::get_crate_data(cstore, cnum).data;
|
2011-07-08 14:53:25 -07:00
|
|
|
ret decoder::lookup_defs(cdata, cnum, path);
|
|
|
|
}
|
|
|
|
|
2011-08-04 16:20:09 -07:00
|
|
|
fn get_tag_variants(tcx: ty::ctxt, def: ast::def_id) -> [ty::variant_info] {
|
2011-07-27 14:19:39 +02:00
|
|
|
let cstore = tcx.sess.get_cstore();
|
|
|
|
let cnum = def.crate;
|
|
|
|
let cdata = cstore::get_crate_data(cstore, cnum).data;
|
|
|
|
let resolver = bind translate_def_id(tcx.sess, cnum, _);
|
2011-07-08 14:53:25 -07:00
|
|
|
ret decoder::get_tag_variants(cdata, def, tcx, resolver)
|
2011-07-07 22:18:38 -07:00
|
|
|
}
|
|
|
|
|
2011-07-29 16:40:23 -07:00
|
|
|
fn get_type(tcx: ty::ctxt, def: ast::def_id) -> ty::ty_param_kinds_and_ty {
|
2011-07-27 14:19:39 +02:00
|
|
|
let cstore = tcx.sess.get_cstore();
|
|
|
|
let cnum = def.crate;
|
|
|
|
let cdata = cstore::get_crate_data(cstore, cnum).data;
|
|
|
|
let resolver = bind translate_def_id(tcx.sess, cnum, _);
|
2011-07-08 14:53:25 -07:00
|
|
|
decoder::get_type(cdata, def, tcx, resolver)
|
2011-07-07 22:18:38 -07:00
|
|
|
}
|
|
|
|
|
2011-07-08 14:53:25 -07: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.
|
2011-07-27 14:19:39 +02:00
|
|
|
fn translate_def_id(sess: &session::session, searched_crate: ast::crate_num,
|
|
|
|
def_id: &ast::def_id) -> ast::def_id {
|
2011-07-08 14:53:25 -07:00
|
|
|
|
2011-07-27 14:19:39 +02:00
|
|
|
let ext_cnum = def_id.crate;
|
|
|
|
let node_id = def_id.node;
|
2011-07-08 14:53:25 -07:00
|
|
|
|
2011-07-27 14:19:39 +02:00
|
|
|
assert (searched_crate != ast::local_crate);
|
|
|
|
assert (ext_cnum != ast::local_crate);
|
2011-07-08 14:53:25 -07:00
|
|
|
|
2011-07-27 14:19:39 +02:00
|
|
|
let cstore = sess.get_cstore();
|
|
|
|
let cmeta = cstore::get_crate_data(cstore, searched_crate);
|
2011-07-08 14:53:25 -07:00
|
|
|
|
2011-07-27 14:19:39 +02:00
|
|
|
let local_cnum =
|
|
|
|
alt cmeta.cnum_map.find(ext_cnum) {
|
|
|
|
option::some(n) { n }
|
|
|
|
option::none. { sess.bug("didn't find a crate in the cnum_map") }
|
|
|
|
};
|
2011-07-08 14:53:25 -07:00
|
|
|
|
2011-07-27 14:19:39 +02:00
|
|
|
ret {crate: local_cnum, node: node_id};
|
2011-07-07 22:18:38 -07: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:
|