forked from farisawan-2000/cfront-3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimpl2.c
2836 lines (2559 loc) · 91.8 KB
/
simpl2.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/simpl2.c 1.39" */
/*******************************************************************************
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.
simpl2.c:
simplify the typechecked function
remove: classes:
class fct-calls
operators
value constructors and destructors
new and delete operators (replace with function calls)
initializers (turn them into statements)
constant expressions (evaluate them)
inline functions (expand the calls)
enums (make const ints)
unreachable code (delete it)
make implicit coersions explicit
in general you cannot simplify something twice
*******************************************************************/
#include "cfront.h"
#include "size.h"
#include <ctype.h>
extern Plist inllist;
Pname find_vptr(Pclass);
extern int is_probably_temp(char *);
extern int no_of_returns;
extern Pname new_fct;
// extern Pname del_fct;
extern Pstmt del_list;
extern Pstmt break_del_list;
extern Pstmt continue_del_list;
extern Pname curr_fct; // current function
extern Pexpr init_list;
extern int imeasure;
Ptype unconst_type(Ptype tp) {
if (!ansi_opt || !tp || !tp->tconst())
return tp;
Ptype curr, t = tp->skiptypedefs();
switch (t->base) {
case VEC:
case FCT:
case OVERLOAD:
return tp;
case PTR:
case RPTR:
curr = new ptr(0, 0);
*(Pptr) curr = *(Pptr) t;
break;
default:
curr = new basetype(0, 0);
*(Pbase) curr = *(Pbase) t;
break;
}
curr->ansi_const = 1;
return curr;
}
bit return_nrv(Pexpr e)
/*
is thing being returned from RETURN stmt __result?
*/
{
if (e->base == DEREF && e->e1->base == NAME && strcmp(Pname(e->e1)->string, "_result") == 0)
return 1;
return 0;
}
Pexpr cdvec(Pname f, Pexpr vec, Pclass cl, Pname cd, int tail, Pexpr i, Pexpr vec2)
/*
generate a call to construct or destroy the elements of a vector
*/
{
// error('d',"cdvec: (f %n cl %t cd %n)",f,cl,cd);
Pexpr sz = new texpr(SIZEOF, cl, 0); // sizeof elem
sz->tp = uint_type;
(void) cl->tsizeof();
Pexpr esz = new texpr(SIZEOF, cl, 0); // noe = sizeof(vec)/sizeof(elem)
esz->tp = int_type;
Pexpr noe;
if (vec2)
noe = new texpr(SIZEOF, vec2->tp, 0);
else
noe = new texpr(SIZEOF, vec->tp, 0);
// Pexpr noe = new texpr(SIZEOF,vec->tp,0);
noe->tp = int_type;
noe = new expr(DIV, noe, esz);
noe->tp = uint_type;
// error('d',"cdvec tail %d i %d",tail,i);
// Pexpr arg = (0<=tail) ? new expr(ELIST,zero,0) : 0; // 0 or 1 for dtors
Pexpr arg = (i) ? new expr(ELIST, i, 0) : 0;
arg = (0 <= tail) ? new expr(ELIST, zero, arg) : arg; // 0 or 1 for dtors
arg = new expr(ELIST, new texpr(G_CAST, Pvoid_type, cd), arg); // constructor or destructor
cd->lval(ADDROF); // cd->take_addr();
arg = new expr(ELIST, sz, arg);
arg = new expr(ELIST, noe, arg);
arg = new expr(ELIST, new texpr(G_CAST, Pvoid_type, vec), arg);
arg = new call(f, arg);
arg->base = G_CALL;
arg->fct_name = f;
return arg;
}
/*
int new_used; // pre-define new and delete only if the user didn't
void new_init()
{
char* ns = oper_name(NEW);
char* ds = oper_name(DELETE);
new_used = 1;
new_fct = gtbl->look(ns,0);
del_fct = gtbl->look(ds,0);
if (new_fct && !del_fct)
error('w',"%n defined but not operator delete()",new_fct);
if (del_fct && !new_fct)
error('w',"%n defined but not operator new()",del_fct);
if (Pfct(new_fct->tp)->body==0) new_fct->dcl_print(0);
if (Pfct(del_fct->tp)->body==0) del_fct->dcl_print(0);
}
*/
Pstmt trim_tail(Pstmt tt)
/*
strip off statements after RETURN etc.
NOT general: used for stripping off spurious destructor calls
*/
{
if (tt == 0)
return 0;
while (tt->s_list) {
Pstmt tpx;
switch (tt->base) {
case PAIR:
tpx = trim_tail(tt->s2);
goto tpxl;
case BLOCK:
tpx = trim_tail(tt->s);
tpxl:
if (tpx == 0)
return 0;
switch (tpx->base) {
case SM:
break;
case CONTINUE:
case BREAK:
case GOTO:
case RETURN:
if (tt->s_list->base != LABEL)
tt->s_list = 0;
default:
return tpx;
}
default:
if (tt = tt->s_list)
break;
return 0;
case RETURN:
if (tt->s_list->base != LABEL)
tt->s_list = 0;
return tt;
}
}
switch (tt->base) {
case PAIR:
return trim_tail(tt->s2);
// case LABEL: return trim_tail(tt->s);
case BLOCK:
if (tt->s)
return trim_tail(tt->s);
default:
return tt;
}
}
extern Ptype Pfct_type;
Pexpr mptr_assign(Pexpr n, Pexpr in) {
Pexpr i1;
Pexpr i2;
Pexpr i3;
if (n->base == NAME)
Pname(n)->use();
if (in->base == NAME) {
i1 = new mdot("d", in);
i1->i1 = 9;
i2 = new mdot("i", in);
i2->i1 = 9;
i3 = new mdot("f", in);
i3->i1 = 9;
} else if (in->base == ZERO) {
i1 = zero;
i2 = zero;
i3 = zero;
} else {
i1 = in->e1->e1 ? in->e1->e1 : zero;
i2 = in->e1->e2 ? in->e1->e2 : zero;
i3 = in->e2 ? in->e2 : zero;
}
Pexpr nd = new mdot("d", n);
nd->i1 = 9;
Pexpr e1 = new expr(ASSIGN, nd, i1);
Pexpr ni = new mdot("i", n);
ni->i1 = 9;
Pexpr e2 = new expr(ASSIGN, ni, i2);
Pexpr nf = new mdot("f", n);
nf->i1 = 9;
Pexpr e3 = new expr(ASSIGN, nf, i3);
Pexpr ee = new expr(CM, e2, e3);
return new expr(CM, e1, ee);
}
/*
* to move up dtors in &&, || and ?: expressions
* need to keep track of temporaries handled
* not to destroy twice :: recognized in expr::typ
* actual rewriting is initiated in stmt::simpl
* need_lift_dtors(): predicate: yes, proceed
* make_dtor_expr(): create dtor expr
* find_temps_in_expr(): temporaries to make_dtor
* lift_dtor(): actually rewrite the &&/||/?: expression
* interestingly enough, temporary generated in ?: can
* be a class object itself, requiring a dtor call --
* purpose of tmp_dtor, and mk_dtor_for_temp
*/
Ptable tmp_tbl;
static Pname tmp_list;
static Ptable Ntmp_tbl; // if Cstmt set, use Cstmt->memtbl
static Pstmt tmp_dtor;
bit need_lift;
Pexpr Ntmp_dtor;
static bit need_lift_dtors(Pexpr e) { // confirm that expression requires lifting
// error('d',"need_lift_dtors( %d %k )", e, e->base);
Pexpr ee, ex;
for (ex = Ntmp_dtor; ex; ex = ex->e2) {
ee = ex->e1;
if (ee == e)
break;
}
if (!ex)
return 0;
return 1;
}
static Pexpr make_dtor_expr(Pname nl) {
Pexpr dl = 0;
Pname n;
for (n = nl; n; n = n->n_list) {
// error('d',"make_dtor_expr: nl: %n", n );
// if (tmp_tbl->look(n->string,0)) continue;
tmp_tbl->insert_copy(n, 0);
Pname cln = n->tp->is_cl_obj();
Pname d = Pclass(cln->tp)->has_dtor();
Pexpr e = call_dtor(n, d, 0, DOT, one);
if (dl == 0)
dl = e;
else {
dl = new expr(CM, dl, e);
dl->tp = e->tp;
}
}
dl->simpl();
return dl;
}
static int prune;
static void find_temps_in_expr(Pexpr e, char *s = 0) {
if (e == 0)
return;
switch (e->base) {
case ANDAND:
case OROR:
case QUEST:
if (prune)
return;
if (s && tmp_list)
return;
find_temps_in_expr(e->cond, s); // no break
default:
if (s && tmp_list)
return;
find_temps_in_expr(e->e1, s);
if (s && tmp_list)
return;
find_temps_in_expr(e->e2, s);
return;
case REF:
case DOT:
if (s && tmp_list)
return;
find_temps_in_expr(e->e1, s); // no break
case MDOT:
// find_temps_in_expr( e->mem ); // no break
case SIZEOF:
case ZERO:
case TNAME:
case STRING:
case ICON:
case ID:
case FCON:
case CCON:
case IVAL:
case BLOCK:
case ANAME:
case TEXT:
return;
case NAME: {
Pname n = Pname(e);
Pname cln = n->tp->is_cl_obj();
if (cln && Pclass(cln->tp)->has_dtor() && is_probably_temp(n->string)) {
// error('d',"find_temps_in_expr n %n s %s", n,s);
if (s) {
if (strcmp(s, n->string) == 0)
tmp_list = n;
return;
}
if (tmp_list == 0)
tmp_list = n;
else {
Pname nn = tmp_list;
if (n == nn)
return;
while (nn->n_list) {
nn = nn->n_list;
if (n == nn)
return;
}
nn->n_list = n;
}
}
return;
}
}
}
static bit find_in_Ntmp(char *s) { // does `s' occur within Ntmp
// error('d',"find_in_ntmp( %s )", s);
Pexpr ee, ex;
tmp_list = 0;
for (ex = Ntmp_dtor; ex; ex = ex->e2) {
ee = ex->e1;
// error('d',"find_in_Ntmp : find_temps_in_expr(%k, %s)",ee?ee->base:0,s);
// display_expr(ee,"ee");
find_temps_in_expr(ee, s);
if (tmp_list) {
tmp_list = 0;
return 1;
}
}
return 0;
}
static void mk_dtor_for_temp(Pname tmp, Pname dtor) {
// error('d',"mk_dtor_for_temp: %n dtor: %n", tmp,dtor);
Pexpr dl = call_dtor(tmp, dtor, 0, DOT, one);
Pstmt dls = new estmt(SM, tmp->where, dl, 0);
if (tmp_dtor) {
dls->s_list = tmp_dtor;
tmp_dtor = dls;
} else
tmp_dtor = dls;
}
static Pexpr lift_dtors(Pexpr e, Ptable tbl) { // find class object temporaries in expression: &&,||,?:
// error('d',"lift_dtor(operators): e: %k", e->base);
prune = 1;
tmp_list = 0;
find_temps_in_expr(e->e1);
prune = 0;
Pname n1 = tmp_list;
tmp_list = 0;
prune = 1;
find_temps_in_expr(e->e2);
prune = 0;
Pname n2 = tmp_list;
tmp_list = 0;
// generate dtor calls and rewrite expressions
if (tbl == 0)
tbl = scope;
Ptype t = 0;
Pname tmp = 0;
Pexpr ex;
Pexpr dl = make_dtor_expr(n1);
if (dl) {
t = e->e1->tp;
tmp = make_tmp('Q', t, tbl);
tmp->n_assigned_to++;
ex = new expr(ASSIGN, tmp, e->e1);
ex->tp = t;
e->e1 = ex;
e->e1->tp = t;
e->e1 = new expr(CM, e->e1, dl);
e->e1->tp = dl->tp;
e->e1 = new expr(CM, e->e1, tmp);
e->e1->tp = t;
}
dl = make_dtor_expr(n2);
if (dl) {
// reuse same temp if possible
if (e->e2->tp != t) {
t = e->e2->tp;
tmp = make_tmp('Q', t, tbl);
}
tmp->n_assigned_to++;
ex = new expr(ASSIGN, tmp, e->e2);
ex->tp = t;
e->e2 = ex;
e->e2->tp = t;
e->e2 = new expr(CM, e->e2, dl);
e->e2->tp = dl->tp;
e->e2 = new expr(CM, e->e2, tmp);
e->e2->tp = t;
}
// ?: can generate a class temporary -- and although it is in
// the proper table, generating a call to its destructor has
// to be done by hand -- the relevant code in block::simpl
// has already been executed. since ?: must return the same
// type, we are assured only one `tmp' has been generated...
Pname cn;
Pname d;
if (e->base == QUEST && (cn = t->is_cl_obj()) && (d = Pclass(cn->tp)->has_dtor()))
mk_dtor_for_temp(tmp, d);
return e;
}
static Pexpr lift_dtors(Pexpr &e, Ptable tbl, TOK) { // for loop condition; for(;e;;)
// error('d',"lift_dtor(for loop): e: %k",e->base);
prune = 1;
tmp_list = 0;
find_temps_in_expr(e);
prune = 0;
Pname n1 = tmp_list;
tmp_list = 0;
// generate dtor calls and rewrite expressions
if (tbl == 0)
tbl = scope;
Pexpr dl = make_dtor_expr(n1);
if (dl) {
Ptype t = e->tp;
Pname tmp = make_tmp('Q', t, tbl);
tmp->n_assigned_to++;
Pexpr ex = new expr(ASSIGN, tmp, e);
ex->tp = t;
e = ex;
e->tp = t;
e = new expr(CM, e, dl);
e->tp = dl->tp;
e = new expr(CM, e, tmp);
e->tp = t;
}
return e;
}
Pstmt block::simpl() {
int i;
Pname n;
Pstmt ss = 0, sst = 0;
Pstmt dd = 0, ddt = 0;
Pstmt stail;
Ptable old_scope = scope;
char *fudge_007 = 0; // license to hack
// need_lift = 0;
if (!need_lift)
tmp_tbl->reinit();
DB(if (Sdebug >= 1) error('d', "%d->block::simple() own_tbl %d memtbl %d curr_fct%n", this,
own_tbl, memtbl, curr_fct););
// error('d',"%d->block::simpl() own_tbl %d memtbl %d curr_fct%n",this,own_tbl,memtbl,curr_fct);
if (own_tbl == 0) {
ss = (s) ? s->simpl() : 0;
return ss;
}
Pfct f = curr_fct->fct_type();
scope = memtbl;
if (scope->init_stat == 0)
scope->init_stat = 1; /* table is simplified. */
for (n = scope->get_mem(i = 1); n; NEXT_NAME(scope, n, i)) {
Pstmt st = 0;
bit is_nrv = !strcmp(n->string, "__NRV");
Pname cln;
Pexpr in = n->n_initializer;
// error('d',"local %k %n in %k %t",n->n_sto,n,in?in->base:0,in?in->tp:0);
if (in || n->n_evaluated) {
scope->init_stat = 2; /* initializer in this scope */
if (n->n_sto == EXTERN) {
error(&n->where, "Id local extern%n", n);
continue;
}
}
switch (n->n_scope) {
case ARG:
case 0:
case PUBLIC:
continue;
}
if (n->n_stclass == STATIC) { // local static class object
/* initialization of local static objects;
* set up first pass switch
* temp_switch ? 0
* : (stat_obj=init_expr, temp_switch=1);
*
* ARGS: temporary class object in init_expr with dtor
* must call dtor once in std function
*/
if ((in == 0 && n->n_scope == ARGS) || (in && in->base == STAT_INIT)) {
Pname cn;
Pname x;
Ptype ct;
int vec_seen = 0;
cn = n->tp->is_cl_obj();
if (cn == 0) {
++vec_seen;
cn = cl_obj_vec;
}
if (cn) {
ct = new ptr(PTR, vec_seen ? Pvec(n->tp)->typ : n->tp);
x = make_tmp('F', ct, gtbl);
// x->n_initializer = zero;
x->n_initializer = mk_zero_init(x->tp, n, n);
} else
x = make_tmp('F', int_type, scope);
x->n_sto = n->n_stclass = STATIC;
x->where = n->where;
if (in) {
if (in->e2)
in->base = ASSIGN;
else
in = in->e1;
}
Pexpr set;
if (cn) {
x->dcl_print(0);
Pclass cl = Pclass(cn->tp);
Pname dtor = cl->has_dtor();
Pexpr cc;
if (dtor) {
if (vec_seen == 0) {
Pexpr eee = new expr(DEREF, x, 0);
Pexpr c = call_dtor(eee, dtor, 0, DOT, one);
c->tp = any_type;
Pexpr e4;
if (ansi_opt) {
e4 = new expr(G_CM, c, zero);
e4->tp = zero_type;
} else {
e4 = c;
}
cc = new expr(QUEST, e4, zero);
cc->cond = x;
} else
cc = cdvec(vec_del_fct, x, cl, dtor, 0, zero, n);
cc->tp = any_type; // arghh!
Pstmt dls = new estmt(SM, n->where, cc, 0);
if (st_dlist)
dls->s_list = st_dlist;
st_dlist = dls;
}
Pexpr xe;
if (cn) {
if (vec_seen == 0)
xe = new expr(G_ADDROF, 0, n);
else {
Pexpr ee = new expr(DEREF, n, zero);
xe = new expr(G_ADDROF, 0, ee);
}
}
set = new expr(ASSIGN, x, xe);
set->tp = ct;
} else {
set = new expr(ASSIGN, x, one);
set->tp = int_type;
}
// set pointer to static object and continue.
// sorry for goto, but beats rewriting code.
if (n->n_scope == ARGS && in == 0) {
set = new expr(QUEST, zero, set);
set->cond = x;
st = new estmt(SM, n->where, set, 0);
goto init_stat3;
}
if (one == set->e2)
in = new expr(G_CM, set, in);
else
in = new expr(G_CM, in, set);
in = new expr(STAT_INIT, zero, in);
in->cond = x;
} else
continue;
}
if (in) {
if ((in->base == ILIST && in->e2 == 0)
|| (in->base == STRING && n->tp->skiptypedefs()->base == VEC))
if (ansi_opt == 0) {
error('s', &n->where, "initialization of%n (automatic aggregate)", n);
continue;
} else {
n->n_initializer = in;
continue;
}
}
if (ansi_opt && in && n->tp->tconst() && n->tp->base != VEC && n->n_sto != STATIC) {
// in->simpl();
// n->n_initializer=in;
// continue;
Pbase(n->tp)->ansi_const = 1;
}
if (n->tp == 0)
continue; /* label */
if (n->n_evaluated)
continue;
// error('d',"***** block::simpl: %n->check",n);
// construction and destruction of temporaries is handled locally
// `D' :: int; X; ==> generates int __D<some_number> */
// note: does not appear necessary since all go to int
{
char *s = n->string;
if (s[0] == '_' && s[1] == '_' && s[2] == 'D' && isdigit(s[3]))
continue;
}
if (cln = n->tp->is_cl_obj()) {
Pclass cl = Pclass(cln->tp);
Pname d = cl->has_dtor();
if (n->n_stclass == STATIC // local static class object
&& in && in->base == STAT_INIT)
goto stat_init;
if (d && !is_nrv) { // n->cl.dtor(0);
// error('d',"***** block::simpl: %n->%t.dtor(0)",n,cl);
// special case: int i = foo() && foo();
// dtors hoisted within stmt::simpl, called below ...
if (Ntmp_dtor && is_probably_temp(n->string) && find_in_Ntmp(n->string))
continue;
Pexpr dl = call_dtor(n, d, 0, DOT, one);
if (pdlist
&& ((strncmp("__R", n->string, 3) == 0) || (strncmp("__V", n->string, 3) == 0))) {
int len = strlen(n->string) + 1;
for (con_dtor *pcd = pdlist; pcd; pcd = pcd->next) {
if (strncmp(n->string, pcd->tn->string, len) == 0) {
fudge_007 = pcd->condition->string;
Pexpr e = new expr(ASSIGN, pcd->condition, zero);
e->tp = int_type;
Pexpr ee = new expr(G_CM, e, dl);
ee->tp = int_type;
ee = new expr(G_CM, ee, zero);
ee->tp = int_type;
Pexpr qe = new expr(QUEST, ee, zero);
qe->cond = pcd->condition;
qe->tp = int_type;
dl = qe;
break;
}
}
}
// Pstmt dls = new estmt(SM,n->where,dl,0);
Pstmt dls = new estmt(SM, no_where, dl, 0);
if (dd) {
dls->s_list = dd;
dd = dls;
} else
ddt = dd = dls;
}
// error('d',"%n: in %d",n,in?in->base:0);
if (in) {
switch (in->base) {
case DEREF: // *constructor?
if (in->e1->base == G_CALL) {
Pname fn = in->e1->fct_name;
if (fn == 0 || fn->n_oper != CTOR)
goto ddd;
if (is_nrv) {
Pexpr et = in->e1->e1;
et->e1 = f->f_result;
et->base = REF;
}
st = new estmt(SM, n->where, in->e1, 0);
n->n_initializer = 0;
break;
}
goto ddd;
case STAT_INIT:
stat_init:
// error('d', "block::simpl: case #1 stat_init : n: %n", n );
in->base = QUEST;
st = new estmt(SM, n->where, in, 0);
n->n_initializer = 0;
break;
case G_CM:
if (is_nrv && (in->e1->base == CALL || in->e1->base == G_CALL)
&& in->e1->e2->e1->base == G_ADDROF && Pname(in->e1->e2->e1->e2) == n) {
in->e1->e2->e1 = f->f_result;
}
st = new estmt(SM, n->where, in->e1, 0);
n->n_initializer = 0;
break;
case ASSIGN: // assignment to "n"?
if (in->e1 == n) {
st = new estmt(SM, n->where, in, 0);
n->n_initializer = 0;
break;
}
default:
goto ddd;
}
}
} else if (cl_obj_vec) {
Pclass cl = Pclass(cl_obj_vec->tp);
Pname d = cl->has_dtor();
Pname c = cl->has_ictor();
n->n_initializer = 0;
if (n->n_stclass == STATIC // local static class object
&& in && in->base == STAT_INIT)
goto stat_init2;
if (c) { // _vec_new(vec,noe,sz,ctor);
if (in == 0 || in->base == ILIST) {
// vctor passed if ictor has default arguments
Pname vctor = cl->has_vtor();
Pexpr a = cdvec(vec_new_fct, n, cl, vctor ? vctor : c, -1, 0);
st = new estmt(SM, n->where, a, 0);
} else
st = new estmt(SM, n->where, in, 0);
}
// no default ctor but provided all elements with argument
else if (in)
st = new estmt(SM, n->where, in, 0);
if (d) { // __vec_delete(vec,noe,sz,dtor,0);
Pfct f = Pfct(d->tp);
int i = 0;
for (Pname nn = f->f_args->n_list; nn && nn->n_list; nn = nn->n_list)
i++;
Pexpr a = cdvec(vec_del_fct, n, cl, d, 0, new ival(i));
// Pstmt dls = new estmt(SM,n->where,a,0);
Pstmt dls = new estmt(SM, no_where, a, 0);
if (dd) {
dls->s_list = dd;
dd = dls;
} else
ddt = dd = dls;
}
} else if (in) {
switch (in->base) {
case ILIST:
switch (n->n_scope) {
case FCT:
if (in->e2) { // pointer to member
Pexpr ee = mptr_assign(n, in);
st = new estmt(SM, n->where, ee, 0);
n->n_initializer = 0;
break;
}
case ARG:
if (ansi_opt == 0)
error('s', "Ir list for localV%n", n);
}
break;
case STAT_INIT:
stat_init2:
// error('d', "block::simpl: case #2 stat_init : n: %n", n );
in->base = QUEST;
st = new estmt(SM, n->where, in, 0);
n->n_initializer = 0;
break;
case STRING:
if (n->tp->base == VEC)
break; /* BUG char vec only */
default:
ddd : {
// error('d',"fudge_007: %s n: %n ",fudge_007,n);
if (fudge_007 && (strcmp(n->string, fudge_007) == 0))
fudge_007 = 0;
else {
Pexpr ee = new expr(ASSIGN, n, in);
st = new estmt(SM, n->where, ee, 0);
n->n_initializer = 0;
}
}
}
}
init_stat3:
if (st) {
if (ss)
sst->s_list = st;
else
ss = st;
sst = st;
}
if (is_nrv)
n->tp = any_type;
}
if (dd) {
Pstmt od = del_list;
Pstmt obd = break_del_list;
Pstmt ocd = continue_del_list;
dd->simpl();
del_list = (od) ? Pstmt(new pair(curloc, dd, od)) : dd;
break_del_list = (break_del_list && obd) ? Pstmt(new pair(curloc, dd, obd)) : dd;
continue_del_list = (continue_del_list && ocd) ? Pstmt(new pair(curloc, dd, ocd)) : dd;
stail = s ? s->simpl() : 0;
Pfct f = Pfct(curr_fct->tp);
if (this != f->body || f->returns->base == VOID
|| (f->returns->base != VOID && no_of_returns == 0) // you have been warned!
|| strcmp(curr_fct->string, "main") == 0) {
// not dropping through the bottom of a value returning function
if (stail) {
Pstmt tt = (stail->base == RETURN || stail->base == LABEL) ? stail : trim_tail(stail);
if (tt && tt->base != RETURN)
stail->s_list = dd;
} else
s = dd;
stail = ddt;
}
del_list = od;
continue_del_list = ocd;
break_del_list = obd;
} else
stail = s ? s->simpl() : 0;
if (ss) { /* place constructor calls */
ss->simpl();
sst->s_list = s;
s = ss;
if (stail == 0)
stail = sst;
}
if (tmp_dtor) {
tmp_dtor->simpl();
if (stail == 0)
stail = tmp_dtor;
else
stail->s_list = tmp_dtor;
tmp_dtor = 0;
}
// need_lift = 0;
scope = old_scope;
return stail;
}
int no_sizeof;
void expr::simpl() {
DB(if (Sdebug >= 2) {
error('d', "%d->expr::simpl() %k", this, this ? base : 0);
if (Sdebug >= 3)
display_expr(this);
});
// error('d',"%d->expr::simpl() %k",this,this?base:0);
if (this == 0 || permanent == 2)
return; // already expanded
static TOK obase = 0;
// error('d',"expr::simpl()"); display_expr(this,"e");
switch (base) {
case MDOT:
obase = base;
mem->simpl();
obase = 0;
// no break
case ICALL: // already expanded
return;
case G_ADDROF:
case ADDROF:
// error('d',"simpl & %k",e2->base);
e2->simpl();
switch (e2->base) {
case DOT:
case REF: {
Pref r = Pref(e2);
Pname m = Pname(r->mem);
while (m->base == MDOT)
m = Pname(m->mem);
if (m->n_stclass == STATIC) { // & static member
Pexpr x;
delp:
x = e2;
e2 = m;
r->mem = 0;
DEL(x);
} else if (m->tp->base == FCT) { // & member fct
Pfct f = Pfct(m->tp);
if (f->f_virtual) { // &p->f ==> p->vtbl[fi].f
int index = f->f_virtual;
Pexpr ie = index ? new ival(index) : 0;
if (ie)
ie->tp = int_type;
Pname cn = m->n_table->t_name;
Pname vp = find_vptr(Pclass(cn->tp));
r->mem = vp;
if (obase == MDOT) {
base = DEREF;
e1 = e2;
e2 = ie;
} else { // support old style &b.vf
base = MDOT;
mem = new expr(DEREF, e2, ie);
string2 = "f";
i1 = 9;
}