ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/calexpr.c
(Generate patch)

Comparing ray/src/common/calexpr.c (file contents):
Revision 2.39 by greg, Sat Dec 28 18:05:13 2019 UTC vs.
Revision 2.42 by greg, Fri Apr 8 23:32:25 2022 UTC

# Line 33 | Line 33 | static const char      RCSid[] = "$Id$";
33  
34   #define  newnode()      (EPNODE *)ecalloc(1, sizeof(EPNODE))
35  
36 < #define  isdecimal(c)   (isdigit(c) || (c) == '.')
36 > #define  isdecimal(c)   (isdigit(c) | ((c) == '.'))
37  
38   static double  euminus(EPNODE *), eargument(EPNODE *), enumber(EPNODE *);
39   static double  echannel(EPNODE *);
# Line 198 | Line 198 | epfree(                        /* free a parse tree */
198  
199      }
200  
201 <    efree((char *)epar);
201 >    efree(epar);
202   }
203  
204                                  /* the following used to be a switch */
# Line 303 | Line 303 | epow(
303              errno = ERANGE;
304      }
305   #endif
306 <    if (errno == EDOM || errno == ERANGE) {
306 >    if ((errno == EDOM) | (errno == ERANGE)) {
307          wputs("Illegal power\n");
308          return(0.0);
309      }
# Line 471 | Line 471 | syntax(                        /* report syntax error and quit */
471   {
472      int  i;
473  
474 <    if (infile != NULL || lineno != 0) {
474 >    if ((infile != NULL) | (lineno != 0)) {
475          if (infile != NULL) eputs(infile);
476          if (lineno != 0) {
477              eputs(infile != NULL ? ", line " : "line ");
# Line 552 | Line 552 | getnum(void)                   /* scan a positive float */
552          str[i++] = lnext;
553          lnext = scan();
554      }
555 <    if (lnext == '.' && i < RMAXWORD) {
555 >    if ((lnext == '.') & (i < RMAXWORD)) {
556          str[i++] = lnext;
557          lnext = scan();
558          if (i == 1 && !isdigit(lnext))
# Line 589 | Line 589 | getE1(void)                    /* E1 -> E1 ADDOP E2 */
589      EPNODE  *ep1, *ep2;
590  
591      ep1 = getE2();
592 <    while (nextc == '+' || nextc == '-') {
592 >    while ((nextc == '+') | (nextc == '-')) {
593          ep2 = newnode();
594          ep2->type = nextc;
595          scan();
596          addekid(ep2, ep1);
597          addekid(ep2, getE2());
598          if (esupport&E_RCONST &&
599 <                        ep1->type == NUM && ep1->sibling->type == NUM)
599 >                        (ep1->type == NUM) & (ep1->sibling->type == NUM))
600                  ep2 = rconst(ep2);
601          ep1 = ep2;
602      }
# Line 611 | Line 611 | getE2(void)                    /* E2 -> E2 MULOP E3 */
611      EPNODE  *ep1, *ep2;
612  
613      ep1 = getE3();
614 <    while (nextc == '*' || nextc == '/') {
614 >    while ((nextc == '*') | (nextc == '/')) {
615          ep2 = newnode();
616          ep2->type = nextc;
617          scan();
# Line 619 | Line 619 | getE2(void)                    /* E2 -> E2 MULOP E3 */
619          addekid(ep2, getE3());
620          if (esupport&E_RCONST) {
621                  EPNODE  *ep3 = ep1->sibling;
622 <                if (ep1->type == NUM && ep3->type == NUM) {
622 >                if ((ep1->type == NUM) & (ep3->type == NUM)) {
623                          ep2 = rconst(ep2);
624                  } else if (ep3->type == NUM) {
625                          if (ep2->type == '/') {
# Line 635 | Line 635 | getE2(void)                    /* E2 -> E2 MULOP E3 */
635                  } else if (ep1->type == NUM && ep1->v.num == 0) {
636                          epfree(ep3);            /* (0 * E3) or (0 / E3) */
637                          ep1->sibling = NULL;
638 <                        efree((char *)ep2);
638 >                        efree(ep2);
639                          ep2 = ep1;
640                  }
641          }
# Line 661 | Line 661 | getE3(void)                    /* E3 -> E4 ^ E3 */
661          addekid(ep2, getE3());
662          if (esupport&E_RCONST) {
663                  EPNODE  *ep3 = ep1->sibling;
664 <                if (ep1->type == NUM && ep3->type == NUM) {
664 >                if ((ep1->type == NUM) & (ep3->type == NUM)) {
665                          ep2 = rconst(ep2);
666                  } else if (ep1->type == NUM && ep1->v.num == 0) {
667                          epfree(ep3);            /* (0 ^ E3) */
668                          ep1->sibling = NULL;
669 <                        efree((char *)ep2);
669 >                        efree(ep2);
670                          ep2 = ep1;
671 <                } else if ((ep3->type == NUM && ep3->v.num == 0) ||
671 >                } else if ((ep3->type == NUM && ep3->v.num == 0) |
672                                  (ep1->type == NUM && ep1->v.num == 1)) {
673                          epfree(ep2);            /* (E4 ^ 0) or (1 ^ E3) */
674                          ep2 = newnode();
675                          ep2->type = NUM;
676                          ep2->v.num = 1;
677 +                } else if (ep3->type == NUM && ep3->v.num == 1) {
678 +                        efree(ep3);     /* (E4 ^ 1) */
679 +                        ep1->sibling = NULL;
680 +                        efree(ep2);
681 +                        ep2 = ep1;
682                  }
683          }
684          return(ep2);
# Line 695 | Line 700 | getE4(void)                    /* E4 -> ADDOP E5 */
700          }
701          if (ep2->type == UMINUS) {      /* don't generate -(-E5) */
702              ep1 = ep2->v.kid;
703 <            efree((char *)ep2);
703 >            efree(ep2);
704              return(ep1);
705          }
706          ep1 = newnode();
# Line 739 | Line 744 | getE5(void)                    /* E5 -> (E1) */
744          }
745  
746          if (esupport&(E_VARIABLE|E_FUNCTION) &&
747 <                        (isalpha(nextc) || nextc == CNTXMARK)) {
747 >                        (isalpha(nextc) | (nextc == CNTXMARK))) {
748                  nam = getname();
749                  ep1 = NULL;
750                  if ((esupport&(E_VARIABLE|E_FUNCTION)) == (E_VARIABLE|E_FUNCTION)
# Line 798 | Line 803 | rconst(                        /* reduce a constant expression */
803      ep->type = NUM;
804      errno = 0;
805      ep->v.num = evalue(epar);
806 <    if (errno == EDOM || errno == ERANGE)
806 >    if ((errno == EDOM) | (errno == ERANGE))
807          syntax("bad constant expression");
808      epfree(epar);
809  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines