diff options
| author | Erick Tryzelaar <erick.tryzelaar@gmail.com> | 2013-09-16 21:12:18 -0700 |
|---|---|---|
| committer | Erick Tryzelaar <erick.tryzelaar@gmail.com> | 2013-10-02 07:55:41 -0700 |
| commit | 0feaccf5260bc59f7ee4294a2ecc875da669ad30 (patch) | |
| tree | 633a987e41b539c7d52acde7479f37a87f72022d /src/libsyntax/ext/build.rs | |
| parent | d9d1dfc1955fabb7ee3a55e9c84cdcd5aad67417 (diff) | |
syntax: Add #[deriving(FromPrimitive)] syntax extension
Right now this only works for c-style enums.
Diffstat (limited to 'src/libsyntax/ext/build.rs')
| -rw-r--r-- | src/libsyntax/ext/build.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 5111682f6d0..8e4f553cb83 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -113,6 +113,7 @@ pub trait AstBuilder { expr: @ast::Expr, ident: ast::Ident, args: ~[@ast::Expr]) -> @ast::Expr; fn expr_block(&self, b: ast::Block) -> @ast::Expr; + fn expr_cast(&self, sp: Span, expr: @ast::Expr, ty: ast::Ty) -> @ast::Expr; fn field_imm(&self, span: Span, name: Ident, e: @ast::Expr) -> ast::Field; fn expr_struct(&self, span: Span, path: ast::Path, fields: ~[ast::Field]) -> @ast::Expr; @@ -132,6 +133,9 @@ pub trait AstBuilder { fn expr_str(&self, sp: Span, s: @str) -> @ast::Expr; fn expr_str_uniq(&self, sp: Span, s: @str) -> @ast::Expr; + fn expr_some(&self, sp: Span, expr: @ast::Expr) -> @ast::Expr; + fn expr_none(&self, sp: Span) -> @ast::Expr; + fn expr_unreachable(&self, span: Span) -> @ast::Expr; fn pat(&self, span: Span, pat: ast::Pat_) -> @ast::Pat; @@ -564,6 +568,29 @@ impl AstBuilder for @ExtCtxt { } + fn expr_cast(&self, sp: Span, expr: @ast::Expr, ty: ast::Ty) -> @ast::Expr { + self.expr(sp, ast::ExprCast(expr, ty)) + } + + + fn expr_some(&self, sp: Span, expr: @ast::Expr) -> @ast::Expr { + let some = ~[ + self.ident_of("std"), + self.ident_of("option"), + self.ident_of("Some"), + ]; + self.expr_call_global(sp, some, ~[expr]) + } + + fn expr_none(&self, sp: Span) -> @ast::Expr { + let none = self.path_global(sp, ~[ + self.ident_of("std"), + self.ident_of("option"), + self.ident_of("None"), + ]); + self.expr_path(none) + } + fn expr_unreachable(&self, span: Span) -> @ast::Expr { let loc = self.codemap().lookup_char_pos(span.lo); self.expr_call_global( |
