Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20030619140917

Diff

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