mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 15:23:46 +00:00
move std_inject to libsyntax
This commit is contained in:
parent
520671f150
commit
375c95b7ad
@ -197,8 +197,14 @@ pub fn phase_2_configure_and_expand(sess: &Session,
|
|||||||
time(time_passes, "gated feature checking", (), |_|
|
time(time_passes, "gated feature checking", (), |_|
|
||||||
front::feature_gate::check_crate(sess, &krate));
|
front::feature_gate::check_crate(sess, &krate));
|
||||||
|
|
||||||
|
let any_exe = sess.crate_types.borrow().iter().any(|ty| {
|
||||||
|
*ty == config::CrateTypeExecutable
|
||||||
|
});
|
||||||
|
|
||||||
krate = time(time_passes, "crate injection", krate, |krate|
|
krate = time(time_passes, "crate injection", krate, |krate|
|
||||||
front::std_inject::maybe_inject_crates_ref(sess, krate));
|
syntax::std_inject::maybe_inject_crates_ref(krate,
|
||||||
|
sess.opts.alt_std_name.clone(),
|
||||||
|
any_exe));
|
||||||
|
|
||||||
// strip before expansion to allow macros to depend on
|
// strip before expansion to allow macros to depend on
|
||||||
// configuration variables e.g/ in
|
// configuration variables e.g/ in
|
||||||
@ -299,7 +305,7 @@ pub fn phase_2_configure_and_expand(sess: &Session,
|
|||||||
sess.diagnostic()));
|
sess.diagnostic()));
|
||||||
|
|
||||||
krate = time(time_passes, "prelude injection", krate, |krate|
|
krate = time(time_passes, "prelude injection", krate, |krate|
|
||||||
front::std_inject::maybe_inject_prelude(sess, krate));
|
syntax::std_inject::maybe_inject_prelude(krate));
|
||||||
|
|
||||||
time(time_passes, "checking that all macro invocations are gone", &krate, |krate|
|
time(time_passes, "checking that all macro invocations are gone", &krate, |krate|
|
||||||
syntax::ext::expand::check_for_macros(&sess.parse_sess, krate));
|
syntax::ext::expand::check_for_macros(&sess.parse_sess, krate));
|
||||||
|
@ -117,7 +117,6 @@ pub mod middle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub mod front {
|
pub mod front {
|
||||||
pub mod std_inject;
|
|
||||||
pub mod feature_gate;
|
pub mod feature_gate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,6 +67,7 @@ pub mod owned_slice;
|
|||||||
pub mod parse;
|
pub mod parse;
|
||||||
pub mod ptr;
|
pub mod ptr;
|
||||||
pub mod show_span;
|
pub mod show_span;
|
||||||
|
pub mod std_inject;
|
||||||
pub mod test;
|
pub mod test;
|
||||||
pub mod visit;
|
pub mod visit;
|
||||||
|
|
||||||
|
@ -8,36 +8,33 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
use driver::config;
|
use ast;
|
||||||
use driver::session::Session;
|
use attr;
|
||||||
|
use codemap::DUMMY_SP;
|
||||||
use syntax::ast;
|
use codemap;
|
||||||
use syntax::attr;
|
use fold::Folder;
|
||||||
use syntax::codemap::DUMMY_SP;
|
use fold;
|
||||||
use syntax::codemap;
|
use owned_slice::OwnedSlice;
|
||||||
use syntax::fold::Folder;
|
use parse::token::InternedString;
|
||||||
use syntax::fold;
|
use parse::token::special_idents;
|
||||||
use syntax::owned_slice::OwnedSlice;
|
use parse::token;
|
||||||
use syntax::parse::token::InternedString;
|
use ptr::P;
|
||||||
use syntax::parse::token::special_idents;
|
use util::small_vector::SmallVector;
|
||||||
use syntax::parse::token;
|
|
||||||
use syntax::ptr::P;
|
|
||||||
use syntax::util::small_vector::SmallVector;
|
|
||||||
|
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
pub fn maybe_inject_crates_ref(sess: &Session, krate: ast::Crate)
|
pub fn maybe_inject_crates_ref(krate: ast::Crate, alt_std_name: Option<String>, any_exe: bool)
|
||||||
-> ast::Crate {
|
-> ast::Crate {
|
||||||
if use_std(&krate) {
|
if use_std(&krate) {
|
||||||
inject_crates_ref(sess, krate)
|
inject_crates_ref(krate, alt_std_name, any_exe)
|
||||||
} else {
|
} else {
|
||||||
krate
|
krate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn maybe_inject_prelude(sess: &Session, krate: ast::Crate) -> ast::Crate {
|
pub fn maybe_inject_prelude(krate: ast::Crate) -> ast::Crate {
|
||||||
if use_std(&krate) {
|
if use_std(&krate) {
|
||||||
inject_prelude(sess, krate)
|
inject_prelude(krate)
|
||||||
} else {
|
} else {
|
||||||
krate
|
krate
|
||||||
}
|
}
|
||||||
@ -56,14 +53,15 @@ fn no_prelude(attrs: &[ast::Attribute]) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct StandardLibraryInjector<'a> {
|
struct StandardLibraryInjector<'a> {
|
||||||
sess: &'a Session,
|
alt_std_name: Option<String>,
|
||||||
|
any_exe: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> fold::Folder for StandardLibraryInjector<'a> {
|
impl<'a> fold::Folder for StandardLibraryInjector<'a> {
|
||||||
fn fold_crate(&mut self, mut krate: ast::Crate) -> ast::Crate {
|
fn fold_crate(&mut self, mut krate: ast::Crate) -> ast::Crate {
|
||||||
|
|
||||||
// The name to use in `extern crate "name" as std;`
|
// The name to use in `extern crate "name" as std;`
|
||||||
let actual_crate_name = match self.sess.opts.alt_std_name {
|
let actual_crate_name = match self.alt_std_name {
|
||||||
Some(ref s) => token::intern_and_get_ident(s.as_slice()),
|
Some(ref s) => token::intern_and_get_ident(s.as_slice()),
|
||||||
None => token::intern_and_get_ident("std"),
|
None => token::intern_and_get_ident("std"),
|
||||||
};
|
};
|
||||||
@ -83,10 +81,7 @@ impl<'a> fold::Folder for StandardLibraryInjector<'a> {
|
|||||||
span: DUMMY_SP
|
span: DUMMY_SP
|
||||||
});
|
});
|
||||||
|
|
||||||
let any_exe = self.sess.crate_types.borrow().iter().any(|ty| {
|
if use_start(&krate) && self.any_exe {
|
||||||
*ty == config::CrateTypeExecutable
|
|
||||||
});
|
|
||||||
if use_start(&krate) && any_exe {
|
|
||||||
let visible_rt_name = "rt";
|
let visible_rt_name = "rt";
|
||||||
let actual_rt_name = "native";
|
let actual_rt_name = "native";
|
||||||
// Gensym the ident so it can't be named
|
// Gensym the ident so it can't be named
|
||||||
@ -124,9 +119,12 @@ impl<'a> fold::Folder for StandardLibraryInjector<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn inject_crates_ref(sess: &Session, krate: ast::Crate) -> ast::Crate {
|
fn inject_crates_ref(krate: ast::Crate,
|
||||||
|
alt_std_name: Option<String>,
|
||||||
|
any_exe: bool) -> ast::Crate {
|
||||||
let mut fold = StandardLibraryInjector {
|
let mut fold = StandardLibraryInjector {
|
||||||
sess: sess,
|
alt_std_name: alt_std_name,
|
||||||
|
any_exe: any_exe,
|
||||||
};
|
};
|
||||||
fold.fold_crate(krate)
|
fold.fold_crate(krate)
|
||||||
}
|
}
|
||||||
@ -231,7 +229,7 @@ impl<'a> fold::Folder for PreludeInjector<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn inject_prelude(_: &Session, krate: ast::Crate) -> ast::Crate {
|
fn inject_prelude(krate: ast::Crate) -> ast::Crate {
|
||||||
let mut fold = PreludeInjector;
|
let mut fold = PreludeInjector;
|
||||||
fold.fold_crate(krate)
|
fold.fold_crate(krate)
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user