split the metadata code into rustc_metadata

tests & rustdoc still broken
This commit is contained in:
Ariel Ben-Yehuda 2015-11-25 00:00:26 +02:00 committed by Ariel Ben-Yehuda
parent 1430a35000
commit 0a8bb4c509
64 changed files with 629 additions and 908 deletions

View File

@ -57,7 +57,7 @@ TARGET_CRATES := libc std flate arena term \
RUSTC_CRATES := rustc rustc_typeck rustc_mir rustc_borrowck rustc_resolve rustc_driver \
rustc_trans rustc_back rustc_llvm rustc_privacy rustc_lint \
rustc_data_structures rustc_front rustc_platform_intrinsics \
rustc_plugin
rustc_plugin rustc_metadata
HOST_CRATES := syntax $(RUSTC_CRATES) rustdoc fmt_macros
TOOLS := compiletest rustdoc rustc rustbook error-index-generator
@ -88,22 +88,23 @@ DEPS_test := std getopts serialize rbml term native:rust_test_helpers
DEPS_syntax := std term serialize log fmt_macros arena libc rustc_bitflags
DEPS_rustc := syntax flate arena serialize getopts rbml rustc_front\
DEPS_rustc := syntax flate arena serialize getopts rustc_front\
log graphviz rustc_llvm rustc_back rustc_data_structures
DEPS_rustc_back := std syntax rustc_llvm rustc_front flate log libc
DEPS_rustc_borrowck := rustc rustc_front log graphviz syntax
DEPS_rustc_data_structures := std log serialize
DEPS_rustc_driver := arena flate getopts graphviz libc rustc rustc_back rustc_borrowck \
rustc_typeck rustc_mir rustc_resolve log syntax serialize rustc_llvm \
rustc_trans rustc_privacy rustc_lint rustc_front rustc_plugin
rustc_trans rustc_privacy rustc_lint rustc_front rustc_plugin \
rustc_metadata
DEPS_rustc_front := std syntax log serialize
DEPS_rustc_lint := rustc log syntax
DEPS_rustc_llvm := native:rustllvm libc std rustc_bitflags
DEPS_rustc_metadata := rustc rustc_front syntax rbml
DEPS_rustc_mir := rustc rustc_front syntax
DEPS_rustc_resolve := rustc rustc_front log syntax
DEPS_rustc_platform_intrinsics := rustc rustc_llvm
DEPS_rustc_plugin := rustc syntax
DEPS_rustc_plugin := rustc rustc_metadata syntax
DEPS_rustc_privacy := rustc rustc_front log syntax
DEPS_rustc_trans := arena flate getopts graphviz libc rustc rustc_back rustc_mir \
log syntax serialize rustc_llvm rustc_front rustc_platform_intrinsics

View File

@ -1899,51 +1899,6 @@ contain references (with a maximum lifetime of `'a`).
[1]: https://github.com/rust-lang/rfcs/pull/1156
"##,
E0454: r##"
A link name was given with an empty name. Erroneous code example:
```
#[link(name = "")] extern {} // error: #[link(name = "")] given with empty name
```
The rust compiler cannot link to an external library if you don't give it its
name. Example:
```
#[link(name = "some_lib")] extern {} // ok!
```
"##,
E0458: r##"
An unknown "kind" was specified for a link attribute. Erroneous code example:
```
#[link(kind = "wonderful_unicorn")] extern {}
// error: unknown kind: `wonderful_unicorn`
```
Please specify a valid "kind" value, from one of the following:
* static
* dylib
* framework
"##,
E0459: r##"
A link was used without a name parameter. Erroneous code example:
```
#[link(kind = "dylib")] extern {}
// error: #[link(...)] specified without `name = "foo"`
```
Please add the name parameter to allow the rust compiler to find the library
you want. Example:
```
#[link(kind = "dylib", name = "some_lib")] extern {} // ok!
```
"##,
E0493: r##"
A type with a destructor was assigned to an invalid type of variable. Erroneous
code example:
@ -2144,20 +2099,6 @@ register_diagnostics! {
E0400, // overloaded derefs are not allowed in constants
E0452, // malformed lint attribute
E0453, // overruled by outer forbid
E0455, // native frameworks are only available on OSX targets
E0456, // plugin `..` is not available for triple `..`
E0457, // plugin `..` only found in rlib format, but must be available...
E0460, // found possibly newer version of crate `..`
E0461, // couldn't find crate `..` with expected target triple ..
E0462, // found staticlib `..` instead of rlib or dylib
E0463, // can't find crate for `..`
E0464, // multiple matching crates for `..`
E0465, // multiple .. candidates for `..` found
E0466, // bad macro import
E0467, // bad macro reexport
E0468, // an `extern crate` loading macros must be at the crate root
E0469, // imported macro not found
E0470, // reexported macro not found
E0471, // constant evaluation error: ..
E0472, // asm! is unsupported on this target
E0473, // dereference of reference outside its lifetime
@ -2181,5 +2122,4 @@ register_diagnostics! {
E0491, // in type `..`, reference has a longer lifetime than the data it...
E0492, // cannot borrow a constant which contains interior mutability
E0495, // cannot infer an appropriate lifetime due to conflicting requirements
E0514, // metadata version mismatch
}

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use metadata::cstore::LOCAL_CRATE;
use middle::cstore::LOCAL_CRATE;
use middle::def_id::{DefId, DefIndex};
use rustc_data_structures::fnv::FnvHashMap;
use rustc_front::hir;

View File

@ -14,8 +14,8 @@ use self::MapEntry::*;
use self::collector::NodeCollector;
pub use self::definitions::{Definitions, DefKey, DefPath, DefPathData, DisambiguatedDefPathData};
use metadata::inline::InlinedItem;
use metadata::inline::InlinedItem as II;
use middle::cstore::InlinedItem;
use middle::cstore::InlinedItem as II;
use middle::def_id::DefId;
use syntax::abi;

View File

@ -67,7 +67,6 @@ extern crate rustc_back;
extern crate rustc_front;
extern crate rustc_data_structures;
extern crate serialize;
extern crate rbml;
extern crate collections;
#[macro_use] extern crate log;
#[macro_use] extern crate syntax;
@ -101,7 +100,6 @@ pub mod front {
pub mod middle {
pub mod astconv_util;
pub mod expr_use_visitor; // STAGE0: increase glitch immunity
pub mod astencode;
pub mod cfg;
pub mod check_const;
pub mod check_static_recursion;
@ -110,6 +108,7 @@ pub mod middle {
pub mod check_no_asm;
pub mod check_rvalues;
pub mod const_eval;
pub mod cstore;
pub mod dataflow;
pub mod dead;
pub mod def;
@ -137,8 +136,6 @@ pub mod middle {
pub mod weak_lang_items;
}
pub mod metadata;
pub mod session;
pub mod lint;

View File

@ -1,408 +0,0 @@
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Searching for information from the cstore
use front::map as ast_map;
use metadata::cstore;
use metadata::decoder;
use metadata::inline::InlinedItem;
use middle::def_id::{DefId, DefIndex};
use middle::lang_items;
use middle::ty;
use util::nodemap::FnvHashMap;
use std::rc::Rc;
use syntax::ast;
use syntax::attr;
use rustc_front::hir;
#[derive(Copy, Clone)]
pub struct MethodInfo {
pub name: ast::Name,
pub def_id: DefId,
pub vis: hir::Visibility,
}
pub fn get_symbol(cstore: &cstore::CStore, def: DefId) -> String {
let cdata = cstore.get_crate_data(def.krate);
decoder::get_symbol(&cdata, def.index)
}
/// Iterates over all the language items in the given crate.
pub fn each_lang_item<F>(cstore: &cstore::CStore,
cnum: ast::CrateNum,
f: F)
-> bool where
F: FnMut(DefIndex, usize) -> bool,
{
let crate_data = cstore.get_crate_data(cnum);
decoder::each_lang_item(&*crate_data, f)
}
/// Iterates over each child of the given item.
pub fn each_child_of_item<F>(cstore: &cstore::CStore,
def_id: DefId,
callback: F) where
F: FnMut(decoder::DefLike, ast::Name, hir::Visibility),
{
let crate_data = cstore.get_crate_data(def_id.krate);
let get_crate_data = |cnum| {
cstore.get_crate_data(cnum)
};
decoder::each_child_of_item(cstore.intr.clone(),
&*crate_data,
def_id.index,
get_crate_data,
callback)
}
/// Iterates over each top-level crate item.
pub fn each_top_level_item_of_crate<F>(cstore: &cstore::CStore,
cnum: ast::CrateNum,
callback: F) where
F: FnMut(decoder::DefLike, ast::Name, hir::Visibility),
{
let crate_data = cstore.get_crate_data(cnum);
let get_crate_data = |cnum| {
cstore.get_crate_data(cnum)
};
decoder::each_top_level_item_of_crate(cstore.intr.clone(),
&*crate_data,
get_crate_data,
callback)
}
pub fn get_item_path(tcx: &ty::ctxt, def: DefId) -> Vec<ast_map::PathElem> {
let cstore = &tcx.sess.cstore;
let cdata = cstore.get_crate_data(def.krate);
let path = decoder::get_item_path(&*cdata, def.index);
cdata.with_local_path(|cpath| {
let mut r = Vec::with_capacity(cpath.len() + path.len());
r.push_all(cpath);
r.push_all(&path);
r
})
}
pub fn get_item_name(tcx: &ty::ctxt, def: DefId) -> ast::Name {
let cstore = &tcx.sess.cstore;
let cdata = cstore.get_crate_data(def.krate);
decoder::get_item_name(&cstore.intr, &cdata, def.index)
}
pub enum FoundAst<'ast> {
Found(&'ast InlinedItem),
FoundParent(DefId, &'ast InlinedItem),
NotFound,
}
// Finds the AST for this item in the crate metadata, if any. If the item was
// not marked for inlining, then the AST will not be present and hence none
// will be returned.
pub fn maybe_get_item_ast<'tcx>(tcx: &ty::ctxt<'tcx>, def: DefId,
decode_inlined_item: decoder::DecodeInlinedItem)
-> FoundAst<'tcx> {
let cstore = &tcx.sess.cstore;
let cdata = cstore.get_crate_data(def.krate);
decoder::maybe_get_item_ast(&*cdata, tcx, def.index, decode_inlined_item)
}
/// Returns information about the given implementation.
pub fn get_impl_items(cstore: &cstore::CStore, impl_def_id: DefId)
-> Vec<ty::ImplOrTraitItemId> {
let cdata = cstore.get_crate_data(impl_def_id.krate);
decoder::get_impl_items(&*cdata, impl_def_id.index)
}
pub fn get_impl_or_trait_item<'tcx>(tcx: &ty::ctxt<'tcx>, def: DefId)
-> ty::ImplOrTraitItem<'tcx> {
let cdata = tcx.sess.cstore.get_crate_data(def.krate);
decoder::get_impl_or_trait_item(tcx.sess.cstore.intr.clone(),
&*cdata,
def.index,
tcx)
}
pub fn get_trait_name(cstore: &cstore::CStore, def: DefId) -> ast::Name {
let cdata = cstore.get_crate_data(def.krate);
decoder::get_trait_name(cstore.intr.clone(),
&*cdata,
def.index)
}
pub fn is_static_method(cstore: &cstore::CStore, def: DefId) -> bool {
let cdata = cstore.get_crate_data(def.krate);
decoder::is_static_method(&*cdata, def.index)
}
pub fn get_trait_item_def_ids(cstore: &cstore::CStore, def: DefId)
-> Vec<ty::ImplOrTraitItemId> {
let cdata = cstore.get_crate_data(def.krate);
decoder::get_trait_item_def_ids(&*cdata, def.index)
}
pub fn get_item_variances(cstore: &cstore::CStore,
def: DefId) -> ty::ItemVariances {
let cdata = cstore.get_crate_data(def.krate);
decoder::get_item_variances(&*cdata, def.index)
}
pub fn get_provided_trait_methods<'tcx>(tcx: &ty::ctxt<'tcx>,
def: DefId)
-> Vec<Rc<ty::Method<'tcx>>> {
let cstore = &tcx.sess.cstore;
let cdata = cstore.get_crate_data(def.krate);
decoder::get_provided_trait_methods(cstore.intr.clone(), &*cdata, def.index, tcx)
}
pub fn get_associated_consts<'tcx>(tcx: &ty::ctxt<'tcx>, def: DefId)
-> Vec<Rc<ty::AssociatedConst<'tcx>>> {
let cstore = &tcx.sess.cstore;
let cdata = cstore.get_crate_data(def.krate);
decoder::get_associated_consts(cstore.intr.clone(), &*cdata, def.index, tcx)
}
pub fn get_methods_if_impl(cstore: &cstore::CStore,
def: DefId)
-> Option<Vec<MethodInfo> > {
let cdata = cstore.get_crate_data(def.krate);
decoder::get_methods_if_impl(cstore.intr.clone(), &*cdata, def.index)
}
pub fn get_item_attrs(cstore: &cstore::CStore,
def_id: DefId)
-> Vec<ast::Attribute> {
let cdata = cstore.get_crate_data(def_id.krate);
decoder::get_item_attrs(&*cdata, def_id.index)
}
pub fn get_struct_field_names(cstore: &cstore::CStore, def: DefId) -> Vec<ast::Name> {
let cdata = cstore.get_crate_data(def.krate);
decoder::get_struct_field_names(&cstore.intr, &*cdata, def.index)
}
pub fn get_struct_field_attrs(cstore: &cstore::CStore, def: DefId)
-> FnvHashMap<DefId, Vec<ast::Attribute>> {
let cdata = cstore.get_crate_data(def.krate);
decoder::get_struct_field_attrs(&*cdata)
}
pub fn get_type<'tcx>(tcx: &ty::ctxt<'tcx>,
def: DefId)
-> ty::TypeScheme<'tcx> {
let cstore = &tcx.sess.cstore;
let cdata = cstore.get_crate_data(def.krate);
decoder::get_type(&*cdata, def.index, tcx)
}
pub fn get_trait_def<'tcx>(tcx: &ty::ctxt<'tcx>, def: DefId) -> ty::TraitDef<'tcx> {
let cstore = &tcx.sess.cstore;
let cdata = cstore.get_crate_data(def.krate);
decoder::get_trait_def(&*cdata, def.index, tcx)
}
pub fn get_adt_def<'tcx>(tcx: &ty::ctxt<'tcx>, def: DefId) -> ty::AdtDefMaster<'tcx> {
let cstore = &tcx.sess.cstore;
let cdata = cstore.get_crate_data(def.krate);
decoder::get_adt_def(&cstore.intr, &*cdata, def.index, tcx)
}
pub fn get_predicates<'tcx>(tcx: &ty::ctxt<'tcx>, def: DefId)
-> ty::GenericPredicates<'tcx>
{
let cstore = &tcx.sess.cstore;
let cdata = cstore.get_crate_data(def.krate);
decoder::get_predicates(&*cdata, def.index, tcx)
}
pub fn get_super_predicates<'tcx>(tcx: &ty::ctxt<'tcx>, def: DefId)
-> ty::GenericPredicates<'tcx>
{
let cstore = &tcx.sess.cstore;
let cdata = cstore.get_crate_data(def.krate);
decoder::get_super_predicates(&*cdata, def.index, tcx)
}
pub fn get_impl_polarity<'tcx>(tcx: &ty::ctxt<'tcx>,
def: DefId)
-> Option<hir::ImplPolarity>
{
let cstore = &tcx.sess.cstore;
let cdata = cstore.get_crate_data(def.krate);
decoder::get_impl_polarity(&*cdata, def.index)
}
pub fn get_custom_coerce_unsized_kind<'tcx>(
tcx: &ty::ctxt<'tcx>,
def: DefId)
-> Option<ty::adjustment::CustomCoerceUnsized>
{
let cstore = &tcx.sess.cstore;
let cdata = cstore.get_crate_data(def.krate);
decoder::get_custom_coerce_unsized_kind(&*cdata, def.index)
}
// Given a def_id for an impl, return the trait it implements,
// if there is one.
pub fn get_impl_trait<'tcx>(tcx: &ty::ctxt<'tcx>,
def: DefId)
-> Option<ty::TraitRef<'tcx>> {
let cstore = &tcx.sess.cstore;
let cdata = cstore.get_crate_data(def.krate);
decoder::get_impl_trait(&*cdata, def.index, tcx)
}
pub fn get_native_libraries(cstore: &cstore::CStore, crate_num: ast::CrateNum)
-> Vec<(cstore::NativeLibraryKind, String)> {
let cdata = cstore.get_crate_data(crate_num);
decoder::get_native_libraries(&*cdata)
}
pub fn each_inherent_implementation_for_type<F>(cstore: &cstore::CStore,
def_id: DefId,
callback: F) where
F: FnMut(DefId),
{
let cdata = cstore.get_crate_data(def_id.krate);
decoder::each_inherent_implementation_for_type(&*cdata, def_id.index, callback)
}
pub fn each_implementation_for_trait<F>(cstore: &cstore::CStore,
def_id: DefId,
mut callback: F) where
F: FnMut(DefId),
{
cstore.iter_crate_data(|_, cdata| {
decoder::each_implementation_for_trait(cdata, def_id, &mut callback)
})
}
/// If the given def ID describes an item belonging to a trait (either a
/// default method or an implementation of a trait method), returns the ID of
/// the trait that the method belongs to. Otherwise, returns `None`.
pub fn get_trait_of_item(cstore: &cstore::CStore,
def_id: DefId,
tcx: &ty::ctxt)
-> Option<DefId> {
let cdata = cstore.get_crate_data(def_id.krate);
decoder::get_trait_of_item(&*cdata, def_id.index, tcx)
}
pub fn get_tuple_struct_definition_if_ctor(cstore: &cstore::CStore,
def_id: DefId)
-> Option<DefId>
{
let cdata = cstore.get_crate_data(def_id.krate);
decoder::get_tuple_struct_definition_if_ctor(&*cdata, def_id.index)
}
pub fn get_dylib_dependency_formats(cstore: &cstore::CStore,
cnum: ast::CrateNum)
-> Vec<(ast::CrateNum, cstore::LinkagePreference)>
{
let cdata = cstore.get_crate_data(cnum);
decoder::get_dylib_dependency_formats(&*cdata)
}
pub fn get_missing_lang_items(cstore: &cstore::CStore, cnum: ast::CrateNum)
-> Vec<lang_items::LangItem>
{
let cdata = cstore.get_crate_data(cnum);
decoder::get_missing_lang_items(&*cdata)
}
pub fn get_method_arg_names(cstore: &cstore::CStore, did: DefId)
-> Vec<String>
{
let cdata = cstore.get_crate_data(did.krate);
decoder::get_method_arg_names(&*cdata, did.index)
}
pub fn get_reachable_ids(cstore: &cstore::CStore, cnum: ast::CrateNum)
-> Vec<DefId>
{
let cdata = cstore.get_crate_data(cnum);
decoder::get_reachable_ids(&*cdata)
}
pub fn is_typedef(cstore: &cstore::CStore, did: DefId) -> bool {
let cdata = cstore.get_crate_data(did.krate);
decoder::is_typedef(&*cdata, did.index)
}
pub fn is_const_fn(cstore: &cstore::CStore, did: DefId) -> bool {
let cdata = cstore.get_crate_data(did.krate);
decoder::is_const_fn(&*cdata, did.index)
}
pub fn is_static(cstore: &cstore::CStore, did: DefId) -> bool {
let cdata = cstore.get_crate_data(did.krate);
decoder::is_static(&*cdata, did.index)
}
pub fn is_impl(cstore: &cstore::CStore, did: DefId) -> bool {
let cdata = cstore.get_crate_data(did.krate);
decoder::is_impl(&*cdata, did.index)
}
pub fn get_stability(cstore: &cstore::CStore,
def: DefId)
-> Option<attr::Stability> {
let cdata = cstore.get_crate_data(def.krate);
decoder::get_stability(&*cdata, def.index)
}
pub fn is_staged_api(cstore: &cstore::CStore, krate: ast::CrateNum) -> bool {
cstore.get_crate_data(krate).staged_api
}
pub fn get_repr_attrs(cstore: &cstore::CStore, def: DefId)
-> Vec<attr::ReprAttr> {
let cdata = cstore.get_crate_data(def.krate);
decoder::get_repr_attrs(&*cdata, def.index)
}
pub fn is_defaulted_trait(cstore: &cstore::CStore, trait_def_id: DefId) -> bool {
let cdata = cstore.get_crate_data(trait_def_id.krate);
decoder::is_defaulted_trait(&*cdata, trait_def_id.index)
}
pub fn is_default_impl(cstore: &cstore::CStore, impl_did: DefId) -> bool {
let cdata = cstore.get_crate_data(impl_did.krate);
decoder::is_default_impl(&*cdata, impl_did.index)
}
pub fn is_extern_fn(cstore: &cstore::CStore, did: DefId,
tcx: &ty::ctxt) -> bool {
let cdata = cstore.get_crate_data(did.krate);
decoder::is_extern_fn(&*cdata, did.index, tcx)
}
pub fn closure_kind<'tcx>(tcx: &ty::ctxt<'tcx>, def_id: DefId) -> ty::ClosureKind {
assert!(!def_id.is_local());
let cdata = tcx.sess.cstore.get_crate_data(def_id.krate);
decoder::closure_kind(&*cdata, def_id.index)
}
pub fn closure_ty<'tcx>(tcx: &ty::ctxt<'tcx>, def_id: DefId) -> ty::ClosureTy<'tcx> {
assert!(!def_id.is_local());
let cdata = tcx.sess.cstore.get_crate_data(def_id.krate);
decoder::closure_ty(&*cdata, def_id.index, tcx)
}
pub fn def_path(tcx: &ty::ctxt, def: DefId) -> ast_map::DefPath {
let cstore = &tcx.sess.cstore;
let cdata = cstore.get_crate_data(def.krate);
let path = decoder::def_path(&*cdata, def.index);
let local_path = cdata.local_def_path();
local_path.into_iter().chain(path).collect()
}

View File

@ -1,60 +0,0 @@
// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use middle::def_id::DefId;
use rustc_front::hir;
use rustc_front::util::IdVisitor;
use syntax::ast_util::{IdRange, IdRangeComputingVisitor, IdVisitingOperation};
use syntax::ptr::P;
use rustc_front::intravisit::Visitor;
use self::InlinedItem::*;
/// The data we save and restore about an inlined item or method. This is not
/// part of the AST that we parse from a file, but it becomes part of the tree
/// that we trans.
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub enum InlinedItem {
Item(P<hir::Item>),
TraitItem(DefId /* impl id */, P<hir::TraitItem>),
ImplItem(DefId /* impl id */, P<hir::ImplItem>),
Foreign(P<hir::ForeignItem>),
}
/// A borrowed version of `hir::InlinedItem`.
pub enum InlinedItemRef<'a> {
Item(&'a hir::Item),
TraitItem(DefId, &'a hir::TraitItem),
ImplItem(DefId, &'a hir::ImplItem),
Foreign(&'a hir::ForeignItem)
}
impl InlinedItem {
pub fn visit<'ast,V>(&'ast self, visitor: &mut V)
where V: Visitor<'ast>
{
match *self {
Item(ref i) => visitor.visit_item(&**i),
Foreign(ref i) => visitor.visit_foreign_item(&**i),
TraitItem(_, ref ti) => visitor.visit_trait_item(ti),
ImplItem(_, ref ii) => visitor.visit_impl_item(ii),
}
}
pub fn visit_ids<O: IdVisitingOperation>(&self, operation: &mut O) {
let mut id_visitor = IdVisitor::new(operation);
self.visit(&mut id_visitor);
}
pub fn compute_id_range(&self) -> IdRange {
let mut visitor = IdRangeComputingVisitor::new();
self.visit_ids(&mut visitor);
visitor.result()
}
}

View File

@ -1,23 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
pub mod common;
pub mod tyencode;
pub mod tydecode;
pub mod encoder;
pub mod decoder;
pub mod creader;
pub mod cstore;
pub mod index;
pub mod loader;
pub mod filesearch;
pub mod macro_import;
pub mod inline;
pub mod util;

View File

@ -16,7 +16,7 @@ use self::EvalHint::*;
use front::map as ast_map;
use front::map::blocks::FnLikeNode;
use metadata::util::{self as mdutil, CrateStore, InlinedItem};
use middle::cstore::{self, CrateStore, InlinedItem};
use middle::{def, infer, subst, traits};
use middle::def_id::DefId;
use middle::pat_util::def_to_path;
@ -145,11 +145,11 @@ pub fn lookup_const_by_id<'a, 'tcx: 'a>(tcx: &'a ty::ctxt<'tcx>,
}
let mut used_ref_id = false;
let expr_id = match tcx.sess.cstore.maybe_get_item_ast(tcx, def_id) {
mdutil::FoundAst::Found(&InlinedItem::Item(ref item)) => match item.node {
cstore::FoundAst::Found(&InlinedItem::Item(ref item)) => match item.node {
hir::ItemConst(_, ref const_expr) => Some(const_expr.id),
_ => None
},
mdutil::FoundAst::Found(&InlinedItem::TraitItem(trait_id, ref ti)) => match ti.node {
cstore::FoundAst::Found(&InlinedItem::TraitItem(trait_id, ref ti)) => match ti.node {
hir::ConstTraitItem(_, _) => {
used_ref_id = true;
match maybe_ref_id {
@ -168,7 +168,7 @@ pub fn lookup_const_by_id<'a, 'tcx: 'a>(tcx: &'a ty::ctxt<'tcx>,
}
_ => None
},
mdutil::FoundAst::Found(&InlinedItem::ImplItem(_, ref ii)) => match ii.node {
cstore::FoundAst::Found(&InlinedItem::ImplItem(_, ref ii)) => match ii.node {
hir::ImplItemKind::Const(_, ref expr) => Some(expr.id),
_ => None
},
@ -200,8 +200,8 @@ fn inline_const_fn_from_external_crate(tcx: &ty::ctxt, def_id: DefId)
}
let fn_id = match tcx.sess.cstore.maybe_get_item_ast(tcx, def_id) {
mdutil::FoundAst::Found(&InlinedItem::Item(ref item)) => Some(item.id),
mdutil::FoundAst::Found(&InlinedItem::ImplItem(_, ref item)) => Some(item.id),
cstore::FoundAst::Found(&InlinedItem::Item(ref item)) => Some(item.id),
cstore::FoundAst::Found(&InlinedItem::ImplItem(_, ref item)) => Some(item.id),
_ => None
};
tcx.extern_const_fns.borrow_mut().insert(def_id,

View File

@ -0,0 +1,277 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// the rustc crate store interface. This also includes types that
// are *mostly* used as a part of that interface, but these should
// probably get a better home if someone can find one.
use back::svh::Svh;
use front::map as hir_map;
use middle::def;
use middle::lang_items;
use middle::ty::{self, Ty};
use middle::def_id::{DefId, DefIndex};
use session::Session;
use session::search_paths::PathKind;
use util::nodemap::{FnvHashMap, NodeMap, NodeSet};
use std::any::Any;
use std::cell::RefCell;
use std::rc::Rc;
use std::path::PathBuf;
use syntax::ast;
use syntax::ast_util::{IdVisitingOperation};
use syntax::attr;
use syntax::codemap::Span;
use syntax::ptr::P;
use rustc_back::target::Target;
use rustc_front::hir;
use rustc_front::visit::Visitor;
use rustc_front::util::IdVisitor;
pub use self::DefLike::{DlDef, DlField, DlImpl};
pub use self::NativeLibraryKind::{NativeStatic, NativeFramework, NativeUnknown};
// lonely orphan structs and enums looking for a better home
#[derive(Clone, Debug)]
pub struct LinkMeta {
pub crate_name: String,
pub crate_hash: Svh,
}
// Where a crate came from on the local filesystem. One of these two options
// must be non-None.
#[derive(PartialEq, Clone, Debug)]
pub struct CrateSource {
pub dylib: Option<(PathBuf, PathKind)>,
pub rlib: Option<(PathBuf, PathKind)>,
pub cnum: ast::CrateNum,
}
#[derive(Copy, Debug, PartialEq, Clone)]
pub enum LinkagePreference {
RequireDynamic,
RequireStatic,
}
enum_from_u32! {
#[derive(Copy, Clone, PartialEq)]
pub enum NativeLibraryKind {
NativeStatic, // native static library (.a archive)
NativeFramework, // OSX-specific
NativeUnknown, // default way to specify a dynamic library
}
}
// Something that a name can resolve to.
#[derive(Copy, Clone, Debug)]
pub enum DefLike {
DlDef(def::Def),
DlImpl(DefId),
DlField
}
/// The data we save and restore about an inlined item or method. This is not
/// part of the AST that we parse from a file, but it becomes part of the tree
/// that we trans.
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub enum InlinedItem {
Item(P<hir::Item>),
TraitItem(DefId /* impl id */, P<hir::TraitItem>),
ImplItem(DefId /* impl id */, P<hir::ImplItem>),
Foreign(P<hir::ForeignItem>),
}
/// A borrowed version of `hir::InlinedItem`.
pub enum InlinedItemRef<'a> {
Item(&'a hir::Item),
TraitItem(DefId, &'a hir::TraitItem),
ImplItem(DefId, &'a hir::ImplItem),
Foreign(&'a hir::ForeignItem)
}
/// Item definitions in the currently-compiled crate would have the CrateNum
/// LOCAL_CRATE in their DefId.
pub const LOCAL_CRATE: ast::CrateNum = 0;
pub struct ChildItem {
pub def: DefLike,
pub name: ast::Name,
pub vis: hir::Visibility
}
pub enum FoundAst<'ast> {
Found(&'ast InlinedItem),
FoundParent(DefId, &'ast InlinedItem),
NotFound,
}
pub trait CrateStore<'tcx> : Any {
// item info
fn stability(&self, def: DefId) -> Option<attr::Stability>;
fn closure_kind(&self, tcx: &ty::ctxt<'tcx>, def_id: DefId)
-> ty::ClosureKind;
fn closure_ty(&self, tcx: &ty::ctxt<'tcx>, def_id: DefId)
-> ty::ClosureTy<'tcx>;
fn item_variances(&self, def: DefId) -> ty::ItemVariances;
fn repr_attrs(&self, def: DefId) -> Vec<attr::ReprAttr>;
fn item_type(&self, tcx: &ty::ctxt<'tcx>, def: DefId)
-> ty::TypeScheme<'tcx>;
fn item_path(&self, def: DefId) -> Vec<hir_map::PathElem>;
fn item_name(&self, def: DefId) -> ast::Name;
fn item_predicates(&self, tcx: &ty::ctxt<'tcx>, def: DefId)
-> ty::GenericPredicates<'tcx>;
fn item_super_predicates(&self, tcx: &ty::ctxt<'tcx>, def: DefId)
-> ty::GenericPredicates<'tcx>;
fn item_attrs(&self, def_id: DefId) -> Vec<ast::Attribute>;
fn item_symbol(&self, def: DefId) -> String;
fn trait_def(&self, tcx: &ty::ctxt<'tcx>, def: DefId)-> ty::TraitDef<'tcx>;
fn adt_def(&self, tcx: &ty::ctxt<'tcx>, def: DefId) -> ty::AdtDefMaster<'tcx>;
fn method_arg_names(&self, did: DefId) -> Vec<String>;
fn inherent_implementations_for_type(&self, def_id: DefId) -> Vec<DefId>;
// trait info
fn implementations_of_trait(&self, def_id: DefId) -> Vec<DefId>;
fn provided_trait_methods(&self, tcx: &ty::ctxt<'tcx>, def: DefId)
-> Vec<Rc<ty::Method<'tcx>>>;
fn trait_item_def_ids(&self, def: DefId)
-> Vec<ty::ImplOrTraitItemId>;
// impl info
fn impl_items(&self, impl_def_id: DefId) -> Vec<ty::ImplOrTraitItemId>;
fn impl_trait_ref(&self, tcx: &ty::ctxt<'tcx>, def: DefId)
-> Option<ty::TraitRef<'tcx>>;
fn impl_polarity(&self, def: DefId) -> Option<hir::ImplPolarity>;
fn custom_coerce_unsized_kind(&self, def: DefId)
-> Option<ty::adjustment::CustomCoerceUnsized>;
fn associated_consts(&self, tcx: &ty::ctxt<'tcx>, def: DefId)
-> Vec<Rc<ty::AssociatedConst<'tcx>>>;
// trait/impl-item info
fn trait_of_item(&self, tcx: &ty::ctxt<'tcx>, def_id: DefId)
-> Option<DefId>;
fn impl_or_trait_item(&self, tcx: &ty::ctxt<'tcx>, def: DefId)
-> ty::ImplOrTraitItem<'tcx>;
// flags
fn is_const_fn(&self, did: DefId) -> bool;
fn is_defaulted_trait(&self, did: DefId) -> bool;
fn is_impl(&self, did: DefId) -> bool;
fn is_default_impl(&self, impl_did: DefId) -> bool;
fn is_extern_fn(&self, tcx: &ty::ctxt<'tcx>, did: DefId) -> bool;
fn is_static(&self, did: DefId) -> bool;
fn is_static_method(&self, did: DefId) -> bool;
fn is_statically_included_foreign_item(&self, id: ast::NodeId) -> bool;
fn is_typedef(&self, did: DefId) -> bool;
// crate metadata
fn dylib_dependency_formats(&self, cnum: ast::CrateNum)
-> Vec<(ast::CrateNum, LinkagePreference)>;
fn lang_items(&self, cnum: ast::CrateNum) -> Vec<(DefIndex, usize)>;
fn missing_lang_items(&self, cnum: ast::CrateNum) -> Vec<lang_items::LangItem>;
fn is_staged_api(&self, cnum: ast::CrateNum) -> bool;
fn is_explicitly_linked(&self, cnum: ast::CrateNum) -> bool;
fn is_allocator(&self, cnum: ast::CrateNum) -> bool;
fn crate_attrs(&self, cnum: ast::CrateNum) -> Vec<ast::Attribute>;
fn crate_name(&self, cnum: ast::CrateNum) -> String;
fn crate_hash(&self, cnum: ast::CrateNum) -> Svh;
fn crate_struct_field_attrs(&self, cnum: ast::CrateNum)
-> FnvHashMap<DefId, Vec<ast::Attribute>>;
fn plugin_registrar_fn(&self, cnum: ast::CrateNum) -> Option<DefId>;
fn native_libraries(&self, cnum: ast::CrateNum) -> Vec<(NativeLibraryKind, String)>;
fn reachable_ids(&self, cnum: ast::CrateNum) -> Vec<DefId>;
// resolve
fn def_path(&self, def: DefId) -> hir_map::DefPath;
fn tuple_struct_definition_if_ctor(&self, did: DefId) -> Option<DefId>;
fn struct_field_names(&self, def: DefId) -> Vec<ast::Name>;
fn item_children(&self, did: DefId) -> Vec<ChildItem>;
fn crate_top_level_items(&self, cnum: ast::CrateNum) -> Vec<ChildItem>;
// misc. metadata
fn maybe_get_item_ast(&'tcx self, tcx: &ty::ctxt<'tcx>, def: DefId)
-> FoundAst<'tcx>;
// This is basically a 1-based range of ints, which is a little
// silly - I may fix that.
fn crates(&self) -> Vec<ast::CrateNum>;
fn used_libraries(&self) -> Vec<(String, NativeLibraryKind)>;
fn used_link_args(&self) -> Vec<String>;
// utility functions
fn metadata_filename(&self) -> &str;
fn metadata_section_name(&self, target: &Target) -> &str;
fn encode_type(&self, tcx: &ty::ctxt<'tcx>, ty: Ty<'tcx>) -> Vec<u8>;
fn used_crates(&self, prefer: LinkagePreference) -> Vec<(ast::CrateNum, Option<PathBuf>)>;
fn used_crate_source(&self, cnum: ast::CrateNum) -> CrateSource;
fn extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) -> Option<ast::CrateNum>;
fn encode_metadata(&self,
tcx: &ty::ctxt<'tcx>,
reexports: &def::ExportMap,
item_symbols: &RefCell<NodeMap<String>>,
link_meta: &LinkMeta,
reachable: &NodeSet,
krate: &hir::Crate) -> Vec<u8>;
fn metadata_encoding_version(&self) -> &[u8];
}
impl InlinedItem {
pub fn visit<'ast,V>(&'ast self, visitor: &mut V)
where V: Visitor<'ast>
{
match *self {
InlinedItem::Item(ref i) => visitor.visit_item(&**i),
InlinedItem::Foreign(ref i) => visitor.visit_foreign_item(&**i),
InlinedItem::TraitItem(_, ref ti) => visitor.visit_trait_item(ti),
InlinedItem::ImplItem(_, ref ii) => visitor.visit_impl_item(ii),
}
}
pub fn visit_ids<O: IdVisitingOperation>(&self, operation: &mut O) {
let mut id_visitor = IdVisitor {
operation: operation,
pass_through_items: true,
visited_outermost: false,
};
self.visit(&mut id_visitor);
}
}
// FIXME: find a better place for this?
pub fn validate_crate_name(sess: Option<&Session>, s: &str, sp: Option<Span>) {
let say = |s: &str| {
match (sp, sess) {
(_, None) => panic!("{}", s),
(Some(sp), Some(sess)) => sess.span_err(sp, s),
(None, Some(sess)) => sess.err(s),
}
};
if s.is_empty() {
say("crate name must not be empty");
}
for c in s.chars() {
if c.is_alphanumeric() { continue }
if c == '_' { continue }
say(&format!("invalid character `{}` in crate name: `{}`", c, s));
}
match sess {
Some(sess) => sess.abort_if_errors(),
None => {}
}
}

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use metadata::cstore::LOCAL_CRATE;
use middle::cstore::LOCAL_CRATE;
use middle::ty;
use syntax::ast::CrateNum;
use std::fmt;

View File

@ -65,8 +65,8 @@ use syntax::ast;
use session;
use session::config;
use metadata::util::CrateStore;
use metadata::util::LinkagePreference::{self, RequireStatic, RequireDynamic};
use middle::cstore::CrateStore;
use middle::cstore::LinkagePreference::{self, RequireStatic, RequireDynamic};
use util::nodemap::FnvHashMap;
/// A list of dependencies for a certain crate type.

View File

@ -76,7 +76,7 @@ use front::map as ast_map;
use rustc_front::hir;
use rustc_front::print::pprust;
use metadata::util::CrateStore;
use middle::cstore::CrateStore;
use middle::def;
use middle::def_id::DefId;
use middle::infer::{self, TypeOrigin};

View File

@ -23,7 +23,7 @@ pub use self::LangItem::*;
use front::map as hir_map;
use session::Session;
use metadata::util::CrateStore;
use middle::cstore::CrateStore;
use middle::def_id::DefId;
use middle::ty;
use middle::weak_lang_items;

View File

@ -16,10 +16,10 @@
//! Most of the documentation on regions can be found in
//! `middle/typeck/infer/region_inference.rs`
use metadata::inline::InlinedItem;
use front::map as ast_map;
use session::Session;
use util::nodemap::{FnvHashMap, NodeMap, NodeSet};
use middle::cstore::InlinedItem;
use middle::ty::{self, Ty};
use std::cell::RefCell;

View File

@ -15,8 +15,7 @@ pub use self::StabilityLevel::*;
use session::Session;
use lint;
use metadata::cstore::LOCAL_CRATE;
use metadata::util::CrateStore;
use middle::cstore::{CrateStore, LOCAL_CRATE};
use middle::def;
use middle::def_id::{CRATE_DEF_INDEX, DefId};
use middle::ty;

View File

@ -17,7 +17,7 @@ use super::PredicateObligation;
use super::project;
use super::util;
use metadata::cstore::LOCAL_CRATE;
use middle::cstore::LOCAL_CRATE;
use middle::def_id::DefId;
use middle::subst::{Subst, Substs, TypeSpace};
use middle::ty::{self, Ty};

View File

@ -16,8 +16,8 @@
use front::map as ast_map;
use session::Session;
use lint;
use metadata::util::CrateStore;
use middle;
use middle::cstore::CrateStore;
use middle::def::DefMap;
use middle::def_id::DefId;
use middle::free_region::FreeRegionMap;

View File

@ -21,9 +21,8 @@ pub use self::LvaluePreference::*;
use front::map as ast_map;
use front::map::LinkedPath;
use metadata::cstore::LOCAL_CRATE;
use metadata::util::CrateStore;
use middle;
use middle::cstore::{CrateStore, LOCAL_CRATE};
use middle::def::{self, ExportMap};
use middle::def_id::DefId;
use middle::lang_items::{FnTraitLangItem, FnMutTraitLangItem, FnOnceTraitLangItem};

View File

@ -12,7 +12,7 @@
use session::config;
use session::Session;
use metadata::util::CrateStore;
use middle::cstore::CrateStore;
use middle::lang_items;
use syntax::ast;

View File

@ -22,7 +22,7 @@ use session::search_paths::SearchPaths;
use rustc_back::target::Target;
use lint;
use metadata::cstore;
use middle::cstore;
use syntax::ast::{self, IntTy, UintTy};
use syntax::attr;

View File

@ -9,8 +9,7 @@
// except according to those terms.
use lint;
use metadata::filesearch;
use metadata::util::CrateStore;
use middle::cstore::CrateStore;
use middle::dependency_format;
use session::search_paths::PathKind;
use util::nodemap::{NodeMap, FnvHashMap};
@ -34,6 +33,7 @@ use std::env;
use std::rc::Rc;
pub mod config;
pub mod filesearch;
pub mod search_paths;
// Represents the data associated with a compilation

View File

@ -16,9 +16,6 @@ use rustc::session::Session;
use rustc::session::config::{self, Input, OutputFilenames, OutputType};
use rustc::session::search_paths::PathKind;
use rustc::lint;
use rustc::metadata;
use rustc::metadata::creader::LocalCrateReader;
use rustc::metadata::cstore::CStore;
use rustc::middle::{stability, ty, reachable};
use rustc::middle::dependency_format;
use rustc::middle;
@ -26,6 +23,9 @@ use rustc::util::nodemap::NodeMap;
use rustc::util::common::time;
use rustc_borrowck as borrowck;
use rustc_resolve as resolve;
use rustc_metadata::macro_import;
use rustc_metadata::creader::LocalCrateReader;
use rustc_metadata::cstore::CStore;
use rustc_trans::back::link;
use rustc_trans::back::write;
use rustc_trans::trans;
@ -482,7 +482,7 @@ pub fn phase_2_configure_and_expand(sess: &Session,
let macros = time(time_passes,
"macro loading",
|| metadata::macro_import::read_macro_defs(sess, &cstore, &krate));
|| macro_import::read_macro_defs(sess, &cstore, &krate));
let mut addl_plugins = Some(addl_plugins);
let registrars = time(time_passes, "plugin loading", || {

View File

@ -47,6 +47,7 @@ extern crate rustc_front;
extern crate rustc_lint;
extern crate rustc_plugin;
extern crate rustc_privacy;
extern crate rustc_metadata;
extern crate rustc_mir;
extern crate rustc_resolve;
extern crate rustc_trans;
@ -68,11 +69,11 @@ use rustc_trans::back::link;
use rustc_trans::save;
use rustc::session::{config, Session, build_session};
use rustc::session::config::{Input, PrintRequest, OutputType};
use rustc::middle::cstore::CrateStore;
use rustc::lint::Lint;
use rustc::lint;
use rustc::metadata;
use rustc::metadata::cstore::CStore;
use rustc::metadata::util::CrateStore;
use rustc_metadata::loader;
use rustc_metadata::cstore::CStore;
use rustc::util::common::time;
use std::cmp::Ordering::Equal;
@ -448,7 +449,7 @@ impl RustcDefaultCalls {
&Input::File(ref ifile) => {
let path = &(*ifile);
let mut v = Vec::new();
metadata::loader::list_file_metadata(&sess.target.target, path, &mut v)
loader::list_file_metadata(&sess.target.target, path, &mut v)
.unwrap();
println!("{}", String::from_utf8(v).unwrap());
}

View File

@ -19,7 +19,6 @@ use rustc_trans::back::link;
use driver;
use rustc::metadata::cstore::CStore;
use rustc::middle::ty;
use rustc::middle::cfg;
use rustc::middle::cfg::graphviz::LabelledCFG;
@ -28,6 +27,7 @@ use rustc::session::config::Input;
use rustc_borrowck as borrowck;
use rustc_borrowck::graphviz as borrowck_dot;
use rustc_resolve as resolve;
use rustc_metadata::cstore::CStore;
use syntax::ast;
use syntax::codemap;

View File

@ -29,11 +29,11 @@
//! a `pub fn new()`.
use middle::{cfg, def, infer, stability, traits};
use middle::cstore::CrateStore;
use middle::def_id::DefId;
use middle::subst::Substs;
use middle::ty::{self, Ty};
use middle::ty::adjustment;
use rustc::metadata::util::CrateStore;
use rustc::front::map as hir_map;
use util::nodemap::{NodeSet};
use lint::{Level, LateContext, LintContext, LintArray, Lint};

View File

@ -50,7 +50,6 @@ extern crate rustc_front;
extern crate rustc_back;
pub use rustc::lint as lint;
pub use rustc::metadata as metadata;
pub use rustc::middle as middle;
pub use rustc::session as session;
pub use rustc::util as util;

View File

@ -12,19 +12,21 @@
// FIXME: remove this after snapshot, and Results are handled
#![allow(unused_must_use)]
use front::map as ast_map;
use rustc::front::map as ast_map;
use rustc::session::Session;
use rustc_front::hir;
use rustc_front::fold;
use rustc_front::fold::Folder;
use metadata::common as c;
use metadata::cstore as cstore;
use session::Session;
use metadata::decoder;
use metadata::encoder as e;
use metadata::inline::{InlinedItem, InlinedItemRef};
use metadata::tydecode;
use metadata::tyencode;
use common as c;
use cstore;
use decoder;
use encoder as e;
use tydecode;
use tyencode;
use middle::cstore::{InlinedItem, InlinedItemRef};
use middle::ty::adjustment;
use middle::ty::cast;
use middle::check_const::ConstQualif;
@ -89,7 +91,7 @@ pub fn encode_inlined_item(ecx: &e::EncodeContext,
// Folding could be avoided with a smarter encoder.
let ii = simplify_ast(ii);
let id_range = ii.compute_id_range();
let id_range = inlined_item_id_range(&ii);
rbml_w.start_tag(c::tag_ast as usize);
id_range.encode(rbml_w);
@ -1326,6 +1328,12 @@ fn copy_item_types(dcx: &DecodeContext, ii: &InlinedItem, orig_did: DefId) {
}
}
fn inlined_item_id_range(v: &InlinedItem) -> ast_util::IdRange {
let mut visitor = ast_util::IdRangeComputingVisitor::new();
v.visit_ids(&mut visitor);
visitor.result()
}
// ______________________________________________________________________
// Testing of astencode_gen

View File

@ -12,8 +12,6 @@
pub use self::astencode_tag::*;
use back::svh::Svh;
// RBML enum definitions and utils shared by the encoder and decoder
//
// 0x00..0x1f: reserved for RBML generic type tags
@ -191,12 +189,6 @@ pub const tag_items_data_item_stability: usize = 0x88;
pub const tag_items_data_item_repr: usize = 0x89;
#[derive(Clone, Debug)]
pub struct LinkMeta {
pub crate_name: String,
pub crate_hash: Svh,
}
pub const tag_struct_fields: usize = 0x10d; // top-level only
pub const tag_struct_field: usize = 0x8a;

View File

@ -12,17 +12,17 @@
//! Validates all used crates and extern libraries and loads their metadata
use back::svh::Svh;
use session::{config, Session};
use session::search_paths::PathKind;
use metadata::common::rustc_version;
use metadata::cstore;
use metadata::cstore::{CStore, CrateSource, MetadataBlob};
use metadata::decoder;
use metadata::loader;
use metadata::loader::CratePaths;
use util::nodemap::FnvHashMap;
use front::map as hir_map;
use common::rustc_version;
use cstore::{self, CStore, CrateSource, MetadataBlob};
use decoder;
use loader::{self, CratePaths};
use rustc::back::svh::Svh;
use rustc::session::{config, Session};
use rustc::session::search_paths::PathKind;
use rustc::middle::cstore::validate_crate_name;
use rustc::util::nodemap::FnvHashMap;
use rustc::front::map as hir_map;
use std::cell::{RefCell, Cell};
use std::path::PathBuf;
@ -91,29 +91,6 @@ struct CrateInfo {
should_link: bool,
}
pub fn validate_crate_name(sess: Option<&Session>, s: &str, sp: Option<Span>) {
let say = |s: &str| {
match (sp, sess) {
(_, None) => panic!("{}", s),
(Some(sp), Some(sess)) => sess.span_err(sp, s),
(None, Some(sess)) => sess.err(s),
}
};
if s.is_empty() {
say("crate name must not be empty");
}
for c in s.chars() {
if c.is_alphanumeric() { continue }
if c == '_' { continue }
say(&format!("invalid character `{}` in crate name: `{}`", c, s));
}
match sess {
Some(sess) => sess.abort_if_errors(),
None => {}
}
}
fn register_native_lib(sess: &Session,
cstore: &CStore,
span: Option<Span>,

View File

@ -8,160 +8,31 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use back::svh::Svh;
use front::map as ast_map;
use metadata::cstore;
use metadata::decoder;
use metadata::encoder;
use metadata::loader;
use middle::astencode;
use astencode;
use cstore;
use decoder;
use encoder;
use loader;
use middle::cstore::{CrateStore, CrateSource, ChildItem, FoundAst};
use middle::cstore::{NativeLibraryKind, LinkMeta, LinkagePreference};
use middle::def;
use middle::lang_items;
use middle::ty::{self, Ty};
use middle::def_id::{DefId, DefIndex};
use util::nodemap::{FnvHashMap, NodeMap, NodeSet};
use std::any::Any;
use rustc::front::map as ast_map;
use rustc::util::nodemap::{FnvHashMap, NodeMap, NodeSet};
use std::cell::RefCell;
use std::rc::Rc;
use std::path::PathBuf;
use syntax::ast;
use syntax::attr;
use rustc_back::svh::Svh;
use rustc_back::target::Target;
use rustc_front::hir;
pub use metadata::common::LinkMeta;
pub use metadata::creader::validate_crate_name;
pub use metadata::cstore::CrateSource;
pub use metadata::cstore::LinkagePreference;
pub use metadata::cstore::NativeLibraryKind;
pub use metadata::decoder::DecodeInlinedItem;
pub use metadata::decoder::DefLike;
pub use metadata::inline::InlinedItem;
pub use self::DefLike::{DlDef, DlField, DlImpl};
pub use self::NativeLibraryKind::{NativeStatic, NativeFramework, NativeUnknown};
pub struct ChildItem {
pub def: DefLike,
pub name: ast::Name,
pub vis: hir::Visibility
}
pub enum FoundAst<'ast> {
Found(&'ast InlinedItem),
FoundParent(DefId, &'ast InlinedItem),
NotFound,
}
pub trait CrateStore<'tcx> : Any {
// item info
fn stability(&self, def: DefId) -> Option<attr::Stability>;
fn closure_kind(&self, tcx: &ty::ctxt<'tcx>, def_id: DefId)
-> ty::ClosureKind;
fn closure_ty(&self, tcx: &ty::ctxt<'tcx>, def_id: DefId)
-> ty::ClosureTy<'tcx>;
fn item_variances(&self, def: DefId) -> ty::ItemVariances;
fn repr_attrs(&self, def: DefId) -> Vec<attr::ReprAttr>;
fn item_type(&self, tcx: &ty::ctxt<'tcx>, def: DefId)
-> ty::TypeScheme<'tcx>;
fn item_path(&self, def: DefId) -> Vec<ast_map::PathElem>;
fn item_name(&self, def: DefId) -> ast::Name;
fn item_predicates(&self, tcx: &ty::ctxt<'tcx>, def: DefId)
-> ty::GenericPredicates<'tcx>;
fn item_super_predicates(&self, tcx: &ty::ctxt<'tcx>, def: DefId)
-> ty::GenericPredicates<'tcx>;
fn item_attrs(&self, def_id: DefId) -> Vec<ast::Attribute>;
fn item_symbol(&self, def: DefId) -> String;
fn trait_def(&self, tcx: &ty::ctxt<'tcx>, def: DefId)-> ty::TraitDef<'tcx>;
fn adt_def(&self, tcx: &ty::ctxt<'tcx>, def: DefId) -> ty::AdtDefMaster<'tcx>;
fn method_arg_names(&self, did: DefId) -> Vec<String>;
fn inherent_implementations_for_type(&self, def_id: DefId) -> Vec<DefId>;
// trait info
fn implementations_of_trait(&self, def_id: DefId) -> Vec<DefId>;
fn provided_trait_methods(&self, tcx: &ty::ctxt<'tcx>, def: DefId)
-> Vec<Rc<ty::Method<'tcx>>>;
fn trait_item_def_ids(&self, def: DefId)
-> Vec<ty::ImplOrTraitItemId>;
// impl info
fn impl_items(&self, impl_def_id: DefId) -> Vec<ty::ImplOrTraitItemId>;
fn impl_trait_ref(&self, tcx: &ty::ctxt<'tcx>, def: DefId)
-> Option<ty::TraitRef<'tcx>>;
fn impl_polarity(&self, def: DefId) -> Option<hir::ImplPolarity>;
fn custom_coerce_unsized_kind(&self, def: DefId)
-> Option<ty::adjustment::CustomCoerceUnsized>;
fn associated_consts(&self, tcx: &ty::ctxt<'tcx>, def: DefId)
-> Vec<Rc<ty::AssociatedConst<'tcx>>>;
// trait/impl-item info
fn trait_of_item(&self, tcx: &ty::ctxt<'tcx>, def_id: DefId)
-> Option<DefId>;
fn impl_or_trait_item(&self, tcx: &ty::ctxt<'tcx>, def: DefId)
-> ty::ImplOrTraitItem<'tcx>;
// flags
fn is_const_fn(&self, did: DefId) -> bool;
fn is_defaulted_trait(&self, did: DefId) -> bool;
fn is_impl(&self, did: DefId) -> bool;
fn is_default_impl(&self, impl_did: DefId) -> bool;
fn is_extern_fn(&self, tcx: &ty::ctxt<'tcx>, did: DefId) -> bool;
fn is_static(&self, did: DefId) -> bool;
fn is_static_method(&self, did: DefId) -> bool;
fn is_statically_included_foreign_item(&self, id: ast::NodeId) -> bool;
fn is_typedef(&self, did: DefId) -> bool;
// crate metadata
fn dylib_dependency_formats(&self, cnum: ast::CrateNum)
-> Vec<(ast::CrateNum, LinkagePreference)>;
fn lang_items(&self, cnum: ast::CrateNum) -> Vec<(DefIndex, usize)>;
fn missing_lang_items(&self, cnum: ast::CrateNum) -> Vec<lang_items::LangItem>;
fn is_staged_api(&self, cnum: ast::CrateNum) -> bool;
fn is_explicitly_linked(&self, cnum: ast::CrateNum) -> bool;
fn is_allocator(&self, cnum: ast::CrateNum) -> bool;
fn crate_attrs(&self, cnum: ast::CrateNum) -> Vec<ast::Attribute>;
fn crate_name(&self, cnum: ast::CrateNum) -> String;
fn crate_hash(&self, cnum: ast::CrateNum) -> Svh;
fn crate_struct_field_attrs(&self, cnum: ast::CrateNum)
-> FnvHashMap<DefId, Vec<ast::Attribute>>;
fn plugin_registrar_fn(&self, cnum: ast::CrateNum) -> Option<DefId>;
fn native_libraries(&self, cnum: ast::CrateNum) -> Vec<(NativeLibraryKind, String)>;
fn reachable_ids(&self, cnum: ast::CrateNum) -> Vec<DefId>;
// resolve
fn def_path(&self, def: DefId) -> ast_map::DefPath;
fn tuple_struct_definition_if_ctor(&self, did: DefId) -> Option<DefId>;
fn struct_field_names(&self, def: DefId) -> Vec<ast::Name>;
fn item_children(&self, did: DefId) -> Vec<ChildItem>;
fn crate_top_level_items(&self, cnum: ast::CrateNum) -> Vec<ChildItem>;
// misc. metadata
fn maybe_get_item_ast(&'tcx self, tcx: &ty::ctxt<'tcx>, def: DefId)
-> FoundAst<'tcx>;
// This is basically a 1-based range of ints, which is a little
// silly - I may fix that.
fn crates(&self) -> Vec<ast::CrateNum>;
fn used_libraries(&self) -> Vec<(String, NativeLibraryKind)>;
fn used_link_args(&self) -> Vec<String>;
// utility functions
fn metadata_filename(&self) -> &str;
fn metadata_section_name(&self, target: &Target) -> &str;
fn encode_type(&self, tcx: &ty::ctxt<'tcx>, ty: Ty<'tcx>) -> Vec<u8>;
fn used_crates(&self, prefer: LinkagePreference) -> Vec<(ast::CrateNum, Option<PathBuf>)>;
fn used_crate_source(&self, cnum: ast::CrateNum) -> CrateSource;
fn extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) -> Option<ast::CrateNum>;
fn encode_metadata(&self,
tcx: &ty::ctxt<'tcx>,
reexports: &def::ExportMap,
item_symbols: &RefCell<NodeMap<String>>,
link_meta: &LinkMeta,
reachable: &NodeSet,
krate: &hir::Crate) -> Vec<u8>;
fn metadata_encoding_version(&self) -> &[u8];
}
impl<'tcx> CrateStore<'tcx> for cstore::CStore {
fn stability(&self, def: DefId) -> Option<attr::Stability>
{

View File

@ -14,13 +14,15 @@
// crates and libraries
pub use self::MetadataBlob::*;
pub use self::LinkagePreference::*;
pub use self::NativeLibraryKind::*;
use back::svh::Svh;
use metadata::{creader, decoder, index, loader};
use session::search_paths::PathKind;
use util::nodemap::{FnvHashMap, NodeMap, NodeSet};
use creader;
use decoder;
use index;
use loader;
use rustc::back::svh::Svh;
use rustc::front::map as ast_map;
use rustc::util::nodemap::{FnvHashMap, NodeMap, NodeSet};
use std::cell::{RefCell, Ref, Cell};
use std::rc::Rc;
@ -32,7 +34,10 @@ use syntax::codemap;
use syntax::parse::token;
use syntax::parse::token::IdentInterner;
use syntax::util::small_vector::SmallVector;
use front::map as ast_map;
pub use middle::cstore::{NativeLibraryKind, LinkagePreference};
pub use middle::cstore::{NativeStatic, NativeFramework, NativeUnknown};
pub use middle::cstore::{CrateSource, LinkMeta};
// A map from external crate numbers (as decoded from some crate file) to
// local crate numbers (as generated during this session). Each external
@ -77,30 +82,6 @@ pub struct crate_metadata {
pub explicitly_linked: Cell<bool>,
}
#[derive(Copy, Debug, PartialEq, Clone)]
pub enum LinkagePreference {
RequireDynamic,
RequireStatic,
}
enum_from_u32! {
#[derive(Copy, Clone, PartialEq)]
pub enum NativeLibraryKind {
NativeStatic, // native static library (.a archive)
NativeFramework, // OSX-specific
NativeUnknown, // default way to specify a dynamic library
}
}
// Where a crate came from on the local filesystem. One of these two options
// must be non-None.
#[derive(PartialEq, Clone, Debug)]
pub struct CrateSource {
pub dylib: Option<(PathBuf, PathKind)>,
pub rlib: Option<(PathBuf, PathKind)>,
pub cnum: ast::CrateNum,
}
pub struct CStore {
metas: RefCell<FnvHashMap<ast::CrateNum, Rc<crate_metadata>>>,
/// Map from NodeId's of local extern crate statements to crate numbers
@ -112,10 +93,6 @@ pub struct CStore {
pub intr: Rc<IdentInterner>,
}
/// Item definitions in the currently-compiled crate would have the CrateNum
/// LOCAL_CRATE in their DefId.
pub const LOCAL_CRATE: ast::CrateNum = 0;
impl CStore {
pub fn new(intr: Rc<IdentInterner>) -> CStore {
CStore {
@ -218,8 +195,8 @@ impl CStore {
let mut libs = self.used_crate_sources.borrow()
.iter()
.map(|src| (src.cnum, match prefer {
RequireDynamic => src.dylib.clone().map(|p| p.0),
RequireStatic => src.rlib.clone().map(|p| p.0),
LinkagePreference::RequireDynamic => src.dylib.clone().map(|p| p.0),
LinkagePreference::RequireStatic => src.rlib.clone().map(|p| p.0),
}))
.collect::<Vec<_>>();
libs.sort_by(|&(a, _), &(b, _)| {

View File

@ -12,29 +12,27 @@
#![allow(non_camel_case_types)]
pub use self::DefLike::*;
use self::Family::*;
use front::map as hir_map;
use cstore::{self, crate_metadata};
use common::*;
use encoder::def_to_u64;
use index;
use tydecode::TyDecoder;
use rustc::back::svh::Svh;
use rustc::front::map as hir_map;
use rustc::util::nodemap::FnvHashMap;
use rustc_front::hir;
use back::svh::Svh;
use metadata::cstore::crate_metadata;
use metadata::cstore::LOCAL_CRATE;
use metadata::common::*;
use metadata::cstore;
use metadata::encoder::def_to_u64;
use metadata::index;
use metadata::inline::InlinedItem;
use metadata::tydecode::TyDecoder;
use metadata::util::FoundAst;
use middle::cstore::{LOCAL_CRATE, FoundAst, InlinedItem, LinkagePreference};
use middle::cstore::{DefLike, DlDef, DlField, DlImpl};
use middle::def;
use middle::def_id::{DefId, DefIndex};
use middle::lang_items;
use middle::subst;
use middle::ty::{ImplContainer, TraitContainer};
use middle::ty::{self, RegionEscape, Ty};
use util::nodemap::FnvHashMap;
use std::cell::{Cell, RefCell};
use std::io::prelude::*;
@ -590,14 +588,6 @@ pub fn get_symbol_from_buf(data: &[u8], id: DefIndex) -> String {
item_symbol(doc)
}
// Something that a name can resolve to.
#[derive(Copy, Clone, Debug)]
pub enum DefLike {
DlDef(def::Def),
DlImpl(DefId),
DlField
}
/// Iterates over the language items in the given crate.
pub fn each_lang_item<F>(cdata: Cmd, mut f: F) -> bool where
F: FnMut(DefIndex, usize) -> bool,
@ -1315,7 +1305,7 @@ pub fn each_exported_macro<F>(data: &[u8], intr: &IdentInterner, mut f: F) where
}
pub fn get_dylib_dependency_formats(cdata: Cmd)
-> Vec<(ast::CrateNum, cstore::LinkagePreference)>
-> Vec<(ast::CrateNum, LinkagePreference)>
{
let formats = reader::get_doc(rbml::Doc::new(cdata.data()),
tag_dylib_dependency_formats);
@ -1332,9 +1322,9 @@ pub fn get_dylib_dependency_formats(cdata: Cmd)
None => panic!("didn't find a crate in the cnum_map")
};
result.push((cnum, if link == "d" {
cstore::RequireDynamic
LinkagePreference::RequireDynamic
} else {
cstore::RequireStatic
LinkagePreference::RequireStatic
}));
}
return result;

View File

@ -0,0 +1,77 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![allow(non_snake_case)]
register_long_diagnostics! {
E0454: r##"
A link name was given with an empty name. Erroneous code example:
```
#[link(name = "")] extern {} // error: #[link(name = "")] given with empty name
```
The rust compiler cannot link to an external library if you don't give it its
name. Example:
```
#[link(name = "some_lib")] extern {} // ok!
```
"##,
E0458: r##"
An unknown "kind" was specified for a link attribute. Erroneous code example:
```
#[link(kind = "wonderful_unicorn")] extern {}
// error: unknown kind: `wonderful_unicorn`
```
Please specify a valid "kind" value, from one of the following:
* static
* dylib
* framework
"##,
E0459: r##"
A link was used without a name parameter. Erroneous code example:
```
#[link(kind = "dylib")] extern {}
// error: #[link(...)] specified without `name = "foo"`
```
Please add the name parameter to allow the rust compiler to find the library
you want. Example:
```
#[link(kind = "dylib", name = "some_lib")] extern {} // ok!
```
"##,
}
register_diagnostics! {
E0455, // native frameworks are only available on OSX targets
E0456, // plugin `..` is not available for triple `..`
E0457, // plugin `..` only found in rlib format, but must be available...
E0514, // metadata version mismatch
E0460, // found possibly newer version of crate `..`
E0461, // couldn't find crate `..` with expected target triple ..
E0462, // found staticlib `..` instead of rlib or dylib
E0463, // can't find crate for `..`
E0464, // multiple matching crates for `..`
E0465, // multiple .. candidates for `..` found
E0466, // bad macro import
E0467, // bad macro reexport
E0468, // an `extern crate` loading macros must be at the crate root
E0469, // imported macro not found
E0470, // reexported macro not found
}

View File

@ -13,23 +13,25 @@
#![allow(unused_must_use)] // everything is just a MemWriter, can't fail
#![allow(non_camel_case_types)]
use back::svh::Svh;
use session::config;
use metadata::common::*;
use metadata::cstore;
use metadata::cstore::LOCAL_CRATE;
use metadata::decoder;
use metadata::tyencode;
use metadata::index::{self, IndexData};
use metadata::inline::InlinedItemRef;
use metadata::util::CrateStore;
use common::*;
use cstore;
use decoder;
use tyencode;
use index::{self, IndexData};
use middle::cstore::{LOCAL_CRATE, CrateStore, InlinedItemRef, LinkMeta};
use middle::def;
use middle::def_id::{CRATE_DEF_INDEX, DefId};
use middle::dependency_format::Linkage;
use middle::stability;
use middle::subst;
use middle::ty::{self, Ty};
use util::nodemap::{FnvHashMap, NodeMap, NodeSet};
use rustc::back::svh::Svh;
use rustc::front::map::{LinkedPath, PathElem, PathElems};
use rustc::front::map as ast_map;
use rustc::session::config;
use rustc::util::nodemap::{FnvHashMap, NodeMap, NodeSet};
use serialize::Encodable;
use std::cell::RefCell;
@ -49,8 +51,6 @@ use rbml::writer::Encoder;
use rustc_front::hir;
use rustc_front::intravisit::Visitor;
use rustc_front::intravisit;
use front::map::{LinkedPath, PathElem, PathElems};
use front::map as ast_map;
pub type EncodeInlinedItem<'a> =
Box<FnMut(&EncodeContext, &mut Encoder, InlinedItemRef) + 'a>;

View File

@ -0,0 +1,61 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![cfg_attr(stage0, feature(custom_attribute))]
#![crate_name = "rustc_metadata"]
#![unstable(feature = "rustc_private", issue = "27812")]
#![cfg_attr(stage0, staged_api)]
#![crate_type = "dylib"]
#![crate_type = "rlib"]
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
html_root_url = "https://doc.rust-lang.org/nightly/")]
#![feature(box_patterns)]
#![feature(duration_span)]
#![feature(enumset)]
#![feature(quote)]
#![feature(staged_api)]
#![feature(vec_push_all)]
#![feature(rustc_diagnostic_macros)]
#![feature(rustc_private)]
#[macro_use] extern crate log;
#[macro_use] extern crate syntax;
#[macro_use] #[no_link] extern crate rustc_bitflags;
extern crate flate;
extern crate rbml;
extern crate serialize;
extern crate rustc;
extern crate rustc_back;
extern crate rustc_front;
extern crate rustc_llvm;
pub use rustc::middle;
#[macro_use]
mod macros;
pub mod diagnostics;
pub mod astencode;
pub mod common;
pub mod tyencode;
pub mod tydecode;
pub mod encoder;
pub mod decoder;
pub mod creader;
pub mod csearch;
pub mod cstore;
pub mod index;
pub mod loader;
pub mod macro_import;

View File

@ -212,19 +212,21 @@
//! no means all of the necessary details. Take a look at the rest of
//! metadata::loader or metadata::creader for all the juicy details!
use back::svh::Svh;
use session::Session;
use session::search_paths::PathKind;
use llvm;
use llvm::{False, ObjectFile, mk_section_iter};
use llvm::archive_ro::ArchiveRO;
use metadata::cstore::{MetadataBlob, MetadataVec, MetadataArchive};
use metadata::decoder;
use metadata::encoder;
use metadata::filesearch::{FileSearch, FileMatches, FileDoesntMatch};
use cstore::{MetadataBlob, MetadataVec, MetadataArchive};
use decoder;
use encoder;
use rustc::back::svh::Svh;
use rustc::session::Session;
use rustc::session::filesearch::{FileSearch, FileMatches, FileDoesntMatch};
use rustc::session::search_paths::PathKind;
use rustc::util::common;
use rustc_llvm as llvm;
use rustc_llvm::{False, ObjectFile, mk_section_iter};
use rustc_llvm::archive_ro::ArchiveRO;
use syntax::codemap::Span;
use syntax::diagnostic::SpanHandler;
use util::common;
use rustc_back::target::Target;
use std::cmp;

View File

@ -10,9 +10,10 @@
//! Used by `rustc` when loading a crate with exported macros.
use session::Session;
use metadata::creader::CrateReader;
use metadata::cstore::CStore;
use creader::CrateReader;
use cstore::CStore;
use rustc::session::Session;
use std::collections::{HashSet, HashMap};
use syntax::codemap::Span;

View File

@ -0,0 +1,46 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
macro_rules! enum_from_u32 {
($(#[$attr:meta])* pub enum $name:ident {
$($variant:ident = $e:expr,)*
}) => {
$(#[$attr])*
pub enum $name {
$($variant = $e),*
}
impl $name {
pub fn from_u32(u: u32) -> Option<$name> {
$(if u == $name::$variant as u32 {
return Some($name::$variant)
})*
None
}
}
};
($(#[$attr:meta])* pub enum $name:ident {
$($variant:ident,)*
}) => {
$(#[$attr])*
pub enum $name {
$($variant,)*
}
impl $name {
pub fn from_u32(u: u32) -> Option<$name> {
$(if u == $name::$variant as u32 {
return Some($name::$variant)
})*
None
}
}
}
}

View File

@ -23,7 +23,7 @@ use middle::subst;
use middle::subst::VecPerParamSpace;
use middle::ty::ParamTy;
use middle::ty::{self, Ty};
use util::nodemap::FnvHashMap;
use rustc::util::nodemap::FnvHashMap;
use rustc_front::hir;

View File

@ -71,6 +71,7 @@
extern crate rustc;
extern crate rustc_front;
extern crate rustc_metadata;
pub use self::registry::Registry;

View File

@ -11,8 +11,8 @@
//! Used by `rustc` when loading a plugin.
use rustc::session::Session;
use rustc::metadata::creader::CrateReader;
use rustc::metadata::cstore::CStore;
use rustc_metadata::creader::CrateReader;
use rustc_metadata::cstore::CStore;
use registry::Registry;
use std::borrow::ToOwned;

View File

@ -28,7 +28,7 @@ use {resolve_error, ResolutionError};
use self::DuplicateCheckingMode::*;
use rustc::metadata::util::{CrateStore, ChildItem, DlDef, DlField, DlImpl};
use rustc::middle::cstore::{CrateStore, ChildItem, DlDef, DlField, DlImpl};
use rustc::middle::def::*;
use rustc::middle::def_id::{CRATE_DEF_INDEX, DefId};

View File

@ -54,7 +54,7 @@ use self::FallbackChecks::*;
use rustc::front::map as hir_map;
use rustc::session::Session;
use rustc::lint;
use rustc::metadata::util::{CrateStore, DefLike, DlDef};
use rustc::middle::cstore::{CrateStore, DefLike, DlDef};
use rustc::middle::def::*;
use rustc::middle::def_id::DefId;
use rustc::middle::pat_util::pat_bindings_hygienic;

View File

@ -21,7 +21,7 @@ use std::process::{Command, Output, Stdio};
use std::ptr;
use std::str;
use metadata::util::CrateStore;
use middle::cstore::CrateStore;
use libc;
use llvm::archive_ro::{ArchiveRO, Child};

View File

@ -17,12 +17,11 @@ use super::svh::Svh;
use session::config;
use session::config::NoDebugInfo;
use session::config::{OutputFilenames, Input, OutputType};
use session::filesearch;
use session::search_paths::PathKind;
use session::Session;
use metadata::{util as mdutil};
use metadata::filesearch;
use metadata::util::{CrateStore, LinkMeta};
use metadata::util::{LinkagePreference, NativeLibraryKind};
use middle::cstore::{self, CrateStore, LinkMeta};
use middle::cstore::{LinkagePreference, NativeLibraryKind};
use middle::dependency_format::Linkage;
use middle::ty::{self, Ty};
use rustc::front::map::DefPath;
@ -138,7 +137,7 @@ pub fn find_crate_name(sess: Option<&Session>,
attrs: &[ast::Attribute],
input: &Input) -> String {
let validate = |s: String, span: Option<Span>| {
mdutil::validate_crate_name(sess, &s[..], span);
cstore::validate_crate_name(sess, &s[..], span);
s
};

View File

@ -16,7 +16,7 @@ use std::path::{Path, PathBuf};
use std::process::Command;
use back::archive;
use metadata::util::CrateStore;
use middle::cstore::CrateStore;
use middle::dependency_format::Linkage;
use session::Session;
use session::config::CrateTypeDylib;

View File

@ -62,7 +62,6 @@ extern crate serialize;
#[macro_use] extern crate syntax;
pub use rustc::session;
pub use rustc::metadata;
pub use rustc::middle;
pub use rustc::lint;
pub use rustc::util;

View File

@ -13,7 +13,7 @@ pub use self::Row::*;
use super::escape;
use super::span_utils::SpanUtils;
use metadata::cstore::LOCAL_CRATE;
use middle::cstore::LOCAL_CRATE;
use middle::def_id::{CRATE_DEF_INDEX, DefId};
use middle::ty;

View File

@ -35,6 +35,7 @@ use lint;
use llvm::{BasicBlockRef, Linkage, ValueRef, Vector, get_param};
use llvm;
use middle::cfg;
use middle::cstore::CrateStore;
use middle::def_id::DefId;
use middle::infer;
use middle::lang_items::{LangItem, ExchangeMallocFnLangItem, StartFnLangItem};
@ -42,7 +43,6 @@ use middle::weak_lang_items;
use middle::pat_util::simple_name;
use middle::subst::Substs;
use middle::ty::{self, Ty, HasTypeFlags};
use metadata::util::CrateStore;
use rustc::front::map as hir_map;
use rustc_mir::mir_map::MirMap;
use session::config::{self, NoDebugInfo, FullDebugInfo};

View File

@ -22,7 +22,7 @@ use arena::TypedArena;
use back::link;
use session;
use llvm::{self, ValueRef, get_params};
use metadata::cstore::LOCAL_CRATE;
use middle::cstore::LOCAL_CRATE;
use middle::def;
use middle::def_id::DefId;
use middle::infer;

View File

@ -13,8 +13,8 @@ use back::abi;
use llvm;
use llvm::{ConstFCmp, ConstICmp, SetLinkage, SetUnnamedAddr};
use llvm::{InternalLinkage, ValueRef, Bool, True};
use metadata::cstore::LOCAL_CRATE;
use middle::{check_const, def};
use middle::cstore::LOCAL_CRATE;
use middle::const_eval::{self, ConstVal, ConstEvalErr};
use middle::const_eval::{const_int_checked_neg, const_uint_checked_neg};
use middle::const_eval::{const_int_checked_add, const_uint_checked_add};

View File

@ -10,7 +10,7 @@
use llvm;
use llvm::{ContextRef, ModuleRef, ValueRef, BuilderRef};
use metadata::common::LinkMeta;
use middle::cstore::LinkMeta;
use middle::def::ExportMap;
use middle::def_id::DefId;
use middle::traits;

View File

@ -9,7 +9,7 @@
// except according to those terms.
use llvm::{AvailableExternallyLinkage, InternalLinkage, SetLinkage};
use metadata::util::{CrateStore, FoundAst, InlinedItem};
use middle::cstore::{CrateStore, FoundAst, InlinedItem};
use middle::def_id::DefId;
use middle::subst::Substs;
use trans::base::{push_ctxt, trans_item, get_item_val, trans_fn};

View File

@ -9,7 +9,7 @@
// except according to those terms.
use llvm::{ContextRef, ModuleRef};
use metadata::common::LinkMeta;
use middle::cstore::LinkMeta;
pub use self::base::trans_crate;
pub use self::context::CrateContext;

View File

@ -25,7 +25,7 @@ use super::UnresolvedTypeAction;
use super::write_call;
use CrateCtxt;
use metadata::cstore::LOCAL_CRATE;
use middle::cstore::LOCAL_CRATE;
use middle::def_id::DefId;
use middle::infer;
use middle::ty::{self, LvaluePreference, Ty};

View File

@ -17,12 +17,12 @@ use astconv::AstConv;
use check::{self, FnCtxt};
use front::map as hir_map;
use middle::ty::{self, Ty, ToPolyTraitRef, ToPredicate, HasTypeFlags};
use middle::cstore::{self, CrateStore, DefLike};
use middle::def;
use middle::def_id::DefId;
use middle::lang_items::FnOnceTraitLangItem;
use middle::subst::Substs;
use middle::traits::{Obligation, SelectionContext};
use metadata::util::{self as mdutil, CrateStore, DefLike};
use util::nodemap::{FnvHashSet};
use syntax::ast;
@ -418,13 +418,13 @@ pub fn all_traits<'a>(ccx: &'a CrateCtxt) -> AllTraits<'a> {
fn handle_external_def(traits: &mut AllTraitsVec,
external_mods: &mut FnvHashSet<DefId>,
ccx: &CrateCtxt,
cstore: &for<'a> mdutil::CrateStore<'a>,
dl: mdutil::DefLike) {
cstore: &for<'a> cstore::CrateStore<'a>,
dl: cstore::DefLike) {
match dl {
mdutil::DlDef(def::DefTrait(did)) => {
cstore::DlDef(def::DefTrait(did)) => {
traits.push(TraitInfo::new(did));
}
mdutil::DlDef(def::DefMod(did)) => {
cstore::DlDef(def::DefMod(did)) => {
if !external_mods.insert(did) {
return;
}

View File

@ -83,8 +83,8 @@ use self::TupleArgumentsFlag::*;
use astconv::{self, ast_region_to_region, ast_ty_to_ty, AstConv, PathParamMode};
use check::_match::pat_ctxt;
use fmt_macros::{Parser, Piece, Position};
use metadata::cstore::LOCAL_CRATE;
use middle::astconv_util::prohibit_type_params;
use middle::cstore::LOCAL_CRATE;
use middle::def;
use middle::def_id::DefId;
use middle::infer;

View File

@ -11,7 +11,7 @@
//! Orphan checker: every impl either implements a trait defined in this
//! crate or pertains to a type defined in this crate.
use metadata::cstore::LOCAL_CRATE;
use middle::cstore::LOCAL_CRATE;
use middle::def_id::DefId;
use middle::traits;
use middle::ty;

View File

@ -11,8 +11,7 @@
//! Overlap: No two impls for the same trait are implemented for the
//! same type.
use metadata::cstore::LOCAL_CRATE;
use metadata::util::CrateStore;
use middle::cstore::{CrateStore, LOCAL_CRATE};
use middle::def_id::DefId;
use middle::traits;
use middle::ty;

View File

@ -99,7 +99,6 @@ extern crate rustc_back;
pub use rustc::front;
pub use rustc::lint;
pub use rustc::metadata;
pub use rustc::middle;
pub use rustc::session;
pub use rustc::util;