1 // Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
20 struct MacroRegistrarContext {
21 registrars: Vec<(ast::NodeId, Span)> ,
24 impl Visitor<()> for MacroRegistrarContext {
25 fn visit_item(&mut self, item: &ast::Item, _: ()) {
28 if attr::contains_name(item.attrs.as_slice(),
30 self.registrars.push((item.id, item.span));
36 visit::walk_item(self, item, ());
40 pub fn find_macro_registrar(diagnostic: @diagnostic::SpanHandler,
41 krate: &ast::Crate) -> Option<ast::DefId> {
42 let mut ctx = MacroRegistrarContext { registrars: Vec::new() };
43 visit::walk_crate(&mut ctx, krate, ());
45 match ctx.registrars.len() {
48 let (node_id, _) = ctx.registrars.pop().unwrap();
50 krate: ast::LOCAL_CRATE,
55 diagnostic.handler().err("multiple macro registration functions found");
56 for &(_, span) in ctx.registrars.iter() {
57 diagnostic.span_note(span, "one is here");
59 diagnostic.handler().abort_if_errors();