From 8143662836ccecca0b1f177f0c12528a4aa74c0d Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sat, 28 Dec 2013 22:06:22 -0700 Subject: [PATCH] Start passing around &mut ExtCtxt --- src/libsyntax/ext/asm.rs | 2 +- src/libsyntax/ext/base.rs | 16 ++++++++-------- src/libsyntax/ext/build.rs | 6 +++--- src/libsyntax/ext/bytes.rs | 2 +- src/libsyntax/ext/cfg.rs | 2 +- src/libsyntax/ext/concat.rs | 2 +- src/libsyntax/ext/concat_idents.rs | 2 +- src/libsyntax/ext/env.rs | 4 ++-- src/libsyntax/ext/expand.rs | 6 +++--- src/libsyntax/ext/fmt.rs | 2 +- src/libsyntax/ext/format.rs | 15 ++++++++------- src/libsyntax/ext/log_syntax.rs | 2 +- src/libsyntax/ext/quote.rs | 12 ++++++------ src/libsyntax/ext/source_util.rs | 18 +++++++++--------- src/libsyntax/ext/trace_macros.rs | 2 +- src/libsyntax/ext/tt/macro_rules.rs | 4 ++-- 16 files changed, 49 insertions(+), 48 deletions(-) diff --git a/src/libsyntax/ext/asm.rs b/src/libsyntax/ext/asm.rs index fdde336ffa7..cd7953aac20 100644 --- a/src/libsyntax/ext/asm.rs +++ b/src/libsyntax/ext/asm.rs @@ -37,7 +37,7 @@ fn next_state(s: State) -> Option { } } -pub fn expand_asm(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree]) +pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult { let p = parse::new_parser_from_tts(cx.parse_sess(), cx.cfg(), diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 842f2bfdffc..b5f8329a0b2 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -45,7 +45,7 @@ pub struct SyntaxExpanderTT { pub trait SyntaxExpanderTTTrait { fn expand(&self, - ecx: &ExtCtxt, + ecx: &mut ExtCtxt, span: Span, token_tree: &[ast::token_tree], context: ast::SyntaxContext) @@ -53,7 +53,7 @@ pub trait SyntaxExpanderTTTrait { } pub type SyntaxExpanderTTFunNoCtxt = - fn(ecx: &ExtCtxt, span: codemap::Span, token_tree: &[ast::token_tree]) + fn(ecx: &mut ExtCtxt, span: codemap::Span, token_tree: &[ast::token_tree]) -> MacResult; enum SyntaxExpanderTTExpander { @@ -62,7 +62,7 @@ enum SyntaxExpanderTTExpander { impl SyntaxExpanderTTTrait for SyntaxExpanderTT { fn expand(&self, - ecx: &ExtCtxt, + ecx: &mut ExtCtxt, span: Span, token_tree: &[ast::token_tree], _: ast::SyntaxContext) @@ -87,7 +87,7 @@ pub struct SyntaxExpanderTTItem { pub trait SyntaxExpanderTTItemTrait { fn expand(&self, - cx: &ExtCtxt, + cx: &mut ExtCtxt, sp: Span, ident: ast::Ident, token_tree: ~[ast::token_tree], @@ -97,7 +97,7 @@ pub trait SyntaxExpanderTTItemTrait { impl SyntaxExpanderTTItemTrait for SyntaxExpanderTTItem { fn expand(&self, - cx: &ExtCtxt, + cx: &mut ExtCtxt, sp: Span, ident: ast::Ident, token_tree: ~[ast::token_tree], @@ -115,11 +115,11 @@ impl SyntaxExpanderTTItemTrait for SyntaxExpanderTTItem { } pub type SyntaxExpanderTTItemFun = - fn(&ExtCtxt, Span, ast::Ident, ~[ast::token_tree], ast::SyntaxContext) + fn(&mut ExtCtxt, Span, ast::Ident, ~[ast::token_tree], ast::SyntaxContext) -> MacResult; pub type SyntaxExpanderTTItemFunNoCtxt = - fn(&ExtCtxt, Span, ast::Ident, ~[ast::token_tree]) -> MacResult; + fn(&mut ExtCtxt, Span, ast::Ident, ~[ast::token_tree]) -> MacResult; pub trait AnyMacro { fn make_expr(&self) -> @ast::Expr; @@ -320,7 +320,7 @@ impl ExtCtxt { } } - pub fn expand_expr(&self, mut e: @ast::Expr) -> @ast::Expr { + pub fn expand_expr(&mut self, mut e: @ast::Expr) -> @ast::Expr { loop { match e.node { ast::ExprMac(..) => { diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index f5c3c1792c9..e5f20950412 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -236,7 +236,7 @@ pub trait AstBuilder { vis: ast::visibility, path: ~[ast::Ident]) -> ast::view_item; } -impl<'a> AstBuilder for &'a ExtCtxt { +impl AstBuilder for ExtCtxt { fn path(&self, span: Span, strs: ~[ast::Ident]) -> ast::Path { self.path_all(span, false, strs, opt_vec::Empty, ~[]) } @@ -686,12 +686,12 @@ impl<'a> AstBuilder for &'a ExtCtxt { } fn lambda0(&self, _span: Span, blk: P) -> @ast::Expr { let blk_e = self.expr(blk.span, ast::ExprBlock(blk)); - quote_expr!(*self, || $blk_e ) + quote_expr!(self, || $blk_e ) } fn lambda1(&self, _span: Span, blk: P, ident: ast::Ident) -> @ast::Expr { let blk_e = self.expr(blk.span, ast::ExprBlock(blk)); - quote_expr!(*self, |$ident| $blk_e ) + quote_expr!(self, |$ident| $blk_e ) } fn lambda_expr(&self, span: Span, ids: ~[ast::Ident], expr: @ast::Expr) -> @ast::Expr { diff --git a/src/libsyntax/ext/bytes.rs b/src/libsyntax/ext/bytes.rs index 1ceb2a1668e..1878f6f3c3c 100644 --- a/src/libsyntax/ext/bytes.rs +++ b/src/libsyntax/ext/bytes.rs @@ -18,7 +18,7 @@ use ext::build::AstBuilder; use std::char; -pub fn expand_syntax_ext(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult { +pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult { // Gather all argument expressions let exprs = get_exprs_from_tts(cx, sp, tts); let mut bytes = ~[]; diff --git a/src/libsyntax/ext/cfg.rs b/src/libsyntax/ext/cfg.rs index 2ca8917ed8f..d9fbc33153a 100644 --- a/src/libsyntax/ext/cfg.rs +++ b/src/libsyntax/ext/cfg.rs @@ -25,7 +25,7 @@ use parse; use parse::token; use parse::attr::parser_attr; -pub fn expand_cfg(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult { +pub fn expand_cfg(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult { let p = parse::new_parser_from_tts(cx.parse_sess(), cx.cfg(), tts.to_owned()); let mut cfgs = ~[]; diff --git a/src/libsyntax/ext/concat.rs b/src/libsyntax/ext/concat.rs index b6a81a8bea5..d8be7dedef2 100644 --- a/src/libsyntax/ext/concat.rs +++ b/src/libsyntax/ext/concat.rs @@ -15,7 +15,7 @@ use codemap; use ext::base; use ext::build::AstBuilder; -pub fn expand_syntax_ext(cx: &base::ExtCtxt, +pub fn expand_syntax_ext(cx: &mut base::ExtCtxt, sp: codemap::Span, tts: &[ast::token_tree]) -> base::MacResult { let es = base::get_exprs_from_tts(cx, sp, tts); diff --git a/src/libsyntax/ext/concat_idents.rs b/src/libsyntax/ext/concat_idents.rs index 6b204a243cb..0cb3e781c26 100644 --- a/src/libsyntax/ext/concat_idents.rs +++ b/src/libsyntax/ext/concat_idents.rs @@ -16,7 +16,7 @@ use opt_vec; use parse::token; use parse::token::{str_to_ident}; -pub fn expand_syntax_ext(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree]) +pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult { let mut res_str = ~""; for (i, e) in tts.iter().enumerate() { diff --git a/src/libsyntax/ext/env.rs b/src/libsyntax/ext/env.rs index b5f5f8c41d0..cebd7aac4e3 100644 --- a/src/libsyntax/ext/env.rs +++ b/src/libsyntax/ext/env.rs @@ -22,7 +22,7 @@ use ext::build::AstBuilder; use std::os; -pub fn expand_option_env(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree]) +pub fn expand_option_env(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult { let var = get_single_str_from_tts(cx, sp, tts, "option_env!"); @@ -33,7 +33,7 @@ pub fn expand_option_env(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree]) MRExpr(e) } -pub fn expand_env(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree]) +pub fn expand_env(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult { let exprs = get_exprs_from_tts(cx, sp, tts); diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index e20161ea2d0..eb07353cda3 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -932,7 +932,7 @@ pub fn inject_std_macros(parse_sess: @mut parse::ParseSess, pub struct MacroExpander<'a> { extsbox: @mut SyntaxEnv, - cx: &'a ExtCtxt, + cx: &'a mut ExtCtxt, } impl<'a> ast_fold for MacroExpander<'a> { @@ -970,10 +970,10 @@ pub fn expand_crate(parse_sess: @mut parse::ParseSess, // exts table through the fold, but that would require updating // every method/element of AstFoldFns in fold.rs. let extsbox = syntax_expander_table(); - let cx = ExtCtxt::new(parse_sess, cfg.clone()); + let mut cx = ExtCtxt::new(parse_sess, cfg.clone()); let mut expander = MacroExpander { extsbox: @mut extsbox, - cx: &cx, + cx: &mut cx, }; let ret = expander.fold_crate(c); diff --git a/src/libsyntax/ext/fmt.rs b/src/libsyntax/ext/fmt.rs index f2eab3f1cbc..34a8236905b 100644 --- a/src/libsyntax/ext/fmt.rs +++ b/src/libsyntax/ext/fmt.rs @@ -15,7 +15,7 @@ use codemap::Span; use ext::base; use ext::build::AstBuilder; -pub fn expand_syntax_ext(ecx: &base::ExtCtxt, sp: Span, +pub fn expand_syntax_ext(ecx: &mut base::ExtCtxt, sp: Span, _tts: &[ast::token_tree]) -> base::MacResult { ecx.span_err(sp, "`fmt!` is deprecated, use `format!` instead"); ecx.parse_sess.span_diagnostic.span_note(sp, diff --git a/src/libsyntax/ext/format.rs b/src/libsyntax/ext/format.rs index 2b51203eca5..3bfab7da9b4 100644 --- a/src/libsyntax/ext/format.rs +++ b/src/libsyntax/ext/format.rs @@ -29,7 +29,7 @@ enum ArgumentType { } struct Context<'a> { - ecx: &'a ExtCtxt, + ecx: &'a mut ExtCtxt, fmtsp: Span, // Parsed argument expressions and the types that we've found so far for @@ -722,7 +722,7 @@ impl<'a> Context<'a> { } } -pub fn expand_args(ecx: &ExtCtxt, sp: Span, +pub fn expand_args(ecx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult { let mut cx = Context { ecx: ecx, @@ -739,19 +739,20 @@ pub fn expand_args(ecx: &ExtCtxt, sp: Span, }; let (extra, efmt) = match cx.parse_args(sp, tts) { (extra, Some(e)) => (extra, e), - (_, None) => { return MRExpr(ecx.expr_uint(sp, 2)); } + (_, None) => { return MRExpr(cx.ecx.expr_uint(sp, 2)); } }; cx.fmtsp = efmt.span; // Be sure to recursively expand macros just in case the format string uses // a macro to build the format expression. - let (fmt, _) = expr_to_str(ecx, ecx.expand_expr(efmt), + let expr = cx.ecx.expand_expr(efmt); + let (fmt, _) = expr_to_str(cx.ecx, expr, "format argument must be a string literal."); let mut err = false; parse::parse_error::cond.trap(|m| { if !err { err = true; - ecx.span_err(efmt.span, m); + cx.ecx.span_err(efmt.span, m); } }).inside(|| { for piece in parse::Parser::new(fmt) { @@ -767,12 +768,12 @@ pub fn expand_args(ecx: &ExtCtxt, sp: Span, // Make sure that all arguments were used and all arguments have types. for (i, ty) in cx.arg_types.iter().enumerate() { if ty.is_none() { - ecx.span_err(cx.args[i].span, "argument never used"); + cx.ecx.span_err(cx.args[i].span, "argument never used"); } } for (name, e) in cx.names.iter() { if !cx.name_types.contains_key(name) { - ecx.span_err(e.span, "named argument never used"); + cx.ecx.span_err(e.span, "named argument never used"); } } diff --git a/src/libsyntax/ext/log_syntax.rs b/src/libsyntax/ext/log_syntax.rs index 7dfd487b379..22b04501cfb 100644 --- a/src/libsyntax/ext/log_syntax.rs +++ b/src/libsyntax/ext/log_syntax.rs @@ -15,7 +15,7 @@ use ext::base; use print; use parse::token::{get_ident_interner}; -pub fn expand_syntax_ext(cx: &ExtCtxt, +pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: codemap::Span, tt: &[ast::token_tree]) -> base::MacResult { diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index f6086734003..330d33d6fc6 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -289,7 +289,7 @@ pub mod rt { } -pub fn expand_quote_tokens(cx: &ExtCtxt, +pub fn expand_quote_tokens(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult { let (cx_expr, expr) = expand_tts(cx, sp, tts); @@ -297,14 +297,14 @@ pub fn expand_quote_tokens(cx: &ExtCtxt, base::MRExpr(expanded) } -pub fn expand_quote_expr(cx: &ExtCtxt, +pub fn expand_quote_expr(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult { let expanded = expand_parse_call(cx, sp, "parse_expr", ~[], tts); base::MRExpr(expanded) } -pub fn expand_quote_item(cx: &ExtCtxt, +pub fn expand_quote_item(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult { let e_attrs = cx.expr_vec_uniq(sp, ~[]); @@ -313,7 +313,7 @@ pub fn expand_quote_item(cx: &ExtCtxt, base::MRExpr(expanded) } -pub fn expand_quote_pat(cx: &ExtCtxt, +pub fn expand_quote_pat(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult { let e_refutable = cx.expr_lit(sp, ast::lit_bool(true)); @@ -322,7 +322,7 @@ pub fn expand_quote_pat(cx: &ExtCtxt, base::MRExpr(expanded) } -pub fn expand_quote_ty(cx: &ExtCtxt, +pub fn expand_quote_ty(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult { let e_param_colons = cx.expr_lit(sp, ast::lit_bool(false)); @@ -331,7 +331,7 @@ pub fn expand_quote_ty(cx: &ExtCtxt, base::MRExpr(expanded) } -pub fn expand_quote_stmt(cx: &ExtCtxt, +pub fn expand_quote_stmt(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult { let e_attrs = cx.expr_vec_uniq(sp, ~[]); diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index cf11bdcce64..ccf4bf2acd6 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -28,7 +28,7 @@ use std::str; // a given file into the current one. /* line!(): expands to the current line number */ -pub fn expand_line(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree]) +pub fn expand_line(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult { base::check_zero_tts(cx, sp, tts, "line!"); @@ -39,7 +39,7 @@ pub fn expand_line(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree]) } /* col!(): expands to the current column number */ -pub fn expand_col(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree]) +pub fn expand_col(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult { base::check_zero_tts(cx, sp, tts, "col!"); @@ -51,7 +51,7 @@ pub fn expand_col(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree]) /* file!(): expands to the current filename */ /* The filemap (`loc.file`) contains a bunch more information we could spit * out if we wanted. */ -pub fn expand_file(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree]) +pub fn expand_file(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult { base::check_zero_tts(cx, sp, tts, "file!"); @@ -61,13 +61,13 @@ pub fn expand_file(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree]) base::MRExpr(cx.expr_str(topmost.call_site, filename)) } -pub fn expand_stringify(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree]) +pub fn expand_stringify(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult { let s = pprust::tts_to_str(tts, get_ident_interner()); base::MRExpr(cx.expr_str(sp, s.to_managed())) } -pub fn expand_mod(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree]) +pub fn expand_mod(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult { base::check_zero_tts(cx, sp, tts, "module_path!"); base::MRExpr(cx.expr_str(sp, @@ -77,7 +77,7 @@ pub fn expand_mod(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree]) // include! : parse the given file as an expr // This is generally a bad idea because it's going to behave // unhygienically. -pub fn expand_include(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree]) +pub fn expand_include(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult { let file = get_single_str_from_tts(cx, sp, tts, "include!"); // The file will be added to the code map by the parser @@ -88,7 +88,7 @@ pub fn expand_include(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree]) } // include_str! : read the given file, insert it as a literal string expr -pub fn expand_include_str(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree]) +pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult { let file = get_single_str_from_tts(cx, sp, tts, "include_str!"); let file = res_rel_file(cx, sp, &Path::new(file)); @@ -120,7 +120,7 @@ pub fn expand_include_str(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree]) } } -pub fn expand_include_bin(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree]) +pub fn expand_include_bin(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult { use std::at_vec; @@ -167,7 +167,7 @@ fn topmost_expn_info(expn_info: @codemap::ExpnInfo) -> @codemap::ExpnInfo { // resolve a file-system path to an absolute file-system path (if it // isn't already) -fn res_rel_file(cx: &ExtCtxt, sp: codemap::Span, arg: &Path) -> Path { +fn res_rel_file(cx: &mut ExtCtxt, sp: codemap::Span, arg: &Path) -> Path { // NB: relative paths are resolved relative to the compilation unit if !arg.is_absolute() { let mut cu = Path::new(cx.codemap().span_to_filename(sp)); diff --git a/src/libsyntax/ext/trace_macros.rs b/src/libsyntax/ext/trace_macros.rs index cd172495d70..d9b1c2bddbc 100644 --- a/src/libsyntax/ext/trace_macros.rs +++ b/src/libsyntax/ext/trace_macros.rs @@ -16,7 +16,7 @@ use parse::lexer::{new_tt_reader, reader}; use parse::parser::Parser; use parse::token::keywords; -pub fn expand_trace_macros(cx: &ExtCtxt, +pub fn expand_trace_macros(cx: &mut ExtCtxt, sp: Span, tt: &[ast::token_tree]) -> base::MacResult { diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 63517ca2269..ae9bbdadf2c 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -83,7 +83,7 @@ struct MacroRulesSyntaxExpanderTTFun { impl SyntaxExpanderTTTrait for MacroRulesSyntaxExpanderTTFun { fn expand(&self, - cx: &ExtCtxt, + cx: &mut ExtCtxt, sp: Span, arg: &[ast::token_tree], _: ast::SyntaxContext) @@ -168,7 +168,7 @@ fn generic_extension(cx: &ExtCtxt, // this procedure performs the expansion of the // macro_rules! macro. It parses the RHS and adds // an extension to the current context. -pub fn add_new_extension(cx: &ExtCtxt, +pub fn add_new_extension(cx: &mut ExtCtxt, sp: Span, name: Ident, arg: ~[ast::token_tree],