Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20030612092208

Diff

Diff from 1.54 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;
ragge
1.54
82         int changed;    /* XXX 4.4 */
ragge
1.1
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
ragge
1.54
92 #ifdef PCC_DEBUG
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.54
99 #endif
ragge
1.1
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
ragge
1.54
109 #ifdef PCC_DEBUG
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.54
119 #endif
ragge
1.1
120
ragge
1.54
121         if (stp == FTN && p->sclass == SNULL)   /* XXX 4.4 */
ragge
1.33
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.54
139         if (stp == UNDEF|| stp == FARG/* XXX 4.4 */
ragge
1.33
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.54
152         changed = 0;    /* XXX 4.4 */
ragge
1.1
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) {
ragge
1.54
167                 FIXDEF(p);      /* XXX 4.4 */
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
ragge
1.54
179 #ifdef PCC_DEBUG
ragge
1.33
180         if (ddebug)
181                 printf("        previous class: %s\n"scnames(scl));
ragge
1.54
182 #endif
ragge
1.1
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
ragge
1.54
253         case MOE:       /* XXX 4.4 */
ragge
1.1
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
ragge
1.54
301 #ifdef PCC_DEBUG
ragge
1.33
302         if(ddebug)
303                 printf("        new entry made\n");
ragge
1.54
304 #endif
305         if (type == UNDEF)      /* XXX 4.4 */
ragge
1.33
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.54
343                         oalloc(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:
ragge
1.54
362                 oalloc(p, &strucoff);
363                 if (class == MOU)
364                         strucoff = 0;
ragge
1.46
365                 ssave(p);
ragge
1.1
366                 break;
367
368         case MOE:
ragge
1.33
369                 p->soffset = strucoff++;
ragge
1.46
370                 ssave(p);
ragge
1.1
371                 break;
372         case REGISTER:
ragge
1.33
373                 p->soffset = regvar--;
374                 if (blevel == 1)
375                         p->sflags |= SSET;
376                 if (regvar < minrvar)
377                         minrvar = regvar;
ragge
1.1
378                 break;
ragge
1.33
379         }
ragge
1.1
380
ragge
1.41
381         if (p->slevel > 0 && (p->sflags & SMASK) == SNORMAL)
382                 schedremove(p);
ragge
1.1
383
384         /* user-supplied routine to fix up new definitions */
385         FIXDEF(p);
386
ragge
1.54
387 #ifdef PCC_DEBUG
ragge
1.33
388         if (ddebug)
ragge
1.52
389                 printf"       sdf, ssue, offset: %p, %p, %d\n",
390                     p->sdfp->ssuep->soffset);
ragge
1.54
391 #endif
ragge
1.1
392
ragge
1.33
393 }
ragge
1.1
394
ragge
1.2
395 void
ragge
1.46
396 ssave(struct symtab *sym)
ragge
1.2
397 {
ragge
1.46
398         struct params *p;
399
400         p = tmpalloc(sizeof(struct params));
401         p->next = NULL;
402         p->sym = sym;
403
404         if (lparam == NULL) {
405                 p->prev = (struct params *)&lpole;
406                 lpole = p;
407         } else {
408                 lparam->next = p;
409                 p->prev = lparam;
ragge
1.2
410         }
ragge
1.46
411         lparam = p;
ragge
1.2
412 }
ragge
1.1
413
ragge
1.2
414 /*
415  * end of function
416  */
417 void
418 ftnend()
419 {
ragge
1.51
420         extern struct savbc *savbc;
421
ragge
1.33
422         if (retlab != NOLAB && nerrors == 0/* inside a real function */
ragge
1.1
423                 efcode();
ragge
1.33
424
ragge
1.1
425         checkst(0);
426         retstat = 0;
427         tcheck();
428         brklab = contlab = retlab = NOLAB;
429         flostat = 0;
ragge
1.51
430         if (nerrors == 0) {
431                 if (savbc != NULL)
432                         cerror("bcsave error");
ragge
1.46
433                 if (lparam != NULL)
434                         cerror("parameter reset error");
ragge
1.1
435                 ifswx != 0 ) cerror"switch error");
ragge
1.46
436         }
ragge
1.51
437         savbc = NULL;
ragge
1.46
438         lparam = NULL;
ragge
1.1
439         autooff = AUTOINIT;
440         minrvar = regvar = MAXRVAR;
441         reached = 1;
442         swx = 0;
443         swp = swtab;
ragge
1.37
444         tmpfree(); /* Release memory resources */
ragge
1.54
445         locctr(DATA);
ragge
1.2
446 }
ragge
1.1
447
ragge
1.2
448 void
449 dclargs()
450 {
ragge
1.45
451         struct params *a;
452         struct symtab *p, **parr;
ragge
1.2
453         NODE *q;
ragge
1.45
454         int i;
455
ragge
1.1
456         argoff = ARGINIT;
ragge
1.54
457 #ifdef PCC_DEBUG
ragge
1.12
458         if (ddebug > 2)
459                 printf("dclargs()\n");
ragge
1.54
460 #endif
ragge
1.45
461
ragge
1.47
462         /* Generate a list for bfcode() */
ragge
1.45
463         parr = tmpalloc(sizeof(struct symtab *) * nparams);
ragge
1.47
464         for (a = lparami = 0a != NULL && a != (struct params *)&lpole;
465             a = a->prev) {
466                 p = parr[i++] = a->sym;
ragge
1.54
467 #ifdef PCC_DEBUG
468                 if (ddebug > 2) {       /* XXX 4.4 */
ragge
1.45
469                         printf("\t%s (%p) ",p->snamep);
ragge
1.1
470                         tprint(p->stype);
471                         printf("\n");
ragge
1.12
472                 }
ragge
1.54
473 #endif
ragge
1.12
474                 if (p->stype == FARG) {
ragge
1.45
475                         q = block(FREENILNILINT0MKSUE(INT));
476                         q->n_sp = p;
ragge
1.12
477                         defid(qPARAM);
478                 }
ragge
1.54
479 /* XXX 4.4 */           FIXARG(p); /* local arg hook, eg. for sym. debugger */
ragge
1.12
480           /* always set aside space, even for register arguments */
481                 oalloc(p, &argoff);
482         }
ragge
1.1
483         cendarg();
ragge
1.54
484         locctr(PROG);
ragge
1.1
485         defalign(ALINT);
486         ftnno = getlab();
ragge
1.45
487         bfcode(parrnparams);
ragge
1.47
488         lparam = NULL;
ragge
1.45
489         nparams = 0;
ragge
1.2
490 }
ragge
1.1
491
ragge
1.21
492 /*
493  * reference to a structure or union, with no definition
494  */
ragge
1.1
495 NODE *
ragge
1.33
496 rstruct(char *tagint soru)
ragge
1.21
497 {
ragge
1.2
498         struct symtab *p;
499         NODE *q;
ragge
1.32
500
ragge
1.40
501         p = (struct symtab *)lookup(tagSTAGNAME);
ragge
1.21
502         switch (p->stype) {
ragge
1.1
503
504         case UNDEF:
505         def:
ragge
1.21
506                 q = block(FREENILNIL000);
ragge
1.33
507                 q->n_sp = p;
ragge
1.31
508                 q->n_type = (soru&INSTRUCT) ? STRTY :
ragge
1.21
509                     ((soru&INUNION) ? UNIONTY : ENUMTY);
510                 defid(q, (soru&INSTRUCT) ? STNAME :
511                     ((soru&INUNION) ? UNAME : ENAME));
ragge
1.1
512                 break;
513
514         case STRTY:
ragge
1.21
515                 if (soru & INSTRUCT)
516                         break;
ragge
1.1
517                 goto def;
518
519         case UNIONTY:
ragge
1.21
520                 if (soru & INUNION)
521                         break;
ragge
1.1
522                 goto def;
523
524         case ENUMTY:
ragge
1.21
525                 if (!(soru&(INUNION|INSTRUCT)))
526                         break;
ragge
1.1
527                 goto def;
528
ragge
1.21
529         }
ragge
1.43
530         q = mkty(p->stype0p->ssue);
531         q->n_sue = p->ssue;
532         return q;
ragge
1.21
533 }
ragge
1.1
534
ragge
1.2
535 void
ragge
1.33
536 moedef(char *name)
ragge
1.2
537 {
538         NODE *q;
ragge
1.1
539
ragge
1.33
540         q = block(FREENILNILMOETY00);
541         q->n_sp = lookup(name0);
542         defid(qMOE);
ragge
1.2
543 }
ragge
1.1
544
ragge
1.2
545 /*
546  * begining of structure or union declaration
547  */
ragge
1.43
548 struct rstack *
ragge
1.33
549 bstruct(char *nameint soru)
ragge
1.2
550 {
ragge
1.43
551         struct rstack *r;
ragge
1.33
552         struct symtab *s;
ragge
1.2
553         NODE *q;
ragge
1.1
554
ragge
1.33
555         if (name != NULL)
ragge
1.40
556                 s = lookup(nameSTAGNAME);
ragge
1.33
557         else
558                 s = NULL;
559
ragge
1.43
560         r = tmpalloc(sizeof(struct rstack));
561         r->rinstruct = instruct;
562         r->rclass = strunem;
563         r->rstrucoff = strucoff;
564
ragge
1.1
565         strucoff = 0;
566         instruct = soru;
ragge
1.21
567         q = block(FREENILNIL000);
ragge
1.33
568         q->n_sp = s;
ragge
1.21
569         if (instruct==INSTRUCT) {
ragge
1.18
570                 strunem = MOS;
ragge
1.31
571                 q->n_type = STRTY;
ragge
1.33
572                 if (s != NULL)
ragge
1.21
573                         defid(qSTNAME);
574         } else if(instruct == INUNION) {
ragge
1.18
575                 strunem = MOU;
ragge
1.31
576                 q->n_type = UNIONTY;
ragge
1.33
577                 if (s != NULL)
ragge
1.21
578                         defid(qUNAME);
579         } else { /* enum */
ragge
1.18
580                 strunem = MOE;
ragge
1.31
581                 q->n_type = ENUMTY;
ragge
1.33
582                 if (s != NULL)
ragge
1.21
583                         defid(qENAME);
584         }
ragge
1.43
585         r->rsym = q->n_sp;
ragge
1.46
586         r->rlparam = lparam;
ragge
1.33
587
ragge
1.43
588         return r;
ragge
1.2
589 }
ragge
1.1
590
ragge
1.18
591 /*
592  * Called after a struct is declared to restore the environment.
593  */
ragge
1.1
594 NODE *
ragge
1.43
595 dclstruct(struct rstack *r)
ragge
1.2
596 {
ragge
1.43
597         NODE *n;
ragge
1.50
598         struct params *l, *m;
ragge
1.43
599         struct suedef *sue;
ragge
1.2
600         struct symtab *p;
ragge
1.46
601         int alsasz;
ragge
1.2
602         TWORD temp;
ragge
1.50
603         int ihighlow;
ragge
1.1
604
ragge
1.43
605         if (r->rsym == NULL) {
606                 sue = permalloc(sizeof(struct suedef));
607                 sue->suesize = 0;
608                 sue->suealign = ALSTRUCT;
ragge
1.18
609         } else
ragge
1.43
610                 sue = r->rsym->ssue;
ragge
1.1
611
ragge
1.43
612 #ifdef PCC_DEBUG
613         if (ddebug)
ragge
1.46
614                 printf("dclstruct(%s)\n"r->rsym ? r->rsym->sname : "??");
ragge
1.43
615 #endif
ragge
1.1
616         temp = (instruct&INSTRUCT)?STRTY:((instruct&INUNION)?UNIONTY:ENUMTY);
ragge
1.43
617         instruct = r->rinstruct;
618         strunem = r->rclass;
ragge
1.1
619         al = ALSTRUCT;
620
621         high = low = 0;
622
ragge
1.46
623         if ((l = r->rlparam) == NULL)
624                 l = lpole;
625         else
626                 l = l->next;
627
ragge
1.50
628         /* memory for the element array must be allocated first */
629         for (m = li = 1m != NULLm = m->next)
630                 i++;
631         sue->suelem = permalloc(sizeof(struct symtab *) * i);
632
633         for (i = 0l != NULLl = l->next) {
634                 sue->suelem[i++] = p = l->sym;
635
ragge
1.46
636                 if (p == NULL)
ragge
1.43
637                         cerror("gummy structure member");
ragge
1.46
638                 if (temp == ENUMTY) {
639                         if (p->soffset < low)
640                                 low = p->soffset;
641                         if (p->soffset > high)
642                                 high = p->soffset;
ragge
1.43
643                         p->ssue = sue;
ragge
1.1
644                         continue;
ragge
1.46
645                 }
ragge
1.43
646                 sa = talign(p->stypep->ssue);
ragge
1.21
647                 if (p->sclass & FIELD) {
ragge
1.1
648                         sz = p->sclass&FLDSIZ;
ragge
1.21
649                 } else {
ragge
1.52
650                         sz = tsize(p->stypep->sdfp->ssue);
ragge
1.1
651                 }
ragge
1.21
652                 if (sz > strucoff)
653                         strucoff = sz;  /* for use with unions */
654                 /*
655                  * set al, the alignment, to the lcm of the alignments
656                  * of the members.
657                  */
658                 SETOFF(alsa);
659         }
ragge
1.50
660         sue->suelem[i] = NULL;
ragge
1.46
661         SETOFF(strucoffal);
ragge
1.1
662
ragge
1.43
663         if (temp == ENUMTY) {
ragge
1.2
664                 TWORD ty;
ragge
1.1
665
ragge
1.43
666 #ifdef ENUMSIZE
ragge
1.1
667                 ty = ENUMSIZE(high,low);
ragge
1.43
668 #else
669                 if ((char)high == high && (char)low == low)
670                         ty = ctype(CHAR);
671                 else if ((short)high == high && (short)low == low)
672                         ty = ctype(SHORT);
673                 else
674                         ty = ctype(INT);
ragge
1.1
675 #endif
ragge
1.43
676                 strucoff = tsize(ty0MKSUE(ty));
677                 sue->suealign = al = talign(tyMKSUE(ty));
ragge
1.21
678         }
ragge
1.1
679
ragge
1.43
680         sue->suesize = strucoff;
681         sue->suealign = al;
682
ragge
1.46
683 #ifdef PCC_DEBUG
ragge
1.21
684         if (ddebug>1) {
ragge
1.50
685                 int i;
686
ragge
1.46
687                 printf("\tsize %d align %d elem %p\n",
688                     sue->suesizesue->suealignsue->suelem);
ragge
1.50
689                 for (i = 0sue->suelem[i] != NULL; ++i) {
690                         printf("\tmember %s(%p)\n",
691                             sue->suelem[i]->snamesue->suelem[i]);
ragge
1.1
692                 }
ragge
1.21
693         }
ragge
1.43
694 #endif
ragge
1.1
695
ragge
1.43
696         strucoff = r->rstrucoff;
ragge
1.46
697         if ((lparam = r->rlparam) != NULL)
698                 lparam->next = NULL;
699         n = mkty(temp0sue);
ragge
1.43
700         return n;
ragge
1.21
701 }
ragge
1.1
702
ragge
1.2
703 /*
704  * error printing routine in parser
705  */
706 void yyerror(char *s);
707 void
708 yyerror(char *s)
709 {
710         uerror(s);
711 }
712
713 void yyaccpt(void);
714 void
715 yyaccpt(void)
716 {
ragge
1.1
717         ftnend();
ragge
1.2
718 }
ragge
1.1
719
ragge
1.54
720 void    /* XXX 4.4  hela funktionen */
ragge
1.33
721 ftnarg(char *name)
ragge
1.2
722 {
ragge
1.33
723         struct symtab *s = lookup(name0);
ragge
1.1
724
ragge
1.41
725         blevel = 1/* Always */
726
ragge
1.33
727         switch (s->stype) {
ragge
1.1
728         case UNDEF:
729                 /* this parameter, entered at scan */
730                 break;
731         case FARG:
ragge
1.33
732                 uerror("redeclaration of formal parameter, %s"s->sname);
ragge
1.1
733                 /* fall thru */
734         case FTN:
735                 /* the name of this function matches parm */
736                 /* fall thru */
737         default:
ragge
1.33
738                 s = hide(s);
ragge
1.1
739                 break;
740         case TNULL:
741                 /* unused entry, fill it */
742                 ;
ragge
1.33
743         }
744         s->stype = FARG;
745         s->sclass = PARAM;
ragge
1.45
746
ragge
1.47
747         ssave(s);
ragge
1.45
748         nparams++;
ragge
1.2
749 }
ragge
1.1
750
ragge
1.2
751 /*
752  * compute the alignment of an object with type ty, sizeoff index s
753  */
754 int
ragge
1.43
755 talign(unsigned int tystruct suedef *sue)
ragge
1.2
756 {
757         int i;
ragge
1.1
758
ragge
1.43
759         if(sue == NULL && ty!=INT && ty!=CHAR && ty!=SHORT &&
760             ty!=UNSIGNED && ty!=UCHAR && ty!=USHORT) {
761                 return(fldal(ty));
762         }
ragge
1.1
763
764         fori=0i<=(SZINT-BTSHIFT-1); i+=TSHIFT ){
765                 switch( (ty>>i)&TMASK ){
766
767                 case FTN:
ragge
1.54
768                         cerror("compiler takes alignment of function");
ragge
1.1
769                 case PTR:
ragge
1.54
770                         return(ALPOINT);
ragge
1.1
771                 case ARY:
772                         continue;
773                 case 0:
774                         break;
775                         }
776                 }
777
778         switchBTYPE(ty) ){
779
780         case UNIONTY:
781         case ENUMTY:
782         case STRTY:
ragge
1.43
783                 return((unsigned int)sue->suealign);
ragge
1.1
784         case CHAR:
785         case UCHAR:
ragge
1.9
786                 return (ALCHAR);
ragge
1.1
787         case FLOAT:
ragge
1.9
788                 return (ALFLOAT);
ragge
1.1
789         case DOUBLE:
ragge
1.9
790                 return (ALDOUBLE);
791         case LONGLONG:
792         case ULONGLONG:
793                 return (ALLONGLONG);
ragge
1.1
794         case LONG:
795         case ULONG:
ragge
1.9
796                 return (ALLONG);
ragge
1.1
797         case SHORT:
798         case USHORT:
ragge
1.9
799                 return (ALSHORT);
ragge
1.1
800         default:
ragge
1.9
801                 return (ALINT);
ragge
1.1
802         }
ragge
1.43
803 }
ragge
1.1
804
ragge
1.43
805 /* compute the size associated with type ty,
806  *  dimoff d, and sizoff s */
807 /* BETTER NOT BE CALLED WHEN t, d, and s REFER TO A BIT FIELD... */
ragge
1.1
808 OFFSZ
ragge
1.52
809 tsize(TWORD tyunion dimfun *dstruct suedef *sue)
ragge
1.43
810 {
ragge
1.1
811
812         int i;
813         OFFSZ mult;
814
815         mult = 1;
816
817         fori=0i<=(SZINT-BTSHIFT-1); i+=TSHIFT ){
818                 switch( (ty>>i)&TMASK ){
819
820                 case FTN:
ragge
1.54
821                         cerror"compiler takes size of function");
ragge
1.1