Quick Search:

Mode

Context

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

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.29
 
1.30
 
MAIN:ragge:20030528120058
 
pftn.c
_>2626 
 2727 /* defines used for getting things off of the initialization stack */
 2828 
<> 29+static NODE *arrstk[10];
  30+static int arrstkp;
2931 
 3032 struct symtab *relook(struct symtab *);
 3133 struct symtab * mknonuniq(int *);
     
 !
3436 int falloc(struct symtab *p, int w, int new, NODE *pty);
 3537 void psave(int);
 3638 int oalloc(struct symtab *p, int *poff);
<> 39+static void dynalloc(struct symtab *p, int *poff);
3740 int hide(struct symtab *p);
 3841 void inforce(OFFSZ n);
 3942 void vfdalign(int n);
     
 !
322325         else switch( class ){
 323326 
 324327         case AUTO:
<>325 -                (void) oalloc( p, &autooff );
  328+                if (arrstkp)
  329+                        dynalloc(p, &autooff);
  330+                else
  331+                        (void) oalloc( p, &autooff );
326332                 break;
 327333         case STATIC:
 328334         case EXTDEF:
     
 !
14551461 }
 14561462 
 14571463 /*
<> 1464+ * Allocate space on the stack for dynamic arrays.
  1465+ * Strategy is as follows:
  1466+ * - first entry is a pointer to the dynamic datatype.
  1467+ * - if it's a one-dimensional array this will be the only entry used.
  1468+ * - if it's a multi-dimensional array the following (numdim-1) integers
  1469+ *   will contain the sizes to multiply the indexes with.
  1470+ * - code to write the dimension sizes this will be generated here.
  1471+ * - code to allocate space on the stack will be generated here.
  1472+ */
  1473+static void
  1474+dynalloc(struct symtab *p, int *poff)
  1475+{
  1476+//      struct symtab *q;
  1477+        NODE *n, *nn;
  1478+        OFFSZ ptroff, argoff;
  1479+        TWORD t;
  1480+//      int al, off, tsz;
  1481+        int i;
  1482+
  1483+        bccode(); /* Init code generation */
  1484+        /*
  1485+         * Setup space on the stack, one pointer to the array space
  1486+         * and n-1 integers for the array sizes.
  1487+         */
  1488+        ptroff = upoff(tsize(PTR, 0, 0), talign(PTR, 0), poff);
  1489+        if (arrstkp > 1) {
  1490+                dimtab[curdim] = arrstkp-1;
  1491+                dimtab[curdim+1] = INT;
  1492+                argoff = upoff(tsize(ARY+INT, dimtab[curdim], dimtab[curdim+1]),                    talign(ARY+INT, 0), poff);
  1493+        }
  1494+
  1495+        /*
  1496+         * Set the initial pointer the same as the stack pointer.
  1497+         * Assume that the stack pointer is correctly aligned already.
  1498+         */
  1499+        p->offset = ptroff;
  1500+        p->stype = INCREF(p->stype);
  1501+        idname = p - stab;
  1502+        nn = buildtree(NAME, NIL, NIL);
  1503+
  1504+        /*
  1505+         * Calculate the size of the array to be allocated on stack.
  1506+         * Save the sizes on the stack while doing this.
  1507+         */
  1508+        n = arrstk[0];
  1509+        i = 0;
  1510+
  1511+        if (arrstkp != 1)
  1512+                cerror("dynalloc: no multidim arrays");
  1513+#if 0
  1514+        while (++i < arrstkp) {
  1515+                
  1516+                sp = clocal(block(PLUS, stknode(INCREF(STRTY), 0, 0),
  1517+                    offcon(argoff + (i-1) * ALINT, INT, 0, INT), INT, 0, INT);
  1518+                sp = buildtree(UNARY MUL, sp, NIL);
  1519+
  1520+                n = buildtree(ASSIGN, sp, arrstk[i]);
  1521+        }
  1522+
  1523+        sp = block(PCONV, stknode(INCREF(STRTY), 0, 0), NIL,
  1524+            INCREF(BTYPE(p->stype)), p->dimoff, p->sizoff);
  1525+        n = buildtree(PLUS, sp, n);
  1526+
  1527+#endif
  1528+
  1529+        /* get the underlying size without ARYs */
  1530+        t = p->stype;
  1531+        while (ISARY(t))
  1532+                t = DECREF(t);
  1533+
  1534+        /* Write it onto the stack */
  1535+        spalloc(nn, n, tsize(t, 0, p->sizoff));
  1536+        p->sflags |= SDYNARRAY;
  1537+        arrstkp = 0;
  1538+}
  1539+
  1540+/*
14581541  * allocate a field of width w
 14591542  * new is 0 if new entry, 1 if redefinition, -1 if alignment
 14601543  */
     
 !
17511834         }
 17521835 
 17531836 /*
<>1754 - * build a type, and stash away dimensions, from a parse tree of the declaration
  1837+ * build a type, and stash away dimensions,
  1838+ * from a parse tree of the declaration
17551839  * the type is build top down, the dimensions bottom up
 17561840  */
 17571841 void
 17581842 tyreduce(NODE *p)
 17591843 {
<> 1844+        NODE *q;
17601845         int o, temp;
 17611846         unsigned int t;
 17621847 
 17631848         o = p->in.op;
 17641849         p->in.op = FREE;
 17651850 
<>1766 -        if( o == NAME ) return;
  1851+        if (o == NAME)
  1852+                return;
17671853 
<>1768 -        t = INCREF( p->in.type );
 1769 -        if( o == UNARY CALL ) t += (FTN-PTR);
 1770 -        else if( o == LB ){
  1854+        t = INCREF(p->in.type);
  1855+        switch (o) {
  1856+        case UNARY CALL:
  1857+                t += (FTN-PTR);
  1858+                break;
  1859+        case LB:
17711860                 t += (ARY-PTR);
<>1772 -                temp = p->in.right->tn.lval;
 1773 -                p->in.right->in.op = FREE;
 1774 -                if( temp == 0 && p->in.left->tn.op == LB )
 1775 -                        uerror( "null dimension" );
  1861+                if (p->in.right->in.op != ICON) {
  1862+                        q = p->in.right;
  1863+                        o = RB; /* cannot happen */
  1864+                } else {
  1865+                        temp = p->in.right->tn.lval;
  1866+                        p->in.right->in.op = FREE;
  1867+                        if (temp == 0 && p->in.left->tn.op == LB)
  1868+                                uerror("null dimension");
17761869                 }
<> 1870+                break;
  1871+        }
17771872 
 17781873         p->in.left->in.type = t;
<>1779 -        tyreduce( p->in.left );
  1874+        tyreduce(p->in.left);
17801875 
<>1781 -        if( o == LB ) dstash( temp );
  1876+        if (o == LB)
  1877+                dstash(temp);
  1878+        if (o == RB) {
  1879+                dstash(-1);
  1880+                arrstk[arrstkp++] = q;
  1881+        }
17821882 
 17831883         p->tn.rval = p->in.left->tn.rval;
 17841884         p->in.type = p->in.left->in.type;
<> 1885+}
17851886 
<>1786 -        }
 1787 -
17881887 void
 17891888 fixtype(NODE *p, int class)
 17901889 {
     
 !
22202319         *q = *p;
 22212320         p->sflags |= SHIDDEN;
 22222321         q->sflags = (p->sflags&(SMOS|STAG)) | SHIDES;
<> 2322+#if 0
22232323         if (p->slevel > 0)
 22242324                 werror("%s redefinition hides earlier one", p->sname);
<> 2325+#endif
<_22252326 # ifndef BUG1
 22262327         if( ddebug ) printf( "  %d hidden in %d\n", p-stab, q-stab );
 22272328 # endif
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-10-31 16:04 +0100