Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20030619161753

Diff

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