about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-09-29 17:18:07 +0000
committerbors <bors@rust-lang.org>2014-09-29 17:18:07 +0000
commit1f3cda8bd8496c3b3771b0201d1073ed575321d0 (patch)
tree0acaf08d99d544c93df6f688fa96ce40e747588f /src/libsyntax
parent5079a10b1e9d87fa0b0d50f1456f920b1ba8323c (diff)
parentd3e171861f0fd8f3a61ad28d70f675ea9dc712b8 (diff)
downloadrust-1f3cda8bd8496c3b3771b0201d1073ed575321d0.tar.gz
rust-1f3cda8bd8496c3b3771b0201d1073ed575321d0.zip
auto merge of #17629 : alexcrichton/rust/rollup, r=alexcrichton
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ast.rs5
-rw-r--r--src/libsyntax/codemap.rs14
-rw-r--r--src/libsyntax/ext/asm.rs13
-rw-r--r--src/libsyntax/ext/base.rs57
-rw-r--r--src/libsyntax/ext/expand.rs43
-rw-r--r--src/libsyntax/feature_gate.rs17
-rw-r--r--src/libsyntax/fold.rs6
-rw-r--r--src/libsyntax/lib.rs1
-rw-r--r--src/libsyntax/parse/parser.rs6
-rw-r--r--src/libsyntax/parse/token.rs57
-rw-r--r--src/libsyntax/print/pprust.rs4
-rw-r--r--src/libsyntax/test.rs5
12 files changed, 122 insertions, 106 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs
index 38d8136c1a1..0fee3ff3218 100644
--- a/src/libsyntax/ast.rs
+++ b/src/libsyntax/ast.rs
@@ -10,7 +10,7 @@
 
 // The Rust abstract syntax tree.
 
-use codemap::{Span, Spanned, DUMMY_SP};
+use codemap::{Span, Spanned, DUMMY_SP, ExpnId};
 use abi::Abi;
 use ast_util;
 use owned_slice::OwnedSlice;
@@ -983,7 +983,8 @@ pub struct InlineAsm {
     pub clobbers: InternedString,
     pub volatile: bool,
     pub alignstack: bool,
-    pub dialect: AsmDialect
+    pub dialect: AsmDialect,
+    pub expn_id: ExpnId,
 }
 
 /// represents an argument in a function header
diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs
index 9072889463c..e9b2556c53e 100644
--- a/src/libsyntax/codemap.rs
+++ b/src/libsyntax/codemap.rs
@@ -26,6 +26,7 @@ source code snippets, etc.
 use serialize::{Encodable, Decodable, Encoder, Decoder};
 use std::cell::RefCell;
 use std::rc::Rc;
+use libc::c_uint;
 
 pub trait Pos {
     fn from_uint(n: uint) -> Self;
@@ -223,11 +224,22 @@ pub struct ExpnInfo {
     pub callee: NameAndSpan
 }
 
-#[deriving(PartialEq, Eq, Clone, Show, Hash)]
+#[deriving(PartialEq, Eq, Clone, Show, Hash, Encodable, Decodable)]
 pub struct ExpnId(u32);
 
 pub static NO_EXPANSION: ExpnId = ExpnId(-1);
 
+impl ExpnId {
+    pub fn from_llvm_cookie(cookie: c_uint) -> ExpnId {
+        ExpnId(cookie as u32)
+    }
+
+    pub fn to_llvm_cookie(self) -> i32 {
+        let ExpnId(cookie) = self;
+        cookie as i32
+    }
+}
+
 pub type FileName = String;
 
 pub struct FileLines {
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
diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs
index cd0fa184a09..1c6ee8acc94 100644
--- a/src/libsyntax/feature_gate.rs
+++ b/src/libsyntax/feature_gate.rs
@@ -102,6 +102,7 @@ pub struct Features {
     pub rustc_diagnostic_macros: bool,
     pub import_shadowing: bool,
     pub visible_private_types: bool,
+    pub quote: bool,
 }
 
 impl Features {
@@ -112,6 +113,7 @@ impl Features {
             rustc_diagnostic_macros: false,
             import_shadowing: false,
             visible_private_types: false,
+            quote: false,
         }
     }
 }
@@ -282,10 +284,6 @@ impl<'a, 'v> Visitor<'v> for Context<'a> {
     fn visit_mac(&mut self, macro: &ast::Mac) {
         let ast::MacInvocTT(ref path, _, _) = macro.node;
         let id = path.segments.last().unwrap().identifier;
-        let quotes = ["quote_tokens", "quote_expr", "quote_ty",
-                      "quote_item", "quote_pat", "quote_stmt"];
-        let msg = " is not stable enough for use and are subject to change";
-
 
         if id == token::str_to_ident("macro_rules") {
             self.gate_feature("macro_rules", path.span, "macro definitions are \
@@ -311,16 +309,6 @@ impl<'a, 'v> Visitor<'v> for Context<'a> {
             self.gate_feature("concat_idents", path.span, "`concat_idents` is not \
                 stable enough for use and is subject to change");
         }
-
-        else {
-            for &quote in quotes.iter() {
-                if id == token::str_to_ident(quote) {
-                  self.gate_feature("quote",
-                                    path.span,
-                                    format!("{}{}", quote, msg).as_slice());
-                }
-            }
-        }
     }
 
     fn visit_foreign_item(&mut self, i: &ast::ForeignItem) {
@@ -483,6 +471,7 @@ pub fn check_crate(span_handler: &SpanHandler, krate: &ast::Crate) -> (Features,
         rustc_diagnostic_macros: cx.has_feature("rustc_diagnostic_macros"),
         import_shadowing: cx.has_feature("import_shadowing"),
         visible_private_types: cx.has_feature("visible_private_types"),
+        quote: cx.has_feature("quote"),
     },
     unknown_features)
 }
diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs
index 91a339a73f7..53be7f2c20c 100644
--- a/src/libsyntax/fold.rs
+++ b/src/libsyntax/fold.rs
@@ -1279,7 +1279,8 @@ pub fn noop_fold_expr<T: Folder>(Expr {id, node, span}: Expr, folder: &mut T) ->
                 clobbers,
                 volatile,
                 alignstack,
-                dialect
+                dialect,
+                expn_id,
             }) => ExprInlineAsm(InlineAsm {
                 inputs: inputs.move_map(|(c, input)| {
                     (c, folder.fold_expr(input))
@@ -1292,7 +1293,8 @@ pub fn noop_fold_expr<T: Folder>(Expr {id, node, span}: Expr, folder: &mut T) ->
                 clobbers: clobbers,
                 volatile: volatile,
                 alignstack: alignstack,
-                dialect: dialect
+                dialect: dialect,
+                expn_id: expn_id,
             }),
             ExprMac(mac) => ExprMac(folder.fold_mac(mac)),
             ExprStruct(path, fields, maybe_expr) => {
diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs
index 7a504d22c1e..a4271544146 100644
--- a/src/libsyntax/lib.rs
+++ b/src/libsyntax/lib.rs
@@ -33,6 +33,7 @@ extern crate debug;
 #[phase(plugin, link)] extern crate log;
 extern crate serialize;
 extern crate term;
+extern crate libc;
 
 pub mod util {
     pub mod interner;
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index cbc710821f9..415ff6a4097 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -2084,7 +2084,7 @@ impl<'a> Parser<'a> {
                                     ExprBlock(blk));
             },
             token::BINOP(token::OR) |  token::OROR => {
-                return self.parse_lambda_expr(CaptureByValue);
+                return self.parse_lambda_expr(CaptureByRef);
             },
             // FIXME #13626: Should be able to stick in
             // token::SELF_KEYWORD_NAME
@@ -2135,8 +2135,8 @@ impl<'a> Parser<'a> {
                 hi = self.last_span.hi;
             }
             _ => {
-                if self.eat_keyword(keywords::Ref) {
-                    return self.parse_lambda_expr(CaptureByRef);
+                if self.eat_keyword(keywords::Move) {
+                    return self.parse_lambda_expr(CaptureByValue);
                 }
                 if self.eat_keyword(keywords::Proc) {
                     let decl = self.parse_proc_decl();
diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs
index f71190da430..a486ac40a97 100644
--- a/src/libsyntax/parse/token.rs
+++ b/src/libsyntax/parse/token.rs
@@ -482,40 +482,41 @@ declare_special_idents_and_keywords! {
         (25,                         Loop,       "loop");
         (26,                         Match,      "match");
         (27,                         Mod,        "mod");
-        (28,                         Mut,        "mut");
-        (29,                         Once,       "once");
-        (30,                         Pub,        "pub");
-        (31,                         Ref,        "ref");
-        (32,                         Return,     "return");
+        (28,                         Move,       "move");
+        (29,                         Mut,        "mut");
+        (30,                         Once,       "once");
+        (31,                         Pub,        "pub");
+        (32,                         Ref,        "ref");
+        (33,                         Return,     "return");
         // Static and Self are also special idents (prefill de-dupes)
         (super::STATIC_KEYWORD_NAME_NUM, Static, "static");
         (super::SELF_KEYWORD_NAME_NUM,   Self,   "self");
-        (33,                         Struct,     "struct");
+        (34,                         Struct,     "struct");
         (super::SUPER_KEYWORD_NAME_NUM, Super,   "super");
-        (34,                         True,       "true");
-        (35,                         Trait,      "trait");
-        (36,                         Type,       "type");
-        (37,                         Unsafe,     "unsafe");
-        (38,                         Use,        "use");
-        (39,                         Virtual,    "virtual");
-        (40,                         While,      "while");
-        (41,                         Continue,   "continue");
-        (42,                         Proc,       "proc");
-        (43,                         Box,        "box");
-        (44,                         Const,      "const");
-        (45,                         Where,      "where");
+        (35,                         True,       "true");
+        (36,                         Trait,      "trait");
+        (37,                         Type,       "type");
+        (38,                         Unsafe,     "unsafe");
+        (39,                         Use,        "use");
+        (40,                         Virtual,    "virtual");
+        (41,                         While,      "while");
+        (42,                         Continue,   "continue");
+        (43,                         Proc,       "proc");
+        (44,                         Box,        "box");
+        (45,                         Const,      "const");
+        (46,                         Where,      "where");
 
         'reserved:
-        (46,                         Alignof,    "alignof");
-        (47,                         Be,         "be");
-        (48,                         Offsetof,   "offsetof");
-        (49,                         Priv,       "priv");
-        (50,                         Pure,       "pure");
-        (51,                         Sizeof,     "sizeof");
-        (52,                         Typeof,     "typeof");
-        (53,                         Unsized,    "unsized");
-        (54,                         Yield,      "yield");
-        (55,                         Do,         "do");
+        (47,                         Alignof,    "alignof");
+        (48,                         Be,         "be");
+        (49,                         Offsetof,   "offsetof");
+        (50,                         Priv,       "priv");
+        (51,                         Pure,       "pure");
+        (52,                         Sizeof,     "sizeof");
+        (53,                         Typeof,     "typeof");
+        (54,                         Unsized,    "unsized");
+        (55,                         Yield,      "yield");
+        (56,                         Do,         "do");
     }
 }
 
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs
index 1fbd4af8627..ae4ba611bab 100644
--- a/src/libsyntax/print/pprust.rs
+++ b/src/libsyntax/print/pprust.rs
@@ -2176,8 +2176,8 @@ impl<'a> State<'a> {
     pub fn print_capture_clause(&mut self, capture_clause: ast::CaptureClause)
                                 -> IoResult<()> {
         match capture_clause {
-            ast::CaptureByValue => Ok(()),
-            ast::CaptureByRef => self.word_space("ref"),
+            ast::CaptureByValue => self.word_space("move"),
+            ast::CaptureByRef => Ok(()),
         }
     }
 
diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs
index 091b0ce8ed9..828a6124aa0 100644
--- a/src/libsyntax/test.rs
+++ b/src/libsyntax/test.rs
@@ -235,10 +235,7 @@ fn generate_test_harness(sess: &ParseSess,
         sess: sess,
         span_diagnostic: sd,
         ext_cx: ExtCtxt::new(sess, cfg.clone(),
-                             ExpansionConfig {
-                                 deriving_hash_type_parameter: false,
-                                 crate_name: "test".to_string(),
-                             }),
+                             ExpansionConfig::default("test".to_string())),
         path: Vec::new(),
         testfns: Vec::new(),
         reexport_test_harness_main: reexport_test_harness_main,