Add exprs map to crate, collect item blocks there
This commit is contained in:
parent
1c448574bc
commit
069a2442b8
2 changed files with 40 additions and 9 deletions
|
@ -47,9 +47,12 @@ use hir::def_id::{DefIndex, DefId};
|
|||
use hir::def::{Def, PathResolution};
|
||||
use session::Session;
|
||||
use util::nodemap::NodeMap;
|
||||
use rustc_data_structures::fnv::FnvHashMap;
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::iter;
|
||||
use std::mem;
|
||||
|
||||
use syntax::ast::*;
|
||||
use syntax::errors;
|
||||
use syntax::ptr::P;
|
||||
|
@ -68,6 +71,7 @@ pub struct LoweringContext<'a> {
|
|||
// the form of a DefIndex) so that if we create a new node which introduces
|
||||
// a definition, then we can properly create the def id.
|
||||
parent_def: Option<DefIndex>,
|
||||
exprs: FnvHashMap<hir::ExprId, hir::Expr>,
|
||||
resolver: &'a mut Resolver,
|
||||
|
||||
/// The items being lowered are collected here.
|
||||
|
@ -104,6 +108,7 @@ pub fn lower_crate(sess: &Session,
|
|||
crate_root: std_inject::injected_crate_name(krate),
|
||||
sess: sess,
|
||||
parent_def: None,
|
||||
exprs: FnvHashMap(),
|
||||
resolver: resolver,
|
||||
items: BTreeMap::new(),
|
||||
impl_items: BTreeMap::new(),
|
||||
|
@ -120,6 +125,23 @@ enum ParamMode {
|
|||
|
||||
impl<'a> LoweringContext<'a> {
|
||||
fn lower_crate(mut self, c: &Crate) -> hir::Crate {
|
||||
self.lower_items(c);
|
||||
let module = self.lower_mod(&c.module);
|
||||
let attrs = self.lower_attrs(&c.attrs);
|
||||
let exported_macros = c.exported_macros.iter().map(|m| self.lower_macro_def(m)).collect();
|
||||
|
||||
hir::Crate {
|
||||
module: module,
|
||||
attrs: attrs,
|
||||
span: c.span,
|
||||
exported_macros: exported_macros,
|
||||
items: self.items,
|
||||
impl_items: self.impl_items,
|
||||
exprs: mem::replace(&mut self.exprs, FnvHashMap()),
|
||||
}
|
||||
}
|
||||
|
||||
fn lower_items(&mut self, c: &Crate) {
|
||||
struct ItemLowerer<'lcx, 'interner: 'lcx> {
|
||||
lctx: &'lcx mut LoweringContext<'interner>,
|
||||
}
|
||||
|
@ -139,16 +161,14 @@ impl<'a> LoweringContext<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
visit::walk_crate(&mut ItemLowerer { lctx: &mut self }, c);
|
||||
let mut item_lowerer = ItemLowerer { lctx: self };
|
||||
visit::walk_crate(&mut item_lowerer, c);
|
||||
}
|
||||
|
||||
hir::Crate {
|
||||
module: self.lower_mod(&c.module),
|
||||
attrs: self.lower_attrs(&c.attrs),
|
||||
span: c.span,
|
||||
exported_macros: c.exported_macros.iter().map(|m| self.lower_macro_def(m)).collect(),
|
||||
items: self.items,
|
||||
impl_items: self.impl_items,
|
||||
}
|
||||
fn record_expr(&mut self, expr: hir::Expr) -> hir::ExprId {
|
||||
let id = hir::ExprId(expr.id);
|
||||
self.exprs.insert(id, expr);
|
||||
id
|
||||
}
|
||||
|
||||
fn next_id(&self) -> NodeId {
|
||||
|
|
|
@ -33,6 +33,7 @@ pub use self::PathParameters::*;
|
|||
use hir::def::Def;
|
||||
use hir::def_id::DefId;
|
||||
use util::nodemap::{NodeMap, FxHashSet};
|
||||
use rustc_data_structures::fnv::FnvHashMap;
|
||||
|
||||
use syntax_pos::{mk_sp, Span, ExpnId, DUMMY_SP};
|
||||
use syntax::codemap::{self, respan, Spanned};
|
||||
|
@ -428,6 +429,7 @@ pub struct Crate {
|
|||
pub items: BTreeMap<NodeId, Item>,
|
||||
|
||||
pub impl_items: BTreeMap<ImplItemId, ImplItem>,
|
||||
pub exprs: FnvHashMap<ExprId, Expr>,
|
||||
}
|
||||
|
||||
impl Crate {
|
||||
|
@ -846,6 +848,15 @@ pub enum UnsafeSource {
|
|||
UserProvided,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||
pub struct ExprId(NodeId);
|
||||
|
||||
impl ExprId {
|
||||
pub fn node_id(self) -> NodeId {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
/// An expression
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)]
|
||||
pub struct Expr {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue