use ext::base::ExtCtxt;
use ext::build::AstBuilder;
use ext::deriving::generic::*;
+ use parse::token::InternedString;
pub fn expand_deriving_clone(cx: &mut ExtCtxt,
span: Span,
mitem: @MetaItem,
item: @Item,
push: |@Item|) {
+ let inline = cx.meta_word(span, InternedString::new("inline"));
+ let attrs = vec!(cx.attribute(span, inline));
let trait_def = TraitDef {
span: span,
attributes: Vec::new(),
explicit_self: borrowed_explicit_self(),
args: Vec::new(),
ret_ty: Self,
- inline: true,
+ attributes: attrs,
const_nonmatching: false,
- combine_substructure: |c, s, sub| cs_clone("Clone", c, s, sub)
+ combine_substructure: combine_substructure(|c, s, sub| {
+ cs_clone("Clone", c, s, sub)
+ }),
}
)
};
use ext::base::ExtCtxt;
use ext::build::AstBuilder;
use ext::deriving::generic::*;
+ use parse::token::InternedString;
pub fn expand_deriving_eq(cx: &mut ExtCtxt,
span: Span,
}
macro_rules! md (
- ($name:expr, $f:ident) => {
+ ($name:expr, $f:ident) => { {
+ let inline = cx.meta_word(span, InternedString::new("inline"));
+ let attrs = vec!(cx.attribute(span, inline));
MethodDef {
name: $name,
generics: LifetimeBounds::empty(),
explicit_self: borrowed_explicit_self(),
args: vec!(borrowed_self()),
ret_ty: Literal(Path::new(vec!("bool"))),
- inline: true,
+ attributes: attrs,
const_nonmatching: true,
- combine_substructure: $f
+ combine_substructure: combine_substructure(|a, b, c| {
+ $f(a, b, c)
+ })
}
- }
+ } }
);
let trait_def = TraitDef {
use ext::base::ExtCtxt;
use ext::build::AstBuilder;
use ext::deriving::generic::*;
+ use parse::token::InternedString;
pub fn expand_deriving_ord(cx: &mut ExtCtxt,
span: Span,
item: @Item,
push: |@Item|) {
macro_rules! md (
- ($name:expr, $op:expr, $equal:expr) => {
+ ($name:expr, $op:expr, $equal:expr) => { {
+ let inline = cx.meta_word(span, InternedString::new("inline"));
+ let attrs = vec!(cx.attribute(span, inline));
MethodDef {
name: $name,
generics: LifetimeBounds::empty(),
explicit_self: borrowed_explicit_self(),
args: vec!(borrowed_self()),
ret_ty: Literal(Path::new(vec!("bool"))),
- inline: true,
+ attributes: attrs,
const_nonmatching: false,
- combine_substructure: |cx, span, substr| cs_op($op, $equal, cx, span, substr)
+ combine_substructure: combine_substructure(|cx, span, substr| {
+ cs_op($op, $equal, cx, span, substr)
+ })
}
- }
+ } }
);
let trait_def = TraitDef {
use ext::base::ExtCtxt;
use ext::build::AstBuilder;
use ext::deriving::generic::*;
+ use parse::token::InternedString;
pub fn expand_deriving_totaleq(cx: &mut ExtCtxt,
span: Span,
substr)
}
+ let inline = cx.meta_word(span, InternedString::new("inline"));
+ let hidden = cx.meta_word(span, InternedString::new("hidden"));
+ let doc = cx.meta_list(span, InternedString::new("doc"), vec!(hidden));
+ let attrs = vec!(cx.attribute(span, inline),
+ cx.attribute(span, doc));
let trait_def = TraitDef {
span: span,
attributes: Vec::new(),
explicit_self: borrowed_explicit_self(),
args: vec!(),
ret_ty: nil_ty(),
- inline: true,
+ attributes: attrs,
const_nonmatching: true,
- combine_substructure: cs_total_eq_assert
+ combine_substructure: combine_substructure(|a, b, c| {
+ cs_total_eq_assert(a, b, c)
+ })
}
)
};
use ext::base::ExtCtxt;
use ext::build::AstBuilder;
use ext::deriving::generic::*;
+ use parse::token::InternedString;
use std::cmp::{Ordering, Equal, Less, Greater};
mitem: @MetaItem,
item: @Item,
push: |@Item|) {
+ let inline = cx.meta_word(span, InternedString::new("inline"));
+ let attrs = vec!(cx.attribute(span, inline));
let trait_def = TraitDef {
span: span,
attributes: Vec::new(),
explicit_self: borrowed_explicit_self(),
args: vec!(borrowed_self()),
ret_ty: Literal(Path::new(vec!("std", "cmp", "Ordering"))),
- inline: true,
+ attributes: attrs,
const_nonmatching: false,
- combine_substructure: cs_cmp
+ combine_substructure: combine_substructure(|a, b, c| {
+ cs_cmp(a, b, c)
+ }),
}
)
};
Borrowed(None, MutMutable))),
ret_ty: Literal(Path::new_(vec!("std", "result", "Result"), None,
vec!(~Self, ~Literal(Path::new_local("__E"))), true)),
- inline: false,
+ attributes: Vec::new(),
const_nonmatching: true,
- combine_substructure: decodable_substructure,
+ combine_substructure: combine_substructure(|a, b, c| {
+ decodable_substructure(a, b, c)
+ }),
})
};
use ext::base::ExtCtxt;
use ext::build::AstBuilder;
use ext::deriving::generic::*;
+ use parse::token::InternedString;
pub fn expand_deriving_default(cx: &mut ExtCtxt,
span: Span,
mitem: @MetaItem,
item: @Item,
push: |@Item|) {
+ let inline = cx.meta_word(span, InternedString::new("inline"));
+ let attrs = vec!(cx.attribute(span, inline));
let trait_def = TraitDef {
span: span,
attributes: Vec::new(),
explicit_self: None,
args: Vec::new(),
ret_ty: Self,
- inline: true,
+ attributes: attrs,
const_nonmatching: false,
- combine_substructure: default_substructure
+ combine_substructure: combine_substructure(|a, b, c| {
+ default_substructure(a, b, c)
+ })
})
};
trait_def.expand(cx, mitem, item, push)
vec!(~Tuple(Vec::new()),
~Literal(Path::new_local("__E"))),
true)),
- inline: false,
+ attributes: Vec::new(),
const_nonmatching: true,
- combine_substructure: encodable_substructure,
+ combine_substructure: combine_substructure(|a, b, c| {
+ encodable_substructure(a, b, c)
+ }),
})
};
*/
+use std::cell::RefCell;
+
use ast;
use ast::{P, EnumDef, Expr, Ident, Generics, StructDef};
use ast_util;
/// Return type
pub ret_ty: Ty<'a>,
- /// Whether to mark this as #[inline]
- pub inline: bool,
+ pub attributes: Vec<ast::Attribute>,
/// if the value of the nonmatching enums is independent of the
/// actual enum variants, i.e. can use _ => .. match.
pub const_nonmatching: bool,
- pub combine_substructure: CombineSubstructureFunc<'a>,
+ pub combine_substructure: RefCell<CombineSubstructureFunc<'a>>,
}
/// All the data about the data structure/method being derived upon.
&[@Expr]|: 'a
-> @Expr;
+pub fn combine_substructure<'a>(f: CombineSubstructureFunc<'a>)
+ -> RefCell<CombineSubstructureFunc<'a>> {
+ RefCell::new(f)
+}
+
impl<'a> TraitDef<'a> {
pub fn expand(&self,
nonself_args: nonself_args,
fields: fields
};
- (self.combine_substructure)(cx, trait_.span,
- &substructure)
+ let mut f = self.combine_substructure.borrow_mut();
+ let f: &mut CombineSubstructureFunc = &mut *f;
+ (*f)(cx, trait_.span, &substructure)
}
fn get_ret_ty(&self,
let fn_decl = cx.fn_decl(args, ret_type);
let body_block = cx.block_expr(body);
- let attrs = if self.inline {
- vec!(
- cx
- .attribute(trait_.span,
- cx
- .meta_word(trait_.span,
- InternedString::new(
- "inline")))
- )
- } else {
- Vec::new()
- };
-
// Create the method.
@ast::Method {
ident: method_ident,
- attrs: attrs,
+ attrs: self.attributes.clone(),
generics: fn_generics,
explicit_self: explicit_self,
fn_style: ast::NormalFn,
use ext::base::ExtCtxt;
use ext::build::AstBuilder;
use ext::deriving::generic::*;
+ use parse::token::InternedString;
pub fn expand_deriving_hash(cx: &mut ExtCtxt,
span: Span,
LifetimeBounds::empty(),
Path::new(vec!("std", "hash", "sip", "SipState")))
};
+ let inline = cx.meta_word(span, InternedString::new("inline"));
+ let attrs = vec!(cx.attribute(span, inline));
let hash_trait_def = TraitDef {
span: span,
attributes: Vec::new(),
explicit_self: borrowed_explicit_self(),
args: vec!(Ptr(~Literal(args), Borrowed(None, MutMutable))),
ret_ty: nil_ty(),
- inline: true,
+ attributes: attrs,
const_nonmatching: false,
- combine_substructure: hash_substructure
+ combine_substructure: combine_substructure(|a, b, c| {
+ hash_substructure(a, b, c)
+ })
}
)
};
mitem: @MetaItem,
item: @Item,
push: |@Item|) {
+ let inline = cx.meta_word(span, InternedString::new("inline"));
+ let attrs = vec!(cx.attribute(span, inline));
let trait_def = TraitDef {
span: span,
attributes: Vec::new(),
None,
vec!(~Self),
true)),
- // liable to cause code-bloat
- inline: true,
+ // #[inline] liable to cause code-bloat
+ attributes: attrs.clone(),
const_nonmatching: false,
- combine_substructure: |c, s, sub| cs_from("i64", c, s, sub),
+ combine_substructure: combine_substructure(|c, s, sub| {
+ cs_from("i64", c, s, sub)
+ }),
},
MethodDef {
name: "from_u64",
None,
vec!(~Self),
true)),
- // liable to cause code-bloat
- inline: true,
+ // #[inline] liable to cause code-bloat
+ attributes: attrs,
const_nonmatching: false,
- combine_substructure: |c, s, sub| cs_from("u64", c, s, sub),
+ combine_substructure: combine_substructure(|c, s, sub| {
+ cs_from("u64", c, s, sub)
+ }),
})
};
Borrowed(None, ast::MutMutable))
),
ret_ty: Self,
- inline: false,
+ attributes: Vec::new(),
const_nonmatching: false,
- combine_substructure: rand_substructure
+ combine_substructure: combine_substructure(|a, b, c| {
+ rand_substructure(a, b, c)
+ })
}
)
};
explicit_self: borrowed_explicit_self(),
args: vec!(fmtr),
ret_ty: Literal(Path::new(vec!("std", "fmt", "Result"))),
- inline: false,
+ attributes: Vec::new(),
const_nonmatching: false,
- combine_substructure: show_substructure
+ combine_substructure: combine_substructure(|a, b, c| {
+ show_substructure(a, b, c)
+ })
}
)
};
use ext::base::ExtCtxt;
use ext::build::AstBuilder;
use ext::deriving::generic::*;
+ use parse::token::InternedString;
pub fn expand_deriving_zero(cx: &mut ExtCtxt,
span: Span,
mitem: @MetaItem,
item: @Item,
push: |@Item|) {
+ let inline = cx.meta_word(span, InternedString::new("inline"));
+ let attrs = vec!(cx.attribute(span, inline));
let trait_def = TraitDef {
span: span,
attributes: Vec::new(),
explicit_self: None,
args: Vec::new(),
ret_ty: Self,
- inline: true,
+ attributes: attrs.clone(),
const_nonmatching: false,
- combine_substructure: zero_substructure
+ combine_substructure: combine_substructure(|a, b, c| {
+ zero_substructure(a, b, c)
+ })
},
MethodDef {
name: "is_zero",
explicit_self: borrowed_explicit_self(),
args: Vec::new(),
ret_ty: Literal(Path::new(vec!("bool"))),
- inline: true,
+ attributes: attrs,
const_nonmatching: false,
- combine_substructure: |cx, span, substr| {
+ combine_substructure: combine_substructure(|cx, span, substr| {
cs_and(|cx, span, _, _| cx.span_bug(span,
"Non-matching enum \
variant in \
deriving(Zero)"),
cx, span, substr)
- }
+ })
}
)
};