mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-05 11:33:04 +00:00
libsyntax: Pass feature set in ExpansionConfig, not just enable_quotes.
This commit is contained in:
parent
cf636c233d
commit
20d8222e6a
@ -469,9 +469,10 @@ pub fn phase_2_configure_and_expand(sess: &Session,
|
||||
new_path.extend(env::split_paths(&_old_path));
|
||||
env::set_var("PATH", &env::join_paths(new_path.iter()).unwrap());
|
||||
}
|
||||
let features = sess.features.borrow();
|
||||
let cfg = syntax::ext::expand::ExpansionConfig {
|
||||
crate_name: crate_name.to_string(),
|
||||
enable_quotes: sess.features.borrow().quote,
|
||||
features: Some(&features),
|
||||
recursion_limit: sess.recursion_limit.get(),
|
||||
};
|
||||
let ret = syntax::ext::expand::expand_crate(&sess.parse_sess,
|
||||
|
@ -439,7 +439,8 @@ impl BlockInfo {
|
||||
|
||||
/// The base map of methods for expanding syntax extension
|
||||
/// AST nodes into full ASTs
|
||||
fn initial_syntax_expander_table(ecfg: &expand::ExpansionConfig) -> SyntaxEnv {
|
||||
fn initial_syntax_expander_table<'feat>(ecfg: &expand::ExpansionConfig<'feat>)
|
||||
-> SyntaxEnv {
|
||||
// utility function to simplify creating NormalTT syntax extensions
|
||||
fn builtin_normal_expander(f: MacroExpanderFn) -> SyntaxExtension {
|
||||
NormalTT(box f, None)
|
||||
@ -470,7 +471,7 @@ fn initial_syntax_expander_table(ecfg: &expand::ExpansionConfig) -> SyntaxEnv {
|
||||
syntax_expanders.insert(intern("deriving"),
|
||||
Decorator(box ext::deriving::expand_deprecated_deriving));
|
||||
|
||||
if ecfg.enable_quotes {
|
||||
if ecfg.enable_quotes() {
|
||||
// Quasi-quoting expanders
|
||||
syntax_expanders.insert(intern("quote_tokens"),
|
||||
builtin_normal_expander(
|
||||
@ -541,7 +542,7 @@ pub struct ExtCtxt<'a> {
|
||||
pub parse_sess: &'a parse::ParseSess,
|
||||
pub cfg: ast::CrateConfig,
|
||||
pub backtrace: ExpnId,
|
||||
pub ecfg: expand::ExpansionConfig,
|
||||
pub ecfg: expand::ExpansionConfig<'a>,
|
||||
pub use_std: bool,
|
||||
|
||||
pub mod_path: Vec<ast::Ident> ,
|
||||
@ -554,7 +555,7 @@ pub struct ExtCtxt<'a> {
|
||||
|
||||
impl<'a> ExtCtxt<'a> {
|
||||
pub fn new(parse_sess: &'a parse::ParseSess, cfg: ast::CrateConfig,
|
||||
ecfg: expand::ExpansionConfig) -> ExtCtxt<'a> {
|
||||
ecfg: expand::ExpansionConfig<'a>) -> ExtCtxt<'a> {
|
||||
let env = initial_syntax_expander_table(&ecfg);
|
||||
ExtCtxt {
|
||||
parse_sess: parse_sess,
|
||||
|
@ -22,6 +22,7 @@ use attr::AttrMetaMethods;
|
||||
use codemap;
|
||||
use codemap::{Span, Spanned, ExpnInfo, NameAndSpan, MacroBang, MacroAttribute};
|
||||
use ext::base::*;
|
||||
use feature_gate::{Features};
|
||||
use fold;
|
||||
use fold::*;
|
||||
use parse;
|
||||
@ -1407,28 +1408,35 @@ fn new_span(cx: &ExtCtxt, sp: Span) -> Span {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ExpansionConfig {
|
||||
pub struct ExpansionConfig<'feat> {
|
||||
pub crate_name: String,
|
||||
pub enable_quotes: bool,
|
||||
pub features: Option<&'feat Features>,
|
||||
pub recursion_limit: usize,
|
||||
}
|
||||
|
||||
impl ExpansionConfig {
|
||||
pub fn default(crate_name: String) -> ExpansionConfig {
|
||||
impl<'feat> ExpansionConfig<'feat> {
|
||||
pub fn default(crate_name: String) -> ExpansionConfig<'static> {
|
||||
ExpansionConfig {
|
||||
crate_name: crate_name,
|
||||
enable_quotes: false,
|
||||
features: None,
|
||||
recursion_limit: 64,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn enable_quotes(&self) -> bool {
|
||||
match self.features {
|
||||
Some(&Features { quote: true, .. }) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn expand_crate(parse_sess: &parse::ParseSess,
|
||||
cfg: ExpansionConfig,
|
||||
// these are the macros being imported to this crate:
|
||||
imported_macros: Vec<ast::MacroDef>,
|
||||
user_exts: Vec<NamedSyntaxExtension>,
|
||||
c: Crate) -> Crate {
|
||||
pub fn expand_crate<'feat>(parse_sess: &parse::ParseSess,
|
||||
cfg: ExpansionConfig<'feat>,
|
||||
// these are the macros being imported to this crate:
|
||||
imported_macros: Vec<ast::MacroDef>,
|
||||
user_exts: Vec<NamedSyntaxExtension>,
|
||||
c: Crate) -> Crate {
|
||||
let mut cx = ExtCtxt::new(parse_sess, c.config.clone(), cfg);
|
||||
cx.use_std = std_inject::use_std(&c);
|
||||
|
||||
@ -1597,7 +1605,7 @@ mod test {
|
||||
// these following tests are quite fragile, in that they don't test what
|
||||
// *kind* of failure occurs.
|
||||
|
||||
fn test_ecfg() -> ExpansionConfig {
|
||||
fn test_ecfg() -> ExpansionConfig<'static> {
|
||||
ExpansionConfig::default("test".to_string())
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user