Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20030610120813

Diff

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