Skip to content

Commit a7aecc4

Browse files
committed
rustc: Implement "deriving" for monomorphic structs via a syntax extension. r=brson
1 parent 8f22582 commit a7aecc4

File tree

6 files changed

+450
-0
lines changed

6 files changed

+450
-0
lines changed

src/libsyntax/ext/base.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ fn syntax_expander_table() -> HashMap<~str, syntax_extension> {
9797
ext::log_syntax::expand_syntax_ext));
9898
syntax_expanders.insert(~"ast",
9999
builtin(ext::qquote::expand_ast));
100+
syntax_expanders.insert(~"deriving_eq",
101+
item_decorator(
102+
ext::deriving::expand_deriving_eq));
100103

101104
// Quasi-quoting expanders
102105
syntax_expanders.insert(~"quote_tokens",

src/libsyntax/ext/build.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,29 @@ fn mk_block(cx: ext_ctxt, sp: span,
136136
span: sp };
137137
mk_expr(cx, sp, ast::expr_block(blk))
138138
}
139+
fn mk_simple_block(cx: ext_ctxt, span: span, expr: @ast::expr) -> ast::blk {
140+
let block = {
141+
view_items: ~[],
142+
stmts: ~[],
143+
expr: Some(expr),
144+
id: cx.next_id(),
145+
rules: ast::default_blk
146+
};
147+
{ node: move block, span: span }
148+
}
139149
fn mk_copy(cx: ext_ctxt, sp: span, e: @ast::expr) -> @ast::expr {
140150
mk_expr(cx, sp, ast::expr_copy(e))
141151
}
142152
fn mk_managed(cx: ext_ctxt, sp: span, e: @ast::expr) -> @ast::expr {
143153
mk_expr(cx, sp, ast::expr_unary(ast::box(ast::m_imm), e))
144154
}
155+
fn mk_pat_ident(cx: ext_ctxt, span: span, ident: ast::ident) -> @ast::pat {
156+
let path = build::mk_raw_path(span, ~[ ident ]);
157+
let pat = ast::pat_ident(ast::bind_by_value, path, None);
158+
@{ id: cx.next_id(), node: move pat, span: span }
159+
}
160+
fn mk_bool(cx: ext_ctxt, span: span, value: bool) -> @ast::expr {
161+
let lit_expr = ast::expr_lit(@{ node: ast::lit_bool(value), span: span });
162+
build::mk_expr(cx, span, move lit_expr)
163+
}
164+

0 commit comments

Comments
 (0)