Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20030606193955

Diff

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