Quick Search:

Mode

Context

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

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.292
 
1.293
 
MAIN:ragge:20100904192233
 
pftn.c
_>118118 void fixtype(NODE *p, int class);
 119119 int fixclass(int class, TWORD type);
 120120 static void dynalloc(struct symtab *p, int *poff);
<> 121+static void evalidx(struct symtab *p);
  122+int isdyn(struct symtab *p);
121123 void inforce(OFFSZ n);
 122124 void vfdalign(int n);
 123125 static void ssave(struct symtab *);
     
 !
150152         if (q == NIL)
 151153                 return/* an error was detected */
 152154 
<>153 -#ifdef GCC_COMPAT
 154 -        if (q->n_op == CM)
 155 -                cerror("defid0");
 156 -#endif
157155         p = q->n_sp;
 158156 
 159157         if (p->sname == NULL)
     
 !
384382         if (ISFTN(type) && oldstyle)
 385383                 p->sdf->dfun = NULL;
 386384 
<> 385+        if (arrstkp)
  386+                evalidx(p);
  387+
387388         /* allocate offsets */
 388389         if (class&FIELD) {
 389390                 (void) falloc(p, class&FLDSIZ, NIL);  /* new entry */
     
 !
393394                 cerror("register var");
 394395 
 395396         case AUTO:
<>396 -                if (arrstkp)
  397+                if (isdyn(p)) {
  398+                        p->sflags |= SDYNARRAY;
397399                         dynalloc(p, &autooff);
<>398 -                else
  400+                } else
399401                         oalloc(p, &autooff);
 400402                 break;
<> 403+
401404         case PARAM:
<>402 -                if (arrstkp) {
 403 -                        dynalloc(p, &argoff);
 404 -                } else {
 405 -                        if (ISARY(p->stype)) {
 406 -                        /* remove array type on parameters before oalloc */
 407 -                                p->stype += (PTR-ARY);
 408 -                                p->sdf++;
 409 -                        }
 410 -                        oalloc(p, &argoff);
 411 -                }
  405+                oalloc(p, &argoff);
412406                 break;
 413407                 
 414408         case STATIC:
     
 !
13161310 }
 13171311 
 13181312 /*
<> 1313+ * Traverse through the array args, evaluate them and put the
  1314+ * resulting temp numbers in the dim fields.
  1315+ */
  1316+static void
  1317+evalidx(struct symtab *sp)
  1318+{
  1319+        union dimfun *df;
  1320+        NODE *p;
  1321+        TWORD t;
  1322+        int astkp = 0;
  1323+
  1324+        if (arrstk[0] == NIL)
  1325+                astkp++; /* for parameter arrays */
  1326+
  1327+        if (isdyn(sp))
  1328+                sp->sflags |= SDYNARRAY;
  1329+
  1330+        df = sp->sdf;
  1331+        for (t = sp->stype; t > BTMASK; t = DECREF(t)) {
  1332+                if (!ISARY(t))
  1333+                        continue;
  1334+                if (df->ddim == -1) {
  1335+                        p = tempnode(0, INT, 0, MKAP(INT));
  1336+                        df->ddim = -regno(p);
  1337+                        edelay(buildtree(ASSIGN, p, arrstk[astkp++]));
  1338+                }
  1339+                df++;
  1340+        }
  1341+        arrstkp = 0;
  1342+}
  1343+
  1344+/*
  1345+ * Return 1 if dynamic array, 0 otherwise.
  1346+ */
  1347+int
  1348+isdyn(struct symtab *sp)
  1349+{
  1350+        union dimfun *df = sp->sdf;
  1351+        TWORD t;
  1352+
  1353+        for (t = sp->stype; t > BTMASK; t = DECREF(t)) {
  1354+                if (!ISARY(t))
  1355+                        return 0;
  1356+                if (df->ddim < 0 && df->ddim != NOOFFSET)
  1357+                        return 1;
  1358+                df++;
  1359+        }
  1360+        return 0;
  1361+}
  1362+
  1363+/*
13191364  * Allocate space on the stack for dynamic arrays (or at least keep track
 13201365  * of the index).
 13211366  * Strategy is as follows:
     
 !
13301375 dynalloc(struct symtab *p, int *poff)
 13311376 {
 13321377         union dimfun *df;
<>1333 -        NODE *n, *nn, *tn, *pol;
  1378+        NODE *n, *tn, *pol;
13341379         TWORD t;
<>1335 -        int astkp, no;
13361380 
 13371381         /*
 13381382          * The pointer to the array is not necessarily stored in a
 13391383          * TEMP node, but if it is, its number is in the soffset field;
 13401384          */
 13411385         t = p->stype;
<>1342 -        astkp = 0;
 1343 -        if (ISARY(t) && blevel == 1) {
 1344 -                /* must take care of side effects of dynamic arg arrays */
 1345 -                if (p->sdf->ddim < 0 && p->sdf->ddim != NOOFFSET) {
 1346 -                        /* first-level array will be indexed correct */
 1347 -                        edelay(arrstk[astkp++]);
 1348 -                }
 1349 -                p->sdf++;
 1350 -                p->stype += (PTR-ARY);
 1351 -                t = p->stype;
 1352 -        }
 1353 -        if (ISARY(t)) {
 1354 -                p->sflags |= (STNODE|SDYNARRAY);
 1355 -                p->stype = INCREF(p->stype); /* Make this an indirect pointer */
 1356 -                tn = tempnode(0, p->stype, p->sdf, p->sap);
 1357 -                p->soffset = regno(tn);
 1358 -        } else {
 1359 -                oalloc(p, poff);
 1360 -                tn = NIL;
 1361 -        }
  1386+        p->sflags |= STNODE;
  1387+        p->stype = INCREF(p->stype); /* Make this an indirect pointer */
  1388+        tn = tempnode(0, p->stype, p->sdf, p->sap);
  1389+        p->soffset = regno(tn);
13621390 
 13631391         df = p->sdf;
 13641392 
<>1365 -        pol = NIL;
  1393+        pol = bcon(1);
13661394         for (; t > BTMASK; t = DECREF(t)) {
 13671395                 if (!ISARY(t))
<>1368 -                        continue;
 1369 -                if (df->ddim < 0) {
 1370 -                        n = arrstk[astkp++];
 1371 -                        do {
 1372 -                                nn = tempnode(0, INT, 0, MKAP(INT));
 1373 -                                no = regno(nn);
 1374 -                        } while (no == -NOOFFSET);
 1375 -                        edelay(buildtree(ASSIGN, nn, n));
 1376 -
 1377 -                        df->ddim = -no;
 1378 -                        n = tempnode(no, INT, 0, MKAP(INT));
 1379 -                } else
  1396+                        break;
  1397+                if (df->ddim < 0)
  1398+                        n = tempnode(-df->ddim, INT, 0, MKAP(INT));
  1399+                else
13801400                         n = bcon(df->ddim);
 13811401 
<>1382 -                pol = (pol == NIL ? n : buildtree(MUL, pol, n));
  1402+                pol = buildtree(MUL, pol, n);
13831403                 df++;
 13841404         }
 13851405         /* Create stack gap */
<>1386 -        if (blevel == 1) {
 1387 -                if (tn)
 1388 -                        tfree(tn);
 1389 -                if (pol)
 1390 -                        tfree(pol);
 1391 -        } else {
 1392 -                if (pol == NIL)
 1393 -                        uerror("aggregate dynamic array not allowed");
 1394 -                if (tn)
 1395 -                        spalloc(tn, pol, tsize(t, 0, p->sap));
 1396 -                else
 1397 -                        tfree(pol);
 1398 -        }
 1399 -        arrstkp = 0;
  1406+        spalloc(tn, pol, tsize(t, 0, p->sap));
<_14001407 }
 14011408 
 14021409 /*
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 10:12 +0100