use ext::base::ExtCtxt;
use ext::build::AstBuilder;
use ext::deriving::generic::*;
-
use parse::token;
-use std::hashmap::HashMap;
+use collections::HashMap;
+use std::strbuf::StrBuf;
pub fn expand_deriving_show(cx: &mut ExtCtxt,
span: Span,
item: @Item,
push: |@Item|) {
// &mut ::std::fmt::Formatter
- let fmtr = Ptr(~Literal(Path::new(~["std", "fmt", "Formatter"])),
+ let fmtr = Ptr(~Literal(Path::new(vec!("std", "fmt", "Formatter"))),
Borrowed(None, ast::MutMutable));
let trait_def = TraitDef {
span: span,
- path: Path::new(~["std", "fmt", "Show"]),
- additional_bounds: ~[],
+ attributes: Vec::new(),
+ path: Path::new(vec!("std", "fmt", "Show")),
+ additional_bounds: Vec::new(),
generics: LifetimeBounds::empty(),
- methods: ~[
+ methods: vec!(
MethodDef {
name: "fmt",
generics: LifetimeBounds::empty(),
explicit_self: borrowed_explicit_self(),
- args: ~[fmtr],
- ret_ty: Literal(Path::new(~["std", "fmt", "Result"])),
- inline: false,
+ args: vec!(fmtr),
+ ret_ty: Literal(Path::new(vec!("std", "fmt", "Result"))),
+ attributes: Vec::new(),
const_nonmatching: false,
- combine_substructure: show_substructure
+ combine_substructure: combine_substructure(|a, b, c| {
+ show_substructure(a, b, c)
+ })
}
- ]
+ )
};
trait_def.expand(cx, mitem, item, push)
}
}
};
- let mut format_string = token::get_ident(name).get().to_owned();
+ let mut format_string = StrBuf::from_str(token::get_ident(name).get());
// the internal fields we're actually formatting
- let mut exprs = ~[];
+ let mut exprs = Vec::new();
// Getting harder... making the format string:
match *substr.fields {
// unit struct/nullary variant: no work necessary!
- Struct([]) | EnumMatching(_, _, []) => {}
+ Struct(ref fields) if fields.len() == 0 => {}
+ EnumMatching(_, _, ref fields) if fields.len() == 0 => {}
Struct(ref fields) | EnumMatching(_, _, ref fields) => {
- if fields[0].name.is_none() {
+ if fields.get(0).name.is_none() {
// tuple struct/"normal" variant
format_string.push_str("(");
let formatter = substr.nonself_args[0];
let buf = cx.expr_field_access(span, formatter, cx.ident_of("buf"));
- let std_write = ~[cx.ident_of("std"), cx.ident_of("fmt"), cx.ident_of("write")];
+ let std_write = vec!(cx.ident_of("std"), cx.ident_of("fmt"), cx.ident_of("write"));
let args = cx.ident_of("__args");
- let write_call = cx.expr_call_global(span, std_write, ~[buf, cx.expr_ident(span, args)]);
- let format_closure = cx.lambda_expr(span, ~[args], write_call);
+ let write_call = cx.expr_call_global(span, std_write, vec!(buf, cx.expr_ident(span, args)));
+ let format_closure = cx.lambda_expr(span, vec!(args), write_call);
- let s = token::intern_and_get_ident(format_string);
+ let s = token::intern_and_get_ident(format_string.as_slice());
let format_string = cx.expr_str(span, s);
// phew, not our responsibility any more!
format::expand_preparsed_format_args(cx, span,
format_closure,
- format_string, exprs, HashMap::new())
+ format_string, exprs, Vec::new(),
+ HashMap::new())
}