From 0816255c80ee3f2a8870ee5e4379e3739d8ed72e Mon Sep 17 00:00:00 2001 From: Keegan McAllister Date: Thu, 1 Jan 2015 16:37:47 -0800 Subject: Move #[macro_reexport] to extern crate --- src/libsyntax/ast.rs | 1 + src/libsyntax/ext/base.rs | 10 ++++++++++ src/libsyntax/ext/expand.rs | 22 ++++----------------- src/libsyntax/ext/tt/reexport.rs | 41 ---------------------------------------- src/libsyntax/lib.rs | 1 - 5 files changed, 15 insertions(+), 60 deletions(-) delete mode 100644 src/libsyntax/ext/tt/reexport.rs (limited to 'src/libsyntax') diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 36fc8a691dc..e34060a73c1 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1708,6 +1708,7 @@ pub struct MacroDef { pub id: NodeId, pub span: Span, pub imported_from: Option, + pub export: bool, pub body: Vec, } diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 9a06745967f..815159e94c8 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -16,6 +16,7 @@ use codemap; use codemap::{CodeMap, Span, ExpnId, ExpnInfo, NO_EXPANSION}; use ext; use ext::expand; +use ext::tt::macro_rules; use parse; use parse::parser; use parse::token; @@ -568,6 +569,15 @@ impl<'a> ExtCtxt<'a> { } } } + + pub fn insert_macro(&mut self, def: ast::MacroDef) { + if def.export { + self.exported_macros.push(def.clone()); + } + let ext = macro_rules::compile(self, &def); + self.syntax_env.insert(def.ident.name, ext); + } + /// Emit `msg` attached to `sp`, and stop compilation immediately. /// /// `span_err` should be strongly preferred where-ever possible: diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index d56df2d7fb4..6c2b0610fa0 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -17,7 +17,6 @@ use ast; use ast_util::path_to_ident; use ext::mtwt; use ext::build::AstBuilder; -use ext::tt::macro_rules; use attr; use attr::AttrMetaMethods; use codemap; @@ -636,14 +635,10 @@ pub fn expand_item_mac(it: P, id: ast::DUMMY_NODE_ID, span: it.span, imported_from: None, + export: attr::contains_name(it.attrs.as_slice(), "macro_export"), body: tts, }; - let ext = macro_rules::compile(fld.cx, &def); - fld.cx.syntax_env.insert(def.ident.name, ext); - - if attr::contains_name(def.attrs.as_slice(), "macro_export") { - fld.cx.exported_macros.push(def); - } + fld.cx.insert_macro(def); // macro_rules! has a side effect but expands to nothing. fld.cx.bt_pop(); @@ -1178,7 +1173,6 @@ pub struct ExpansionConfig { pub deriving_hash_type_parameter: bool, pub enable_quotes: bool, pub recursion_limit: uint, - pub reexported_macros: Vec, } impl ExpansionConfig { @@ -1188,7 +1182,6 @@ impl ExpansionConfig { deriving_hash_type_parameter: false, enable_quotes: false, recursion_limit: 64, - reexported_macros: vec![], } } } @@ -1202,15 +1195,8 @@ pub fn expand_crate(parse_sess: &parse::ParseSess, let mut cx = ExtCtxt::new(parse_sess, c.config.clone(), cfg); let mut expander = MacroExpander::new(&mut cx); - for def in imported_macros.iter() { - let ext = macro_rules::compile(expander.cx, def); - expander.cx.syntax_env.insert(def.ident.name, ext); - - if expander.cx.ecfg.reexported_macros.iter() - .any(|e| e[] == token::get_ident(def.ident).get()) { - - expander.cx.exported_macros.push(def.clone()); - } + for def in imported_macros.into_iter() { + expander.cx.insert_macro(def); } for (name, extension) in user_exts.into_iter() { diff --git a/src/libsyntax/ext/tt/reexport.rs b/src/libsyntax/ext/tt/reexport.rs deleted file mode 100644 index 104f3787253..00000000000 --- a/src/libsyntax/ext/tt/reexport.rs +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Defines the crate attribute syntax for macro re-export. - -use ast; -use attr::AttrMetaMethods; -use diagnostic::SpanHandler; - -/// Return a vector of the names of all macros re-exported from the crate. -pub fn gather(diag: &SpanHandler, krate: &ast::Crate) -> Vec { - let usage = "malformed macro_reexport attribute, expected \ - #![macro_reexport(ident, ident, ...)]"; - - let mut reexported: Vec = vec!(); - for attr in krate.attrs.iter() { - if !attr.check_name("macro_reexport") { - continue; - } - - match attr.meta_item_list() { - None => diag.span_err(attr.span, usage), - Some(list) => for mi in list.iter() { - match mi.node { - ast::MetaWord(ref word) - => reexported.push(word.to_string()), - _ => diag.span_err(mi.span, usage), - } - } - } - } - - reexported -} diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 774a9f61cf9..b7bfd346d50 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -111,6 +111,5 @@ pub mod ext { pub mod transcribe; pub mod macro_parser; pub mod macro_rules; - pub mod reexport; } } -- cgit 1.4.1-3-g733a5