Quick Search:

Mode

Context

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

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.283
 
1.284
 
MAIN:ragge:20110601173903
 
trees.c
_>706706 }
 707707 
 708708 /*
<> 709+ * Do an actual cast of a constant (if possible).
  710+ * Routine assumes 2-complement (is there anything else today?)
  711+ * Returns 1 if handled, 0 otherwise.
  712+ */
  713+int
  714+concast(NODE *p, TWORD t)
  715+{
  716+        extern short sztable[];
  717+        CONSZ val;
  718+
  719+        if (p->n_op != ICON && p->n_op != FCON) /* only constants */
  720+                return 0;
  721+        if (p->n_op == ICON && p->n_sp != NULL) { /* no addresses */
  722+                if (t == BOOL) {
  723+                        p->n_lval = 1, p->n_type = BOOL, p->n_sp = NULL;
  724+                        return 1;
  725+                }
  726+                return 0;
  727+        }
  728+        if ((p->n_type & TMASK) || (t & TMASK)) /* no cast of pointers */
  729+                return 0;
  730+
  731+//printf("concast till %d\n", t);
  732+//fwalk(p, eprint, 0);
  733+
  734+#define TYPMSK(y) ((((1LL << (y-1))-1) << 1) | 1)
  735+        if (p->n_op == ICON) {
  736+                val = p->n_lval;
  737+
  738+                if (t == BOOL) {
  739+                        if (val)
  740+                                p->n_lval = 1;
  741+                } else if (t <= ULONGLONG) {
  742+                        p->n_lval = val & TYPMSK(sztable[t]);
  743+                        if (!ISUNSIGNED(t)) {
  744+                                if (val & (1LL << (sztable[t]-1)))
  745+                                        p->n_lval |= ~TYPMSK(sztable[t]);
  746+                        }
  747+                } else if (t <= LDOUBLE) {
  748+                        p->n_op = FCON;
  749+                        p->n_dcon = FLOAT_CAST(val, p->n_type);
  750+                }
  751+        } else { /* p->n_op == FCON */
  752+                if (t == BOOL) {
  753+                        p->n_op = ICON;
  754+                        p->n_lval = FLOAT_NE(p->n_dcon,0.0);
  755+                        p->n_sp = NULL;
  756+                } else if (t <= ULONGLONG) {
  757+                        p->n_op = ICON;
  758+                        p->n_lval = ISUNSIGNED(t) ? /* XXX FIXME */
  759+                            ((U_CONSZ)p->n_dcon) : p->n_dcon;
  760+                        p->n_sp = NULL;
  761+                } else {
  762+                        p->n_dcon = t == FLOAT ? (float)p->n_dcon :
  763+                            t == DOUBLE ? (double)p->n_dcon : p->n_dcon;
  764+                }
  765+        }
  766+        p->n_type = t;
  767+//fwalk(p, eprint, 0);
  768+        return 1;
  769+}
  770+
  771+/*
709772  * Do a conditional branch.
 710773  */
 711774 void
     
 !
12401303          * XXX - complain?
 12411304          */
 12421305         if (r->n_type != INTPTR)
<>1243 -                r = clocal(block(SCONV, r, NIL, INTPTR, 0, 0));
  1306+                r = clocal(makety(r, INTPTR, 0, 0, 0));
12441307         if (f == CVTL)
 12451308                 p->n_left = r;
 12461309         else
     
 !
15391602                 return(p);
 15401603         }
 15411604 
<>1542 -        if (p->n_op == FCON && (t >= FLOAT && t <= LDOUBLE)) {
 1543 -                if (t == FLOAT)
 1544 -                        p->n_dcon = (float)p->n_dcon;
 1545 -                else if (t == DOUBLE)
 1546 -                        p->n_dcon = (double)p->n_dcon;
 1547 -                else
 1548 -                        p->n_dcon = (long double)p->n_dcon;
 1549 -                p->n_type = t;
 1550 -                return p;
 1551 -        }
  1605+        if (ISITY(t) || ISCTY(t) || ISITY(p->n_type) || ISCTY(p->n_type))
  1606+                cerror("makety");
15521607 
<>1553 -        if (p->n_op == FCON) {
 1554 -                int isf = ISFTY(t);
 1555 -                NODE *r;
 1556 -
 1557 -                if (isf||ISITY(t)) {
 1558 -                        if (isf == ISFTY(p->n_type)) {
 1559 -                                p->n_type = t;
 1560 -                                p->n_qual = q;
 1561 -                                p->n_df = d;
 1562 -                                p->n_ap = ap;
 1563 -                                return(p);
 1564 -                        } else if (isf == ISITY(p->n_type)) {
 1565 -                                /* will be zero */
 1566 -                                nfree(p);
 1567 -                                return fzero(t);
 1568 -                        } else if (ISCTY(p->n_type))
 1569 -                                cerror("complex constant");
 1570 -                } else if (ISCTY(t)) {
 1571 -                        if (ISITY(p->n_type)) {
 1572 -                                /* convert to correct subtype */
 1573 -                                r = fzero(t - (COMPLEX-DOUBLE));
 1574 -                                p->n_type = t + (IMAG-COMPLEX);
 1575 -                                p->n_qual = q;
 1576 -                                p->n_df = d;
 1577 -                                p->n_ap = NULL;
 1578 -                                return block(CM, r, p, t, 0, 0);
 1579 -                        } else if (ISFTY(p->n_type)) {
 1580 -                                /* convert to correct subtype */
 1581 -                                r = fzero(t + (IMAG-COMPLEX));
 1582 -                                p->n_type = t - (COMPLEX-DOUBLE);
 1583 -                                p->n_qual = q;
 1584 -                                p->n_df = d;
 1585 -                                p->n_ap = NULL;
 1586 -                                return block(CM, p, r, t, 0, 0);
 1587 -                        } else if (ISCTY(p->n_type))
 1588 -                                cerror("complex constant2");
 1589 -                }
 1590 -        }
 1591 -
 1592 -        if (t & TMASK) {
 1593 -                /* non-simple type */
 1594 -                p = block(PCONV, p, NIL, t, d, ap);
 1595 -                p->n_qual = q;
  1608+        if (concast(p, t))
15961609                 return clocal(p);
<>1597 -        }
15981610 
<>1599 -        if (p->n_op == ICON) {
 1600 -                if (ISFTY(t)) {
 1601 -                        p->n_op = FCON;
 1602 -                        p->n_dcon = FLOAT_CAST(p->n_lval, p->n_type);
 1603 -                        p->n_type = t;
 1604 -                        p->n_qual = q;
 1605 -                        p->n_ap = NULL;
 1606 -                        return (clocal(p));
 1607 -                } else if (ISCTY(t) || ISITY(t))
 1608 -                        cerror("complex constant3");
 1609 -        }
 1610 -
 1611 -        p = block(SCONV, p, NIL, t, d, ap);
  1611+        p = block(t & TMASK ? PCONV : SCONV, p, NIL, t, d, ap);
<_16121612         p->n_qual = q;
 16131613         return clocal(p);
 16141614 
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-09-17 03:34 +0200