Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20030609174257

Diff

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