Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20030617140914

Diff

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