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