Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20030610080804

Diff

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