Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20030607202603

Diff

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