rustc: middle: move DefMap from resolve to def.

This commit is contained in:
Eduard Burtescu 2014-12-18 21:03:56 +02:00
parent fb1d6f24fc
commit d8f57c3804
7 changed files with 24 additions and 26 deletions

View file

@ -12,8 +12,7 @@
// recursively.
use session::Session;
use middle::resolve;
use middle::def::{DefStatic, DefConst};
use middle::def::{DefStatic, DefConst, DefMap};
use syntax::ast;
use syntax::{ast_util, ast_map};
@ -22,7 +21,7 @@ use syntax::visit;
struct CheckCrateVisitor<'a, 'ast: 'a> {
sess: &'a Session,
def_map: &'a resolve::DefMap,
def_map: &'a DefMap,
ast_map: &'a ast_map::Map<'ast>
}
@ -34,7 +33,7 @@ impl<'v, 'a, 'ast> Visitor<'v> for CheckCrateVisitor<'a, 'ast> {
pub fn check_crate<'ast>(sess: &Session,
krate: &ast::Crate,
def_map: &resolve::DefMap,
def_map: &DefMap,
ast_map: &ast_map::Map<'ast>) {
let mut visitor = CheckCrateVisitor {
sess: sess,
@ -60,7 +59,7 @@ struct CheckItemRecursionVisitor<'a, 'ast: 'a> {
root_it: &'a ast::Item,
sess: &'a Session,
ast_map: &'a ast_map::Map<'ast>,
def_map: &'a resolve::DefMap,
def_map: &'a DefMap,
idstack: Vec<ast::NodeId>
}
@ -68,7 +67,7 @@ struct CheckItemRecursionVisitor<'a, 'ast: 'a> {
// FIXME: Should use the dependency graph when it's available (#1356)
pub fn check_item_recursion<'a>(sess: &'a Session,
ast_map: &'a ast_map::Map,
def_map: &'a resolve::DefMap,
def_map: &'a DefMap,
it: &'a ast::Item) {
let mut visitor = CheckItemRecursionVisitor {

View file

@ -12,9 +12,12 @@ pub use self::Def::*;
pub use self::MethodProvenance::*;
use middle::subst::ParamSpace;
use util::nodemap::NodeMap;
use syntax::ast;
use syntax::ast_util::local_def;
use std::cell::RefCell;
#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub enum Def {
DefFn(ast::DefId, bool /* is_ctor */),
@ -56,6 +59,9 @@ pub enum Def {
DefMethod(ast::DefId /* method */, Option<ast::DefId> /* trait */, MethodProvenance),
}
// Definition mapping
pub type DefMap = RefCell<NodeMap<Def>>;
#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub enum MethodProvenance {
FromTrait(ast::DefId),

View file

@ -9,7 +9,6 @@
// except according to those terms.
use middle::def::*;
use middle::resolve;
use middle::ty;
use util::nodemap::FnvHashMap;
@ -21,7 +20,7 @@ pub type PatIdMap = FnvHashMap<ast::Ident, ast::NodeId>;
// This is used because same-named variables in alternative patterns need to
// use the NodeId of their namesake in the first pattern.
pub fn pat_id_map(dm: &resolve::DefMap, pat: &ast::Pat) -> PatIdMap {
pub fn pat_id_map(dm: &DefMap, pat: &ast::Pat) -> PatIdMap {
let mut map = FnvHashMap::new();
pat_bindings(dm, pat, |_bm, p_id, _s, path1| {
map.insert(path1.node, p_id);
@ -29,7 +28,7 @@ pub fn pat_id_map(dm: &resolve::DefMap, pat: &ast::Pat) -> PatIdMap {
map
}
pub fn pat_is_refutable(dm: &resolve::DefMap, pat: &ast::Pat) -> bool {
pub fn pat_is_refutable(dm: &DefMap, pat: &ast::Pat) -> bool {
match pat.node {
ast::PatLit(_) | ast::PatRange(_, _) => true,
ast::PatEnum(_, _) |
@ -45,7 +44,7 @@ pub fn pat_is_refutable(dm: &resolve::DefMap, pat: &ast::Pat) -> bool {
}
}
pub fn pat_is_variant_or_struct(dm: &resolve::DefMap, pat: &ast::Pat) -> bool {
pub fn pat_is_variant_or_struct(dm: &DefMap, pat: &ast::Pat) -> bool {
match pat.node {
ast::PatEnum(_, _) |
ast::PatIdent(_, _, None) |
@ -59,7 +58,7 @@ pub fn pat_is_variant_or_struct(dm: &resolve::DefMap, pat: &ast::Pat) -> bool {
}
}
pub fn pat_is_const(dm: &resolve::DefMap, pat: &ast::Pat) -> bool {
pub fn pat_is_const(dm: &DefMap, pat: &ast::Pat) -> bool {
match pat.node {
ast::PatIdent(_, _, None) | ast::PatEnum(..) => {
match dm.borrow().get(&pat.id) {
@ -71,7 +70,7 @@ pub fn pat_is_const(dm: &resolve::DefMap, pat: &ast::Pat) -> bool {
}
}
pub fn pat_is_binding(dm: &resolve::DefMap, pat: &ast::Pat) -> bool {
pub fn pat_is_binding(dm: &DefMap, pat: &ast::Pat) -> bool {
match pat.node {
ast::PatIdent(..) => {
!pat_is_variant_or_struct(dm, pat) &&
@ -81,7 +80,7 @@ pub fn pat_is_binding(dm: &resolve::DefMap, pat: &ast::Pat) -> bool {
}
}
pub fn pat_is_binding_or_wild(dm: &resolve::DefMap, pat: &ast::Pat) -> bool {
pub fn pat_is_binding_or_wild(dm: &DefMap, pat: &ast::Pat) -> bool {
match pat.node {
ast::PatIdent(..) => pat_is_binding(dm, pat),
ast::PatWild(_) => true,
@ -91,7 +90,7 @@ pub fn pat_is_binding_or_wild(dm: &resolve::DefMap, pat: &ast::Pat) -> bool {
/// Call `it` on every "binding" in a pattern, e.g., on `a` in
/// `match foo() { Some(a) => (), None => () }`
pub fn pat_bindings<I>(dm: &resolve::DefMap, pat: &ast::Pat, mut it: I) where
pub fn pat_bindings<I>(dm: &DefMap, pat: &ast::Pat, mut it: I) where
I: FnMut(ast::BindingMode, ast::NodeId, Span, &ast::SpannedIdent),
{
walk_pat(pat, |p| {
@ -107,7 +106,7 @@ pub fn pat_bindings<I>(dm: &resolve::DefMap, pat: &ast::Pat, mut it: I) where
/// Checks if the pattern contains any patterns that bind something to
/// an ident, e.g. `foo`, or `Foo(foo)` or `foo @ Bar(..)`.
pub fn pat_contains_bindings(dm: &resolve::DefMap, pat: &ast::Pat) -> bool {
pub fn pat_contains_bindings(dm: &DefMap, pat: &ast::Pat) -> bool {
let mut contains_bindings = false;
walk_pat(pat, |p| {
if pat_is_binding(dm, p) {

View file

@ -84,9 +84,6 @@ use std::mem::replace;
use std::rc::{Rc, Weak};
use std::uint;
// Definition mapping
pub type DefMap = RefCell<NodeMap<Def>>;
#[deriving(Copy)]
struct BindingInfo {
span: Span,

View file

@ -19,9 +19,8 @@ pub use self::DefRegion::*;
use self::ScopeChain::*;
use session::Session;
use middle::def;
use middle::def::{mod, DefMap};
use middle::region;
use middle::resolve::DefMap;
use middle::subst;
use middle::ty;
use std::fmt;

View file

@ -46,13 +46,12 @@ use lint;
use metadata::csearch;
use middle;
use middle::const_eval;
use middle::def;
use middle::def::{mod, DefMap};
use middle::dependency_format;
use middle::lang_items::{FnTraitLangItem, FnMutTraitLangItem};
use middle::lang_items::{FnOnceTraitLangItem, TyDescStructLangItem};
use middle::mem_categorization as mc;
use middle::region;
use middle::resolve;
use middle::resolve_lifetime;
use middle::infer;
use middle::stability;
@ -615,7 +614,7 @@ pub struct ctxt<'tcx> {
// queried from a HashSet.
interner: RefCell<FnvHashMap<InternedTy<'tcx>, Ty<'tcx>>>,
pub sess: Session,
pub def_map: resolve::DefMap,
pub def_map: DefMap,
pub named_region_map: resolve_lifetime::NamedRegionMap,
@ -1967,7 +1966,7 @@ impl UnboxedClosureKind {
pub fn mk_ctxt<'tcx>(s: Session,
type_arena: &'tcx TypedArena<TyS<'tcx>>,
dm: resolve::DefMap,
dm: DefMap,
named_region_map: resolve_lifetime::NamedRegionMap,
map: ast_map::Map<'tcx>,
freevars: RefCell<FreevarMap>,

View file

@ -193,12 +193,11 @@ use llvm::{ValueRef, BasicBlockRef};
use middle::check_match::StaticInliner;
use middle::check_match;
use middle::const_eval;
use middle::def;
use middle::def::{mod, DefMap};
use middle::expr_use_visitor as euv;
use middle::lang_items::StrEqFnLangItem;
use middle::mem_categorization as mc;
use middle::pat_util::*;
use middle::resolve::DefMap;
use trans::adt;
use trans::base::*;
use trans::build::{AddCase, And, BitCast, Br, CondBr, GEPi, InBoundsGEP, Load};