Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20030611144225

Diff

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