Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20030610142855

Diff

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