struct TestCtxt {
sess: session::Session,
path: RefCell<~[ast::Ident]>,
- ext_cx: @ExtCtxt,
+ ext_cx: ExtCtxt,
testfns: RefCell<~[Test]>,
is_extra: bool,
config: ast::CrateConfig,
config: crate.config.clone(),
};
- let ext_cx = cx.ext_cx;
- ext_cx.bt_push(ExpnInfo {
+ cx.ext_cx.bt_push(ExpnInfo {
call_site: dummy_sp(),
callee: NameAndSpan {
name: @"test",
cx: cx
};
let res = fold.fold_crate(crate);
- ext_cx.bt_pop();
+ cx.ext_cx.bt_pop();
return res;
}
// The synthesized main function which will call the console test runner
// with our list of tests
- let mainfn = (quote_item!(cx.ext_cx,
+ let mainfn = (quote_item!(&cx.ext_cx,
pub fn main() {
#[main];
extra::test::test_main_static(::std::os::args(), TESTS);
// The vector of test_descs for this crate
let test_descs = mk_test_descs(cx);
- (quote_item!(cx.ext_cx,
+ (quote_item!(&cx.ext_cx,
pub static TESTS : &'static [self::extra::test::TestDescAndFn] =
$test_descs
;
};
let t_expr = if test.bench {
- quote_expr!(cx.ext_cx, self::extra::test::StaticBenchFn($fn_expr) )
+ quote_expr!(&cx.ext_cx, self::extra::test::StaticBenchFn($fn_expr) )
} else {
- quote_expr!(cx.ext_cx, self::extra::test::StaticTestFn($fn_expr) )
+ quote_expr!(&cx.ext_cx, self::extra::test::StaticTestFn($fn_expr) )
};
let ignore_expr = if test.ignore {
- quote_expr!(cx.ext_cx, true )
+ quote_expr!(&cx.ext_cx, true )
} else {
- quote_expr!(cx.ext_cx, false )
+ quote_expr!(&cx.ext_cx, false )
};
let fail_expr = if test.should_fail {
- quote_expr!(cx.ext_cx, true )
+ quote_expr!(&cx.ext_cx, true )
} else {
- quote_expr!(cx.ext_cx, false )
+ quote_expr!(&cx.ext_cx, false )
};
- let e = quote_expr!(cx.ext_cx,
+ let e = quote_expr!(&cx.ext_cx,
self::extra::test::TestDescAndFn {
desc: self::extra::test::TestDesc {
name: self::extra::test::StaticTestName($name_expr),
struct ReadyCtx {
sess: session::Session,
- ext_cx: @ExtCtxt,
+ ext_cx: ExtCtxt,
path: ~[ast::Ident],
fns: ~[ListenerFn]
}
}
}
-pub fn expand_asm(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
+pub fn expand_asm(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree])
-> base::MacResult {
let p = parse::new_parser_from_tts(cx.parse_sess(),
cx.cfg(),
ext: SyntaxExtension
}
-pub type ItemDecorator = extern "Rust" fn(@ExtCtxt,
+pub type ItemDecorator = extern "Rust" fn(&ExtCtxt,
Span,
@ast::MetaItem,
~[@ast::item])
pub trait SyntaxExpanderTTTrait {
fn expand(&self,
- ecx: @ExtCtxt,
+ ecx: &ExtCtxt,
span: Span,
token_tree: &[ast::token_tree],
context: ast::SyntaxContext)
}
pub type SyntaxExpanderTTFunNoCtxt =
- extern "Rust" fn(ecx: @ExtCtxt,
+ extern "Rust" fn(ecx: &ExtCtxt,
span: codemap::Span,
token_tree: &[ast::token_tree])
-> MacResult;
impl SyntaxExpanderTTTrait for SyntaxExpanderTT {
fn expand(&self,
- ecx: @ExtCtxt,
+ ecx: &ExtCtxt,
span: Span,
token_tree: &[ast::token_tree],
_: ast::SyntaxContext)
pub trait SyntaxExpanderTTItemTrait {
fn expand(&self,
- cx: @ExtCtxt,
+ cx: &ExtCtxt,
sp: Span,
ident: ast::Ident,
token_tree: ~[ast::token_tree],
impl SyntaxExpanderTTItemTrait for SyntaxExpanderTTItem {
fn expand(&self,
- cx: @ExtCtxt,
+ cx: &ExtCtxt,
sp: Span,
ident: ast::Ident,
token_tree: ~[ast::token_tree],
}
}
-pub type SyntaxExpanderTTItemFun = extern "Rust" fn(@ExtCtxt,
+pub type SyntaxExpanderTTItemFun = extern "Rust" fn(&ExtCtxt,
Span,
ast::Ident,
~[ast::token_tree],
-> MacResult;
pub type SyntaxExpanderTTItemFunNoCtxt =
- extern "Rust" fn(@ExtCtxt, Span, ast::Ident, ~[ast::token_tree])
+ extern "Rust" fn(&ExtCtxt, Span, ast::Ident, ~[ast::token_tree])
-> MacResult;
pub trait AnyMacro {
impl ExtCtxt {
pub fn new(parse_sess: @mut parse::ParseSess, cfg: ast::CrateConfig)
- -> @ExtCtxt {
- @ExtCtxt {
+ -> ExtCtxt {
+ ExtCtxt {
parse_sess: parse_sess,
cfg: cfg,
backtrace: @mut None,
}
}
- pub fn expand_expr(@self, mut e: @ast::Expr) -> @ast::Expr {
+ pub fn expand_expr(&self, mut e: @ast::Expr) -> @ast::Expr {
loop {
match e.node {
ast::ExprMac(..) => {
}
}
-pub fn expr_to_str(cx: @ExtCtxt, expr: @ast::Expr, err_msg: &str) -> (@str, ast::StrStyle) {
+pub fn expr_to_str(cx: &ExtCtxt, expr: @ast::Expr, err_msg: &str) -> (@str, ast::StrStyle) {
match expr.node {
ast::ExprLit(l) => match l.node {
ast::lit_str(s, style) => (s, style),
}
}
-pub fn check_zero_tts(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree],
+pub fn check_zero_tts(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree],
name: &str) {
if tts.len() != 0 {
cx.span_fatal(sp, format!("{} takes no arguments", name));
}
}
-pub fn get_single_str_from_tts(cx: @ExtCtxt,
+pub fn get_single_str_from_tts(cx: &ExtCtxt,
sp: Span,
tts: &[ast::token_tree],
name: &str)
}
}
-pub fn get_exprs_from_tts(cx: @ExtCtxt,
+pub fn get_exprs_from_tts(cx: &ExtCtxt,
sp: Span,
tts: &[ast::token_tree]) -> ~[@ast::Expr] {
let p = parse::new_parser_from_tts(cx.parse_sess(),
use codemap::{Span, respan, dummy_sp};
use ext::base::ExtCtxt;
use ext::quote::rt::*;
-use fold;
+use fold::ast_fold;
use opt_vec;
use opt_vec::OptVec;
vis: ast::visibility, path: ~[ast::Ident]) -> ast::view_item;
}
-impl AstBuilder for @ExtCtxt {
+impl<'a> AstBuilder for &'a ExtCtxt {
fn path(&self, span: Span, strs: ~[ast::Ident]) -> ast::Path {
self.path_all(span, false, strs, opt_vec::Empty, ~[])
}
}
}
-struct Duplicator {
- cx: @ExtCtxt,
+struct Duplicator<'a> {
+ cx: &'a ExtCtxt,
}
-impl fold::ast_fold for Duplicator {
+impl<'a> ast_fold for Duplicator<'a> {
fn new_id(&self, _: NodeId) -> NodeId {
ast::DUMMY_NODE_ID
}
// These functions just duplicate AST nodes.
//
- fn duplicate(&self, cx: @ExtCtxt) -> Self;
+ fn duplicate(&self, cx: &ExtCtxt) -> Self;
}
impl Duplicate for @ast::Expr {
- fn duplicate(&self, cx: @ExtCtxt) -> @ast::Expr {
- let folder = @Duplicator {
+ fn duplicate(&self, cx: &ExtCtxt) -> @ast::Expr {
+ let folder = Duplicator {
cx: cx,
- } as @fold::ast_fold;
+ };
folder.fold_expr(*self)
}
}
use std::char;
-pub fn expand_syntax_ext(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult {
+pub fn expand_syntax_ext(cx: &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 = ~[];
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: &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 = ~[];
use ext::base;
use ext::build::AstBuilder;
-pub fn expand_syntax_ext(cx: @base::ExtCtxt,
+pub fn expand_syntax_ext(cx: &base::ExtCtxt,
sp: codemap::Span,
tts: &[ast::token_tree]) -> base::MacResult {
let es = base::get_exprs_from_tts(cx, sp, tts);
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: &ExtCtxt, sp: Span, tts: &[ast::token_tree])
-> base::MacResult {
let mut res_str = ~"";
for (i, e) in tts.iter().enumerate() {
use ext::build::AstBuilder;
use ext::deriving::generic::*;
-pub fn expand_deriving_clone(cx: @ExtCtxt,
+pub fn expand_deriving_clone(cx: &ExtCtxt,
span: Span,
mitem: @MetaItem,
in_items: ~[@item])
trait_def.expand(mitem, in_items)
}
-pub fn expand_deriving_deep_clone(cx: @ExtCtxt,
+pub fn expand_deriving_deep_clone(cx: &ExtCtxt,
span: Span,
mitem: @MetaItem,
in_items: ~[@item])
fn cs_clone(
name: &str,
- cx: @ExtCtxt, span: Span,
+ cx: &ExtCtxt, span: Span,
substr: &Substructure) -> @Expr {
let clone_ident = substr.method_ident;
let ctor_ident;
use ext::build::AstBuilder;
use ext::deriving::generic::*;
-pub fn expand_deriving_eq(cx: @ExtCtxt,
+pub fn expand_deriving_eq(cx: &ExtCtxt,
span: Span,
mitem: @MetaItem,
in_items: ~[@item]) -> ~[@item] {
// structures are equal if all fields are equal, and non equal, if
// any fields are not equal or if the enum variants are different
- fn cs_eq(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
+ fn cs_eq(cx: &ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
cs_and(|cx, span, _, _| cx.expr_bool(span, false),
cx, span, substr)
}
- fn cs_ne(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
+ fn cs_ne(cx: &ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
cs_or(|cx, span, _, _| cx.expr_bool(span, true),
cx, span, substr)
}
use ext::build::AstBuilder;
use ext::deriving::generic::*;
-pub fn expand_deriving_ord(cx: @ExtCtxt,
+pub fn expand_deriving_ord(cx: &ExtCtxt,
span: Span,
mitem: @MetaItem,
in_items: ~[@item]) -> ~[@item] {
}
/// Strict inequality.
-fn cs_op(less: bool, equal: bool, cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
+fn cs_op(less: bool, equal: bool, cx: &ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
let op = if less {ast::BiLt} else {ast::BiGt};
cs_fold(
false, // need foldr,
use ext::build::AstBuilder;
use ext::deriving::generic::*;
-pub fn expand_deriving_totaleq(cx: @ExtCtxt,
+pub fn expand_deriving_totaleq(cx: &ExtCtxt,
span: Span,
mitem: @MetaItem,
in_items: ~[@item]) -> ~[@item] {
- fn cs_equals(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
+ fn cs_equals(cx: &ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
cs_and(|cx, span, _, _| cx.expr_bool(span, false),
cx, span, substr)
}
use ext::deriving::generic::*;
use std::cmp::{Ordering, Equal, Less, Greater};
-pub fn expand_deriving_totalord(cx: @ExtCtxt,
+pub fn expand_deriving_totalord(cx: &ExtCtxt,
span: Span,
mitem: @MetaItem,
in_items: ~[@item]) -> ~[@item] {
}
-pub fn ordering_const(cx: @ExtCtxt, span: Span, cnst: Ordering) -> ast::Path {
+pub fn ordering_const(cx: &ExtCtxt, span: Span, cnst: Ordering) -> ast::Path {
let cnst = match cnst {
Less => "Less",
Equal => "Equal",
cx.ident_of(cnst)])
}
-pub fn cs_cmp(cx: @ExtCtxt, span: Span,
+pub fn cs_cmp(cx: &ExtCtxt, span: Span,
substr: &Substructure) -> @Expr {
let test_id = cx.ident_of("__test");
let equals_path = ordering_const(cx, span, Equal);
use ext::build::AstBuilder;
use ext::deriving::generic::*;
-pub fn expand_deriving_decodable(cx: @ExtCtxt,
+pub fn expand_deriving_decodable(cx: &ExtCtxt,
span: Span,
mitem: @MetaItem,
in_items: ~[@item]) -> ~[@item] {
trait_def.expand(mitem, in_items)
}
-fn decodable_substructure(cx: @ExtCtxt, span: Span,
+fn decodable_substructure(cx: &ExtCtxt, span: Span,
substr: &Substructure) -> @Expr {
let decoder = substr.nonself_args[0];
let recurse = ~[cx.ident_of("extra"),
/// Create a decoder for a single enum variant/struct:
/// - `outer_pat_ident` is the name of this enum variant/struct
/// - `getarg` should retrieve the `uint`-th field with name `@str`.
-fn decode_static_fields(cx: @ExtCtxt,
+fn decode_static_fields(cx: &ExtCtxt,
outer_span: Span,
outer_pat_ident: Ident,
fields: &StaticFields,
use ext::build::AstBuilder;
use ext::deriving::generic::*;
-pub fn expand_deriving_default(cx: @ExtCtxt,
+pub fn expand_deriving_default(cx: &ExtCtxt,
span: Span,
mitem: @MetaItem,
in_items: ~[@item])
trait_def.expand(mitem, in_items)
}
-fn default_substructure(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
+fn default_substructure(cx: &ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
let default_ident = ~[
cx.ident_of("std"),
cx.ident_of("default"),
use ext::build::AstBuilder;
use ext::deriving::generic::*;
-pub fn expand_deriving_encodable(cx: @ExtCtxt,
+pub fn expand_deriving_encodable(cx: &ExtCtxt,
span: Span,
mitem: @MetaItem,
in_items: ~[@item]) -> ~[@item] {
trait_def.expand(mitem, in_items)
}
-fn encodable_substructure(cx: @ExtCtxt, span: Span,
+fn encodable_substructure(cx: &ExtCtxt, span: Span,
substr: &Substructure) -> @Expr {
let encoder = substr.nonself_args[0];
// throw an underscore in front to suppress unused variable warnings
pub struct TraitDef<'a> {
/// The extension context
- cx: @ExtCtxt,
+ cx: &'a ExtCtxt,
/// The span for the current #[deriving(Foo)] header.
span: Span,
all the fields of all the structures, see above for details.
*/
pub type CombineSubstructureFunc<'a> =
- 'a |@ExtCtxt, Span, &Substructure| -> @Expr;
+ 'a |&ExtCtxt, Span, &Substructure| -> @Expr;
/**
Deal with non-matching enum variants, the arguments are a list
[variant fields]), and a list of the nonself args of the type
*/
pub type EnumNonMatchFunc<'a> =
- 'a |@ExtCtxt,
+ 'a |&ExtCtxt,
Span,
&[(uint, P<ast::variant>, ~[(Span, Option<Ident>, @Expr)])],
&[@Expr]|
left-to-right (`true`) or right-to-left (`false`).
*/
pub fn cs_fold(use_foldl: bool,
- f: |@ExtCtxt, Span, @Expr, @Expr, &[@Expr]| -> @Expr,
+ f: |&ExtCtxt, Span, @Expr, @Expr, &[@Expr]| -> @Expr,
base: @Expr,
enum_nonmatch_f: EnumNonMatchFunc,
- cx: @ExtCtxt,
+ cx: &ExtCtxt,
trait_span: Span,
substructure: &Substructure)
-> @Expr {
~~~
*/
#[inline]
-pub fn cs_same_method(f: |@ExtCtxt, Span, ~[@Expr]| -> @Expr,
+pub fn cs_same_method(f: |&ExtCtxt, Span, ~[@Expr]| -> @Expr,
enum_nonmatch_f: EnumNonMatchFunc,
- cx: @ExtCtxt,
+ cx: &ExtCtxt,
trait_span: Span,
substructure: &Substructure)
-> @Expr {
*/
#[inline]
pub fn cs_same_method_fold(use_foldl: bool,
- f: |@ExtCtxt, Span, @Expr, @Expr| -> @Expr,
+ f: |&ExtCtxt, Span, @Expr, @Expr| -> @Expr,
base: @Expr,
enum_nonmatch_f: EnumNonMatchFunc,
- cx: @ExtCtxt,
+ cx: &ExtCtxt,
trait_span: Span,
substructure: &Substructure)
-> @Expr {
#[inline]
pub fn cs_binop(binop: ast::BinOp, base: @Expr,
enum_nonmatch_f: EnumNonMatchFunc,
- cx: @ExtCtxt, trait_span: Span,
+ cx: &ExtCtxt, trait_span: Span,
substructure: &Substructure) -> @Expr {
cs_same_method_fold(
true, // foldl is good enough
/// cs_binop with binop == or
#[inline]
pub fn cs_or(enum_nonmatch_f: EnumNonMatchFunc,
- cx: @ExtCtxt, span: Span,
+ cx: &ExtCtxt, span: Span,
substructure: &Substructure) -> @Expr {
cs_binop(ast::BiOr, cx.expr_bool(span, false),
enum_nonmatch_f,
/// cs_binop with binop == and
#[inline]
pub fn cs_and(enum_nonmatch_f: EnumNonMatchFunc,
- cx: @ExtCtxt, span: Span,
+ cx: &ExtCtxt, span: Span,
substructure: &Substructure) -> @Expr {
cs_binop(ast::BiAnd, cx.expr_bool(span, true),
enum_nonmatch_f,
use ext::deriving::generic::*;
-pub fn expand_deriving_iter_bytes(cx: @ExtCtxt,
+pub fn expand_deriving_iter_bytes(cx: &ExtCtxt,
span: Span,
mitem: @MetaItem,
in_items: ~[@item]) -> ~[@item] {
trait_def.expand(mitem, in_items)
}
-fn iter_bytes_substructure(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
+fn iter_bytes_substructure(cx: &ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
let (lsb0, f)= match substr.nonself_args {
[l, f] => (l, f),
_ => cx.span_bug(span, "Incorrect number of arguments in `deriving(IterBytes)`")
pub mod generic;
-pub type ExpandDerivingStructDefFn<'a> = 'a |@ExtCtxt,
+pub type ExpandDerivingStructDefFn<'a> = 'a |&ExtCtxt,
Span,
x: &struct_def,
Ident,
y: &Generics|
-> @item;
-pub type ExpandDerivingEnumDefFn<'a> = 'a |@ExtCtxt,
+pub type ExpandDerivingEnumDefFn<'a> = 'a |&ExtCtxt,
Span,
x: &enum_def,
Ident,
y: &Generics|
-> @item;
-pub fn expand_meta_deriving(cx: @ExtCtxt,
+pub fn expand_meta_deriving(cx: &ExtCtxt,
_span: Span,
mitem: @MetaItem,
in_items: ~[@item])
use ext::build::AstBuilder;
use ext::deriving::generic::*;
-pub fn expand_deriving_from_primitive(cx: @ExtCtxt,
+pub fn expand_deriving_from_primitive(cx: &ExtCtxt,
span: Span,
mitem: @MetaItem,
in_items: ~[@item]) -> ~[@item] {
trait_def.expand(mitem, in_items)
}
-fn cs_from(name: &str, cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
+fn cs_from(name: &str, cx: &ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
let n = match substr.nonself_args {
[n] => n,
_ => cx.span_bug(span, "Incorrect number of arguments in `deriving(FromPrimitive)`")
use ext::deriving::generic::*;
use opt_vec;
-pub fn expand_deriving_rand(cx: @ExtCtxt,
+pub fn expand_deriving_rand(cx: &ExtCtxt,
span: Span,
mitem: @MetaItem,
in_items: ~[@item])
trait_def.expand(mitem, in_items)
}
-fn rand_substructure(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
+fn rand_substructure(cx: &ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
let rng = match substr.nonself_args {
[rng] => ~[ rng ],
_ => cx.bug("Incorrect number of arguments to `rand` in `deriving(Rand)`")
_ => cx.bug("Non-static method in `deriving(Rand)`")
};
- fn rand_thing(cx: @ExtCtxt,
+ fn rand_thing(cx: &ExtCtxt,
span: Span,
ctor_ident: Ident,
summary: &StaticFields,
use ext::build::AstBuilder;
use ext::deriving::generic::*;
-pub fn expand_deriving_to_str(cx: @ExtCtxt,
+pub fn expand_deriving_to_str(cx: &ExtCtxt,
span: Span,
mitem: @MetaItem,
in_items: ~[@item])
// doesn't invoke the to_str() method on each field. Hence we mirror
// the logic of the repr_to_str() method, but with tweaks to call to_str()
// on sub-fields.
-fn to_str_substructure(cx: @ExtCtxt, span: Span,
+fn to_str_substructure(cx: &ExtCtxt, span: Span,
substr: &Substructure) -> @Expr {
let to_str = cx.ident_of("to_str");
}
pub fn to_ty(&self,
- cx: @ExtCtxt,
+ cx: &ExtCtxt,
span: Span,
self_ty: Ident,
self_generics: &Generics)
cx.ty_path(self.to_path(cx, span, self_ty, self_generics), None)
}
pub fn to_path(&self,
- cx: @ExtCtxt,
+ cx: &ExtCtxt,
span: Span,
self_ty: Ident,
self_generics: &Generics)
Tuple(~[])
}
-fn mk_lifetime(cx: @ExtCtxt, span: Span, lt: &Option<&str>) -> Option<ast::Lifetime> {
+fn mk_lifetime(cx: &ExtCtxt, span: Span, lt: &Option<&str>) -> Option<ast::Lifetime> {
match *lt {
Some(ref s) => Some(cx.lifetime(span, cx.ident_of(*s))),
None => None
}
}
-fn mk_lifetimes(cx: @ExtCtxt, span: Span, lt: &Option<&str>) -> OptVec<ast::Lifetime> {
+fn mk_lifetimes(cx: &ExtCtxt, span: Span, lt: &Option<&str>) -> OptVec<ast::Lifetime> {
match *lt {
Some(ref s) => opt_vec::with(cx.lifetime(span, cx.ident_of(*s))),
None => opt_vec::Empty
impl<'a> Ty<'a> {
pub fn to_ty(&self,
- cx: @ExtCtxt,
+ cx: &ExtCtxt,
span: Span,
self_ty: Ident,
self_generics: &Generics)
}
pub fn to_path(&self,
- cx: @ExtCtxt,
+ cx: &ExtCtxt,
span: Span,
self_ty: Ident,
self_generics: &Generics)
}
-fn mk_ty_param(cx: @ExtCtxt, span: Span, name: &str, bounds: &[Path],
+fn mk_ty_param(cx: &ExtCtxt, span: Span, name: &str, bounds: &[Path],
self_ident: Ident, self_generics: &Generics) -> ast::TyParam {
let bounds = opt_vec::from(
bounds.map(|b| {
}
}
pub fn to_generics(&self,
- cx: @ExtCtxt,
+ cx: &ExtCtxt,
span: Span,
self_ty: Ident,
self_generics: &Generics)
}
-pub fn get_explicit_self(cx: @ExtCtxt, span: Span, self_ptr: &Option<PtrTy>)
+pub fn get_explicit_self(cx: &ExtCtxt, span: Span, self_ptr: &Option<PtrTy>)
-> (@Expr, ast::explicit_self) {
let self_path = cx.expr_self(span);
match *self_ptr {
use ext::build::AstBuilder;
use ext::deriving::generic::*;
-pub fn expand_deriving_zero(cx: @ExtCtxt,
+pub fn expand_deriving_zero(cx: &ExtCtxt,
span: Span,
mitem: @MetaItem,
in_items: ~[@item])
trait_def.expand(mitem, in_items)
}
-fn zero_substructure(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
+fn zero_substructure(cx: &ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
let zero_ident = ~[
cx.ident_of("std"),
cx.ident_of("num"),
use std::os;
-pub fn expand_option_env(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
+pub fn expand_option_env(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree])
-> base::MacResult {
let var = get_single_str_from_tts(cx, sp, tts, "option_env!");
MRExpr(e)
}
-pub fn expand_env(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
+pub fn expand_env(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree])
-> base::MacResult {
let exprs = get_exprs_from_tts(cx, sp, tts);
use std::vec;
pub fn expand_expr(extsbox: @mut SyntaxEnv,
- cx: @ExtCtxt,
+ cx: &ExtCtxt,
e: @ast::Expr,
fld: &MacroExpander)
-> @ast::Expr {
// NB: there is some redundancy between this and expand_item, below, and
// they might benefit from some amount of semantic and language-UI merger.
pub fn expand_mod_items(extsbox: @mut SyntaxEnv,
- cx: @ExtCtxt,
+ cx: &ExtCtxt,
module_: &ast::_mod,
fld: &MacroExpander)
-> ast::_mod {
// When we enter a module, record it, for the sake of `module!`
pub fn expand_item(extsbox: @mut SyntaxEnv,
- cx: @ExtCtxt,
+ cx: &ExtCtxt,
it: @ast::item,
fld: &MacroExpander)
-> SmallVector<@ast::item> {
// Support for item-position macro invocations, exactly the same
// logic as for expression-position macro invocations.
pub fn expand_item_mac(extsbox: @mut SyntaxEnv,
- cx: @ExtCtxt,
+ cx: &ExtCtxt,
it: @ast::item,
fld: &MacroExpander)
-> SmallVector<@ast::item> {
// expand a stmt
pub fn expand_stmt(extsbox: @mut SyntaxEnv,
- cx: @ExtCtxt,
+ cx: &ExtCtxt,
s: &Stmt,
fld: &MacroExpander)
-> SmallVector<@Stmt> {
// expand a block. pushes a new exts_frame, then calls expand_block_elts
pub fn expand_block(extsbox: @mut SyntaxEnv,
- _: @ExtCtxt,
+ _: &ExtCtxt,
blk: &Block,
fld: &MacroExpander)
-> P<Block> {
} as @ast_fold
}
-pub fn new_span(cx: @ExtCtxt, sp: Span) -> Span {
+pub fn new_span(cx: &ExtCtxt, sp: Span) -> Span {
/* this discards information in the case of macro-defining macros */
Span {
lo: sp.lo,
injector.fold_crate(c)
}
-pub struct MacroExpander {
+pub struct MacroExpander<'a> {
extsbox: @mut SyntaxEnv,
- cx: @ExtCtxt,
+ cx: &'a ExtCtxt,
}
-impl ast_fold for MacroExpander {
+impl<'a> ast_fold for MacroExpander<'a> {
fn fold_expr(&self, expr: @ast::Expr) -> @ast::Expr {
expand_expr(self.extsbox,
self.cx,
// every method/element of AstFoldFns in fold.rs.
let extsbox = syntax_expander_table();
let cx = ExtCtxt::new(parse_sess, cfg.clone());
- let expander = @MacroExpander {
+ let expander = MacroExpander {
extsbox: @mut extsbox,
- cx: cx,
- } as @ast_fold;
+ cx: &cx,
+ };
let ret = expander.fold_crate(c);
parse_sess.span_diagnostic.handler().abort_if_errors();
mark_tts(tts,outer_mark)
}
-fn original_span(cx: @ExtCtxt) -> @codemap::ExpnInfo {
+fn original_span(cx: &ExtCtxt) -> @codemap::ExpnInfo {
let mut relevant_info = cx.backtrace();
let mut einfo = relevant_info.unwrap();
loop {
use ext::base;
use ext::build::AstBuilder;
-pub fn expand_syntax_ext(ecx: @base::ExtCtxt, sp: Span,
+pub fn expand_syntax_ext(ecx: &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,
String,
}
-struct Context {
- ecx: @ExtCtxt,
+struct Context<'a> {
+ ecx: &'a ExtCtxt,
fmtsp: Span,
// Parsed argument expressions and the types that we've found so far for
next_arg: uint,
}
-impl Context {
+impl<'a> Context<'a> {
/// Parses the arguments from the given list of tokens, returning None if
/// there's a parse error so we can continue parsing other format! expressions.
fn parse_args(&mut self, sp: Span,
}
}
-pub fn expand_args(ecx: @ExtCtxt, sp: Span,
+pub fn expand_args(ecx: &ExtCtxt, sp: Span,
tts: &[ast::token_tree]) -> base::MacResult {
let mut cx = Context {
ecx: ecx,
use print;
use parse::token::{get_ident_interner};
-pub fn expand_syntax_ext(cx: @ExtCtxt,
+pub fn expand_syntax_ext(cx: &ExtCtxt,
sp: codemap::Span,
tt: &[ast::token_tree])
-> base::MacResult {
pub use codemap::{BytePos, Span, dummy_spanned};
pub trait ToTokens {
- fn to_tokens(&self, _cx: @ExtCtxt) -> ~[token_tree];
+ fn to_tokens(&self, _cx: &ExtCtxt) -> ~[token_tree];
}
impl ToTokens for ~[token_tree] {
- fn to_tokens(&self, _cx: @ExtCtxt) -> ~[token_tree] {
+ fn to_tokens(&self, _cx: &ExtCtxt) -> ~[token_tree] {
(*self).clone()
}
}
pub fn to_source() -> ~str;
// If you can make source, you can definitely make tokens.
- pub fn to_tokens(cx: @ExtCtxt) -> ~[token_tree] {
+ pub fn to_tokens(cx: &ExtCtxt) -> ~[token_tree] {
cx.parse_tts(self.to_source())
}
}
macro_rules! impl_to_tokens(
($t:ty) => (
impl ToTokens for $t {
- fn to_tokens(&self, cx: @ExtCtxt) -> ~[token_tree] {
+ fn to_tokens(&self, cx: &ExtCtxt) -> ~[token_tree] {
cx.parse_tts(self.to_source())
}
}
macro_rules! impl_to_tokens_self(
($t:ty) => (
impl<'a> ToTokens for $t {
- fn to_tokens(&self, cx: @ExtCtxt) -> ~[token_tree] {
+ fn to_tokens(&self, cx: &ExtCtxt) -> ~[token_tree] {
cx.parse_tts(self.to_source())
}
}
}
-pub fn expand_quote_tokens(cx: @ExtCtxt,
+pub fn expand_quote_tokens(cx: &ExtCtxt,
sp: Span,
tts: &[ast::token_tree]) -> base::MacResult {
let (cx_expr, expr) = expand_tts(cx, sp, tts);
base::MRExpr(expanded)
}
-pub fn expand_quote_expr(cx: @ExtCtxt,
+pub fn expand_quote_expr(cx: &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: &ExtCtxt,
sp: Span,
tts: &[ast::token_tree]) -> base::MacResult {
let e_attrs = cx.expr_vec_uniq(sp, ~[]);
base::MRExpr(expanded)
}
-pub fn expand_quote_pat(cx: @ExtCtxt,
+pub fn expand_quote_pat(cx: &ExtCtxt,
sp: Span,
tts: &[ast::token_tree]) -> base::MacResult {
let e_refutable = cx.expr_lit(sp, ast::lit_bool(true));
base::MRExpr(expanded)
}
-pub fn expand_quote_ty(cx: @ExtCtxt,
+pub fn expand_quote_ty(cx: &ExtCtxt,
sp: Span,
tts: &[ast::token_tree]) -> base::MacResult {
let e_param_colons = cx.expr_lit(sp, ast::lit_bool(false));
base::MRExpr(expanded)
}
-pub fn expand_quote_stmt(cx: @ExtCtxt,
+pub fn expand_quote_stmt(cx: &ExtCtxt,
sp: Span,
tts: &[ast::token_tree]) -> base::MacResult {
let e_attrs = cx.expr_vec_uniq(sp, ~[]);
}
// Lift an ident to the expr that evaluates to that ident.
-fn mk_ident(cx: @ExtCtxt, sp: Span, ident: ast::Ident) -> @ast::Expr {
+fn mk_ident(cx: &ExtCtxt, sp: Span, ident: ast::Ident) -> @ast::Expr {
let e_str = cx.expr_str(sp, cx.str_of(ident));
cx.expr_method_call(sp,
cx.expr_ident(sp, id_ext("ext_cx")),
~[e_str])
}
-fn mk_binop(cx: @ExtCtxt, sp: Span, bop: token::binop) -> @ast::Expr {
+fn mk_binop(cx: &ExtCtxt, sp: Span, bop: token::binop) -> @ast::Expr {
let name = match bop {
PLUS => "PLUS",
MINUS => "MINUS",
cx.expr_ident(sp, id_ext(name))
}
-fn mk_token(cx: @ExtCtxt, sp: Span, tok: &token::Token) -> @ast::Expr {
+fn mk_token(cx: &ExtCtxt, sp: Span, tok: &token::Token) -> @ast::Expr {
match *tok {
BINOP(binop) => {
}
-fn mk_tt(cx: @ExtCtxt, sp: Span, tt: &ast::token_tree)
+fn mk_tt(cx: &ExtCtxt, sp: Span, tt: &ast::token_tree)
-> ~[@ast::Stmt] {
match *tt {
}
}
-fn mk_tts(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
+fn mk_tts(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree])
-> ~[@ast::Stmt] {
let mut ss = ~[];
for tt in tts.iter() {
ss
}
-fn expand_tts(cx: @ExtCtxt,
+fn expand_tts(cx: &ExtCtxt,
sp: Span,
tts: &[ast::token_tree]) -> (@ast::Expr, @ast::Expr) {
(cx_expr, block)
}
-fn expand_wrapper(cx: @ExtCtxt,
+fn expand_wrapper(cx: &ExtCtxt,
sp: Span,
cx_expr: @ast::Expr,
expr: @ast::Expr) -> @ast::Expr {
cx.expr_block(cx.block_all(sp, uses, ~[stmt_let_ext_cx], Some(expr)))
}
-fn expand_parse_call(cx: @ExtCtxt,
+fn expand_parse_call(cx: &ExtCtxt,
sp: Span,
parse_method: &str,
arg_exprs: ~[@ast::Expr],
// 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: &ExtCtxt, sp: Span, tts: &[ast::token_tree])
-> base::MacResult {
base::check_zero_tts(cx, sp, tts, "line!");
}
/* col!(): expands to the current column number */
-pub fn expand_col(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
+pub fn expand_col(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree])
-> base::MacResult {
base::check_zero_tts(cx, sp, tts, "col!");
/* 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: &ExtCtxt, sp: Span, tts: &[ast::token_tree])
-> base::MacResult {
base::check_zero_tts(cx, sp, tts, "file!");
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: &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: &ExtCtxt, sp: Span, tts: &[ast::token_tree])
-> base::MacResult {
base::check_zero_tts(cx, sp, tts, "module_path!");
base::MRExpr(cx.expr_str(sp,
// 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: &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
}
// 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: &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));
}
}
-pub fn expand_include_bin(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
+pub fn expand_include_bin(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree])
-> base::MacResult
{
use std::at_vec;
// 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: &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));
use parse::parser::Parser;
use parse::token::keywords;
-pub fn expand_trace_macros(cx: @ExtCtxt,
+pub fn expand_trace_macros(cx: &ExtCtxt,
sp: Span,
tt: &[ast::token_tree])
-> base::MacResult {
impl SyntaxExpanderTTTrait for MacroRulesSyntaxExpanderTTFun {
fn expand(&self,
- cx: @ExtCtxt,
+ cx: &ExtCtxt,
sp: Span,
arg: &[ast::token_tree],
_: ast::SyntaxContext)
}
// Given `lhses` and `rhses`, this is the new macro we create
-fn generic_extension(cx: @ExtCtxt,
+fn generic_extension(cx: &ExtCtxt,
sp: Span,
name: Ident,
arg: &[ast::token_tree],
// 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: &ExtCtxt,
sp: Span,
name: Ident,
arg: ~[ast::token_tree],
use syntax::ext::base::ExtCtxt;
-fn syntax_extension(cx: @ExtCtxt) {
+fn syntax_extension(cx: &ExtCtxt) {
let e_toks : ~[syntax::ast::token_tree] = quote_tokens!(cx, 1 + 2);
let p_toks : ~[syntax::ast::token_tree] = quote_tokens!(cx, (x, 1 .. 4, *));