提交 20d8222e 编写于 作者: F Felix S. Klock II

libsyntax: Pass feature set in ExpansionConfig, not just enable_quotes.

上级 cf636c23
......@@ -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 @@ pub fn new() -> 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 builtin_normal_expander(f: MacroExpanderFn) -> SyntaxExtension {
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 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 @@ fn crate_idents(the_crate: &ast::Crate) -> Vec<ast::Ident> {
// 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())
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册