From 0e9785ccc1d2c440d4251df74c909964fd46f312 Mon Sep 17 00:00:00 2001 From: Joe Wilm Date: Fri, 16 Sep 2016 20:24:37 -0700 Subject: Add custom Debug for ext::Transition This shows the variant in addition to the packed value - much more helpful when debugging. --- codegen/src/ext.rs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'codegen/src/ext.rs') diff --git a/codegen/src/ext.rs b/codegen/src/ext.rs index 0124435..94fdd51 100644 --- a/codegen/src/ext.rs +++ b/codegen/src/ext.rs @@ -1,3 +1,5 @@ +use std::fmt; + use syntex::Registry; use syntex_syntax::ast::{self, ExprKind, MetaItem, Arm, Expr, PatKind, LitKind, Pat}; @@ -141,21 +143,35 @@ fn input_mapping_from_arm(arm: Arm, cx: &mut ExtCtxt) -> Result fmt::Result { + match *self { + Transition::State(state) => try!(write!(f, "State({:?})", state)), + Transition::Action(action) => try!(write!(f, "Action({:?})", action)), + Transition::StateAction(state, action) => { + try!(write!(f, "StateAction({:?}, {:?})", state, action)); + } + } + + write!(f, " -> {:?}", self.pack_u8()) + } +} + impl Transition { // State is stored in the top 4 bits fn pack_u8(&self) -> u8 { match *self { - Transition::State(ref state) => (*state as u8) << 4, - Transition::Action(ref action) => *action as u8, - Transition::StateAction(ref state, ref action) => { - ((*state as u8) << 4) & (*action as u8) + Transition::State(state) => state as u8, + Transition::Action(action) => (action as u8) << 4, + Transition::StateAction(state, action) => { + ((action as u8) << 4) | (state as u8) } } } -- cgit