Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20030604200825

Diff

Diff from 1.34 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         /* allow nonunique structure/union member names */
287
288         ifclass==MOU || class==MOS || class & FIELD ){/* make a new entry */
ragge
1.33
289                 cerror("mismatch nonunique");
290         }
ragge
1.24
291         if (blevel > slev && class != EXTERN && class != FORTRAN &&
292             class != UFORTRAN) {
ragge
1.33
293                 p = hide(p);
294                 q->n_sp = p;
ragge
1.1
295                 goto enter;
ragge
1.24
296         }
ragge
1.33
297         uerror("redeclaration of %s"p->sname);
298         if (class==EXTDEF && ISFTN(type))
299                 cftnsp = p;
ragge
1.1
300         return;
301
302         enter:  /* make a new entry */
303
304 # ifndef BUG1
ragge
1.33
305         if(ddebug)
306                 printf("        new entry made\n");
ragge
1.1
307 # endif
ragge
1.33
308         if (type == UNDEF)
309                 uerror("void type for %s"p->sname);
ragge
1.1
310         p->stype = type;
311         p->sclass = class;
312         p->slevel = blevel;
ragge
1.33
313         p->soffset = NOOFFSET;
ragge
1.1
314         p->suse = lineno;
315         ifclass == STNAME || class == UNAME || class == ENAME ) {
316                 p->sizoff = curdim;
317                 dstash0 );  /* size */
318                 dstash( -1 ); /* index to members of str or union */
319                 dstashALSTRUCT );  /* alignment */
ragge
1.33
320                 dstash((int)p); /* dstash( idp ); XXX cast */
ragge
1.1
321                 }
322         else {
323                 switchBTYPE(type) ){
324                 case STRTY:
325                 case UNIONTY:
326                 case ENUMTY:
ragge
1.31
327                         p->sizoff = q->n_csiz;
ragge
1.1
328                         break;
329                 default:
330                         p->sizoff = BTYPE(type);
331                         }
332                 }
333
334         /* copy dimensions */
335
ragge
1.31
336         p->dimoff = q->n_cdim;
ragge
1.1
337
338         /* allocate offsets */
ragge
1.33
339         if (class&FIELD) {
340                 (voidfalloc(pclass&FLDSIZ0NIL);  /* new entry */
341                 psave((int)p); /* XXX cast */
342         } else switch (class) {
ragge
1.1
343
344         case AUTO:
ragge
1.30
345                 if (arrstkp)
346                         dynalloc(p, &autooff);
347                 else
ragge
1.33
348                         (voidoalloc(p, &autooff);
ragge
1.1
349                 break;
350         case STATIC:
351         case EXTDEF:
ragge
1.33
352                 p->soffset = getlab();
353                 if (class == STATIC && blevel > 0)
354                         p->sflags |= SLABEL;
355                 if (ISFTN(type))
356                         cftnsp = p;
ragge
1.1
357                 break;
358
359         case EXTERN:
360         case UFORTRAN:
361         case FORTRAN:
ragge
1.33
362                 p->soffset = getlab();
ragge
1.1
363                 p->slevel = 0;
364                 break;
365         case MOU:
366         case MOS:
367                 (voidoallocp, &strucoff );
368                 ifclass == MOU ) strucoff = 0;
ragge
1.33
369                 psave((int)p); /* XXX cast */
ragge
1.1
370                 break;
371
372         case MOE:
ragge
1.33
373                 p->soffset = strucoff++;
374                 psave((int)p); /* XXX cast */
ragge
1.1
375                 break;
376         case REGISTER:
ragge
1.33
377                 p->soffset = regvar--;
378                 if (blevel == 1)
379                         p->sflags |= SSET;
380                 if (regvar < minrvar)
381                         minrvar = regvar;
ragge
1.1
382                 break;
ragge
1.33
383         }
ragge
1.1
384
385         {
ragge
1.2
386                 int l = p->slevel;
ragge
1.1
387
388                 ifl >= MAXSCOPES )
389                         cerror"scopes nested too deep" );
390
391                 p->snext = schain[l];
392                 schain[l] = p;
393                 ifl >= chaintop )
394                         chaintop = l + 1;
ragge
1.33
395         }
ragge
1.1
396
397         /* user-supplied routine to fix up new definitions */
398
399         FIXDEF(p);
400
401 # ifndef BUG1
ragge
1.33
402         if (ddebug)
403                 printf"       dimoff, sizoff, offset: %d, %d, %d\n",
404                     p->dimoffp->sizoffp->soffset );
ragge
1.1
405 # endif
406
ragge
1.33
407 }
ragge
1.1
408
ragge
1.2
409 void
410 psave(int i)
411 {
ragge
1.1
412         ifparamno >= PARAMSZ ){
413                 cerror"parameter stack overflow");
ragge
1.2
414         }
ragge
1.1
415         paramstkparamno++ ] = i;
ragge
1.2
416 }
ragge
1.1
417
ragge
1.2
418 /*
419  * end of function
420  */
421 void
422 ftnend()
423 {
ragge
1.33
424         if (retlab != NOLAB && nerrors == 0/* inside a real function */
ragge
1.1
425                 efcode();
ragge
1.33
426
ragge
1.1
427         checkst(0);
428         retstat = 0;
429         tcheck();
430         brklab = contlab = retlab = NOLAB;
431         flostat = 0;
432         ifnerrors == 0 ){
433                 ifpsavbc != & asavbc[0] ) cerror("bcsave error");
434                 ifparamno != 0 ) cerror("parameter reset error");
435                 ifswx != 0 ) cerror"switch error");
436                 }
437         psavbc = &asavbc[0];
438         paramno = 0;
439         autooff = AUTOINIT;
440         minrvar = regvar = MAXRVAR;
441         reached = 1;
442         swx = 0;
443         swp = swtab;
444         (voidlocctr(DATA);
ragge
1.2
445 }
ragge
1.1
446
ragge
1.2
447 void
448 dclargs()
449 {
450         int ij;
451         struct symtab *p;
452         NODE *q;
ragge
1.1
453         argoff = ARGINIT;
ragge
1.12
454
ragge
1.1
455 # ifndef BUG1
ragge
1.12
456         if (ddebug > 2)
457                 printf("dclargs()\n");
ragge
1.1
458 # endif
ragge
1.12
459         for (i = 0i < paramno; ++i) {
460                 if ((j = paramstk[i]) < 0)
461                         continue;
ragge
1.33
462                 p = (struct symtab *)j;
ragge
1.1
463 # ifndef BUG1
ragge
1.12
464                 if (ddebug > 2) {
ragge
1.1
465                         printf("\t%s (%d) ",p->snamej);
466                         tprint(p->stype);
467                         printf("\n");
ragge
1.12
468                 }
ragge
1.1
469 # endif
ragge
1.12
470                 if (p->stype == FARG) {
ragge
1.1
471                         q = block(FREE,NIL,NIL,INT,0,INT);
ragge
1.31
472                         q->n_rval = j;
ragge
1.12
473                         defid(qPARAM);
474                 }
ragge
1.1
475                 FIXARG(p); /* local arg hook, eg. for sym. debugger */
ragge
1.12
476           /* always set aside space, even for register arguments */
477                 oalloc(p, &argoff);
478         }
ragge
1.1
479         cendarg();
480         (voidlocctr(PROG);
481         defalign(ALINT);
482         ftnno = getlab();
ragge
1.12
483         bfcode(paramstkparamno);
ragge
1.1
484         paramno = 0;
ragge
1.2
485 }
ragge
1.1
486
ragge
1.21
487 /*
488  * reference to a structure or union, with no definition
489  */
ragge
1.1
490 NODE *
ragge
1.33
491 rstruct(char *tagint soru)
ragge
1.21
492 {
ragge
1.2
493         struct symtab *p;
494         NODE *q;
ragge
1.32
495
ragge
1.33
496         p = (struct symtab *)lookup(tagSTAG);
ragge
1.21
497         switch (p->stype) {
ragge
1.1
498
499         case UNDEF:
500         def:
ragge
1.21
501                 q = block(FREENILNIL000);
ragge
1.33
502                 q->n_sp = p;
ragge
1.31
503                 q->n_type = (soru&INSTRUCT) ? STRTY :
ragge
1.21
504                     ((soru&INUNION) ? UNIONTY : ENUMTY);
505                 defid(q, (soru&INSTRUCT) ? STNAME :
506                     ((soru&INUNION) ? UNAME : ENAME));
ragge
1.1
507                 break;
508
509         case STRTY:
ragge
1.21
510                 if (soru & INSTRUCT)
511                         break;
ragge
1.1
512                 goto def;
513
514         case UNIONTY:
ragge
1.21
515                 if (soru & INUNION)
516                         break;
ragge
1.1
517                 goto def;
518
519         case ENUMTY:
ragge
1.21
520                 if (!(soru&(INUNION|INSTRUCT)))
521                         break;
ragge
1.1
522                 goto def;
523
ragge
1.21
524         }
525         return(mkty(p->stype0p->sizoff));
526 }
ragge
1.1
527
ragge
1.2
528 void
ragge
1.33
529 moedef(char *name)
ragge
1.2
530 {
531         NODE *q;
ragge
1.1
532
ragge
1.33
533         q = block(FREENILNILMOETY00);
534         q->n_sp = lookup(name0);
535         defid(qMOE);
ragge
1.2
536 }
ragge
1.1
537
ragge
1.2
538 /*
539  * begining of structure or union declaration
540  */
541 int
ragge
1.33
542 bstruct(char *nameint soru)
ragge
1.2
543 {
ragge
1.33
544         struct symtab *s;
ragge
1.2
545         NODE *q;
ragge
1.1
546
ragge
1.33
547         if (name != NULL)
548                 s = lookup(nameSTAG);
549         else
550                 s = NULL;
551
ragge
1.18
552         psave(instruct);
553         psave(strunem);
554         psave(strucoff);
ragge
1.1
555         strucoff = 0;
556         instruct = soru;
ragge
1.21
557         q = block(FREENILNIL000);
ragge
1.33
558         q->n_sp = s;
ragge
1.21
559         if (instruct==INSTRUCT) {
ragge
1.18
560                 strunem = MOS;
ragge
1.31
561                 q->n_type = STRTY;
ragge
1.33
562                 if (s != NULL)
ragge
1.21
563                         defid(qSTNAME);
564         } else if(instruct == INUNION) {
ragge
1.18
565                 strunem = MOU;
ragge
1.31
566                 q->n_type = UNIONTY;
ragge
1.33
567                 if (s != NULL)
ragge
1.21
568                         defid(qUNAME);
569         } else { /* enum */
ragge
1.18
570                 strunem = MOE;
ragge
1.31
571                 q->n_type = ENUMTY;
ragge
1.33
572                 if (s != NULL)
ragge
1.21
573                         defid(qENAME);
574         }
ragge
1.33
575         psave((int)q->n_sp); /* XXX cast */
576
ragge
1.1
577         /* the "real" definition is where the members are seen */
ragge
1.33
578         if (s != NULL)
579                 s->suse = lineno;
ragge
1.21
580         return(paramno-4);
ragge
1.2
581 }
ragge
1.1
582
ragge
1.18
583 /*
584  * Called after a struct is declared to restore the environment.
585  */
ragge
1.1
586 NODE *
ragge
1.2
587 dclstruct(int oparam)
588 {
589         struct symtab *p;
590         int ialsajszszindex;
591         TWORD temp;
592         int highlow;
ragge
1.1
593
ragge
1.18
594         /*
595          * paramstk contains:
596          *      paramstk[oparam] = previous instruct
597          *      paramstk[oparam+1] = previous class
598          *      paramstk[oparam+2] = previous strucoff
599          *      paramstk[oparam+3] = structure name
600          *
601          *      paramstk[oparam+4, ...]  = member stab indices
602          */
ragge
1.1
603
604
ragge
1.33
605         if ((i = paramstk[oparam+3]) <= 0) {
ragge
1.1
606                 szindex = curdim;
ragge
1.18
607                 dstash(0);  /* size */
608                 dstash(-1);  /* index to member names */
609                 dstash(ALSTRUCT);  /* alignment */
610                 dstash(-lineno);        /* name of structure */
611         } else
ragge
1.32
612                 szindex = ((struct symtab *)i)->sizoff;
ragge
1.1
613
614 # ifndef BUG1
ragge
1.18
615         if (ddebug) {
616                 printf("dclstruct( %s ), szindex = %d\n",
ragge
1.33
617                     (i>0)? ((struct symtab *)i)->sname : "??"szindex);
ragge
1.18
618         }
ragge
1.1
619 # endif
620         temp = (instruct&INSTRUCT)?STRTY:((instruct&INUNION)?UNIONTY:ENUMTY);
ragge
1.34
621         instruct = paramstk[oparam];
ragge
1.18
622         strunem = paramstk[oparam+1];
623         dimtab[szindex+1] = curdim;
ragge
1.1
624         al = ALSTRUCT;
625
626         high = low = 0;
627
628         fori = oparam+4;  iparamno; ++i ){
629                 dstashj=paramstk[i] );
ragge
1.33
630                 ifj<0 /* || j>= SYMTSZ */ ) cerror"gummy structure member" ); /* XXX cast bad test */
631                 p = (struct symtab *)j/* XXX - cast */
ragge
1.1
632                 iftemp == ENUMTY ){
ragge
1.33
633                         ifp->soffset < low ) low = p->soffset;
634                         ifp->soffset > high ) high = p->soffset;
ragge
1.1
635                         p->sizoff = szindex;
636                         continue;
637                         }
638                 sa = talignp->stypep->sizoff );
ragge
1.21
639                 if (p->sclass & FIELD) {
ragge
1.1
640                         sz = p->sclass&FLDSIZ;
ragge
1.21
641                 } else {
642                         sz = tsize(p->stypep->dimoffp->sizoff);
643                 }
644 #if 0
645                 if (sz == 0) {
646                         werror("illegal zero sized structure member: %s"p->sname );
ragge
1.1
647                 }
ragge
1.21
648 #endif
649                 if (sz > strucoff)
650                         strucoff = sz;  /* for use with unions */
651                 /*
652                  * set al, the alignment, to the lcm of the alignments
653                  * of the members.
654                  */
655                 SETOFF(alsa);
656         }
657         dstash(-1);  /* endmarker */
ragge
1.1
658         SETOFFstrucoffal );
659
660         iftemp == ENUMTY ){
ragge
1.2
661                 TWORD ty;
ragge
1.1
662
663 # ifdef ENUMSIZE
664                 ty = ENUMSIZE(high,low);
665 # else
666                 if( (char)high == high && (char)low == low ) ty = ctypeCHAR );
667                 else if( (short)high == high && (short)low == low ) ty = ctypeSHORT );
668                 else ty = ctype(INT);
669 #endif
670                 strucoff = tsizety0, (int)ty );
671                 dimtabszindex+2 ] = al = talignty, (int)ty );
ragge
1.21
672         }
ragge
1.1
673
ragge
1.21
674 #if 0
675         if (strucoff == 0)
676                 uerror"zero sized structure" );
677 #endif
678         dimtab[szindex] = strucoff;
679         dimtab[szindex+2] = al;
680         dimtab[szindex+3] = paramstkoparam+3 ];  /* name index */
ragge
1.1
681
ragge
1.21
682         FIXSTRUCT(szindexoparam); /* local hook, eg. for sym debugger */
ragge
1.1
683 # ifndef BUG1
ragge
1.21
684         if (ddebug>1) {
685                 printf("\tdimtab[%d,%d,%d] = %d,%d,%d\n",
686                     szindex,szindex+1,szindex+2,
687                     dimtab[szindex],dimtab[szindex+1],dimtab[szindex+2] );
688                 for (i = dimtab[szindex+1]; dimtab[i] >= 0; ++i) {
689                         printf("\tmember %s(%d)\n",
ragge
1.33
690                             ((struct symtab *)dimtab[i])->snamedimtab[i]);
ragge
1.1
691                 }
ragge
1.21
692         }
ragge
1.1
693 # endif
694
695         strucoff = paramstkoparam+2 ];
696         paramno = oparam;
697
698         returnmktytemp0szindex ) );
ragge
1.21
699 }
ragge
1.1
700
ragge
1.2
701 /*
702  * error printing routine in parser
703  */
704 void yyerror(char *s);
705 void
706 yyerror(char *s)
707 {
708         uerror(s);
709 }
710
711 void yyaccpt(void);
712 void
713 yyaccpt(void)
714 {
ragge
1.1
715         ftnend();
ragge
1.2
716 }
ragge
1.1
717
ragge
1.2
718 void
ragge
1.33
719 ftnarg(char *name)
ragge
1.2
720 {
ragge
1.33
721         struct symtab *s = lookup(name0);
ragge
1.1
722
ragge
1.33
723         switch (s->stype) {
ragge
1.1
724         case UNDEF:
725                 /* this parameter, entered at scan */
726                 break;
727         case FARG:
ragge
1.33
728                 uerror("redeclaration of formal parameter, %s"s->sname);
ragge
1.1
729                 /* fall thru */
730         case FTN:
731                 /* the name of this function matches parm */
732                 /* fall thru */
733         default:
ragge
1.33
734                 s = hide(s);
ragge
1.1
735                 break;
736         case TNULL:
737                 /* unused entry, fill it */
738                 ;
ragge
1.33
739         }
740         s->stype = FARG;
741         s->sclass = PARAM;
742         psave((int)s);
ragge
1.2
743 }
ragge
1.1
744
ragge
1.2
745 /*
746  * compute the alignment of an object with type ty, sizeoff index s
747  */
748 int
749 talign(unsigned int tyint s)
750 {
751         int i;
ragge
1.1
752
753         ifs<0 && ty!=INT && ty!=CHAR && ty!=SHORT && ty!=UNSIGNED && ty!=UCHAR && ty!=USHORT 
754                                         ){
755                 returnfldalty ) );
756                 }
757
758         fori=0i<=(SZINT-BTSHIFT-1); i+=TSHIFT ){
759                 switch( (ty>>i)&TMASK ){
760
761                 case FTN:
762                         uerror"can't assign to function" );
763                         returnALCHAR );
764                 case PTR:
765                         returnALPOINT );
766                 case ARY:
767                         continue;
768                 case 0:
769                         break;
770                         }
771                 }
772
773         switchBTYPE(ty) ){
774
775         case UNIONTY:
776         case ENUMTY:
777         case STRTY:
778                 return( (unsigned intdimtabs+2 ] );
779         case CHAR:
780         case UCHAR:
ragge
1.9
781                 return (ALCHAR);
ragge
1.1
782         case FLOAT:
ragge
1.9
783                 return (ALFLOAT);
ragge
1.1
784         case DOUBLE:
ragge
1.9
785                 return (ALDOUBLE);
786         case LONGLONG:
787         case ULONGLONG:
788                 return (ALLONGLONG);
ragge
1.1
789         case LONG:
790         case ULONG:
ragge
1.9
791                 return (ALLONG);
ragge
1.1
792         case SHORT:
793         case USHORT:
ragge
1.9
794                 return (ALSHORT);
ragge
1.1
795         default:
ragge
1.9
796                 return (ALINT);
ragge
1.1
797                 }
798         }
799
800 OFFSZ
801 tsizetyds )  TWORD ty; {
802         /* compute the size associated with type ty,
803             dimoff d, and sizoff s */
804         /* BETTER NOT BE CALLED WHEN t, d, and s REFER TO A BIT FIELD... */
805
806         int i;
807         OFFSZ mult;
808
809         mult = 1;
810
811         fori=0i<=(SZINT-BTSHIFT-1); i+=TSHIFT ){
812                 switch( (ty>>i)&TMASK ){
813
814                 case FTN:
815                         /* cerror( "compiler takes size of function"); */
816                         uerror"can't take size of function" );
817                         returnSZCHAR );
818                 case PTR:
819                         returnSZPOINT * mult );
820                 case ARY:
821                         mult *= (unsigned intdimtabd++ ];
822                         continue;
823                 case 0:
824                         break;
825
826                         }
827                 }
828
ragge
1.21
829         if (ty != STRTY && ty != UNIONTY) {
830                 if (dimtab[s] == 0) {
831                         uerror("unknown size");
832                         return(SZINT);
833                 }
834         } else {
835                 if (dimtab[s+1] == -1)
836                         uerror("unknown structure/union");
837         }
838
ragge
1.1
839         return( (unsigned intdimtabs ] * mult );
ragge
1.21
840 }
ragge
1.1
841
ragge
1.2
842 /*
843  * force inoff to have the value n
844  */
845 void
846 inforce(OFFSZ n)
847 {
ragge
1.1
848         /* inoff is updated to have the value n */
849         OFFSZ wb;
ragge
1.2
850         int rest;
ragge
1.1
851         /* rest is used to do a lot of conversion to ints... */
852
853         ifinoff == n ) return;
ragge
1.20
854         if (inoff > n)
855                 cerror("initialization alignment error: inoff %lld n %lld",
856                     inoffn);
ragge
1.1
857
858         wb = inoff;
859         SETOFFwbSZINT );
860
861         /* wb now has the next higher word boundary */
862
863         ifwb >= n ){ /* in the same word */
864                 rest = n - inoff;
865                 vfdzerorest );
866                 return;
867                 }
868
869         /* otherwise, extend inoff to be word aligned */
870
871         rest = wb - inoff;
872         vfdzerorest );
873
874         /* now, skip full words until near to n */
875
876         rest = (n-inoff)/SZINT;
877         zecoderest );
878
879         /* now, the remainder of the last word */
880
881         rest = n-inoff;
882         vfdzerorest );
883         ifinoff != n ) cerror"inoff error");
884
885         }
886
ragge
1.2
887 /*
888  * make inoff have the offset the next alignment of n
889  */
890 void
891 vfdalign(int n)
892 {
ragge
1.1
893         OFFSZ m;
894
895         m = inoff;
896         SETOFFmn );
897         inforcem );
ragge
1.2
898 }
ragge
1.1
899