forked from farisawan-2000/cfront-3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtyp.c
1198 lines (1108 loc) · 38 KB
/
typ.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/typ.c 1.18" */
/*******************************************************************************
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.
*******************************************************************************/
#include "cfront.h"
#include "size.h"
Pbase short_type;
Pbase int_type;
Pbase char_type;
Pbase long_type;
Pbase uchar_type;
Pbase ushort_type;
Pbase uint_type;
Pbase ulong_type;
Pbase zero_type;
Pbase float_type;
Pbase double_type;
Pbase ldouble_type;
Pbase void_type;
Pbase any_type;
Ptype Pint_type;
Ptype Pchar_type;
Ptype Pvoid_type;
Ptype Pfctvec_type;
Ptable gtbl;
Ptable ptbl;
Pname Cdcl;
Pstmt Cstmt;
bit new_type;
Pclass type::classtype() {
return (base == COBJ) ? Pclass(Pbase(this)->b_name->tp)
: (error('i', "T::classtype(): %k cobjX", base), Pclass(0));
}
Ptype np_promote(TOK oper, TOK r1, TOK r2, Ptype t1, Ptype t2, TOK p, bit perr)
/*
an arithmetic operator "oper" is applied to "t1" and "t2",
types t1 and t2 has been checked and belongs to catagories
"r1" and "r2", respectively:
A ANY
Z ZERO
I CHAR, SHORT, INT, LONG, FIELD, or EOBJ
F FLOAT DOUBLE LDOUBLE
P PTR (to something) or VEC (of something)
test for compatability of the operands,
if (p) return the promoted result type
*/
{
if (r2 == 'A')
return t1;
switch (r1) {
case 'A':
return t2;
case 'Z':
switch (oper) {
case ASMOD:
case ASAND:
case ASOR:
case ASLS:
case ASRS:
case ASPLUS:
case ASMINUS:
return any_type;
}
switch (r2) {
case 'Z':
return int_type;
case 'F':
switch (oper) {
case MOD:
case AND:
case ER:
case OR:
case LS:
case RS:
return any_type;
}
// no break
case 'I':
switch (oper) {
case DEREF:
return any_type;
case LS: // result type is that of promoted left op
case RS:
return int_type;
}
return (p) ? Pbase(t2->skiptypedefs())->arit_conv(0) : 0;
case 'P':
switch (oper) {
case MOD:
case AND:
case ER:
case OR:
case LS:
case RS:
case GE:
case GT:
case LE:
case LT:
return any_type;
case PLUS:
case ASPLUS:
if (t2 != Pvoid_type)
break;
case EQ:
case NE:
case QUEST:
break;
default:
return any_type;
}
return t2;
case FCT:
switch (oper) {
case QUEST:
return any_type;
case EQ:
case NE:
return t2;
}
if (perr)
error("zero%kF", oper);
return any_type;
default:
error('i', "zero(%d)", r2);
}
case 'I':
switch (r2) {
case 'Z':
t2 = 0;
switch (oper) {
case DEREF:
return any_type;
}
return (p) ? Pbase(t1->skiptypedefs())->arit_conv(Pbase(t2)) : 0;
case 'F':
switch (oper) {
case MOD:
case AND:
case ER:
case OR:
case LS:
case RS:
case ASMOD:
case ASAND:
case ASOR:
case ASLS:
case ASRS:
return any_type;
}
// no break;
case 'I':
switch (oper) {
case DEREF:
return any_type;
case LS: // result type is that of promoted left op
case RS:
return (p) ? Pbase(t1->skiptypedefs())->arit_conv(Pbase(0)) : 0;
}
return (p) ? Pbase(t1->skiptypedefs())->arit_conv(Pbase(t2)) : 0;
case 'P':
switch (oper) {
case DEREF:
break;
case PLUS:
case ASPLUS:
if (t2 != Pvoid_type)
break;
default:
if (perr)
error("int%kP", oper);
return any_type;
}
return t2;
case FCT:
if (perr)
error("int%kF", oper);
return any_type;
default:
error('i', "int(%d)", r2);
return any_type;
}
case 'F':
switch (oper) {
case MOD:
case ASMOD:
case AND:
case ER:
case OR:
case ASAND:
case ASOR:
case LS:
case RS:
case ASLS:
case ASRS:
return any_type;
}
switch (r2) {
case 'Z':
t2 = 0;
case 'I':
case 'F':
if (oper == DEREF)
return any_type;
return (p) ? Pbase(t1->skiptypedefs())->arit_conv(Pbase(t2)) : 0;
case 'P':
if (perr)
error("float%kP", oper);
return any_type;
case FCT:
if (perr)
error("float%kF", oper);
return any_type;
default:
error('i', "float(%d)", r2);
return any_type;
}
case 'P':
switch (oper) {
case LS:
case RS:
case ASLS:
case ASRS:
case MOD:
case ASMOD:
case ER:
case OR:
case ASOR:
case AND:
case ASAND:
case DIV:
case MUL:
return any_type;
}
switch (r2) {
case 'Z':
switch (oper) {
case GE:
case GT:
case LE:
case LT:
return any_type;
}
return t1;
case 'I':
switch (oper) {
case DEREF:
case PLUS:
case MINUS:
case ASPLUS:
case ASMINUS:
if (t1->check(Pvoid_type, 0) == 0) {
return any_type;
}
break;
default:
if (perr)
error("P%k int", oper);
return any_type;
}
return t1;
case 'F':
if (perr)
error("P%k float", oper);
return any_type;
case 'P':
if (t1->check(t2, ASSIGN)) {
Ptype tt1 = t1->is_ptr()->typ->skiptypedefs();
Ptype tt2 = t2->is_ptr()->typ->skiptypedefs();
switch (oper) {
case EQ:
case NE:
case LE:
case GE:
case GT:
case LT:
case MINUS:
case QUEST:
if (tt1 && tt2 && tt1->base == COBJ && tt2->base == COBJ) {
Pclass c1 = tt1->classtype();
Pclass c2 = tt2->classtype();
if (c1 && c2 && c1->baseof(c2) || c2->baseof(c1))
goto zz;
}
if (t2->check(t1, ASSIGN) == 0) {
if (oper == QUEST)
return t2;
goto zz;
}
break;
case REFMUL: {
Pname cn = tt1->is_cl_obj();
if (cn && tt2->base == FCT
&& same_class(Pclass(cn->tp), Pfct(tt2)->memof))
return t2;
}
}
if (perr)
error("T mismatch:%t %k%t", t1, oper, t2);
return any_type;
}
zz:
switch (oper) {
case MINUS:
return (t2 != Pvoid_type) ? int_type : any_type;
case ASMINUS:
if (perr)
error("P -=P");
return any_type;
case PLUS:
if (perr)
error("P +P");
return any_type;
case ASPLUS:
if (perr)
error("P +=P");
return any_type;
case MOD:
case ASMOD:
case AND:
case ER:
case OR:
case ASAND:
case ASOR:
case ASLS:
case ASRS:
case LS:
case RS:
case DEREF:
return any_type;
default:
return t1;
}
case FCT:
return t1;
default:
error('i', "P(%d)", r2);
}
case FCT:
if (oper == QUEST) {
switch (r2) {
case 'Z':
return any_type;
case 'P':
return t2;
case 'I':
case 'F':
if (perr)
error("F%k%t", oper, t2);
default:
return t1;
}
}
if (Pfct(t1)->memof && r2 == 'P' && t2->memptr())
return t2;
if ((oper == EQ || oper == NE) && r2 == 'Z')
return t1;
if (perr)
error("F%k%t", oper, t2);
return any_type;
default:
error('i', "np_promote(%d,%d)", r1, r2);
return 0;
}
}
TOK type::kind(TOK oper, TOK v, bit perr)
/* v == 'I' integral
'N' numeric
'P' numeric or pointer
*/
{
Ptype t = this;
if (this == 0)
error('i', "type::kind(): this==0");
t = t->skiptypedefs();
switch (t->base) {
case ANY:
return 'A';
case ZTYPE:
return 'Z';
case FIELD:
case CHAR:
case SHORT:
case INT:
case LONG:
case EOBJ:
return 'I';
case FLOAT:
case LDOUBLE:
case DOUBLE:
if (v == 'I')
if (perr)
error("float operand for %k", oper);
return 'F';
case VEC:
case PTR:
if (v != 'P')
if (perr)
error("P operand for %k", oper);
switch (oper) {
case INCR:
case DECR:
case MINUS:
case PLUS:
case ASMINUS:
case ASPLUS:
if (t->base == PTR && (Pptr(t)->memof || Pptr(t)->typ->base == FCT)) {
if (perr)
error("%t operand of%k", this, oper);
} else {
Pptr(t)->typ->tsizeof(); // get increment
}
break;
default:
if (t->base == PTR && (Pptr(t)->memof || Pptr(t)->typ->base == FCT))
if (perr)
error("%t operand of%k", this, oper);
case LT:
case LE:
case GT:
case GE:
case ANDAND:
case OROR:
case ASSIGN:
case NE:
case EQ:
case IF:
case WHILE:
case DO:
case FOR:
case QUEST:
case NOT:
break;
}
return 'P';
case RPTR:
if (perr)
error("R operand for %k", oper);
return 'A';
case FCT:
if (v != 'P')
if (perr)
error("F operand for %k", oper);
return FCT;
case OVERLOAD:
if (perr)
error("overloaded operand for %k", oper);
return 'A';
case CLASS:
case ENUM:
if (perr)
error("%k operand for %k", base, oper);
return 'A';
default:
if (perr)
error("%t operand for %k", this, oper);
return 'A';
}
}
void type::dcl(Ptable tbl)
/*
go through the type (list) and
(1) evaluate vector dimensions
(2) evaluate field sizes
(3) lookup struct tags, etc.
(4) handle implicit tag declarations
*/
{
Ptype t = this;
// processing_sizeof suppresses errors for refs to names in the arg
// to sizeof. Turn errors back on for exprs within type specs
// (such as array subscripts)
int os = processing_sizeof;
processing_sizeof = 0;
if (this == 0)
error('i', "T::dcl(this==0)");
if (tbl->base != TABLE)
error('i', "T::dcl(%d)", tbl->base);
xx:
switch (t->base) {
case TYPE:
t = Pbase(t)->b_name->tp;
goto xx;
case PTR:
case RPTR: {
Pptr p = Pptr(t);
if (p->memof == 0 && p->ptname) { // T::*, where T is a template formal
Ptype tp = p->ptname->tp->skiptypedefs();
switch (tp->base) {
case COBJ: {
p->memof = tp->classtype();
if (p->typ) {
Ptype t = p->typ->skiptypedefs();
if (t && t->base == FCT) {
Pfct(t)->memof = p->memof;
}
}
break;
}
case CLASS: {
p->memof = Pclass(tp);
Ptype t = p->typ->skiptypedefs();
Pfct f = Pfct(t); // safe???
f->memof = p->memof;
break;
}
default:
error("illegalZizedP toM %t::*", tp);
break;
}
}
t = p->typ;
if (t->base == TYPE) {
Ptype tt = Pbase(t)->b_name->tp;
if (tt->base == FCT)
p->typ = tt;
goto done;
}
goto xx;
}
case VEC: {
Pvec v = Pvec(t);
Pexpr e = v->dim;
if (e) {
Ptype et;
v->dim = e = e->typ(tbl);
if (e->tp->skiptypedefs()->base == COBJ) {
e = check_cond(e, DEREF, tbl);
v->dim = e;
}
et = e->tp;
if (et->integral(0) == 'A') {
error("UN in array dimension");
} else {
long i;
Neval = 0;
i = e->eval();
if (Neval == 0) {
if (largest_int < i)
error("array dimension too large");
v->size = int(i);
DEL(v->dim);
v->dim = 0;
}
if (new_type) {
if (Neval)
;
else if (i == 0)
v->dim = zero;
else if (i < 0) {
error("negative array dimension");
i = 1;
}
} else {
if (Neval)
error("%s", Neval);
else if (i == 0) {
error("array dimension == 0");
v->dim = e;
} else if (i < 0) {
error("negative array dimension");
i = 1;
}
}
}
}
t = v->typ;
llx:
switch (t->base) {
case TYPE:
t = Pbase(t)->b_name->tp;
goto llx;
case FCT:
v->typ = t;
break;
case VEC:
if (Pvec(t)->dim == 0 && Pvec(t)->size == 0)
error("null dimension (something like [][] seen)");
}
goto xx;
}
case FCT: {
Pfct f = Pfct(t);
void dargs(Pname, Pfct, Ptable);
if (f->argtype)
dargs(0, f, tbl);
for (Pname n = f->argtype; n; n = n->n_list) {
Ptype t = n->tp;
n->tp->dcl(tbl);
while (t->base == TYPE)
t = Pbase(t)->b_name->tp;
if (t->base == VEC)
n->tp = new ptr(PTR, Pvec(t)->typ);
}
Pname cn = f->returns->is_cl_obj();
if (cn && Pclass(cn->tp)->has_itor())
make_res(f);
else if (f->f_this == 0)
f->f_args = f->argtype;
t = f->returns;
goto xx;
}
case FIELD: {
Pbase f = Pbase(t);
Pexpr e = Pexpr(f->b_name);
long i;
Ptype et;
e = e->typ(tbl);
f->b_name = Pname(e);
et = e->tp;
if (et->integral(0) == 'A') {
error("UN in field size");
i = 1;
} else {
Neval = 0;
i = e->eval();
if (Neval)
error("%s", Neval);
else if (i < 0) {
error("negative field size");
i = 1;
} else if (f->b_fieldtype->tsizeof() * BI_IN_BYTE < i)
error("field size > sizeof(%t)", f->b_fieldtype);
DEL(e);
}
f->b_bits = int(i);
f->b_name = 0;
break;
}
}
done:
processing_sizeof = os;
return;
}
static bit fm_same_class(Pclass c1, Pclass c2)
/* Predicate to determine whether two classes are indeed the same.
* as arguments to a template function: uninstantiated: t
* template <class T> void f(X<T> t));
* X<T> results in an UNINSTANTIATED template class
* friend X<T> void foo( X<T> ) results in a CL_TEMPLATE
* because the template nature is extrapolated from the declaration
* and class objects referenced within friend declarations are not
* placed on the class templ_ref list for instantiation
*/
{
// error('d',"fm_same_class: %t %d %t %d",c1,c1,c2,c2);
// error('d',"fm_same_class: c1->cl_base %d c2->cl_base %d",c1->class_base,c2->class_base);
if (same_class(c1, c2))
return 1;
Templ_type t1 = c1->class_base;
Templ_type t2 = c2->class_base;
if ((t1 == UNINSTANTIATED || t1 == CL_TEMPLATE) && (t2 == UNINSTANTIATED || t2 == CL_TEMPLATE)
&& (strcmp(c1->string, c2->string) == 0))
return 1;
return 0;
}
bit const_problem; // types differ only in const
bit return_error; // functions differ only in return
static bit pt_ptm; // template pointer to member
static bit pt_over; // strong check of template_classes
int Vcheckerror;
extern int template_hier; // permit derived/base conversion in templates
bit type::check(Ptype t, TOK oper, bit level)
/*
check if "this" can be combined with "t" by the operator "oper"
used for check of
assignment types (oper==ASSIGN)
declaration compatability (oper==0)
decl. compatibility without "const"ness (oper=254)
(oper == IGNORE_CONST)
parameterized type formals (oper==255)
as for (oper==0) but
special checking for ANY types
argument types (oper==ARG)
return types (oper==RETURN)
overloaded function name match (oper==OVERLOAD)
overloaded function coercion (oper==COERCE)
virtual function match (oper==VIRTUAL)
NOT for arithmetic operators
return 1 if the check failed
*/
{
register Ptype t1 = this, t2 = t;
bit cnst1 = 0, cnst2 = 0;
TOK b1, b2;
bit vv = 0, over = 0, strict_any_check = 0;
TOK rec_oper; // value of oper for recursive calls to type::check
// oper, 255, or PT_OVERLOAD
TOK rec_oper0; // value of oper for recursive calls to type::check
// 0, 255, or PT_OVERLOAD
if (t1 == 0 || t2 == 0)
error('i', "check(%p,%p,%d)", t1, t2, oper);
if (t1 == t2)
return 0;
switch (oper) {
case VIRTUAL:
vv = 1;
Vcheckerror = 0;
oper = 0;
break;
case OVERLOAD:
over = 1;
oper = 0;
break;
case PT_OVERLOAD:
over = 1;
// no break
case 255:
oper = 0;
strict_any_check = 1;
break;
}
if (level == 0) {
const_problem = 0;
return_error = 0;
pt_ptm = 0;
pt_over = over;
}
rec_oper = strict_any_check ? (over ? PT_OVERLOAD : 255) : oper;
rec_oper0 = strict_any_check ? (over ? PT_OVERLOAD : 255) : 0;
t1 = t1->skiptypedefs(cnst1);
/*
** GLOG: the following test on ANY must be done before unrolling
** t2, to accommodate templates (in a way I don't yet understand)
*/
if (t1->base == ANY || t2->base == ANY)
if (over == 0 || strict_any_check == 0)
return strict_any_check ? t1 != t2 : 0;
t2 = t2->skiptypedefs(cnst2);
if (t1 == t2)
goto const_check;
b1 = t1->base;
b2 = t2->base;
if (b1 != b2) {
switch (b1) {
case PTR:
switch (b2) {
case VEC:
if (level > 0 || (oper == 0 || oper == IGNORE_CONST) && over == 0
|| Pptr(t1)->memof || Pptr(t1)->ptname
|| Pptr(t1)->typ->check(Pvec(t2)->typ, rec_oper, level + 1))
return 1;
goto const_check;
case FCT:
if (level > 0 || Pptr(t1)->typ->check(t2, rec_oper, level + 1))
return 1;
goto const_check;
}
break;
case FCT:
if (b2 == PTR) {
if (level > 0 || t1->check(Pptr(t2)->typ, rec_oper, level + 1))
return 1;
goto const_check;
}
break;
case VEC:
if (b2 == PTR) {
if (level > 0 || (oper == 0 || oper == IGNORE_CONST) && over == 0 || Pptr(t2)->memof
|| Pptr(t2)->ptname || Pvec(t1)->typ->check(Pptr(t2)->typ, rec_oper, level + 1))
return 1;
goto const_check;
}
break;
}
if (level > 0) {
if ((oper != 0 && oper != IGNORE_CONST) && b1 == VOID && level == 1) {
if (b2 == FCT) {
Pfct f = Pfct(t2);
if (f->memof && f->f_static == 0)
return 1;
}
goto const_check;
}
return 1;
}
switch (oper) {
case 0:
case IGNORE_CONST:
if (b2 == ZTYPE && b1 == INT && Pbase(t1)->b_unsigned == 0
|| b1 == ZTYPE && b2 == INT && Pbase(t2)->b_unsigned == 0)
goto const_check;
return 1;
case ARG:
case ASSIGN:
case RETURN:
case COERCE:
switch (b1) {
case ZTYPE:
case CHAR:
case SHORT:
case INT:
case LONG:
case FLOAT:
case DOUBLE:
case LDOUBLE:
case FIELD:
switch (b2) {
case LONG:
case FLOAT:
case DOUBLE:
case LDOUBLE:
case EOBJ:
case ZTYPE:
case CHAR:
case SHORT:
case INT:
case FIELD:
if (oper == COERCE)
Nstd++;
goto const_check;
}
return 1;
case PTR:
case VEC:
if (b2 == ZTYPE) {
if (oper == COERCE)
Nstd++;
goto const_check;
}
case RPTR:
case COBJ:
case FCT:
case EOBJ:
default:
return 1;
}
}
goto const_check;
}
switch (b1) {
case VEC:
if (Pvec(t1)->size != Pvec(t2)->size
&& (level > 0
|| (oper == 0 || oper == IGNORE_CONST) && strict_any_check == 0 && Pvec(t1)->size
&& Pvec(t2)->size))
return 1;
if (Pvec(t1)->typ->check(Pvec(t2)->typ, rec_oper, level + 1))
return 1;
break;
case PTR:
case RPTR: {
Pptr p1 = Pptr(t1);
Pptr p2 = Pptr(t2);
if ((p1->ptname && p2->ptname) && (!p1->memof || !p2->memof))
return 1;
if (!same_class(p1->memof, p2->memof)) {
// T::* requires we defer setting up memof
// until instantiation of the Template type T
// ptname holds the formal parameter T
// can't merge with other if because of memof usage
if (p1->memof == 0 && p1->ptname || p2->memof == 0 && p2->ptname)
pt_ptm = 1;
else if (p1->memof == 0 || p2->memof == 0
|| (p1->memof->baseof(p2->memof) == 0
&& same_class(p1->memof, p2->memof, 1) == 0))
return 1;
if (pt_ptm == 0 && (oper == 0 || oper == IGNORE_CONST)
&& same_class(p1->memof, p2->memof) == 0)
return 1;
if (oper == COERCE)
Nstd++;
}
#if 0
if (!level && (oper == 0 || oper == ASSIGN || oper == COERCE ||
oper == ARG || oper == RETURN)) {
Ptype t11;
Ptype t22;
Ptype ta;
Ptype tb;
int i = 0;
int j = 0;
int k = 0;
ta = t1;
while ((ta->base == PTR || ta->base == RPTR) &&
(tb = ta->is_ptr_or_ref())) {
ta = Pptr(tb)->typ;
i++;
k += ta->tconst();
}
t11 = ta;
ta = t2;
while ((ta->base == PTR || ta->base == RPTR) &&
(tb = ta->is_ptr_or_ref())) {
ta = Pptr(tb)->typ;
j++;
}
t22 = ta;
if (i >= 2 && j == i && t11->tconst() &&
!t22->tconst() && k != i)
return const_problem = 1;
}
#endif
if (p1->typ->check(p2->typ, rec_oper, level + 1))
return 1;
break;
}
case FCT: {
Pfct f1 = Pfct(t1);
Pfct f2 = Pfct(t2);
Pname a1 = f1->argtype;
Pname a2 = f2->argtype;
TOK k1 = f1->nargs_known;
TOK k2 = f2->nargs_known;
int n1 = f1->nargs;
int n2 = f2->nargs;
// if pt_ptm, want to check arguments and return type
// but template ptm has no memof until instantiation
if (!same_class(f1->memof, f2->memof) && pt_ptm == 0) {
if (f1->memof == 0 && f2->f_static)
goto sss;
if (vv == 0) // match even if private base class
if (f1->memof == 0 || f2->memof == 0
|| (level > 1 || f1->memof->baseof(f2->memof) == 0)
&& same_class(f1->memof, f2->memof) == 0)
return 1;
if (oper == COERCE)
Nstd++;
sss:; // SSS
}
if (k1 != k2)
return 1;