Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20030608182650

Diff

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