forked from farisawan-2000/cfront-3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpr.c
2485 lines (2289 loc) · 85.5 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
/*ident "@(#)cls4:src/expr.c 1.28" */
/*******************************************************************************
C++ source for the C++ Language System, Release 3.0. This product
is a new release of the original cfront developed in the computer
science research center of AT&T Bell Laboratories.
Copyright (c) 1993 UNIX System Laboratories, Inc.
Copyright (c) 1991, 1992 AT&T and UNIX System Laboratories, Inc.
Copyright (c) 1984, 1989, 1990 AT&T. All Rights Reserved.
THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE of AT&T and UNIX System
Laboratories, Inc. The copyright notice above does not evidence
any actual or intended publication of such source code.
expr.c:
type check expressions
************************************************************************/
#include "cfront.h"
#include "size.h"
int const_save;
extern int no_const;
extern Ptype Pfct_type;
extern Pexpr make_dot(Pexpr, Ptable, char *c = "i");
int processing_sizeof = 0;
Pexpr expr::address() {
// error('d',"address %k %d %s",base,base,base==NAME||base==ANAME?string:"?");
// error('d',"address e1 %d %k e2 %d %k", e1, e1?e1->base:0, e2, e2?e2->base:0);
switch (base) {
case DEREF:
if (e2 == 0)
return e1; // &*e => e
break;
case QUEST: // &(a?b:c) => a?&b:&c
e1 = e1->address();
// no break;
case G_CM:
if (e1 && (e1->base == G_CALL || e1->base == CALL) && e2 && e2->base == G_ADDROF)
return this;
case CM:
if (e2 && e2->base == G_CALL) { // (x,f())=>(x,(tmp=f(),&tmp))
Pname tmp = make_tmp('Q', e2->tp, cc->ftbl);
e2 = init_tmp(tmp, e2, cc->ftbl);
Pexpr aa = tmp->address();
e2 = new expr(G_CM, e2, aa);
e2->tp = aa->tp;
} else
e2 = e2->address(); // &(e1,e2) => (e1,&e2)
tp = e2->tp; // LLL
return this;
case INCR:
case DECR: // &(++a) => (++a,&a)
if (e1)
break;
nin++;
if (e2->not_simple())
error('s', "& of%k", base);
nin--;
e1 = new expr(base, 0, e2);
e2 = e2->address();
base = G_CM;
tp = e2->tp;
return this;
case ASSIGN: // &(a=b) => ((a=b),&a)
case ASPLUS:
case ASMINUS:
case ASMUL:
case ASDIV:
case ASMOD:
case ASAND:
case ASOR:
case ASER:
case ASLS:
case ASRS: {
nin++;
if (e1->not_simple())
error('s', "& of%k", base);
nin--;
Pexpr a = new expr(base, e1, e2);
a->tp = a->e1->tp;
base = G_CM;
e1 = a;
e2 = a->e1->address();
tp = e2->tp;
return this;
}
case NAME:
Pname(this)->take_addr();
if (Pname(this)->n_xref)
// function argument of class type becomes
// class* due to user-defined copy ctor
return this;
break;
case CALL:
case CAST:
case G_CAST:
case NEW:
case GNEW:
if (tp && tp->is_ptr_or_ref()) { // hack?
return this;
}
break;
}
register Pexpr ee = new expr(G_ADDROF, 0, this);
if (tp) { // tp==0 ???
ee->tp = tp->addrof();
switch (tp->base) {
case PTR:
Pptr(ee->tp)->memof = Pptr(tp)->memof;
break;
case FCT:
if (Pfct(tp)->f_static == 0)
Pptr(ee->tp)->memof = Pfct(tp)->memof;
break;
case OVERLOAD:
if (Pfct(Pgen(tp)->fct_list->f->tp)->f_static == 0)
Pptr(ee->tp)->memof = Pfct(Pgen(tp)->fct_list->f->tp)->memof;
}
}
return ee;
}
Pexpr make_dot(Pexpr e, Ptable tbl, char *c) {
if (!e->tp->memptr())
return e;
if (e->base == CM || e->base == G_CALL || e->base == CALL || e->base == ASSIGN) {
Pname atmp = make_tmp('A', e->tp, tbl);
Pexpr as = init_tmp(atmp, e, tbl);
e = new mdot(c, atmp);
e->i1 = 9;
e = new expr(G_CM, as, e);
} else if (e->base == ILIST) {
if (c[0] == 'i')
e = e->e1->e2;
if (c[0] == 'f')
e = e->e2;
} else {
e = new mdot(c, e);
e->i1 = 9;
}
return e;
}
Pexpr expr::contents() {
// error('d',"deref %k %d %t",base,base,tp);
switch (base) {
case ADDROF:
case G_ADDROF:
return e2; // *&
case ELIST:
// error('d',"contents of elist");
e1 = e1->contents();
tp = e1->tp;
return this;
};
register Pexpr ee = new expr(DEREF, this, 0);
if (tp) { // tp==0 ???
Ptype tt = tp->skiptypedefs();
ee->tp = Pptr(tt)->typ;
Pname cn = ee->tp->is_cl_obj();
if (cn) {
// look for first use of class
Pclass cl = Pclass(cn->tp);
if (cl->c_body == 1)
cl->dcl_print(0);
}
}
return ee;
}
#if 0
static Pexpr
make_postfix( Pexpr op, Pname fn=0 )
{
/* apply the postfix form of increment/decrement operator
* if (fn) special call from check_postscipt to handle
* the two operator instances declared at different scopes
* i.e., member and non-member, therefore stored as FCTs.
*/
Pfct f;
Plist fl;
Pname n = fn?fn:0;
Pexpr e = op->e1->base==NAME?op->e1:op->e1->mem;
if (n) goto mk_postfix; // sorry(!!!)
for (fl=Pgen(e->tp)->fct_list;fl; fl=fl->l) {
n = fl->f;
f = Pfct(n->tp);
if ((f->nargs==1 && f->f_this) ||
(f->nargs==2 && f->f_this==0)) {
mk_postfix: // rewrite the call expression
if (op->e1->base == NAME) {
op->e1 = n;
op->e2->e2 = new expr(ELIST,zero,0);
} else {
op->e1->mem = n;
op->e2 = new expr(ELIST,zero,0);
}
op->fct_name = n;
n->dcl_print(0);
return op;
}
}
error('w',"no postfix instance of%n, although overloaded",Pname(e));
return op; // as it were
}
static Pexpr
check_postfix( Pexpr op )
{
/* special case: member and non-member operator++/-- instances
* each stored as FCT, and so oper_overload() returns prefix instance
* need to make an explicit check if postfix instance exists
*/
int is_glob = op->e1->base==NAME ? 1: 0;
Pname fn = is_glob ? Pname(op->e1) : Pname(op->e1->mem);
// error('d',"check_postfix: fn: %n is_glob: %d",fn,is_glob);
if (is_glob == 0) { // found operator++/--() as member
Pname n = gtbl->look(fn->string,0);
Ptype arg_tp = op->e1->e1->tp;
if (n==0) return op;
if (n->tp->base == FCT) { // one global instance
Pfct ff = Pfct(n->tp);
// error('d',"check_postfix: global n:%n arg: %t act: %t",n,ff->argtype->tp,arg_tp);
extern int exact1(Pname,Ptype); // place in cfront.h
if (ff->nargs != 2) return op;
if (exact1(ff->argtype, arg_tp)==0) return op;
return make_postfix(op,n);
}
if (n->tp->base == OVERLOAD) { // multiple global instances
for (Plist fl=Pgen(n->tp)->fct_list; fl; fl=fl->l) {
Pname nn = fl->f;
Pfct ff = Pfct(nn->tp);
if (ff->nargs != 2) continue;
if (exact1(ff->argtype, arg_tp)==0) continue;
return make_postfix(op,nn);
}
return op;
}
}
else { // examine class table for postfix member
Pfct f = Pfct(fn->tp);
Pptr p = f->argtype->tp->is_ptr_or_ref();
Ptype t = p?p->typ:f->argtype->tp;
Pname cn = t->is_cl_obj();
if (cn == 0) error('i',"check_postfix: %n(%n %t),CTX",fn,f->argtype,t);
Pname nn = Pclass(cn->tp)->memtbl->look(fn->string,0);
// error('d',"check_postfix: found: %n %t", nn, nn->tp);
if (nn) return make_postfix(op,nn);
return op;
}
error('i', "fall off end of check_postfix()");
return 0;
}
#endif
int bound;
int chars_in_largest; // no of characters in largest int
static bit ptr_is_template_formal(Pptr p) {
// error('d',"ptr_is_template_formal: %t",p);
if (p->typ) {
if (p->typ->base != TYPE)
return 0;
Pname n = p->typ->bname();
return n->is_template_arg();
} else
return 0;
}
Ptype common_base(Pclass cl1, Pclass cl2)
/*
do cl1 and cl2 have one common base class?
*/
{
if (cl1 == 0 || cl2 == 0)
return 0;
if (cl1->baselist == 0 || cl2->baselist == 0)
return 0;
Pbase answer = 0;
for (Pbcl b = cl1->baselist; b; b = b->next) {
if (b->ppp != PUBLIC && !same_class(cc->cot, cl1)
&& (cc->nof == 0 || cl1->has_friend(Pfct(cc->nof->tp)) == 0)
&& (cc->cot == 0 || cl1->has_friend(cc->cot) == 0))
continue;
Nvis = 0;
if (cl2->has_base(b->bclass)) {
if (Nvis)
continue;
if (answer)
return 0;
Pname bn = new name(b->bclass->string);
bn->tp = b->bclass;
answer = new basetype(COBJ, bn);
}
}
return answer;
}
static Pexpr do_qualifiers(Ptype t, Pexpr mem)
/*
** saw ( (t*) p )->mem
** if mem has unprocessed qualifiers, look up qualifier names
*/
{
// qualifiers after . or -> processed after type of base object is known
Pname m = Pname(mem);
if (m->base != NAME && m->base != DTOR || m->n_qualifier == 0 || m->n_qualifier->base != MEMQ)
return mem;
Pname cn = t ? t->is_cl_obj() : 0;
Pname tn = 0;
Pname q = m->n_qualifier;
m->n_qualifier = 0;
if (q->string == 0) { // ->::
// error("scope qualification syntax");
do {
Pname qx = q->n_list;
delete q;
q = qx;
} while (q && q->string == 0);
if (q == 0) {
m->n_initializer = sta_name;
return mem;
}
tn = k_find_name(q->string, Gtbl, HIDDEN);
} else if (cn)
tn = k_find_name(q->string, Pclass(cn->tp)->k_tbl, HIDDEN);
else
tn = k_find_name(q->string, Ctbl, HIDDEN);
/* // check if first qualifier is a base class of cn
** if ( cn && tn ) {
** Pclass cl = Pclass(cn->tp);
** Pname qn = tn->is_cl_obj();
** if (qn && !same_class(Pclass(qn->tp),cl)) { // really a base?
** Pclass qcl = Pclass(qn->tp);
** Pclass bcl = cl->is_base(qcl->string);
** if (bcl == 0 || !same_class(bcl,qcl)) {
** error("(%n*)->%n:: --%n is not aBC of%n",cn,qn,qn,cn);
** return mem;
** }
** }
** }
*/
Pname cx = 0;
for (;;) {
if (tn == 0) {
error("%n :: --TN%n not found", q, q);
return mem;
}
cn = tn->tp->is_cl_obj();
if (cn == 0) {
// if at the final qualifier and mem is
// a dtor, mem could be a basic type dtor,
// in which case the qualifier doesn't have
// to be a class name
if (q->n_list == 0 && m->base == DTOR)
m->n_qualifier = tn;
else
error("%n :: --%n is not aCN", tn, tn);
return mem;
}
if (cx) { // cx::cn::
if (Pclass(cx->tp)->has_base(Pclass(cn->tp)))
error("%n ::%n :: --%n not aM of%n", cx, cn, cn, cx);
}
cx = cn;
{
Pname qx = q->n_list;
delete q;
q = qx;
}
if (q == 0)
break;
if (q->string == 0) { // ->X:: ::
error("scope qualification syntax");
return mem;
}
tn = k_find_member(q->string, Pclass(cn->tp), HIDDEN);
}
m->n_qualifier = tn;
return mem;
}
static Pexpr do_dtor(Ptype t, Pexpr mem) {
Pname m = Pname(mem);
// m->base == DTOR
// represents
// p->something::~something
// something::~something
// p->~something
// where t == type of *p or 0
// fields of m (see dummy_dtor() in gram.y):
// X::~Y m->n_qualifier==X m->n_dtag==Y
// int::~int m->tp2==int_type m->tpdef==int_type
// X::~int m->n_qualifier==X m->tpdef==int_type
// int::~Y m->tp2==int_type m->n_dtag==Y
// etc
Pname q = m->n_qualifier;
Pname d = m->n_dtag;
Pname cn = (t ? t->is_cl_obj() : 0);
DB(if (Edebug >= 1) {
error('d', "do_dtor: t%t b%k cn%n", t, m->base, cn);
error('d', " q%n d%n tp2%t tpdef%t", q, d, m->tp2, m->tpdef);
error('d', " qtp%t dtp%t", q->tp, d->tp);
});
if (cn) { // cp->something::~something -- look up qualifier again
// q already looked up in do_qualifiers()
if (d && d->string) {
Pclass cl = (q && q->tp->is_cl_obj()) ? q->tp->skiptypedefs()->classtype() : Pclass(cn->tp);
Pname dx = k_find_name(d->string, cl->k_tbl, HIDDEN);
if (dx == 0) {
error("TN%n not found in%t", d, t);
dx = q;
}
d = m->n_dtag = dx;
}
}
DB(if (Edebug >= 1) { error('d', " new q%n%t d%n%t", q, q ? q->tp : 0, d, d ? d->tp : 0); });
if (q) {
if (d && d->tp->check(q->tp, 0)) {
error("bad syntax for destructor call:N andQr do not match");
q = d;
} else if (m->tpdef && m->tpdef->check(q->tp, 0))
error("bad syntax for destructor call:N andQr do not match");
if (d && d->tp->is_cl_obj()) {
real_dtor:
m->base = NAME;
//// m->n_dtag = 0; // Keep n_dtag for find_name if needed.
m->tp = m->tpdef = m->tp2 = 0;
m->string = oper_name(DTOR);
m->n_oper = DTOR;
} else {
if (m->tpdef)
m->tp2 = m->tpdef;
else
m->tp2 = m->tpdef = q->tp;
m->n_qualifier = m->n_dtag = 0;
}
} else { // int::~something or p->~something
if (d && m->tp2 == 0 && d->tp->is_cl_obj()) {
goto real_dtor;
}
if (d && m->tp2 && d->tp->check(m->tp2, 0))
error("bad syntax for destructor call:N andQr do not match");
if (d) {
m->tp2 = m->tpdef = d->tp;
m->n_dtag = 0;
}
}
DB(if (Edebug >= 1) error('d', "do_dtor: returning%k%t", mem->base, mem->tp););
// If "t" is provided, check that the type of the object referenced
// agrees with the type associated with the DTOR or that the DTOR
// is an accessible base class of that object.
if (t) {
if (mem->tp2) {
// i.int::~int() or some basic type.
if (t->check(mem->tp2, 0)) {
error("T mismatch for simpleT destructor:XO ofT%t", mem->tp2);
} /* if */
} else {
if (cn) {
// The object referenced is a class object; the DTOR must be for
// the same object or at least a base class.
if (d && t->check(d->tp, 0)) {
// This was not an identical match. Check if a DTOR of a
// base class before complaining of an error.
Pname dn = (d->tp ? d->tp->is_cl_obj() : 0);
if (cn && dn) {
if (!q && !Pclass(cn->tp)->has_base(Pclass(dn->tp))) {
// The class of the DTOR is not a
// base class of the referenced object. The
// "X is not a base class of Y" message will
// be generated by find_name later in
// expr::typ().
error("bad syntax for destructor call");
} /* if */
} else {
error("T mismatch for destructor:XO ofT%t", d->tp);
} /* if */
} /* if */
} else {
error("T mismatch for destructor:XO ofT%t", d->tp);
} /* if */
} /* if */
} /* if */
return mem;
}
#define nppromote(b) t = np_promote(b, r1, r2, t1, t2, 1)
#define npcheck(b) (void) np_promote(b, r1, r2, t1, t2, 0)
Pname Ntmp_flag_list;
bit in_quest;
con_dtor *pdlist;
Pexpr expr::typ(Ptable tbl)
/*
find the type of "this" and place it in tp;
return the typechecked version of the expression:
"tbl" provides the scope for the names in "this"
*/
{
Pname n;
Ptype t = 0;
Ptype t1, t2;
TOK b = base;
TOK r1, r2;
if (tbl->base != TABLE)
error('i', "expr::typ(%d)", tbl->base);
DB(if (Tdebug >= 1) {
error('d', "%d->expr::typ(%d) %k %t", this, tbl, b, tp);
display_expr(this);
});
// error('d',"%k->typ %n tp: %t", b,b==NAME?this:0,tp);
// error('d'," e1 %d %k e1 %d %k",e1,e1?e1->base:0,e2,e2?e2->base:0);
if (tp) {
switch (b) {
case NAME:
break;
case MDOT:
mem = mem->typ(tbl);
};
return this;
}
switch (b) { // is it a basic type
case MDOT:
error('i', "mdot %s", string2);
case DUMMY:
error("emptyE");
tp = any_type;
case DTOR: // dummy type destructor
{
Pexpr e = do_dtor(0, this);
return e->base == NAME ? e->typ(tbl) : e;
}
case ZERO:
tp = zero_type;
return this;
case IVAL:
tp = int_type;
return this;
case ICON:
/* is it long?
explicit long?
decimal larger than largest signed int
octal or hexadecimal larger than largest unsigned int
*/
{
int ll = strlen(string);
switch (string[ll - 1]) {
case 'l':
case 'L':
switch (string[ll - 2]) {
case 'u':
case 'U':
string[ll - 2] = 0;
tp = ulong_type;
goto cast_n_save;
}
lng:
tp = long_type;
goto save;
case 'u':
case 'U': // 1u => unsigned(1)
switch (string[ll - 2]) {
case 'l':
case 'L':
string[ll - 2] = 0;
ulng:
tp = ulong_type;
goto cast_n_save;
default:
string[ll - 1] = 0;
labuint:
tp = uint_type;
goto cast_n_save;
}
}
// no suffix - see if we can figure it out
if (string[0] == '0') { // assume 8 bits in byte
register int index = 1;
switch (string[1]) {
case 'x':
case 'X': {
while (string[++index] == '0')
;
ll -= index;
int HSZ = SZ_INT + SZ_INT;
if (ll < HSZ)
goto nrm;
if (ll == HSZ)
if (string[2] >= '8')
goto labuint;
else
goto nrm;
if (SZ_INT == SZ_LONG)
break;
HSZ = SZ_LONG + SZ_LONG;
if (ll < HSZ)
goto lng;
if (ll == HSZ)
if (string[2] >= '8')
goto ulng;
else
goto lng;
break;
}
default: // OCTAL
{
register int IBITS = BI_IN_BYTE * SZ_INT;
while (string[index] == '0')
index++;
register char x = string[index];
int lbt = x == '1' ? 1 : (x == '2' || x == '3' ? 2 : 3);
int nbits = (ll - index - 1) * 3 + lbt;
if (nbits < IBITS)
goto nrm;
if (nbits == IBITS)
goto labuint;
if (nbits < BI_IN_BYTE * SZ_LONG)
goto lng;
}
}
goto ulng;
} else { // DECIMAL
if (ll < chars_in_largest) {
nrm:
tp = int_type;
goto save;
}
if (ll > chars_in_largest) {
if (SZ_INT == SZ_LONG || ll > 2 * chars_in_largest)
goto ulng;
goto lng;
}
// ll == chars_in_largest
char *p = string;
char *q = LARGEST_INT;
do
if (*p > *q) {
if (SZ_INT == SZ_LONG)
goto ulng;
goto lng;
}
while (*p++ == *q++ && *p);
}
goto nrm;
}
case CCON:
tp = c_strlen(string) < 5 ? char_type : int_type; // stored as 'a'
goto save;
case FCON: {
int ll = strlen(string);
int last = string[ll - 1];
tp = double_type;
if (last == 'F' || last == 'f') {
tp = float_type;
if (!ansi_opt) {
string[ll - 1] = 0;
goto cast_n_save;
}
} else if (last == 'L' || last == 'l') {
if (ansi_opt == 0)
string[ll - 1] = 0;
tp = ldouble_type;
}
goto save;
}
case STRING: // type of "as\tdf" is char[6]
// c_strlen counts the terminating '\0'
{
Pvec v = new vec(char_type, 0);
v->size = c_strlen(string);
tp = v;
}
save:
if (const_save) { // "as\tdf" needs 7 chars for storage
char *p = new char[strlen(string) + 1];
strcpy(p, string);
string = p;
}
return this;
cast_n_save:
if (const_save) { // "as\tdf" needs 7 chars for storage
char *p = new char[strlen(string) + 1];
strcpy(p, string);
string = p;
}
return new cast(tp, this);
case THIS:
delete this;
if (cc->c_this) {
cc->c_this->use();
return cc->c_this;
}
error("``this'' used in nonC context");
n = new name("this");
n->tp = any_type;
return tbl->insert(n, 0);
case NAME: {
Pname q = Pname(this)->n_qualifier; // suppress virtual iff x::
Pexpr ee = find_name(Pname(this), cc->cot, tbl, 0, cc->nof);
if (q && (ee->base == REF || ee->base == DOT))
ee->n_initializer = Pexpr(q);
if (cc->nof && Pfct(cc->nof->tp)->f_const && (ee->base == REF || ee->base == DOT) && ee->tp
&& ee->tp->skiptypedefs()->base != FCT && ee->tp->skiptypedefs()->base != OVERLOAD)
ee->tp = ee->tp->mkconst();
// error('d',"ee %k %t %n",ee->base,ee->tp,ee->base==NAME?ee:ee->base==REF?ee->mem:0);
if (ee->tp->is_ref())
return ee->contents();
if (ee->base == NAME && Pname(ee)->n_xref) {
// fudge to handle X(X&) args
ee = new expr(DEREF, ee, 0);
ee->tp = ee->e1->tp; // !!
}
return ee;
}
case ADDROF:
if (e2->base == THIS) {
error("&this");
break;
}
case G_ADDROF: // handle lookup for &s::i
if (e2->base == NAME)
e2 = find_name(Pname(e2), cc->cot, tbl, ADDROF, cc->nof);
if (cc->nof && Pfct(cc->nof->tp)->f_const && (e2->base == REF || e2->base == DOT) && e2->tp
&& e2->tp->skiptypedefs()->base != FCT && e2->tp->skiptypedefs()->base != OVERLOAD)
e2->tp = e2->tp->mkconst();
if (e2->base == NAME && Pname(e2)->n_xref) {
// fudge to handle X(X&) args
e2 = new expr(DEREF, e2, 0);
e2->tp = e2->e1->tp; // !!
}
if (e2->base == DOT) { // &f().x = > &(tmp=f(),&tmp)->x
switch (e2->e1->base) {
case CALL:
case G_CALL: {
Pcall c = Pcall(e2->e1);
if (c && c->e1) {
c->e1 = c->e1->typ(tbl);
if (c->e1->tp && Pfct(c->e1->tp)->returns->base == RPTR)
break;
}
}
case VALUE:
error("& non-lvalue");
}
}
break;
case SIZEOF:
if (tp2) {
tp2->dcl(tbl);
switch (tp2->base) {
case VOID:
error("sizeof(void)");
break;
case CLASS: {
Pclass cl = Pclass(tp2);
if (cl->c_body == 1 && (cl->defined & (DEFINED | SIMPLIFIED)) == 0)
error('s', "class defined within sizeof");
}
}
if (e1 && e1 != dummy) {
e1 = e1->typ(tbl);
DEL(e1);
e1 = dummy;
}
Pptr r = tp2->is_ref();
if (r)
tp2 = r->typ; // sizeof(T&)==sizeof(T)
} else if (e1 == dummy) {
error("sizeof emptyE");
tp = any_type;
return this;
} else {
++processing_sizeof;
e1 = e1->typ(tbl);
--processing_sizeof;
tp2 = e1->tp;
if (tp2->base == VEC)
tp2->permanent = 1;
if (e1->base == ILIST) // PtoM
e1 = dummy;
else if (tp2 == char_type) // sizeof ('a')
e1 = dummy;
}
(void) tp2->tsizeof();
if (tp2->base == VOID)
error("sizeof(void)");
tp = size_t_type;
return this;
case CAST:
case G_CAST: {
Pexpr ee = docast(tbl);
return ee->tp->is_ref() ? ee->contents() : ee;
}
case VALUE:
// SYM obsolete table hack removed
return dovalue(tbl);
case NEW:
case GNEW:
return donew(tbl);
case DELETE: // delete e1 OR delete[e2] e1
case GDELETE: {
int i;
// if (e1->base == ADDROF) error('w',"delete &E");
e1 = e1->typ(tbl);
if (e1->tp->skiptypedefs()->base == COBJ) {
Pexpr x = try_to_coerce(Pvoid_type, e1, "argument", tbl);
if (x)
e1 = x;
}
i = e1->tp->num_ptr(DELETE);
if (i != 'P')
error("nonP deleted");
if (e2) {
e2 = e2->typ(tbl);
e2->tp->integral(DELETE);
}
tp = void_type;
return this;
}
case ILIST: /* an ILIST is pointer to an ELIST */
e1 = e1->typ(tbl);
tp = any_type;
return this;
case ELIST: {
Pexpr e;
Pexpr ex;
if (e1 == dummy && e2 == 0) {
error("emptyIrL");
tp = any_type;
return this;
}
for (e = this; e; e = ex) {
Pexpr ee = e->e1;
// error('d',"e %d %d ee %d %d",e,e?e->base:0,ee,ee?ee->base:0);
if (e->base != ELIST)
error('i', "elist%k", e->base);
if (ex = e->e2) { /* look ahead for end of list */
if (ee == dummy)
error("EX in EL");
if (ex->e1 == dummy && ex->e2 == 0) {
/* { ... , } */
DEL(ex);
e->e2 = ex = 0;
}
}
e->e1 = ee->typ(tbl);
t = e->e1->tp;
if (t->base == FCT) { // yuk!
ee = new expr(G_ADDROF, 0, e->e1);
e->e1 = ee->typ(tbl);
t = e->e1->tp;
}
}
tp = t;
return this;
}
case DOT:
case REF: {
if (e2) { // .* or ->*
if (b == REF)
b = base = REFMUL;
if (e2->base == NAME && Pname(e2)->permanent != 1)
PERM(Pname(e2));
break;
}
Pbase b;
bit bcc;
e1 = e1->typ(tbl);
t = e1->tp->skiptypedefs(bcc);
if (base == DOT && e1->base == DEREF && e1->e1->base == NAME
&& is_probably_temp(Pname(e1->e1)->string))
bcc = 0;
// check that . (->) is applied to class object (pointer)
if (base == REF) {
switch (t->base) {
case COBJ: {
Pname n = t->classtype()->has_oper(REF);
if (n) {
n->n_used += 2;
e1 = new call(new ref(DOT, e1, new name(n->string)), 0);
return typ(tbl);
}
// no break;
}
default:
error("nonP ->%n", mem);
t = any_type;
// no break;
case ANY:
goto qqq;
case PTR:
case VEC:
b = Pbase(Pptr(t)->typ->skiptypedefs(bcc));
mem = do_qualifiers(b, mem);
if (mem->base == DTOR)
mem = do_dtor(b, mem);
}
} else { // base == DOT
qqq:
mem = do_qualifiers(t, mem);
switch (t->base) {
default:
if (mem->base == DTOR)
mem = do_dtor(t, mem);
if (mem->base == DTOR) // i.int::~int(), etc
break;
error("nonO .%n", mem);
t = any_type;
case ANY:
break;
case COBJ:
if (mem->base == DTOR)
mem = do_dtor(t, mem);
}
// error('d',"dot %k",e1->base);
switch (e1->base) {
case QUEST:
case ASSIGN:
case INCR:
case DECR:
case ASPLUS:
case ASMINUS:
case ASMUL:
case ASDIV:
case ASMOD:
case ASAND:
case ASOR:
case ASER:
case ASLS:
case ASRS:
case CM:
case G_CM:
base = REF;
e1 = e1->address();
break;
case CALL:
case G_CALL: