Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20030615212153

Diff

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