diff options
| author | bors <bors@rust-lang.org> | 2014-09-29 17:18:07 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-09-29 17:18:07 +0000 |
| commit | 1f3cda8bd8496c3b3771b0201d1073ed575321d0 (patch) | |
| tree | 0acaf08d99d544c93df6f688fa96ce40e747588f /src/libsyntax/ext | |
| parent | 5079a10b1e9d87fa0b0d50f1456f920b1ba8323c (diff) | |
| parent | d3e171861f0fd8f3a61ad28d70f675ea9dc712b8 (diff) | |
| download | rust-1f3cda8bd8496c3b3771b0201d1073ed575321d0.tar.gz rust-1f3cda8bd8496c3b3771b0201d1073ed575321d0.zip | |
auto merge of #17629 : alexcrichton/rust/rollup, r=alexcrichton
Diffstat (limited to 'src/libsyntax/ext')
| -rw-r--r-- | src/libsyntax/ext/asm.rs | 13 | ||||
| -rw-r--r-- | src/libsyntax/ext/base.rs | 57 | ||||
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 43 |
3 files changed, 63 insertions, 50 deletions
diff --git a/src/libsyntax/ext/asm.rs b/src/libsyntax/ext/asm.rs index 4b8c3376cad..702be0c0eee 100644 --- a/src/libsyntax/ext/asm.rs +++ b/src/libsyntax/ext/asm.rs @@ -13,6 +13,7 @@ */ use ast; +use codemap; use codemap::Span; use ext::base; use ext::base::*; @@ -198,6 +199,15 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) } } + let expn_id = cx.codemap().record_expansion(codemap::ExpnInfo { + call_site: sp, + callee: codemap::NameAndSpan { + name: "asm".to_string(), + format: codemap::MacroBang, + span: None, + }, + }); + MacExpr::new(P(ast::Expr { id: ast::DUMMY_NODE_ID, node: ast::ExprInlineAsm(ast::InlineAsm { @@ -208,7 +218,8 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) clobbers: token::intern_and_get_ident(cons.as_slice()), volatile: volatile, alignstack: alignstack, - dialect: dialect + dialect: dialect, + expn_id: expn_id, }), span: sp })) diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 8bf13e20fed..212cd33e16e 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -344,7 +344,7 @@ impl BlockInfo { /// The base map of methods for expanding syntax extension /// AST nodes into full ASTs -fn initial_syntax_expander_table() -> SyntaxEnv { +fn initial_syntax_expander_table(ecfg: &expand::ExpansionConfig) -> SyntaxEnv { // utility function to simplify creating NormalTT syntax extensions fn builtin_normal_expander(f: MacroExpanderFn) -> SyntaxExtension { NormalTT(box f, None) @@ -383,31 +383,33 @@ fn initial_syntax_expander_table() -> SyntaxEnv { syntax_expanders.insert(intern("deriving"), Decorator(box ext::deriving::expand_meta_deriving)); - // Quasi-quoting expanders - syntax_expanders.insert(intern("quote_tokens"), - builtin_normal_expander( - ext::quote::expand_quote_tokens)); - syntax_expanders.insert(intern("quote_expr"), - builtin_normal_expander( - ext::quote::expand_quote_expr)); - syntax_expanders.insert(intern("quote_ty"), - builtin_normal_expander( - ext::quote::expand_quote_ty)); - syntax_expanders.insert(intern("quote_method"), - builtin_normal_expander( - ext::quote::expand_quote_method)); - syntax_expanders.insert(intern("quote_item"), - builtin_normal_expander( - ext::quote::expand_quote_item)); - syntax_expanders.insert(intern("quote_pat"), - builtin_normal_expander( - ext::quote::expand_quote_pat)); - syntax_expanders.insert(intern("quote_arm"), - builtin_normal_expander( - ext::quote::expand_quote_arm)); - syntax_expanders.insert(intern("quote_stmt"), - builtin_normal_expander( - ext::quote::expand_quote_stmt)); + if ecfg.enable_quotes { + // Quasi-quoting expanders + syntax_expanders.insert(intern("quote_tokens"), + builtin_normal_expander( + ext::quote::expand_quote_tokens)); + syntax_expanders.insert(intern("quote_expr"), + builtin_normal_expander( + ext::quote::expand_quote_expr)); + syntax_expanders.insert(intern("quote_ty"), + builtin_normal_expander( + ext::quote::expand_quote_ty)); + syntax_expanders.insert(intern("quote_method"), + builtin_normal_expander( + ext::quote::expand_quote_method)); + syntax_expanders.insert(intern("quote_item"), + builtin_normal_expander( + ext::quote::expand_quote_item)); + syntax_expanders.insert(intern("quote_pat"), + builtin_normal_expander( + ext::quote::expand_quote_pat)); + syntax_expanders.insert(intern("quote_arm"), + builtin_normal_expander( + ext::quote::expand_quote_arm)); + syntax_expanders.insert(intern("quote_stmt"), + builtin_normal_expander( + ext::quote::expand_quote_stmt)); + } syntax_expanders.insert(intern("line"), builtin_normal_expander( @@ -466,6 +468,7 @@ pub struct ExtCtxt<'a> { impl<'a> ExtCtxt<'a> { pub fn new<'a>(parse_sess: &'a parse::ParseSess, cfg: ast::CrateConfig, ecfg: expand::ExpansionConfig) -> ExtCtxt<'a> { + let env = initial_syntax_expander_table(&ecfg); ExtCtxt { parse_sess: parse_sess, cfg: cfg, @@ -474,7 +477,7 @@ impl<'a> ExtCtxt<'a> { ecfg: ecfg, trace_mac: false, exported_macros: Vec::new(), - syntax_env: initial_syntax_expander_table(), + syntax_env: env, } } diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 70cf41d5e17..9f3df1a7623 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -975,8 +975,19 @@ fn new_span(cx: &ExtCtxt, sp: Span) -> Span { } pub struct ExpansionConfig { - pub deriving_hash_type_parameter: bool, pub crate_name: String, + pub deriving_hash_type_parameter: bool, + pub enable_quotes: bool, +} + +impl ExpansionConfig { + pub fn default(crate_name: String) -> ExpansionConfig { + ExpansionConfig { + crate_name: crate_name, + deriving_hash_type_parameter: false, + enable_quotes: false, + } + } } pub struct ExportedMacros { @@ -1106,7 +1117,7 @@ impl<'a, 'v> Visitor<'v> for MacroExterminator<'a> { #[cfg(test)] mod test { use super::{pattern_bindings, expand_crate, contains_macro_escape}; - use super::{PatIdentFinder, IdentRenamer, PatIdentRenamer}; + use super::{PatIdentFinder, IdentRenamer, PatIdentRenamer, ExpansionConfig}; use ast; use ast::{Attribute_, AttrOuter, MetaWord, Name}; use attr; @@ -1171,6 +1182,10 @@ mod test { // these following tests are quite fragile, in that they don't test what // *kind* of failure occurs. + fn test_ecfg() -> ExpansionConfig { + ExpansionConfig::default("test".to_string()) + } + // make sure that macros can't escape fns #[should_fail] #[test] fn macros_cant_escape_fns_test () { @@ -1182,11 +1197,7 @@ mod test { src, Vec::new(), &sess); // should fail: - let cfg = ::syntax::ext::expand::ExpansionConfig { - deriving_hash_type_parameter: false, - crate_name: "test".to_string(), - }; - expand_crate(&sess,cfg,vec!(),vec!(),crate_ast); + expand_crate(&sess,test_ecfg(),vec!(),vec!(),crate_ast); } // make sure that macros can't escape modules @@ -1199,11 +1210,7 @@ mod test { "<test>".to_string(), src, Vec::new(), &sess); - let cfg = ::syntax::ext::expand::ExpansionConfig { - deriving_hash_type_parameter: false, - crate_name: "test".to_string(), - }; - expand_crate(&sess,cfg,vec!(),vec!(),crate_ast); + expand_crate(&sess,test_ecfg(),vec!(),vec!(),crate_ast); } // macro_escape modules should allow macros to escape @@ -1215,11 +1222,7 @@ mod test { "<test>".to_string(), src, Vec::new(), &sess); - let cfg = ::syntax::ext::expand::ExpansionConfig { - deriving_hash_type_parameter: false, - crate_name: "test".to_string(), - }; - expand_crate(&sess, cfg, vec!(), vec!(), crate_ast); + expand_crate(&sess, test_ecfg(), vec!(), vec!(), crate_ast); } #[test] fn test_contains_flatten (){ @@ -1252,11 +1255,7 @@ mod test { let ps = parse::new_parse_sess(); let crate_ast = string_to_parser(&ps, crate_str).parse_crate_mod(); // the cfg argument actually does matter, here... - let cfg = ::syntax::ext::expand::ExpansionConfig { - deriving_hash_type_parameter: false, - crate_name: "test".to_string(), - }; - expand_crate(&ps,cfg,vec!(),vec!(),crate_ast) + expand_crate(&ps,test_ecfg(),vec!(),vec!(),crate_ast) } // find the pat_ident paths in a crate |
