Quick Search:

Mode

Context

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

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.193
 
1.194
 
MAIN:ragge:20080202162750
 
pftn.c
_>7777 int symtabcnt, suedefcnt;       /* statistics */
 7878 int autooff,            /* the next unused automatic offset */
 7979     maxautooff,         /* highest used automatic offset in function */
<>80 -    argoff,             /* the next unused argument offset */
 81 -    strucoff;           /* the next structure offset position */
  80+    argoff;             /* the next unused argument offset */
8281 int retlab = NOLAB;     /* return label for subroutine */
 8382 int brklab;
 8483 int contlab;
 8584 int flostat;
<>86 -int instruct, blevel;
  85+int blevel;
8786 int reached, prolab;
 8887 
 8988 struct params;
     
 !
9695 /*
 9796  * Linked list stack while reading in structs.
 9897  */
<>99 -static struct rstack {
  98+struct rstack {
10099         struct  rstack *rnext;
<>101 -        int     rinstruct;
 102 -        int     rstrucoff;
 103 -        struct  params *rlparam;
  100+        int     rsou;
  101+        int     rstr;
104102         struct  symtab *rsym;
<> 103+        struct  symtab *rb;
105104 } *rpole;
 106105 
 107106 /*
     
 !
362361         /* allocate offsets */
 363362         if (class&FIELD) {
 364363                 (void) falloc(p, class&FLDSIZ, 0, NIL);  /* new entry */
<>365 -                ssave(p);
366364         } else switch (class) {
 367365 
 368366         case REGISTER:
     
 !
394392 
 395393         case MOU:
 396394         case MOS:
<>397 -                oalloc(p, &strucoff);
  395+                oalloc(p, &rpole->rstr);
398396                 if (class == MOU)
<>399 -                        strucoff = 0;
 400 -                ssave(p);
  397+                        rpole->rstr = 0;
401398                 break;
 402399         }
 403400 
     
 !
567564                 /* New tag */
 568565                 sp->ssue = permalloc(sizeof(struct suedef));
 569566                 sp->ssue->suesize = 0;
<>570 -                sp->ssue->suelem = NULL;
 571 -                sp->ssue->suealign = ALSTRUCT;
  567+                sp->ssue->sylnk = NULL;
  568+                sp->ssue->suealign = 0;
572569                 sp->sclass = class;
<> 570+                if (class == STNAME)
  571+                        sp->stype = STRTY;
  572+                else if (class == UNAME)
  573+                        sp->stype = UNIONTY;
573574         } else if (sp->sclass != class) {
 574575                 /* redeclaration of tag */
 575576                 uerror("tag %s redeclared", name);
     
 !
584585 rstruct(char *tag, int soru)
 585586 {
 586587         struct symtab *sp;
<>587 -        TWORD t;
588588 
 589589         sp = deftag(tag, soru);
<>590 -        t = sp->stype != UNDEF ? sp->stype : soru == STNAME ? STRTY : UNIONTY;
 591 -        return mkty(t, 0, sp->ssue);
  590+        return mkty(sp->stype, 0, sp->ssue);
592591 }
 593592 
 594593 static int enumlow, enumhigh;
     
 !
694693 
 695694         if (name != NULL) {
 696695                 sp = deftag(name, soru);
<>697 -                if (sp->stype != UNDEF)
  696+                if (sp->ssue->suealign != 0)
698697                         uerror("%s redeclared", name);
<> 698+                sp->ssue->suealign = ALSTRUCT;
699699         } else
 700700                 sp = NULL;
 701701 
<>702 -
703702         r = tmpalloc(sizeof(struct rstack));
<>704 -        r->rinstruct = instruct;
 705 -        r->rstrucoff = strucoff;
  703+        r->rsou = soru;
  704+        r->rstr = 0;
706705         r->rsym = sp;
<> 706+        r->rb = NULL;
707707         r->rnext = rpole;
 708708         rpole = r;
 709709 
<>710 -        strucoff = 0;
 711 -        instruct = soru;
 712 -        if ((r->rlparam = lparam) == NULL)
 713 -                lpole = NULL;
 714 -
715710         return r;
 716711 }
 717712 
     
 !
722717 dclstruct(struct rstack *r)
 723718 {
 724719         NODE *n;
<>725 -        struct params *l, *m;
726720         struct suedef *sue;
<>727 -        struct symtab *p;
  721+        struct symtab *sp;
728722         int al, sa, sz, coff;
 729723         TWORD temp;
<>730 -        int i, high, low;
731724 
 732725         if (r->rsym == NULL) {
 733726                 sue = permalloc(sizeof(struct suedef));
     
 !
736729                 sue->suealign = ALSTRUCT;
 737730         } else
 738731                 sue = r->rsym->ssue;
<> 732+        if (sue->suealign == 0/* suealign == 0 is undeclared struct */
  733+                sue->suealign = ALSTRUCT;
739734 
 740735 #ifdef PCC_DEBUG
 741736         if (ddebug)
 742737                 printf("dclstruct(%s)\n", r->rsym ? r->rsym->sname : "??");
 743738 #endif
<>744 -        temp = instruct == STNAME ? STRTY : instruct == UNAME ? UNIONTY : 0;
 745 -        instruct = r->rinstruct;
  739+        temp = r->rsou == STNAME ? STRTY : UNIONTY;
746740         al = ALSTRUCT;
 747741 
<>748 -        high = low = 0;
 749 -
 750 -        if ((l = r->rlparam) == NULL)
 751 -                l = lpole;
 752 -        else
 753 -                l = l->next;
 754 -
 755 -        /* memory for the element array must be allocated first */
 756 -        for (m = l, i = 1; m != NULL; m = m->next)
 757 -                i++;
 758 -        sue->suelem = permalloc(sizeof(struct symtab *) * i);
 759 -
760742         coff = 0;
 761743         if (pragma_packed || pragma_aligned)
<>762 -                strucoff = 0; /* must recount it */
  744+                rpole->rstr = 0; /* must recount it */
763745 
<>764 -        for (i = 0; l != NULL; l = l->next) {
 765 -                sue->suelem[i++] = p = l->sym;
 766 -
 767 -                if (p == NULL)
 768 -                        cerror("gummy structure member");
 769 -                sa = talign(p->stype, p->ssue);
 770 -                if (p->sclass & FIELD)
 771 -                        sz = p->sclass&FLDSIZ;
  746+        sue->sylnk = r->rb;
  747+        for (sp = r->rb; sp; sp = sp->snext) {
  748+                sa = talign(sp->stype, sp->ssue);
  749+                if (sp->sclass & FIELD)
  750+                        sz = sp->sclass&FLDSIZ;
772751                 else
<>773 -                        sz = tsize(p->stype, p->sdf, p->ssue);
  752+                        sz = tsize(sp->stype, sp->sdf, sp->ssue);
774753 
 775754                 if (pragma_packed || pragma_aligned) {
 776755                         /* XXX check pack/align sizes */
<>777 -                        p->soffset = coff;
  756+                        sp->soffset = coff;
778757                         if (pragma_aligned)
 779758                                 coff += ALLDOUBLE;
 780759                         else
 781760                                 coff += sz;
<>782 -                        strucoff = coff;
  761+                        rpole->rstr = coff;
783762                 }
 784763 
<>785 -                if (sz > strucoff)
 786 -                        strucoff = sz/* for use with unions */
  764+                if (sz > rpole->rstr)
  765+                        rpole->rstr = sz/* for use with unions */
787766                 /*
 788767                  * set al, the alignment, to the lcm of the alignments
 789768                  * of the members.
 790769                  */
 791770                 SETOFF(al, sa);
 792771         }
<>793 -        sue->suelem[i] = NULL;
 794 -        SETOFF(strucoff, al);
  772+        SETOFF(rpole->rstr, al);
795773 
<>796 -        sue->suesize = strucoff;
  774+        sue->suesize = rpole->rstr;
797775         sue->suealign = al;
 798776 
 799777         pragma_packed = pragma_aligned = 0;
     
 !
805783 
 806784 #ifdef PCC_DEBUG
 807785         if (ddebug>1) {
<>808 -                int i;
 809 -
 810 -                printf("\tsize %d align %d elem %p\n",
 811 -                    sue->suesize, sue->suealign, sue->suelem);
 812 -                for (i = 0; sue->suelem[i] != NULL; ++i) {
 813 -                        printf("\tmember %s(%p)\n",
 814 -                            sue->suelem[i]->sname, sue->suelem[i]);
  786+                printf("\tsize %d align %d link %p\n",
  787+                    sue->suesize, sue->suealign, sue->sylnk);
  788+                for (sp = sue->sylnk; sp != NULL; sp = sp->snext) {
  789+                        printf("\tmember %s(%p)\n", sp->sname, sp);
815790                 }
 816791         }
 817792 #endif
 818793 
<>819 -        strucoff = r->rstrucoff;
 820 -        if ((lparam = r->rlparam) != NULL)
 821 -                lparam->next = NULL;
 822 -        else
 823 -                lpole = NULL;
824794         rpole = r->rnext;
 825795         n = mkty(temp, 0, sue);
 826796         return n;
     
 !
832802 void
 833803 soumemb(NODE *n, char *name, int class)
 834804 {
<>835 -        struct params *l;
  805+        struct symtab *sp, *lsp;
836806  
<>837 -        if (rpole == NULL || !instruct)
  807+        if (rpole == NULL)
838808                 cerror("soumemb");
<>839 -        if ((l = rpole->rlparam) == NULL)
 840 -                l = lpole;
 841 -        else
 842 -                l = l->next;
843809  
<>844 -        for (; l != NULL; l = l->next) {
 845 -                if (l->sym->sname == name) {
  810+        lsp = NULL;
  811+        for (sp = rpole->rb; sp != NULL; lsp = sp, sp = sp->snext)
  812+                if (sp->sname == name)
846813                         uerror("redeclaration of %s", name);
<>847 -                        return;
 848 -                }
 849 -        }
 850 -        n->n_sp = getsymtab(name, SMOSNAME);
  814+
  815+        sp = getsymtab(name, SMOSNAME);
  816+        if (rpole->rb == NULL)
  817+                rpole->rb = sp;
  818+        else
  819+                lsp->snext = sp;
  820+        n->n_sp = sp;
851821         defid(n, class);
 852822 }
 853823  
     
 !
1021991                         return(SZINT);
 1022992                 }
 1023993         } else {
<>1024 -                if (sue->suelem == NULL)
  994+                if (sue->suealign == 0)
1025995                         uerror("unknown structure/union/enum");
 1026996         }
 1027997 
     
 !
13031273                 }
 13041274 
 13051275         if( w == 0 ){ /* align only */
<>1306 -                SETOFF( strucoff, al );
  1276+                SETOFF( rpole->rstr, al );
13071277                 if( new >= 0 ) uerror( "zero size field");
 13081278                 return(0);
 13091279                 }
 13101280 
<>1311 -        if( strucoff%al + w > sz ) SETOFF( strucoff, al );
  1281+        if( rpole->rstr%al + w > sz ) SETOFF( rpole->rstr, al );
13121282         if( new < 0 ) {
<>1313 -                strucoff += w/* we know it will fit */
  1283+                rpole->rstr += w/* we know it will fit */
13141284                 return(0);
 13151285                 }
 13161286 
 13171287         /* establish the field */
 13181288 
 13191289         if( new == 1 ) { /* previous definition */
<>1320 -                if( p->soffset != strucoff || p->sclass != (FIELD|w) ) return(1);
  1290+                if( p->soffset != rpole->rstr || p->sclass != (FIELD|w) ) return(1);
13211291                 }
<>1322 -        p->soffset = strucoff;
 1323 -        strucoff += w;
  1292+        p->soffset = rpole->rstr;
  1293+        rpole->rstr += w;
13241294         p->stype = type;
 13251295         fldty( p );
 13261296         return(0);
     
 !
13421312         if (class == SNULL) {
 13431313                 if (blevel > 1)
 13441314                         class = AUTO;
<>1345 -                else if (blevel != 0 || instruct)
  1315+                else if (blevel != 0 || rpole)
13461316                         cerror( "nidcl error" );
 13471317                 else /* blevel = 0 */
 13481318                         commflag = 1, class = EXTERN;
     
 !
14581428         type = class = qual = sig = uns = 0;
 14591429         saved = NIL;
 14601430 
<>1461 -        if (instruct != 0)
 1462 -                class = instruct == STNAME ? MOS : MOU;
  1431+        if (rpole != NULL)
  1432+                class = rpole->rsou == STNAME ? MOS : MOU;
14631433 
 14641434         for (q = p; p; p = p->n_left) {
 14651435                 switch (p->n_op) {
     
 !
23362306                 }
 23372307 
 23382308         /* detect function arguments, watching out for structure declarations */
<>2339 -        if (instruct && ISFTN(type)) {
  2309+        if (rpole && ISFTN(type)) {
23402310                 uerror("function illegal in structure or union");
 23412311                 type = INCREF(type);
 23422312         }
     
 !
23642334 {
 23652335         /* first, fix null class */
 23662336         if (class == SNULL) {
<>2367 -                if (instruct == STNAME)
 2368 -                        class = MOS;
 2369 -                else if (instruct == UNAME)
 2370 -                        class = MOU;
  2337+                if (rpole)
  2338+                        class = rpole->rsou == STNAME ? MOS : MOU;
23712339                 else if (blevel == 0)
 23722340                         class = EXTDEF;
 23732341                 else
     
 !
23942362                 }
 23952363 
 23962364         if (class & FIELD) {
<>2397 -                if (instruct != STNAME)
  2365+                if (rpole && rpole->rsou != STNAME)
23982366                         uerror("illegal use of field");
 23992367                 return(class);
 24002368         }
 24012369 
 24022370         switch (class) {
 24032371 
<> 2372+        case MOS:
24042373         case MOU:
<>2405 -                if (instruct != UNAME)
 2406 -                        uerror("illegal MOU class");
  2374+                if (rpole == NULL)
  2375+                        uerror("illegal member class");
24072376                 return(class);
 24082377 
<>2409 -        case MOS:
 2410 -                if (instruct != STNAME)
 2411 -                        uerror("illegal MOS class");
 2412 -                return(class);
 2413 -
24142378         case REGISTER:
 24152379                 if (blevel == 0)
 24162380                         uerror("illegal register declaration");
     
 !
25052469         return s;
 25062470 }
 25072471 
<> 2472+int
  2473+fldchk(int sz)
  2474+{
  2475+        if (rpole->rsou != STNAME)
  2476+                uerror("field outside of structure");
  2477+        if (sz < 0 || sz >= FIELD) {
  2478+                uerror("illegal field size");
  2479+                return 1;
  2480+        }
  2481+        return 0;
  2482+}
  2483+
<_25082484 #ifdef PCC_DEBUG
 25092485 static char *
 25102486 ccnames[] = { /* names of storage classes */
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-08-22 17:43 +0200