use index;
use loader;
-use rustc::back::svh::Svh;
-use rustc::front::map as ast_map;
-use rustc::util::nodemap::{FnvHashMap, NodeMap, NodeSet};
+use rustc::hir::def_id::DefId;
+use rustc::hir::svh::Svh;
+use rustc::middle::cstore::{ExternCrate};
+use rustc::util::nodemap::{FnvHashMap, NodeMap, NodeSet, DefIdMap};
use std::cell::{RefCell, Ref, Cell};
use std::rc::Rc;
use syntax::ast;
use syntax::attr;
use syntax::codemap;
-use syntax::parse::token;
use syntax::parse::token::IdentInterner;
-use syntax::util::small_vector::SmallVector;
pub use middle::cstore::{NativeLibraryKind, LinkagePreference};
pub use middle::cstore::{NativeStatic, NativeFramework, NativeUnknown};
pub struct crate_metadata {
pub name: String,
- pub local_path: RefCell<SmallVector<ast_map::PathElem>>,
- pub local_def_path: RefCell<ast_map::DefPath>,
+
+ /// Information about the extern crate that caused this crate to
+ /// be loaded. If this is `None`, then the crate was injected
+ /// (e.g., by the allocator)
+ pub extern_crate: Cell<Option<ExternCrate>>,
+
pub data: MetadataBlob,
pub cnum_map: RefCell<cnum_map>,
pub cnum: ast::CrateNum,
pub codemap_import_info: RefCell<Vec<ImportedFileMap>>,
- pub span: codemap::Span,
pub staged_api: bool,
pub index: index::Index,
used_link_args: RefCell<Vec<String>>,
statically_included_foreign_items: RefCell<NodeSet>,
pub intr: Rc<IdentInterner>,
+ pub visible_parent_map: RefCell<DefIdMap<DefId>>,
}
impl CStore {
used_link_args: RefCell::new(Vec::new()),
intr: intr,
statically_included_foreign_items: RefCell::new(NodeSet()),
+ visible_parent_map: RefCell::new(FnvHashMap()),
}
}
impl crate_metadata {
pub fn data<'a>(&'a self) -> &'a [u8] { self.data.as_slice() }
- pub fn name(&self) -> String { decoder::get_crate_name(self.data()) }
+ pub fn name(&self) -> &str { decoder::get_crate_name(self.data()) }
pub fn hash(&self) -> Svh { decoder::get_crate_hash(self.data()) }
+ pub fn disambiguator(&self) -> &str {
+ decoder::get_crate_disambiguator(self.data())
+ }
pub fn imported_filemaps<'a>(&'a self, codemap: &codemap::CodeMap)
-> Ref<'a, Vec<ImportedFileMap>> {
let filemaps = self.codemap_import_info.borrow();
}
}
- pub fn with_local_path<T, F>(&self, f: F) -> T
- where F: Fn(&[ast_map::PathElem]) -> T
- {
- let cpath = self.local_path.borrow();
- if cpath.is_empty() {
- let name = ast_map::PathMod(token::intern(&self.name));
- f(&[name])
- } else {
- f(cpath.as_slice())
- }
- }
-
- pub fn update_local_path<'a, 'b>(&self, candidate: ast_map::PathElems<'a, 'b>) {
- let mut cpath = self.local_path.borrow_mut();
- let cap = cpath.len();
- match cap {
- 0 => *cpath = candidate.collect(),
- 1 => (),
- _ => {
- let candidate: SmallVector<_> = candidate.collect();
- if candidate.len() < cap {
- *cpath = candidate;
- }
- },
- }
- }
-
- pub fn local_def_path(&self) -> ast_map::DefPath {
- let local_def_path = self.local_def_path.borrow();
- if local_def_path.is_empty() {
- let name = ast_map::DefPathData::DetachedCrate(token::intern(&self.name));
- vec![ast_map::DisambiguatedDefPathData { data: name, disambiguator: 0 }]
- } else {
- local_def_path.clone()
- }
- }
-
- pub fn update_local_def_path(&self, candidate: ast_map::DefPath) {
- let mut local_def_path = self.local_def_path.borrow_mut();
- if local_def_path.is_empty() || candidate.len() < local_def_path.len() {
- *local_def_path = candidate;
- }
- }
-
pub fn is_allocator(&self) -> bool {
let attrs = decoder::get_crate_attributes(self.data());
attr::contains_name(&attrs, "allocator")