Skip to content

Commit 57588ed

Browse files
committed
libsyntax: Implement deriving via a syntax extension for the IterBytes trait. r=brson
1 parent b053f0b commit 57588ed

File tree

5 files changed

+442
-123
lines changed

5 files changed

+442
-123
lines changed

src/libsyntax/ext/base.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ fn syntax_expander_table() -> HashMap<~str, syntax_extension> {
100100
syntax_expanders.insert(~"deriving_eq",
101101
item_decorator(
102102
ext::deriving::expand_deriving_eq));
103+
syntax_expanders.insert(~"deriving_iter_bytes",
104+
item_decorator(
105+
ext::deriving::expand_deriving_iter_bytes));
103106

104107
// Quasi-quoting expanders
105108
syntax_expanders.insert(~"quote_tokens",

src/libsyntax/ext/build.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,18 @@ fn mk_block(cx: ext_ctxt, sp: span,
141141
span: sp };
142142
mk_expr(cx, sp, ast::expr_block(blk))
143143
}
144+
fn mk_block_(cx: ext_ctxt, sp: span, +stmts: ~[@ast::stmt]) -> ast::blk {
145+
{
146+
node: {
147+
view_items: ~[],
148+
stmts: move stmts,
149+
expr: None,
150+
id: cx.next_id(),
151+
rules: ast::default_blk
152+
},
153+
span: sp
154+
}
155+
}
144156
fn mk_simple_block(cx: ext_ctxt, span: span, expr: @ast::expr) -> ast::blk {
145157
let block = {
146158
view_items: ~[],
@@ -177,4 +189,39 @@ fn mk_bool(cx: ext_ctxt, span: span, value: bool) -> @ast::expr {
177189
let lit_expr = ast::expr_lit(@{ node: ast::lit_bool(value), span: span });
178190
build::mk_expr(cx, span, move lit_expr)
179191
}
192+
fn mk_stmt(cx: ext_ctxt, span: span, expr: @ast::expr) -> @ast::stmt {
193+
let stmt_ = ast::stmt_semi(expr, cx.next_id());
194+
@{ node: move stmt_, span: span }
195+
}
196+
fn mk_ty_path(cx: ext_ctxt,
197+
span: span,
198+
idents: ~[ ast::ident ])
199+
-> @ast::Ty {
200+
let ty = build::mk_raw_path(span, idents);
201+
let ty = ast::ty_path(ty, cx.next_id());
202+
let ty = @{ id: cx.next_id(), node: move ty, span: span };
203+
ty
204+
}
205+
fn mk_simple_ty_path(cx: ext_ctxt,
206+
span: span,
207+
ident: ast::ident)
208+
-> @ast::Ty {
209+
mk_ty_path(cx, span, ~[ ident ])
210+
}
211+
fn mk_arg(cx: ext_ctxt,
212+
span: span,
213+
ident: ast::ident,
214+
ty: @ast::Ty)
215+
-> ast::arg {
216+
let arg_pat = mk_pat_ident(cx, span, ident);
217+
{
218+
mode: ast::infer(cx.next_id()),
219+
ty: ty,
220+
pat: arg_pat,
221+
id: cx.next_id()
222+
}
223+
}
224+
fn mk_fn_decl(+inputs: ~[ast::arg], output: @ast::Ty) -> ast::fn_decl {
225+
{ inputs: move inputs, output: output, cf: ast::return_val }
226+
}
180227

0 commit comments

Comments
 (0)