# HG changeset patch # User Matti Hamalainen # Date 1366131039 -10800 # Node ID b8c8cf55c7616043409c1432f47ac5bfb5347eb3 # Parent 837ad9dcc3483c7b0169659a9ea69fb2e44ffdbe Improve reordering some more, produce less nesting. diff -r 837ad9dcc348 -r b8c8cf55c761 dmeval.c --- a/dmeval.c Tue Apr 16 19:02:42 2013 +0300 +++ b/dmeval.c Tue Apr 16 19:50:39 2013 +0300 @@ -872,13 +872,19 @@ { DMEvalNode *list = NULL; DMEvalNode *tmp, *sub; - int res; for (; node != NULL; node = node->next) switch (node->op) { case OP_SUB: case OP_ADD: + if (node->ok) + { + if (dm_eval_push_node(&list, node) == NULL) + return -32; + break; + } + // Pop previous node, f.e. 5*3 -> 5 if ((tmp = dm_eval_pop_node(&list)) == NULL) return -24; @@ -891,7 +897,8 @@ dm_eval_push_node(&(sub->subexpr), tmp); // Add this operator into subexpression - dm_eval_add_node(&(sub->subexpr), node->op); + DMEvalNode *foo = dm_eval_add_node(&(sub->subexpr), node->op); + foo->ok = TRUE; // Next node node = node->next; @@ -1062,8 +1069,15 @@ result = DMCONVTYPE result % DMCONVTYPE tmp; break; - case OP_LSHIFT: result = DMCONVTYPE result << DMCONVTYPE tmp; break; - case OP_RSHIFT: result = DMCONVTYPE result >> DMCONVTYPE tmp; break; + case OP_LSHIFT: + if (tmp > 31) + dm_eval_err(ev, "Left shift count >= width of type"); + result = DMCONVTYPE result << DMCONVTYPE tmp; break; + + case OP_RSHIFT: + if (tmp > 31) + dm_eval_err(ev, "Right shift count >= width of type"); + result = DMCONVTYPE result >> DMCONVTYPE tmp; break; case OP_AND: result = DMCONVTYPE result & DMCONVTYPE tmp; break; case OP_OR: result = DMCONVTYPE result | DMCONVTYPE tmp; break;