提交 5bf385be 编写于 作者: K Keegan McAllister

Rename macro_escape to macro_use

In the future we want to support

    #[macro_use(foo, bar)]
    mod macros;

but it's not an essential part of macro reform.  Reserve the syntax for now.
上级 fc584793
......@@ -54,7 +54,8 @@
// Needed for the vec! macro
pub use alloc::boxed;
#[macro_escape]
#[cfg_attr(stage0, macro_escape)]
#[cfg_attr(not(stage0), macro_use)]
mod macros;
pub mod binary_heap;
......
......@@ -62,19 +62,23 @@
#![feature(default_type_params, unboxed_closures, associated_types)]
#![deny(missing_docs)]
#[macro_escape]
#[cfg_attr(stage0, macro_escape)]
#[cfg_attr(not(stage0), macro_use)]
mod macros;
#[path = "num/float_macros.rs"]
#[macro_escape]
#[cfg_attr(stage0, macro_escape)]
#[cfg_attr(not(stage0), macro_use)]
mod float_macros;
#[path = "num/int_macros.rs"]
#[macro_escape]
#[cfg_attr(stage0, macro_escape)]
#[cfg_attr(not(stage0), macro_use)]
mod int_macros;
#[path = "num/uint_macros.rs"]
#[macro_escape]
#[cfg_attr(stage0, macro_escape)]
#[cfg_attr(not(stage0), macro_use)]
mod uint_macros;
#[path = "num/int.rs"] pub mod int;
......
......@@ -14,7 +14,8 @@
use core::ops::{Add, Sub, Mul, Div, Rem};
use core::kinds::Copy;
#[macro_escape]
#[cfg_attr(stage0, macro_escape)]
#[cfg_attr(not(stage0), macro_use)]
mod int_macros;
mod i8;
......@@ -23,7 +24,8 @@
mod i64;
mod int;
#[macro_escape]
#[cfg_attr(stage0, macro_escape)]
#[cfg_attr(not(stage0), macro_use)]
mod uint_macros;
mod u8;
......
......@@ -183,7 +183,8 @@
use directive::LOG_LEVEL_NAMES;
#[macro_escape]
#[cfg_attr(stage0, macro_escape)]
#[cfg_attr(not(stage0), macro_use)]
pub mod macros;
mod directive;
......
......@@ -182,7 +182,7 @@ pub fn phase_2_configure_and_expand(sess: &Session,
// strip before expansion to allow macros to depend on
// configuration variables e.g/ in
//
// #[macro_escape] #[cfg(foo)]
// #[macro_use] #[cfg(foo)]
// mod bar { macro_rules! baz!(() => {{}}) }
//
// baz! should not use this definition unless foo is enabled.
......
......@@ -16,7 +16,8 @@
pub use self::context::CrateContext;
pub use self::common::gensym_name;
#[macro_escape]
#[cfg_attr(stage0, macro_escape)]
#[cfg_attr(not(stage0), macro_use)]
mod macros;
mod doc;
......
......@@ -49,7 +49,8 @@
// reexported from `clean` so it can be easily updated with the mod itself
pub use clean::SCHEMA_VERSION;
#[macro_escape]
#[cfg_attr(stage0, macro_escape)]
#[cfg_attr(not(stage0), macro_use)]
pub mod externalfiles;
pub mod clean;
......
......@@ -285,7 +285,8 @@
pub mod timer;
pub mod util;
#[macro_escape]
#[cfg_attr(stage0, macro_escape)]
#[cfg_attr(not(stage0), macro_use)]
pub mod test;
/// The default buffer size for various I/O operations
......
......@@ -173,14 +173,17 @@
/* Exported macros */
#[cfg(stage0)]
#[macro_escape]
#[cfg_attr(stage0, macro_escape)]
#[cfg_attr(not(stage0), macro_use)]
pub mod macros_stage0;
#[cfg(not(stage0))]
#[macro_escape]
#[cfg_attr(stage0, macro_escape)]
#[cfg_attr(not(stage0), macro_use)]
pub mod macros;
#[macro_escape]
#[cfg_attr(stage0, macro_escape)]
#[cfg_attr(not(stage0), macro_use)]
pub mod bitflags;
mod rtdeps;
......@@ -193,15 +196,18 @@
/* Primitive types */
#[path = "num/float_macros.rs"]
#[macro_escape]
#[cfg_attr(stage0, macro_escape)]
#[cfg_attr(not(stage0), macro_use)]
mod float_macros;
#[path = "num/int_macros.rs"]
#[macro_escape]
#[cfg_attr(stage0, macro_escape)]
#[cfg_attr(not(stage0), macro_use)]
mod int_macros;
#[path = "num/uint_macros.rs"]
#[macro_escape]
#[cfg_attr(stage0, macro_escape)]
#[cfg_attr(not(stage0), macro_use)]
mod uint_macros;
#[path = "num/int.rs"] pub mod int;
......@@ -229,7 +235,8 @@
/* Runtime and platform support */
#[macro_escape]
#[cfg_attr(stage0, macro_escape)]
#[cfg_attr(not(stage0), macro_use)]
pub mod thread_local;
pub mod c_str;
......
......@@ -39,6 +39,8 @@
pub mod backtrace;
// Internals
#[cfg_attr(stage0, macro_escape)]
#[cfg_attr(not(stage0), macro_use)]
mod macros;
// These should be refactored/moved/made private over time
......
......@@ -40,7 +40,8 @@
use cell::UnsafeCell;
#[macro_escape]
#[cfg_attr(stage0, macro_escape)]
#[cfg_attr(not(stage0), macro_use)]
pub mod scoped;
// Sure wish we had macro hygiene, no?
......
......@@ -440,9 +440,9 @@ pub fn expand_item(it: P<ast::Item>, fld: &mut MacroExpander)
if valid_ident {
fld.cx.mod_push(it.ident);
}
let macro_escape = contains_macro_escape(new_attrs[]);
let macro_use = contains_macro_use(fld, new_attrs[]);
let result = with_exts_frame!(fld.cx.syntax_env,
macro_escape,
macro_use,
noop_fold_item(it, fld));
if valid_ident {
fld.cx.mod_pop();
......@@ -522,9 +522,28 @@ fn expand_item_underscore(item: ast::Item_, fld: &mut MacroExpander) -> ast::Ite
}
}
// does this attribute list contain "macro_escape" ?
fn contains_macro_escape(attrs: &[ast::Attribute]) -> bool {
attr::contains_name(attrs, "macro_escape")
// does this attribute list contain "macro_use" ?
fn contains_macro_use(fld: &mut MacroExpander, attrs: &[ast::Attribute]) -> bool {
for attr in attrs.iter() {
let mut is_use = attr.check_name("macro_use");
if attr.check_name("macro_escape") {
fld.cx.span_warn(attr.span, "macro_escape is a deprecated synonym for macro_use");
is_use = true;
if let ast::AttrInner = attr.node.style {
fld.cx.span_help(attr.span, "consider an outer attribute, \
#[macro_use] mod ...");
}
};
if is_use {
match attr.node.value.node {
ast::MetaWord(..) => (),
_ => fld.cx.span_err(attr.span, "arguments to macro_use are not allowed here"),
}
return true;
}
}
false
}
// Support for item-position macro invocations, exactly the same
......@@ -1299,7 +1318,7 @@ fn visit_mac(&mut self, macro: &ast::Mac) {
#[cfg(test)]
mod test {
use super::{pattern_bindings, expand_crate, contains_macro_escape};
use super::{pattern_bindings, expand_crate, contains_macro_use};
use super::{PatIdentFinder, IdentRenamer, PatIdentRenamer, ExpansionConfig};
use ast;
use ast::{Attribute_, AttrOuter, MetaWord, Name};
......@@ -1396,9 +1415,9 @@ fn test_ecfg() -> ExpansionConfig {
expand_crate(&sess,test_ecfg(),vec!(),vec!(),crate_ast);
}
// macro_escape modules should allow macros to escape
// macro_use modules should allow macros to escape
#[test] fn macros_can_escape_flattened_mods_test () {
let src = "#[macro_escape] mod foo {macro_rules! z (() => (3+4));}\
let src = "#[macro_use] mod foo {macro_rules! z (() => (3+4));}\
fn inty() -> int { z!() }".to_string();
let sess = parse::new_parse_sess();
let crate_ast = parse::parse_crate_from_source_str(
......@@ -1408,16 +1427,6 @@ fn test_ecfg() -> ExpansionConfig {
expand_crate(&sess, test_ecfg(), vec!(), vec!(), crate_ast);
}
#[test] fn test_contains_flatten (){
let attr1 = make_dummy_attr ("foo");
let attr2 = make_dummy_attr ("bar");
let escape_attr = make_dummy_attr ("macro_escape");
let attrs1 = vec!(attr1.clone(), escape_attr, attr2.clone());
assert_eq!(contains_macro_escape(attrs1[]),true);
let attrs2 = vec!(attr1,attr2);
assert_eq!(contains_macro_escape(attrs2[]),false);
}
// make a MetaWord outer attribute with the given name
fn make_dummy_attr(s: &str) -> ast::Attribute {
Spanned {
......
......@@ -24,7 +24,8 @@
use std::str;
use std::iter;
#[macro_escape]
#[cfg_attr(stage0, macro_escape)]
#[cfg_attr(not(stage0), macro_use)]
pub mod parser;
pub mod lexer;
......
// Copyright 2013-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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#[macro_use(foo, bar)] //~ ERROR arguments to macro_use are not allowed here
mod foo {
}
fn main() {
}
......@@ -16,7 +16,7 @@
#![feature(macro_rules)]
#[cfg(foo)]
#[macro_escape]
#[macro_use]
mod foo {
macro_rules! bar {
() => { true }
......@@ -24,7 +24,7 @@ mod foo {
}
#[cfg(not(foo))]
#[macro_escape]
#[macro_use]
mod foo {
macro_rules! bar {
() => { false }
......
......@@ -16,7 +16,7 @@
#![feature(macro_rules)]
#[cfg(foo)]
#[macro_escape]
#[macro_use]
mod foo {
macro_rules! bar {
() => { true }
......@@ -24,7 +24,7 @@ mod foo {
}
#[cfg(not(foo))]
#[macro_escape]
#[macro_use]
mod foo {
macro_rules! bar {
() => { false }
......
// Copyright 2013-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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-pretty
mod foo {
#![macro_escape] //~ WARNING macro_escape is a deprecated synonym for macro_use
//~^ HELP consider an outer attribute
}
fn main() {
}
// Copyright 2013-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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-pretty
#[macro_escape] //~ WARNING macro_escape is a deprecated synonym for macro_use
mod foo {
}
fn main() {
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册