Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20030619223001

Diff

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