Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20030607101630

Diff

Diff from 1.37 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;
ragge
1.37
440         tmpfree(); /* Release memory resources */
ragge
1.1
441         (voidlocctr(DATA);
ragge
1.2
442 }
ragge
1.1
443
ragge
1.2
444 void
445 dclargs()
446 {
447         int ij;
448         struct symtab *p;
449         NODE *q;
ragge
1.1
450         argoff = ARGINIT;
ragge
1.12
451
ragge
1.1
452 # ifndef BUG1
ragge
1.12
453         if (ddebug > 2)
454                 printf("dclargs()\n");
ragge
1.1
455 # endif
ragge
1.12
456         for (i = 0i < paramno; ++i) {
457                 if ((j = paramstk[i]) < 0)
458                         continue;
ragge
1.33
459                 p = (struct symtab *)j;
ragge
1.1
460 # ifndef BUG1
ragge
1.12
461                 if (ddebug > 2) {
ragge
1.1
462                         printf("\t%s (%d) ",p->snamej);
463                         tprint(p->stype);
464                         printf("\n");
ragge
1.12
465                 }
ragge
1.1
466 # endif
ragge
1.12
467                 if (p->stype == FARG) {
ragge
1.1
468                         q = block(FREE,NIL,NIL,INT,0,INT);
ragge
1.31
469                         q->n_rval = j;
ragge
1.12
470                         defid(qPARAM);
471                 }
ragge
1.1
472                 FIXARG(p); /* local arg hook, eg. for sym. debugger */
ragge
1.12
473           /* always set aside space, even for register arguments */
474                 oalloc(p, &argoff);
475         }
ragge
1.1
476         cendarg();
477         (voidlocctr(PROG);
478         defalign(ALINT);
479         ftnno = getlab();
ragge
1.12
480         bfcode(paramstkparamno);
ragge
1.1
481         paramno = 0;
ragge
1.2
482 }
ragge
1.1
483
ragge
1.21
484 /*
485  * reference to a structure or union, with no definition
486  */
ragge
1.1
487 NODE *
ragge
1.33
488 rstruct(char *tagint soru)
ragge
1.21
489 {
ragge
1.2
490         struct symtab *p;
491         NODE *q;
ragge
1.32
492
ragge
1.33
493         p = (struct symtab *)lookup(tagSTAG);
ragge
1.21
494         switch (p->stype) {
ragge
1.1
495
496         case UNDEF:
497         def:
ragge
1.21
498                 q = block(FREENILNIL000);
ragge
1.33
499                 q->n_sp = p;
ragge
1.31
500                 q->n_type = (soru&INSTRUCT) ? STRTY :
ragge
1.21
501                     ((soru&INUNION) ? UNIONTY : ENUMTY);
502                 defid(q, (soru&INSTRUCT) ? STNAME :
503                     ((soru&INUNION) ? UNAME : ENAME));
ragge
1.1
504                 break;
505
506         case STRTY:
ragge
1.21
507                 if (soru & INSTRUCT)
508                         break;
ragge
1.1
509                 goto def;
510
511         case UNIONTY:
ragge
1.21
512                 if (soru & INUNION)
513                         break;
ragge
1.1
514                 goto def;
515
516         case ENUMTY:
ragge
1.21
517                 if (!(soru&(INUNION|INSTRUCT)))
518                         break;
ragge
1.1
519                 goto def;
520
ragge
1.21
521         }
522         return(mkty(p->stype0p->sizoff));
523 }
ragge
1.1
524
ragge
1.2
525 void
ragge
1.33
526 moedef(char *name)
ragge
1.2
527 {
528         NODE *q;
ragge
1.1
529
ragge
1.33
530         q = block(FREENILNILMOETY00);
531         q->n_sp = lookup(name0);
532         defid(qMOE);
ragge
1.2
533 }
ragge
1.1
534
ragge
1.2
535 /*
536  * begining of structure or union declaration
537  */
538 int
ragge
1.33
539 bstruct(char *nameint soru)
ragge
1.2
540 {
ragge
1.33
541         struct symtab *s;
ragge
1.2
542         NODE *q;
ragge
1.1
543
ragge
1.33
544         if (name != NULL)
545                 s = lookup(nameSTAG);
546         else
547                 s = NULL;
548
ragge
1.18
549         psave(instruct);
550         psave(strunem);
551         psave(strucoff);
ragge
1.1
552         strucoff = 0;
553         instruct = soru;
ragge
1.21
554         q = block(FREENILNIL000);
ragge
1.33
555         q->n_sp = s;
ragge
1.21
556         if (instruct==INSTRUCT) {
ragge
1.18
557                 strunem = MOS;
ragge
1.31
558                 q->n_type = STRTY;
ragge
1.33
559                 if (s != NULL)
ragge
1.21
560                         defid(qSTNAME);
561         } else if(instruct == INUNION) {
ragge
1.18
562                 strunem = MOU;
ragge
1.31
563                 q->n_type = UNIONTY;
ragge
1.33
564                 if (s != NULL)
ragge
1.21
565                         defid(qUNAME);
566         } else { /* enum */
ragge
1.18
567                 strunem = MOE;
ragge
1.31
568                 q->n_type = ENUMTY;
ragge
1.33
569                 if (s != NULL)
ragge
1.21
570                         defid(qENAME);
571         }
ragge
1.33
572         psave((int)q->n_sp); /* XXX cast */
573
ragge
1.1
574         /* the "real" definition is where the members are seen */
ragge
1.33
575         if (s != NULL)
576                 s->suse = lineno;
ragge
1.21
577         return(paramno-4);
ragge
1.2
578 }
ragge
1.1
579
ragge
1.18
580 /*
581  * Called after a struct is declared to restore the environment.
582  */
ragge
1.1
583 NODE *
ragge
1.2
584 dclstruct(int oparam)
585 {
586         struct symtab *p;
587         int ialsajszszindex;
588         TWORD temp;
589         int highlow;
ragge
1.1
590
ragge
1.18
591         /*
592          * paramstk contains:
593          *      paramstk[oparam] = previous instruct
594          *      paramstk[oparam+1] = previous class
595          *      paramstk[oparam+2] = previous strucoff
596          *      paramstk[oparam+3] = structure name
597          *
598          *      paramstk[oparam+4, ...]  = member stab indices
599          */
ragge
1.1
600
601
ragge
1.33
602         if ((i = paramstk[oparam+3]) <= 0) {
ragge
1.1
603                 szindex = curdim;
ragge
1.18
604                 dstash(0);  /* size */
605                 dstash(-1);  /* index to member names */
606                 dstash(ALSTRUCT);  /* alignment */
607                 dstash(-lineno);        /* name of structure */
608         } else
ragge
1.32
609                 szindex = ((struct symtab *)i)->sizoff;
ragge
1.1
610
611 # ifndef BUG1
ragge
1.18
612         if (ddebug) {
613                 printf("dclstruct( %s ), szindex = %d\n",
ragge
1.33
614                     (i>0)? ((struct symtab *)i)->sname : "??"szindex);
ragge
1.18
615         }
ragge
1.1
616 # endif
617         temp = (instruct&INSTRUCT)?STRTY:((instruct&INUNION)?UNIONTY:ENUMTY);
ragge
1.34
618         instruct = paramstk[oparam];
ragge
1.18
619         strunem = paramstk[oparam+1];
620         dimtab[szindex+1] = curdim;
ragge
1.1
621         al = ALSTRUCT;
622
623         high = low = 0;
624
625         fori = oparam+4;  iparamno; ++i ){
626                 dstashj=paramstk[i] );
ragge
1.33
627                 ifj<0 /* || j>= SYMTSZ */ ) cerror"gummy structure member" ); /* XXX cast bad test */
628                 p = (struct symtab *)j/* XXX - cast */
ragge
1.1
629                 iftemp == ENUMTY ){
ragge
1.33
630                         ifp->soffset < low ) low = p->soffset;
631                         ifp->soffset > high ) high = p->soffset;
ragge
1.1
632                         p->sizoff = szindex;
633                         continue;
634                         }
635                 sa = talignp->stypep->sizoff );
ragge
1.21
636                 if (p->sclass & FIELD) {
ragge
1.1
637                         sz = p->sclass&FLDSIZ;
ragge
1.21
638                 } else {
639                         sz = tsize(p->stypep->dimoffp->sizoff);
640                 }
641 #if 0
642                 if (sz == 0) {
643                         werror("illegal zero sized structure member: %s"p->sname );
ragge
1.1
644                 }
ragge
1.21
645 #endif
646                 if (sz > strucoff)
647                         strucoff = sz;  /* for use with unions */
648                 /*
649                  * set al, the alignment, to the lcm of the alignments
650                  * of the members.
651                  */
652                 SETOFF(alsa);
653         }
654         dstash(-1);  /* endmarker */
ragge
1.1
655         SETOFFstrucoffal );
656
657         iftemp == ENUMTY ){
ragge
1.2
658                 TWORD ty;
ragge
1.1
659
660 # ifdef ENUMSIZE
661                 ty = ENUMSIZE(high,low);
662 # else
663                 if( (char)high == high && (char)low == low ) ty = ctypeCHAR );
664                 else if( (short)high == high && (short)low == low ) ty = ctypeSHORT );
665                 else ty = ctype(INT);
666 #endif
667                 strucoff = tsizety0, (int)ty );
668                 dimtabszindex+2 ] = al = talignty, (int)ty );
ragge
1.21
669         }
ragge
1.1
670
ragge
1.21
671 #if 0
672         if (strucoff == 0)
673                 uerror"zero sized structure" );
674 #endif
675         dimtab[szindex] = strucoff;
676         dimtab[szindex+2] = al;
677         dimtab[szindex+3] = paramstkoparam+3 ];  /* name index */
ragge
1.1
678
ragge
1.21
679         FIXSTRUCT(szindexoparam); /* local hook, eg. for sym debugger */
ragge
1.1
680 # ifndef BUG1
ragge
1.21
681         if (ddebug>1) {
682                 printf("\tdimtab[%d,%d,%d] = %d,%d,%d\n",
683                     szindex,szindex+1,szindex+2,
684                     dimtab[szindex],dimtab[szindex+1],dimtab[szindex+2] );
685                 for (i = dimtab[szindex+1]; dimtab[i] >= 0; ++i) {
686                         printf("\tmember %s(%d)\n",
ragge
1.33
687                             ((struct symtab *)dimtab[i])->snamedimtab[i]);
ragge
1.1
688                 }
ragge
1.21
689         }
ragge
1.1
690 # endif
691
692         strucoff = paramstkoparam+2 ];
693         paramno = oparam;
694
695         returnmktytemp0szindex ) );
ragge
1.21
696 }
ragge
1.1
697
ragge
1.2
698 /*
699  * error printing routine in parser
700  */
701 void yyerror(char *s);
702 void
703 yyerror(char *s)
704 {
705         uerror(s);
706 }
707
708 void yyaccpt(void);
709 void
710 yyaccpt(void)
711 {
ragge
1.1
712         ftnend();
ragge
1.2
713 }
ragge
1.1
714
ragge
1.2
715 void
ragge
1.33
716 ftnarg(char *name)
ragge
1.2
717 {
ragge
1.33
718         struct symtab *s = lookup(name0);
ragge
1.1
719
ragge
1.33
720         switch (s->stype) {
ragge
1.1
721         case UNDEF:
722                 /* this parameter, entered at scan */
723                 break;
724         case FARG:
ragge
1.33
725                 uerror("redeclaration of formal parameter, %s"s->sname);
ragge
1.1
726                 /* fall thru */
727         case FTN:
728                 /* the name of this function matches parm */
729                 /* fall thru */
730         default:
ragge
1.33
731                 s = hide(s);
ragge
1.1
732                 break;
733         case TNULL:
734                 /* unused entry, fill it */
735                 ;
ragge
1.33
736         }
737         s->stype = FARG;
738         s->sclass = PARAM;
739         psave((int)s);
ragge
1.2
740 }
ragge
1.1
741
ragge
1.2
742 /*
743  * compute the alignment of an object with type ty, sizeoff index s
744  */
745 int
746 talign(unsigned int tyint s)
747 {
748         int i;
ragge
1.1
749
750         ifs<0 && ty!=INT && ty!=CHAR && ty!=SHORT && ty!=UNSIGNED && ty!=UCHAR && ty!=USHORT 
751                                         ){
752                 returnfldalty ) );
753                 }
754
755         fori=0i<=(SZINT-BTSHIFT-1); i+=TSHIFT ){
756                 switch( (ty>>i)&TMASK ){
757
758                 case FTN:
759                         uerror"can't assign to function" );
760                         returnALCHAR );
761                 case PTR:
762                         returnALPOINT );
763                 case ARY:
764                         continue;
765                 case 0:
766                         break;
767                         }
768                 }
769
770         switchBTYPE(ty) ){
771
772         case UNIONTY:
773         case ENUMTY:
774         case STRTY:
775                 return( (unsigned intdimtabs+2 ] );
776         case CHAR:
777         case UCHAR:
ragge
1.9
778                 return (ALCHAR);
ragge
1.1
779         case FLOAT:
ragge
1.9
780                 return (ALFLOAT);
ragge
1.1
781         case DOUBLE:
ragge
1.9
782                 return (ALDOUBLE);
783         case LONGLONG:
784         case ULONGLONG:
785                 return (ALLONGLONG);
ragge
1.1
786         case LONG:
787         case ULONG:
ragge
1.9
788                 return (ALLONG);
ragge
1.1
789         case SHORT:
790         case USHORT:
ragge
1.9
791                 return (ALSHORT);
ragge
1.1
792         default:
ragge
1.9
793                 return (ALINT);
ragge
1.1
794                 }
795         }
796
797 OFFSZ
798 tsizetyds )  TWORD ty; {
799         /* compute the size associated with type ty,
800             dimoff d, and sizoff s */
801         /* BETTER NOT BE CALLED WHEN t, d, and s REFER TO A BIT FIELD... */
802
803         int i;
804         OFFSZ mult;
805
806         mult = 1;
807
808         fori=0i<=(SZINT-BTSHIFT-1); i+=TSHIFT ){
809                 switch( (ty>>i)&TMASK ){
810
811                 case FTN:
812                         /* cerror( "compiler takes size of function"); */
813                         uerror"can't take size of function" );
814                         returnSZCHAR );
815                 case PTR:
816                         returnSZPOINT * mult );
817                 case ARY:
818                         mult *= (unsigned intdimtabd++ ];
819                         continue;
820                 case 0:
821                         break;
822
823                         }
824                 }
825
ragge
1.21
826         if (ty != STRTY && ty != UNIONTY) {
827                 if (dimtab[s] == 0) {
828                         uerror("unknown size");
829                         return(SZINT);
830                 }
831         } else {
832                 if (dimtab[s+1] == -1)
833                         uerror("unknown structure/union");
834         }
835
ragge
1.1
836         return( (unsigned intdimtabs ] * mult );
ragge
1.21
837 }
ragge
1.1
838
ragge
1.2
839 /*
840  * force inoff to have the value n
841  */
842 void
843 inforce(OFFSZ n)
844 {
ragge
1.1
845         /* inoff is updated to have the value n */
846         OFFSZ wb;
ragge
1.2
847         int rest;
ragge
1.1
848         /* rest is used to do a lot of conversion to ints... */
849
850         ifinoff == n ) return;
ragge
1.20
851         if (inoff > n)
852                 cerror("initialization alignment error: inoff %lld n %lld",
853                     inoffn);
ragge
1.1
854
855         wb = inoff;
856         SETOFFwbSZINT );
857
858         /* wb now has the next higher word boundary */
859
860         ifwb >= n ){ /* in the same word */
861                 rest = n - inoff;
862                 vfdzerorest );
863                 return;
864                 }
865
866         /* otherwise, extend inoff to be word aligned */
867
868         rest = wb - inoff;
869         vfdzerorest );
870
871         /* now, skip full words until near to n */
872
873         rest = (n-inoff)/SZINT;
874         zecoderest );
875
876         /* now, the remainder of the last word */
877
878         rest = n-inoff;
879         vfdzerorest );
880         ifinoff != n ) cerror"inoff error");
881
882         }
883
ragge
1.2
884 /*
885  * make inoff have the offset the next alignment of n
886  */
887 void
888 vfdalign(int n)
889 {
ragge
1.1
890         OFFSZ m;
891
892         m = inoff;
893         SETOFFmn );
894         inforcem );
ragge
1.2
895 }
ragge
1.1
896
897