Start passing around &mut ExtCtxt

This commit is contained in:
Steven Fackler 2013-12-28 22:06:22 -07:00
parent 3965dddf49
commit 8143662836
16 changed files with 49 additions and 48 deletions

View File

@ -37,7 +37,7 @@ fn next_state(s: State) -> Option<State> {
}
}
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(),

View File

@ -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(..) => {

View File

@ -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::Block>) -> @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<ast::Block>, 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 {

View File

@ -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 = ~[];

View File

@ -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 = ~[];

View File

@ -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);

View File

@ -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() {

View File

@ -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);

View File

@ -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);

View File

@ -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,

View File

@ -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");
}
}

View File

@ -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 {

View File

@ -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, ~[]);

View File

@ -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));

View File

@ -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 {

View File

@ -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],