Eliminate temp_case, and a few other cleanups.
[pspp] / src / expr-opt.c
index e221d4e2e0c0373234079243ad2ca5abbbfd54a8..4cfaf04b817ee5ae126aa1f98bbefd1a2e60e8aa 100644 (file)
    02111-1307, USA. */
 
 #include <config.h>
+#include "expr.h"
+#include "exprP.h"
 #include <assert.h>
 #include <math.h>
 #include <ctype.h>
 #include <errno.h>
 #include <stdlib.h>
 #include "alloc.h"
-#include "approx.h"
 #include "data-in.h"
 #include "error.h"
-#include "expr.h"
-#include "exprP.h"
 #include "julcal/julcal.h"
 #include "misc.h"
+#include "pool.h"
 #include "stats.h"
 #include "str.h"
 #include "var.h"
@@ -145,7 +145,7 @@ optimize_tree (struct nonterm_node * n)
       int nvar = 0;
 
       /* New node. */
-      struct nonterm_node *m;
+      struct nonterm_node *m = NULL;
 
       /* Argument copying counter. */
       int c;
@@ -171,7 +171,7 @@ optimize_tree (struct nonterm_node * n)
 
       /* 0*SYSMIS=0, 0/SYSMIS=0; otherwise, SYSMIS and infinities
          produce SYSMIS. */
-      if (approx_eq (cval, 0.0) && n->type == OP_MUL)
+      if (cval == 0.0 && n->type == OP_MUL)
        nvar = 0;
       else if (sysmis || !finite (cval))
        {
@@ -197,7 +197,7 @@ optimize_tree (struct nonterm_node * n)
        {
          /* Otherwise consolidate all the nonconstant terms. */
          m = xmalloc (sizeof (struct nonterm_node)
-                      + ((nvar + approx_ne (cval, def) - 1)
+                      + ((nvar + (cval != def) - 1)
                          * sizeof (union any_node *)));
          for (i = c = 0; i < n->n; i++)
            if (n->arg[i]->type != OP_NUM_CON)
@@ -205,7 +205,7 @@ optimize_tree (struct nonterm_node * n)
            else
              free_node (n->arg[i]);
 
-         if (approx_ne (cval, def))
+         if (cval != def)
            {
              m->arg[c] = xmalloc (sizeof (struct num_con_node));
              m->arg[c]->num_con.type = OP_NUM_CON;
@@ -223,7 +223,7 @@ optimize_tree (struct nonterm_node * n)
     {
       if (n->arg[1]->type == OP_NUM_CON)
        {
-         if (approx_eq (n1, 1.0))
+         if (n1 == 1.0)
            {
              struct nonterm_node *m = (struct nonterm_node *) n->arg[0];
 
@@ -231,7 +231,7 @@ optimize_tree (struct nonterm_node * n)
              free (n);
              return m;
            }
-         else if (approx_eq (n1, 2.0))
+         else if (n1 == 2.0)
            {
              n = xrealloc (n, sizeof (struct nonterm_node));
              n->type = OP_SQUARE;
@@ -285,7 +285,7 @@ evaluate_tree (struct nonterm_node * n)
       return optimize_tree (n);
 
     case OP_POW:
-      if (approx_eq (n0, 0.0) && approx_eq (n1, 0.0))
+      if (n0 == 0.0 && n1 == 0.0)
        frnc (SYSMIS);
       else if (n0 == SYSMIS && n1 == 0.0)
        frnc (1.0);
@@ -316,22 +316,22 @@ evaluate_tree (struct nonterm_node * n)
       break;
 
     case OP_EQ:
-      rnc (approx_eq (n0, n1));
+      rnc (n0 == n1);
       break;
     case OP_GE:
-      rnc (approx_ge (n0, n1));
+      rnc (n0 >= n1);
       break;
     case OP_GT:
-      rnc (approx_gt (n0, n1));
+      rnc (n0 > n1);
       break;
     case OP_LE:
-      rnc (approx_le (n0, n1));
+      rnc (n0 <= n1);
       break;
     case OP_LT:
-      rnc (approx_lt (n0, n1));
+      rnc (n0 < n1);
       break;
     case OP_NE:
-      rnc (approx_ne (n0, n1));
+      rnc (n0 != n1);
       break;
 
       /* String operators. */
@@ -413,7 +413,7 @@ evaluate_tree (struct nonterm_node * n)
          for (i = 1; i < n->n; i++)
            {
              ni = n->arg[i]->num_con.value;
-             if (approx_eq (n0, ni))
+             if (n0 == ni)
                {
                  frnc (1.0);
                  goto any_done;
@@ -518,7 +518,7 @@ evaluate_tree (struct nonterm_node * n)
              if (min == SYSMIS || max == SYSMIS)
                continue;
              sysmis = 0;
-             if (approx_ge (n0, min) && approx_le (n0, max))
+             if (n0 >= min && n0 <= max)
                {
                  frnc (1.0);
                  goto range_done;
@@ -768,7 +768,7 @@ evaluate_tree (struct nonterm_node * n)
     case OP_RTRIM:
     case OP_RTRIM_OPT:
       {
-       int c;
+       int c = ' ';
        char *cp = s0;
 
        if (n->type == OP_LTRIM_OPT || n->type == OP_RTRIM_OPT)
@@ -778,7 +778,6 @@ evaluate_tree (struct nonterm_node * n)
                c = n->type == OP_LTRIM_OPT ? 'L' : 'R';
                msg (SE, _("Second argument to %cTRIM() must be at least one "
                     "character in length."), c);
-               c = ' ';
              }
            else
              c = s1[0];
@@ -834,6 +833,7 @@ evaluate_tree (struct nonterm_node * n)
        f.d = (int) n->arg[3];
        v.f = n0;
 
+        assert ((formats[f.type].cat & FCAT_STRING) == 0);
        data_out (strbuf, &f, &v);
        n = repl_str_con (n, strbuf, f.w);
       }
@@ -865,15 +865,15 @@ evaluate_tree (struct nonterm_node * n)
       rnc (1.0 / n0);
       break;
     case OP_MOD:
-      if (approx_eq (n0, 0.0) && n1 == SYSMIS)
+      if (n0 == 0.0 && n1 == SYSMIS)
        frnc (0.0);
       else
        rnc (fmod (n0, n1));
       break;
     case OP_NUM_TO_BOOL:
-      if (approx_eq (n0, 0.0))
+      if (n0 == 0.0)
        n0 = 0.0;
-      else if (approx_eq (n0, 1.0))
+      else if (n0 == 1.0)
        n0 = 1.0;
       else if (n0 != SYSMIS)
        {
@@ -884,12 +884,6 @@ evaluate_tree (struct nonterm_node * n)
        }
       rnc (n0);
       break;
-
-#if __CHECKER__
-      /* This case prevents Checker from choking. */
-    case 42000:
-      assert (0);
-#endif
     }
   return n;
 }
@@ -1027,19 +1021,13 @@ dump_expression (union any_node * n, struct expression * expr)
        max_height = height;
     }
 
-  /* ANSI says we have to waste space for one `value' since pointers
-     are not guaranteed to be able to point to a spot *before* a
-     block.  If only all the world were a VAX... */
+  /* We waste space for one `value' since pointers are not
+     guaranteed to be able to point to a spot before a block. */
   max_height++;
 
   e->stack = xmalloc (max_height * sizeof *e->stack);
 
-#if PAGED_STACK
-  e->str_stack = e->type == EX_STRING ? xmalloc (256) : NULL;
-#else
-  e->str_stack = xmalloc (256);
-  e->str_size = 256;
-#endif
+  e->pool = pool_create ();
 }
 
 static void