Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20020520162701

Diff

Diff from 1.6 to:

Annotations

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

Annotated File View

ragge
1.2
1 #if 0
ragge
1.1
2 static char *sccsid ="@(#)trees.c       4.37 (Berkeley) 6/18/90";
3 #endif
4
5 # include "pass1.h"
6
7 # include <setjmp.h>
8
9 int bdebug = 0;
10 int adebug = 0;
ragge
1.2
11 extern int ddebug;
ragge
1.1
12
ragge
1.2
13 void chkpun(NODE *p);
14 int opact(NODE *p);
15 int chkstr(intintTWORD);
16 int moditype(TWORD);
17
18 /* corrections when in violation of lint */
ragge
1.1
19
20 /*      some special actions, used in finding the type of nodes */
21 # define NCVT 01
22 # define PUN 02
23 # define TYPL 04
24 # define TYPR 010
25 # define TYMATCH 040
26 # define LVAL 0100
27 # define CVTO 0200
28 # define CVTL 0400
29 # define CVTR 01000
30 # define PTMATCH 02000
31 # define OTHER 04000
32 # define NCVTR 010000
33
34 #ifndef BUG1
ragge
1.2
35 static void
36 printact(NODE *tint acts)
ragge
1.1
37 {
38         static struct actions {
39                 int     a_bit;
40                 char    *a_name;
41         } actions[] = {
42                 { PUN,          "PUN" },
43                 { CVTL,         "CVTL" },
44                 { CVTR,         "CVTR" },
45                 { TYPL,         "TYPL" },
46                 { TYPR,         "TYPR" },
47                 { TYMATCH,      "TYMATCH" },
48                 { PTMATCH,      "PTMATCH" },
49                 { LVAL,         "LVAL" },
50                 { CVTO,         "CVTO" },
51                 { NCVT,         "NCVT" },
52                 { OTHER,        "OTHER" },
53                 { NCVTR,        "NCVTR" },
54                 { 0 }
55         };
56         register struct actions *p;
57         char *sep = " ";
58
59         printf("actions");
60         for (p = actionsp->a_namep++)
61                 if (p->a_bit & acts) {
62                         printf("%s%s"sepp->a_name);
63                         sep = "|";
64                 }
65         if (!bdebug) {
66                 printf(" for:\n");
67                 fwalk(teprint0);
68         } else
69                 putchar('\n');
70 }
71 #endif
72
73 /* node conventions:
74
75         NAME:   rval>0 is stab index for external
76                 rval<0 is -inlabel number
77                 lval is offset in bits
78         ICON:   lval has the value
79                 rval has the STAB index, or - label number,
80                         if a name whose address is in the constant
81                 rval = NONAME means no name
82         REG:    rval is reg. identification cookie
83
84         */
85
86 NODE *
ragge
1.2
87 buildtree(int oNODE *lNODE *r)
88 {
89         NODE *p, *q;
90         int actions;
91         int opty;
92         struct symtab *sp;
93         NODE *lr, *ll;
ragge
1.1
94         int i;
95
96 # ifndef BUG1
ragge
1.2
97         if (bdebug)
98                 printf("buildtree(%s, %p, %p)\n"opst[o], lr);
ragge
1.1
99 # endif
100         opty = optype(o);
101
102         /* check for constants */
103
104         ifopty == UTYPE && l->in.op == ICON ){
105
106                 switcho ){
107
108                 case NOT:
109                         ifhflag ) werror"constant argument to NOT" );
110                 case UNARY MINUS:
111                 case COMPL:
112                         ifconvallol ) ) return(l);
113                         break;
114
115                         }
116                 }
117
118         else ifopty == UTYPE && (l->in.op == FCON || l->in.op == DCON) ){
119
120                 switcho ){
121
122                 case NOT:
123                         ifhflag ) werror"constant argument to NOT" );
124                         ifl->in.op == FCON )
125                                 l->tn.lval = l->fpn.fval == 0.0;
126                         else
127                                 l->tn.lval = l->dpn.dval == 0.0;
128                         l->tn.rval = NONAME;
129                         l->in.op = ICON;
130                         l->fn.csiz = l->in.type = INT;
131                         l->fn.cdim = 0;
132                         return(l);
133                 case UNARY MINUS:
134                         ifl->in.op == FCON )
135                                 l->fpn.fval = -l->fpn.fval;
136                         else
137                                 l->dpn.dval = -l->dpn.dval;
138                         return(l);
139                         }
140                 }
141
142         else ifo==QUEST && l->in.op==ICON ) {
143                 l->in.op = FREE;
144                 r->in.op = FREE;
145                 ifl->tn.lval ){
146                         tfreer->in.right );
147                         returnr->in.left );
148                         }
149                 else {
150                         tfreer->in.left );
151                         returnr->in.right );
152                         }
153                 }
154
155         else if( (o==ANDAND || o==OROR) && (l->in.op==ICON||r->in.op==ICON) ) goto ccwarn;
156
157         else ifopty == BITYPE && l->in.op == ICON && r->in.op == ICON ){
158
159                 switcho ){
160
161                 case ULT:
162                 case UGT:
163                 case ULE:
164                 case UGE:
165                 case LT:
166                 case GT:
167                 case LE:
168                 case GE:
169                 case EQ:
170                 case NE:
171                         ifl->in.type == ENUMTY && r->in.type == ENUMTY ){
172                                 p = blockolrINT0INT );
173                                 chkpunp );
174                                 p->in.op = FREE;
175                                 }
176
177                 case ANDAND:
178                 case OROR:
179                 case CBRANCH:
180
181                 ccwarn:
182                         ifhflag ) werror"constant in conditional context" );
183
184                 case PLUS:
185                 case MINUS:
186                 case MUL:
187                 case DIV:
188                 case MOD:
189                 case AND:
190                 case OR:
191                 case ER:
192                 case LS:
193                 case RS:
194                         ifconvallor ) ) {
195                                 r->in.op = FREE;
196                                 return(l);
197                                 }
198                         break;
199                         }
200                 }
201         else if (opty == BITYPE &&
202                 (l->in.op == FCON || l->in.op == DCON || l->in.op == ICON) &&
203                 (r->in.op == FCON || r->in.op == DCON || r->in.op == ICON)) {
204                         if (o == PLUS || o == MINUS || o == MUL || o == DIV) {
205                                 extern int fpe_count;
206                                 extern jmp_buf gotfpe;
207
208                                 fpe_count = 0;
209                                 if (setjmp(gotfpe))
210                                         goto treatfpe;
211                                 if (l->in.op == ICON)
212                                         l->dpn.dval = l->tn.lval;
213                                 else if (l->in.op == FCON)
214                                         l->dpn.dval = l->fpn.fval;
215                                 if (r->in.op == ICON)
216                                         r->dpn.dval = r->tn.lval;
217                                 else if (r->in.op == FCON)
218                                         r->dpn.dval = r->fpn.fval;
219                                 switch (o) {
220
221                                 case PLUS:
222                                         l->dpn.dval += r->dpn.dval;
223                                         break;
224
225                                 case MINUS:
226                                         l->dpn.dval -= r->dpn.dval;
227                                         break;
228
229                                 case MUL:
230                                         l->dpn.dval *= r->dpn.dval;
231                                         break;
232
233                                 case DIV:
234                                         if (r->dpn.dval == 0)
235                                                 uerror("division by 0.");
236                                         else
237                                                 l->dpn.dval /= r->dpn.dval;
238                                         break;
239                                         }
240                         treatfpe:
241                                 if (fpe_count > 0) {
242                                         uerror("floating point exception in constant expression");
243                                         l->dpn.dval = 1.0/* Fairly harmless */
244                                         }
245                                 fpe_count = -1;
246                                 l->in.op = DCON;
247                                 l->in.type = l->fn.csiz = DOUBLE;
248                                 r->in.op = FREE;
249                                 return (l);
250                         }
251                 }
252
253         /* it's real; we must make a new node */
254
255         p = blockolrINT0INT );
256
257         actions = opact(p);
258 #ifndef BUG1
259         if (adebug)
260                 printact(pactions);
261 #endif
262
263         ifactions&LVAL ){ /* check left descendent */
264                 ifnotlval(p->in.left) ) {
265                         uerror"illegal lvalue operand of assignment operator" );
266                         }
267                 }
268
269         ifactions & NCVTR ){
270                 p->in.left = pconvertp->in.left );
271                 }
272         else if( !(actions & NCVT ) ){
273                 switchopty ){
274
275                 case BITYPE:
276                         p->in.right = pconvertp->in.right );
277                 case UTYPE:
278                         p->in.left = pconvertp->in.left );
279
280                         }
281                 }
282
283         if( (actions&PUN) && (o!=CAST||cflag) ){
284                 chkpun(p);
285                 }
286
287         ifactions & (TYPL|TYPR) ){
288
289                 q = (actions&TYPL) ? p->in.left : p->in.right;
290
291                 p->in.type = q->in.type;
292                 p->fn.cdim = q->fn.cdim;
293                 p->fn.csiz = q->fn.csiz;
294                 }
295
296         ifactions & CVTL ) p = convertpCVTL );
297         ifactions & CVTR ) p = convertpCVTR );
298         ifactions & TYMATCH ) p = tymatch(p);
299         ifactions & PTMATCH ) p = ptmatch(p);
300
301         ifactions & OTHER ){
302                 l = p->in.left;
303                 r = p->in.right;
304
305                 switch(o){
306
307                 case NAME:
308                         sp = &stab[idname];
309                         ifsp->stype == UNDEF ){
310                                 uerror"%s undefined"sp->sname );
311                                 /* make p look reasonable */
312                                 p->in.type = p->fn.csiz = INT;
313                                 p->fn.cdim = 0;
314                                 p->tn.rval = idname;
315                                 p->tn.lval = 0;
316                                 defidpSNULL );
317                                 break;
318                                 }
319                         p->in.type = sp->stype;
320                         p->fn.cdim = sp->dimoff;
321                         p->fn.csiz = sp->sizoff;
322                         p->tn.lval = 0;
323                         p->tn.rval = idname;
324                         /* special case: MOETY is really an ICON... */
325                         ifp->in.type == MOETY ){
326                                 p->tn.rval = NONAME;
327                                 p->tn.lval = sp->offset;
328                                 p->fn.cdim = 0;
329                                 p->in.type = ENUMTY;
330                                 p->in.op = ICON;
331                                 }
332                         break;
333
334                 case ICON:
335                         p->in.type = INT;
336                         p->fn.cdim = 0;
337                         p->fn.csiz = INT;
338                         break;
339
340                 case STRING:
341                         p->in.op = NAME;
342                         p->in.type = CHAR+ARY;
343                         p->tn.lval = 0;
344                         p->tn.rval = NOLAB;
345                         p->fn.cdim = curdim;
346                         p->fn.csiz = CHAR;
347                         break;
348
349                 case FCON:
350                         p->tn.lval = 0;
351                         p->tn.rval = 0;
352                         p->in.type = FLOAT;
353                         p->fn.cdim = 0;
354                         p->fn.csiz = FLOAT;
355                         break;
356
357                 case DCON:
358                         p->tn.lval = 0;
359                         p->tn.rval = 0;
360                         p->in.type = DOUBLE;
361                         p->fn.cdim = 0;
362                         p->fn.csiz = DOUBLE;
363                         break;
364
365                 case STREF:
366                         /* p->x turned into *(p+offset) */
367                         /* rhs must be a name; check correctness */
368
369                         i = r->tn.rval;
370                         ifi<0 || ((sp= &stab[i])->sclass != MOS && sp->sclass != MOU && !(sp->sclass&FIELD)) ){
371                                 uerror"member of structure or union required" );
372                                 }else
373                         /* if this name is non-unique, find right one */
374                         ifstab[i].sflags & SNONUNIQ &&
375                                 (l->in.type==PTR+STRTY || l->in.type == PTR+UNIONTY) &&
376                                 (l->fn.csiz +1) >= 0 ){
377                                 /* nonunique name && structure defined */
378                                 char * memnam, * tabnam;
379                                 int j;
380                                 int memi;
381                                 j=dimtab[l->fn.csiz+1];
382                                 for( ; (memi=dimtab[j]) >= 0; ++j ){
383                                         tabnam = stab[memi].sname;
384                                         memnam = stab[i].sname;
385 # ifndef BUG1
386                                         ifddebug>1 ){
387                                                 printf("member %s==%s?\n",
388                                                         memnamtabnam);
389                                                 }
390 # endif
391                                         ifstab[memi].sflags & SNONUNIQ ){
392                                                 if (memnam != tabnam)
393                                                         goto next;
394                                                 r->tn.rval = i = memi;
395                                                 break;
396                                                 }
397                                         nextcontinue;
398                                         }
399                                 ifmemi < 0 )
400                                         uerror("illegal member use: %s",
401                                                 stab[i].sname);
402                                 }
403                         else {
ragge
1.2
404                                 int j;
ragge
1.1
405                                 ifl->in.type != PTR+STRTY && l->in.type != PTR+UNIONTY ){
406                                         ifstab[i].sflags & SNONUNIQ ){
407                                                 uerror"nonunique name demands struct/union or struct/union pointer" );
408                                                 }
409                                         else werror"struct/union or struct/union pointer required" );
410                                         }
411                                 else if( (j=l->fn.csiz+1)<0 ) cerror"undefined structure or union" );
412                                 else if( !chkstridimtab[j], DECREF(l->in.type) ) ){
413                                         werror"illegal member use: %s"stab[i].sname );
414                                         }
415                                 }
416
417                         p = strefp );
418                         break;
419
420                 case UNARY MUL:
421                         ifl->in.op == UNARY AND ){
422                                 p->in.op = l->in.op = FREE;
423                                 p = l->in.left;
424                                 }
425                         if( !ISPTR(l->in.type))uerror("illegal indirection");
426                         p->in.type = DECREF(l->in.type);
427                         p->fn.cdim = l->fn.cdim;
428                         p->fn.csiz = l->fn.csiz;
429                         break;
430
431                 case UNARY AND:
432                         switchl->in.op ){
433
434                         case UNARY MUL:
435                                 p->in.op = l->in.op = FREE;
436                                 p = l->in.left;
437                         case NAME:
438                                 p->in.type = INCREFl->in.type );
439                                 p->fn.cdim = l->fn.cdim;
440                                 p->fn.csiz = l->fn.csiz;
441                                 break;
442
443                         case COMOP:
444                                 lr = buildtreeUNARY ANDl->in.rightNIL );
445                                 p->in.op = l->in.op = FREE;
446                                 p = buildtreeCOMOPl->in.leftlr );
447                                 break;
448
449                         case QUEST:
450                                 lr = buildtreeUNARY ANDl->in.right->in.rightNIL );
451                                 ll = buildtreeUNARY ANDl->in.right->in.leftNIL );
452                                 p->in.op = l->in.op = l->in.right->in.op = FREE;
453                                 p = buildtreeQUESTl->in.leftbuildtreeCOLONlllr ) );
454                                 break;
455
456 # ifdef ADDROREG
457                         case OREG:
458                                 /* OREG was built in clocal()
459                                  * for an auto or formal parameter
460                                  * now its address is being taken
461                                  * local code must unwind it
462                                  * back to PLUS/MINUS REG ICON
463                                  * according to local conventions
464                                  */
465                                 p->in.op = FREE;
466                                 p = addroregl );
467                                 break;
468
469 # endif
470                         default:
471                                 uerror"unacceptable operand of &" );
472                                 break;
473                                 }
474                         break;
475
476                 case LS:
477                 case RS:
478                         ifl->in.type == CHAR || l->in.type == SHORT )
479                                 p->in.type = INT;
480                         else ifl->in.type == UCHAR || l->in.type == USHORT )
481                                 p->in.type = UNSIGNED;
482                         else
483                                 p->in.type = l->in.type;
484                 case ASG LS:
485                 case ASG RS:
486                         ifr->in.type != INT )
487                                 p->in.right = r = makety(rINT0INT );
488                         break;
489
490                 case RETURN:
491                 case ASSIGN:
492                 case CAST:
493                         /* structure assignment */
494                         /* take the addresses of the two sides; then make an
ragge
1.2
495                          * operator using STASG and
496                          * the addresses of left and right */
ragge
1.1
497
498                         {
ragge
1.2
499                                 TWORD t;
500                                 int ds;
ragge
1.1
501
502                                 ifl->fn.csiz != r->fn.csiz ) uerror"assignment of different structures" );
503
504                                 r = buildtreeUNARY ANDrNIL );
505                                 t = r->in.type;
506                                 d = r->fn.cdim;
507                                 s = r->fn.csiz;
508
509                                 l = blockSTASGlrtds );
510
511                                 ifo == RETURN ){
512                                         p->in.op = FREE;
513                                         p = l;
514                                         break;
515                                         }
516
517                                 p->in.op = UNARY MUL;
518                                 p->in.left = l;
519                                 p->in.right = NIL;
520                                 break;
521                                 }
522                 case COLON:
523                         /* structure colon */
524
525                         ifl->fn.csiz != r->fn.csiz ) uerror"type clash in conditional" );
526                         break;
527
528                 case CALL:
529                         p->in.right = r = fixargsp->in.right );
530                 case UNARY CALL:
531                         if( !ISPTR(l->in.type)) uerror("illegal function");
532                         p->in.type = DECREF(l->in.type);
533                         if( !ISFTN(p->in.type)) uerror("illegal function");
534                         p->in.type = DECREFp->in.type );
535                         p->fn.cdim = l->fn.cdim;
536                         p->fn.csiz = l->fn.csiz;
537                         ifl->in.op == UNARY AND && l->in.left->in.op == NAME &&
538                                 l->in.left->tn.rval >= 0 && l->in.left->tn.rval != NONAME &&
539                                 ( (i=stab[l->in.left->tn.rval].sclass) == FORTRAN || i==UFORTRAN ) ){
540                                 p->in.op += (FORTCALL-CALL);
541                                 }
542                         ifp->in.type == STRTY || p->in.type == UNIONTY ){
543                                 /* function returning structure */
544                                 /*  make function really return ptr to str., with * */
545
546                                 p->in.op += STCALL-CALL;
547                                 p->in.type = INCREFp->in.type );
548                                 p = buildtreeUNARY MULpNIL );
549
550                                 }
551                         break;
552
553                 default:
554                         cerror"other code %d"o );
555                         }
556
557                 }
558
559         ifactions & CVTO ) p = oconvert(p);
560         p = clocal(p);
561
562 # ifndef BUG1
563         ifbdebug ) fwalkpeprint0 );
564 # endif
565
566         return(p);
567
568         }
569
570 int fpe_count = -1;
571 jmp_buf gotfpe;
572
ragge
1.2
573 void fpe(int);
ragge
1.1
574 void
ragge
1.2
575 fpe(int a)
576 {
ragge
1.1
577         if (fpe_count < 0)
578                 cerror("floating point exception");
579         ++fpe_count;
580         longjmp(gotfpe1);
ragge
1.2
581 }
ragge
1.1
582
583 /*
584  * Rewrite arguments in a function call.
585  * Structure arguments are massaged, single
586  * precision floating point constants are
587  * cast to double (to eliminate convert code).
588  */
589 NODE *
590 fixargsp ) register NODE *p;  {
591         int o = p->in.op;
592
593         ifo == CM ){
594                 p->in.left = fixargsp->in.left );
595                 p->in.right = fixargsp->in.right );
596                 returnp );
597                 }
598
599         ifp->in.type == STRTY || p->in.type == UNIONTY ){
600                 p = blockSTARGpNILp->in.typep->fn.cdimp->fn.csiz );
601                 p->in.left = buildtreeUNARY ANDp->in.leftNIL );
602                 p = clocal(p);
603                 }
604         else ifo == FCON )
605                 p = makety(pDOUBLE00);
606         returnp );
ragge
1.2
607 }
ragge
1.1
608
ragge
1.2
609 /*
610  * is the MOS or MOU at stab[i] OK for strict reference by a ptr
611  * i has been checked to contain a MOS or MOU
612  * j is the index in dimtab of the members...
613  */
614 int
615 chkstr(int iint jTWORD type)
616 {
ragge
1.1
617         int kkk;
618
619         extern int ddebug;
620
621 # ifndef BUG1
622         ifddebug > 1 ) printf"chkstr( %s(%d), %d )\n"stab[i].snameij );
623 # endif
624         if( (k = j) < 0 ) uerror"undefined structure or union" );
625         else {
626                 for( ; (kk = dimtab[k] ) >= 0; ++k ){
627                         ifkk >= SYMTSZ ){
628                                 cerror"gummy structure" );
629                                 return(1);
630                                 }
631                         ifkk == i ) return1 );
632                         switchstab[kk].stype ){
633
634                         case STRTY:
635                         case UNIONTY:
636                                 iftype == STRTY ) continue;  /* no recursive looking for strs */
637                                 ifhflag && chkstridimtab[stab[kk].sizoff+1], stab[kk].stype ) ){
638                                         ifstab[kk].sname[0] == '$' ) return(0);  /* $FAKE */
639                                         werror(
640                                         "illegal member use: perhaps %s.%s?",
641                                         stab[kk].snamestab[i].sname );
642                                         return(1);
643                                         }
644                                 }
645                         }
646                 }
647         return0 );
ragge
1.2
648 }
ragge
1.1
649
ragge
1.2
650 /*
651  * apply the op o to the lval part of p; if binary, rhs is val
652  * works only on integer constants
653  */
654 int
655 conval(NODE *pint oNODE *q)
656 {
ragge
1.1
657         int iu;
658         CONSZ val;
659         TWORD utype;
660
661         val = q->tn.lval;
662         u = ISUNSIGNED(p->in.type) || ISUNSIGNED(q->in.type);
663         ifu && (o==LE||o==LT||o==GE||o==GT)) o += (UGE-GE);
664
665         ifp->tn.rval != NONAME && q->tn.rval != NONAME ) return(0);
666         ifq->tn.rval != NONAME && o!=PLUS ) return(0);
667         ifp->tn.rval != NONAME && o!=PLUS && o!=MINUS ) return(0);
668
669         /* usual type conversions -- handle casts of constants */
670 #define ISLONG(t)       ((t) == LONG || (t) == ULONG)
ragge
1.6
671 #define ISLONGLONG(t)   ((t) == LONGLONG || (t) == ULONGLONG)
ragge
1.1
672         if (ISLONG(p->in.type) || ISLONG(q->in.type))
673                 utype = u ? ULONG : LONG;
ragge
1.6
674         else if (ISLONGLONG(p->in.type) || ISLONGLONG(q->in.type))
675                 utype = u ? ULONGLONG : LONGLONG;
ragge
1.1
676         else
677                 utype = u ? UNSIGNED : INT;
678         if( !ISPTR(p->in.type) && p->in.type != utype )
679                 p = makety(putype0, (int)utype);
680         ifq->in.type != utype )
681                 q = makety(qutype0, (int)utype);
682
683         switcho ){
684
685         case PLUS:
686                 p->tn.lval += val;
687                 ifp->tn.rval == NONAME ){
688                         p->tn.rval = q->tn.rval;
689                         p->in.type = q->in.type;
690                         }
691                 break;
692         case MINUS:
693                 p->tn.lval -= val;
694                 break;
695         case MUL:
696                 p->tn.lval *= val;
697                 break;
698         case DIV:
699                 ifval == 0 ) uerror"division by 0" );
700                 else if ( u ) p->tn.lval = (unsignedp->tn.lval / val;
701                 else p->tn.lval /= val;
702                 break;
703         case MOD:
704                 ifval == 0 ) uerror"division by 0" );
705                 else if ( u ) p->tn.lval = (unsignedp->tn.lval % val;
706                 else p->tn.lval %= val;
707                 break;
708         case AND:
709                 p->tn.lval &= val;
710                 break;
711         case OR:
712                 p->tn.lval |= val;
713                 break;
714         case ER:
715                 p->tn.lval ^= val;
716                 break;
717         case LS:
718                 i = val;
719                 p->tn.lval = p->tn.lval << i;
720                 break;
721         case RS:
722                 i = val;
723                 if ( u ) p->tn.lval = (unsignedp->tn.lval >> i;
724                 else p->tn.lval = p->tn.lval >> i;
725                 break;
726
727         case UNARY MINUS:
728                 p->tn.lval = - p->tn.lval;
729                 break;
730         case COMPL:
731                 p->tn.lval = ~p->tn.lval;
732                 break;
733         case NOT:
734                 p->tn.lval = !p->tn.lval;
735                 break;
736         case LT:
737                 p->tn.lval = p->tn.lval < val;
738                 break;
739         case LE:
740                 p->tn.lval = p->tn.lval <= val;
741                 break;
742         case GT:
743                 p->tn.lval = p->tn.lval > val;
744                 break;
745         case GE:
746                 p->tn.lval = p->tn.lval >= val;
747                 break;
748         case ULT:
749                 p->tn.lval = p->tn.lval < (unsignedval;
750                 break;
751         case ULE:
752                 p->tn.lval = p->tn.lval <= (unsignedval;
753                 break;
754         case UGT:
755                 p->tn.lval = p->tn.lval > (unsignedval;
756                 break;
757         case UGE:
758                 p->tn.lval = p->tn.lval >= (unsignedval;
759                 break;
760         case EQ:
761                 p->tn.lval = p->tn.lval == val;
762                 break;
763         case NE:
764                 p->tn.lval = p->tn.lval != val;
765                 break;
766         default:
767                 return(0);
768                 }
769         return(1);
770         }
771
ragge
1.2
772 void
ragge
1.1
773 chkpun(pregister NODE *p; {
774
775         /* checks p for the existance of a pun */
776
777         /* this is called when the op of p is ASSIGN, RETURN, CAST, COLON, or relational */
778
779         /* one case is when enumerations are used: this applies only to lint */
780         /* in the other case, one operand is a pointer, the other integer type */
781         /* we check that this integer is in fact a constant zero... */
782
783         /* in the case of ASSIGN, any assignment of pointer to integer is illegal */
784         /* this falls out, because the LHS is never 0 */
785
ragge
1.2
786         NODE *q;
787         int t1t2d1d2ref1ref2;
ragge
1.1
788
789         t1 = p->in.left->in.type;
790         t2 = p->in.right->in.type;
791
792         ift1==ENUMTY || t2==ENUMTY ) { /* check for enumerations */
793                 /* rob pike says this is obnoxious...
794                 if( logop( p->in.op ) && p->in.op != EQ && p->in.op != NE )
795                         werror( "comparison of enums" ); */
796                 ift1==ENUMTY && t2==ENUMTY ) {
797                         if ( p->in.left->fn.csiz!=p->in.right->fn.csiz )
798                                 werror"enumeration type clash, operator %s"opst[p->in.op] );
799                         return;
800                         }
801                 if ( t1 == ENUMTY ) t1 = INT;
802                 if ( t2 == ENUMTY ) t2 = INT;
803                 }
804
805         ref1 = ISPTR(t1) || ISARY(t1);
806         ref2 = ISPTR(t2) || ISARY(t2);
807
808         ifref1 ^ ref2 ){
809                 ifref1 ) q = p->in.right;
810                 else q = p->in.left;
811                 ifq->in.op != ICON || q->tn.lval != 0 ){
812                         werror"illegal combination of pointer and integer, op %s",
813                                 opst[p->in.op] );
814                 }
ragge
1.5
815         } else ifref1 ) {
ragge
1.1
816                 ift1 == t2 ) {
817                         ifp->in.left->fn.csiz != p->in.right->fn.csiz ) {
ragge
1.5
818                                 werror("illegal structure pointer combination");
ragge
1.1
819                                 return;
ragge
1.5
820                         }
ragge
1.1
821                         d1 = p->in.left->fn.cdim;
822                         d2 = p->in.right->fn.cdim;
823                         for( ;; ){
824                                 ifISARY(t1) ){
825                                         ifdimtab[d1] != dimtab[d2] ){
826                                                 werror"illegal array size combination" );
827                                                 return;
ragge
1.5
828                                         }
ragge
1.1
829                                         ++d1;
830                                         ++d2;
ragge
1.5
831                                 } else
832                                         if( !ISPTR(t1) )
833                                                 break;
ragge
1.1
834                                 t1 = DECREF(t1);
835                         }
ragge
1.5
836                 } else ift1 != INCREF(UNDEF) && t2 != INCREF(UNDEF) )
ragge
1.1
837                         werror"illegal pointer combination" );
838         }
ragge
1.5
839 }
ragge
1.1
840
841 NODE *
842 strefp ) register NODE *p; {
843
844         TWORD t;
845         int dsdscalign;
846         OFFSZ off;
847         register struct symtab *q;
848
849         /* make p->x */
850         /* this is also used to reference automatic variables */
851
852         q = &stab[p->in.right->tn.rval];
853         p->in.right->in.op = FREE;
854         p->in.op = FREE;
855         p = pconvertp->in.left );
856
857         /* make p look like ptr to x */
858
859         if( !ISPTR(p->in.type)){
860                 p->in.type = PTR+UNIONTY;
861                 }
862
863         t = INCREFq->stype );
864         d = q->dimoff;
865         s = q->sizoff;
866
867         p = maketyptds );
868
869         /* compute the offset to be added */
870
871         off = q->offset;
872         dsc = q->sclass;
873
874         ifdsc & FIELD ) {  /* normalize offset */
875                 align = ALINT;
876                 s = INT;
877                 off = (off/align)*align;
878                 }
879         ifoff != 0 ) p = clocalblockPLUSpoffconofftds ), tds ) );
880
881         p = buildtreeUNARY MULpNIL );
882
883         /* if field, build field info */
884
885         ifdsc & FIELD ){
886                 p = blockFLDpNILq->stype0q->sizoff );
887                 p->tn.rval = PKFIELDdsc&FLDSIZq->offset%align );
888                 }
889
890         returnclocal(p) );
891         }
892
ragge
1.2
893 int
ragge
1.1
894 notlval(pregister NODE *p; {
895
896         /* return 0 if p an lvalue, 1 otherwise */
897
898         again:
899
900         switchp->in.op ){
901
902         case FLD:
903                 p = p->in.left;
904                 goto again;
905
906         case UNARY MUL:
907                 /* fix the &(a=b) bug, given that a and b are structures */
908                 ifp->in.left->in.op == STASG ) return1 );
909                 /* and the f().a bug, given that f returns a structure */
910                 ifp->in.left->in.op == UNARY STCALL ||
911                     p->in.left->in.op == STCALL ) return1 );
912         case NAME:
913         case OREG:
914                 ifISARY(p->in.type) || ISFTN(p->in.type) ) return(1);
915         case REG:
916                 return(0);
917
918         default:
919                 return(1);
920
921                 }
922
923         }
924
925 NODE *
926 bconi ){ /* make a constant node with value i */
927         register NODE *p;
928
929         p = blockICONNILNILINT0INT );
930         p->tn.lval = i;
931         p->tn.rval = NONAME;
932         returnclocal(p) );
933         }
934
935 NODE *
936 bpsize(pregister NODE *p; {
937         returnoffconpsize(p), p->in.typep->fn.cdimp->fn.csiz ) );
938         }
939
940 OFFSZ
941 psizep ) NODE *p; {
942         /* p is a node of type pointer; psize returns the
943            size of the thing pointed to */
944
945         if( !ISPTR(p->in.type) ){
946                 uerror"pointer required");
947                 returnSZINT );
948                 }
949         /* note: no pointers to fields */
950         returntsizeDECREF(p->in.type), p->fn.cdimp->fn.csiz ) );
951         }
952
953 NODE *
954 convertpf )  register NODE *p; {
955         /*  convert an operand of p
956             f is either CVTL or CVTR
957             operand has type int, and is converted by the size of the other side
958             */
959
960         register NODE *q, *r;
961
962         q = (f==CVTL)?p->in.left:p->in.right;
963
964         r = blockPMCONV,
965                 qbpsize(f==CVTL?p->in.right:p->in.left), INT0INT );
966         r = clocal(r);
967         iff == CVTL )
968                 p->in.left = r;
969         else
970                 p->in.right = r;
971         return(p);
972
973         }
974
975 #ifndef econvert
ragge
1.2
976 void
ragge
1.1
977 econvertp ) register NODE *p; {
978
979         /* change enums to ints, or appropriate types */
980
981         register TWORD ty;
982
983         if( (ty=BTYPE(p->in.type)) == ENUMTY || ty == MOETY ) {
ragge
1.6
984                 if (dimtab[p->fn.csiz] == SZCHAR)
985                         ty = CHAR;
986                 else if (dimtab[p->fn.csiz] == SZINT)
987                         ty = INT;
988                 else if (dimtab[p->fn.csiz] == SZSHORT)
989                         ty = SHORT;
990                 else if (dimtab[p->fn.csiz] == SZLONGLONG)
991                         ty = LONGLONG;
992                 else
993                         ty = LONG;
994                 ty = ctype(ty);
ragge
1.1
995                 p->fn.csiz = ty;
996                 MODTYPE(p->in.type,ty);
ragge
1.6
997                 if (p->in.op == ICON && ty != LONG && ty != LONGLONG)
998                         p->in.type = p->fn.csiz = INT;
ragge
1.1
999                 }
1000         }
1001 #endif
1002
1003 NODE *
1004 pconvertp ) register NODE *p; {
1005
1006         /* if p should be changed into a pointer, do so */
1007
1008         ifISARYp->in.type) ){
1009                 p->in.type = DECREFp->in.type );
1010                 ++p->fn.cdim;
1011                 returnbuildtreeUNARY ANDpNIL ) );
1012                 }
1013         ifISFTNp->in.type) )
1014                 returnbuildtreeUNARY ANDpNIL ) );
1015
1016         returnp );
1017         }
1018
1019 NODE *
1020 oconvert(pregister NODE *p; {
1021         /* convert the result itself: used for pointer and unsigned */
1022
1023         switch(p->in.op) {
1024
1025         case LE:
1026         case LT:
1027         case GE:
1028         case GT:
1029                 ifISUNSIGNED(p->in.left->in.type) || ISUNSIGNED(p->in.right->in.type) )  p->in.op += (ULE-LE);
1030         case EQ:
1031         case NE:
1032                 returnp );
1033
1034         case MINUS:
1035                 return(  clocalblockPVCONV,
1036                         pbpsize(p->in.left), INT0INT ) ) );
1037                 }
1038
1039         cerror"illegal oconvert: %d"p->in.op );
1040
1041         return(p);
1042         }
1043
1044 NODE *
1045 ptmatch(p)  register NODE *p; {
1046
1047         /* makes the operands of p agree; they are
1048            either pointers or integers, by this time */
1049         /* with MINUS, the sizes must be the same */
1050         /* with COLON, the types must be the same */
1051
1052         TWORD t1t2t;
1053         int od2ds2s;
1054
1055         o = p->in.op;
1056         t = t1 = p->in.left->in.type;
1057         t2 = p->in.right->in.type;
1058