Skip to content

Commit 5841564

Browse files
committed
syntax: add support for #[deriving(Encodable)]
1 parent f50a8e2 commit 5841564

File tree

3 files changed

+455
-8
lines changed

3 files changed

+455
-8
lines changed

src/libsyntax/ext/build.rs

Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,7 @@ pub fn mk_unary(cx: @ext_ctxt, sp: span, op: ast::unop, e: @ast::expr)
6464
mk_expr(cx, sp, ast::expr_unary(op, e))
6565
}
6666
pub fn mk_raw_path(sp: span, +idents: ~[ast::ident]) -> @ast::Path {
67-
let p = @ast::Path { span: sp,
68-
global: false,
69-
idents: idents,
70-
rp: None,
71-
types: ~[] };
72-
return p;
67+
mk_raw_path_(sp, idents, ~[])
7368
}
7469
pub fn mk_raw_path_(sp: span,
7570
+idents: ~[ast::ident],
@@ -82,11 +77,16 @@ pub fn mk_raw_path_(sp: span,
8277
types: types }
8378
}
8479
pub fn mk_raw_path_global(sp: span, +idents: ~[ast::ident]) -> @ast::Path {
80+
mk_raw_path_global_(sp, idents, ~[])
81+
}
82+
pub fn mk_raw_path_global_(sp: span,
83+
+idents: ~[ast::ident],
84+
+types: ~[@ast::Ty]) -> @ast::Path {
8585
@ast::Path { span: sp,
8686
global: true,
8787
idents: idents,
8888
rp: None,
89-
types: ~[] }
89+
types: types }
9090
}
9191
pub fn mk_path(cx: @ext_ctxt, sp: span, +idents: ~[ast::ident])
9292
-> @ast::expr {
@@ -271,6 +271,29 @@ pub fn mk_simple_block(cx: @ext_ctxt,
271271
span: span,
272272
}
273273
}
274+
pub fn mk_lambda_(cx: @ext_ctxt,
275+
span: span,
276+
fn_decl: ast::fn_decl,
277+
blk: ast::blk)
278+
-> @ast::expr {
279+
mk_expr(cx, span, ast::expr_fn_block(fn_decl, blk))
280+
}
281+
pub fn mk_lambda(cx: @ext_ctxt,
282+
span: span,
283+
fn_decl: ast::fn_decl,
284+
expr: @ast::expr)
285+
-> @ast::expr {
286+
let blk = mk_simple_block(cx, span, expr);
287+
mk_lambda_(cx, span, fn_decl, blk)
288+
}
289+
pub fn mk_lambda_stmts(cx: @ext_ctxt,
290+
span: span,
291+
fn_decl: ast::fn_decl,
292+
stmts: ~[@ast::stmt])
293+
-> @ast::expr {
294+
let blk = mk_block(cx, span, ~[], stmts, None);
295+
mk_lambda(cx, span, fn_decl, blk)
296+
}
274297
pub fn mk_copy(cx: @ext_ctxt, sp: span, e: @ast::expr) -> @ast::expr {
275298
mk_expr(cx, sp, ast::expr_copy(e))
276299
}
@@ -337,12 +360,35 @@ pub fn mk_ty_path_global(cx: @ext_ctxt,
337360
let ty = @ast::Ty { id: cx.next_id(), node: ty, span: span };
338361
ty
339362
}
363+
pub fn mk_ty_rptr(cx: @ext_ctxt,
364+
span: span,
365+
ty: @ast::Ty,
366+
mutbl: ast::mutability)
367+
-> @ast::Ty {
368+
@ast::Ty {
369+
id: cx.next_id(),
370+
span: span,
371+
node: ast::ty_rptr(
372+
None,
373+
ast::mt { ty: ty, mutbl: mutbl }
374+
),
375+
}
376+
}
377+
pub fn mk_ty_infer(cx: @ext_ctxt, span: span) -> @ast::Ty {
378+
@ast::Ty {
379+
id: cx.next_id(),
380+
node: ast::ty_infer,
381+
span: span,
382+
}
383+
}
340384
pub fn mk_trait_ref_global(cx: @ext_ctxt,
341385
span: span,
342386
+idents: ~[ ast::ident ])
343387
-> @ast::trait_ref
344388
{
345-
let path = build::mk_raw_path_global(span, idents);
389+
mk_trait_ref_(cx, build::mk_raw_path_global(span, idents))
390+
}
391+
pub fn mk_trait_ref_(cx: @ext_ctxt, path: @ast::Path) -> @ast::trait_ref {
346392
@ast::trait_ref {
347393
path: path,
348394
ref_id: cx.next_id()
@@ -371,6 +417,16 @@ pub fn mk_arg(cx: @ext_ctxt,
371417
pub fn mk_fn_decl(+inputs: ~[ast::arg], output: @ast::Ty) -> ast::fn_decl {
372418
ast::fn_decl { inputs: inputs, output: output, cf: ast::return_val }
373419
}
420+
pub fn mk_trait_ty_param_bound_global(cx: @ext_ctxt,
421+
span: span,
422+
+idents: ~[ast::ident])
423+
-> ast::TyParamBound {
424+
ast::TraitTyParamBound(mk_trait_ref_global(cx, span, idents))
425+
}
426+
pub fn mk_trait_ty_param_bound_(cx: @ext_ctxt,
427+
path: @ast::Path) -> ast::TyParamBound {
428+
ast::TraitTyParamBound(mk_trait_ref_(cx, path))
429+
}
374430
pub fn mk_ty_param(cx: @ext_ctxt,
375431
ident: ast::ident,
376432
bounds: @OptVec<ast::TyParamBound>)

0 commit comments

Comments
 (0)