Skip to content

Commit

Permalink
libsyntax: Pass feature set in ExpansionConfig, not just enable_quotes.
Browse files Browse the repository at this point in the history
  • Loading branch information
pnkfelix committed Feb 15, 2015
1 parent cf636c2 commit 20d8222
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 5 additions & 4 deletions src/libsyntax/ext/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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> ,
Expand All @@ -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,
Expand Down
32 changes: 20 additions & 12 deletions src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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())
}

Expand Down

0 comments on commit 20d8222

Please sign in to comment.