add Macro Exterminator
the Macro Exterminator ensures that there are no macro invocations in an AST. This should help make later passes confident that there aren't hidden items, methods, expressions, etc.
This commit is contained in:
parent
53642eed80
commit
c253b3675a
@ -259,6 +259,8 @@ pub fn phase_2_configure_and_expand(sess: &Session,
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// JBC: make CFG processing part of expansion to avoid this problem:
|
||||||
|
|
||||||
// strip again, in case expansion added anything with a #[cfg].
|
// strip again, in case expansion added anything with a #[cfg].
|
||||||
krate = time(time_passes, "configuration 2", krate, |krate|
|
krate = time(time_passes, "configuration 2", krate, |krate|
|
||||||
front::config::strip_unconfigured_items(krate));
|
front::config::strip_unconfigured_items(krate));
|
||||||
@ -279,6 +281,9 @@ pub fn phase_2_configure_and_expand(sess: &Session,
|
|||||||
krate.encode(&mut json).unwrap();
|
krate.encode(&mut json).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
time(time_passes, "checking that all macro invocations are gone", &krate, |krate|
|
||||||
|
syntax::ext::expand::check_for_macros(&sess.parse_sess, krate));
|
||||||
|
|
||||||
Some((krate, map))
|
Some((krate, map))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,6 +296,7 @@ pub struct CrateAnalysis {
|
|||||||
pub name: String,
|
pub name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Run the resolution, typechecking, region checking and other
|
/// Run the resolution, typechecking, region checking and other
|
||||||
/// miscellaneous analysis passes on the crate. Return various
|
/// miscellaneous analysis passes on the crate. Return various
|
||||||
/// structures carrying the results of the analysis.
|
/// structures carrying the results of the analysis.
|
||||||
@ -298,7 +304,6 @@ pub fn phase_3_run_analysis_passes(sess: Session,
|
|||||||
krate: &ast::Crate,
|
krate: &ast::Crate,
|
||||||
ast_map: syntax::ast_map::Map,
|
ast_map: syntax::ast_map::Map,
|
||||||
name: String) -> CrateAnalysis {
|
name: String) -> CrateAnalysis {
|
||||||
|
|
||||||
let time_passes = sess.time_passes();
|
let time_passes = sess.time_passes();
|
||||||
|
|
||||||
time(time_passes, "external crate/lib resolution", (), |_|
|
time(time_passes, "external crate/lib resolution", (), |_|
|
||||||
|
@ -1151,6 +1151,25 @@ fn original_span(cx: &ExtCtxt) -> Gc<codemap::ExpnInfo> {
|
|||||||
return einfo;
|
return einfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Check that there are no macro invocations left in the AST:
|
||||||
|
pub fn check_for_macros(sess: &parse::ParseSess, krate: &ast::Crate) {
|
||||||
|
visit::walk_crate(&mut MacroExterminator{sess:sess}, krate, ());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A visitor that ensures that no macro invocations remain in an AST.
|
||||||
|
struct MacroExterminator<'a>{
|
||||||
|
sess: &'a parse::ParseSess
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> visit::Visitor<()> for MacroExterminator<'a> {
|
||||||
|
fn visit_mac(&mut self, macro: &ast::Mac, _:()) {
|
||||||
|
self.sess.span_diagnostic.span_bug(macro.span,
|
||||||
|
"macro exterminator: expected AST \
|
||||||
|
with no macro invocations");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::{pattern_bindings, expand_crate, contains_macro_escape};
|
use super::{pattern_bindings, expand_crate, contains_macro_escape};
|
||||||
|
Loading…
Reference in New Issue
Block a user