Skip to content

Commit

Permalink
Move Def out of syntax crate, where it does not belong
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Jun 6, 2014
1 parent 14d626a commit 0f03b56
Show file tree
Hide file tree
Showing 47 changed files with 442 additions and 392 deletions.
1 change: 1 addition & 0 deletions src/librustc/lib.rs
Expand Up @@ -46,6 +46,7 @@ extern crate time;
extern crate log;

pub mod middle {
pub mod def;
pub mod trans;
pub mod ty;
pub mod ty_fold;
Expand Down
33 changes: 17 additions & 16 deletions src/librustc/metadata/decoder.rs
Expand Up @@ -22,6 +22,7 @@ use metadata::tydecode::{parse_ty_data, parse_def_id,
parse_type_param_def_data,
parse_bare_fn_ty_data, parse_trait_ref_data};
use middle::lang_items;
use middle::def;
use middle::ty::{ImplContainer, TraitContainer};
use middle::ty;
use middle::typeck;
Expand Down Expand Up @@ -333,11 +334,11 @@ fn item_to_def_like(item: ebml::Doc, did: ast::DefId, cnum: ast::CrateNum)
-> DefLike {
let fam = item_family(item);
match fam {
ImmStatic => DlDef(ast::DefStatic(did, false)),
MutStatic => DlDef(ast::DefStatic(did, true)),
Struct => DlDef(ast::DefStruct(did)),
UnsafeFn => DlDef(ast::DefFn(did, ast::UnsafeFn)),
Fn => DlDef(ast::DefFn(did, ast::NormalFn)),
ImmStatic => DlDef(def::DefStatic(did, false)),
MutStatic => DlDef(def::DefStatic(did, true)),
Struct => DlDef(def::DefStruct(did)),
UnsafeFn => DlDef(def::DefFn(did, ast::UnsafeFn)),
Fn => DlDef(def::DefFn(did, ast::NormalFn)),
StaticMethod | UnsafeStaticMethod => {
let fn_style = if fam == UnsafeStaticMethod { ast::UnsafeFn } else
{ ast::NormalFn };
Expand All @@ -348,27 +349,27 @@ fn item_to_def_like(item: ebml::Doc, did: ast::DefId, cnum: ast::CrateNum)
// a trait_method_sort.
let provenance = if reader::maybe_get_doc(
item, tag_item_trait_method_sort).is_some() {
ast::FromTrait(item_reqd_and_translated_parent_item(cnum,
def::FromTrait(item_reqd_and_translated_parent_item(cnum,
item))
} else {
ast::FromImpl(item_reqd_and_translated_parent_item(cnum,
def::FromImpl(item_reqd_and_translated_parent_item(cnum,
item))
};
DlDef(ast::DefStaticMethod(did, provenance, fn_style))
DlDef(def::DefStaticMethod(did, provenance, fn_style))
}
Type | ForeignType => DlDef(ast::DefTy(did)),
Mod => DlDef(ast::DefMod(did)),
ForeignMod => DlDef(ast::DefForeignMod(did)),
Type | ForeignType => DlDef(def::DefTy(did)),
Mod => DlDef(def::DefMod(did)),
ForeignMod => DlDef(def::DefForeignMod(did)),
StructVariant => {
let enum_did = item_reqd_and_translated_parent_item(cnum, item);
DlDef(ast::DefVariant(enum_did, did, true))
DlDef(def::DefVariant(enum_did, did, true))
}
TupleVariant => {
let enum_did = item_reqd_and_translated_parent_item(cnum, item);
DlDef(ast::DefVariant(enum_did, did, false))
DlDef(def::DefVariant(enum_did, did, false))
}
Trait => DlDef(ast::DefTrait(did)),
Enum => DlDef(ast::DefTy(did)),
Trait => DlDef(def::DefTrait(did)),
Enum => DlDef(def::DefTy(did)),
Impl => DlImpl(did),
PublicField | InheritedField => DlField,
}
Expand Down Expand Up @@ -459,7 +460,7 @@ pub fn get_symbol(data: &[u8], id: ast::NodeId) -> String {
// Something that a name can resolve to.
#[deriving(Clone)]
pub enum DefLike {
DlDef(ast::Def),
DlDef(def::Def),
DlImpl(ast::DefId),
DlField
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/encoder.rs
Expand Up @@ -1631,7 +1631,7 @@ impl<'a,'b,'c> Visitor<()> for ImplVisitor<'a,'b,'c> {
ItemImpl(_, Some(ref trait_ref), _, _) => {
let def_map = &self.ecx.tcx.def_map;
let trait_def = def_map.borrow().get_copy(&trait_ref.ref_id);
let def_id = ast_util::def_id_of_def(trait_def);
let def_id = trait_def.def_id();

// Load eagerly if this is an implementation of the Drop trait
// or if the trait is not defined in this crate.
Expand Down
69 changes: 35 additions & 34 deletions src/librustc/middle/astencode.rs
Expand Up @@ -16,6 +16,7 @@ use c = metadata::common;
use cstore = metadata::cstore;
use driver::session::Session;
use metadata::decoder;
use middle::def;
use e = metadata::encoder;
use middle::freevars::freevar_entry;
use middle::region;
Expand Down Expand Up @@ -395,58 +396,58 @@ fn renumber_and_map_ast(xcx: &ExtendedDecodeContext,
// ______________________________________________________________________
// Encoding and decoding of ast::def

fn decode_def(xcx: &ExtendedDecodeContext, doc: ebml::Doc) -> ast::Def {
fn decode_def(xcx: &ExtendedDecodeContext, doc: ebml::Doc) -> def::Def {
let mut dsr = reader::Decoder::new(doc);
let def: ast::Def = Decodable::decode(&mut dsr).unwrap();
let def: def::Def = Decodable::decode(&mut dsr).unwrap();
def.tr(xcx)
}

impl tr for ast::Def {
fn tr(&self, xcx: &ExtendedDecodeContext) -> ast::Def {
impl tr for def::Def {
fn tr(&self, xcx: &ExtendedDecodeContext) -> def::Def {
match *self {
ast::DefFn(did, p) => ast::DefFn(did.tr(xcx), p),
ast::DefStaticMethod(did, wrapped_did2, p) => {
ast::DefStaticMethod(did.tr(xcx),
def::DefFn(did, p) => def::DefFn(did.tr(xcx), p),
def::DefStaticMethod(did, wrapped_did2, p) => {
def::DefStaticMethod(did.tr(xcx),
match wrapped_did2 {
ast::FromTrait(did2) => {
ast::FromTrait(did2.tr(xcx))
def::FromTrait(did2) => {
def::FromTrait(did2.tr(xcx))
}
ast::FromImpl(did2) => {
ast::FromImpl(did2.tr(xcx))
def::FromImpl(did2) => {
def::FromImpl(did2.tr(xcx))
}
},
p)
}
ast::DefMethod(did0, did1) => {
ast::DefMethod(did0.tr(xcx), did1.map(|did1| did1.tr(xcx)))
def::DefMethod(did0, did1) => {
def::DefMethod(did0.tr(xcx), did1.map(|did1| did1.tr(xcx)))
}
ast::DefSelfTy(nid) => { ast::DefSelfTy(xcx.tr_id(nid)) }
ast::DefMod(did) => { ast::DefMod(did.tr(xcx)) }
ast::DefForeignMod(did) => { ast::DefForeignMod(did.tr(xcx)) }
ast::DefStatic(did, m) => { ast::DefStatic(did.tr(xcx), m) }
ast::DefArg(nid, b) => { ast::DefArg(xcx.tr_id(nid), b) }
ast::DefLocal(nid, b) => { ast::DefLocal(xcx.tr_id(nid), b) }
ast::DefVariant(e_did, v_did, is_s) => {
ast::DefVariant(e_did.tr(xcx), v_did.tr(xcx), is_s)
def::DefSelfTy(nid) => { def::DefSelfTy(xcx.tr_id(nid)) }
def::DefMod(did) => { def::DefMod(did.tr(xcx)) }
def::DefForeignMod(did) => { def::DefForeignMod(did.tr(xcx)) }
def::DefStatic(did, m) => { def::DefStatic(did.tr(xcx), m) }
def::DefArg(nid, b) => { def::DefArg(xcx.tr_id(nid), b) }
def::DefLocal(nid, b) => { def::DefLocal(xcx.tr_id(nid), b) }
def::DefVariant(e_did, v_did, is_s) => {
def::DefVariant(e_did.tr(xcx), v_did.tr(xcx), is_s)
},
ast::DefTrait(did) => ast::DefTrait(did.tr(xcx)),
ast::DefTy(did) => ast::DefTy(did.tr(xcx)),
ast::DefPrimTy(p) => ast::DefPrimTy(p),
ast::DefTyParam(did, v) => ast::DefTyParam(did.tr(xcx), v),
ast::DefBinding(nid, bm) => ast::DefBinding(xcx.tr_id(nid), bm),
ast::DefUse(did) => ast::DefUse(did.tr(xcx)),
ast::DefUpvar(nid1, def, nid2, nid3) => {
ast::DefUpvar(xcx.tr_id(nid1),
def::DefTrait(did) => def::DefTrait(did.tr(xcx)),
def::DefTy(did) => def::DefTy(did.tr(xcx)),
def::DefPrimTy(p) => def::DefPrimTy(p),
def::DefTyParam(did, v) => def::DefTyParam(did.tr(xcx), v),
def::DefBinding(nid, bm) => def::DefBinding(xcx.tr_id(nid), bm),
def::DefUse(did) => def::DefUse(did.tr(xcx)),
def::DefUpvar(nid1, def, nid2, nid3) => {
def::DefUpvar(xcx.tr_id(nid1),
@(*def).tr(xcx),
xcx.tr_id(nid2),
xcx.tr_id(nid3))
}
ast::DefStruct(did) => ast::DefStruct(did.tr(xcx)),
ast::DefRegion(nid) => ast::DefRegion(xcx.tr_id(nid)),
ast::DefTyParamBinder(nid) => {
ast::DefTyParamBinder(xcx.tr_id(nid))
def::DefStruct(did) => def::DefStruct(did.tr(xcx)),
def::DefRegion(nid) => def::DefRegion(xcx.tr_id(nid)),
def::DefTyParamBinder(nid) => {
def::DefTyParamBinder(xcx.tr_id(nid))
}
ast::DefLabel(nid) => ast::DefLabel(xcx.tr_id(nid))
def::DefLabel(nid) => def::DefLabel(xcx.tr_id(nid))
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/librustc/middle/borrowck/mod.rs
Expand Up @@ -14,6 +14,7 @@

use middle::dataflow::DataFlowContext;
use middle::dataflow::DataFlowOperator;
use middle::def;
use euv = middle::expr_use_visitor;
use mc = middle::mem_categorization;
use middle::ty;
Expand Down Expand Up @@ -399,7 +400,7 @@ impl<'a> BorrowckCtxt<'a> {
id: ast::NodeId,
span: Span,
ty: ty::t,
def: ast::Def)
def: def::Def)
-> mc::cmt {
match self.mc().cat_def(id, span, ty, def) {
Ok(c) => c,
Expand All @@ -412,11 +413,11 @@ impl<'a> BorrowckCtxt<'a> {
pub fn cat_captured_var(&self,
closure_id: ast::NodeId,
closure_span: Span,
upvar_def: ast::Def)
upvar_def: def::Def)
-> mc::cmt {
// Create the cmt for the variable being borrowed, from the
// caller's perspective
let var_id = ast_util::def_id_of_def(upvar_def).node;
let var_id = upvar_def.def_id().node;
let var_ty = ty::node_id_to_type(self.tcx, var_id);
self.cat_def(closure_id, closure_span, var_ty, upvar_def)
}
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/middle/cfg/construct.rs
Expand Up @@ -9,6 +9,7 @@
// except according to those terms.

use middle::cfg::*;
use middle::def;
use middle::graph;
use middle::typeck;
use middle::ty;
Expand Down Expand Up @@ -531,7 +532,7 @@ impl<'a> CFGBuilder<'a> {

Some(_) => {
match self.tcx.def_map.borrow().find(&expr.id) {
Some(&ast::DefLabel(loop_id)) => {
Some(&def::DefLabel(loop_id)) => {
for l in self.loop_scopes.iter() {
if l.loop_id == loop_id {
return *l;
Expand Down
1 change: 1 addition & 0 deletions src/librustc/middle/check_const.rs
Expand Up @@ -10,6 +10,7 @@


use driver::session::Session;
use middle::def::*;
use middle::resolve;
use middle::ty;
use middle::typeck;
Expand Down
1 change: 1 addition & 0 deletions src/librustc/middle/check_match.rs
Expand Up @@ -12,6 +12,7 @@

use middle::const_eval::{compare_const_vals, lookup_const_by_id};
use middle::const_eval::{eval_const_expr, const_val, const_bool, const_float};
use middle::def::*;
use middle::pat_util::*;
use middle::ty::*;
use middle::ty;
Expand Down
5 changes: 3 additions & 2 deletions src/librustc/middle/const_eval.rs
Expand Up @@ -14,6 +14,7 @@
use metadata::csearch;
use middle::astencode;

use middle::def;
use middle::ty;
use middle::typeck::astconv;
use util::nodemap::{DefIdMap};
Expand Down Expand Up @@ -83,10 +84,10 @@ pub fn join_all<It: Iterator<constness>>(mut cs: It) -> constness {
pub fn lookup_const(tcx: &ty::ctxt, e: &Expr) -> Option<@Expr> {
let opt_def = tcx.def_map.borrow().find_copy(&e.id);
match opt_def {
Some(ast::DefStatic(def_id, false)) => {
Some(def::DefStatic(def_id, false)) => {
lookup_const_by_id(tcx, def_id)
}
Some(ast::DefVariant(enum_def, variant_def, _)) => {
Some(def::DefVariant(enum_def, variant_def, _)) => {
lookup_variant_by_id(tcx, enum_def, variant_def)
}
_ => None
Expand Down
7 changes: 4 additions & 3 deletions src/librustc/middle/dataflow.rs
Expand Up @@ -17,15 +17,16 @@
*/


use middle::def;
use middle::ty;
use middle::typeck;
use std::io;
use std::string::String;
use std::uint;
use syntax::ast;
use syntax::ast_util;
use syntax::ast_util::IdRange;
use syntax::print::{pp, pprust};
use middle::ty;
use middle::typeck;
use util::ppaux::Repr;
use util::nodemap::NodeMap;

Expand Down Expand Up @@ -757,7 +758,7 @@ impl<'a, 'b, O:DataFlowOperator> PropagationContext<'a, 'b, O> {

Some(_) => {
match self.tcx().def_map.borrow().find(&expr.id) {
Some(&ast::DefLabel(loop_id)) => {
Some(&def::DefLabel(loop_id)) => {
match loop_scopes.iter().position(|l| l.loop_id == loop_id) {
Some(i) => i,
None => {
Expand Down
9 changes: 5 additions & 4 deletions src/librustc/middle/dead.rs
Expand Up @@ -12,6 +12,7 @@
// closely. The idea is that all reachable symbols are live, codes called
// from live codes are live, and everything else is dead.

use middle::def;
use middle::lint::{Allow, contains_lint, DeadCode};
use middle::privacy;
use middle::ty;
Expand All @@ -21,7 +22,7 @@ use util::nodemap::NodeSet;
use std::collections::HashSet;
use syntax::ast;
use syntax::ast_map;
use syntax::ast_util::{local_def, def_id_of_def, is_local};
use syntax::ast_util::{local_def, is_local};
use syntax::attr;
use syntax::codemap;
use syntax::parse::token;
Expand Down Expand Up @@ -77,9 +78,9 @@ impl<'a> MarkSymbolVisitor<'a> {
None => return
};
let def_id = match def {
ast::DefVariant(enum_id, _, _) => Some(enum_id),
ast::DefPrimTy(_) => None,
_ => Some(def_id_of_def(def)),
def::DefVariant(enum_id, _, _) => Some(enum_id),
def::DefPrimTy(_) => None,
_ => Some(def.def_id())
};
match def_id {
Some(def_id) => self.check_def_id(def_id),
Expand Down

0 comments on commit 0f03b56

Please sign in to comment.