Skip to content

rustc: Implement "deriving" for monomorphic structs via a syntax extensi... #4005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/libsyntax/ext/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ fn syntax_expander_table() -> HashMap<~str, syntax_extension> {
syntax_expanders.insert(~"deriving_eq",
item_decorator(
ext::deriving::expand_deriving_eq));
syntax_expanders.insert(~"deriving_iter_bytes",
item_decorator(
ext::deriving::expand_deriving_iter_bytes));

// Quasi-quoting expanders
syntax_expanders.insert(~"quote_tokens",
Expand Down
74 changes: 72 additions & 2 deletions src/libsyntax/ext/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ fn mk_raw_path(sp: span, idents: ~[ast::ident]) -> @ast::path {
rp: None, types: ~[]};
return p;
}
fn mk_raw_path_(sp: span,
idents: ~[ast::ident],
+types: ~[@ast::Ty])
-> @ast::path {
@{ span: sp, global: false, idents: idents, rp: None, types: move types }
}
fn mk_path(cx: ext_ctxt, sp: span, idents: ~[ast::ident]) ->
@ast::expr {
mk_expr(cx, sp, ast::expr_path(mk_raw_path(sp, idents)))
Expand Down Expand Up @@ -136,6 +142,18 @@ fn mk_block(cx: ext_ctxt, sp: span,
span: sp };
mk_expr(cx, sp, ast::expr_block(blk))
}
fn mk_block_(cx: ext_ctxt, sp: span, +stmts: ~[@ast::stmt]) -> ast::blk {
{
node: {
view_items: ~[],
stmts: move stmts,
expr: None,
id: cx.next_id(),
rules: ast::default_blk
},
span: sp
}
}
fn mk_simple_block(cx: ext_ctxt, span: span, expr: @ast::expr) -> ast::blk {
let block = {
view_items: ~[],
Expand All @@ -152,13 +170,65 @@ fn mk_copy(cx: ext_ctxt, sp: span, e: @ast::expr) -> @ast::expr {
fn mk_managed(cx: ext_ctxt, sp: span, e: @ast::expr) -> @ast::expr {
mk_expr(cx, sp, ast::expr_unary(ast::box(ast::m_imm), e))
}
fn mk_pat(cx: ext_ctxt, span: span, +pat: ast::pat_) -> @ast::pat {
@{ id: cx.next_id(), node: move pat, span: span }
}
fn mk_pat_ident(cx: ext_ctxt, span: span, ident: ast::ident) -> @ast::pat {
let path = build::mk_raw_path(span, ~[ ident ]);
let path = mk_raw_path(span, ~[ ident ]);
let pat = ast::pat_ident(ast::bind_by_value, path, None);
@{ id: cx.next_id(), node: move pat, span: span }
mk_pat(cx, span, move pat)
}
fn mk_pat_enum(cx: ext_ctxt,
span: span,
path: @ast::path,
+subpats: ~[@ast::pat])
-> @ast::pat {
let pat = ast::pat_enum(path, Some(move subpats));
mk_pat(cx, span, move pat)
}
fn mk_bool(cx: ext_ctxt, span: span, value: bool) -> @ast::expr {
let lit_expr = ast::expr_lit(@{ node: ast::lit_bool(value), span: span });
build::mk_expr(cx, span, move lit_expr)
}
fn mk_stmt(cx: ext_ctxt, span: span, expr: @ast::expr) -> @ast::stmt {
let stmt_ = ast::stmt_semi(expr, cx.next_id());
@{ node: move stmt_, span: span }
}
fn mk_ty_path(cx: ext_ctxt,
span: span,
idents: ~[ ast::ident ])
-> @ast::Ty {
let ty = build::mk_raw_path(span, idents);
let ty = ast::ty_path(ty, cx.next_id());
let ty = @{ id: cx.next_id(), node: move ty, span: span };
ty
}
fn mk_simple_ty_path(cx: ext_ctxt,
span: span,
ident: ast::ident)
-> @ast::Ty {
mk_ty_path(cx, span, ~[ ident ])
}
fn mk_arg(cx: ext_ctxt,
span: span,
ident: ast::ident,
ty: @ast::Ty)
-> ast::arg {
let arg_pat = mk_pat_ident(cx, span, ident);
{
mode: ast::infer(cx.next_id()),
ty: ty,
pat: arg_pat,
id: cx.next_id()
}
}
fn mk_fn_decl(+inputs: ~[ast::arg], output: @ast::Ty) -> ast::fn_decl {
{ inputs: move inputs, output: output, cf: ast::return_val }
}
fn mk_ty_param(cx: ext_ctxt,
ident: ast::ident,
bounds: @~[ast::ty_param_bound])
-> ast::ty_param {
{ ident: ident, id: cx.next_id(), bounds: bounds }
}

Loading