Quick Search:

Mode

Context

Displaying 3 lines of context. None | Less | More | Full

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.69
 
1.70
 
MAIN:ragge:20030803150037
 
trees.c
_>178178                 case NE:
 179179                 case ANDAND:
 180180                 case OROR:
<>181 -                case CBRANCH:
182181 
 183182                 ccwarn:
 184183 
     
 !
15001499 extern int negrel[];
 15011500 
 15021501 /*
<> 1502+ * Walk up through the tree from the leaves,
  1503+ * removing constant operators.
  1504+ */
  1505+static void
  1506+logwalk(NODE *p)
  1507+{
  1508+        int o = coptype(p->n_op);
  1509+        NODE *l, *r;
  1510+
  1511+        l = p->n_left;
  1512+        r = p->n_right;
  1513+        switch (o) {
  1514+        case LTYPE:
  1515+                return;
  1516+        case BITYPE:
  1517+                logwalk(r);
  1518+        case UTYPE:
  1519+                logwalk(l);
  1520+        }
  1521+        if (!clogop(p->n_op))
  1522+                return;
  1523+        if (p->n_op == NOT && l->n_op == ICON) {
  1524+                p->n_lval = l->n_lval == 0;
  1525+                nfree(l);
  1526+                p->n_op = ICON;
  1527+        }
  1528+        if (l->n_op == ICON && r->n_op == ICON) {
  1529+                if (conval(l, p->n_op, r) == 0)
  1530+                        cerror("logwalk");
  1531+                p->n_lval = l->n_lval;
  1532+                p->n_op = ICON;
  1533+                nfree(l);
  1534+                nfree(r);
  1535+        }
  1536+}
  1537+
  1538+/*
  1539+ * Removes redundant logical operators for branch conditions.
  1540+ */
  1541+static void
  1542+fixbranch(NODE *p, int label)
  1543+{
  1544+
  1545+        logwalk(p);
  1546+
  1547+        if (p->n_op == ICON) {
  1548+                if (p->n_lval != 0)
  1549+                        branch(label);
  1550+                nfree(p);
  1551+        } else {
  1552+                if (!clogop(p->n_op)) /* Always conditional */
  1553+                        p = buildtree(NE, p, bcon(0));
  1554+                ecode(buildtree(CBRANCH, p, bcon(label)));
  1555+        }
  1556+}
  1557+
  1558+/*
15031559  * Write out logical expressions as branches.
 15041560  */
 15051561 static void
     
 !
15481604 
 15491605                 rmcops(p->n_left);
 15501606                 rmcops(p->n_right);
<>1551 -                ecode(buildtree(CBRANCH, p, bcon(true)));
  1607+                fixbranch(p, true);
15521608                 if (false >= 0)
 15531609                         branch(false);
 15541610                 break;
     
 !
16051661         default:
 16061662                 rmcops(p);
 16071663                 if (true >= 0)
<>1608 -                        ecode(buildtree(CBRANCH, p, bcon(true)));
  1664+                        fixbranch(p, true);
16091665                 if (false >= 0) {
 16101666                         if (true >= 0)
 16111667                                 branch(false);
 16121668                         else
<>1613 -                                ecode(buildtree(CBRANCH,
 1614 -                                    buildtree(EQ, p, bcon(0)), bcon(false)));
  1669+                                fixbranch(buildtree(EQ, p, bcon(0)), false);
16151670                 }
 16161671         }
 16171672 }
     
 !
16391694 
 16401695                 tval = tvaloff++;
 16411696                 /*
<>1642 -                 * Create a CBRANCH node from ?:
  1697+                 * Create a branch node from ?:
<_16431698                  * || and && must be taken special care of.
 16441699                  */
 16451700                 andorbr(p->n_left, -1, lbl = getlab());
FishEye: Open Source License registered to PCC.
Your maintenance has expired. You can renew your license at http://www.atlassian.com/fisheye/renew
Atlassian FishEye, CVS analysis. (Version:1.6.3 Build:build-336 2008-11-04) - Administration - Page generated 2014-07-11 06:40 +0200