From 99dd5911a1026da0a374b697e4a0407a631eb388 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Tue, 15 Apr 2014 22:00:14 +1000 Subject: syntax: unify all MacResult's into a single trait. There's now one unified way to return things from a macro, instead of being able to choose the `AnyMacro` trait or the `MRItem`/`MRExpr` variants of the `MacResult` enum. This does simplify the logic handling the expansions, but the biggest value of this is it makes macros in (for example) type position easier to implement, as there's this single thing to modify. By my measurements (using `-Z time-passes` on libstd and librustc etc.), this appears to have little-to-no impact on expansion speed. There are presumably larger costs than the small number of extra allocations and virtual calls this adds (notably, all `macro_rules!`-defined macros have not changed in behaviour, since they had to use the `AnyMacro` trait anyway). --- src/libhexfloat/lib.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/libhexfloat') diff --git a/src/libhexfloat/lib.rs b/src/libhexfloat/lib.rs index 9f2f417080f..e65b84091e5 100644 --- a/src/libhexfloat/lib.rs +++ b/src/libhexfloat/lib.rs @@ -53,7 +53,7 @@ use syntax::ast; use syntax::ast::Name; use syntax::codemap::{Span, mk_sp}; use syntax::ext::base; -use syntax::ext::base::{SyntaxExtension, BasicMacroExpander, NormalTT, ExtCtxt, MRExpr}; +use syntax::ext::base::{SyntaxExtension, BasicMacroExpander, NormalTT, ExtCtxt, MacExpr}; use syntax::ext::build::AstBuilder; use syntax::parse; use syntax::parse::token; @@ -97,7 +97,7 @@ fn hex_float_lit_err(s: &str) -> Option<(uint, ~str)> { } } -pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> base::MacResult { +pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> ~base::MacResult { let (expr, ty_lit) = parse_tts(cx, tts); let ty = match ty_lit { @@ -121,12 +121,12 @@ pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> } _ => { cx.span_err(expr.span, "unsupported literal in hexfloat!"); - return base::MacResult::dummy_expr(sp); + return base::DummyResult::expr(sp); } }, _ => { cx.span_err(expr.span, "non-literal in hexfloat!"); - return base::MacResult::dummy_expr(sp); + return base::DummyResult::expr(sp); } }; @@ -137,7 +137,7 @@ pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> let pos = expr.span.lo + syntax::codemap::Pos::from_uint(err_pos + 1); let span = syntax::codemap::mk_sp(pos,pos); cx.span_err(span, format!("invalid hex float literal in hexfloat!: {}", err_str)); - return base::MacResult::dummy_expr(sp); + return base::DummyResult::expr(sp); } _ => () } @@ -147,7 +147,7 @@ pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> None => ast::LitFloatUnsuffixed(s), Some (ty) => ast::LitFloat(s, ty) }; - MRExpr(cx.expr_lit(sp, lit)) + MacExpr::new(cx.expr_lit(sp, lit)) } struct Ident { -- cgit 1.4.1-3-g733a5