Quick Search:

Mode

Context

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

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.49
 
1.50
 
MAIN:ragge:20030610135719
 
pftn.c
_>4444         struct  symtab **in_xp/* member in structure initializations */
 4545         int     in_n;           /* number of initializations seen */
 4646         struct  suedef *in_sue;
<>47 -        int     in_d;           /* dimoff */
  47+        int     *in_d;          /* dimoff */
4848         TWORD   in_t;           /* type */
 4949         struct  symtab *in_sym; /* stab index */
 5050         int     in_fl;  /* flag which says if this level is controlled by {} */
     
 !
6363 static void dynalloc(struct symtab *p, int *poff);
 6464 void inforce(OFFSZ n);
 6565 void vfdalign(int n);
<>66 -static void instk(struct symtab *p, TWORD t, int d, struct suedef *, OFFSZ off);
  66+static void instk(struct symtab *p, TWORD t, int *d, struct suedef *, OFFSZ off);
6767 void gotscal(void);
 6868 static void ssave(struct symtab *);
 6969 
     
 !
7676         TWORD type;
 7777         TWORD stp;
 7878         int scl;
<>79 -        int dsym, ddef;
  79+        int *dsym, *ddef;
8080         int slev, temp;
 8181         int changed;
 8282 
     
 !
9292         if (ddebug) {
 9393                 printf("defid(%s (%p), ", p->sname, p);
 9494                 tprint(q->n_type);
<>95 -                printf(", %s, (%d,%p)), level %d\n", scnames(class),
 96 -                    q->n_cdim, q->n_sue, blevel);
  95+                printf(", %s, (%p,%p)), level %d\n", scnames(class),
  96+                    q->n_dim, q->n_sue, blevel);
9797         }
 9898 # endif
 9999 
     
 !
112112                 printf(", %s\n", scnames(class));
 113113                 printf("        previous def'n: ");
 114114                 tprint(stp);
<>115 -                printf(", %s, (%d,%p)), level %d\n",
 116 -                    scnames(p->sclass), p->dimoff, p->ssue, slev);
  115+                printf(", %s, (%p,%p)), level %d\n",
  116+                    scnames(p->sclass), p->sdim, p->ssue, slev);
117117         }
 118118 # endif
 119119 
     
 !
146146                 goto mismatch;
 147147 
 148148         /* test (and possibly adjust) dimensions */
<>149 -        dsym = p->dimoff;
 150 -        ddef = q->n_cdim;
  149+        dsym = p->sdim;
  150+        ddef = q->n_dim;
151151         changed = 0;
 152152         for( temp=type; temp&TMASK; temp = DECREF(temp) ){
 153153                 if( ISARY(temp) ){
<>154 -                        if (dimtab[dsym] == 0) {
 155 -                                dimtab[dsym] = dimtab[ddef];
  154+                        if (*dsym == 0) {
  155+                                *dsym = *ddef;
156156                                 changed = 1;
<>157 -                                }
 158 -                        else if (dimtab[ddef]!=0&&dimtab[dsym]!=dimtab[ddef]) {
  157+                        } else if (*ddef != 0 && *dsym != *ddef) {
159158                                 goto mismatch;
<>160 -                                }
  159+                        }
161160                         ++dsym;
 162161                         ++ddef;
<>163 -                        }
164162                 }
<> 163+        }
165164 
 166165         if (changed) {
 167166                 FIXDEF(p);
<>168 -                }
  167+        }
169168 
 170169         /* check that redeclarations are to the same structure */
 171170         if ((temp == STRTY || temp == UNIONTY || temp == ENUMTY) &&
     
 !
328327 
 329328         /* copy dimensions */
 330329 
<>331 -        p->dimoff = q->n_cdim;
  330+        p->sdim = q->n_dim;
332331 
 333332         /* allocate offsets */
 334333         if (class&FIELD) {
     
 !
385384 
 386385 # ifndef BUG1
 387386         if (ddebug)
<>388 -                printf( "       dimoff, ssue, offset: %d, %p, %d\n",
 389 -                    p->dimoff, p->ssue, p->soffset);
  387+                printf( "       sdim, ssue, offset: %p, %p, %d\n",
  388+                    p->sdim, p->ssue, p->soffset);
390389 # endif
 391390 
 392391 }
     
 !
594593 dclstruct(struct rstack *r)
 595594 {
 596595         NODE *n;
<>597 -        struct params *l;
  596+        struct params *l, *m;
598597         struct suedef *sue;
 599598         struct symtab *p;
 600599         int al, sa, sz;
 601600         TWORD temp;
<>602 -        int high, low;
  601+        int i, high, low;
603602 
 604603         if (r->rsym == NULL) {
 605604                 sue = permalloc(sizeof(struct suedef));
     
 !
615614         temp = (instruct&INSTRUCT)?STRTY:((instruct&INUNION)?UNIONTY:ENUMTY);
 616615         instruct = r->rinstruct;
 617616         strunem = r->rclass;
<>618 -        sue->suelem = (struct symtab **)&dimtab[curdim]; /* XXX cast */
619617         al = ALSTRUCT;
 620618 
 621619         high = low = 0;
     
 !
625623         else
 626624                 l = l->next;
 627625 
<>628 -        for (; l != NULL; l = l->next) {
 629 -                dstash((int)(p = l->sym)); /* XXX cast */
  626+        /* memory for the element array must be allocated first */
  627+        for (m = l, i = 1; m != NULL; m = m->next)
  628+                i++;
  629+        sue->suelem = permalloc(sizeof(struct symtab *) * i);
  630+
  631+        for (i = 0; l != NULL; l = l->next) {
  632+                sue->suelem[i++] = p = l->sym;
  633+
630634                 if (p == NULL)
 631635                         cerror("gummy structure member");
 632636                 if (temp == ENUMTY) {
     
 !
641645                 if (p->sclass & FIELD) {
 642646                         sz = p->sclass&FLDSIZ;
 643647                 } else {
<>644 -                        sz = tsize(p->stype, p->dimoff, p->ssue);
  648+                        sz = tsize(p->stype, p->sdim, p->ssue);
645649                 }
 646650                 if (sz > strucoff)
 647651                         strucoff = sz/* for use with unions */
     
 !
651655                  */
 652656                 SETOFF(al, sa);
 653657         }
<>654 -        dstash(0)/* endmarker XXX cast */
  658+        sue->suelem[i] = NULL;
655659         SETOFF(strucoff, al);
 656660 
 657661         if (temp == ENUMTY) {
     
 !
677681 //      FIXSTRUCT(szindex, oparam); /* local hook, eg. for sym debugger */
 678682 #ifdef PCC_DEBUG
 679683         if (ddebug>1) {
<>680 -                int i = ((int *)sue->suelem) - dimtab;
  684+                int i;
  685+
681686                 printf("\tsize %d align %d elem %p\n",
 682687                     sue->suesize, sue->suealign, sue->suelem);
<>683 -                for (; dimtab[i] != 0; ++i) {
 684 -                        printf("\tmember %s(0x%x)\n",
 685 -                            ((struct symtab *)dimtab[i])->sname, dimtab[i]);
  688+                for (i = 0; sue->suelem[i] != NULL; ++i) {
  689+                        printf("\tmember %s(%p)\n",
  690+                            sue->suelem[i]->sname, sue->suelem[i]);
686691                 }
 687692         }
 688693 #endif
     
 !
801806  *  dimoff d, and sizoff s */
 802807 /* BETTER NOT BE CALLED WHEN t, d, and s REFER TO A BIT FIELD... */
 803808 OFFSZ
<>804 -tsize(TWORD ty, int d, struct suedef *sue)
  809+tsize(TWORD ty, int *d, struct suedef *sue)
805810 {
 806811 
 807812         int i;
     
 !
819824                 case PTR:
 820825                         return( SZPOINT * mult );
 821826                 case ARY:
<>822 -                        mult *= (unsigned int) dimtab[ d++ ];
  827+                        mult *= (unsigned int) *d++;
823828                         continue;
 824829                 case 0:
 825830                         break;
     
 !
949954 
 950955         pstk = 0;
 951956 
<>952 -        instk(p, p->stype, p->dimoff, p->ssue, inoff);
  957+        instk(p, p->stype, p->sdim, p->ssue, inoff);
953958 
 954959 }
 955960 
 956961 /*
 957962  * make a new entry on the parameter stack to initialize p
 958963  */
 959964 void
<>960 -instk(struct symtab *p, TWORD t, int d, struct suedef *sue, OFFSZ off)
  965+instk(struct symtab *p, TWORD t, int *d, struct suedef *sue, OFFSZ off)
961966 {
 962967         struct instk *sp;
 963968 
 964969         for (;;) {
 965970 # ifndef BUG1
 966971                 if (idebug)
<>967 -                        printf("instk((%p, %o,%d,%p, %lld)\n",
  972+                        printf("instk((%p, %o,%p,%p, %lld)\n",
968973                             p, t, d, sue, (long long)off);
 969974 # endif
 970975 
     
 !
10161021                                 cerror("insane %s member list",
 10171022                                     t == STRTY ? "structure" : "union");
 10181023                         t = p->stype;
<>1019 -                        d = p->dimoff;
  1024+                        d = p->sdim;
10201025                         sue = p->ssue;
 10211026                         off += p->soffset;
 10221027                         continue;
     
 !
10501055                  */
 10511056 
 10521057                 lxarg = pstk->in_prev->in_prev != NULL ?
<>1053 -                    dimtab[pstk->in_prev->in_d] : 0;
  1058+                    *pstk->in_prev->in_d : 0;
10541059                 while (*wr != 0) {
 10551060                         if (*wr++ == '\\')
 10561061                                 val = esccon(&wr);
     
 !
11081113                 i = strlen(str)+1;
 11091114         }
 11101115 
<>1111 -        dimtab[curdim] = i; /* in case of later sizeof ... */
11121116         p = buildtree(STRING, NIL, NIL);
<> 1117+        p->n_dim = tmpalloc(sizeof(int));
  1118+        *p->n_dim = i;
11131119         if (isinlining) {
 11141120                 p->n_sp = permalloc(sizeof(struct symtab_hdr));
 11151121                 p->n_sp->sclass = ILABEL;
     
 !
11381144 {
 11391145         struct suedef *sue;
 11401146         TWORD t;
<>1141 -        int d, n, d1;
  1147+        int *d, n, *d1;
11421148 
 11431149 # ifndef BUG1
 11441150         if (idebug)
     
 !
11631169         n = pstk->in_n;
 11641170 
 11651171         if( ISARY(t) ){
<>1166 -                d1 = dimtab[d];
  1172+                d1 = d;
11671173 
<>1168 -                vfdalign( pstk->in_sz );  /* fill out part of the last element, if needed */
  1174+                vfdalign(pstk->in_sz);  /* fill out part of the last element, if needed */
11691175                 n = inoff/pstk->in_sz/* real number of initializers */
<>1170 -                if( d1 >= n ){
  1176+                if (*d1 >= n) {
11711177                         /* once again, t is an array, so no fields */
 11721178                         inforce(tsize(t, d, sue));
<>1173 -                        n = d1;
 1174 -                        }
 1175 -                if( d1!=0 && d1!=n ) uerror( "too many initializers");
 1176 -                if( n==0 ) werror( "empty array declaration");
 1177 -                dimtab[d] = n;
 1178 -                if (d1==0) {
  1179+                        n = *d1;
  1180+                }
  1181+                if (*d1 != 0 && *d1 != n)
  1182+                        uerror("too many initializers");
  1183+                if (n == 0)
  1184+                        werror("empty array declaration");
  1185+                *d = n;
  1186+                if (*d1 == 0) {
11791187                         FIXDEF(pstk->in_sym);
 11801188                 }
 11811189         }
 11821190 
<>1183 -        else if( t == STRTY || t == UNIONTY ){
  1191+        else if (t == STRTY || t == UNIONTY) {
11841192                 /* clearly not fields either */
 11851193                 inforce( tsize( t, d, sue ) );
<>1186 -                }
 1187 -        else if( n > 1 ) uerror( "bad scalar initialization");
  1194+        } else if (n > 1)
  1195+                uerror("bad scalar initialization");
  1196+        else
11881197         /* this will never be called with a field element... */
<>1189 -        else inforce( tsize(t,d,sue) );
  1198+                inforce(tsize(t, d, sue));
11901199 
 11911200         lparam = NULL;
 11921201         vfdalign( AL_INIT );
     
 !
12201229 {
 12211230         NODE *u;
 12221231         struct suedef *sue;
<>1223 -        int sz, d;
  1232+        int sz, *d;
12241233         TWORD t;
 12251234         int o;
 12261235 
     
 !
12711280 
 12721281         inforce( pstk->in_off );
 12731282 
<>1274 -        u = block(NAME, NIL,NIL, t, d, 0);
 1275 -        u->n_sue = sue;
  1283+        u = block(NAME, NIL,NIL, t, d, sue);
12761284         p = buildtree( ASSIGN, u, p );
 12771285         p->n_left->n_op = FREE;
 12781286         p->n_left = p->n_right;
     
 !
13291337                                 continue;
 13301338 
 13311339                         /* otherwise, put next element on the stack */
<>1332 -                        instk(p, p->stype, p->dimoff, p->ssue, p->soffset+pstk->in_off );
  1340+                        instk(p, p->stype, p->sdim, p->ssue,
  1341+                            p->soffset + pstk->in_off);
13331342                         return;
<>1334 -                        }
 1335 -                else if( ISARY(t) ){
  1343+                } else if( ISARY(t) ){
13361344                         n = ++pstk->in_n;
<>1337 -                        if (n >= dimtab[pstk->in_d] && pstk->in_prev != NULL)
  1345+                        if (n >= *pstk->in_d && pstk->in_prev != NULL)
13381346                                 continue;
 13391347 
 13401348                         /* put the new element onto the stack */
 13411349 
 13421350                         temp = pstk->in_sz;
<>1343 -                        instk(pstk->in_sym, (TWORD)DECREF(pstk->in_t), pstk->in_d+1, pstk->in_sue,
 1344 -                                pstk->in_off+n*temp );
  1351+                        instk(pstk->in_sym, (TWORD)DECREF(pstk->in_t),
  1352+                            pstk->in_d+1, pstk->in_sue, pstk->in_off+n*temp);
13451353                         return;
<>1346 -                        }
 1347 -
13481354                 }
<>1349 -        ifull = 1;
  1355+
13501356         }
<> 1357+        ifull = 1;
  1358+}
13511359 
 13521360 /*
 13531361  * process an initializer's left brace
     
 !
14461454 
 14471455         al = talign(p->stype, p->ssue);
 14481456         noff = off = *poff;
<>1449 -        tsz = tsize(p->stype, p->dimoff, p->ssue);
  1457+        tsz = tsize(p->stype, p->sdim, p->ssue);
14501458 #ifdef BACKAUTO
 14511459         if (p->sclass == AUTO) {
 14521460                 if ((offsz-off) < tsz)
     
 !
15171525          */
 15181526         ptroff = upoff(tsize(PTR, 0, &sue), talign(PTR, &sue), poff);
 15191527         if (arrstkp > 1) {
<>1520 -                dimtab[curdim] = arrstkp-1;
 1521 -                dimtab[curdim+1] = INT;
 1522 -                argoff = upoff(tsize(ARY+INT, dimtab[curdim], NULL),
  1528+                int tab[2];
  1529+                tab[0] = arrstkp-1;
  1530+                tab[1] = INT;
  1531+                argoff = upoff(tsize(ARY+INT, tab, NULL),
15231532                     talign(ARY+INT, 0), poff);
 15241533         }
 15251534 
     
 !
16861695 
 16871696         /* if an array is not initialized, no empty dimension */
 16881697         if (class != EXTERN && class != TYPEDEF &&
<>1689 -            ISARY(p->n_type) && dimtab[p->n_cdim]==0)
  1698+            ISARY(p->n_type) && *p->n_dim == 0)
16901699                 uerror("null storage definition");
 16911700 
 16921701 #ifndef LCOMM
     
 !
18331842         struct tylnk *next;
 18341843         int dim;
 18351844 } tylnk, *tylkp;
<> 1845+static int ntdim;
18361846 
 18371847 static void
 18381848 tylkadd(int dim)
     
 !
18411851         tylkp = tylkp->next;
 18421852         tylkp->next = NULL;
 18431853         tylkp->dim = dim;
<> 1854+        ntdim++;
18441855 }
 18451856 
 18461857 /* merge type typ with identifier idp  */
     
 !
18491860 {
 18501861         struct tylnk *base;
 18511862         unsigned int t;
<>1852 -        int i;
  1863+        int i, *j;
18531864 
 18541865         if (typ->n_op != TYPE)
 18551866                 cerror( "tymerge: arg 1" );
     
 !
18611872 # endif
 18621873 
 18631874         idp->n_type = typ->n_type;
<>1864 -        idp->n_cdim = curdim;
18651875 
 18661876         tylkp = &tylnk;
 18671877         tylkp->next = NULL;
<> 1878+        ntdim = 0;
18681879 
 18691880         tyreduce(idp);
 18701881         idp->n_sue = typ->n_sue;
 18711882 
<>1872 -        for (t=typ->n_type, i=typ->n_cdim; t&TMASK; t = DECREF(t))
  1883+        for (t = typ->n_type, j = typ->n_dim; t&TMASK; t = DECREF(t))
18731884                 if (ISARY(t))
<>1874 -                        tylkadd(dimtab[i++]);
  1885+                        tylkadd(*j++);
18751886 
<>1876 -        for (base = tylnk.next; base; base = base->next)
 1877 -                dstash(base->dim);
  1887+        if (ntdim) {
  1888+                int *a = permalloc(sizeof(int) * ntdim);
  1889+                for (i = 0, base = tylnk.next; base; base = base->next, i++)
  1890+                        a[i] = base->dim;
  1891+                idp->n_dim = a;
  1892+        } else
  1893+                idp->n_dim = NULL;
18781894 
 18791895         /* now idp is a single node: fix up type */
 18801896 
     
 !
19671983 
 19681984         if( class==SNULL && blevel==1 && !(instruct&(INSTRUCT|INUNION)) )
 19691985                 class = PARAM;
<>1970 -        if( class == PARAM || ( class==REGISTER && blevel==1 ) ){
 1971 -                if( type == FLOAT ) type = DOUBLE;
 1972 -                else if( ISARY(type) ){
 1973 -                        ++p->n_cdim;
  1986+        if (class == PARAM || (class == REGISTER && blevel == 1)) {
  1987+                if (type == FLOAT)
  1988+                        type = DOUBLE;
  1989+                else if (ISARY(type)) {
  1990+                        ++p->n_dim;
19741991                         type += (PTR-ARY);
<>1975 -                        }
 1976 -                else if( ISFTN(type) ){
 1977 -                        werror( "a function is declared as an argument" );
  1992+                } else if (ISFTN(type)) {
  1993+                        werror("a function is declared as an argument");
19781994                         type = INCREF(type);
<>1979 -                        }
 1980 -
19811995                 }
 19821996 
<>1983 -        if( instruct && ISFTN(type) ){
 1984 -                uerror( "function illegal in structure or union" );
  1997+        }
  1998+
  1999+        if (instruct && ISFTN(type)) {
  2000+                uerror("function illegal in structure or union");
19852001                 type = INCREF(type);
<>1986 -                }
  2002+        }
<_19872003         p->n_type = type;
 19882004 }
 19892005 
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-21 00:06 +0200