Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Move fields single_step and keep_macs from MacroExpander to `Ex…
…pansionConfig`.
  • Loading branch information
jseyfried committed Sep 15, 2016
1 parent d1acabe commit 21ba816
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/librustc_driver/driver.rs
Expand Up @@ -674,11 +674,11 @@ pub fn phase_2_configure_and_expand<'a, F>(sess: &Session,
}
let features = sess.features.borrow();
let cfg = syntax::ext::expand::ExpansionConfig {
crate_name: crate_name.to_string(),
features: Some(&features),
recursion_limit: sess.recursion_limit.get(),
trace_mac: sess.opts.debugging_opts.trace_macros,
should_test: sess.opts.test,
..syntax::ext::expand::ExpansionConfig::default(crate_name.to_string())
};
let mut ecx = ExtCtxt::new(&sess.parse_sess, krate.config.clone(), cfg, &mut resolver);
let ret = syntax::ext::expand::expand_crate(&mut ecx, syntax_exts, krate);
Expand Down
17 changes: 7 additions & 10 deletions src/libsyntax/ext/expand.rs
Expand Up @@ -173,19 +173,12 @@ impl Invocation {

pub struct MacroExpander<'a, 'b:'a> {
pub cx: &'a mut ExtCtxt<'b>,
pub single_step: bool,
pub keep_macs: bool,
monotonic: bool, // c.f. `cx.monotonic_expander()`
}

impl<'a, 'b> MacroExpander<'a, 'b> {
pub fn new(cx: &'a mut ExtCtxt<'b>, monotonic: bool) -> Self {
MacroExpander {
cx: cx,
monotonic: monotonic,
single_step: false,
keep_macs: false,
}
MacroExpander { cx: cx, monotonic: monotonic }
}

fn expand_crate(&mut self, mut krate: ast::Crate) -> ast::Crate {
Expand Down Expand Up @@ -238,7 +231,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
expansions.push(Vec::new());
}
expansions[depth].push((mark.as_u32(), expansion));
if !self.single_step {
if !self.cx.ecfg.single_step {
invocations.extend(new_invocations.into_iter().rev());
}
}
Expand Down Expand Up @@ -417,7 +410,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
self.cx.insert_macro(def.clone());

// If keep_macs is true, expands to a MacEager::items instead.
if self.keep_macs {
if self.cx.ecfg.keep_macs {
Some(placeholders::reconstructed_macro_rules(&def, &path))
} else {
Some(placeholders::macro_scope_placeholder())
Expand Down Expand Up @@ -726,6 +719,8 @@ pub struct ExpansionConfig<'feat> {
pub recursion_limit: usize,
pub trace_mac: bool,
pub should_test: bool, // If false, strip `#[test]` nodes
pub single_step: bool,
pub keep_macs: bool,
}

macro_rules! feature_tests {
Expand All @@ -749,6 +744,8 @@ impl<'feat> ExpansionConfig<'feat> {
recursion_limit: 64,
trace_mac: false,
should_test: false,
single_step: false,
keep_macs: false,
}
}

Expand Down

0 comments on commit 21ba816

Please sign in to comment.