2011-07-08 01:29:09 -05:00
|
|
|
// Searching for information from the cstore
|
|
|
|
|
2011-07-08 00:18:38 -05:00
|
|
|
import syntax::ast;
|
2012-01-20 12:45:25 -06:00
|
|
|
import syntax::ast_util;
|
2011-07-08 00:18:38 -05:00
|
|
|
import middle::ty;
|
2011-07-08 16:53:25 -05:00
|
|
|
import driver::session;
|
|
|
|
|
|
|
|
export get_symbol;
|
|
|
|
export get_type_param_count;
|
|
|
|
export lookup_defs;
|
2012-01-25 07:34:31 -06:00
|
|
|
export get_enum_variants;
|
2011-12-16 07:41:12 -06:00
|
|
|
export get_impls_for_mod;
|
2012-01-05 06:57:27 -06:00
|
|
|
export get_iface_methods;
|
2011-07-08 16:53:25 -05:00
|
|
|
export get_type;
|
2012-01-05 03:57:19 -06:00
|
|
|
export get_impl_iface;
|
2011-07-08 00:18:38 -05:00
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn get_symbol(cstore: cstore::cstore, def: ast::def_id) -> str {
|
2011-07-27 07:19:39 -05:00
|
|
|
let cdata = cstore::get_crate_data(cstore, def.crate).data;
|
2011-07-26 07:06:02 -05:00
|
|
|
ret decoder::get_symbol(cdata, def.node);
|
2011-07-08 00:18:38 -05:00
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn get_type_param_count(cstore: cstore::cstore, def: ast::def_id) -> uint {
|
2011-07-27 07:19:39 -05:00
|
|
|
let cdata = cstore::get_crate_data(cstore, def.crate).data;
|
2011-07-26 07:06:02 -05:00
|
|
|
ret decoder::get_type_param_count(cdata, def.node);
|
2011-07-08 00:18:38 -05:00
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn lookup_defs(cstore: cstore::cstore, cnum: ast::crate_num,
|
|
|
|
path: [ast::ident]) -> [ast::def] {
|
2011-12-15 04:42:27 -06:00
|
|
|
let result = [];
|
|
|
|
for (c, data, def) in resolve_path(cstore, cnum, path) {
|
|
|
|
result += [decoder::lookup_def(c, data, def)];
|
|
|
|
}
|
|
|
|
ret result;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn resolve_path(cstore: cstore::cstore, cnum: ast::crate_num,
|
|
|
|
path: [ast::ident]) ->
|
|
|
|
[(ast::crate_num, @[u8], ast::def_id)] {
|
|
|
|
let cm = cstore::get_crate_data(cstore, cnum);
|
2011-12-22 18:13:40 -06:00
|
|
|
#debug("resolve_path %s in crates[%d]:%s",
|
|
|
|
str::connect(path, "::"), cnum, cm.name);
|
2011-12-15 04:42:27 -06:00
|
|
|
let result = [];
|
|
|
|
for def in decoder::resolve_path(path, cm.data) {
|
|
|
|
if def.crate == ast::local_crate {
|
|
|
|
result += [(cnum, cm.data, def)];
|
|
|
|
} else {
|
|
|
|
if cm.cnum_map.contains_key(def.crate) {
|
|
|
|
// This reexport is itself a reexport from anther crate
|
|
|
|
let next_cnum = cm.cnum_map.get(def.crate);
|
|
|
|
let next_cm_data = cstore::get_crate_data(cstore, next_cnum);
|
|
|
|
result += [(next_cnum, next_cm_data.data, def)];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ret result;
|
2011-07-08 16:53:25 -05:00
|
|
|
}
|
|
|
|
|
2012-01-25 07:34:31 -06:00
|
|
|
fn get_enum_variants(tcx: ty::ctxt, def: ast::def_id) -> [ty::variant_info] {
|
2012-01-12 10:59:49 -06:00
|
|
|
let cstore = tcx.sess.cstore;
|
2012-01-05 09:04:59 -06:00
|
|
|
let cdata = cstore::get_crate_data(cstore, def.crate);
|
2012-01-25 07:34:31 -06:00
|
|
|
ret decoder::get_enum_variants(cdata, def.node, tcx)
|
2011-07-08 00:18:38 -05:00
|
|
|
}
|
|
|
|
|
2011-12-16 07:41:12 -06:00
|
|
|
fn get_impls_for_mod(cstore: cstore::cstore, def: ast::def_id,
|
2012-01-31 19:05:20 -06:00
|
|
|
name: option<ast::ident>)
|
2012-01-05 06:57:27 -06:00
|
|
|
-> @[@middle::resolve::_impl] {
|
2012-01-05 09:04:59 -06:00
|
|
|
let cdata = cstore::get_crate_data(cstore, def.crate);
|
|
|
|
decoder::get_impls_for_mod(cdata, def.node, name)
|
2011-12-16 07:41:12 -06:00
|
|
|
}
|
|
|
|
|
2012-01-05 06:57:27 -06:00
|
|
|
fn get_iface_methods(tcx: ty::ctxt, def: ast::def_id) -> @[ty::method] {
|
2012-01-12 10:59:49 -06:00
|
|
|
let cstore = tcx.sess.cstore;
|
2012-01-05 09:04:59 -06:00
|
|
|
let cdata = cstore::get_crate_data(cstore, def.crate);
|
|
|
|
decoder::get_iface_methods(cdata, def.node, tcx)
|
2011-12-16 07:41:12 -06:00
|
|
|
}
|
|
|
|
|
2011-12-28 10:50:12 -06:00
|
|
|
fn get_type(tcx: ty::ctxt, def: ast::def_id) -> ty::ty_param_bounds_and_ty {
|
2012-01-12 10:59:49 -06:00
|
|
|
let cstore = tcx.sess.cstore;
|
2012-01-05 09:04:59 -06:00
|
|
|
let cdata = cstore::get_crate_data(cstore, def.crate);
|
|
|
|
decoder::get_type(cdata, def.node, tcx)
|
2011-07-08 00:18:38 -05:00
|
|
|
}
|
|
|
|
|
2012-01-05 03:57:19 -06:00
|
|
|
fn get_impl_iface(tcx: ty::ctxt, def: ast::def_id)
|
2012-01-31 19:05:20 -06:00
|
|
|
-> option<ty::t> {
|
2012-01-12 10:59:49 -06:00
|
|
|
let cstore = tcx.sess.cstore;
|
2012-01-05 09:04:59 -06:00
|
|
|
let cdata = cstore::get_crate_data(cstore, def.crate);
|
|
|
|
decoder::get_impl_iface(cdata, def.node, tcx)
|
2011-07-08 00:18:38 -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:
|