changeset 694:b8c8cf55c761

Improve reordering some more, produce less nesting.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 16 Apr 2013 19:50:39 +0300
parents 837ad9dcc348
children 80ac5c21e07f
files dmeval.c
diffstat 1 files changed, 18 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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;