Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20030604193605

Diff

Diff from 1.33 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/pcc/pcc/cc/ccom/pftn.c

Annotated File View

ragge
1.2
1 #if 0
ragge
1.1
2 static char *sccsid ="@(#)pftn.c        1.29 (Berkeley) 6/18/90";
ragge
1.2
3 #endif
ragge
1.1
4
5 # include "pass1.h"
6
ragge
1.25
7 # include <stdlib.h>
8
ragge
1.1
9 unsigned int offsz;
10
11 struct symtab *schain[MAXSCOPES];       /* sym chains for clearst */
ragge
1.33
12 struct symtab *spname;
13 struct symtab *cftnsp;
ragge
1.1
14 int chaintop;                           /* highest active entry */
ragge
1.18
15 static int strunem;                     /* currently parsed member */
ragge
1.1
16
17 struct instk {
18         int in_sz;   /* size of array element */
19         int in_x;    /* current index for structure member in structure initializations */
20         int in_n;    /* number of initializations seen */
21         int in_s;    /* sizoff */
22         int in_d;    /* dimoff */
23         TWORD in_t;    /* type */
ragge
1.33
24         struct symtab *in_sym;   /* stab index */
ragge
1.1
25         int in_fl;   /* flag which says if this level is controlled by {} */
26         OFFSZ in_off;  /* offset of the beginning of this level */
ragge
1.2
27 instack[10], *pstk;
ragge
1.1
28
ragge
1.2
29 /* defines used for getting things off of the initialization stack */
ragge
1.1
30
ragge
1.30
31 static NODE *arrstk[10];
32 static int arrstkp;
ragge
1.1
33
ragge
1.2
34 struct symtab *relook(struct symtab *);
35 struct symtab * mknonuniq(int *);
36 void fixtype(NODE *pint class);
37 int fixclass(int classTWORD type);
38 int falloc(struct symtab *pint wint newNODE *pty);
39 void psave(int);
40 int oalloc(struct symtab *pint *poff);
ragge
1.30
41 static void dynalloc(struct symtab *pint *poff);
ragge
1.2
42 void inforce(OFFSZ n);
43 void vfdalign(int n);
ragge
1.33
44 static void instk(struct symtab *pTWORD tint dint sOFFSZ off);
45 static struct symtab *hide(struct symtab *p);
ragge
1.2
46 void gotscal(void);
ragge
1.1
47
48 int ddebug = 0;
49
ragge
1.32
50 /* XXX - temporary while removing symtab array */
51 #define MAXTAGS 1000
52 struct symtab *strtags[MAXTAGS];
53 int curtag;
54 struct symtab * gettag(char *name);
55
56 struct symtab *
57 gettag(char *name)
58 {
59         int i;
60
61         for (i = 0i < curtagi++)
62                 if (strtags[i]->sname == name)
63                         return strtags[i];
64         if (curtag == MAXTAGS)
65                 cerror("too many tags (%d)"curtag);
ragge
1.33
66         strtags[curtag++] = getsymtab(nameSTAG);
ragge
1.32
67         return strtags[i];
68 }
69 /* end temporary */
70
ragge
1.2
71 void
72 defid(NODE *qint class)
73 {
74         struct symtab *p;
75         TWORD type;
ragge
1.1
76         TWORD stp;
ragge
1.2
77         int scl;
ragge
1.1
78         int dsymddef;
79         int slevtemp;
80         int changed;
81
ragge
1.32
82         if (q == NIL)
83                 return;  /* an error was detected */
ragge
1.1
84
ragge
1.32
85         if (q < node || q >= &node[TREESZ])
86                 cerror("defid call");
ragge
1.1
87
ragge
1.33
88         p = q->n_sp;
ragge
1.1
89
90 # ifndef BUG1
ragge
1.4
91         if (ddebug) {
ragge
1.33
92                 printf("defid(%s (%p), "p->snamep);
ragge
1.31
93                 tprint(q->n_type);
ragge
1.4
94                 printf(", %s, (%d,%d)), level %d\n"scnames(class),
ragge
1.31
95                     q->n_cdimq->n_csizblevel);
ragge
1.4
96         }
ragge
1.1
97 # endif
98
ragge
1.33
99         fixtype(qclass);
ragge
1.1
100
ragge
1.31
101         type = q->n_type;
ragge
1.33
102         class = fixclass(classtype);
ragge
1.1
103
104         stp = p->stype;
105         slev = p->slevel;
106
107 # ifndef BUG1
ragge
1.4
108         if (ddebug) {
109                 printf("        modified to ");
110                 tprint(type);
111                 printf(", %s\n"scnames(class));
112                 printf("        previous def'n: ");
113                 tprint(stp);
114                 printf(", %s, (%d,%d)), level %d\n",
115                     scnames(p->sclass), p->dimoffp->sizoffslev);
116         }
ragge
1.1
117 # endif
118
ragge
1.33
119         if (stp == FTN && p->sclass == SNULL)
120                 goto enter;
121
ragge
1.4
122         if (blevel==1 && stp!=FARG)
ragge
1.33
123                 switch (class) {
ragge
1.1
124                 default:
ragge
1.4
125                         if (!(class&FIELD))
126                                 uerror"declared argument %s is missing",
127                                     p->sname );
ragge
1.1
128                 case MOS:
129                 case STNAME:
130                 case MOU:
131                 case UNAME:
132                 case MOE:
133                 case ENAME:
134                 case TYPEDEF:
135                         ;
ragge
1.4
136         }
ragge
1.33
137         if (stp == UNDEF|| stp == FARG)
138                 goto enter;
ragge
1.1
139
ragge
1.33
140         if (type != stp)
141                 goto mismatch;
142
143         if (blevel > slev && (class == AUTO || class == REGISTER))
ragge
1.1
144                 /* new scope */
145                 goto mismatch;
146
147         /* test (and possibly adjust) dimensions */
148         dsym = p->dimoff;
ragge
1.31
149         ddef = q->n_cdim;
ragge
1.1
150         changed = 0;
151         fortemp=typetemp&TMASKtemp = DECREF(temp) ){
152                 ifISARY(temp) ){
153                         if (dimtab[dsym] == 0) {
154                                 dimtab[dsym] = dimtab[ddef];
155                                 changed = 1;
156                                 }
157                         else if (dimtab[ddef]!=0&&dimtab[dsym]!=dimtab[ddef]) {
158                                 goto mismatch;
159                                 }
160                         ++dsym;
161                         ++ddef;
162                         }
163                 }
164
165         if (changed) {
166                 FIXDEF(p);
167                 }
168
169         /* check that redeclarations are to the same structure */
ragge
1.33
170         if ((temp == STRTY || temp == UNIONTY || temp == ENUMTY) &&
171             p->sizoff != q->n_csiz &&
172             class != STNAME && class != UNAME && class != ENAME) {
ragge
1.1
173                 goto mismatch;
ragge
1.33
174         }
ragge
1.1
175
ragge
1.33
176         scl = p->sclass;
ragge
1.1
177
178 # ifndef BUG1
ragge
1.33
179         if (ddebug)
180                 printf("        previous class: %s\n"scnames(scl));
ragge
1.1
181 # endif
182
ragge
1.33
183         if (class&FIELD) {
ragge
1.1
184                 /* redefinition */
ragge
1.33
185                 if (!falloc(pclass&FLDSIZ1NIL)) {
ragge
1.1
186                         /* successful allocation */
ragge
1.33
187                         psave((int)p); /* XXX cast */
ragge
1.1
188                         return;
ragge
1.33
189                 }
ragge
1.1
190                 /* blew it: resume at end of switch... */
ragge
1.33
191         } else switch(class) {
ragge
1.1
192
193         case EXTERN:
194                 switchscl ){
195                 case STATIC:
196                 case USTATIC:
197                         ifslev==0 ) return;
198                         break;
199                 case EXTDEF:
200                 case EXTERN:
201                 case FORTRAN:
202                 case UFORTRAN:
203                         return;
204                         }
205                 break;
206
207         case STATIC:
ragge
1.33
208                 if (scl==USTATIC || (scl==EXTERN && blevel==0)) {
ragge
1.1
209                         p->sclass = STATIC;
ragge
1.33
210                         if (ISFTN(type))
211                                 cftnsp = p;
ragge
1.1
212                         return;
ragge
1.33
213                 }
ragge
1.1
214                 break;
215
216         case USTATIC:
ragge
1.33
217                 if (scl==STATIC || scl==USTATIC)
218                         return;
ragge
1.1
219                 break;
220
221         case TYPEDEF:
ragge
1.33
222                 if (scl == class)
223                         return;
ragge
1.1
224                 break;
225
226         case UFORTRAN:
ragge
1.33
227                 if (scl == UFORTRAN || scl == FORTRAN)
228                         return;
ragge
1.1
229                 break;
230
231         case FORTRAN:
ragge
1.33
232                 if (scl == UFORTRAN) {
ragge
1.1
233                         p->sclass = FORTRAN;
ragge
1.33
234                         if (ISFTN(type))
235                                 cftnsp = p;
ragge
1.1
236                         return;
ragge
1.33
237                 }
ragge
1.1
238                 break;
239
240         case MOU:
241         case MOS:
ragge
1.33
242                 if (scl == class) {
243                         if (oalloc(p, &strucoff))
244                                 break;
245                         if (class == MOU)
246                                 strucoff = 0;
247                         psave((int)p); /* XXX cast */
ragge
1.1
248                         return;
ragge
1.33
249                 }
ragge
1.1
250                 break;
251
252         case MOE:
253                 break;
254
255         case EXTDEF:
ragge
1.10
256                 switch (scl) {
257                 case EXTERN:
ragge
1.1
258                         p->sclass = EXTDEF;
ragge
1.10
259                         if (ISFTN(type))
ragge
1.33
260                                 cftnsp = p;
ragge
1.1
261                         return;
ragge
1.10
262                 case USTATIC:
263                         p->sclass = STATIC;
264                         if (ISFTN(type))
ragge
1.33
265                                 cftnsp = p;
ragge
1.10
266                         return;
267                 }
ragge
1.1
268                 break;
269
270         case STNAME:
271         case UNAME:
272         case ENAME:
ragge
1.33
273                 if (scl != class)
274                         break;
275                 if (dimtab[p->sizoff] == 0)
276                         return;  /* previous entry just a mention */
ragge
1.1
277                 break;
278
279         case PARAM:
280         case AUTO:
281         case REGISTER:
282                 ;  /* mismatch.. */
ragge
1.33
283         }
ragge
1.1
284
285         mismatch:
286         /* allow nonunique structure/union member names */
287
288         ifclass==MOU || class==MOS || class & FIELD ){/* make a new entry */
ragge
1.33
289                 cerror("mismatch nonunique");
290 #if 0
ragge
1.2
291                 int *memp;
ragge
1.1
292                 p->sflags |= SNONUNIQ;  /* old entry is nonunique */
293                 /* determine if name has occurred in this structure/union */
ragge
1.32
294                 if (paramno > 0) {
295                         memp = &paramstk[paramno-1];
296                         for (; *memp>=0; --memp) {
297                                 char *cname, *oname;
298                                 struct symtab *w;
299
ragge
1.33
300                                 w = (struct symtab *)*memp;
ragge
1.32
301                                 if (w->sclass != STNAME && w->sclass != UNAME)
302                                         break;
303
304                                 if (w->sflags & SNONUNIQ ){
305                                         cname=p->sname;
306                                         oname=w->sname;
307                                         if (cname != onamegoto diff;
308                                         uerror("redeclaration of: %s",p->sname);
309                                         break;
310                                         diffcontinue;
ragge
1.1
311                                 }
312                         }
ragge
1.32
313                 }
ragge
1.1
314                 p = mknonuniq( &idp ); /* update p and idp to new entry */
315                 goto enter;
ragge
1.33
316 #endif
317         }
ragge
1.24
318         if (blevel > slev && class != EXTERN && class != FORTRAN &&
319             class != UFORTRAN) {
ragge
1.33
320                 p = hide(p);
321                 q->n_sp = p;
ragge
1.1
322                 goto enter;
ragge
1.24
323         }
ragge
1.33
324         uerror("redeclaration of %s"p->sname);
325         if (class==EXTDEF && ISFTN(type))
326                 cftnsp = p;
ragge
1.1
327         return;
328
329         enter:  /* make a new entry */
330
331 # ifndef BUG1
ragge
1.33
332         if(ddebug)
333                 printf("        new entry made\n");
ragge
1.1
334 # endif
ragge
1.33
335         if (type == UNDEF)
336                 uerror("void type for %s"p->sname);
ragge
1.1
337         p->stype = type;
338         p->sclass = class;
339         p->slevel = blevel;
ragge
1.33
340         p->soffset = NOOFFSET;
ragge
1.1
341         p->suse = lineno;
342         ifclass == STNAME || class == UNAME || class == ENAME ) {
343                 p->sizoff = curdim;
344                 dstash0 );  /* size */
345                 dstash( -1 ); /* index to members of str or union */
346                 dstashALSTRUCT );  /* alignment */
ragge
1.33
347                 dstash((int)p); /* dstash( idp ); XXX cast */
ragge
1.1
348                 }
349         else {
350                 switchBTYPE(type) ){
351                 case STRTY:
352                 case UNIONTY:
353                 case ENUMTY:
ragge
1.31
354                         p->sizoff = q->n_csiz;
ragge
1.1
355                         break;
356                 default:
357                         p->sizoff = BTYPE(type);
358                         }
359                 }
360
361         /* copy dimensions */
362
ragge
1.31
363         p->dimoff = q->n_cdim;
ragge
1.1
364
365         /* allocate offsets */
ragge
1.33
366         if (class&FIELD) {
367                 (voidfalloc(pclass&FLDSIZ0NIL);  /* new entry */
368                 psave((int)p); /* XXX cast */
369         } else switch (class) {
ragge
1.1
370
371         case AUTO:
ragge
1.30
372                 if (arrstkp)
373                         dynalloc(p, &autooff);
374                 else
ragge
1.33
375                         (voidoalloc(p, &autooff);
ragge
1.1
376                 break;
377         case STATIC:
378         case EXTDEF:
ragge
1.33
379                 p->soffset = getlab();
380                 if (class == STATIC && blevel > 0)
381                         p->sflags |= SLABEL;
382                 if (ISFTN(type))
383                         cftnsp = p;
ragge
1.1
384                 break;
385
386         case EXTERN:
387         case UFORTRAN:
388         case FORTRAN:
ragge
1.33
389                 p->soffset = getlab();
ragge
1.1
390                 p->slevel = 0;
391                 break;
392         case MOU:
393         case MOS:
394                 (voidoallocp, &strucoff );
395                 ifclass == MOU ) strucoff = 0;
ragge
1.33
396                 psave((int)p); /* XXX cast */
ragge
1.1
397                 break;
398
399         case MOE:
ragge
1.33
400                 p->soffset = strucoff++;
401                 psave((int)p); /* XXX cast */
ragge
1.1
402                 break;
403         case REGISTER:
ragge
1.33
404                 p->soffset = regvar--;
405                 if (blevel == 1)
406                         p->sflags |= SSET;
407                 if (regvar < minrvar)
408                         minrvar = regvar;
ragge
1.1
409                 break;
ragge
1.33
410         }
ragge
1.1
411
412         {
ragge
1.2
413                 int l = p->slevel;
ragge
1.1
414
415                 ifl >= MAXSCOPES )
416                         cerror"scopes nested too deep" );
417
418                 p->snext = schain[l];
419                 schain[l] = p;
420                 ifl >= chaintop )
421                         chaintop = l + 1;
ragge
1.33
422         }
ragge
1.1
423
424         /* user-supplied routine to fix up new definitions */
425
426         FIXDEF(p);
427
428 # ifndef BUG1
ragge
1.33
429         if (ddebug)
430                 printf"       dimoff, sizoff, offset: %d, %d, %d\n",
431                     p->dimoffp->sizoffp->soffset );
ragge
1.1
432 # endif
433
ragge
1.33
434 }
ragge
1.1
435
ragge
1.2
436 void
437 psave(int i)
438 {
ragge
1.1
439         ifparamno >= PARAMSZ ){
440                 cerror"parameter stack overflow");
ragge
1.2
441         }
ragge
1.1
442         paramstkparamno++ ] = i;
ragge
1.2
443 }
ragge
1.1
444
ragge
1.2
445 /*
446  * end of function
447  */
448 void
449 ftnend()
450 {
ragge
1.33
451         if (retlab != NOLAB && nerrors == 0/* inside a real function */
ragge
1.1
452                 efcode();
ragge
1.33
453
ragge
1.1
454         checkst(0);
455         retstat = 0;
456         tcheck();
457         brklab = contlab = retlab = NOLAB;
458         flostat = 0;
459         ifnerrors == 0 ){
460                 ifpsavbc != & asavbc[0] ) cerror("bcsave error");
461                 ifparamno != 0 ) cerror("parameter reset error");
462                 ifswx != 0 ) cerror"switch error");
463                 }
464         psavbc = &asavbc[0];
465         paramno = 0;
466         autooff = AUTOINIT;
467         minrvar = regvar = MAXRVAR;
468         reached = 1;
469         swx = 0;
470         swp = swtab;
471         (voidlocctr(DATA);
ragge
1.2
472 }
ragge
1.1
473
ragge
1.2
474 void
475 dclargs()
476 {
477         int ij;
478         struct symtab *p;
479         NODE *q;
ragge
1.1
480         argoff = ARGINIT;
ragge
1.12
481
ragge
1.1
482 # ifndef BUG1
ragge
1.12
483         if (ddebug > 2)
484                 printf("dclargs()\n");
ragge
1.1
485 # endif
ragge
1.12
486         for (i = 0i < paramno; ++i) {
487                 if ((j = paramstk[i]) < 0)
488                         continue;
ragge
1.33
489                 p = (struct symtab *)j;
ragge
1.1
490 # ifndef BUG1
ragge
1.12
491                 if (ddebug > 2) {
ragge
1.1
492                         printf("\t%s (%d) ",p->snamej);
493                         tprint(p->stype);
494                         printf("\n");
ragge
1.12
495                 }
ragge
1.1
496 # endif
ragge
1.12
497                 if (p->stype == FARG) {
ragge
1.1
498                         q = block(FREE,NIL,NIL,INT,0,INT);
ragge
1.31
499                         q->n_rval = j;
ragge
1.12
500                         defid(qPARAM);
501                 }
ragge
1.1
502                 FIXARG(p); /* local arg hook, eg. for sym. debugger */
ragge
1.12
503           /* always set aside space, even for register arguments */
504                 oalloc(p, &argoff);
505         }
ragge
1.1
506         cendarg();
507         (voidlocctr(PROG);
508         defalign(ALINT);
509         ftnno = getlab();
ragge
1.12
510         bfcode(paramstkparamno);
ragge
1.1
511         paramno = 0;
ragge
1.2
512 }
ragge
1.1
513
ragge
1.21
514 /*
515  * reference to a structure or union, with no definition
516  */
ragge
1.1
517 NODE *
ragge
1.33
518 rstruct(char *tagint soru)
ragge
1.21
519 {
ragge
1.2
520         struct symtab *p;
521         NODE *q;
ragge
1.32
522
ragge
1.33
523         p = (struct symtab *)lookup(tagSTAG);
ragge
1.21
524         switch (p->stype) {
ragge
1.1
525
526         case UNDEF:
527         def:
ragge
1.21
528                 q = block(FREENILNIL000);
ragge
1.33
529                 q->n_sp = p;
ragge
1.31
530                 q->n_type = (soru&INSTRUCT) ? STRTY :
ragge
1.21
531                     ((soru&INUNION) ? UNIONTY : ENUMTY);
532                 defid(q, (soru&INSTRUCT) ? STNAME :
533                     ((soru&INUNION) ? UNAME : ENAME));
ragge
1.1
534                 break;
535
536         case STRTY:
ragge
1.21
537                 if (soru & INSTRUCT)
538                         break;
ragge
1.1
539                 goto def;
540
541         case UNIONTY:
ragge
1.21
542                 if (soru & INUNION)
543                         break;
ragge
1.1
544                 goto def;
545
546         case ENUMTY:
ragge
1.21
547                 if (!(soru&(INUNION|INSTRUCT)))
548                         break;
ragge
1.1
549                 goto def;
550
ragge
1.21
551         }
ragge
1.1
552         stwart = instruct;
ragge
1.21
553         return(mkty(p->stype0p->sizoff));
554 }
ragge
1.1
555
ragge
1.2
556 void
ragge
1.33
557 moedef(char *name)
ragge
1.2
558 {
559         NODE *q;
ragge
1.1
560
ragge
1.33
561         q = block(FREENILNILMOETY00);
562         q->n_sp = lookup(name0);
563         defid(qMOE);
ragge
1.2
564 }
ragge
1.1
565
ragge
1.2
566 /*
567  * begining of structure or union declaration
568  */
569 int
ragge
1.33
570 bstruct(char *nameint soru)
ragge
1.2
571 {
ragge
1.33
572         struct symtab *s;
ragge
1.2
573         NODE *q;
ragge
1.1
574
ragge
1.33
575         if (name != NULL)
576                 s = lookup(nameSTAG);
577         else
578                 s = NULL;
579
ragge
1.18
580         psave(instruct);
581         psave(strunem);
582         psave(strucoff);
ragge
1.1
583         strucoff = 0;
584         instruct = soru;
ragge
1.21
585         q = block(FREENILNIL000);
ragge
1.33
586         q->n_sp = s;
ragge
1.21
587         if (instruct==INSTRUCT) {
ragge
1.18
588                 strunem = MOS;
ragge
1.31
589                 q->n_type = STRTY;
ragge
1.33
590                 if (s != NULL)
ragge
1.21
591                         defid(qSTNAME);
592         } else if(instruct == INUNION) {
ragge
1.18
593                 strunem = MOU;
ragge
1.31
594                 q->n_type = UNIONTY;
ragge
1.33
595                 if (s != NULL)
ragge
1.21
596                         defid(qUNAME);
597         } else { /* enum */
ragge
1.18
598                 strunem = MOE;
ragge
1.31
599                 q->n_type = ENUMTY;
ragge
1.33
600                 if (s != NULL)
ragge
1.21
601                         defid(qENAME);
602         }
ragge
1.33
603         psave((int)q->n_sp); /* XXX cast */
604
ragge
1.1
605         /* the "real" definition is where the members are seen */
ragge
1.33
606         if (s != NULL)
607                 s->suse = lineno;
ragge
1.21
608         return(paramno-4);
ragge
1.2
609 }
ragge
1.1
610
ragge
1.18
611 /*
612  * Called after a struct is declared to restore the environment.
613  */
ragge
1.1
614 NODE *
ragge
1.2
615 dclstruct(int oparam)
616 {
617         struct symtab *p;
618         int ialsajszszindex;
619         TWORD temp;
620         int highlow;
ragge
1.1
621
ragge
1.18
622         /*
623          * paramstk contains:
624          *      paramstk[oparam] = previous instruct
625          *      paramstk[oparam+1] = previous class
626          *      paramstk[oparam+2] = previous strucoff
627          *      paramstk[oparam+3] = structure name
628          *
629          *      paramstk[oparam+4, ...]  = member stab indices
630          */
ragge
1.1
631
632
ragge
1.33
633         if ((i = paramstk[oparam+3]) <= 0) {
ragge
1.1
634                 szindex = curdim;
ragge
1.18
635                 dstash(0);  /* size */
636                 dstash(-1);  /* index to member names */
637                 dstash(ALSTRUCT);  /* alignment */
638                 dstash(-lineno);        /* name of structure */
639         } else
ragge
1.32
640                 szindex = ((struct symtab *)i)->sizoff;
ragge
1.1
641
642 # ifndef BUG1
ragge
1.18
643         if (ddebug) {
644                 printf("dclstruct( %s ), szindex = %d\n",
ragge
1.33
645                     (i>0)? ((struct symtab *)i)->sname : "??"szindex);
ragge
1.18
646         }
ragge
1.1
647 # endif
648         temp = (instruct&INSTRUCT)?STRTY:((instruct&INUNION)?UNIONTY:ENUMTY);
ragge
1.18
649         stwart = instruct = paramstk[oparam];
650         strunem = paramstk[oparam+1];
651         dimtab[szindex+1] = curdim;
ragge
1.1
652         al = ALSTRUCT;
653
654         high = low = 0;
655
656         fori = oparam+4;  iparamno; ++i ){
657                 dstashj=paramstk[i] );
ragge
1.33
658                 ifj<0 /* || j>= SYMTSZ */ ) cerror"gummy structure member" ); /* XXX cast bad test */
659                 p = (struct symtab *)j/* XXX - cast */
ragge
1.1
660                 iftemp == ENUMTY ){
ragge
1.33
661                         ifp->soffset < low ) low = p->soffset;
662                         ifp->soffset > high ) high = p->soffset;
ragge
1.1
663                         p->sizoff = szindex;
664                         continue;
665                         }
666                 sa = talignp->stypep->sizoff );
ragge
1.21
667                 if (p->sclass & FIELD) {
ragge
1.1
668                         sz = p->sclass&FLDSIZ;
ragge
1.21
669                 } else {
670                         sz = tsize(p->stypep->dimoffp->sizoff);
671                 }
672 #if 0
673                 if (sz == 0) {
674                         werror("illegal zero sized structure member: %s"p->sname );
ragge
1.1
675                 }
ragge
1.21
676 #endif
677                 if (sz > strucoff)
678                         strucoff = sz;  /* for use with unions */
679                 /*
680                  * set al, the alignment, to the lcm of the alignments
681                  * of the members.
682                  */
683                 SETOFF(alsa);
684         }
685         dstash(-1);  /* endmarker */
ragge
1.1
686         SETOFFstrucoffal );
687
688         iftemp == ENUMTY ){
ragge
1.2
689                 TWORD ty;
ragge
1.1
690
691 # ifdef ENUMSIZE
692                 ty = ENUMSIZE(high,low);
693 # else
694                 if( (char)high == high && (char)low == low ) ty = ctypeCHAR );
695                 else if( (short)high == high && (short)low == low ) ty = ctypeSHORT );
696                 else ty = ctype(INT);
697 #endif
698                 strucoff = tsizety0, (int)ty );
699                 dimtabszindex+2 ] = al = talignty, (int)ty );
ragge
1.21
700         }
ragge
1.1
701
ragge
1.21
702 #if 0
703         if (strucoff == 0)
704                 uerror"zero sized structure" );
705 #endif
706         dimtab[szindex] = strucoff;
707         dimtab[szindex+2] = al;
708         dimtab[szindex+3] = paramstkoparam+3 ];  /* name index */
ragge
1.1
709
ragge
1.21
710         FIXSTRUCT(szindexoparam); /* local hook, eg. for sym debugger */
ragge
1.1
711 # ifndef BUG1
ragge
1.21
712         if (ddebug>1) {
713                 printf("\tdimtab[%d,%d,%d] = %d,%d,%d\n",
714                     szindex,szindex+1,szindex+2,
715                     dimtab[szindex],dimtab[szindex+1],dimtab[szindex+2] );
716                 for (i = dimtab[szindex+1]; dimtab[i] >= 0; ++i) {
717                         printf("\tmember %s(%d)\n",
ragge
1.33
718                             ((struct symtab *)dimtab[i])->snamedimtab[i]);
ragge
1.1
719                 }
ragge
1.21
720         }
ragge
1.1
721 # endif
722
723         strucoff = paramstkoparam+2 ];
724         paramno = oparam;
725
726         returnmktytemp0szindex ) );
ragge
1.21
727 }
ragge
1.1
728
ragge
1.2
729 /*
730  * error printing routine in parser
731  */
732 void yyerror(char *s);
733 void
734 yyerror(char *s)
735 {
736         uerror(s);
737 }
738
739 void yyaccpt(void);
740 void
741 yyaccpt(void)
742 {
ragge
1.1
743         ftnend();
ragge
1.2
744 }
ragge
1.1
745
ragge
1.2
746 void
ragge
1.33
747 ftnarg(char *name)
ragge
1.2
748 {
ragge
1.33
749         struct symtab *s = lookup(name0);
ragge
1.1
750
ragge
1.33
751         switch (s->stype) {
ragge
1.1
752         case UNDEF:
753                 /* this parameter, entered at scan */
754                 break;
755         case FARG:
ragge
1.33
756                 uerror("redeclaration of formal parameter, %s"s->sname);
ragge
1.1
757                 /* fall thru */
758         case FTN:
759                 /* the name of this function matches parm */
760                 /* fall thru */
761         default:
ragge
1.33
762                 s = hide(s);
ragge
1.1
763                 break;
764         case TNULL:
765                 /* unused entry, fill it */
766                 ;
ragge
1.33
767         }
768         s->stype = FARG;
769         s->sclass = PARAM;
770         psave((int)s);
ragge
1.2
771 }
ragge
1.1
772
ragge
1.2
773 /*
774  * compute the alignment of an object with type ty, sizeoff index s
775  */
776 int
777 talign(unsigned int tyint s)
778 {
779         int i;
ragge
1.1
780
781         ifs<0 && ty!=INT && ty!=CHAR && ty!=SHORT && ty!=UNSIGNED && ty!=UCHAR && ty!=USHORT 
782                                         ){
783                 returnfldalty ) );
784                 }
785
786         fori=0i<=(SZINT-BTSHIFT-1); i+=TSHIFT ){
787                 switch( (ty>>i)&TMASK ){
788
789                 case FTN:
790                         uerror"can't assign to function" );
791                         returnALCHAR );
792                 case PTR:
793                         returnALPOINT );
794                 case ARY:
795                         continue;
796                 case 0:
797                         break;
798                         }
799                 }
800
801         switchBTYPE(ty) ){
802
803         case UNIONTY:
804         case ENUMTY:
805         case STRTY:
806                 return( (unsigned intdimtabs+2 ] );
807         case CHAR:
808         case UCHAR:
ragge
1.9
809                 return (ALCHAR);
ragge
1.1
810         case FLOAT:
ragge
1.9
811                 return (ALFLOAT);
ragge
1.1
812         case DOUBLE:
ragge
1.9
813                 return (ALDOUBLE);
814         case LONGLONG:
815         case ULONGLONG:
816                 return (ALLONGLONG);
ragge
1.1
817         case LONG:
818         case ULONG:
ragge
1.9
819                 return (ALLONG);
ragge
1.1
820         case SHORT:
821         case USHORT:
ragge
1.9
822                 return (ALSHORT);
ragge
1.1
823         default:
ragge
1.9
824                 return (ALINT);
ragge
1.1
825                 }
826         }
827
828 OFFSZ
829 tsizetyds )  TWORD ty; {
830         /* compute the size associated with type ty,
831             dimoff d, and sizoff s */
832         /* BETTER NOT BE CALLED WHEN t, d, and s REFER TO A BIT FIELD... */
833
834         int i;
835         OFFSZ mult;
836
837         mult = 1;
838
839         fori=0i<=(SZINT-BTSHIFT-1); i+=TSHIFT ){
840                 switch( (ty>>i)&TMASK ){
841
842                 case FTN:
843                         /* cerror( "compiler takes size of function"); */
844                         uerror"can't take size of function" );
845                         returnSZCHAR );
846                 case PTR:
847                         returnSZPOINT * mult );
848                 case ARY:
849                         mult *= (unsigned intdimtabd++ ];
850                         continue;
851                 case 0:
852                         break;
853
854                         }
855                 }
856
ragge
1.21
857         if (ty != STRTY && ty != UNIONTY) {
858                 if (dimtab[s] == 0) {
859                         uerror("unknown size");
860                         return(SZINT);
861                 }
862         } else {
863                 if (dimtab[s+1] == -1)
864                         uerror("unknown structure/union");
865         }
866
ragge
1.1
867         return( (unsigned intdimtabs ] * mult );
ragge
1.21
868 }
ragge
1.1
869
ragge
1.2
870 /*
871  * force inoff to have the value n
872  */
873 void
874 inforce(OFFSZ n)
875 {
ragge
1.1
876         /* inoff is updated to have the value n */
877         OFFSZ wb;
ragge
1.2
878         int rest;
ragge
1.1
879         /* rest is used to do a lot of conversion to ints... */
880
881         ifinoff == n ) return;
ragge
1.20
882         if (inoff > n)
883                 cerror("initialization alignment error: inoff %lld n %lld",
884                     inoffn);
ragge
1.1
885
886         wb = inoff;
887         SETOFFwbSZINT );
888