mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
Refactor hir::lowering
API
This commit is contained in:
parent
3927ff4fec
commit
33978b0728
@ -91,30 +91,33 @@ impl Resolver for DummyResolver {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> LoweringContext<'a> {
|
||||
pub fn new(id_assigner: &'a NodeIdAssigner,
|
||||
c: Option<&Crate>,
|
||||
resolver: &'a mut Resolver)
|
||||
-> LoweringContext<'a> {
|
||||
let crate_root = c.and_then(|c| {
|
||||
if std_inject::no_core(c) {
|
||||
None
|
||||
} else if std_inject::no_std(c) {
|
||||
Some("core")
|
||||
} else {
|
||||
Some("std")
|
||||
}
|
||||
});
|
||||
pub fn lower_crate(krate: &Crate, id_assigner: &NodeIdAssigner, resolver: &mut Resolver)
|
||||
-> hir::Crate {
|
||||
LoweringContext {
|
||||
crate_root: if std_inject::no_core(krate) {
|
||||
None
|
||||
} else if std_inject::no_std(krate) {
|
||||
Some("core")
|
||||
} else {
|
||||
Some("std")
|
||||
},
|
||||
id_assigner: id_assigner,
|
||||
parent_def: None,
|
||||
resolver: resolver,
|
||||
}.lower_crate(krate)
|
||||
}
|
||||
|
||||
impl<'a> LoweringContext<'a> {
|
||||
pub fn testing_context(id_assigner: &'a NodeIdAssigner, resolver: &'a mut Resolver) -> Self {
|
||||
LoweringContext {
|
||||
crate_root: crate_root,
|
||||
crate_root: None,
|
||||
id_assigner: id_assigner,
|
||||
parent_def: None,
|
||||
resolver: resolver,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn lower_crate(&mut self, c: &Crate) -> hir::Crate {
|
||||
fn lower_crate(&mut self, c: &Crate) -> hir::Crate {
|
||||
struct ItemLowerer<'lcx, 'interner: 'lcx> {
|
||||
items: BTreeMap<NodeId, hir::Item>,
|
||||
lctx: &'lcx mut LoweringContext<'interner>,
|
||||
|
@ -37,7 +37,7 @@ use rustc_typeck as typeck;
|
||||
use rustc_privacy;
|
||||
use rustc_plugin::registry::Registry;
|
||||
use rustc_plugin as plugin;
|
||||
use rustc::hir::lowering::LoweringContext;
|
||||
use rustc::hir::lowering::lower_crate;
|
||||
use rustc_passes::{no_asm, loops, consts, rvalues, static_recursion};
|
||||
use rustc_const_eval::check_match;
|
||||
use super::Compilation;
|
||||
@ -787,8 +787,7 @@ pub fn lower_and_resolve<'a>(sess: &Session,
|
||||
|
||||
// Lower ast -> hir.
|
||||
let hir_forest = time(sess.time_passes(), "lowering ast -> hir", || {
|
||||
let krate = LoweringContext::new(sess, Some(krate), &mut resolver).lower_crate(krate);
|
||||
hir_map::Forest::new(krate, dep_graph)
|
||||
hir_map::Forest::new(lower_crate(krate, sess, &mut resolver), dep_graph)
|
||||
});
|
||||
|
||||
(ty::CrateAnalysis {
|
||||
|
@ -1329,7 +1329,7 @@ fn mk_ctxt() -> parse::ParseSess {
|
||||
fn with_testing_context<T, F: FnOnce(&mut LoweringContext) -> T>(f: F) -> T {
|
||||
let assigner = FakeNodeIdAssigner;
|
||||
let mut resolver = DummyResolver;
|
||||
let mut lcx = LoweringContext::new(&assigner, None, &mut resolver);
|
||||
let mut lcx = LoweringContext::testing_context(&assigner, &mut resolver);
|
||||
f(&mut lcx)
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ use rustc::hir::map as hir_map;
|
||||
use rustc::session::{self, config};
|
||||
use rustc::session::config::{get_unstable_features_setting, OutputType};
|
||||
use rustc::session::search_paths::{SearchPaths, PathKind};
|
||||
use rustc::hir::lowering::{LoweringContext, DummyResolver};
|
||||
use rustc::hir::lowering::{lower_crate, DummyResolver};
|
||||
use rustc_back::dynamic_lib::DynamicLibrary;
|
||||
use rustc_back::tempdir::TempDir;
|
||||
use rustc_driver::{driver, Compilation};
|
||||
@ -98,7 +98,7 @@ pub fn run(input: &str,
|
||||
let defs = &RefCell::new(hir_map::collect_definitions(&krate));
|
||||
|
||||
let mut dummy_resolver = DummyResolver;
|
||||
let krate = LoweringContext::new(&sess, Some(&krate), &mut dummy_resolver).lower_crate(&krate);
|
||||
let krate = lower_crate(&krate, &sess, &mut dummy_resolver);
|
||||
|
||||
let opts = scrape_test_config(&krate);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user