Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20030610135719

Diff

Diff from 1.50 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.33
418         if (retlab != NOLAB && nerrors == 0/* inside a real function */
ragge
1.1
419                 efcode();
ragge
1.33
420
ragge
1.1
421         checkst(0);
422         retstat = 0;
423         tcheck();
424         brklab = contlab = retlab = NOLAB;
425         flostat = 0;
426         ifnerrors == 0 ){
427                 ifpsavbc != & asavbc[0] ) cerror("bcsave error");
ragge
1.46
428                 if (lparam != NULL)
429                         cerror("parameter reset error");
ragge
1.1
430                 ifswx != 0 ) cerror"switch error");
ragge
1.46
431         }
ragge
1.1
432         psavbc = &asavbc[0];
ragge
1.46
433         lparam = NULL;
ragge
1.1
434         autooff = AUTOINIT;
435         minrvar = regvar = MAXRVAR;
436         reached = 1;
437         swx = 0;
438         swp = swtab;
ragge
1.37
439         tmpfree(); /* Release memory resources */
ragge
1.1
440         (voidlocctr(DATA);
ragge
1.2
441 }
ragge
1.1
442
ragge
1.2
443 void
444 dclargs()
445 {
ragge
1.45
446         struct params *a;
447         struct symtab *p, **parr;
ragge
1.2
448         NODE *q;
ragge
1.45
449         int i;
450
ragge
1.1
451         argoff = ARGINIT;
452 # ifndef BUG1
ragge
1.12
453         if (ddebug > 2)
454                 printf("dclargs()\n");
ragge
1.1
455 # endif
ragge
1.45
456
ragge
1.47
457         /* Generate a list for bfcode() */
ragge
1.45
458         parr = tmpalloc(sizeof(struct symtab *) * nparams);
ragge
1.47
459         for (a = lparami = 0a != NULL && a != (struct params *)&lpole;
460             a = a->prev) {
461                 p = parr[i++] = a->sym;
ragge
1.1
462 # ifndef BUG1
ragge
1.12
463                 if (ddebug > 2) {
ragge
1.45
464                         printf("\t%s (%p) ",p->snamep);
ragge
1.1
465                         tprint(p->stype);
466                         printf("\n");
ragge
1.12
467                 }
ragge
1.1
468 # endif
ragge
1.12
469                 if (p->stype == FARG) {
ragge
1.45
470                         q = block(FREENILNILINT0MKSUE(INT));
471                         q->n_sp = p;
ragge
1.12
472                         defid(qPARAM);
473                 }
ragge
1.1
474                 FIXARG(p); /* local arg hook, eg. for sym. debugger */
ragge
1.12
475           /* always set aside space, even for register arguments */
476                 oalloc(p, &argoff);
477         }
ragge
1.1
478         cendarg();
479         (voidlocctr(PROG);
480         defalign(ALINT);
481         ftnno = getlab();
ragge
1.45
482         bfcode(parrnparams);
ragge
1.47
483         lparam = NULL;
ragge
1.45
484         nparams = 0;
ragge
1.2
485 }
ragge
1.1
486
ragge
1.21
487 /*
488  * reference to a structure or union, with no definition
489  */
ragge
1.1
490 NODE *
ragge
1.33
491 rstruct(char *tagint soru)
ragge
1.21
492 {
ragge
1.2
493         struct symtab *p;
494         NODE *q;
ragge
1.32
495
ragge
1.40
496         p = (struct symtab *)lookup(tagSTAGNAME);
ragge
1.21
497         switch (p->stype) {
ragge
1.1
498
499         case UNDEF:
500         def:
ragge
1.21
501                 q = block(FREENILNIL000);
ragge
1.33
502                 q->n_sp = p;
ragge
1.31
503                 q->n_type = (soru&INSTRUCT) ? STRTY :
ragge
1.21
504                     ((soru&INUNION) ? UNIONTY : ENUMTY);
505                 defid(q, (soru&INSTRUCT) ? STNAME :
506                     ((soru&INUNION) ? UNAME : ENAME));
ragge
1.1
507                 break;
508
509         case STRTY:
ragge
1.21
510                 if (soru & INSTRUCT)
511                         break;
ragge
1.1
512                 goto def;
513
514         case UNIONTY:
ragge
1.21
515                 if (soru & INUNION)
516                         break;
ragge
1.1
517                 goto def;
518
519         case ENUMTY:
ragge
1.21
520                 if (!(soru&(INUNION|INSTRUCT)))
521                         break;
ragge
1.1
522                 goto def;
523
ragge
1.21
524         }
ragge
1.43
525         q = mkty(p->stype0p->ssue);
526         q->n_sue = p->ssue;
527         return q;
ragge
1.21
528 }
ragge
1.1
529
ragge
1.2
530 void
ragge
1.33
531 moedef(char *name)
ragge
1.2
532 {
533         NODE *q;
ragge
1.1
534
ragge
1.33
535         q = block(FREENILNILMOETY00);
536         q->n_sp = lookup(name0);
537         defid(qMOE);
ragge
1.2
538 }
ragge
1.1
539
ragge
1.2
540 /*
541  * begining of structure or union declaration
542  */
ragge
1.43
543 struct rstack *
ragge
1.33
544 bstruct(char *nameint soru)
ragge
1.2
545 {
ragge
1.43
546         struct rstack *r;
ragge
1.33
547         struct symtab *s;
ragge
1.2
548         NODE *q;
ragge
1.1
549
ragge
1.33
550         if (name != NULL)
ragge
1.40
551                 s = lookup(nameSTAGNAME);
ragge
1.33
552         else
553                 s = NULL;
554
ragge
1.43
555         r = tmpalloc(sizeof(struct rstack));
556         r->rinstruct = instruct;
557         r->rclass = strunem;
558         r->rstrucoff = strucoff;
559
ragge
1.1
560         strucoff = 0;
561         instruct = soru;
ragge
1.21
562         q = block(FREENILNIL000);
ragge
1.33
563         q->n_sp = s;
ragge
1.21
564         if (instruct==INSTRUCT) {
ragge
1.18
565                 strunem = MOS;
ragge
1.31
566                 q->n_type = STRTY;
ragge
1.33
567                 if (s != NULL)
ragge
1.21
568                         defid(qSTNAME);
569         } else if(instruct == INUNION) {
ragge
1.18
570                 strunem = MOU;
ragge
1.31
571                 q->n_type = UNIONTY;
ragge
1.33
572                 if (s != NULL)
ragge
1.21
573                         defid(qUNAME);
574         } else { /* enum */
ragge
1.18
575                 strunem = MOE;
ragge
1.31
576                 q->n_type = ENUMTY;
ragge
1.33
577                 if (s != NULL)
ragge
1.21
578                         defid(qENAME);
579         }
ragge
1.43
580         r->rsym = q->n_sp;
ragge
1.46
581         r->rlparam = lparam;
ragge
1.33
582
ragge
1.1
583         /* the "real" definition is where the members are seen */
ragge
1.33
584         if (s != NULL)
585                 s->suse = lineno;
ragge
1.43
586         return r;
ragge
1.2
587 }
ragge
1.1
588
ragge
1.18
589 /*
590  * Called after a struct is declared to restore the environment.
591  */
ragge
1.1
592 NODE *
ragge
1.43
593 dclstruct(struct rstack *r)
ragge
1.2
594 {
ragge
1.43
595         NODE *n;
ragge
1.50
596         struct params *l, *m;
ragge
1.43
597         struct suedef *sue;
ragge
1.2
598         struct symtab *p;
ragge
1.46
599         int alsasz;
ragge
1.2
600         TWORD temp;
ragge
1.50
601         int ihighlow;
ragge
1.1
602
ragge
1.43
603         if (r->rsym == NULL) {
604                 sue = permalloc(sizeof(struct suedef));
605                 sue->suesize = 0;
606                 sue->suealign = ALSTRUCT;
ragge
1.18
607         } else
ragge
1.43
608                 sue = r->rsym->ssue;
ragge
1.1
609
ragge
1.43
610 #ifdef PCC_DEBUG
611         if (ddebug)
ragge
1.46
612                 printf("dclstruct(%s)\n"r->rsym ? r->rsym->sname : "??");
ragge
1.43
613 #endif
ragge
1.1
614         temp = (instruct&INSTRUCT)?STRTY:((instruct&INUNION)?UNIONTY:ENUMTY);
ragge
1.43
615         instruct = r->rinstruct;
616         strunem = r->rclass;
ragge
1.1
617         al = ALSTRUCT;
618
619         high = low = 0;
620
ragge
1.46
621         if ((l = r->rlparam) == NULL)
622                 l = lpole;
623         else
624                 l = l->next;
625
ragge
1.50
626         /* memory for the element array must be allocated first */
627         for (m = li = 1m != NULLm = m->next)
628                 i++;
629         sue->suelem = permalloc(sizeof(struct symtab *) * i);
630
631         for (i = 0l != NULLl = l->next) {
632                 sue->suelem[i++] = p = l->sym;
633
ragge
1.46
634                 if (p == NULL)
ragge
1.43
635                         cerror("gummy structure member");
ragge
1.46
636                 if (temp == ENUMTY) {
637                         if (p->soffset < low)
638                                 low = p->soffset;
639                         if (p->soffset > high)
640                                 high = p->soffset;
ragge
1.43
641                         p->ssue = sue;
ragge
1.1
642                         continue;
ragge
1.46
643                 }
ragge
1.43
644                 sa = talign(p->stypep->ssue);
ragge
1.21
645                 if (p->sclass & FIELD) {
ragge
1.1
646                         sz = p->sclass&FLDSIZ;
ragge
1.21
647                 } else {
ragge
1.50
648                         sz = tsize(p->stypep->sdimp->ssue);
ragge
1.1
649                 }
ragge
1.21
650                 if (sz > strucoff)
651                         strucoff = sz;  /* for use with unions */
652                 /*
653                  * set al, the alignment, to the lcm of the alignments
654                  * of the members.
655                  */
656                 SETOFF(alsa);
657         }
ragge
1.50
658         sue->suelem[i] = NULL;
ragge
1.46
659         SETOFF(strucoffal);
ragge
1.1
660
ragge
1.43
661         if (temp == ENUMTY) {
ragge
1.2
662                 TWORD ty;
ragge
1.1
663
ragge
1.43
664 #ifdef ENUMSIZE
ragge
1.1
665                 ty = ENUMSIZE(high,low);
ragge
1.43
666 #else
667                 if ((char)high == high && (char)low == low)
668                         ty = ctype(CHAR);
669                 else if ((short)high == high && (short)low == low)
670                         ty = ctype(SHORT);
671                 else
672                         ty = ctype(INT);
ragge
1.1
673 #endif
ragge
1.43
674                 strucoff = tsize(ty0MKSUE(ty));
675                 sue->suealign = al = talign(tyMKSUE(ty));
ragge
1.21
676         }
ragge
1.1
677
ragge
1.43
678         sue->suesize = strucoff;
679         sue->suealign = al;
680
681 //      FIXSTRUCT(szindex, oparam); /* local hook, eg. for sym debugger */
ragge
1.46
682 #ifdef PCC_DEBUG
ragge
1.21
683         if (ddebug>1) {
ragge
1.50
684                 int i;
685
ragge
1.46
686                 printf("\tsize %d align %d elem %p\n",
687                     sue->suesizesue->suealignsue->suelem);
ragge
1.50
688                 for (i = 0sue->suelem[i] != NULL; ++i) {
689                         printf("\tmember %s(%p)\n",
690                             sue->suelem[i]->snamesue->suelem[i]);
ragge
1.1
691                 }
ragge
1.21
692         }
ragge
1.43
693 #endif
ragge
1.1
694
ragge
1.43
695         strucoff = r->rstrucoff;
ragge
1.46
696         if ((lparam = r->rlparam) != NULL)
697                 lparam->next = NULL;
698         n = mkty(temp0sue);
ragge
1.43
699         return n;
ragge
1.21
700 }
ragge
1.1
701
ragge
1.2
702 /*
703  * error printing routine in parser
704  */
705 void yyerror(char *s);
706 void
707 yyerror(char *s)
708 {
709         uerror(s);
710 }
711
712 void yyaccpt(void);
713 void
714 yyaccpt(void)
715 {
ragge
1.1
716         ftnend();
ragge
1.2
717 }
ragge
1.1
718
ragge
1.2
719 void
ragge
1.33
720 ftnarg(char *name)
ragge
1.2
721 {
ragge
1.33
722         struct symtab *s = lookup(name0);
ragge
1.1
723
ragge
1.41
724         blevel = 1/* Always */
725
ragge
1.33
726         switch (s->stype) {
ragge
1.1
727         case UNDEF:
728                 /* this parameter, entered at scan */
729                 break;
730         case FARG:
ragge
1.33
731                 uerror("redeclaration of formal parameter, %s"s->sname);
ragge
1.1
732                 /* fall thru */
733         case FTN:
734                 /* the name of this function matches parm */
735                 /* fall thru */
736         default:
ragge
1.33
737                 s = hide(s);
ragge
1.1
738                 break;
739         case TNULL:
740                 /* unused entry, fill it */
741                 ;
ragge
1.33
742         }
743         s->stype = FARG;
744         s->sclass = PARAM;
ragge
1.45
745
ragge
1.47
746         ssave(s);
ragge
1.45
747         nparams++;
ragge
1.2
748 }
ragge
1.1
749
ragge
1.2
750 /*
751  * compute the alignment of an object with type ty, sizeoff index s
752  */
753 int
ragge
1.43
754 talign(unsigned int tystruct suedef *sue)
ragge
1.2
755 {
756         int i;
ragge
1.1
757
ragge
1.43
758         if(sue == NULL && ty!=INT && ty!=CHAR && ty!=SHORT &&
759             ty!=UNSIGNED && ty!=UCHAR && ty!=USHORT) {
760                 return(fldal(ty));
761         }
ragge
1.1
762
763         fori=0i<=(SZINT-BTSHIFT-1); i+=TSHIFT ){
764                 switch( (ty>>i)&TMASK ){
765
766                 case FTN:
767                         uerror"can't assign to function" );
768                         returnALCHAR );
769                 case PTR:
770                         returnALPOINT );
771                 case ARY:
772                         continue;
773                 case 0:
774                         break;
775                         }
776                 }
777
778         switchBTYPE(ty) ){
779
780         case UNIONTY:
781         case ENUMTY:
782         case STRTY:
ragge
1.43
783                 return((unsigned int)sue->suealign);
ragge
1.1
784         case CHAR:
785         case UCHAR:
ragge
1.9
786                 return (ALCHAR);
ragge
1.1
787         case FLOAT:
ragge
1.9
788                 return (ALFLOAT);
ragge
1.1
789         case DOUBLE:
ragge
1.9
790                 return (ALDOUBLE);
791         case LONGLONG:
792         case ULONGLONG:
793                 return (ALLONGLONG);
ragge
1.1
794         case LONG:
795         case ULONG:
ragge
1.9
796                 return (ALLONG);
ragge
1.1
797         case SHORT:
798         case USHORT:
ragge
1.9
799                 return (ALSHORT);
ragge
1.1
800         default:
ragge
1.9
801                 return (ALINT);
ragge
1.1
802         }
ragge
1.43
803 }
ragge
1.1
804
ragge
1.43
805 /* compute the size associated with type ty,
806  *  dimoff d, and sizoff s */
807 /* BETTER NOT BE CALLED WHEN t, d, and s REFER TO A BIT FIELD... */
ragge
1.1
808 OFFSZ
ragge
1.50
809 tsize(TWORD tyint *dstruct suedef *sue)
ragge
1.43
810 {
ragge
1.1
811
812         int i;
813         OFFSZ mult;
814
815         mult = 1;
816
817         fori=0i<=(SZINT-BTSHIFT-1); i+=TSHIFT ){
818                 switch( (ty>>i)&TMASK ){
819
820                 case FTN:
821                         /* cerror( "compiler takes size of function"); */
822                         uerror"can't take size of function" );
823                         returnSZCHAR );
824                 case PTR:
825                         returnSZPOINT * mult );
826                 case ARY:
ragge
1.50
827                         mult *= (unsigned int) *d++;
ragge
1.1
828                         continue;
829                 case 0:
830                         break;
831
832                         }
833                 }
834
ragge