Skip to content

Commit 441df26

Browse files
committed
syntax: add support for #[deriving(Decodable)]
1 parent 5841564 commit 441df26

File tree

3 files changed

+510
-7
lines changed

3 files changed

+510
-7
lines changed

src/libsyntax/ext/build.rs

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,10 @@ pub fn mk_lambda_(cx: @ext_ctxt,
279279
mk_expr(cx, span, ast::expr_fn_block(fn_decl, blk))
280280
}
281281
pub fn mk_lambda(cx: @ext_ctxt,
282-
span: span,
283-
fn_decl: ast::fn_decl,
284-
expr: @ast::expr)
285-
-> @ast::expr {
282+
span: span,
283+
fn_decl: ast::fn_decl,
284+
expr: @ast::expr)
285+
-> @ast::expr {
286286
let blk = mk_simple_block(cx, span, expr);
287287
mk_lambda_(cx, span, fn_decl, blk)
288288
}
@@ -294,6 +294,13 @@ pub fn mk_lambda_stmts(cx: @ext_ctxt,
294294
let blk = mk_block(cx, span, ~[], stmts, None);
295295
mk_lambda(cx, span, fn_decl, blk)
296296
}
297+
pub fn mk_lambda_no_args(cx: @ext_ctxt,
298+
span: span,
299+
expr: @ast::expr)
300+
-> @ast::expr {
301+
let fn_decl = mk_fn_decl(~[], mk_ty_infer(cx, span));
302+
mk_lambda(cx, span, fn_decl, expr)
303+
}
297304
pub fn mk_copy(cx: @ext_ctxt, sp: span, e: @ast::expr) -> @ast::expr {
298305
mk_expr(cx, sp, ast::expr_copy(e))
299306
}
@@ -303,11 +310,20 @@ pub fn mk_managed(cx: @ext_ctxt, sp: span, e: @ast::expr) -> @ast::expr {
303310
pub fn mk_pat(cx: @ext_ctxt, span: span, +pat: ast::pat_) -> @ast::pat {
304311
@ast::pat { id: cx.next_id(), node: pat, span: span }
305312
}
313+
pub fn mk_pat_wild(cx: @ext_ctxt, span: span) -> @ast::pat {
314+
mk_pat(cx, span, ast::pat_wild)
315+
}
316+
pub fn mk_pat_lit(cx: @ext_ctxt,
317+
span: span,
318+
expr: @ast::expr) -> @ast::pat {
319+
mk_pat(cx, span, ast::pat_lit(expr))
320+
}
306321
pub fn mk_pat_ident(cx: @ext_ctxt,
307322
span: span,
308323
ident: ast::ident) -> @ast::pat {
309324
mk_pat_ident_with_binding_mode(cx, span, ident, ast::bind_by_copy)
310325
}
326+
311327
pub fn mk_pat_ident_with_binding_mode(cx: @ext_ctxt,
312328
span: span,
313329
ident: ast::ident,
@@ -435,8 +451,38 @@ pub fn mk_ty_param(cx: @ext_ctxt,
435451
}
436452
pub fn mk_lifetime(cx: @ext_ctxt,
437453
span: span,
438-
ident: ast::ident) -> ast::Lifetime
439-
{
454+
ident: ast::ident)
455+
-> ast::Lifetime {
440456
ast::Lifetime { id: cx.next_id(), span: span, ident: ident }
441457
}
442-
458+
pub fn mk_arm(cx: @ext_ctxt,
459+
span: span,
460+
pats: ~[@ast::pat],
461+
expr: @ast::expr)
462+
-> ast::arm {
463+
ast::arm {
464+
pats: pats,
465+
guard: None,
466+
body: mk_simple_block(cx, span, expr)
467+
}
468+
}
469+
pub fn mk_unreachable(cx: @ext_ctxt, span: span) -> @ast::expr {
470+
let loc = cx.codemap().lookup_char_pos(span.lo);
471+
mk_call_global(
472+
cx,
473+
span,
474+
~[
475+
cx.ident_of(~"core"),
476+
cx.ident_of(~"sys"),
477+
cx.ident_of(~"begin_unwind"),
478+
],
479+
~[
480+
mk_uniq_str(cx, span, ~"internal error: entered unreachable code"),
481+
mk_uniq_str(cx, span, loc.file.name),
482+
mk_uint(cx, span, loc.line),
483+
]
484+
)
485+
}
486+
pub fn mk_unreachable_arm(cx: @ext_ctxt, span: span) -> ast::arm {
487+
mk_arm(cx, span, ~[mk_pat_wild(cx, span)], mk_unreachable(cx, span))
488+
}

0 commit comments

Comments
 (0)