(index<- )        ./librustc/metadata/csearch.rs

    git branch:    * master           5200215 auto merge of #14035 : alexcrichton/rust/experimental, r=huonw
    modified:    Fri May  9 13:02:28 2014
   1  // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
   2  // file at the top-level directory of this distribution and at
   3  // http://rust-lang.org/COPYRIGHT.
   4  //
   5  // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
   6  // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
   7  // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
   8  // option. This file may not be copied, modified, or distributed
   9  // except according to those terms.
  10  
  11  // Searching for information from the cstore
  12  
  13  #![allow(non_camel_case_types)]
  14  
  15  use metadata::common::*;
  16  use metadata::cstore;
  17  use metadata::decoder;
  18  use middle::ty;
  19  use middle::typeck;
  20  
  21  use reader = serialize::ebml::reader;
  22  use std::rc::Rc;
  23  use syntax::ast;
  24  use syntax::ast_map;
  25  use syntax::diagnostic::expect;
  26  use syntax::parse::token;
  27  
  28  pub struct StaticMethodInfo {
  29      pub ident: ast::Ident,
  30      pub def_id: ast::DefId,
  31      pub fn_style: ast::FnStyle,
  32      pub vis: ast::Visibility,
  33  }
  34  
  35  pub fn get_symbol(cstore: &cstore::CStore, defast::DefId) -> ~str {
  36      let cdata = cstore.get_crate_data(def.krate);
  37      decoder::get_symbol(cdata.data(), def.node)
  38  }
  39  
  40  /// Iterates over all the language items in the given crate.
  41  pub fn each_lang_item(cstore: &cstore::CStore,
  42                        cnumast::CrateNum,
  43                        f: |ast::NodeId, uint| -> bool)
  44                        -> bool {
  45      let crate_data = cstore.get_crate_data(cnum);
  46      decoder::each_lang_item(&*crate_data, f)
  47  }
  48  
  49  /// Iterates over each child of the given item.
  50  pub fn each_child_of_item(cstore: &cstore::CStore,
  51                            def_idast::DefId,
  52                            callback: |decoder::DefLike,
  53                                       ast::Ident,
  54                                       ast::Visibility|) {
  55      let crate_data = cstore.get_crate_data(def_id.krate);
  56      let get_crate_datadecoder::GetCrateDataCb = |cnum| {
  57          cstore.get_crate_data(cnum)
  58      };
  59      decoder::each_child_of_item(cstore.intr.clone(),
  60                                  &*crate_data,
  61                                  def_id.node,
  62                                  get_crate_data,
  63                                  callback)
  64  }
  65  
  66  /// Iterates over each top-level crate item.
  67  pub fn each_top_level_item_of_crate(cstore: &cstore::CStore,
  68                                      cnumast::CrateNum,
  69                                      callback: |decoder::DefLike,
  70                                                 ast::Ident,
  71                                                 ast::Visibility|) {
  72      let crate_data = cstore.get_crate_data(cnum);
  73      let get_crate_datadecoder::GetCrateDataCb = |cnum| {
  74          cstore.get_crate_data(cnum)
  75      };
  76      decoder::each_top_level_item_of_crate(cstore.intr.clone(),
  77                                            &*crate_data,
  78                                            get_crate_data,
  79                                            callback)
  80  }
  81  
  82  pub fn get_item_path(tcx: &ty::ctxt, defast::DefId) -> Vec<ast_map::PathElem> {
  83      let cstore = &tcx.sess.cstore;
  84      let cdata = cstore.get_crate_data(def.krate);
  85      let path = decoder::get_item_path(&*cdata, def.node);
  86  
  87      // FIXME #1920: This path is not always correct if the crate is not linked
  88      // into the root namespace.
  89      (vec!(ast_map::PathMod(token::intern(cdata.name)))).append(path.as_slice())
  90  }
  91  
  92  pub enum found_ast {
  93      found(ast::InlinedItem),
  94      found_parent(ast::DefId, ast::InlinedItem),
  95      not_found,
  96  }
  97  
  98  // Finds the AST for this item in the crate metadata, if any.  If the item was
  99  // not marked for inlining, then the AST will not be present and hence none
 100  // will be returned.
 101  pub fn maybe_get_item_ast(tcx: &ty::ctxt, defast::DefId,
 102                            decode_inlined_itemdecoder::DecodeInlinedItem)
 103                         -> found_ast {
 104      let cstore = &tcx.sess.cstore;
 105      let cdata = cstore.get_crate_data(def.krate);
 106      decoder::maybe_get_item_ast(&*cdata, tcx, def.node, decode_inlined_item)
 107  }
 108  
 109  pub fn get_enum_variants(tcx: &ty::ctxt, defast::DefId)
 110                        -> Vec<Rc<ty::VariantInfo>> {
 111      let cstore = &tcx.sess.cstore;
 112      let cdata = cstore.get_crate_data(def.krate);
 113      decoder::get_enum_variants(cstore.intr.clone(), &*cdata, def.node, tcx)
 114  }
 115  
 116  /// Returns information about the given implementation.
 117  pub fn get_impl_methods(cstore: &cstore::CStore, impl_def_idast::DefId)
 118                          -> Vec<ast::DefId> {
 119      let cdata = cstore.get_crate_data(impl_def_id.krate);
 120      decoder::get_impl_methods(&*cdata, impl_def_id.node)
 121  }
 122  
 123  pub fn get_method(tcx: &ty::ctxt, defast::DefId) -> ty::Method {
 124      let cdata = tcx.sess.cstore.get_crate_data(def.krate);
 125      decoder::get_method(tcx.sess.cstore.intr.clone(), &*cdata, def.node, tcx)
 126  }
 127  
 128  pub fn get_method_name_and_explicit_self(cstore: &cstore::CStore,
 129                                           defast::DefId)
 130                                       -> (ast::Ident, ast::ExplicitSelf_)
 131  {
 132      let cdata = cstore.get_crate_data(def.krate);
 133      decoder::get_method_name_and_explicit_self(cstore.intr.clone(), &*cdata, def.node)
 134  }
 135  
 136  pub fn get_trait_method_def_ids(cstore: &cstore::CStore,
 137                                  defast::DefId) -> Vec<ast::DefId> {
 138      let cdata = cstore.get_crate_data(def.krate);
 139      decoder::get_trait_method_def_ids(&*cdata, def.node)
 140  }
 141  
 142  pub fn get_item_variances(cstore: &cstore::CStore,
 143                            defast::DefId) -> ty::ItemVariances {
 144      let cdata = cstore.get_crate_data(def.krate);
 145      decoder::get_item_variances(&*cdata, def.node)
 146  }
 147  
 148  pub fn get_provided_trait_methods(tcx: &ty::ctxt,
 149                                    defast::DefId)
 150                                 -> Vec<Rc<ty::Method>> {
 151      let cstore = &tcx.sess.cstore;
 152      let cdata = cstore.get_crate_data(def.krate);
 153      decoder::get_provided_trait_methods(cstore.intr.clone(), &*cdata, def.node, tcx)
 154  }
 155  
 156  pub fn get_supertraits(tcx: &ty::ctxt, defast::DefId) -> Vec<Rc<ty::TraitRef>> {
 157      let cstore = &tcx.sess.cstore;
 158      let cdata = cstore.get_crate_data(def.krate);
 159      decoder::get_supertraits(&*cdata, def.node, tcx)
 160  }
 161  
 162  pub fn get_type_name_if_impl(cstore: &cstore::CStore, defast::DefId)
 163                            -> Option<ast::Ident> {
 164      let cdata = cstore.get_crate_data(def.krate);
 165      decoder::get_type_name_if_impl(&*cdata, def.node)
 166  }
 167  
 168  pub fn get_static_methods_if_impl(cstore: &cstore::CStore,
 169                                    defast::DefId)
 170                                 -> Option<Vec<StaticMethodInfo> > {
 171      let cdata = cstore.get_crate_data(def.krate);
 172      decoder::get_static_methods_if_impl(cstore.intr.clone(), &*cdata, def.node)
 173  }
 174  
 175  pub fn get_item_attrs(cstore: &cstore::CStore,
 176                        def_idast::DefId,
 177                        f: |Vec<@ast::MetaItem> |) {
 178      let cdata = cstore.get_crate_data(def_id.krate);
 179      decoder::get_item_attrs(&*cdata, def_id.node, f)
 180  }
 181  
 182  pub fn get_struct_fields(cstore: &cstore::CStore,
 183                           defast::DefId)
 184                        -> Vec<ty::field_ty> {
 185      let cdata = cstore.get_crate_data(def.krate);
 186      decoder::get_struct_fields(cstore.intr.clone(), &*cdata, def.node)
 187  }
 188  
 189  pub fn get_type(tcx: &ty::ctxt,
 190                  defast::DefId)
 191               -> ty::ty_param_bounds_and_ty {
 192      let cstore = &tcx.sess.cstore;
 193      let cdata = cstore.get_crate_data(def.krate);
 194      decoder::get_type(&*cdata, def.node, tcx)
 195  }
 196  
 197  pub fn get_trait_def(tcx: &ty::ctxt, defast::DefId) -> ty::TraitDef {
 198      let cstore = &tcx.sess.cstore;
 199      let cdata = cstore.get_crate_data(def.krate);
 200      decoder::get_trait_def(&*cdata, def.node, tcx)
 201  }
 202  
 203  pub fn get_field_type(tcx: &ty::ctxt, class_idast::DefId,
 204                        defast::DefId) -> ty::ty_param_bounds_and_ty {
 205      let cstore = &tcx.sess.cstore;
 206      let cdata = cstore.get_crate_data(class_id.krate);
 207      let all_items = reader::get_doc(reader::Doc(cdata.data()), tag_items);
 208      let class_doc = expect(tcx.sess.diagnostic(),
 209                             decoder::maybe_find_item(class_id.node, all_items),
 210                             || {
 211          (format!("get_field_type: class ID {:?} not found",
 212                   class_id)).to_strbuf()
 213      });
 214      let the_field = expect(tcx.sess.diagnostic(),
 215          decoder::maybe_find_item(def.node, class_doc),
 216          || {
 217              (format!("get_field_type: in class {:?}, field ID {:?} not found",
 218                      class_id,
 219                      def)).to_strbuf()
 220          });
 221      let ty = decoder::item_type(def, the_field, tcx, &*cdata);
 222      ty::ty_param_bounds_and_ty {
 223          generics: ty::Generics {type_param_defs: Rc::new(Vec::new()),
 224                                  region_param_defs: Rc::new(Vec::new())},
 225          ty: ty
 226      }
 227  }
 228  
 229  // Given a def_id for an impl, return the trait it implements,
 230  // if there is one.
 231  pub fn get_impl_trait(tcx: &ty::ctxt,
 232                        defast::DefId) -> Option<Rc<ty::TraitRef>> {
 233      let cstore = &tcx.sess.cstore;
 234      let cdata = cstore.get_crate_data(def.krate);
 235      decoder::get_impl_trait(&*cdata, def.node, tcx)
 236  }
 237  
 238  // Given a def_id for an impl, return information about its vtables
 239  pub fn get_impl_vtables(tcx: &ty::ctxt,
 240                          defast::DefId) -> typeck::impl_res {
 241      let cstore = &tcx.sess.cstore;
 242      let cdata = cstore.get_crate_data(def.krate);
 243      decoder::get_impl_vtables(&*cdata, def.node, tcx)
 244  }
 245  
 246  pub fn get_native_libraries(cstore: &cstore::CStore,
 247                              crate_numast::CrateNum)
 248                                  -> Vec<(cstore::NativeLibaryKind, ~str)> {
 249      let cdata = cstore.get_crate_data(crate_num);
 250      decoder::get_native_libraries(&*cdata)
 251  }
 252  
 253  pub fn each_impl(cstore: &cstore::CStore,
 254                   crate_numast::CrateNum,
 255                   callback: |ast::DefId|) {
 256      let cdata = cstore.get_crate_data(crate_num);
 257      decoder::each_impl(&*cdata, callback)
 258  }
 259  
 260  pub fn each_implementation_for_type(cstore: &cstore::CStore,
 261                                      def_idast::DefId,
 262                                      callback: |ast::DefId|) {
 263      let cdata = cstore.get_crate_data(def_id.krate);
 264      decoder::each_implementation_for_type(&*cdata, def_id.node, callback)
 265  }
 266  
 267  pub fn each_implementation_for_trait(cstore: &cstore::CStore,
 268                                       def_idast::DefId,
 269                                       callback: |ast::DefId|) {
 270      let cdata = cstore.get_crate_data(def_id.krate);
 271      decoder::each_implementation_for_trait(&*cdata, def_id.node, callback)
 272  }
 273  
 274  /// If the given def ID describes a method belonging to a trait (either a
 275  /// default method or an implementation of a trait method), returns the ID of
 276  /// the trait that the method belongs to. Otherwise, returns `None`.
 277  pub fn get_trait_of_method(cstore: &cstore::CStore,
 278                             def_idast::DefId,
 279                             tcx: &ty::ctxt)
 280                             -> Option<ast::DefId> {
 281      let cdata = cstore.get_crate_data(def_id.krate);
 282      decoder::get_trait_of_method(&*cdata, def_id.node, tcx)
 283  }
 284  
 285  pub fn get_tuple_struct_definition_if_ctor(cstore: &cstore::CStore,
 286                                             def_idast::DefId)
 287      -> Option<ast::DefId>
 288  {
 289      let cdata = cstore.get_crate_data(def_id.krate);
 290      decoder::get_tuple_struct_definition_if_ctor(&*cdata, def_id.node)
 291  }
 292  
 293  pub fn get_dylib_dependency_formats(cstore: &cstore::CStore,
 294                                      cnumast::CrateNum)
 295      -> Vec<(ast::CrateNum, cstore::LinkagePreference)>
 296  {
 297      let cdata = cstore.get_crate_data(cnum);
 298      decoder::get_dylib_dependency_formats(&*cdata)
 299  }


librustc/metadata/csearch.rs:181:1-181:1 -fn- definition:
pub fn get_struct_fields(cstore: &cstore::CStore,
                         def: ast::DefId)
                      -> Vec<ty::field_ty> {
references:- 2
librustc/middle/resolve.rs:
1691:             child_name_bindings.define_type(def, DUMMY_SP, is_public);
1692:             if csearch::get_struct_fields(&self.session.cstore, def_id).len() == 0 {
1693:                 child_name_bindings.define_value(def, DUMMY_SP, is_public);
librustc/middle/ty.rs:
4014:     } else {
4015:         csearch::get_struct_fields(&cx.sess.cstore, did)
4016:     }


librustc/metadata/csearch.rs:188:1-188:1 -fn- definition:
pub fn get_type(tcx: &ty::ctxt,
                def: ast::DefId)
             -> ty::ty_param_bounds_and_ty {
references:- 5
librustc/middle/trans/callee.rs:
503:     } else {
504:         csearch::get_type(bcx.tcx(), did).ty
505:     };
librustc/middle/trans/consts.rs:
620:                     if !ast_util::is_local(def_id) {
621:                         let ty = csearch::get_type(cx.tcx(), def_id).ty;
622:                         (base::trans_external_path(cx, def_id, ty), true)
librustc/middle/trans/base.rs:
1789:                 } else {
1790:                     let start_fn_type = csearch::get_type(ccx.tcx(),
1791:                                                           start_def_id).ty;
librustc/middle/typeck/collect.rs:
114:         if id.krate != ast::LOCAL_CRATE {
115:             return csearch::get_type(self.tcx, id)
116:         }
librustc/middle/ty.rs:
3862:         "tcache", did, &mut *cx.tcache.borrow_mut(),
3863:         || csearch::get_type(cx, did))
3864: }


librustc/metadata/csearch.rs:230:20-230:20 -fn- definition:
// if there is one.
pub fn get_impl_trait(tcx: &ty::ctxt,
                      def: ast::DefId) -> Option<Rc<ty::TraitRef>> {
references:- 3
librustc/middle/ty.rs:
3586:     } else {
3587:         csearch::get_impl_trait(cx, id)
3588:     };
librustc/middle/typeck/coherence.rs:
612:         let _ = lookup_item_type(tcx, impl_def_id);
613:         let associated_traits = get_impl_trait(tcx, impl_def_id);
librustc/middle/ty.rs:
4346:         // Record the trait->implementation mappings, if applicable.
4347:         let associated_traits = csearch::get_impl_trait(tcx, impl_def_id);
4348:         for trait_ref in associated_traits.iter() {


librustc/metadata/csearch.rs:245:1-245:1 -fn- definition:
pub fn get_native_libraries(cstore: &cstore::CStore,
                            crate_num: ast::CrateNum)
                                -> Vec<(cstore::NativeLibaryKind, ~str)> {
references:- 2
librustc/back/link.rs:
1504:     for (cnum, _) in crates.move_iter() {
1505:         let libs = csearch::get_native_libraries(&sess.cstore, cnum);
1506:         for &(kind, ref lib) in libs.iter() {


librustc/metadata/csearch.rs:116:56-116:56 -fn- definition:
/// Returns information about the given implementation.
pub fn get_impl_methods(cstore: &cstore::CStore, impl_def_id: ast::DefId)
                        -> Vec<ast::DefId> {
references:- 3
librustc/middle/ty.rs:
4343:             |impl_def_id| {
4344:         let methods = csearch::get_impl_methods(&tcx.sess.cstore, impl_def_id);
librustc/middle/typeck/coherence.rs:
602:         let tcx = self.crate_context.tcx;
603:         let methods = csearch::get_impl_methods(&tcx.sess.cstore, impl_def_id);
librustc/middle/ty.rs:
4393:             |implementation_def_id| {
4394:         let methods = csearch::get_impl_methods(&tcx.sess.cstore, implementation_def_id);


librustc/metadata/csearch.rs:135:1-135:1 -fn- definition:
pub fn get_trait_method_def_ids(cstore: &cstore::CStore,
                                def: ast::DefId) -> Vec<ast::DefId> {
    let cdata = cstore.get_crate_data(def.krate);
references:- 2
librustc/middle/resolve.rs:
1651:               let method_def_ids =
1652:                 csearch::get_trait_method_def_ids(&self.session.cstore, def_id);
1653:               for &method_def_id in method_def_ids.iter() {
librustc/middle/ty.rs:
3557:                                      || {
3558:         Rc::new(csearch::get_trait_method_def_ids(&cx.sess.cstore, id))
3559:     })


librustc/metadata/csearch.rs:174:1-174:1 -fn- definition:
pub fn get_item_attrs(cstore: &cstore::CStore,
                      def_id: ast::DefId,
                      f: |Vec<@ast::MetaItem> |) {
references:- 4
librustc/middle/trans/base.rs:
227:     let f = decl_rust_fn(ccx, false, inputs, output, name);
228:     csearch::get_item_attrs(&ccx.sess().cstore, did, |meta_items| {
229:         set_llvm_fn_attrs(meta_items.iter().map(|&x| attr::mk_attr(x))
librustc/middle/ty.rs:
3900:         let mut cont = true;
3901:         csearch::get_item_attrs(&tcx.sess.cstore, did, |meta_items| {
3902:             if cont {
librustc/middle/lint.rs:
1619:         // stability one.
1620:         csearch::get_item_attrs(&cx.tcx.sess.cstore, id, |meta_items| {
1621:             if s.is_none() {


librustc/metadata/csearch.rs:27:1-27:1 -struct- definition:
pub struct StaticMethodInfo {
    pub ident: ast::Ident,
    pub def_id: ast::DefId,
references:- 3
librustc/metadata/decoder.rs:
924:                 static_impl_methods.push(StaticMethodInfo {
925:                     ident: item_name(&*intr, impl_method_doc),
librustc/metadata/csearch.rs:
169:                                   def: ast::DefId)
170:                                -> Option<Vec<StaticMethodInfo> > {
171:     let cdata = cstore.get_crate_data(def.krate);


librustc/metadata/csearch.rs:100:21-100:21 -fn- definition:
// will be returned.
pub fn maybe_get_item_ast(tcx: &ty::ctxt, def: ast::DefId,
                          decode_inlined_item: decoder::DecodeInlinedItem)
references:- 3
librustc/middle/trans/inline.rs:
40:     let csearch_result =
41:         csearch::maybe_get_item_ast(
42:             ccx.tcx(), fn_id,
librustc/middle/const_eval.rs:
127:         }
128:         let e = match csearch::maybe_get_item_ast(tcx, enum_def,
129:             |a, b, c, d| astencode::decode_inlined_item(a, b, c, d)) {
--
162:         }
163:         let e = match csearch::maybe_get_item_ast(tcx, def_id,
164:             |a, b, c, d| astencode::decode_inlined_item(a, b, c, d)) {


librustc/metadata/csearch.rs:91:1-91:1 -enum- definition:
pub enum found_ast {
    found(ast::InlinedItem),
    found_parent(ast::DefId, ast::InlinedItem),
references:- 2
librustc/metadata/decoder.rs:
672:                           decode_inlined_item: DecodeInlinedItem)
673:                           -> csearch::found_ast {
674:     debug!("Looking up item: {}", id);
librustc/metadata/csearch.rs:
102:                           decode_inlined_item: decoder::DecodeInlinedItem)
103:                        -> found_ast {
104:     let cstore = &tcx.sess.cstore;


librustc/metadata/csearch.rs:49:48-49:48 -fn- definition:
/// Iterates over each child of the given item.
pub fn each_child_of_item(cstore: &cstore::CStore,
                          def_id: ast::DefId,
references:- 2
librustc/middle/resolve.rs:
1860:         csearch::each_child_of_item(&self.session.cstore,
1861:                                     def_id,


librustc/metadata/csearch.rs:266:1-266:1 -fn- definition:
pub fn each_implementation_for_trait(cstore: &cstore::CStore,
                                     def_id: ast::DefId,
                                     callback: |ast::DefId|) {
references:- 2
librustc/middle/typeck/coherence.rs:
439:         let crate_store = &self.crate_context.tcx.sess.cstore;
440:         csearch::each_implementation_for_trait(crate_store, trait_def_id, |impl_def_id| {
441:             // Is this actually necessary?
librustc/middle/ty.rs:
4392:     csearch::each_implementation_for_trait(&tcx.sess.cstore, trait_id,
4393:             |implementation_def_id| {


librustc/metadata/csearch.rs:34:1-34:1 -fn- definition:
pub fn get_symbol(cstore: &cstore::CStore, def: ast::DefId) -> ~str {
    let cdata = cstore.get_crate_data(def.krate);
    decoder::get_symbol(cdata.data(), def.node)
references:- 4
librustc/middle/trans/base.rs:
504:         let tcx = ccx.tcx();
505:         let name = csearch::get_symbol(&ccx.sess().cstore, did);
506:         let class_ty = ty::subst_tps(tcx,
--
1871:                                 debug!("but found in other crate...");
1872:                                 (csearch::get_symbol(&ccx.sess().cstore,
1873:                                                      did), false)
librustc/middle/trans/expr.rs:
544:                         let llty = type_of::type_of(bcx.ccx(), const_ty);
545:                         let symbol = csearch::get_symbol(
546:                             &bcx.ccx().sess().cstore,


librustc/metadata/csearch.rs:81:1-81:1 -fn- definition:
pub fn get_item_path(tcx: &ty::ctxt, def: ast::DefId) -> Vec<ast_map::PathElem> {
    let cstore = &tcx.sess.cstore;
    let cdata = cstore.get_crate_data(def.krate);
references:- 3
librustc/middle/trans/meth.rs:
189:     } else {
190:         csearch::get_item_path(bcx.tcx(), method_id).last().unwrap().name()
191:     };
librustc/middle/trans/debuginfo.rs:
1700:         } else {
1701:             csearch::get_item_path(&cx.tcx, def_id).last().unwrap().name()
1702:         };
librustc/middle/ty.rs:
3760:     } else {
3761:         f(ast_map::Values(csearch::get_item_path(cx, id).iter()).chain(None))
3762:     }


librustc/metadata/csearch.rs:284:1-284:1 -fn- definition:
pub fn get_tuple_struct_definition_if_ctor(cstore: &cstore::CStore,
                                           def_id: ast::DefId)
    -> Option<ast::DefId>
references:- 2
librustc/middle/privacy.rs:
856:                     Some(&ast::DefFn(did, _)) if !is_local(did) => {
857:                         match csearch::get_tuple_struct_definition_if_ctor(
858:                                     &self.tcx.sess.cstore, did) {