Quick Search:

Mode

Context

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

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.32
 
1.33
 
MAIN:ragge:20030604193605
 
pftn.c
_>99 unsigned int offsz;
 1010 
 1111 struct symtab *schain[MAXSCOPES];       /* sym chains for clearst */
<> 12+struct symtab *spname;
  13+struct symtab *cftnsp;
1214 int chaintop;                           /* highest active entry */
 1315 static int strunem;                     /* currently parsed member */
 1416 
     
 !
1921         int in_s;    /* sizoff */
 2022         int in_d;    /* dimoff */
 2123         TWORD in_t;    /* type */
<>22 -        int in_id;   /* stab index */
  24+        struct symtab *in_sym;   /* stab index */
2325         int in_fl;   /* flag which says if this level is controlled by {} */
 2426         OFFSZ in_off/* offset of the beginning of this level */
 2527 } instack[10], *pstk;
     
 !
3739 void psave(int);
 3840 int oalloc(struct symtab *p, int *poff);
 3941 static void dynalloc(struct symtab *p, int *poff);
<>40 -int hide(struct symtab *p);
4142 void inforce(OFFSZ n);
 4243 void vfdalign(int n);
<>43 -void instk(int id, TWORD t, int d, int s, OFFSZ off);
  44+static void instk(struct symtab *p, TWORD t, int d, int s, OFFSZ off);
  45+static struct symtab *hide(struct symtab *p);
4446 void gotscal(void);
 4547 
 4648 int ddebug = 0;
     
 !
6163                         return strtags[i];
 6264         if (curtag == MAXTAGS)
 6365                 cerror("too many tags (%d)", curtag);
<>64 -        strtags[curtag++] = calloc(sizeof(struct symtab), 1);
 65 -        strtags[i]->sname = name;
 66 -        strtags[i]->stype = UNDEF;
 67 -        strtags[i]->sclass = SNULL;
 68 -        strtags[i]->s_argn = 0;
  66+        strtags[curtag++] = getsymtab(name, STAG);
6967         return strtags[i];
 7068 }
 7169 /* end temporary */
     
 !
7472 defid(NODE *q, int class)
 7573 {
 7674         struct symtab *p;
<>77 -        int idp;
7875         TWORD type;
 7976         TWORD stp;
 8077         int scl;
     
 !
8885         if (q < node || q >= &node[TREESZ])
 8986                 cerror("defid call");
 9087 
<>91 -        idp = q->n_rval;
  88+        p = q->n_sp;
9289 
<>93 -        if (idp < 0)
 94 -                cerror("tyreduce");
 95 -
 96 -        if (idp > 20000) {
 97 -                p = (struct symtab *)idp;
 98 -        } else
 99 -                p = &stab[idp];
 100 -
10190 # ifndef BUG1
 10291         if (ddebug) {
<>103 -                printf("defid(%s (%d), ", p->sname, idp);
  92+                printf("defid(%s (%p), ", p->sname, p);
10493                 tprint(q->n_type);
 10594                 printf(", %s, (%d,%d)), level %d\n", scnames(class),
 10695                     q->n_cdim, q->n_csiz, blevel);
 10796         }
 10897 # endif
 10998 
<>110 -        fixtype( q, class );
  99+        fixtype(q, class);
111100 
 112101         type = q->n_type;
<>113 -        class = fixclass( class, type );
  102+        class = fixclass(class, type);
114103 
 115104         stp = p->stype;
 116105         slev = p->slevel;
     
 !
127116         }
 128117 # endif
 129118 
<>130 -        if( stp == FTN && p->sclass == SNULL )goto enter;
  119+        if (stp == FTN && p->sclass == SNULL)
  120+                goto enter;
  121+
131122         if (blevel==1 && stp!=FARG)
<>132 -                switch( class ){
  123+                switch (class) {
133124                 default:
 134125                         if (!(class&FIELD))
 135126                                 uerror( "declared argument %s is missing",
     
 !
143134                 case TYPEDEF:
 144135                         ;
 145136         }
<>146 -        if( stp == UNDEF|| stp == FARG ) goto enter;
  137+        if (stp == UNDEF|| stp == FARG)
  138+                goto enter;
147139 
<>148 -        if( type != stp ) goto mismatch;
 149 -        if( blevel > slev && (class == AUTO || class == REGISTER) )
  140+        if (type != stp)
  141+                goto mismatch;
  142+
  143+        if (blevel > slev && (class == AUTO || class == REGISTER))
150144                 /* new scope */
 151145                 goto mismatch;
 152146 
     
 !
173167                 }
 174168 
 175169         /* check that redeclarations are to the same structure */
<>176 -        if( (temp==STRTY||temp==UNIONTY||temp==ENUMTY) && p->sizoff != q->n_csiz
 177 -                 && class!=STNAME && class!=UNAME && class!=ENAME ){
  170+        if ((temp == STRTY || temp == UNIONTY || temp == ENUMTY) &&
  171+            p->sizoff != q->n_csiz &&
  172+            class != STNAME && class != UNAME && class != ENAME) {
178173                 goto mismatch;
<>179 -                }
  174+        }
180175 
<>181 -        scl = ( p->sclass );
  176+        scl = p->sclass;
182177 
 183178 # ifndef BUG1
<>184 -        if( ddebug ){
 185 -                printf( "       previous class: %s\n", scnames(scl) );
 186 -                }
  179+        if (ddebug)
  180+                printf("        previous class: %s\n", scnames(scl));
187181 # endif
 188182 
<>189 -        if( class&FIELD ){
  183+        if (class&FIELD) {
190184                 /* redefinition */
<>191 -                if( !falloc( p, class&FLDSIZ, 1, NIL ) ) {
  185+                if (!falloc(p, class&FLDSIZ, 1, NIL)) {
192186                         /* successful allocation */
<>193 -                        psave( idp );
  187+                        psave((int)p); /* XXX cast */
194188                         return;
<>195 -                        }
 196 -                /* blew it: resume at end of switch... */
197189                 }
<> 190+                /* blew it: resume at end of switch... */
  191+        } else switch(class) {
198192 
<>199 -        else switch( class ){
 200 -
201193         case EXTERN:
 202194                 switch( scl ){
 203195                 case STATIC:
     
 !
213205                 break;
 214206 
 215207         case STATIC:
<>216 -                if( scl==USTATIC || (scl==EXTERN && blevel==0) ){
  208+                if (scl==USTATIC || (scl==EXTERN && blevel==0)) {
217209                         p->sclass = STATIC;
<>218 -                        if( ISFTN(type) ) curftn = idp;
  210+                        if (ISFTN(type))
  211+                                cftnsp = p;
219212                         return;
<>220 -                        }
  213+                }
221214                 break;
 222215 
 223216         case USTATIC:
<>224 -                if( scl==STATIC || scl==USTATIC ) return;
  217+                if (scl==STATIC || scl==USTATIC)
  218+                        return;
225219                 break;
 226220 
 227221         case TYPEDEF:
<>228 -                if( scl == class ) return;
  222+                if (scl == class)
  223+                        return;
229224                 break;
 230225 
 231226         case UFORTRAN:
<>232 -                if( scl == UFORTRAN || scl == FORTRAN ) return;
  227+                if (scl == UFORTRAN || scl == FORTRAN)
  228+                        return;
233229                 break;
 234230 
 235231         case FORTRAN:
<>236 -                if( scl == UFORTRAN ){
  232+                if (scl == UFORTRAN) {
237233                         p->sclass = FORTRAN;
<>238 -                        if( ISFTN(type) ) curftn = idp;
  234+                        if (ISFTN(type))
  235+                                cftnsp = p;
239236                         return;
<>240 -                        }
  237+                }
241238                 break;
 242239 
 243240         case MOU:
 244241         case MOS:
<>245 -                if( scl == class ) {
 246 -                        if( oalloc( p, &strucoff ) ) break;
 247 -                        if( class == MOU ) strucoff = 0;
 248 -                        psave( idp );
  242+                if (scl == class) {
  243+                        if (oalloc(p, &strucoff))
  244+                                break;
  245+                        if (class == MOU)
  246+                                strucoff = 0;
  247+                        psave((int)p); /* XXX cast */
249248                         return;
<>250 -                        }
  249+                }
251250                 break;
 252251 
 253252         case MOE:
     
 !
258257                 case EXTERN:
 259258                         p->sclass = EXTDEF;
 260259                         if (ISFTN(type))
<>261 -                                curftn = idp;
  260+                                cftnsp = p;
262261                         return;
 263262                 case USTATIC:
 264263                         p->sclass = STATIC;
 265264                         if (ISFTN(type))
<>266 -                                curftn = idp;
  265+                                cftnsp = p;
267266                         return;
 268267                 }
 269268                 break;
 270269 
 271270         case STNAME:
 272271         case UNAME:
 273272         case ENAME:
<>274 -                if( scl != class ) break;
 275 -                if( dimtab[p->sizoff] == 0 ) return/* previous entry just a mention */
  273+                if (scl != class)
  274+                        break;
  275+                if (dimtab[p->sizoff] == 0)
  276+                        return/* previous entry just a mention */
276277                 break;
 277278 
 278279         case PARAM:
 279280         case AUTO:
 280281         case REGISTER:
 281282                 ;  /* mismatch.. */
<> 283+        }
282284 
<>283 -                }
 284 -
285285         mismatch:
 286286         /* allow nonunique structure/union member names */
 287287 
 288288         if( class==MOU || class==MOS || class & FIELD ){/* make a new entry */
<> 289+                cerror("mismatch nonunique");
  290+#if 0
289291                 int *memp;
 290292                 p->sflags |= SNONUNIQ/* old entry is nonunique */
 291293                 /* determine if name has occurred in this structure/union */
     
 !
295297                                 char *cname, *oname;
 296298                                 struct symtab *w;
 297299 
<>298 -                                if (*memp > 20000)
 299 -                                        w = (struct symtab *)*memp;
 300 -                                else
 301 -                                        w = &stab[*memp];
  300+                                w = (struct symtab *)*memp;
302301                                 if (w->sclass != STNAME && w->sclass != UNAME)
 303302                                         break;
 304303 
     
 !
314313                 }
 315314                 p = mknonuniq( &idp ); /* update p and idp to new entry */
 316315                 goto enter;
<>317 -                }
  316+#endif
  317+        }
318318         if (blevel > slev && class != EXTERN && class != FORTRAN &&
 319319             class != UFORTRAN) {
<>320 -                q->n_rval = idp = hide( p );
 321 -                p = &stab[idp];
  320+                p = hide(p);
  321+                q->n_sp = p;
322322                 goto enter;
 323323         }
<>324 -        uerror( "redeclaration of %s", p->sname );
 325 -        if( class==EXTDEF && ISFTN(type) ) curftn = idp;
  324+        uerror("redeclaration of %s", p->sname);
  325+        if (class==EXTDEF && ISFTN(type))
  326+                cftnsp = p;
326327         return;
 327328 
 328329         enter/* make a new entry */
 329330 
 330331 # ifndef BUG1
<>331 -        if( ddebug ) printf( "  new entry made\n" );
  332+        if(ddebug)
  333+                printf("        new entry made\n");
332334 # endif
<>333 -        if( type == UNDEF ) uerror("void type for %s",p->sname);
  335+        if (type == UNDEF)
  336+                uerror("void type for %s", p->sname);
334337         p->stype = type;
 335338         p->sclass = class;
 336339         p->slevel = blevel;
<>337 -        p->offset = NOOFFSET;
  340+        p->soffset = NOOFFSET;
338341         p->suse = lineno;
 339342         if( class == STNAME || class == UNAME || class == ENAME ) {
 340343                 p->sizoff = curdim;
 341344                 dstash( 0 );  /* size */
 342345                 dstash( -1 ); /* index to members of str or union */
 343346                 dstash( ALSTRUCT );  /* alignment */
<>344 -                dstash((int)p); /* dstash( idp ); XXX */
  347+                dstash((int)p); /* dstash( idp ); XXX cast */
345348                 }
 346349         else {
 347350                 switch( BTYPE(type) ){
     
 !
360363         p->dimoff = q->n_cdim;
 361364 
 362365         /* allocate offsets */
<>363 -        if( class&FIELD ){
 364 -                (void) falloc( p, class&FLDSIZ, 0, NIL );  /* new entry */
 365 -                psave( idp );
 366 -                }
 367 -        else switch( class ){
  366+        if (class&FIELD) {
  367+                (void) falloc(p, class&FLDSIZ, 0, NIL);  /* new entry */
  368+                psave((int)p); /* XXX cast */
  369+        } else switch (class) {
368370 
 369371         case AUTO:
 370372                 if (arrstkp)
 371373                         dynalloc(p, &autooff);
 372374                 else
<>373 -                        (void) oalloc( p, &autooff );
  375+                        (void) oalloc(p, &autooff);
374376                 break;
 375377         case STATIC:
 376378         case EXTDEF:
<>377 -                p->offset = getlab();
 378 -                if( ISFTN(type) ) curftn = idp;
  379+                p->soffset = getlab();
  380+                if (class == STATIC && blevel > 0)
  381+                        p->sflags |= SLABEL;
  382+                if (ISFTN(type))
  383+                        cftnsp = p;
379384                 break;
 380385 
 381386         case EXTERN:
 382387         case UFORTRAN:
 383388         case FORTRAN:
<>384 -                p->offset = getlab();
  389+                p->soffset = getlab();
385390                 p->slevel = 0;
 386391                 break;
 387392         case MOU:
 388393         case MOS:
 389394                 (void) oalloc( p, &strucoff );
 390395                 if( class == MOU ) strucoff = 0;
<>391 -                psave( idp );
  396+                psave((int)p); /* XXX cast */
392397                 break;
 393398 
 394399         case MOE:
<>395 -                p->offset = strucoff++;
 396 -                psave( idp );
  400+                p->soffset = strucoff++;
  401+                psave((int)p); /* XXX cast */
397402                 break;
 398403         case REGISTER:
<>399 -                p->offset = regvar--;
 400 -                if( blevel == 1 ) p->sflags |= SSET;
 401 -                if( regvar < minrvar ) minrvar = regvar;
  404+                p->soffset = regvar--;
  405+                if (blevel == 1)
  406+                        p->sflags |= SSET;
  407+                if (regvar < minrvar)
  408+                        minrvar = regvar;
402409                 break;
<>403 -                }
  410+        }
404411 
 405412         {
 406413                 int l = p->slevel;
     
 !
412419                 schain[l] = p;
 413420                 if( l >= chaintop )
 414421                         chaintop = l + 1;
<>415 -                }
  422+        }
416423 
 417424         /* user-supplied routine to fix up new definitions */
 418425 
 419426         FIXDEF(p);
 420427 
 421428 # ifndef BUG1
<>422 -        if( ddebug ) printf( "  dimoff, sizoff, offset: %d, %d, %d\n", p->dimoff, p->sizoff, p->offset );
  429+        if (ddebug)
  430+                printf( "       dimoff, sizoff, offset: %d, %d, %d\n",
  431+                    p->dimoff, p->sizoff, p->soffset );
423432 # endif
 424433 
<>425 -        }
  434+}
426435 
 427436 void
 428437 psave(int i)
     
 !
439448 void
 440449 ftnend()
 441450 {
<>442 -        if( retlab != NOLAB && nerrors == 0 ){ /* inside a real function */
  451+        if (retlab != NOLAB && nerrors == 0) /* inside a real function */
443452                 efcode();
<>444 -        }
  453+
445454         checkst(0);
 446455         retstat = 0;
 447456         tcheck();
     
 !
477486         for (i = 0; i < paramno; ++i) {
 478487                 if ((j = paramstk[i]) < 0)
 479488                         continue;
<>480 -                p = &stab[j];
  489+                p = (struct symtab *)j;
481490 # ifndef BUG1
 482491                 if (ddebug > 2) {
 483492                         printf("\t%s (%d) ",p->sname, j);
     
 !
506515  * reference to a structure or union, with no definition
 507516  */
 508517 NODE *
<>509 -rstruct(int idn, int soru)
  518+rstruct(char *tag, int soru)
510519 {
 511520         struct symtab *p;
 512521         NODE *q;
<>513 -        p = (struct symtab *)idn;
514522 
<> 523+        p = (struct symtab *)lookup(tag, STAG);
515524         switch (p->stype) {
 516525 
 517526         case UNDEF:
 518527         def:
 519528                 q = block(FREE, NIL, NIL, 0, 0, 0);
<>520 -                q->n_rval = (int)p;
  529+                q->n_sp = p;
521530                 q->n_type = (soru&INSTRUCT) ? STRTY :
 522531                     ((soru&INUNION) ? UNIONTY : ENUMTY);
 523532                 defid(q, (soru&INSTRUCT) ? STNAME :
     
 !
545554 }
 546555 
 547556 void
<>548 -moedef(int idn)
  557+moedef(char *name)
549558 {
 550559         NODE *q;
 551560 
<>552 -        q = block( FREE, NIL, NIL, MOETY, 0, 0 );
 553 -        q->n_rval = idn;
 554 -        if( idn>=0 ) defid( q, MOE );
  561+        q = block(FREE, NIL, NIL, MOETY, 0, 0);
  562+        q->n_sp = lookup(name, 0);
  563+        defid(q, MOE);
555564 }
 556565 
 557566 /*
 558567  * begining of structure or union declaration
 559568  */
 560569 int
<>561 -bstruct(int idn, int soru)
  570+bstruct(char *name, int soru)
562571 {
<> 572+        struct symtab *s;
563573         NODE *q;
 564574 
<> 575+        if (name != NULL)
  576+                s = lookup(name, STAG);
  577+        else
  578+                s = NULL;
  579+
565580         psave(instruct);
 566581         psave(strunem);
 567582         psave(strucoff);
 568583         strucoff = 0;
 569584         instruct = soru;
 570585         q = block(FREE, NIL, NIL, 0, 0, 0);
<>571 -        q->n_rval = idn;
  586+        q->n_sp = s;
572587         if (instruct==INSTRUCT) {
 573588                 strunem = MOS;
 574589                 q->n_type = STRTY;
<>575 -                if (idn >= 0)
  590+                if (s != NULL)
576591                         defid(q, STNAME);
 577592         } else if(instruct == INUNION) {
 578593                 strunem = MOU;
 579594                 q->n_type = UNIONTY;
<>580 -                if (idn >= 0)
  595+                if (s != NULL)
581596                         defid(q, UNAME);
 582597         } else { /* enum */
 583598                 strunem = MOE;
 584599                 q->n_type = ENUMTY;
<>585 -                if (idn >= 0)
  600+                if (s != NULL)
586601                         defid(q, ENAME);
 587602         }
<>588 -        psave(idn = q->n_rval);
  603+        psave((int)q->n_sp); /* XXX cast */
  604+
589605         /* the "real" definition is where the members are seen */
<>590 -        if (idn >= 0)
 591 -#if 0
 592 -                stab[idn].suse = lineno;
 593 -#else
 594 -                ((struct symtab *)idn)->suse = lineno;
 595 -#endif
  606+        if (s != NULL)
  607+                s->suse = lineno;
596608         return(paramno-4);
 597609 }
 598610 
     
 !
618630          */
 619631 
 620632 
<>621 -        if ((i = paramstk[oparam+3]) < 0) {
  633+        if ((i = paramstk[oparam+3]) <= 0) {
622634                 szindex = curdim;
 623635                 dstash(0);  /* size */
 624636                 dstash(-1);  /* index to member names */
 625637                 dstash(ALSTRUCT);  /* alignment */
 626638                 dstash(-lineno);        /* name of structure */
 627639         } else
<>628 -#if 0
 629 -                szindex = stab[i].sizoff;
 630 -#else
631640                 szindex = ((struct symtab *)i)->sizoff;
<>632 -#endif
633641 
 634642 # ifndef BUG1
 635643         if (ddebug) {
 636644                 printf("dclstruct( %s ), szindex = %d\n",
<>637 -                    (i>=0)? ((struct symtab *)i)->sname : "??", szindex);
  645+                    (i>0)? ((struct symtab *)i)->sname : "??", szindex);
638646         }
 639647 # endif
 640648         temp = (instruct&INSTRUCT)?STRTY:((instruct&INUNION)?UNIONTY:ENUMTY);
     
 !
647655 
 648656         for( i = oparam+4i< paramno; ++i ){
 649657                 dstash( j=paramstk[i] );
<>650 -                if( j<0 || j>= SYMTSZ ) cerror( "gummy structure member" );
 651 -                p = &stab[j];
  658+                if( j<0 /* || j>= SYMTSZ */ ) cerror( "gummy structure member" ); /* XXX cast bad test */
  659+                p = (struct symtab *)j; /* XXX - cast */
652660                 if( temp == ENUMTY ){
<>653 -                        if( p->offset < low ) low = p->offset;
 654 -                        if( p->offset > high ) high = p->offset;
  661+                        if( p->soffset < low ) low = p->soffset;
  662+                        if( p->soffset > high ) high = p->soffset;
655663                         p->sizoff = szindex;
 656664                         continue;
 657665                         }
     
 !
707715                     dimtab[szindex],dimtab[szindex+1],dimtab[szindex+2] );
 708716                 for (i = dimtab[szindex+1]; dimtab[i] >= 0; ++i) {
 709717                         printf("\tmember %s(%d)\n",
<>710 -                            stab[dimtab[i]].sname, dimtab[i]);
  718+                            ((struct symtab *)dimtab[i])->sname, dimtab[i]);
711719                 }
 712720         }
 713721 # endif
     
 !
736744 }
 737745 
 738746 void
<>739 -ftnarg(int idn)
  747+ftnarg(char *name)
740748 {
<>741 -        switch( stab[idn].stype ){
  749+        struct symtab *s = lookup(name, 0);
742750 
<> 751+        switch (s->stype) {
743752         case UNDEF:
 744753                 /* this parameter, entered at scan */
 745754                 break;
 746755         case FARG:
<>747 -                uerror("redeclaration of formal parameter, %s",
 748 -                        stab[idn].sname);
  756+                uerror("redeclaration of formal parameter, %s", s->sname);
749757                 /* fall thru */
 750758         case FTN:
 751759                 /* the name of this function matches parm */
 752760                 /* fall thru */
 753761         default:
<>754 -                idn = hide( &stab[idn]);
  762+                s = hide(s);
755763                 break;
 756764         case TNULL:
 757765                 /* unused entry, fill it */
 758766                 ;
<>759 -                }
 760 -        stab[idn].stype = FARG;
 761 -        stab[idn].sclass = PARAM;
 762 -        psave( idn );
  767+        }
  768+        s->stype = FARG;
  769+        s->sclass = PARAM;
  770+        psave((int)s);
763771 }
 764772 
 765773 /*
     
 !
932940  * beginning of initilization; set location ctr and set type
 933941  */
 934942 void
<>935 -beginit(int curid, int class)
  943+beginit(struct symtab *p, int class)
936944 {
<>937 -        struct symtab *p;
 938 -
939945 # ifndef BUG1
<>940 -        if( idebug >= 3 ) printf( "beginit(), curid = %d\n", curid );
  946+        if (idebug >= 3)
  947+                printf("beginit(), symtab = %p\n", p);
941948 # endif
 942949 
<>943 -        p = &stab[curid];
 944 -
945950         iclass = p->sclass;
<>946 -        if( class == EXTERN || class == FORTRAN )
  951+        if (class == EXTERN || class == FORTRAN)
947952                 iclass = EXTERN;
<>948 -        switch( iclass ){
  953+        switch (iclass) {
949954 
 950955         case UNAME:
 951956         case EXTERN:
     
 !
956961         case EXTDEF:
 957962         case STATIC:
 958963                 ilocctr = ISARY(p->stype)?ADATA:DATA;
<>959 -                if( nerrors == 0 ){
 960 -                        (void) locctr( ilocctr );
 961 -                        defalign( talign( p->stype, p->sizoff ) );
 962 -                        defnam( p );
  964+                if (nerrors == 0) {
  965+                        (void) locctr(ilocctr);
  966+                        defalign(talign(p->stype, p->sizoff));
  967+                        defnam(p);
963968                 }
 964969         }
 965970 
     
 !
969974 
 970975         pstk = 0;
 971976 
<>972 -        instk( curid, p->stype, p->dimoff, p->sizoff, inoff );
  977+        instk(p, p->stype, p->dimoff, p->sizoff, inoff);
973978 
 974979 }
 975980 
 976981 /*
 977982  * make a new entry on the parameter stack to initialize id
 978983  */
 979984 void
<>980 -instk(int id, TWORD t, int d, int s, OFFSZ off)
  985+instk(struct symtab *p, TWORD t, int d, int s, OFFSZ off)
981986 {
<>982 -        struct symtab *p;
983987 
 984988         for (;;) {
 985989 # ifndef BUG1
 986990                 if (idebug)
<>987 -                        printf("instk((%d, %o,%d,%d, %lld)\n",
 988 -                            id, t, d, s, (long long)off);
  991+                        printf("instk((%p, %o,%d,%d, %lld)\n",
  992+                            p, t, d, s, (long long)off);
989993 # endif
 990994 
 991995                 /* save information on the stack */
     
 !
9961000                         ++pstk;
 9971001 
 9981002                 pstk->in_fl = 0;        /* { flag */
<>999 -                pstk->in_id = id;
  1003+                pstk->in_sym = p;
10001004                 pstk->in_t = t;
 10011005                 pstk->in_d = d;
 10021006                 pstk->in_s = s;
     
 !
10081012                 /* in_sz has size of array elements, and -size for fields */
 10091013                 if (ISARY(t)) {
 10101014                         pstk->in_sz = tsize(DECREF(t), d+1, s);
<>1011 -                } else if (stab[id].sclass & FIELD){
 1012 -                        pstk->in_sz = - (stab[id].sclass & FLDSIZ);
  1015+                } else if (p->sclass & FIELD){
  1016+                        pstk->in_sz = - (p->sclass & FLDSIZ);
10131017                 } else {
 10141018                         pstk->in_sz = 0;
 10151019                 }
     
 !
10311035                                 iclass = -1;
 10321036                                 return;
 10331037                         }
<>1034 -                        id = dimtab[pstk->in_x];
 1035 -                        p = &stab[id];
  1038+                        p = (struct symtab *)dimtab[pstk->in_x];
10361039                         if (((p->sclass != MOS && t == STRTY) ||
 10371040                             (p->sclass != MOU && t == UNIONTY)) &&
 10381041                             !(p->sclass&FIELD))
     
 !
10411044                         t = p->stype;
 10421045                         d = p->dimoff;
 10431046                         s = p->sizoff;
<>1044 -                        off += p->offset;
  1047+                        off += p->soffset;
10451048                         continue;
 10461049                 } else
 10471050                         return;
     
 !
11441147 
 11451148         dimtab[curdim] = i; /* in case of later sizeof ... */
 11461149         p = buildtree(STRING, NIL, NIL);
<>1147 -        p->n_rval = -strlab;
  1150+        p->n_sp = permalloc(sizeof(struct symtab_hdr));
  1151+        p->n_sp->sclass = ILABEL;
  1152+        p->n_sp->soffset = strlab;
11481153         return(p);
 11491154 }
 11501155 
     
 !
12021207                 if( n==0 ) werror( "empty array declaration");
 12031208                 dimtab[d] = n;
 12041209                 if (d1==0) {
<>1205 -                        FIXDEF(&stab[pstk->in_id]);
  1210+                        FIXDEF(pstk->in_sym);
12061211                 }
 12071212         }
 12081213 
     
 !
12601265                 /* do the initialization and get out, without regard
 12611266                     for filing out the variable with zeros, etc. */
 12621267                 bccode();
<>1263 -                idname = pstk->in_id;
  1268+                spname = pstk->in_sym;
12641269                 p = buildtree( ASSIGN, buildtree( NAME, NIL, NIL ), p );
 12651270                 ecomp(p);
 12661271                 return;
     
 !
13071312         p->n_op = INIT;
 13081313 
 13091314         if( sz < SZINT ){ /* special case: bit fields, etc. */
<>1310 -                if( o != ICON || p->n_left->n_rval != NONAME )
  1315+                if (o != ICON || p->n_left->n_sp != NULL)
13111316                         uerror( "illegal initialization" );
 13121317                 else
 13131318                         incode( p->n_left, sz );
     
 !
13511356 
 13521357                         /* otherwise, put next element on the stack */
 13531358 
<>1354 -                        p = &stab[id];
 1355 -                        instk( id, p->stype, p->dimoff, p->sizoff, p->offset+pstk->in_off );
  1359+                        p = (struct symtab *)id;
  1360+                        instk(p, p->stype, p->dimoff, p->sizoff, p->soffset+pstk->in_off );
13561361                         return;
 13571362                         }
 13581363                 else if( ISARY(t) ){
     
 !
13621367                         /* put the new element onto the stack */
 13631368 
 13641369                         temp = pstk->in_sz;
<>1365 -                        instk( pstk->in_id, (TWORD)DECREF(pstk->in_t), pstk->in_d+1, pstk->in_s,
  1370+                        instk(pstk->in_sym, (TWORD)DECREF(pstk->in_t), pstk->in_d+1, pstk->in_s,
13661371                                 pstk->in_off+n*temp );
 13671372                         return;
 13681373                         }
     
 !
15011506 
 15021507         if (p->sclass != REGISTER) {
 15031508         /* in case we are allocating stack space for register arguments */
<>1504 -                if (p->offset == NOOFFSET)
 1505 -                        p->offset = off;
 1506 -                else if(off != p->offset)
  1509+                if (p->soffset == NOOFFSET)
  1510+                        p->soffset = off;
  1511+                else if(off != p->soffset)
15071512                         return(1);
 15081513         }
 15091514 
     
 !
15471552          * Set the initial pointer the same as the stack pointer.
 15481553          * Assume that the stack pointer is correctly aligned already.
 15491554          */
<>1550 -        p->offset = ptroff;
  1555+        p->soffset = ptroff;
15511556         p->stype = INCREF(p->stype);
<>1552 -        idname = p - stab;
  1557+        spname = p;
15531558         nn = buildtree(NAME, NIL, NIL);
 15541559 
 15551560         /*
     
 !
16621667         /* establish the field */
 16631668 
 16641669         if( new == 1 ) { /* previous definition */
<>1665 -                if( p->offset != strucoff || p->sclass != (FIELD|w) ) return(1);
  1670+                if( p->soffset != strucoff || p->sclass != (FIELD|w) ) return(1);
16661671                 }
<>1667 -        p->offset = strucoff;
  1672+        p->soffset = strucoff;
16681673         if( (offsz-strucoff) < w ) cerror("structure too large");
 16691674         strucoff += w;
 16701675         p->stype = type;
     
 !
17221727                 if (sz % sizeof (int))
 17231728                         sz += sizeof (int) - (sz % sizeof (int));
 17241729                 if (s->slevel > 1)
<>1725 -                        printf("        .lcomm  L%d,%d\n", s->offset, sz);
  1730+                        printf("        .lcomm  L%d,%d\n", s->soffset, sz);
17261731                 else
 17271732                         printf("        .lcomm  %s,%d\n", exname(s->sname), sz);
 17281733         } else if (class == EXTDEF)
 17291734 #endif
 17301735         {
 17311736                 /* simulate initialization by 0 */
<>1732 -                beginit(p->n_rval, class);
  1737+                beginit(p->n_sp, class);
17331738                 endinit();
 17341739         }
 17351740         if (commflag)
<>1736 -                commdec(p->n_rval > 20000 ? (struct symtab *)p->n_rval : &stab[p->n_rval]);
  1741+                commdec(p->n_sp);
17371742 }
 17381743 
 17391744 /*
     
 !
19321937         }
 19331938 
 19341939         p->n_rval = p->n_left->n_rval;
<> 1940+        p->n_sp = p->n_left->n_sp;
19351941         p->n_type = p->n_left->n_type;
 19361942 }
 19371943 
     
 !
21052111 static int nlabels;
 21062112 
 21072113 static int
<>2108 -lentry(int id)
  2114+lentry(char *name)
21092115 {
 21102116         int l;
 21112117 
<>2112 -        /* Free symtab entry if unused */
 2113 -        if (stab[id].stype == UNDEF)
 2114 -                stab[id].stype = TNULL;
 2115 -
21162118         for (l = 0; l < nlabels; l++)
<>2117 -                if (labelname[l] == stab[id].sname)
  2119+                if (labelname[l] == name)
21182120                         break;
 21192121 
 21202122         if (l == nlabels) {
     
 !
21242126                         return 0;
 21252127                 }
 21262128                 labelno[nlabels] = -getlab();
<>2127 -                labelname[nlabels] = stab[id].sname;
  2129+                labelname[nlabels] = name;
21282130                 l = nlabels++;
 21292131         }
 21302132         return l;
     
 !
21342136  * Generates a goto statement; sets up label number etc.
 21352137  */
 21362138 void
<>2137 -gotolabel(int id)
  2139+gotolabel(char *name)
21382140 {
<>2139 -        int l = lentry(id);
  2141+        int l = lentry(name);
21402142         branch(labelno[l] < 0 ? -labelno[l] : labelno[l]);
 21412143 }
 21422144 
 21432145 /*
 21442146  * Sets a label for gotos.
 21452147  */
 21462148 void
<>2147 -deflabel(int id)
  2149+deflabel(char *name)
21482150 {
<>2149 -        int l = lentry(id);
  2151+        int l = lentry(name);
21502152 
 21512153         if (labelno[l] > 0)
 21522154                 uerror("label '%s' redefined", labelname[l]);
     
 !
21552157         deflab(labelno[l]);
 21562158 }
 21572159 
<> 2160+#if 0
21582161 /*
 21592162  * locate a symbol table entry for
 21602163  * an occurrence of a nonunique structure member name
     
 !
21892192         *idindex = newsidx = i;
 21902193         return ( sp );
 21912194 }
<> 2195+#endif
21922196 
 21932197 /*
 21942198  * look up name: must agree with s w.r.t. STAG, SMOS and SHIDDEN
 21952199  */
<>2196 -int
  2200+struct symtab *
21972201 lookup(char *name, int s)
 21982202 {
 21992203         char *p, *q;
     
 !
22022206 
 22032207         /* compute initial hash index */
 22042208 # ifndef BUG1
<>2205 -        if( ddebug > 2 ){
 2206 -                printf( "lookup( %s, %d ), stwart=%d, instruct=%d\n", name, s, stwart, instruct );
 2207 -                }
  2209+        if (ddebug > 2)
  2210+                printf("lookup(%s, %d), stwart=%d, instruct=%d\n",
  2211+                    name, s, stwart, instruct);
22082212 # endif
 22092213 
 22102214         if (s == STAG)
<>2211 -                return (int)gettag(name);
  2215+                return gettag(name);
22122216 
<>2213 -        i = 0;
  2217+        if (s != 0 && s != SNOCREAT)
  2218+                cerror("lookup s %o", s);
  2219+
22142220         i = (int)name;
 22152221         i = i%SYMTSZ;
 22162222         sp = &stab[ii=i];
 22172223 
<>2218 -        for(;;){ /* look for name */
  2224+        for (;;) { /* look for name */
22192225 
<>2220 -                if( sp->stype == TNULL ){ /* empty slot */
  2226+                if (sp->stype == TNULL) { /* empty slot */
  2227+                        if (s & SNOCREAT)
  2228+                                return NULL;
  2229+//printf("creating %s (%d)\n", name, sp - stab);
22212230                         sp->sflags = s/* set STAG, SMOS if needed, turn off all others */
 22222231                         sp->sname = name;
 22232232                         sp->stype = UNDEF;
 22242233                         sp->sclass = SNULL;
 22252234                         sp->s_argn = 0;
<>2226 -                        return( i );
 2227 -                        }
 2228 -                if( (sp->sflags & (STAG|SMOS|SHIDDEN)) != s ) goto next;
  2235+                        return sp;
  2236+                }
  2237+                if ((sp->sflags & (STAG|SMOS|SHIDDEN)) != (s & ~SNOCREAT))
  2238+                        goto next;
22292239                 p = sp->sname;
 22302240                 q = name;
 22312241                 if (p == q)
<>2232 -                        return ( i );
 2233 -        next:
 2234 -                if( ++i >= SYMTSZ ){
  2242+                        return &stab[i];
  2243+next:
  2244+                if (++i >= SYMTSZ) {
22352245                         i = 0;
 22362246                         sp = stab;
<>2237 -                        }
 2238 -                else ++sp;
 2239 -                if( i == ii ) cerror( "symbol table full" );
 2240 -                }
  2247+                } else
  2248+                        ++sp;
  2249+                if (i == ii)
  2250+                        cerror("symbol table full");
22412251         }
<> 2252+}
22422253 
 22432254 #ifdef PCC_DEBUG
 22442255 /* if not debugging, checkst is a macro */
     
 !
22722283 {
 22732284         struct symtab *q;
 22742285 
<>2275 -        /* I'm not sure that this handles towers of several hidden definitions in all cases */
 2276 -        q = &stab[lookup( p->sname, p->sflags&(STAG|SMOS|SHIDDEN) )];
  2286+        q = lookup(p->sname, p->sflags&(STAG|SMOS|SHIDDEN));
22772287         /* make relook always point to either p or an empty cell */
<>2278 -        if( q->stype == UNDEF ){
  2288+        if (q->stype == UNDEF) {
22792289                 q->stype = TNULL;
 22802290                 return(q);
<>2281 -                }
 2282 -        while( q != p ){
 2283 -                if( q->stype == TNULL ) break;
 2284 -                if( ++q >= &stab[SYMTSZ] ) q=stab;
 2285 -                }
  2291+        }
  2292+        while (q != p) {
  2293+                if (q->stype == TNULL)
  2294+                        break;
  2295+                if (++q >= &stab[SYMTSZ])
  2296+                        q=stab;
  2297+        }
22862298         return(q);
 22872299 }
 22882300 
     
 !
23102322                                 uerror("%s undefined", p->sname);
 23112323                         } else
 23122324                                 aocode(p);
<> 2325+//printf("removing %s (%d)\n", p->sname, p - stab);
23132326 # ifndef BUG1
 23142327                         if( ddebug ){
 23152328                                 printf( "removing %s", p->sname );
     
 !
23352348                         if( ++q >= &stab[SYMTSZ] )q = stab;
 23362349                         if( q == p || q->stype == TNULL )break;
 23372350                         if( (r = relook(q)) != q ) {
<> 2351+//printf("moving %d to %d\n", q - stab, r - stab);
23382352                                 /* move q in schain list */
 23392353                                 t = &schain[(int)q->slevel];
 23402354                                 while( *t && *t != q )
     
 !
23612375         aoend();
 23622376 }
 23632377 
<>2364 -int
  2378+/*
  2379+ * Hide an earlier symbol p by creating a new one.
  2380+ * Return the new symbol.
  2381+ */
  2382+struct symtab *
23652383 hide(struct symtab *p)
 23662384 {
 23672385         struct symtab *q;
<>2368 -        for( q=p+1; ; ++q ){
 2369 -                if( q >= &stab[SYMTSZ] ) q = stab;
 2370 -                if( q == p ) cerror( "symbol table full" );
 2371 -                if( q->stype == TNULL ) break;
 2372 -                }
  2386+
  2387+        for (q = p + 1; ; ++q) {
  2388+                if (q >= &stab[SYMTSZ])
  2389+                        q = stab;
  2390+                if (q == p)
  2391+                        cerror( "symbol table full" );
  2392+                if (q->stype == TNULL)
  2393+                        break;
  2394+        }
23732395         *q = *p;
 23742396         p->sflags |= SHIDDEN;
 23752397         q->sflags = (p->sflags&(SMOS|STAG)) | SHIDES;
     
 !
23782400                 werror("%s redefinition hides earlier one", p->sname);
 23792401 #endif
 23802402 # ifndef BUG1
<>2381 -        if( ddebug ) printf( "  %d hidden in %d\n", p-stab, q-stab );
  2403+        if (ddebug)
  2404+                printf("        %p hidden by %p\n", p, q);
23822405 # endif
<>2383 -        return( idname = q-stab );
  2406+        return (spname = q );
23842407 }
 23852408 
 23862409 void
     
 !
24122435                 }
 24132436         cerror( "unhide fails" );
 24142437         }
<_ 2438+
  2439+struct symtab *
  2440+getsymtab(char *name, int flags)
  2441+{
  2442+        struct symtab *s;
  2443+
  2444+        s = permalloc(sizeof(struct symtab));
  2445+        s->sname = name;
  2446+        s->snext = NULL;
  2447+        s->stype = UNDEF;
  2448+        s->sclass = SNULL;
  2449+        s->sflags = flags;
  2450+        s->soffset = 0;
  2451+        s->s_argn = 0;
  2452+        return s;
  2453+}
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-02 01:34 +0200