提交 c253b367 编写于 作者: J John Clements

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.
上级 53642eed
......@@ -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].
krate = time(time_passes, "configuration 2", krate, |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();
}
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))
}
......@@ -291,6 +296,7 @@ pub struct CrateAnalysis {
pub name: String,
}
/// Run the resolution, typechecking, region checking and other
/// miscellaneous analysis passes on the crate. Return various
/// structures carrying the results of the analysis.
......@@ -298,7 +304,6 @@ pub fn phase_3_run_analysis_passes(sess: Session,
krate: &ast::Crate,
ast_map: syntax::ast_map::Map,
name: String) -> CrateAnalysis {
let time_passes = sess.time_passes();
time(time_passes, "external crate/lib resolution", (), |_|
......
......@@ -1151,6 +1151,25 @@ fn original_span(cx: &ExtCtxt) -> Gc<codemap::ExpnInfo> {
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)]
mod test {
use super::{pattern_bindings, expand_crate, contains_macro_escape};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册