Quick Search:

Mode

Context

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

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.57
 
1.58
 
MAIN:ragge:20030729092515
 
trees.c
_>121121 
 122122 # ifndef BUG1
 123123         if (bdebug)
<>124 -                printf("buildtree(%s, %p, %p)\n", opst[o], l, r);
  124+                printf("buildtree(%s, %p, %p)\n", copst(o), l, r);
125125 # endif
<>126 -        opty = optype(o);
  126+        opty = coptype(o);
127127 
 128128         /* check for constants */
 129129 
     
 !
674674 
 675675         /* check for enumerations */
 676676         if (t1==ENUMTY || t2==ENUMTY) {
<>677 -                if( logop( p->n_op ) && p->n_op != EQ && p->n_op != NE ) {
  677+                if( clogop( p->n_op ) && p->n_op != EQ && p->n_op != NE ) {
678678                         uerror( "comparison of enums" );
 679679                         return;
 680680                         }
 681681                 if (t1==ENUMTY && t2==ENUMTY) {
 682682                         if (p->n_left->n_sue!=p->n_right->n_sue)
 683683                                 werror("enumeration type clash, "
<>684 -                                    "operator %s", opst[p->n_op]);
  684+                                    "operator %s", copst(p->n_op));
685685                         return;
 686686                 }
 687687         }
     
 !
10131013 
 10141014         p->n_left = makety( p->n_left, t, d, sue );
 10151015         p->n_right = makety( p->n_right, t, d, sue );
<>1016 -        if( o!=MINUS && !logop(o) ){
  1016+        if( o!=MINUS && !clogop(o) ){
10171017 
 10181018                 p->n_type = t;
 10191019                 p->n_df = d;
     
 !
10681068         else
 10691069                 t = INT;
 10701070 
<>1071 -        if( asgop(o) ){
  1071+        if( casgop(o) ){
10721072                 tu = p->n_left->n_type;
 10731073                 t = t1;
 10741074         } else {
     
 !
10851085 
 10861086         if( t != t2 || o==CAST) p->n_right = makety( p->n_right, tu, 0, MKSUE(tu));
 10871087 
<>1088 -        if( asgop(o) ){
  1088+        if( casgop(o) ){
10891089                 p->n_type = p->n_left->n_type;
 10901090                 p->n_df = p->n_left->n_df;
 10911091                 p->n_sue = p->n_left->n_sue;
 10921092                 }
<>1093 -        else if( !logop(o) ){
  1093+        else if( !clogop(o) ){
10941094                 p->n_type = tu;
 10951095                 p->n_df = NULL;
 10961096                 p->n_sue = MKSUE(t);
 10971097                 }
 10981098 
 10991099 #ifdef PCC_DEBUG
 11001100         if (tdebug)
<>1101 -                printf("tymatch(%p): %o %s %o => %o\n",p,t1,opst[o],t2,tu );
  1101+                printf("tymatch(%p): %o %s %o => %o\n",p,t1,copst(o),t2,tu );
11021102 #endif
 11031103 
 11041104         return(p);
     
 !
12131213 
 12141214         mt12 = 0;
 12151215 
<>1216 -        switch (optype(o = p->n_op)) {
  1216+        switch (coptype(o = p->n_op)) {
12171217         case BITYPE:
 12181218                 mt12=mt2 = moditype(p->n_right->n_type);
 12191219         case UTYPE:
     
 !
13561356                         return(TYPR+CVTL);
 13571357 
 13581358         }
<>1359 -        uerror("operands of %s have incompatible types", opst[o]);
  1359+        uerror("operands of %s have incompatible types", copst(o));
13601360         return(NCVT);
 13611361 }
 13621362 
     
 !
14241424                 }
 14251425         if( down ) printf( "    " );
 14261426 
<>1427 -        ty = optype( p->n_op );
  1427+        ty = coptype( p->n_op );
14281428 
<>1429 -        printf("%p) %s, ", p, opst[p->n_op] );
  1429+        printf("%p) %s, ", p, copst(p->n_op));
14301430         if (ty == LTYPE) {
 14311431                 printf(CONFMT, p->n_lval);
 14321432                 printf(", %d, ", p->n_rval);
     
 !
14571457 
 14581458 extern int negrel[];
 14591459 
<> 1460+/*
  1461+ * Write out logical expressions as branches.
  1462+ */
14601463 static void
 14611464 andorbr(NODE *p, int true, int false)
 14621465 {
<> 1466+        NODE *q;
14631467         int o, lab, flab, tlab;
 14641468 
 14651469         lab = -1;
     
 !
14751479         case GE:
 14761480         case GT:
 14771481                 if (true < 0) {
<>1478 -                        o = p->n_op = negrel[o - EQ];
  1482+                        p->n_op = negrel[o - EQ];
14791483                         true = false;
 14801484                         false = -1;
 14811485                 }
<> 1486+                /*
  1487+                 * Remove redundant logop nodes.
  1488+                 */
  1489+                while (clogop(o = p->n_left->n_op) &&
  1490+                    p->n_right->n_op == ICON && p->n_right->n_lval == 0) {
  1491+                        if (o == ANDAND || o == OROR || o == NOT)
  1492+                                break;
  1493+                        q = p->n_left;
  1494+                        nfree(p->n_right);
  1495+                        *p = *q;
  1496+                        nfree(q);
  1497+                        p->n_op = negrel[o - EQ];
  1498+                        
  1499+                }
  1500+
14821501                 rmcops(p);
<>1483 -                ecode(buildtree(CBRANCH, buildtree(NOT, p, NIL), bcon(true)));
  1502+                if (clogop(p->n_op))
  1503+                        p->n_op = negrel[p->n_op - EQ];
  1504+                else
  1505+                        p = buildtree(EQ, p, bcon(0));
  1506+                ecode(buildtree(CBRANCH, p, bcon(true)));
14841507                 if (false >= 0)
 14851508                         branch(false);
 14861509                 break;
     
 !
15101533 
 15111534         default:
 15121535                 rmcops(p);
<>1513 -                if (true >= 0)
 1514 -                        ecode(buildtree(CBRANCH, buildtree(NOT, p, NIL),
 1515 -                            bcon(true)));
  1536+                if (true >= 0) {
  1537+                        if (clogop(p->n_op))
  1538+                                p->n_op = negrel[p->n_op - EQ];
  1539+                        else
  1540+                                p = buildtree(EQ, p, bcon(0));
  1541+                        ecode(buildtree(CBRANCH, p, bcon(true)));
  1542+                }
15161543                 if (false >= 0) {
 15171544                         if (true >= 0)
 15181545                                 branch(false);
     
 !
15251552 int tvaloff;
 15261553 
 15271554 /*
<>1528 - * Turn COMOP and QUEST/COLON into normal statements.
  1555+ * Massage the output trees to remove C-specific nodes:
  1556+ *      COMOPs are split into separate statements.
  1557+ *      QUEST/COLON are rewritten to branches.
  1558+ *      ANDAND/OROR/NOT are rewritten to branches for lazy-evaluation.
  1559+ *      CBRANCH villkor are rewritten for lazy-evaluation.
15291560  */
 15301561 static void
 15311562 rmcops(NODE *p)
     
 !
15351566 
 15361567 again:
 15371568         o = p->n_op;
<>1538 -        ty = optype(o);
 1539 -        switch (ty) {
 1540 -        case LTYPE:
 1541 -                break;
 1542 -        case UTYPE:
 1543 -                rmcops(p->n_left);
 1544 -                break;
 1545 -        case BITYPE:
 1546 -                switch (o) {
 1547 -                case QUEST:
 1548 -                        tval = tvaloff++;
 1549 -                        /*
 1550 -                         * Create a CBRANCH node from ?:
 1551 -                         * || and && must be taken special care of.
 1552 -                         */
 1553 -                        andorbr(p->n_left, -1, lbl = getlab());
  1569+        ty = coptype(o);
  1570+        switch (o) {
  1571+        case QUEST:
15541572 
<>1555 -                        /* Make ASSIGN node */
 1556 -                        /* Only if type is not void */
 1557 -                        q = p->n_right->n_left;
 1558 -                        if (p->n_type != VOID) {
 1559 -                                r = block(TEMP, NIL, NIL,
 1560 -                                    q->n_type, q->n_df, q->n_sue);
 1561 -                                r->n_lval = tval;
 1562 -                                q = buildtree(ASSIGN, r, q);
 1563 -                        }
 1564 -                        rmcops(q);
 1565 -                        ecode(q); /* Done with assign */
  1573+                tval = tvaloff++;
  1574+                /*
  1575+                 * Create a CBRANCH node from ?:
  1576+                 * || and && must be taken special care of.
  1577+                 */
  1578+                andorbr(p->n_left, -1, lbl = getlab());
15661579 
<>1567 -                        branch(lbl2 = getlab());
 1568 -                        send_passt(IP_DEFLAB, lbl);
  1580+                /* Make ASSIGN node */
  1581+                /* Only if type is not void */
  1582+                q = p->n_right->n_left;
  1583+                if (p->n_type != VOID) {
  1584+                        r = block(TEMP, NIL, NIL,
  1585+                            q->n_type, q->n_df, q->n_sue);
  1586+                        r->n_lval = tval;
  1587+                        q = buildtree(ASSIGN, r, q);
  1588+                }
  1589+                rmcops(q);
  1590+                ecode(q); /* Done with assign */
  1591+                branch(lbl2 = getlab());
  1592+                send_passt(IP_DEFLAB, lbl);
15691593 
<>1570 -                        q = p->n_right->n_right;
 1571 -                        if (p->n_type != VOID) {
 1572 -                                r = block(TEMP, NIL, NIL,
 1573 -                                    q->n_type, q->n_df, q->n_sue);
 1574 -                                r->n_lval = tval;
 1575 -                                q = buildtree(ASSIGN, r, q);
 1576 -                        }
 1577 -                        rmcops(q);
 1578 -                        ecode(q); /* Done with assign */
  1594+                q = p->n_right->n_right;
  1595+                if (p->n_type != VOID) {
  1596+                        r = block(TEMP, NIL, NIL,
  1597+                            q->n_type, q->n_df, q->n_sue);
  1598+                        r->n_lval = tval;
  1599+                        q = buildtree(ASSIGN, r, q);
  1600+                }
  1601+                rmcops(q);
  1602+                ecode(q); /* Done with assign */
15791603 
<>1580 -                        send_passt(IP_DEFLAB, lbl2);
  1604+                send_passt(IP_DEFLAB, lbl2);
15811605 
<>1582 -                        nfree(p->n_right);
 1583 -                        p->n_op = p->n_type == VOID ? ICON : TEMP;
 1584 -                        p->n_lval = tval;
 1585 -                        break;
  1606+                nfree(p->n_right);
  1607+                p->n_op = p->n_type == VOID ? ICON : TEMP;
  1608+                p->n_lval = tval;
  1609+                break;
15861610 
<>1587 -                case ANDAND:
 1588 -                case OROR:
 1589 -                        rmcops(p->n_left);
 1590 -                case NOT:
  1611+        case ANDAND:
  1612+        case OROR:
  1613+                rmcops(p->n_left);
  1614+        case NOT:
15911615 #ifdef SPECIAL_CCODES
 15921616 #error fix for private CCODES handling
 15931617 #else
<>1594 -                        tval = tvaloff++;
 1595 -                        q = block(TEMP, NIL, NIL, p->n_type, p->n_df, p->n_sue);
 1596 -                        q->n_lval = tval;
 1597 -                        r = talloc();
 1598 -                        *r = *p;
 1599 -                        andorbr(r, -1, lbl = getlab());
 1600 -                        r = talloc();
 1601 -                        *r = *q;
 1602 -                        ecode(buildtree(ASSIGN, q, bcon(1)));
 1603 -                        branch(lbl2 = getlab());
 1604 -                        send_passt(IP_DEFLAB, lbl);
 1605 -                        ecode(buildtree(ASSIGN, r, bcon(0)));
 1606 -                        send_passt(IP_DEFLAB, lbl2);
 1607 -                        p->n_op = TEMP;
 1608 -                        p->n_lval = tval;
  1618+                tval = tvaloff++;
  1619+                q = block(TEMP, NIL, NIL, p->n_type, p->n_df, p->n_sue);
  1620+                q->n_lval = tval;
  1621+                r = talloc();
  1622+                *r = *p;
  1623+                andorbr(r, -1, lbl = getlab());
  1624+                r = talloc();
  1625+                *r = *q;
  1626+                ecode(buildtree(ASSIGN, q, bcon(1)));
  1627+                branch(lbl2 = getlab());
  1628+                send_passt(IP_DEFLAB, lbl);
  1629+                ecode(buildtree(ASSIGN, r, bcon(0)));
  1630+                send_passt(IP_DEFLAB, lbl2);
  1631+                p->n_op = TEMP;
  1632+                p->n_lval = tval;
16091633 #endif
<>1610 -                        break;
 1611 -                case CBRANCH:
 1612 -                        andorbr(p->n_left, -1, p->n_right->n_lval);
 1613 -                        nfree(p->n_right);
 1614 -                        p->n_op = ICON; p->n_type = VOID;
 1615 -                        break;
 1616 -                case COMOP:
 1617 -                        rmcops(p->n_left);
 1618 -                        ecode(p->n_left);
 1619 -                        /* Now when left tree is dealt with, rm COMOP */
 1620 -                        q = p->n_right;
 1621 -                        *p = *p->n_right;
 1622 -                        nfree(q);
 1623 -                        goto again;
  1634+                break;
  1635+        case CBRANCH:
  1636+                andorbr(p->n_left, -1, p->n_right->n_lval);
  1637+                nfree(p->n_right);
  1638+                p->n_op = ICON; p->n_type = VOID;
  1639+                break;
  1640+        case COMOP:
  1641+                rmcops(p->n_left);
  1642+                ecode(p->n_left);
  1643+                /* Now when left tree is dealt with, rm COMOP */
  1644+                q = p->n_right;
  1645+                *p = *p->n_right;
  1646+                nfree(q);
  1647+                goto again;
16241648 
<>1625 -                default:
 1626 -                        rmcops(p->n_left);
  1649+        default:
  1650+                if (ty == LTYPE)
  1651+                        return;
  1652+                rmcops(p->n_left);
  1653+                if (ty == BITYPE)
16271654                         rmcops(p->n_right);
<>1628 -                }
 1629 -        }
  1655+       }
16301656 }
 16311657 
 16321658 
     
 !
16651691         MYP2TREE(p);  /* local action can be taken here; then return... */
 16661692 # endif
 16671693 
<>1668 -        ty = optype(p->n_op);
  1694+        ty = coptype(p->n_op);
16691695 
 16701696         printf("%d\t", p->n_op);
 16711697 
     
 !
17331759         MYP2TREE(p);  /* local action can be taken here; then return... */
 17341760 # endif
 17351761 
<>1736 -        ty = optype(p->n_op);
  1762+        ty = coptype(p->n_op);
17371763 
 17381764         switch( p->n_op ){
 17391765 
     
 !
18381864         else
 18391865                 pass2_compile(ip);
 18401866 }
<_ 1867+
  1868+char *
  1869+copst(int op)
  1870+{
  1871+        if (op <= MAXOP)
  1872+                return opst[op];
  1873+#define SNAM(x,y) case x: return #y;
  1874+        switch (op) {
  1875+        SNAM(QUALIFIER,QUALIFIER)
  1876+        SNAM(CLASS,CLASS)
  1877+        SNAM(RB,])
  1878+        SNAM(DOT,.)
  1879+        SNAM(ELLIPSIS,...)
  1880+        SNAM(LB,[)
  1881+        SNAM(TYPE,TYPE)
  1882+        SNAM(COMOP,COMOP)
  1883+        SNAM(QUEST,?)
  1884+        SNAM(COLON,:)
  1885+        SNAM(ANDAND,&&)
  1886+        SNAM(OROR,||)
  1887+        SNAM(NOT,!)
  1888+        default:
  1889+                cerror("bad copst %d", op);
  1890+        }
  1891+}
  1892+
  1893+int
  1894+cdope(int op)
  1895+{
  1896+        if (op <= MAXOP)
  1897+                return dope[op];
  1898+        switch (op) {
  1899+        case QUALIFIER:
  1900+        case CLASS:
  1901+        case RB:
  1902+        case DOT:
  1903+        case ELLIPSIS:
  1904+        case TYPE:
  1905+                return LTYPE;
  1906+        case COMOP:
  1907+        case QUEST:
  1908+        case COLON:
  1909+        case LB:
  1910+                return BITYPE;
  1911+        case ANDAND:
  1912+        case OROR:
  1913+                return BITYPE|LOGFLG;
  1914+        case NOT:
  1915+                return UTYPE|LOGFLG;
  1916+        }
  1917+}
FishEye: Open Source License registered to PCC.
Atlassian FishEye, CVS analysis. (Version:1.6.3 Build:build-336 2008-11-04) - Administration - Page generated 2014-12-20 19:39 +0100