Quick Search:

Mode

Context

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

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.242
 
1.243
 
MAIN:ragge:20090107205202
 
pftn.c
_>608608         symclear(1);    /* In case of function pointer args */
 609609 }
 610610 
<> 611+#ifdef notyet
611612 /*
<> 613+ * Copy sue to either perm or tmp memory, depending on blevel.
  614+ */
  615+static struct suedef *
  616+suecopy(struct suedef *sue)
  617+{
  618+        struct suedef *r;
  619+
  620+        r = blevel ? tmpalloc(sizeof(struct suedef)) :
  621+            permalloc(sizeof(struct suedef));
  622+        *r = *sue;
  623+        return r;
  624+}
  625+#endif
  626+
  627+/*
612628  * Struct/union/enum symtab construction.
 613629  */
 614630 static void
     
 !
15381554  * TYPE is CHAR, SHORT, INT, LONG, SIGNED, UNSIGNED, VOID, BOOL, FLOAT,
 15391555  *      DOUBLE, STRTY, UNIONTY.
 15401556  */
<>1541 -NODE *
 1542 -typenode(NODE *p)
 1543 -{
 1544 -        NODE *q, *saved;
  1557+struct typctx {
  1558+        int class, qual, sig, uns, cmplx, err;
15451559         TWORD type;
<>1546 -        int class, qual;
 1547 -        int sig, uns, cmplx;
  1560+        NODE *saved;
  1561+};
15481562 
<>1549 -        cmplx = type = class = qual = sig = uns = 0;
 1550 -        saved = NIL;
  1563+static void
  1564+typwalk(NODE *p, void *arg)
  1565+{
  1566+        struct typctx *tc = arg;
15511567 
<>1552 -        for (q = p; p; p = p->n_left) {
 1553 -                switch (p->n_op) {
 1554 -                case CLASS:
 1555 -                        if (class)
 1556 -                                goto bad; /* max 1 class */
 1557 -                        class = p->n_type;
 1558 -                        break;
  1568+        switch (p->n_op) {
  1569+        case CLASS:
  1570+                if (tc->class)
  1571+                        tc->err = 1; /* max 1 class */
  1572+                tc->class = p->n_type;
  1573+                break;
15591574 
<>1560 -                case QUALIFIER:
 1561 -                        qual |= p->n_type >> TSHIFT;
  1575+        case QUALIFIER:
  1576+                tc->qual |= p->n_type >> TSHIFT;
  1577+                break;
  1578+
  1579+        case TYPE:
  1580+                if (p->n_sp != NULL || ISSOU(p->n_type)) {
  1581+                        /* typedef, enum or struct/union */
  1582+                        if (tc->saved || tc->type)
  1583+                                tc->err = 1;
  1584+                        tc->saved = tcopy(p);
15621585                         break;
<> 1586+                }
15631587 
<>1564 -                case TYPE:
 1565 -                        if (p->n_sp != NULL || ISSOU(p->n_type)) {
 1566 -                                /* typedef, enum or struct/union */
 1567 -                                if (saved || type)
 1568 -                                        goto bad;
 1569 -                                saved = p;
  1588+                switch (p->n_type) {
  1589+                case BOOL:
  1590+                case CHAR:
  1591+                case FLOAT:
  1592+                case VOID:
  1593+                        if (tc->type)
  1594+                                tc->err = 1;
  1595+                        tc->type = p->n_type;
  1596+                        break;
  1597+                case DOUBLE:
  1598+                        if (tc->type == 0)
  1599+                                tc->type = DOUBLE;
  1600+                        else if (tc->type == LONG)
  1601+                                tc->type = LDOUBLE;
  1602+                        else
  1603+                                tc->err = 1;
  1604+                        break;
  1605+                case SHORT:
  1606+                        if (tc->type == 0 || tc->type == INT)
  1607+                                tc->type = SHORT;
  1608+                        else
  1609+                                tc->err = 1;
  1610+                        break;
  1611+                case INT:
  1612+                        if (tc->type == SHORT || tc->type == LONG ||
  1613+                            tc->type == LONGLONG)
15701614                                 break;
<>1571 -                        } else if ((p->n_type == SIGNED && uns) ||
 1572 -                            (p->n_type == UNSIGNED && sig))
 1573 -                                goto bad;
 1574 -
 1575 -                        switch (p->n_type) {
 1576 -                        case BOOL:
 1577 -                        case CHAR:
 1578 -                        case FLOAT:
 1579 -                        case VOID:
 1580 -                                if (type)
 1581 -                                        goto bad;
 1582 -                                type = p->n_type;
  1615+                        else if (tc->type == 0)
  1616+                                tc->type = INT;
  1617+                        else
  1618+                                tc->err = 1;
  1619+                        break;
  1620+                case LONG:
  1621+                        if (tc->type == 0)
  1622+                                tc->type = LONG;
  1623+                        else if (tc->type == INT)
15831624                                 break;
<>1584 -                        case DOUBLE:
 1585 -                                if (type == 0)
 1586 -                                        type = DOUBLE;
 1587 -                                else if (type == LONG)
 1588 -                                        type = LDOUBLE;
 1589 -                                else
 1590 -                                        goto bad;
 1591 -                                break;
 1592 -                        case SHORT:
 1593 -                                if (type == 0 || type == INT)
 1594 -                                        type = SHORT;
 1595 -                                else
 1596 -                                        goto bad;
 1597 -                                break;
 1598 -                        case INT:
 1599 -                                if (type == SHORT || type == LONG ||
 1600 -                                    type == LONGLONG)
 1601 -                                        break;
 1602 -                                else if (type == 0)
 1603 -                                        type = INT;
 1604 -                                else
 1605 -                                        goto bad;
 1606 -                                break;
 1607 -                        case LONG:
 1608 -                                if (type == 0)
 1609 -                                        type = LONG;
 1610 -                                else if (type == INT)
 1611 -                                        break;
 1612 -                                else if (type == LONG)
 1613 -                                        type = LONGLONG;
 1614 -                                else if (type == DOUBLE)
 1615 -                                        type = LDOUBLE;
 1616 -                                else
 1617 -                                        goto bad;
 1618 -                                break;
 1619 -                        case SIGNED:
 1620 -                                if (sig || uns)
 1621 -                                        goto bad;
 1622 -                                sig = 1;
 1623 -                                break;
 1624 -                        case UNSIGNED:
 1625 -                                if (sig || uns)
 1626 -                                        goto bad;
 1627 -                                uns = 1;
 1628 -                                break;
 1629 -                        case COMPLEX:
 1630 -                                cmplx = 1;
 1631 -                                break;
 1632 -                        default:
 1633 -                                cerror("typenode");
 1634 -                        }
  1625+                        else if (tc->type == LONG)
  1626+                                tc->type = LONGLONG;
  1627+                        else if (tc->type == DOUBLE)
  1628+                                tc->type = LDOUBLE;
  1629+                        else
  1630+                                tc->err = 1;
  1631+                        break;
  1632+                case SIGNED:
  1633+                        if (tc->sig || tc->uns)
  1634+                                tc->err = 1;
  1635+                        tc->sig = 1;
  1636+                        break;
  1637+                case UNSIGNED:
  1638+                        if (tc->sig || tc->uns)
  1639+                                tc->err = 1;
  1640+                        tc->uns = 1;
  1641+                        break;
  1642+                case COMPLEX:
  1643+                        tc->cmplx = 1;
  1644+                        break;
  1645+                default:
  1646+                        cerror("typenode");
16351647                 }
 16361648         }
<>1637 -        if (cmplx) {
 1638 -                if (sig || uns)
  1649+
  1650+}
  1651+
  1652+NODE *
  1653+typenode(NODE *p)
  1654+{
  1655+        struct typctx tc;
  1656+        NODE *q;
  1657+
  1658+        memset(&tc, 0, sizeof(struct typctx));
  1659+
  1660+        flist(p, typwalk, &tc);
  1661+        tfree(p);
  1662+
  1663+        if (tc.err)
  1664+                goto bad;
  1665+
  1666+        if (tc.cmplx) {
  1667+                if (tc.sig || tc.uns)
16391668                         goto bad;
<>1640 -                switch (type) {
  1669+                switch (tc.type) {
16411670                 case FLOAT:
<>1642 -                        type = FCOMPLEX;
  1671+                        tc.type = FCOMPLEX;
16431672                         break;
 16441673                 case DOUBLE:
<>1645 -                        type = COMPLEX;
  1674+                        tc.type = COMPLEX;
16461675                         break;
 16471676                 case LDOUBLE:
<>1648 -                        type = LCOMPLEX;
  1677+                        tc.type = LCOMPLEX;
16491678                         break;
 16501679                 default:
 16511680                         goto bad;
 16521681                 }
 16531682         }
 16541683 
<>1655 -        if (saved && type)
  1684+        if (tc.saved && tc.type)
16561685                 goto bad;
<>1657 -        if (sig || uns) {
 1658 -                if (type == 0)
 1659 -                        type = sig ? INT : UNSIGNED;
 1660 -                if (type > ULONGLONG)
  1686+        if (tc.sig || tc.uns) {
  1687+                if (tc.type == 0)
  1688+                        tc.type = tc.sig ? INT : UNSIGNED;
  1689+                if (tc.type > ULONGLONG)
16611690                         goto bad;
<>1662 -                if (uns)
 1663 -                        type = ENUNSIGN(type);
  1691+                if (tc.uns)
  1692+                        tc.type = ENUNSIGN(tc.type);
16641693         }
 16651694 
<>1666 -        if (funsigned_char && type == CHAR && sig == 0)
 1667 -                type = UCHAR;
  1695+        if (funsigned_char && tc.type == CHAR && tc.sig == 0)
  1696+                tc.type = UCHAR;
16681697 
<>1669 -        /* free the chain */
 1670 -        while (q) {
 1671 -                p = q->n_left;
 1672 -                if (q != saved)
 1673 -                        nfree(q);
 1674 -                q = p;
 1675 -        }
  1698+        q = (tc.saved ? tc.saved : mkty(tc.type, 0, 0));
  1699+        q->n_qual = tc.qual;
  1700+        q->n_lval = tc.class;
  1701+        if (BTYPE(q->n_type) == UNDEF)
  1702+                MODTYPE(q->n_type, INT);
  1703+        return q;
16761704 
<>1677 -        p = (saved ? saved : block(TYPE, NIL, NIL, type, 0, 0));
 1678 -        p->n_qual = qual;
 1679 -        p->n_lval = class;
 1680 -        if (BTYPE(p->n_type) == UNDEF)
 1681 -                MODTYPE(p->n_type, INT);
 1682 -        return p;
 1683 -
<_16841705 bad:    uerror("illegal type combination");
 16851706         return mkty(INT, 0, 0);
 16861707 }
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-22 23:46 +0100