-
Notifications
You must be signed in to change notification settings - Fork 0
/
expr.c
3738 lines (3245 loc) · 70.6 KB
/
expr.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/****************************************************************
Copyright 1990 - 1996, 2000-2001 by AT&T, Lucent Technologies and Bellcore.
Permission to use, copy, modify, and distribute this software
and its documentation for any purpose and without fee is hereby
granted, provided that the above copyright notice appear in all
copies and that both that the copyright notice and this
permission notice and warranty disclaimer appear in supporting
documentation, and that the names of AT&T, Bell Laboratories,
Lucent or Bellcore or any of their entities not be used in
advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
AT&T, Lucent and Bellcore disclaim all warranties with regard to
this software, including all implied warranties of
merchantability and fitness. In no event shall AT&T, Lucent or
Bellcore be liable for any special, indirect or consequential
damages or any damages whatsoever resulting from loss of use,
data or profits, whether in an action of contract, negligence or
other tortious action, arising out of or in connection with the
use or performance of this software.
****************************************************************/
#include "defs.h"
#include "output.h"
#include "names.h"
typedef struct { double dreal, dimag; } dcomplex;
static void consbinop Argdcl((int, int, Constp, Constp, Constp));
static void conspower Argdcl((Constp, Constp, long int));
static void zdiv Argdcl((dcomplex*, dcomplex*, dcomplex*));
static tagptr mkpower Argdcl((tagptr));
static tagptr stfcall Argdcl((Namep, struct Listblock*));
extern char dflttype[26];
extern int htype;
/* little routines to create constant blocks */
Constp
#ifdef KR_headers
mkconst(t)
int t;
#else
mkconst(int t)
#endif
{
Constp p;
p = ALLOC(Constblock);
p->tag = TCONST;
p->vtype = t;
return(p);
}
/* mklogcon -- Make Logical Constant */
expptr
#ifdef KR_headers
mklogcon(l)
int l;
#else
mklogcon(int l)
#endif
{
Constp p;
p = mkconst(tylog);
p->Const.ci = l;
return( (expptr) p );
}
/* mkintcon -- Make Integer Constant */
expptr
#ifdef KR_headers
mkintcon(l)
ftnint l;
#else
mkintcon(ftnint l)
#endif
{
Constp p;
p = mkconst(tyint);
p->Const.ci = l;
return( (expptr) p );
}
/* mkaddcon -- Make Address Constant, given integer value */
expptr
#ifdef KR_headers
mkaddcon(l)
long l;
#else
mkaddcon(long l)
#endif
{
Constp p;
p = mkconst(TYADDR);
p->Const.ci = l;
return( (expptr) p );
}
/* mkrealcon -- Make Real Constant. The type t is assumed
to be TYREAL or TYDREAL */
expptr
#ifdef KR_headers
mkrealcon(t, d)
int t;
char *d;
#else
mkrealcon(int t, char *d)
#endif
{
Constp p;
p = mkconst(t);
p->Const.cds[0] = cds(d,CNULL);
p->vstg = 1;
return( (expptr) p );
}
/* mkbitcon -- Make bit constant. Reads the input string, which is
assumed to correctly specify a number in base 2^shift (where shift
is the input parameter). shift may not exceed 4, i.e. only binary,
quad, octal and hex bases may be input. */
expptr
#ifdef KR_headers
mkbitcon(shift, leng, s)
int shift;
int leng;
char *s;
#else
mkbitcon(int shift, int leng, char *s)
#endif
{
Constp p;
unsigned long m, ovfl, x, y, z;
int L32, len;
char buff[100], *s0 = s;
#ifndef NO_LONG_LONG
ULlong u;
#endif
static char *kind[3] = { "Binary", "Hex", "Octal" };
p = mkconst(TYLONG);
/* Song and dance to convert to TYQUAD only if ftnint is too small. */
m = x = y = ovfl = 0;
/* Older C compilers may not know about */
/* UL suffixes on hex constants... */
while(--leng >= 0)
if(*s != ' ') {
if (!m) {
z = x;
x = ((x << shift) | hextoi(*s++)) & ff;
if (!((x >> shift) - z))
continue;
m = (ff << (L32 = 32 - shift)) & ff;
--s;
x = z;
}
ovfl |= y & m;
y = y << shift | (x >> L32);
x = ((x << shift) | hextoi(*s++)) & ff;
}
/* Don't change the type to short for short constants, as
* that is dangerous -- there is no syntax for long constants
* with small values.
*/
p->Const.ci = (ftnint)x;
#ifndef NO_LONG_LONG
if (m) {
if (allow_i8c) {
u = y;
p->Const.ucq = (u << 32) | x;
p->vtype = TYQUAD;
}
else
ovfl = 1;
}
#else
ovfl |= m;
#endif
if (ovfl) {
if (--shift == 3)
shift = 1;
if ((len = (int)leng) > 60)
sprintf(buff, "%s constant '%.60s' truncated.",
kind[shift], s0);
else
sprintf(buff, "%s constant '%.*s' truncated.",
kind[shift], len, s0);
err(buff);
}
return( (expptr) p );
}
/* mkstrcon -- Make string constant. Allocates storage and initializes
the memory for a copy of the input Fortran-string. */
expptr
#ifdef KR_headers
mkstrcon(l, v)
int l;
char *v;
#else
mkstrcon(int l, char *v)
#endif
{
Constp p;
char *s;
p = mkconst(TYCHAR);
p->vleng = ICON(l);
p->Const.ccp = s = (char *) ckalloc(l+1);
p->Const.ccp1.blanks = 0;
while(--l >= 0)
*s++ = *v++;
*s = '\0';
return( (expptr) p );
}
/* mkcxcon -- Make complex contsant. A complex number is a pair of
values, each of which may be integer, real or double. */
expptr
#ifdef KR_headers
mkcxcon(realp, imagp)
expptr realp;
expptr imagp;
#else
mkcxcon(expptr realp, expptr imagp)
#endif
{
int rtype, itype;
Constp p;
rtype = realp->headblock.vtype;
itype = imagp->headblock.vtype;
if( ISCONST(realp) && ISNUMERIC(rtype) && ISCONST(imagp) && ISNUMERIC(itype) )
{
p = mkconst( (rtype==TYDREAL||itype==TYDREAL)
? TYDCOMPLEX : tycomplex);
if (realp->constblock.vstg || imagp->constblock.vstg) {
p->vstg = 1;
p->Const.cds[0] = ISINT(rtype)
? string_num("", realp->constblock.Const.ci)
: realp->constblock.vstg
? realp->constblock.Const.cds[0]
: dtos(realp->constblock.Const.cd[0]);
p->Const.cds[1] = ISINT(itype)
? string_num("", imagp->constblock.Const.ci)
: imagp->constblock.vstg
? imagp->constblock.Const.cds[0]
: dtos(imagp->constblock.Const.cd[0]);
}
else {
p->Const.cd[0] = ISINT(rtype)
? realp->constblock.Const.ci
: realp->constblock.Const.cd[0];
p->Const.cd[1] = ISINT(itype)
? imagp->constblock.Const.ci
: imagp->constblock.Const.cd[0];
}
}
else
{
err("invalid complex constant");
p = (Constp)errnode();
}
frexpr(realp);
frexpr(imagp);
return( (expptr) p );
}
/* errnode -- Allocate a new error block */
expptr
errnode(Void)
{
struct Errorblock *p;
p = ALLOC(Errorblock);
p->tag = TERROR;
p->vtype = TYERROR;
return( (expptr) p );
}
/* mkconv -- Make type conversion. Cast expression p into type t.
Note that casting to a character copies only the first sizeof(char)
bytes. */
expptr
#ifdef KR_headers
mkconv(t, p)
int t;
expptr p;
#else
mkconv(int t, expptr p)
#endif
{
expptr q;
int pt, charwarn = 1;
if (t >= 100) {
t -= 100;
charwarn = 0;
}
if(t==TYUNKNOWN || t==TYERROR)
badtype("mkconv", t);
pt = p->headblock.vtype;
/* Casting to the same type is a no-op */
if(t == pt)
return(p);
/* If we're casting a constant which is not in the literal table ... */
else if( ISCONST(p) && pt!=TYADDR && pt != TYCHAR
|| p->tag == TADDR && p->addrblock.uname_tag == UNAM_CONST)
{
#ifndef NO_LONG_LONG
if (t != TYQUAD && pt != TYQUAD) /*20010820*/
#endif
if (ISINT(t) && ISINT(pt) || ISREAL(t) && ISREAL(pt)) {
/* avoid trouble with -i2 */
p->headblock.vtype = t;
return p;
}
q = (expptr) mkconst(t);
consconv(t, &q->constblock, &p->constblock );
if (p->tag == TADDR)
q->constblock.vstg = p->addrblock.user.kludge.vstg1;
frexpr(p);
}
else {
if (pt == TYCHAR && t != TYADDR && charwarn
&& (!halign || p->tag != TADDR
|| p->addrblock.uname_tag != UNAM_CONST))
warn(
"ichar([first char. of] char. string) assumed for conversion to numeric");
q = opconv(p, t);
}
if(t == TYCHAR)
q->constblock.vleng = ICON(1);
return(q);
}
/* opconv -- Convert expression p to type t using the main
expression evaluator; returns an OPCONV expression, I think 14-jun-88 mwm */
expptr
#ifdef KR_headers
opconv(p, t)
expptr p;
int t;
#else
opconv(expptr p, int t)
#endif
{
expptr q;
if (t == TYSUBR)
err("illegal use of subroutine name");
q = mkexpr(OPCONV, p, ENULL);
q->headblock.vtype = t;
return(q);
}
/* addrof -- Create an ADDR expression operation */
expptr
#ifdef KR_headers
addrof(p)
expptr p;
#else
addrof(expptr p)
#endif
{
return( mkexpr(OPADDR, p, ENULL) );
}
/* cpexpr - Returns a new copy of input expression p */
tagptr
#ifdef KR_headers
cpexpr(p)
tagptr p;
#else
cpexpr(tagptr p)
#endif
{
tagptr e;
int tag;
chainp ep, pp;
/* This table depends on the ordering of the T macros, e.g. TNAME */
static int blksize[ ] =
{
0,
sizeof(struct Nameblock),
sizeof(struct Constblock),
sizeof(struct Exprblock),
sizeof(struct Addrblock),
sizeof(struct Primblock),
sizeof(struct Listblock),
sizeof(struct Impldoblock),
sizeof(struct Errorblock)
};
if(p == NULL)
return(NULL);
/* TNAMEs are special, and don't get copied. Each name in the current
symbol table has a unique TNAME structure. */
if( (tag = p->tag) == TNAME)
return(p);
e = cpblock(blksize[p->tag], (char *)p);
switch(tag)
{
case TCONST:
if(e->constblock.vtype == TYCHAR)
{
e->constblock.Const.ccp =
copyn((int)e->constblock.vleng->constblock.Const.ci+1,
e->constblock.Const.ccp);
e->constblock.vleng =
(expptr) cpexpr(e->constblock.vleng);
}
case TERROR:
break;
case TEXPR:
e->exprblock.leftp = (expptr) cpexpr(p->exprblock.leftp);
e->exprblock.rightp = (expptr) cpexpr(p->exprblock.rightp);
break;
case TLIST:
if(pp = p->listblock.listp)
{
ep = e->listblock.listp =
mkchain((char *)cpexpr((tagptr)pp->datap), CHNULL);
for(pp = pp->nextp ; pp ; pp = pp->nextp)
ep = ep->nextp =
mkchain((char *)cpexpr((tagptr)pp->datap),
CHNULL);
}
break;
case TADDR:
e->addrblock.vleng = (expptr) cpexpr(e->addrblock.vleng);
e->addrblock.memoffset = (expptr)cpexpr(e->addrblock.memoffset);
e->addrblock.istemp = NO;
break;
case TPRIM:
e->primblock.argsp = (struct Listblock *)
cpexpr((expptr)e->primblock.argsp);
e->primblock.fcharp = (expptr) cpexpr(e->primblock.fcharp);
e->primblock.lcharp = (expptr) cpexpr(e->primblock.lcharp);
break;
default:
badtag("cpexpr", tag);
}
return(e);
}
/* frexpr -- Free expression -- frees up memory used by expression p */
void
#ifdef KR_headers
frexpr(p)
tagptr p;
#else
frexpr(tagptr p)
#endif
{
chainp q;
if(p == NULL)
return;
switch(p->tag)
{
case TCONST:
if( ISCHAR(p) )
{
free( (charptr) (p->constblock.Const.ccp) );
frexpr(p->constblock.vleng);
}
break;
case TADDR:
if (p->addrblock.vtype > TYERROR) /* i/o block */
break;
frexpr(p->addrblock.vleng);
frexpr(p->addrblock.memoffset);
break;
case TERROR:
break;
/* TNAME blocks don't get free'd - probably because they're pointed to in
the hash table. 14-Jun-88 -- mwm */
case TNAME:
return;
case TPRIM:
frexpr((expptr)p->primblock.argsp);
frexpr(p->primblock.fcharp);
frexpr(p->primblock.lcharp);
break;
case TEXPR:
frexpr(p->exprblock.leftp);
if(p->exprblock.rightp)
frexpr(p->exprblock.rightp);
break;
case TLIST:
for(q = p->listblock.listp ; q ; q = q->nextp)
frexpr((tagptr)q->datap);
frchain( &(p->listblock.listp) );
break;
default:
badtag("frexpr", p->tag);
}
free( (charptr) p );
}
void
#ifdef KR_headers
wronginf(np)
Namep np;
#else
wronginf(Namep np)
#endif
{
int c;
ftnint k;
warn1("fixing wrong type inferred for %.65s", np->fvarname);
np->vinftype = 0;
c = letter(np->fvarname[0]);
if ((np->vtype = impltype[c]) == TYCHAR
&& (k = implleng[c]))
np->vleng = ICON(k);
}
/* fix up types in expression; replace subtrees and convert
names to address blocks */
expptr
#ifdef KR_headers
fixtype(p)
tagptr p;
#else
fixtype(tagptr p)
#endif
{
if(p == 0)
return(0);
switch(p->tag)
{
case TCONST:
if(ONEOF(p->constblock.vtype,MSKINT|MSKLOGICAL|MSKADDR|
MSKREAL) )
return( (expptr) p);
return( (expptr) putconst((Constp)p) );
case TADDR:
p->addrblock.memoffset = fixtype(p->addrblock.memoffset);
return( (expptr) p);
case TERROR:
return( (expptr) p);
default:
badtag("fixtype", p->tag);
/* This case means that fixexpr can't call fixtype with any expr,
only a subexpr of its parameter. */
case TEXPR:
if (((Exprp)p)->typefixed)
return (expptr)p;
return( fixexpr((Exprp)p) );
case TLIST:
return( (expptr) p );
case TPRIM:
if(p->primblock.argsp && p->primblock.namep->vclass!=CLVAR)
{
if(p->primblock.namep->vtype == TYSUBR)
{
err("function invocation of subroutine");
return( errnode() );
}
else {
if (p->primblock.namep->vinftype)
wronginf(p->primblock.namep);
return( mkfunct(p) );
}
}
/* The lack of args makes p a function name, substring reference
or variable name. */
else return mklhs((struct Primblock *) p, keepsubs);
}
}
int
#ifdef KR_headers
badchleng(p)
expptr p;
#else
badchleng(expptr p)
#endif
{
if (!p->headblock.vleng) {
if (p->headblock.tag == TADDR
&& p->addrblock.uname_tag == UNAM_NAME)
errstr("bad use of character*(*) variable %.60s",
p->addrblock.user.name->fvarname);
else
err("Bad use of character*(*)");
return 1;
}
return 0;
}
static expptr
#ifdef KR_headers
cplenexpr(p)
expptr p;
#else
cplenexpr(expptr p)
#endif
{
expptr rv;
if (badchleng(p))
return ICON(1);
rv = cpexpr(p->headblock.vleng);
if (ISCONST(p) && p->constblock.vtype == TYCHAR)
rv->constblock.Const.ci += p->constblock.Const.ccp1.blanks;
return rv;
}
/* special case tree transformations and cleanups of expression trees.
Parameter p should have a TEXPR tag at its root, else an error is
returned */
expptr
#ifdef KR_headers
fixexpr(p)
Exprp p;
#else
fixexpr(Exprp p)
#endif
{
expptr lp, rp, q;
char *hsave;
int opcode, ltype, rtype, ptype, mtype;
if( ISERROR(p) || p->typefixed )
return( (expptr) p );
else if(p->tag != TEXPR)
badtag("fixexpr", p->tag);
opcode = p->opcode;
/* First set the types of the left and right subexpressions */
lp = p->leftp;
if (!ISCONST(lp) || lp->constblock.vtype != TYCHAR)
lp = p->leftp = fixtype(lp);
ltype = lp->headblock.vtype;
if(opcode==OPASSIGN && lp->tag!=TADDR)
{
err("left side of assignment must be variable");
eret:
frexpr((expptr)p);
return( errnode() );
}
if(rp = p->rightp)
{
if (!ISCONST(rp) || rp->constblock.vtype != TYCHAR)
rp = p->rightp = fixtype(rp);
rtype = rp->headblock.vtype;
}
else
rtype = 0;
if(ltype==TYERROR || rtype==TYERROR)
goto eret;
/* Now work on the whole expression */
/* force folding if possible */
if( ISCONST(lp) && (rp==NULL || ISCONST(rp)) )
{
q = opcode == OPCONV && lp->constblock.vtype == p->vtype
? lp : mkexpr(opcode, lp, rp);
/* mkexpr is expected to reduce constant expressions */
if( ISCONST(q) ) {
p->leftp = p->rightp = 0;
frexpr((expptr)p);
return(q);
}
free( (charptr) q ); /* constants did not fold */
}
if( (ptype = cktype(opcode, ltype, rtype)) == TYERROR)
goto eret;
if (ltype == TYCHAR && ISCONST(lp)) {
if (opcode == OPCONV) {
hsave = halign;
halign = 0;
lp = (expptr)putconst((Constp)lp);
halign = hsave;
}
else
lp = (expptr)putconst((Constp)lp);
p->leftp = lp;
}
if (rtype == TYCHAR && ISCONST(rp))
p->rightp = rp = (expptr)putconst((Constp)rp);
switch(opcode)
{
case OPCONCAT:
if(p->vleng == NULL)
p->vleng = mkexpr(OPPLUS, cplenexpr(lp),
cplenexpr(rp) );
break;
case OPASSIGN:
if (rtype == TYREAL || ISLOGICAL(ptype)
|| rtype == TYDREAL && ltype == TYREAL && !ISCONST(rp))
break;
case OPPLUSEQ:
case OPSTAREQ:
if(ltype == rtype)
break;
if( ! ISCONST(rp) && ISREAL(ltype) && ISREAL(rtype) )
break;
if( ISCOMPLEX(ltype) || ISCOMPLEX(rtype) )
break;
if( ONEOF(ltype, MSKADDR|MSKINT) && ONEOF(rtype, MSKADDR|MSKINT)
&& typesize[ltype]>=typesize[rtype] )
break;
/* Cast the right hand side to match the type of the expression */
p->rightp = fixtype( mkconv(ptype, rp) );
break;
case OPSLASH:
if( ISCOMPLEX(rtype) )
{
p = (Exprp) call2(ptype,
/* Handle double precision complex variables */
(char*)(ptype == TYCOMPLEX ? "c_div" : "z_div"),
mkconv(ptype, lp), mkconv(ptype, rp) );
break;
}
case OPPLUS:
case OPMINUS:
case OPSTAR:
case OPMOD:
if(ptype==TYDREAL && ( (ltype==TYREAL && ! ISCONST(lp) ) ||
(rtype==TYREAL && ! ISCONST(rp) ) ))
break;
if( ISCOMPLEX(ptype) )
break;
/* Cast both sides of the expression to match the type of the whole
expression. */
if(ltype != ptype && (ltype < TYINT1 || ptype > TYDREAL))
p->leftp = fixtype(mkconv(ptype,lp));
if(rtype != ptype && (rtype < TYINT1 || ptype > TYDREAL))
p->rightp = fixtype(mkconv(ptype,rp));
break;
case OPPOWER:
rp = mkpower((expptr)p);
if (rp->tag == TEXPR)
rp->exprblock.typefixed = 1;
return rp;
case OPLT:
case OPLE:
case OPGT:
case OPGE:
case OPEQ:
case OPNE:
if(ltype == rtype)
break;
if (htype) {
if (ltype == TYCHAR) {
p->leftp = fixtype(mkconv(rtype,lp));
break;
}
if (rtype == TYCHAR) {
p->rightp = fixtype(mkconv(ltype,rp));
break;
}
}
mtype = cktype(OPMINUS, ltype, rtype);
if(mtype==TYDREAL && (ltype==TYREAL || rtype==TYREAL))
break;
if( ISCOMPLEX(mtype) )
break;
if(ltype != mtype)
p->leftp = fixtype(mkconv(mtype,lp));
if(rtype != mtype)
p->rightp = fixtype(mkconv(mtype,rp));
break;
case OPCONV:
ptype = cktype(OPCONV, p->vtype, ltype);
if(lp->tag==TEXPR && lp->exprblock.opcode==OPCOMMA
&& !ISCOMPLEX(ptype))
{
lp->exprblock.rightp =
fixtype( mkconv(ptype, lp->exprblock.rightp) );
free( (charptr) p );
p = (Exprp) lp;
}
break;
case OPADDR:
if(lp->tag==TEXPR && lp->exprblock.opcode==OPADDR)
Fatal("addr of addr");
break;
case OPCOMMA:
case OPQUEST:
case OPCOLON:
break;
case OPMIN:
case OPMAX:
case OPMIN2:
case OPMAX2:
case OPDMIN:
case OPDMAX:
case OPABS:
case OPDABS:
ptype = p->vtype;
break;
default:
break;
}
p->vtype = ptype;
p->typefixed = 1;
return((expptr) p);
}
/* fix an argument list, taking due care for special first level cases */
int
#ifdef KR_headers
fixargs(doput, p0)
int doput;
struct Listblock *p0;
#else
fixargs(int doput, struct Listblock *p0)
#endif
/* doput is true if constants need to be passed by reference */
{
chainp p;
tagptr q, t;
int qtag, nargs;
nargs = 0;
if(p0)
for(p = p0->listp ; p ; p = p->nextp)
{
++nargs;
q = (tagptr)p->datap;
qtag = q->tag;
if(qtag == TCONST)
{
/* Call putconst() to store values in a constant table. Since even
constants must be passed by reference, this can optimize on the storage
required */
p->datap = doput ? (char *)putconst((Constp)q)
: (char *)q;
continue;
}
/* Take a function name and turn it into an Addr. This only happens when
nothing else has figured out the function beforehand */
if (qtag == TPRIM && q->primblock.argsp == 0) {
if (q->primblock.namep->vclass==CLPROC
&& q->primblock.namep->vprocclass != PTHISPROC) {
p->datap = (char *)mkaddr(q->primblock.namep);
continue;
}
if (q->primblock.namep->vdim != NULL) {
p->datap = (char *)mkscalar(q->primblock.namep);
if ((q->primblock.fcharp||q->primblock.lcharp)
&& (q->primblock.namep->vtype != TYCHAR
|| q->primblock.namep->vdim))
sserr(q->primblock.namep);
continue;
}
if (q->primblock.namep->vdovar
&& (t = (tagptr) memversion(q->primblock.namep))) {
p->datap = (char *)fixtype(t);
continue;
}
}
p->datap = (char *)fixtype(q);
}
return(nargs);
}
/* mkscalar -- only called by fixargs above, and by some routines in
io.c */
Addrp
#ifdef KR_headers
mkscalar(np)
Namep np;
#else
mkscalar(Namep np)
#endif
{