forked from farisawan-2000/cfront-3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnorm.c
2171 lines (2008 loc) · 71.4 KB
/
norm.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/norm.c 1.12" */
/*******************************************************************************
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.
norm.c:
"normalization" handles problems which could have been handled
by the syntax analyser; but has not been done. The idea is
to simplify the grammar and the actions accociated with it,
and to get a more robust error handling
****************************************************************************/
#include "cfront.h"
#include "size.h"
#include "template.h"
// SYM -- table defs
Pktab Gtbl;
Pktab Ctbl;
Pname sta_name = 0;
static Ptype generic_tpdef = 0;
void syn_init() {
generic_tpdef = new type;
generic_tpdef->base = TPDEF;
PERM(generic_tpdef);
any_type = new basetype(ANY, 0);
PERM(any_type);
any_type->defined = DEFINED;
dummy = new expr(DUMMY, 0, 0);
PERM(dummy);
dummy->tp = any_type;
zero = new expr(ZERO, 0, 0);
PERM(zero);
sta_name = new name;
PERM(sta_name);
// SYM -- init new tables
Gtbl = new ktable(GTBLSIZE, 0, 0); // SYM
Ctbl = Gtbl; // SYM
}
int stcount;
char *make_name(TOK c) {
char *s = new char[8]; // as it happens: fits in two words
if (10000 <= ++stcount)
error('i', "too many generatedNs");
sprintf(s, "__%c%d", c, stcount);
return s;
}
Pbase basetype::type_adj(TOK t) {
DB(if (Ndebug >= 1) error('d', "'%k'->type_adj(%k) --%t b_xname%n", base, t, this, b_xname););
if (b_xname) {
if (base)
error("badBT:%n%k", b_xname, t);
else {
base = TYPE;
b_name = b_xname;
}
b_xname = 0;
}
switch (t) {
case TYPEDEF:
if (b_typedef)
error('w', "two typedefs");
else if (b_inline) {
error("badBT:%k and%k", INLINE, TYPEDEF);
b_typedef = 0;
} else
b_typedef = 1;
break;
case INLINE:
if (b_inline)
error('w', "two inlines");
else if (b_typedef) {
error("badBT:%k and%k", TYPEDEF, INLINE);
b_inline = 0;
} else
b_inline = 1;
break;
case VIRTUAL:
b_virtual = 1;
break;
case CONST:
if (b_const)
error('w', "two const declarators");
b_const = 1;
break;
case UNSIGNED:
b_unsigned = 1;
break;
case SHORT:
b_short = 1;
break;
case LONG:
if (b_long)
error('w', "two long declarators");
if (base == DOUBLE)
base = LDOUBLE;
else
b_long = 1;
break;
case FRIEND:
case OVERLOAD:
case EXTERN:
case STATIC:
case AUTO:
case REGISTER:
if (b_sto)
error("badBT:%k%k", b_sto, t);
else
b_sto = t;
break;
case DOUBLE:
if (b_long) {
t = LDOUBLE;
b_long = 0;
}
// no break
case VOID:
case CHAR:
case INT:
case FLOAT:
if (base)
error("badBT:%k%k", base, t);
else
base = t;
break;
case SIGNED:
case VOLATILE:
error('w', "\"%k\" not implemented (ignored)", t);
break;
default:
error('i', "BT::type_adj(%k)", t);
}
return this;
}
Pbase basetype::name_adj(Pname n) {
DB(if (Ndebug >= 1) error('d', "'%k'->name_adj(%n) --%t b_xname%n", base, n, this, b_xname));
if (b_xname) {
if (base)
error("badBT:%n%n", b_xname, n);
else {
base = TYPE;
b_name = b_xname;
}
b_xname = 0;
}
if (base == 0 && n->base == TNAME
&& (n->tp->base != COBJ // SYM || in_arg_list )) {
|| Ctbl->k_id == ARG)) {
base = TYPE;
b_name = n;
} else
b_xname = n;
return this;
}
static TOK type_set(Pbase b) {
TOK t = 0;
if (b->b_long)
t = LONG;
else if (b->b_short)
t = SHORT;
else if (b->b_unsigned)
t = UNSIGNED;
else if (b->b_inline)
t = INLINE;
else if (b->b_virtual)
t = VIRTUAL;
else if (b->b_sto == OVERLOAD)
t = OVERLOAD;
return t;
}
int declTag = 1;
Pbase basetype::base_adj(Pbase b) {
DB(if (Ndebug >= 1) error('d', "'%k'->base_adj(%t) --%t b_xname%n", base, b, this, b_xname));
Pname bn = b->b_name;
switch (base) {
case COBJ:
case EOBJ:
error("NX after%k%n", base, b_name);
return this;
}
TOK t;
if (base) {
if (b_name)
error("badBT:%k%n%k%n", base, b_name, b->base, bn);
else
error("badBT:%k%k%n", base, b->base, bn);
} else if (t = type_set(this)) {
if (b_name)
error("badBT:%k%n%k%n", t, b_name, b->base, bn);
else {
if (declTag++ && !(t == INLINE && b->base == EOBJ))
error("badBT:%k%k%n", t, b->base, bn);
base = b->base;
b_name = bn;
// error('d',"base_adj: t: %k", t );
}
} else {
base = b->base;
b_name = bn;
b_table = b->b_table;
}
return this;
}
Pbase basetype::check(Pname n)
/*
"n" is the first name to be declared using "this"
check the consistency of "this"
and use "b_xname" for "n->string" if possible and needed
*/
{
b_inline = 0;
b_virtual = 0;
// error('d',"basetype::check(%n) base %k b_xname %n",n,base,b_xname);
if (b_xname && (n->tp || n->string)) {
if (base)
error("badBT:%k%n", base, b_xname);
else {
base = TYPE;
b_name = b_xname;
}
b_xname = 0;
}
if (b_xname) {
if (n->string)
error("twoNs inD:%n%n", b_xname, n);
else {
n->string = b_xname->string;
b_xname->hide(); // SYM?
}
b_xname = 0;
}
if (ccl == 0 && n && n->n_oper == TNAME && !in_typedef && n->n_qualifier == 0
&& n->string) { // hide type name
Pname nx = k_find_name(n->string, Ctbl, 0); // SYM
if (nx && nx->base == TNAME)
nx->hide();
}
int defa = 0;
switch (base) {
case 0:
defa = 1;
base = INT;
break;
case EOBJ:
case COBJ:
if (b_name->base == TNAME)
error('i', "TN%n inCO %p", b_name, this);
}
if (b_long || b_short) {
TOK sl = (b_short) ? SHORT : LONG;
if (b_long && b_short)
error("badBT:long short%k%n", base, n);
if (base != INT)
error("badBT:%k%k%n", sl, base, n);
else
base = sl;
b_short = b_long = 0;
}
if (b_typedef && b_sto)
error("badBT:Tdef%k%n", b_sto, n);
b_typedef = b_sto = 0;
if (b_linkage) {
if (1 <= bl_level)
error("local linkage directive");
}
if (Pfctvec_type == 0)
return this;
if (b_const) {
if (b_unsigned) {
switch (base) {
default:
error("badBT: unsigned const %k%n", base, n);
b_unsigned = 0;
case LONG:
case SHORT:
case INT:
case CHAR:
return this;
}
}
return this;
} else if (b_unsigned) {
switch (base) {
case LONG:
delete this;
return ulong_type;
case SHORT:
delete this;
return ushort_type;
case INT:
delete this;
return uint_type;
case CHAR:
delete this;
return uchar_type;
default:
error("badBT: unsigned%k%n", base, n);
b_unsigned = 0;
return this;
}
} else {
switch (base) {
case LONG:
delete this;
return long_type;
case SHORT:
delete this;
return short_type;
case INT:
if (this == int_type || this == defa_type)
return this;
delete this;
if (defa)
return defa_type;
return int_type;
case CHAR:
delete this;
return char_type;
case VOID:
delete this;
return void_type;
case TYPE:
/* use a single base saved in the keyword */
if (b_name->n_qualifier) {
Pbase rv = Pbase(b_name->n_qualifier);
delete this;
return rv;
} else {
PERM(this);
b_name->n_qualifier = (Pname) this;
return this;
}
default:
return this;
}
}
}
static int check_redef(Pname on, Pname nn) {
// nn is a new typedef
// on was returned from insert_type()
// check for conflicts
// return 1 for duplicate def, else 0
if (Nold) { // SYM type name was already in symbol table
// error('d',"'%n'->tdef() -- redef%t,%t",on,on->tp,nn->tp);
// error('d'," -- nn->base%k, on->base%k, nn->n_oper%k,
// on->n_key%k",nn->base,on->base,nn->n_oper,on->n_key);
if (on->tp->check(nn->tp, 0) == 0) { // duplicate typedef
nn->base = TNAME;
return 1; // avoid infinite loop for typedef I I;
}
if (nn->tpdef->in_class && nn->tpdef->in_class->csu == ANON) {
if (nn->tpdef->defined == 0)
error(&nn->where, "twoDs of %s (one in anonymous union)", nn->string);
} else if (on->tpdef)
error(&nn->where, "%n redefined:Tdef%t andTdef%t", on, on->tp, nn->tp);
else
error(&nn->where, "%n redefined:%t andTdef%t", on, on->tp, nn->tp);
// kluge: avoid printing error twice for nested anon
nn->tpdef->defined = 1;
Pname nw = new name;
Pname x = on;
x->n_key = VOID; // anything to get rid of it
*nw = *nn;
nw->n_tbl_list = 0;
nw->n_ktable = 0;
nw->n_table = 0;
on = insert_type(nw, Ctbl, TYPE);
if (Nold)
error('i', &nn->where, "cannot recover");
on->n_hidden = x;
}
if (on->n_key == HIDDEN) {
if (nn->tpdef->in_class && nn->tpdef->in_class->csu == ANON) {
if (nn->tpdef->defined == 0)
error(&nn->where, "twoDs of %s (one in anonymous union)", nn->string);
} else
error(&nn->where, "%n redefined: identifier andTdef", on);
// kluge: avoid printing error twice for nested anon
nn->tpdef->defined = 1;
}
return 0;
}
Pname basetype::aggr()
/*
"type SM" seen e.g. struct s {};
class x;
enum e;
int tname;
friend cname;
friend class x;
int;
typedef int i; // where i is tname
convert
union { ... };
into
union name { ... } name ;
*/
{
DB(if (Ndebug >= 1) error('d', "'%k'->aggr() --%t b_xname%n ccl%t", base, this, b_xname, ccl));
if (b_xname) {
if (base) {
Pname n = new name(b_xname->string);
// b_xname->hide();//SYM?
b_xname = 0;
return n->normalize(this, 0, 0);
} else {
base = TYPE;
b_name = b_xname;
b_xname = 0;
}
}
switch (base) {
case COBJ: {
Pclass cl = Pclass(b_name->tp);
char *s = cl->string;
/*SYM?*/ if (cl->class_base != CL_TEMPLATE
&& (cl->in_class == 0 || cl->in_class->class_base != CL_TEMPLATE)
&& b_name->base == TNAME)
error('i', "TN%n inCO", b_name);
if (b_const)
error("const%k%n", cl->csu, b_name);
if (cl->c_body == 2) { /* body seen */
if (s[0] == '_' && s[1] == '_' && s[2] == 'C') {
char *ss = new char[8]; // max size of generated name is 7 chars, see make_name()
Pname obj = new name(ss);
strcpy(ss, s);
if (cl->csu == UNION && cl->class_base != CL_TEMPLATE) {
ss[2] = 'O';
cl->csu = ANON;
Pname un = obj->normalize(this, 0, 0);
// SYM -- export anon union names
// SYM to current table
int i = 1;
Pname nn = cl->k_tbl->get_mem(i);
for (; nn; NEXT_NAME(cl->k_tbl, nn, i)) {
if (nn->string == 0)
continue;
if (nn->base == NAME) {
insert_name(new name(nn->string), Ctbl);
} else if (nn->tp == 0) {
error('i', "BT::aggr(): nullT for%n in anon union", nn);
} else {
Pname nx = new name(nn->string);
nx->tp = nn->tp;
nx->tpdef = nn->tpdef;
nx->where = nn->where;
if (nn->tpdef) {
nx = insert_type(nx, Ctbl, TYPE);
check_redef(nx, nn);
} else {
switch (nx->tp->base) {
case COBJ: {
Pclass mcl = (Pclass) Pbase(nn->tp)->b_name->tp;
if (mcl->csu != ANON
&& !(mcl->string[0] == '_' && mcl->string[1] == '_'
&& mcl->string[2] == 'C')) {
nx = insert_type(nx, Ctbl, mcl->csu);
if (Nold) {
Pname x = nx->tp->is_cl_obj();
Pclass ocl = x ? Pclass(x->tp) : 0;
if (ocl == 0 || strcmp(ocl->string, mcl->string)
|| (ocl->defined & (DEF_SEEN | DEFINED))
&& (mcl->defined & (DEF_SEEN | DEFINED)))
error(&nn->where,
"twoDs of %s (one in anonymous union)",
nn->string);
else if (mcl->defined & (DEF_SEEN | DEFINED))
nx->tp = nn->tp;
}
}
} break;
case EOBJ:
if (nn->string[0] == '_' && nn->string[1] == '_'
&& nn->string[2] == 'E')
break;
nx = insert_type(nx, Ctbl, ENUM);
if (Nold) {
Ptype t = nx->tp->skiptypedefs();
Penum oe =
t->base == EOBJ ? (Penum) Pbase(t)->b_name->tp : 0;
t = nn->tp->skiptypedefs();
Penum ne =
t->base == EOBJ ? (Penum) Pbase(t)->b_name->tp : 0;
if (oe == 0 || strcmp(oe->string, ne->string)
|| (oe->defined & (DEF_SEEN | DEFINED))
&& (ne->defined & (DEF_SEEN | DEFINED)))
error(&nn->where,
"twoDs of %s (one in anonymous union)",
nn->string);
else if (ne->defined & (DEF_SEEN | DEFINED))
nx->tp = nn->tp;
}
break;
default:
error('i', &nn->where, "missing tpdef forTdefN %s",
nx->string);
} // switch
} // else tag
// error('d',&nn->where,"exportingTN %n%t",nx,nx->tp);
} // else TNAME
} // for nn
return un;
}
if (cl->class_base != CL_TEMPLATE)
error('w', "unusable%k ignored", cl->csu);
}
if (b_sto == FRIEND)
error("friend%k%n{...} -- may only declare a friendC", cl->csu, b_name);
cl->c_body = 1;
return b_name;
} else { /* really a typedef for cfront only: class x; */
if (b_sto == FRIEND)
goto frr;
Pname nn = new name(cl->string);
nn->tp = b_name->tp;
nn->n_key = REF;
return nn;
}
}
case EOBJ: {
Penum en = Penum(b_name->tp);
/*SYM?*/ if (b_name->base == TNAME)
error('i', "TN%n in enumO", b_name);
if (b_const)
error("const enum%n", b_name);
if (en->e_body == 2) {
en->e_body = 1;
return b_name;
} else {
error("forwardD of enum%n", b_name);
en->e_type = int_type;
}
return 0;
}
case 0: {
Pname n = new name(make_name('D'));
n->tp = defa_type;
error("NX inDL");
return n;
}
default:
if (b_typedef)
error('w', "illegalTdef ignored");
if (b_sto == FRIEND && b_name) {
frr: // see also name::normalize(), stc == FRIEND
Pname fr = k_find_name(b_name->string, Ctbl, 0); // SYM
if (fr == 0 || fr->base != TNAME)
error('i', "cannot find friend%n", b_name);
Pname n = new name(b_name->string);
n->n_sto = FRIEND;
// If it is a parameterized type, use the instantiation
// type, not the general type.
if ((fr->tp->base == COBJ)
&& (Pclass(Pbase(fr->tp)->b_name->tp)->class_base == CL_TEMPLATE)) {
if (base == COBJ)
n->tp = this;
else if ((base == TYPE) && (Pbase(this)->b_name->base == TNAME)
&& (Pbase(this)->b_name->tp->base == COBJ))
n->tp = Pbase(this)->b_name->tp;
else
error('i', "basetype wasn't a COBJ");
} else
n->tp = fr->tp;
return n;
} else {
Pname n = new name(make_name('D'));
n->tp = defa_type;
error("NX inDL");
return n;
}
}
}
// SYM -- removed void local_name()
// SYM void local_restore() removed
// SYM -- local_hide() removed
// SYM void nested_restore() removed
// SYM nested_hide(Pname) removed
// SYM static void nested_hide( Plist l ) removed
int defer_check = 0;
// SYM removed Pname statStat = 0;
void name::hide()
/*
hide "this": that is, "this" should not be a keyword in this scope
*/
{
if (base != TNAME)
return;
// error('d',"'%n '->hide() -- %t lex_level %d bl_level %d",this,tp,lex_level,::bl_level);
if (n_key == 0) {
if (lex_level == bl_level && in_arg_list == 0) {
if (tp->base != COBJ) {
// error('d',"%n::hide() -- in_typedef base%k %t
// %t",this,in_typedef->base,tp,in_typedef);
if (in_typedef && in_typedef->base && tp->base != type_set(Pbase(in_typedef))
&& in_typedef->check(tp, 0)) {
if (defer_check == 0)
error("%n redefined: previous: %t now: %t", this, tp, in_typedef);
}
} else {
// error('d',"in_typedef%t %d tp%t %d",in_typedef,in_typedef,tp,tp);
// error('d',"in_typedef%k tp%k",in_typedef->base,tp->base);
if (in_typedef && in_typedef->base && in_typedef->check(tp, 0)) {
if (defer_check == 0)
error("%n redefined: previous: %t now: %t", this, tp, in_typedef);
} else {
Pname nn = Pbase(tp)->b_name;
Pclass cl = Pclass(nn->tp);
// check for 'typedef class X X;'
// and 'typedef X X;'
if (in_typedef)
while (in_typedef->base == TYPE)
in_typedef = Pbase(in_typedef)->b_name->tp;
if (in_typedef && in_typedef->base == COBJ
&& same_class(Pclass(Pbase(in_typedef)->b_name->tp), cl))
in_typedef = tp;
else if (cl->has_ctor())
error("%n redefined: both aCNWK and %s", this,
in_typedef ? "a type name" : "an identifier");
}
}
}
// error( 'd', "%n::hide", this );
if (n_table == 0) {
// error('d',"templp: in progress: %d", templp->in_progress);
Pclass cl = 0;
if (tp->base == COBJ)
cl = tp->classtype();
if (n_template_arg == template_type_formal && templp->in_progress)
error('s', "reuse of formalYZ%n", this);
else if (cl && (cl->class_base == INSTANTIATED || cl->class_base == UNINSTANTIATED))
error("illegal use of instantiatedYC%t", cl);
else
error('i', "%n->hide() -- no n_table", this);
}
insert_name(new name(string), Ctbl);
}
}
// SYM removed Ntncheck, notReally
// SYM void set_scope(Pname tn) removed
// SYM void restore() removed
int classid; // index of generated class names
// saved and reset by grammer at start of each class def
// so nested tag indices will be relative
// -- ensures link compatibility for static member anon unions
Pname start_cl(TOK t, Pname c, Pbcl b) {
int mk_local = 0;
DB(if (Ndebug >= 1) error('d', "start_cl(%k,%n,%d) ll %d", t, c, b, c ? c->lex_level : 0););
if (c == 0) {
int save = stcount;
stcount = classid++;
c = new name(make_name('C'));
stcount = save;
c->lex_level -= in_class_decl + 1;
if (in_typedef && c->lex_level)
mk_local = 1;
// SYM else c->lex_level = 0;
} else if (ccl && ccl->lex_level == c->lex_level && strcmp(ccl->string, c->string) == 0) {
error("%k %s redefines enclosing class", t, c->string);
error('i', "can't recover from previous errors");
}
Pname n = c->tname(t); /* t ignored */
n->where = curloc;
Pbase bt = Pbase(n->tp); /* COBJ */
if (bt->base != COBJ) {
error("twoDs of%n:%t andC", n, bt);
error('i', "can't recover from previous errors");
} else {
if (strcmp(n->string, Pbase(n->tp)->b_name->string) != 0)
error("twoDs of %n:Tdef andC", n);
if (n->tp->classtype()->csu != t && (t == UNION || n->tp->classtype()->csu == UNION))
error("twoDs of%n:%k and%k", n, t, n->tp->classtype()->csu);
bt->b_name->where = curloc; // line#s in dcl()
}
// SYM for ( Pclass tc = ccl; tc; tc = tc->in_class ) {
// SYM if ( tc->lex_level == c->lex_level // c not local to mem ftn of tc
// SYM && strcmp( tc->string, c->string) == 0) {
// SYM error( "C %s redefined", c->string );
// SYM error('i', "can't recover from previous errors");
// SYM }
// error('d',"ccl: %t bl: %d in_class_decl: %d ccl->lex_level:
// %d",ccl,bl_level,in_class_decl,ccl?ccl->lex_level:0); if (templp->in_progress && (c->lex_level ==
// 0))
if (templp->in_progress && (c->lex_level == 0)
&& (ccl == 0 || (!ccl->in_class && ccl->class_base != CL_TEMPLATE)
|| bl_level != ccl->lex_level + in_class_decl + 1))
// bring the template in scope
templp->introduce_class_templ(n);
// error('d',"'%n'->start_cl() ll %d",c, c->lex_level);
// error('d'," templ %d in_cl %d in_memf %d",templp->in_progress, in_class_decl, in_mem_fct);
if (templp->in_progress && c->lex_level) {
if (in_class_decl == 0 || in_mem_fct)
if (mk_local == 0)
error('s', "localC%nWinYF", c);
else
error('s', "localCWinYF");
}
// typedef struct {} x;
if (mk_local) {
local_class = new name_list(n, local_class);
// SYM -- tn stuff removed
}
Pclass occl = ccl;
ccl = Pclass(bt->b_name->tp); /* CLASS */
if (ccl->defined)
ccl->defined |= IN_ERROR;
ccl->defined |= DEF_SEEN;
// error('d', "start_cl: %n ccl->in_class: %t lex_level: %d", n, ccl->in_class, n->lex_level );
ccl->string = n->string;
ccl->csu = t;
// error('d',"typedef: ccl %t %n", ccl, n);
if (occl == 0) {
// if specialization, ccl->templ_base set within explicit_inst()
ccl->templ_base = templp->in_progress ? BOUND_TEMPLATE : ccl->templ_base;
}
// error('d',"ccl%t %d ll %d %s",ccl,ccl,ccl->lex_level,ccl->k_tbl->whereami());
if (b) { // list of base classes
for (Pbcl bx, bb = b, l = 0; bb; bb = bx) {
bx = bb->next;
bb->next = 0;
if (bb->bclass
//&& strcmp(ccl->string,bb->bclass->string)==0
&& ((bb->bclass->nested_sig && ccl->nested_sig
&& strcmp(ccl->nested_sig, bb->bclass->nested_sig) == 0)
|| (!bb->bclass->nested_sig && !ccl->nested_sig
&& strcmp(ccl->string, bb->bclass->string) == 0)))
error(&n->where, "%n derived from itself", n);
else if (l == 0)
l = bb;
else { // append and check for duplicates
for (Pbcl ll = l;;) {
if (bb->bclass && same_class(ll->bclass, bb->bclass)) {
error("%s has %s asB twice", ccl->string, bb->bclass->string);
break;
}
if (ll->next)
ll = ll->next;
else {
bb->next = l;
l = bb;
break;
}
}
}
}
ccl->baselist = l;
// SYM notReally++; set_scope(n); notReally--;
}
return n;
}
void end_cl() {
if (templp->parameters_in_progress)
error("definition ofC %tWinY parameterL : %d", ccl, templp->parameters_in_progress);
ccl->c_body = 2;
// ccl->templ_base may be set within explicit_inst()
ccl->templ_base = templp->in_progress ? BOUND_TEMPLATE
: ccl->in_class ? ccl->in_class->templ_base : ccl->templ_base;
ccl = ccl->in_class;
// SYM -- lots of stuff removed
}
Pbase end_enum(Pname n, nlist *b) {
// error( 'd', "end_enum: %n ccl: %t", n , ccl );
bit anon = 0;
if (n == 0) {
anon = 1;
n = new name(make_name('E'));
n->lex_level = bl_level - in_class_decl; // SYM
}
// error('d',"'%n'->end_enum() ll %d",n, n->lex_level);
// error('d'," templ %d in_cl %d in_memf %d",templp->in_progress, in_class_decl, in_mem_fct);
if (templp->parameters_in_progress)
error("definition of enum %sWinY parameterL", anon ? "" : n->string);
if (templp->in_progress && n->lex_level) {
if (in_class_decl == 0 || in_mem_fct)
if (anon == 0)
error('s', "local enum%nWinYF", n);
else
error('s', "local enumWinYF");
}
n = n->tname(ENUM);
Pbase bt = (Pbase) n->tp;
if (bt->base != EOBJ) {
error("twoDs of%n:%t and enum", n, bt);
error('i', "can't recover from previous errors");
}
bt->b_name->where = curloc;
Penum en = (Penum) bt->b_name->tp;
en->e_body = 2;
en->mem = name_unlist(b);
if (en->defined) {
// shouldn't be necessary anymore with nested types
// if ( in_class_decl )
// error("%n redefined, enum tag not local to class", n);
en->defined |= IN_ERROR;
}
en->defined |= DEF_SEEN;
en->templ_base =
templp->in_progress ? BOUND_TEMPLATE : en->in_class ? en->in_class->templ_base : en->templ_base;
return bt;
}
Pname name::tdef()
/*
typedef "this"
*/
{
// error('d',&where,"'%n'->tdef()%t in_typedef %d",this,tp,in_typedef);
// error('d',&where," lex_level %d tpdef%d",lex_level,tpdef);
// error('d',&where," templ %d in_cl %d in_memf %d",templp->in_progress, in_class_decl,
// in_mem_fct);
// SYM anon_cl removed
if (n_qualifier) {
error("QdN in typedef", this);
n_qualifier = 0;
}
if (tp == 0)
error('i', "Tdef%n tp==0", this);
lex_level = bl_level - in_class_decl;
if (ccl && ccl->lex_level == lex_level) {
// error('d',&where,"Tdef%n ccl%t ll %d",this,ccl,lex_level);
tpdef = new type;
tpdef->base = TPDEF;
PERM(tpdef);
tpdef->nested_sig = make_nested_name(string, ccl);
if (strcmp(ccl->string, string) == 0) {
error(&where, "nestedTdef%n redefines immediately enclosingC", this);
// SYM lookup mechanism in front end will ignore
// SYM members with same name as class
}
tpdef->in_class = ccl;
} else
tpdef = generic_tpdef;
if (templp->in_progress && lex_level) {
if (in_class_decl == 0 || in_mem_fct)
error('s', "localTdef%nWinYF", this);
}
Pname n;
n = insert_type(this, Ctbl, TYPE); // SYM
if (tpdef->in_class) { // nested typedef
// error('d', "*****%s->tdef: %d ccl: %t", string, tpdef, ccl );
// SYM fields copied by insert()
if (tp != n->tp || tpdef != n->tpdef) // error detected below...
;
else {
n->tpdef->templ_base = templp->in_progress ? BOUND_TEMPLATE : tpdef->in_class->templ_base;
}
// error('d',"tdef: templ_base: %d", n->tpdef->templ_base);
}
// else {
// SYM removed check for clash w/nested type
// }
if (check_redef(n, this))
return n;
n->base = base = TNAME;
PERM(n);
PERM(tp);
if (tp->base == PTR)
PERM(Pptr(tp)->typ);
if (tp->base == COBJ || tp->base == EOBJ) { // typedef struct/enum { } s; => struct/enum s {};
Pname b = Pbase(tp)->b_name;
if (b->string[0] == '_' && b->string[1] == '_')
switch (tp->base) {
case COBJ: {
if (b->string[2] == 'C') {
Pclass cl = Pclass(b->tp);
b->string = n->string;
cl->string = n->string;
if (!cl->local_sig)
cl->c_strlen = strlen(cl->string);
}
break;
}
case EOBJ: {
if (b->string[2] == 'E') {
Penum en = Penum(b->tp);
b->string = n->string;
en->string = n->string;
if (!en->local_sig)
en->e_strlen = strlen(en->string);
}
}
}
}
DB(if (Ndebug >= 1) {
error('d', &where, ">>'%n'->tdef()%t returning", this, tp);
error('d', &where, " lex_level %d tpdef%t", lex_level, tpdef);
});
return n;
}
Pname name::tname(TOK csu)
/*
"csu" "this" seen, return typedef'd name for "this"
return (TNAME,x)-tp->(COBJ/EOBJ,y)-b_name->(NAME,z)-tp->(csue)
*/
{
// error('d',"'%n'::tname(%k)",this,csu);
char *s = 0;
bit nt = 0;
switch (base) {
case TNAME:
return this;
case NAME: {
Pname tn = insert_type(this, Ctbl, csu); // SYM
Pname on = new name;
tn->base = TNAME;
tn->lex_level = lex_level;
// SYM tn->n_list = n_list = 0;
n_list = 0;
string = tn->string;
*on = *this;