1
Fork 0

syntax: convert deriving to take &mut ExtCtxt.

This commit is contained in:
Huon Wilson 2014-02-06 08:50:21 +11:00
parent eac673ab0c
commit fa191a5591
16 changed files with 63 additions and 63 deletions

View file

@ -36,7 +36,7 @@ pub struct MacroDef {
} }
pub type ItemDecorator = pub type ItemDecorator =
fn(&ExtCtxt, Span, @ast::MetaItem, ~[@ast::Item]) -> ~[@ast::Item]; fn(&mut ExtCtxt, Span, @ast::MetaItem, ~[@ast::Item]) -> ~[@ast::Item];
pub struct BasicMacroExpander { pub struct BasicMacroExpander {
expander: MacroExpanderFn, expander: MacroExpanderFn,

View file

@ -14,7 +14,7 @@ use ext::base::ExtCtxt;
use ext::build::AstBuilder; use ext::build::AstBuilder;
use ext::deriving::generic::*; use ext::deriving::generic::*;
pub fn expand_deriving_clone(cx: &ExtCtxt, pub fn expand_deriving_clone(cx: &mut ExtCtxt,
span: Span, span: Span,
mitem: @MetaItem, mitem: @MetaItem,
in_items: ~[@Item]) in_items: ~[@Item])
@ -42,7 +42,7 @@ pub fn expand_deriving_clone(cx: &ExtCtxt,
trait_def.expand(mitem, in_items) trait_def.expand(mitem, in_items)
} }
pub fn expand_deriving_deep_clone(cx: &ExtCtxt, pub fn expand_deriving_deep_clone(cx: &mut ExtCtxt,
span: Span, span: Span,
mitem: @MetaItem, mitem: @MetaItem,
in_items: ~[@Item]) in_items: ~[@Item])
@ -74,7 +74,7 @@ pub fn expand_deriving_deep_clone(cx: &ExtCtxt,
fn cs_clone( fn cs_clone(
name: &str, name: &str,
cx: &ExtCtxt, trait_span: Span, cx: &mut ExtCtxt, trait_span: Span,
substr: &Substructure) -> @Expr { substr: &Substructure) -> @Expr {
let clone_ident = substr.method_ident; let clone_ident = substr.method_ident;
let ctor_ident; let ctor_ident;

View file

@ -14,17 +14,17 @@ use ext::base::ExtCtxt;
use ext::build::AstBuilder; use ext::build::AstBuilder;
use ext::deriving::generic::*; use ext::deriving::generic::*;
pub fn expand_deriving_eq(cx: &ExtCtxt, pub fn expand_deriving_eq(cx: &mut ExtCtxt,
span: Span, span: Span,
mitem: @MetaItem, mitem: @MetaItem,
in_items: ~[@Item]) -> ~[@Item] { in_items: ~[@Item]) -> ~[@Item] {
// structures are equal if all fields are equal, and non equal, if // structures are equal if all fields are equal, and non equal, if
// any fields are not equal or if the enum variants are different // 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: &mut ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
cs_and(|cx, span, _, _| cx.expr_bool(span, false), cs_and(|cx, span, _, _| cx.expr_bool(span, false),
cx, span, substr) cx, span, substr)
} }
fn cs_ne(cx: &ExtCtxt, span: Span, substr: &Substructure) -> @Expr { fn cs_ne(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
cs_or(|cx, span, _, _| cx.expr_bool(span, true), cs_or(|cx, span, _, _| cx.expr_bool(span, true),
cx, span, substr) cx, span, substr)
} }

View file

@ -15,7 +15,7 @@ use ext::base::ExtCtxt;
use ext::build::AstBuilder; use ext::build::AstBuilder;
use ext::deriving::generic::*; use ext::deriving::generic::*;
pub fn expand_deriving_ord(cx: &ExtCtxt, pub fn expand_deriving_ord(cx: &mut ExtCtxt,
span: Span, span: Span,
mitem: @MetaItem, mitem: @MetaItem,
in_items: ~[@Item]) -> ~[@Item] { in_items: ~[@Item]) -> ~[@Item] {
@ -51,7 +51,7 @@ pub fn expand_deriving_ord(cx: &ExtCtxt,
} }
/// Strict inequality. /// Strict inequality.
fn cs_op(less: bool, equal: bool, cx: &ExtCtxt, span: Span, substr: &Substructure) -> @Expr { fn cs_op(less: bool, equal: bool, cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
let op = if less {ast::BiLt} else {ast::BiGt}; let op = if less {ast::BiLt} else {ast::BiGt};
cs_fold( cs_fold(
false, // need foldr, false, // need foldr,

View file

@ -14,11 +14,11 @@ use ext::base::ExtCtxt;
use ext::build::AstBuilder; use ext::build::AstBuilder;
use ext::deriving::generic::*; use ext::deriving::generic::*;
pub fn expand_deriving_totaleq(cx: &ExtCtxt, pub fn expand_deriving_totaleq(cx: &mut ExtCtxt,
span: Span, span: Span,
mitem: @MetaItem, mitem: @MetaItem,
in_items: ~[@Item]) -> ~[@Item] { in_items: ~[@Item]) -> ~[@Item] {
fn cs_equals(cx: &ExtCtxt, span: Span, substr: &Substructure) -> @Expr { fn cs_equals(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
cs_and(|cx, span, _, _| cx.expr_bool(span, false), cs_and(|cx, span, _, _| cx.expr_bool(span, false),
cx, span, substr) cx, span, substr)
} }

View file

@ -16,7 +16,7 @@ use ext::build::AstBuilder;
use ext::deriving::generic::*; use ext::deriving::generic::*;
use std::cmp::{Ordering, Equal, Less, Greater}; use std::cmp::{Ordering, Equal, Less, Greater};
pub fn expand_deriving_totalord(cx: &ExtCtxt, pub fn expand_deriving_totalord(cx: &mut ExtCtxt,
span: Span, span: Span,
mitem: @MetaItem, mitem: @MetaItem,
in_items: ~[@Item]) -> ~[@Item] { in_items: ~[@Item]) -> ~[@Item] {
@ -44,7 +44,7 @@ pub fn expand_deriving_totalord(cx: &ExtCtxt,
} }
pub fn ordering_const(cx: &ExtCtxt, span: Span, cnst: Ordering) -> ast::Path { pub fn ordering_const(cx: &mut ExtCtxt, span: Span, cnst: Ordering) -> ast::Path {
let cnst = match cnst { let cnst = match cnst {
Less => "Less", Less => "Less",
Equal => "Equal", Equal => "Equal",
@ -56,7 +56,7 @@ pub fn ordering_const(cx: &ExtCtxt, span: Span, cnst: Ordering) -> ast::Path {
cx.ident_of(cnst)]) cx.ident_of(cnst)])
} }
pub fn cs_cmp(cx: &ExtCtxt, span: Span, pub fn cs_cmp(cx: &mut ExtCtxt, span: Span,
substr: &Substructure) -> @Expr { substr: &Substructure) -> @Expr {
let test_id = cx.ident_of("__test"); let test_id = cx.ident_of("__test");
let equals_path = ordering_const(cx, span, Equal); let equals_path = ordering_const(cx, span, Equal);
@ -106,8 +106,10 @@ pub fn cs_cmp(cx: &ExtCtxt, span: Span,
// an earlier nonmatching variant is Less than a // an earlier nonmatching variant is Less than a
// later one. // later one.
[(self_var, _, _), [(self_var, _, _),
(other_var, _, _)] => cx.expr_path(ordering_const(cx, span, (other_var, _, _)] => {
self_var.cmp(&other_var))), let order = ordering_const(cx, span, self_var.cmp(&other_var));
cx.expr_path(order)
}
_ => cx.span_bug(span, "Not exactly 2 arguments in `deriving(TotalOrd)`") _ => cx.span_bug(span, "Not exactly 2 arguments in `deriving(TotalOrd)`")
} }
}, },

View file

@ -21,7 +21,7 @@ use ext::deriving::generic::*;
use parse::token::InternedString; use parse::token::InternedString;
use parse::token; use parse::token;
pub fn expand_deriving_decodable(cx: &ExtCtxt, pub fn expand_deriving_decodable(cx: &mut ExtCtxt,
span: Span, span: Span,
mitem: @MetaItem, mitem: @MetaItem,
in_items: ~[@Item]) -> ~[@Item] { in_items: ~[@Item]) -> ~[@Item] {
@ -53,7 +53,7 @@ pub fn expand_deriving_decodable(cx: &ExtCtxt,
trait_def.expand(mitem, in_items) trait_def.expand(mitem, in_items)
} }
fn decodable_substructure(cx: &ExtCtxt, trait_span: Span, fn decodable_substructure(cx: &mut ExtCtxt, trait_span: Span,
substr: &Substructure) -> @Expr { substr: &Substructure) -> @Expr {
let decoder = substr.nonself_args[0]; let decoder = substr.nonself_args[0];
let recurse = ~[cx.ident_of("serialize"), let recurse = ~[cx.ident_of("serialize"),
@ -77,7 +77,7 @@ fn decodable_substructure(cx: &ExtCtxt, trait_span: Span,
trait_span, trait_span,
substr.type_ident, substr.type_ident,
summary, summary,
|span, name, field| { |cx, span, name, field| {
cx.expr_method_call(span, blkdecoder, read_struct_field, cx.expr_method_call(span, blkdecoder, read_struct_field,
~[cx.expr_str(span, name), ~[cx.expr_str(span, name),
cx.expr_uint(span, field), cx.expr_uint(span, field),
@ -108,10 +108,10 @@ fn decodable_substructure(cx: &ExtCtxt, trait_span: Span,
v_span, v_span,
name, name,
parts, parts,
|span, _, field| { |cx, span, _, field| {
let idx = cx.expr_uint(span, field);
cx.expr_method_call(span, blkdecoder, rvariant_arg, cx.expr_method_call(span, blkdecoder, rvariant_arg,
~[cx.expr_uint(span, field), ~[idx, lambdadecode])
lambdadecode])
}); });
arms.push(cx.arm(v_span, arms.push(cx.arm(v_span,
@ -143,11 +143,11 @@ fn decodable_substructure(cx: &ExtCtxt, trait_span: Span,
/// Create a decoder for a single enum variant/struct: /// Create a decoder for a single enum variant/struct:
/// - `outer_pat_ident` is the name of this enum variant/struct /// - `outer_pat_ident` is the name of this enum variant/struct
/// - `getarg` should retrieve the `uint`-th field with name `@str`. /// - `getarg` should retrieve the `uint`-th field with name `@str`.
fn decode_static_fields(cx: &ExtCtxt, fn decode_static_fields(cx: &mut ExtCtxt,
trait_span: Span, trait_span: Span,
outer_pat_ident: Ident, outer_pat_ident: Ident,
fields: &StaticFields, fields: &StaticFields,
getarg: |Span, InternedString, uint| -> @Expr) getarg: |&mut ExtCtxt, Span, InternedString, uint| -> @Expr)
-> @Expr { -> @Expr {
match *fields { match *fields {
Unnamed(ref fields) => { Unnamed(ref fields) => {
@ -155,7 +155,7 @@ fn decode_static_fields(cx: &ExtCtxt,
cx.expr_ident(trait_span, outer_pat_ident) cx.expr_ident(trait_span, outer_pat_ident)
} else { } else {
let fields = fields.iter().enumerate().map(|(i, &span)| { let fields = fields.iter().enumerate().map(|(i, &span)| {
getarg(span, getarg(cx, span,
token::intern_and_get_ident(format!("_field{}", token::intern_and_get_ident(format!("_field{}",
i)), i)),
i) i)
@ -167,9 +167,8 @@ fn decode_static_fields(cx: &ExtCtxt,
Named(ref fields) => { Named(ref fields) => {
// use the field's span to get nicer error messages. // use the field's span to get nicer error messages.
let fields = fields.iter().enumerate().map(|(i, &(name, span))| { let fields = fields.iter().enumerate().map(|(i, &(name, span))| {
cx.field_imm(span, let arg = getarg(cx, span, token::get_ident(name.name), i);
name, cx.field_imm(span, name, arg)
getarg(span, token::get_ident(name.name), i))
}).collect(); }).collect();
cx.expr_struct_ident(trait_span, outer_pat_ident, fields) cx.expr_struct_ident(trait_span, outer_pat_ident, fields)
} }

View file

@ -14,7 +14,7 @@ use ext::base::ExtCtxt;
use ext::build::AstBuilder; use ext::build::AstBuilder;
use ext::deriving::generic::*; use ext::deriving::generic::*;
pub fn expand_deriving_default(cx: &ExtCtxt, pub fn expand_deriving_default(cx: &mut ExtCtxt,
span: Span, span: Span,
mitem: @MetaItem, mitem: @MetaItem,
in_items: ~[@Item]) in_items: ~[@Item])
@ -41,7 +41,7 @@ pub fn expand_deriving_default(cx: &ExtCtxt,
trait_def.expand(mitem, in_items) trait_def.expand(mitem, in_items)
} }
fn default_substructure(cx: &ExtCtxt, trait_span: Span, substr: &Substructure) -> @Expr { fn default_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> @Expr {
let default_ident = ~[ let default_ident = ~[
cx.ident_of("std"), cx.ident_of("std"),
cx.ident_of("default"), cx.ident_of("default"),

View file

@ -82,7 +82,7 @@ use ext::build::AstBuilder;
use ext::deriving::generic::*; use ext::deriving::generic::*;
use parse::token; use parse::token;
pub fn expand_deriving_encodable(cx: &ExtCtxt, pub fn expand_deriving_encodable(cx: &mut ExtCtxt,
span: Span, span: Span,
mitem: @MetaItem, mitem: @MetaItem,
in_items: ~[@Item]) -> ~[@Item] { in_items: ~[@Item]) -> ~[@Item] {
@ -114,7 +114,7 @@ pub fn expand_deriving_encodable(cx: &ExtCtxt,
trait_def.expand(mitem, in_items) trait_def.expand(mitem, in_items)
} }
fn encodable_substructure(cx: &ExtCtxt, trait_span: Span, fn encodable_substructure(cx: &mut ExtCtxt, trait_span: Span,
substr: &Substructure) -> @Expr { substr: &Substructure) -> @Expr {
let encoder = substr.nonself_args[0]; let encoder = substr.nonself_args[0];
// throw an underscore in front to suppress unused variable warnings // throw an underscore in front to suppress unused variable warnings

View file

@ -194,7 +194,7 @@ mod ty;
pub struct TraitDef<'a> { pub struct TraitDef<'a> {
/// The extension context /// The extension context
cx: &'a ExtCtxt<'a>, cx: &'a mut ExtCtxt<'a>,
/// The span for the current #[deriving(Foo)] header. /// The span for the current #[deriving(Foo)] header.
span: Span, span: Span,
@ -304,7 +304,7 @@ Combine the values of all the fields together. The last argument is
all the fields of all the structures, see above for details. all the fields of all the structures, see above for details.
*/ */
pub type CombineSubstructureFunc<'a> = pub type CombineSubstructureFunc<'a> =
'a |&ExtCtxt, Span, &Substructure| -> @Expr; 'a |&mut ExtCtxt, Span, &Substructure| -> @Expr;
/** /**
Deal with non-matching enum variants, the arguments are a list Deal with non-matching enum variants, the arguments are a list
@ -312,7 +312,7 @@ representing each variant: (variant index, ast::Variant instance,
[variant fields]), and a list of the nonself args of the type [variant fields]), and a list of the nonself args of the type
*/ */
pub type EnumNonMatchFunc<'a> = pub type EnumNonMatchFunc<'a> =
'a |&ExtCtxt, 'a |&mut ExtCtxt,
Span, Span,
&[(uint, P<ast::Variant>, ~[(Span, Option<Ident>, @Expr)])], &[(uint, P<ast::Variant>, ~[(Span, Option<Ident>, @Expr)])],
&[@Expr]| &[@Expr]|
@ -356,7 +356,7 @@ impl<'a> TraitDef<'a> {
fn create_derived_impl(&self, fn create_derived_impl(&self,
type_ident: Ident, generics: &Generics, type_ident: Ident, generics: &Generics,
methods: ~[@ast::Method]) -> @ast::Item { methods: ~[@ast::Method]) -> @ast::Item {
let cx = self.cx; let cx = &*self.cx;
let trait_path = self.path.to_path(cx, self.span, type_ident, generics); let trait_path = self.path.to_path(cx, self.span, type_ident, generics);
let mut trait_generics = self.generics.to_generics(cx, self.span, let mut trait_generics = self.generics.to_generics(cx, self.span,
@ -764,7 +764,7 @@ impl<'a> MethodDef<'a> {
matches_so_far: &mut ~[(uint, P<ast::Variant>, matches_so_far: &mut ~[(uint, P<ast::Variant>,
~[(Span, Option<Ident>, @Expr)])], ~[(Span, Option<Ident>, @Expr)])],
match_count: uint) -> @Expr { match_count: uint) -> @Expr {
let cx = trait_.cx; let cx = &trait_.cx;
if match_count == self_args.len() { if match_count == self_args.len() {
// we've matched against all arguments, so make the final // we've matched against all arguments, so make the final
// expression at the bottom of the match tree // expression at the bottom of the match tree
@ -990,7 +990,7 @@ impl<'a> TraitDef<'a> {
prefix: &str, prefix: &str,
mutbl: ast::Mutability) mutbl: ast::Mutability)
-> (@ast::Pat, ~[(Span, Option<Ident>, @Expr)]) { -> (@ast::Pat, ~[(Span, Option<Ident>, @Expr)]) {
let cx = self.cx; let cx = &self.cx;
if struct_def.fields.is_empty() { if struct_def.fields.is_empty() {
return ( return (
@ -1050,7 +1050,7 @@ impl<'a> TraitDef<'a> {
prefix: &str, prefix: &str,
mutbl: ast::Mutability) mutbl: ast::Mutability)
-> (@ast::Pat, ~[(Span, Option<Ident>, @Expr)]) { -> (@ast::Pat, ~[(Span, Option<Ident>, @Expr)]) {
let cx = self.cx; let cx = &*self.cx;
let variant_ident = variant.node.name; let variant_ident = variant.node.name;
match variant.node.kind { match variant.node.kind {
ast::TupleVariantKind(ref variant_args) => { ast::TupleVariantKind(ref variant_args) => {
@ -1093,10 +1093,10 @@ Fold the fields. `use_foldl` controls whether this is done
left-to-right (`true`) or right-to-left (`false`). left-to-right (`true`) or right-to-left (`false`).
*/ */
pub fn cs_fold(use_foldl: bool, pub fn cs_fold(use_foldl: bool,
f: |&ExtCtxt, Span, @Expr, @Expr, &[@Expr]| -> @Expr, f: |&mut ExtCtxt, Span, @Expr, @Expr, &[@Expr]| -> @Expr,
base: @Expr, base: @Expr,
enum_nonmatch_f: EnumNonMatchFunc, enum_nonmatch_f: EnumNonMatchFunc,
cx: &ExtCtxt, cx: &mut ExtCtxt,
trait_span: Span, trait_span: Span,
substructure: &Substructure) substructure: &Substructure)
-> @Expr { -> @Expr {
@ -1132,9 +1132,9 @@ f(cx, span, ~[self_1.method(__arg_1_1, __arg_2_1),
~~~ ~~~
*/ */
#[inline] #[inline]
pub fn cs_same_method(f: |&ExtCtxt, Span, ~[@Expr]| -> @Expr, pub fn cs_same_method(f: |&mut ExtCtxt, Span, ~[@Expr]| -> @Expr,
enum_nonmatch_f: EnumNonMatchFunc, enum_nonmatch_f: EnumNonMatchFunc,
cx: &ExtCtxt, cx: &mut ExtCtxt,
trait_span: Span, trait_span: Span,
substructure: &Substructure) substructure: &Substructure)
-> @Expr { -> @Expr {
@ -1166,10 +1166,10 @@ fields. `use_foldl` controls whether this is done left-to-right
*/ */
#[inline] #[inline]
pub fn cs_same_method_fold(use_foldl: bool, pub fn cs_same_method_fold(use_foldl: bool,
f: |&ExtCtxt, Span, @Expr, @Expr| -> @Expr, f: |&mut ExtCtxt, Span, @Expr, @Expr| -> @Expr,
base: @Expr, base: @Expr,
enum_nonmatch_f: EnumNonMatchFunc, enum_nonmatch_f: EnumNonMatchFunc,
cx: &ExtCtxt, cx: &mut ExtCtxt,
trait_span: Span, trait_span: Span,
substructure: &Substructure) substructure: &Substructure)
-> @Expr { -> @Expr {
@ -1196,7 +1196,7 @@ on all the fields.
#[inline] #[inline]
pub fn cs_binop(binop: ast::BinOp, base: @Expr, pub fn cs_binop(binop: ast::BinOp, base: @Expr,
enum_nonmatch_f: EnumNonMatchFunc, enum_nonmatch_f: EnumNonMatchFunc,
cx: &ExtCtxt, trait_span: Span, cx: &mut ExtCtxt, trait_span: Span,
substructure: &Substructure) -> @Expr { substructure: &Substructure) -> @Expr {
cs_same_method_fold( cs_same_method_fold(
true, // foldl is good enough true, // foldl is good enough
@ -1214,7 +1214,7 @@ pub fn cs_binop(binop: ast::BinOp, base: @Expr,
/// cs_binop with binop == or /// cs_binop with binop == or
#[inline] #[inline]
pub fn cs_or(enum_nonmatch_f: EnumNonMatchFunc, pub fn cs_or(enum_nonmatch_f: EnumNonMatchFunc,
cx: &ExtCtxt, span: Span, cx: &mut ExtCtxt, span: Span,
substructure: &Substructure) -> @Expr { substructure: &Substructure) -> @Expr {
cs_binop(ast::BiOr, cx.expr_bool(span, false), cs_binop(ast::BiOr, cx.expr_bool(span, false),
enum_nonmatch_f, enum_nonmatch_f,
@ -1224,7 +1224,7 @@ pub fn cs_or(enum_nonmatch_f: EnumNonMatchFunc,
/// cs_binop with binop == and /// cs_binop with binop == and
#[inline] #[inline]
pub fn cs_and(enum_nonmatch_f: EnumNonMatchFunc, pub fn cs_and(enum_nonmatch_f: EnumNonMatchFunc,
cx: &ExtCtxt, span: Span, cx: &mut ExtCtxt, span: Span,
substructure: &Substructure) -> @Expr { substructure: &Substructure) -> @Expr {
cs_binop(ast::BiAnd, cx.expr_bool(span, true), cs_binop(ast::BiAnd, cx.expr_bool(span, true),
enum_nonmatch_f, enum_nonmatch_f,

View file

@ -15,7 +15,7 @@ use ext::build::AstBuilder;
use ext::deriving::generic::*; use ext::deriving::generic::*;
pub fn expand_deriving_iter_bytes(cx: &ExtCtxt, pub fn expand_deriving_iter_bytes(cx: &mut ExtCtxt,
span: Span, span: Span,
mitem: @MetaItem, mitem: @MetaItem,
in_items: ~[@Item]) -> ~[@Item] { in_items: ~[@Item]) -> ~[@Item] {
@ -45,7 +45,7 @@ pub fn expand_deriving_iter_bytes(cx: &ExtCtxt,
trait_def.expand(mitem, in_items) trait_def.expand(mitem, in_items)
} }
fn iter_bytes_substructure(cx: &ExtCtxt, trait_span: Span, substr: &Substructure) -> @Expr { fn iter_bytes_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> @Expr {
let (lsb0, f)= match substr.nonself_args { let (lsb0, f)= match substr.nonself_args {
[l, f] => (l, f), [l, f] => (l, f),
_ => cx.span_bug(trait_span, "Incorrect number of arguments in `deriving(IterBytes)`") _ => cx.span_bug(trait_span, "Incorrect number of arguments in `deriving(IterBytes)`")

View file

@ -44,7 +44,7 @@ pub mod totalord;
pub mod generic; pub mod generic;
pub fn expand_meta_deriving(cx: &ExtCtxt, pub fn expand_meta_deriving(cx: &mut ExtCtxt,
_span: Span, _span: Span,
mitem: @MetaItem, mitem: @MetaItem,
in_items: ~[@Item]) in_items: ~[@Item])

View file

@ -16,7 +16,7 @@ use ext::build::AstBuilder;
use ext::deriving::generic::*; use ext::deriving::generic::*;
use parse::token::InternedString; use parse::token::InternedString;
pub fn expand_deriving_from_primitive(cx: &ExtCtxt, pub fn expand_deriving_from_primitive(cx: &mut ExtCtxt,
span: Span, span: Span,
mitem: @MetaItem, mitem: @MetaItem,
in_items: ~[@Item]) -> ~[@Item] { in_items: ~[@Item]) -> ~[@Item] {
@ -65,7 +65,7 @@ pub fn expand_deriving_from_primitive(cx: &ExtCtxt,
trait_def.expand(mitem, in_items) trait_def.expand(mitem, in_items)
} }
fn cs_from(name: &str, cx: &ExtCtxt, trait_span: Span, substr: &Substructure) -> @Expr { fn cs_from(name: &str, cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> @Expr {
let n = match substr.nonself_args { let n = match substr.nonself_args {
[n] => n, [n] => n,
_ => cx.span_bug(trait_span, "Incorrect number of arguments in `deriving(FromPrimitive)`") _ => cx.span_bug(trait_span, "Incorrect number of arguments in `deriving(FromPrimitive)`")

View file

@ -16,7 +16,7 @@ use ext::build::{AstBuilder};
use ext::deriving::generic::*; use ext::deriving::generic::*;
use opt_vec; use opt_vec;
pub fn expand_deriving_rand(cx: &ExtCtxt, pub fn expand_deriving_rand(cx: &mut ExtCtxt,
span: Span, span: Span,
mitem: @MetaItem, mitem: @MetaItem,
in_items: ~[@Item]) in_items: ~[@Item])
@ -50,7 +50,7 @@ pub fn expand_deriving_rand(cx: &ExtCtxt,
trait_def.expand(mitem, in_items) trait_def.expand(mitem, in_items)
} }
fn rand_substructure(cx: &ExtCtxt, trait_span: Span, substr: &Substructure) -> @Expr { fn rand_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> @Expr {
let rng = match substr.nonself_args { let rng = match substr.nonself_args {
[rng] => ~[ rng ], [rng] => ~[ rng ],
_ => cx.bug("Incorrect number of arguments to `rand` in `deriving(Rand)`") _ => cx.bug("Incorrect number of arguments to `rand` in `deriving(Rand)`")
@ -112,9 +112,8 @@ fn rand_substructure(cx: &ExtCtxt, trait_span: Span, substr: &Substructure) -> @
let i_expr = cx.expr_uint(v_span, i); let i_expr = cx.expr_uint(v_span, i);
let pat = cx.pat_lit(v_span, i_expr); let pat = cx.pat_lit(v_span, i_expr);
cx.arm(v_span, let thing = rand_thing(cx, v_span, ident, summary, |sp| rand_call(sp));
~[ pat ], cx.arm(v_span, ~[ pat ], thing)
rand_thing(cx, v_span, ident, summary, |sp| rand_call(sp)))
}).collect::<~[ast::Arm]>(); }).collect::<~[ast::Arm]>();
// _ => {} at the end. Should never occur // _ => {} at the end. Should never occur
@ -128,7 +127,7 @@ fn rand_substructure(cx: &ExtCtxt, trait_span: Span, substr: &Substructure) -> @
_ => cx.bug("Non-static method in `deriving(Rand)`") _ => cx.bug("Non-static method in `deriving(Rand)`")
}; };
fn rand_thing(cx: &ExtCtxt, fn rand_thing(cx: &mut ExtCtxt,
trait_span: Span, trait_span: Span,
ctor_ident: Ident, ctor_ident: Ident,
summary: &StaticFields, summary: &StaticFields,

View file

@ -17,7 +17,7 @@ use ext::deriving::generic::*;
use parse::token::InternedString; use parse::token::InternedString;
use parse::token; use parse::token;
pub fn expand_deriving_to_str(cx: &ExtCtxt, pub fn expand_deriving_to_str(cx: &mut ExtCtxt,
span: Span, span: Span,
mitem: @MetaItem, mitem: @MetaItem,
in_items: ~[@Item]) in_items: ~[@Item])
@ -49,7 +49,7 @@ pub fn expand_deriving_to_str(cx: &ExtCtxt,
// doesn't invoke the to_str() method on each field. Hence we mirror // 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() // the logic of the repr_to_str() method, but with tweaks to call to_str()
// on sub-fields. // on sub-fields.
fn to_str_substructure(cx: &ExtCtxt, span: Span, substr: &Substructure) fn to_str_substructure(cx: &mut ExtCtxt, span: Span, substr: &Substructure)
-> @Expr { -> @Expr {
let to_str = cx.ident_of("to_str"); let to_str = cx.ident_of("to_str");

View file

@ -14,7 +14,7 @@ use ext::base::ExtCtxt;
use ext::build::AstBuilder; use ext::build::AstBuilder;
use ext::deriving::generic::*; use ext::deriving::generic::*;
pub fn expand_deriving_zero(cx: &ExtCtxt, pub fn expand_deriving_zero(cx: &mut ExtCtxt,
span: Span, span: Span,
mitem: @MetaItem, mitem: @MetaItem,
in_items: ~[@Item]) in_items: ~[@Item])
@ -57,7 +57,7 @@ pub fn expand_deriving_zero(cx: &ExtCtxt,
trait_def.expand(mitem, in_items) trait_def.expand(mitem, in_items)
} }
fn zero_substructure(cx: &ExtCtxt, trait_span: Span, substr: &Substructure) -> @Expr { fn zero_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> @Expr {
let zero_ident = ~[ let zero_ident = ~[
cx.ident_of("std"), cx.ident_of("std"),
cx.ident_of("num"), cx.ident_of("num"),