Skip to content

Commit 8143662

Browse files
committed
Start passing around &mut ExtCtxt
1 parent 3965ddd commit 8143662

File tree

16 files changed

+49
-48
lines changed

16 files changed

+49
-48
lines changed

src/libsyntax/ext/asm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fn next_state(s: State) -> Option<State> {
3737
}
3838
}
3939

40-
pub fn expand_asm(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree])
40+
pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
4141
-> base::MacResult {
4242
let p = parse::new_parser_from_tts(cx.parse_sess(),
4343
cx.cfg(),

src/libsyntax/ext/base.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ pub struct SyntaxExpanderTT {
4545

4646
pub trait SyntaxExpanderTTTrait {
4747
fn expand(&self,
48-
ecx: &ExtCtxt,
48+
ecx: &mut ExtCtxt,
4949
span: Span,
5050
token_tree: &[ast::token_tree],
5151
context: ast::SyntaxContext)
5252
-> MacResult;
5353
}
5454

5555
pub type SyntaxExpanderTTFunNoCtxt =
56-
fn(ecx: &ExtCtxt, span: codemap::Span, token_tree: &[ast::token_tree])
56+
fn(ecx: &mut ExtCtxt, span: codemap::Span, token_tree: &[ast::token_tree])
5757
-> MacResult;
5858

5959
enum SyntaxExpanderTTExpander {
@@ -62,7 +62,7 @@ enum SyntaxExpanderTTExpander {
6262

6363
impl SyntaxExpanderTTTrait for SyntaxExpanderTT {
6464
fn expand(&self,
65-
ecx: &ExtCtxt,
65+
ecx: &mut ExtCtxt,
6666
span: Span,
6767
token_tree: &[ast::token_tree],
6868
_: ast::SyntaxContext)
@@ -87,7 +87,7 @@ pub struct SyntaxExpanderTTItem {
8787

8888
pub trait SyntaxExpanderTTItemTrait {
8989
fn expand(&self,
90-
cx: &ExtCtxt,
90+
cx: &mut ExtCtxt,
9191
sp: Span,
9292
ident: ast::Ident,
9393
token_tree: ~[ast::token_tree],
@@ -97,7 +97,7 @@ pub trait SyntaxExpanderTTItemTrait {
9797

9898
impl SyntaxExpanderTTItemTrait for SyntaxExpanderTTItem {
9999
fn expand(&self,
100-
cx: &ExtCtxt,
100+
cx: &mut ExtCtxt,
101101
sp: Span,
102102
ident: ast::Ident,
103103
token_tree: ~[ast::token_tree],
@@ -115,11 +115,11 @@ impl SyntaxExpanderTTItemTrait for SyntaxExpanderTTItem {
115115
}
116116

117117
pub type SyntaxExpanderTTItemFun =
118-
fn(&ExtCtxt, Span, ast::Ident, ~[ast::token_tree], ast::SyntaxContext)
118+
fn(&mut ExtCtxt, Span, ast::Ident, ~[ast::token_tree], ast::SyntaxContext)
119119
-> MacResult;
120120

121121
pub type SyntaxExpanderTTItemFunNoCtxt =
122-
fn(&ExtCtxt, Span, ast::Ident, ~[ast::token_tree]) -> MacResult;
122+
fn(&mut ExtCtxt, Span, ast::Ident, ~[ast::token_tree]) -> MacResult;
123123

124124
pub trait AnyMacro {
125125
fn make_expr(&self) -> @ast::Expr;
@@ -320,7 +320,7 @@ impl ExtCtxt {
320320
}
321321
}
322322

323-
pub fn expand_expr(&self, mut e: @ast::Expr) -> @ast::Expr {
323+
pub fn expand_expr(&mut self, mut e: @ast::Expr) -> @ast::Expr {
324324
loop {
325325
match e.node {
326326
ast::ExprMac(..) => {

src/libsyntax/ext/build.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ pub trait AstBuilder {
236236
vis: ast::visibility, path: ~[ast::Ident]) -> ast::view_item;
237237
}
238238

239-
impl<'a> AstBuilder for &'a ExtCtxt {
239+
impl AstBuilder for ExtCtxt {
240240
fn path(&self, span: Span, strs: ~[ast::Ident]) -> ast::Path {
241241
self.path_all(span, false, strs, opt_vec::Empty, ~[])
242242
}
@@ -686,12 +686,12 @@ impl<'a> AstBuilder for &'a ExtCtxt {
686686
}
687687
fn lambda0(&self, _span: Span, blk: P<ast::Block>) -> @ast::Expr {
688688
let blk_e = self.expr(blk.span, ast::ExprBlock(blk));
689-
quote_expr!(*self, || $blk_e )
689+
quote_expr!(self, || $blk_e )
690690
}
691691

692692
fn lambda1(&self, _span: Span, blk: P<ast::Block>, ident: ast::Ident) -> @ast::Expr {
693693
let blk_e = self.expr(blk.span, ast::ExprBlock(blk));
694-
quote_expr!(*self, |$ident| $blk_e )
694+
quote_expr!(self, |$ident| $blk_e )
695695
}
696696

697697
fn lambda_expr(&self, span: Span, ids: ~[ast::Ident], expr: @ast::Expr) -> @ast::Expr {

src/libsyntax/ext/bytes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use ext::build::AstBuilder;
1818

1919
use std::char;
2020

21-
pub fn expand_syntax_ext(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult {
21+
pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult {
2222
// Gather all argument expressions
2323
let exprs = get_exprs_from_tts(cx, sp, tts);
2424
let mut bytes = ~[];

src/libsyntax/ext/cfg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use parse;
2525
use parse::token;
2626
use parse::attr::parser_attr;
2727

28-
pub fn expand_cfg(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult {
28+
pub fn expand_cfg(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult {
2929
let p = parse::new_parser_from_tts(cx.parse_sess(), cx.cfg(), tts.to_owned());
3030

3131
let mut cfgs = ~[];

src/libsyntax/ext/concat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use codemap;
1515
use ext::base;
1616
use ext::build::AstBuilder;
1717

18-
pub fn expand_syntax_ext(cx: &base::ExtCtxt,
18+
pub fn expand_syntax_ext(cx: &mut base::ExtCtxt,
1919
sp: codemap::Span,
2020
tts: &[ast::token_tree]) -> base::MacResult {
2121
let es = base::get_exprs_from_tts(cx, sp, tts);

src/libsyntax/ext/concat_idents.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use opt_vec;
1616
use parse::token;
1717
use parse::token::{str_to_ident};
1818

19-
pub fn expand_syntax_ext(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree])
19+
pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
2020
-> base::MacResult {
2121
let mut res_str = ~"";
2222
for (i, e) in tts.iter().enumerate() {

src/libsyntax/ext/env.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use ext::build::AstBuilder;
2222

2323
use std::os;
2424

25-
pub fn expand_option_env(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree])
25+
pub fn expand_option_env(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
2626
-> base::MacResult {
2727
let var = get_single_str_from_tts(cx, sp, tts, "option_env!");
2828

@@ -33,7 +33,7 @@ pub fn expand_option_env(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree])
3333
MRExpr(e)
3434
}
3535

36-
pub fn expand_env(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree])
36+
pub fn expand_env(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
3737
-> base::MacResult {
3838
let exprs = get_exprs_from_tts(cx, sp, tts);
3939

src/libsyntax/ext/expand.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ pub fn inject_std_macros(parse_sess: @mut parse::ParseSess,
932932

933933
pub struct MacroExpander<'a> {
934934
extsbox: @mut SyntaxEnv,
935-
cx: &'a ExtCtxt,
935+
cx: &'a mut ExtCtxt,
936936
}
937937

938938
impl<'a> ast_fold for MacroExpander<'a> {
@@ -970,10 +970,10 @@ pub fn expand_crate(parse_sess: @mut parse::ParseSess,
970970
// exts table through the fold, but that would require updating
971971
// every method/element of AstFoldFns in fold.rs.
972972
let extsbox = syntax_expander_table();
973-
let cx = ExtCtxt::new(parse_sess, cfg.clone());
973+
let mut cx = ExtCtxt::new(parse_sess, cfg.clone());
974974
let mut expander = MacroExpander {
975975
extsbox: @mut extsbox,
976-
cx: &cx,
976+
cx: &mut cx,
977977
};
978978

979979
let ret = expander.fold_crate(c);

src/libsyntax/ext/fmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use codemap::Span;
1515
use ext::base;
1616
use ext::build::AstBuilder;
1717

18-
pub fn expand_syntax_ext(ecx: &base::ExtCtxt, sp: Span,
18+
pub fn expand_syntax_ext(ecx: &mut base::ExtCtxt, sp: Span,
1919
_tts: &[ast::token_tree]) -> base::MacResult {
2020
ecx.span_err(sp, "`fmt!` is deprecated, use `format!` instead");
2121
ecx.parse_sess.span_diagnostic.span_note(sp,

src/libsyntax/ext/format.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ enum ArgumentType {
2929
}
3030

3131
struct Context<'a> {
32-
ecx: &'a ExtCtxt,
32+
ecx: &'a mut ExtCtxt,
3333
fmtsp: Span,
3434

3535
// Parsed argument expressions and the types that we've found so far for
@@ -722,7 +722,7 @@ impl<'a> Context<'a> {
722722
}
723723
}
724724

725-
pub fn expand_args(ecx: &ExtCtxt, sp: Span,
725+
pub fn expand_args(ecx: &mut ExtCtxt, sp: Span,
726726
tts: &[ast::token_tree]) -> base::MacResult {
727727
let mut cx = Context {
728728
ecx: ecx,
@@ -739,19 +739,20 @@ pub fn expand_args(ecx: &ExtCtxt, sp: Span,
739739
};
740740
let (extra, efmt) = match cx.parse_args(sp, tts) {
741741
(extra, Some(e)) => (extra, e),
742-
(_, None) => { return MRExpr(ecx.expr_uint(sp, 2)); }
742+
(_, None) => { return MRExpr(cx.ecx.expr_uint(sp, 2)); }
743743
};
744744
cx.fmtsp = efmt.span;
745745
// Be sure to recursively expand macros just in case the format string uses
746746
// a macro to build the format expression.
747-
let (fmt, _) = expr_to_str(ecx, ecx.expand_expr(efmt),
747+
let expr = cx.ecx.expand_expr(efmt);
748+
let (fmt, _) = expr_to_str(cx.ecx, expr,
748749
"format argument must be a string literal.");
749750

750751
let mut err = false;
751752
parse::parse_error::cond.trap(|m| {
752753
if !err {
753754
err = true;
754-
ecx.span_err(efmt.span, m);
755+
cx.ecx.span_err(efmt.span, m);
755756
}
756757
}).inside(|| {
757758
for piece in parse::Parser::new(fmt) {
@@ -767,12 +768,12 @@ pub fn expand_args(ecx: &ExtCtxt, sp: Span,
767768
// Make sure that all arguments were used and all arguments have types.
768769
for (i, ty) in cx.arg_types.iter().enumerate() {
769770
if ty.is_none() {
770-
ecx.span_err(cx.args[i].span, "argument never used");
771+
cx.ecx.span_err(cx.args[i].span, "argument never used");
771772
}
772773
}
773774
for (name, e) in cx.names.iter() {
774775
if !cx.name_types.contains_key(name) {
775-
ecx.span_err(e.span, "named argument never used");
776+
cx.ecx.span_err(e.span, "named argument never used");
776777
}
777778
}
778779

src/libsyntax/ext/log_syntax.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use ext::base;
1515
use print;
1616
use parse::token::{get_ident_interner};
1717

18-
pub fn expand_syntax_ext(cx: &ExtCtxt,
18+
pub fn expand_syntax_ext(cx: &mut ExtCtxt,
1919
sp: codemap::Span,
2020
tt: &[ast::token_tree])
2121
-> base::MacResult {

src/libsyntax/ext/quote.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -289,22 +289,22 @@ pub mod rt {
289289
290290
}
291291
292-
pub fn expand_quote_tokens(cx: &ExtCtxt,
292+
pub fn expand_quote_tokens(cx: &mut ExtCtxt,
293293
sp: Span,
294294
tts: &[ast::token_tree]) -> base::MacResult {
295295
let (cx_expr, expr) = expand_tts(cx, sp, tts);
296296
let expanded = expand_wrapper(cx, sp, cx_expr, expr);
297297
base::MRExpr(expanded)
298298
}
299299
300-
pub fn expand_quote_expr(cx: &ExtCtxt,
300+
pub fn expand_quote_expr(cx: &mut ExtCtxt,
301301
sp: Span,
302302
tts: &[ast::token_tree]) -> base::MacResult {
303303
let expanded = expand_parse_call(cx, sp, "parse_expr", ~[], tts);
304304
base::MRExpr(expanded)
305305
}
306306

307-
pub fn expand_quote_item(cx: &ExtCtxt,
307+
pub fn expand_quote_item(cx: &mut ExtCtxt,
308308
sp: Span,
309309
tts: &[ast::token_tree]) -> base::MacResult {
310310
let e_attrs = cx.expr_vec_uniq(sp, ~[]);
@@ -313,7 +313,7 @@ pub fn expand_quote_item(cx: &ExtCtxt,
313313
base::MRExpr(expanded)
314314
}
315315

316-
pub fn expand_quote_pat(cx: &ExtCtxt,
316+
pub fn expand_quote_pat(cx: &mut ExtCtxt,
317317
sp: Span,
318318
tts: &[ast::token_tree]) -> base::MacResult {
319319
let e_refutable = cx.expr_lit(sp, ast::lit_bool(true));
@@ -322,7 +322,7 @@ pub fn expand_quote_pat(cx: &ExtCtxt,
322322
base::MRExpr(expanded)
323323
}
324324

325-
pub fn expand_quote_ty(cx: &ExtCtxt,
325+
pub fn expand_quote_ty(cx: &mut ExtCtxt,
326326
sp: Span,
327327
tts: &[ast::token_tree]) -> base::MacResult {
328328
let e_param_colons = cx.expr_lit(sp, ast::lit_bool(false));
@@ -331,7 +331,7 @@ pub fn expand_quote_ty(cx: &ExtCtxt,
331331
base::MRExpr(expanded)
332332
}
333333

334-
pub fn expand_quote_stmt(cx: &ExtCtxt,
334+
pub fn expand_quote_stmt(cx: &mut ExtCtxt,
335335
sp: Span,
336336
tts: &[ast::token_tree]) -> base::MacResult {
337337
let e_attrs = cx.expr_vec_uniq(sp, ~[]);

src/libsyntax/ext/source_util.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use std::str;
2828
// a given file into the current one.
2929

3030
/* line!(): expands to the current line number */
31-
pub fn expand_line(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree])
31+
pub fn expand_line(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
3232
-> base::MacResult {
3333
base::check_zero_tts(cx, sp, tts, "line!");
3434

@@ -39,7 +39,7 @@ pub fn expand_line(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree])
3939
}
4040

4141
/* col!(): expands to the current column number */
42-
pub fn expand_col(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree])
42+
pub fn expand_col(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
4343
-> base::MacResult {
4444
base::check_zero_tts(cx, sp, tts, "col!");
4545

@@ -51,7 +51,7 @@ pub fn expand_col(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree])
5151
/* file!(): expands to the current filename */
5252
/* The filemap (`loc.file`) contains a bunch more information we could spit
5353
* out if we wanted. */
54-
pub fn expand_file(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree])
54+
pub fn expand_file(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
5555
-> base::MacResult {
5656
base::check_zero_tts(cx, sp, tts, "file!");
5757

@@ -61,13 +61,13 @@ pub fn expand_file(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree])
6161
base::MRExpr(cx.expr_str(topmost.call_site, filename))
6262
}
6363

64-
pub fn expand_stringify(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree])
64+
pub fn expand_stringify(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
6565
-> base::MacResult {
6666
let s = pprust::tts_to_str(tts, get_ident_interner());
6767
base::MRExpr(cx.expr_str(sp, s.to_managed()))
6868
}
6969

70-
pub fn expand_mod(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree])
70+
pub fn expand_mod(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
7171
-> base::MacResult {
7272
base::check_zero_tts(cx, sp, tts, "module_path!");
7373
base::MRExpr(cx.expr_str(sp,
@@ -77,7 +77,7 @@ pub fn expand_mod(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree])
7777
// include! : parse the given file as an expr
7878
// This is generally a bad idea because it's going to behave
7979
// unhygienically.
80-
pub fn expand_include(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree])
80+
pub fn expand_include(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
8181
-> base::MacResult {
8282
let file = get_single_str_from_tts(cx, sp, tts, "include!");
8383
// 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])
8888
}
8989

9090
// include_str! : read the given file, insert it as a literal string expr
91-
pub fn expand_include_str(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree])
91+
pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
9292
-> base::MacResult {
9393
let file = get_single_str_from_tts(cx, sp, tts, "include_str!");
9494
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])
120120
}
121121
}
122122

123-
pub fn expand_include_bin(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree])
123+
pub fn expand_include_bin(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
124124
-> base::MacResult
125125
{
126126
use std::at_vec;
@@ -167,7 +167,7 @@ fn topmost_expn_info(expn_info: @codemap::ExpnInfo) -> @codemap::ExpnInfo {
167167

168168
// resolve a file-system path to an absolute file-system path (if it
169169
// isn't already)
170-
fn res_rel_file(cx: &ExtCtxt, sp: codemap::Span, arg: &Path) -> Path {
170+
fn res_rel_file(cx: &mut ExtCtxt, sp: codemap::Span, arg: &Path) -> Path {
171171
// NB: relative paths are resolved relative to the compilation unit
172172
if !arg.is_absolute() {
173173
let mut cu = Path::new(cx.codemap().span_to_filename(sp));

src/libsyntax/ext/trace_macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use parse::lexer::{new_tt_reader, reader};
1616
use parse::parser::Parser;
1717
use parse::token::keywords;
1818

19-
pub fn expand_trace_macros(cx: &ExtCtxt,
19+
pub fn expand_trace_macros(cx: &mut ExtCtxt,
2020
sp: Span,
2121
tt: &[ast::token_tree])
2222
-> base::MacResult {

0 commit comments

Comments
 (0)