Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20030608180336

Diff

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