Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20030609155556

Diff

Diff from 1.43 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/pcc/pcc/cc/ccom/pftn.c

Annotated File View

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