forked from farisawan-2000/cfront-3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dcl.c
1905 lines (1736 loc) · 76.4 KB
/
dcl.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/dcl.c 1.26" */
/*******************************************************************************
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.
dcl.c:
``declare'' all names, that is insert them in the appropriate symbol tables.
Calculate the size for all objects (incl. stack frames),
and find store the offsets for all members (incl. auto variables).
"size.h" holds the constants needed for calculating sizes.
Note that (due to errors) functions may nest
*****************************************************************************/
#include "cfront.h"
#include "size.h"
#include "template.h"
class dcl_context ccvec[MAXCONT], *cc = ccvec;
int byte_offset;
int bit_offset;
int max_align;
int friend_in_class;
extern int no_const;
static Pstmt itail;
Pname dclass(Pname, Ptable);
Pname denum(Pname, Ptable);
void merge_init(Pname, Pfct, Pfct);
static bit check_static_pt(Pname n) {
if (!dtpt_opt)
return 1;
if (all_flag)
return 1;
if (none_flag)
return 1;
if (n->n_stclass == AUTO || n->n_stclass == REGISTER)
return 1;
if (n->n_sto == STATIC)
return 1;
if (curloc.file != first_file)
return 0;
return 1;
}
static int is_empty(Pclass cl, bit const_chk = 0) { /*
** for nested class check, empty means *no* members
** for const object check, means no *data* members
*/
int mbr_cnt = cl->memtbl->max();
if (mbr_cnt == 0)
return 1;
if (cl->baselist == 0 && cl->real_size != 1)
return 0;
// empty class to turn on transitional nested class scope
if (const_chk == 0 && (cl->baselist != 0 || mbr_cnt > 1))
return 0;
int i = 1;
for (Pname nn = cl->memtbl->get_mem(i); nn; NEXT_NAME(cl->memtbl, nn, i)) {
if (nn->base == NAME && nn->n_anon == 0 && nn->tp->base != FCT && nn->tp->base != OVERLOAD
&& nn->tp->base != CLASS && nn->tp->base != ENUM && nn->tp->base != EOBJ
&& nn->n_stclass != STATIC) {
if (nn->string[0] == '_' && nn->string[1] == '_' && nn->string[2] == 'W')
return 1;
else
return 0;
}
}
return 1; // if here, no data members encountered
}
void dosimpl(Pexpr e, Pname n) {
if (n == 0) {
if (dummy_fct == 0)
make_dummy();
n = dummy_fct;
}
Pname cf = curr_fct;
curr_fct = n;
e->simpl();
curr_fct = cf;
}
static Pexpr co_array_init(Pname n, Ptable tbl)
/*
handle simple arrays only. To be done well list_check() must
be rewritten to handle dynamic initialization.
*/
{
Pexpr init = n->n_initializer;
if (init->base != ILIST) {
error("badIr for array ofCOs%n", n);
return 0;
}
Pexpr el = 0;
Pvec v = Pvec(n->tp->skiptypedefs());
Pname cn = v->typ->is_cl_obj();
Pclass cl = cn ? Pclass(cn->tp) : 0;
int i = v->size;
int count = 0;
Pexpr il2;
for (Pexpr il = init->e1; il; il = il2) {
// generate n[0].cl(initializer),
// ...
// n[max].cl(initializer),
Pexpr e = il->e1;
il2 = il->e2;
il->e2 = 0;
if (e == dummy)
break;
if (e->base == VALUE) {
switch (e->tp2->base) {
case CLASS:
if (!same_class(Pclass(e->tp2), cl))
e = new texpr(VALUE, cl, il);
break;
default: {
Pname n2 = e->tp2->is_cl_obj();
if (n2 == 0 || !same_class(Pclass(n2->tp), cl))
e = new texpr(VALUE, cl, il);
}
}
} else
e = new texpr(VALUE, cl, il);
e->e2 = new expr(DEREF, n, new ival(count++));
e = e->typ(tbl);
Ptable oscope = scope;
scope = tbl;
dosimpl(e, cc->nof);
scope = oscope;
if (sti_tbl == tbl) {
Pstmt ist = new estmt(SM, no_where, e, 0);
if (st_ilist == 0)
st_ilist = ist;
else
itail->s_list = ist;
itail = ist;
} else {
// if (il->e1->base==VALUE && il->e1->e1==0 && i!=0) { // no explicit
//initializer el = new texpr(NEW,n->tp,0); el = el->typ(tbl); el->simpl();
// }
// else
el = el ? new expr(G_CM, el, e) : e;
}
}
if (i == 0)
v->size = count;
else if (i < count) {
error("too manyIrs for%n (%d)", n, count);
return 0;
} else if (i > count) {
if (cl->has_ictor())
error('s', "too fewIrs for%n", n);
else
error("too fewIrs for%n (C %srequires a defaultK)", n, cl->string);
return 0;
}
return el;
}
int need_sti(Pexpr e, Ptable tbl, bit accept_name)
/*
check if non-static variables or operations are used
INCOMPLETE
*/
{
if (e == 0)
return 0;
switch (e->base) {
case QUEST:
if (need_sti(e->cond, tbl, 0) && tbl == 0)
return 1;
case PLUS:
case MINUS:
case MUL:
case DIV:
case MOD:
case ER:
case OR:
case ANDAND:
case OROR:
case LS:
case RS:
case EQ:
case NE:
case LT:
case LE:
case GT:
case GE:
case INCR:
case DECR:
case ASSIGN:
if (need_sti(e->e1, tbl, accept_name) && tbl == 0)
return 1;
// no break;
case UMINUS:
case UPLUS:
case NOT:
case COMPL:
if (need_sti(e->e2, tbl, accept_name) && tbl == 0)
return 1;
// no break
case SIZEOF:
default:
return 0;
case CAST:
case G_CAST:
return need_sti(e->e1, tbl, accept_name);
case ADDROF:
return need_sti(e->e2, tbl, 1);
case NAME:
if (accept_name && Pname(e)->n_stclass == STATIC)
return 0;
if (e->tp->tconst()) {
if (vec_const || fct_const)
return 0;
Neval = 0;
e->eval();
if (Neval == 0)
return 0;
}
return 1;
case DEREF:
case REF:
case DOT:
if (accept_name || e->tp && e->tp->base == VEC) {
int x1 = need_sti(e->e1, tbl, e->base == DOT);
int x2 = need_sti(e->e2, tbl, 0);
return x1 || x2;
}
// no break
case ELIST:
case G_CM:
case CM:
if (e->base == CM) {
if (need_sti(e->e1, tbl, 0) || need_sti(e->e2, tbl, 0))
return 1;
else
return 0;
}
// no break
case CALL:
case G_CALL:
case NEW:
case GNEW:
case 0: // hack for `new type (expr)'
if (tbl) {
need_sti(e->e1, tbl, accept_name);
need_sti(e->e2, tbl, accept_name);
if (e->tp && e->tp->base == VEC && e->base == NEW || e->base == GNEW)
need_sti(Pvec(e->tp)->dim, tbl); // preserve ICON,STRING,CCON,FCON
} else if (e->base == 0)
return 0;
// no break
case ICALL:
return 1;
case ICON:
case STRING:
case CCON:
case FCON:
if (tbl) {
char *p = new char[strlen(e->string) + 1];
strcpy(p, e->string);
e->string = p;
}
return 0;
}
}
static void check_def_name(Pname nn, int scope) {
Pfct f = Pfct(nn->tp);
if (def_name == 0 && pdef_name == 0 && friend_in_class == 0 && scope == EXTERN
&& nn->n_scope != STATIC && nn->n_oper != NEW && nn->n_oper != DELETE) {
if (f->body && f->f_inline == 0 && f->f_imeasure == 0) {
pdef_name = def_name = nn;
def_name = 0;
}
}
if (strcmp(nn->string, "main") == 0 && nn->n_table == gtbl && f->f_inline) {
pdef_name = def_name = nn;
def_name = 0;
}
}
static void export_anon(Pname un, Pclass cl, Ptable tbl) {
if (tbl == gtbl) {
if (un->n_sto != STATIC)
error("extern anonymous union (declare as static)");
} else if (tbl->t_name && un->n_sto == STATIC)
error('s', "staticM anonymous union");
// cannot cope with use counts for ANONs:
Pbase(un->tp)->b_name->n_used = 1;
Pbase(un->tp)->b_name->n_assigned_to = 1;
Ptable mtbl = cl->memtbl;
Ptable realtbl = (tbl == gtbl || tbl->t_name) ? tbl : curr_block->memtbl;
int i;
for (Pname nn = mtbl->get_mem(i = 1); nn; NEXT_NAME(mtbl, nn, i)) {
if (nn->base == NAME && nn->tp->base == FCT) {
error(&nn->where, "FM%n for anonymous union", nn);
continue;
}
Ptable tb = nn->n_table;
nn->n_table = 0;
nn->n_tbl_list = 0;
nn->n_scope = un->n_protect ? un->n_protect : un->n_scope;
if (nn->n_key == HIDDEN) // was an error ...
continue;
if (nn->n_key == CLASS && nn->string[0] == '_' && nn->string[1] == '_' && nn->string[2] == 'C')
continue;
// error('d',&nn->where,"exporting anon unionM%n base%k tp%t
// n_key%k",nn,nn->base,nn->tp,nn->n_key);
Pname n = realtbl->look(nn->string, 0);
// error('d',&nn->where,"nn%n n%n ll %d %d",nn,n,n?n->lex_level:0,nn->lex_level);
// if(n)error('d',&nn->where," ntbl %d tbl %d realtbl %d",n->n_table,tbl,realtbl);
if (n && n->n_table != tbl) {
if (tbl == gtbl || tbl->t_name)
error('i', &nn->where, "table mismatch");
if (n->n_table->real_block != realtbl->real_block || n->lex_level != nn->lex_level)
n = 0;
}
if (n == 0) {
adef:
n = tbl->insert(nn, nn->n_key);
if (nn->n_key == CLASS && Nold) { // class/enum tag
// error caught in norm.c
// error(&nn->where,"twoDs of tag %s (one in anonymous union)",n->string);
continue;
}
} else {
// error('d',&nn->where," -- n%n base%k tp%t n_key%k",n,n->base,n->tp,n->n_key);
if (nn->n_key == CLASS) { // class/enum tag
if (n->base == TNAME) { // previously typedef
error(&nn->where, "twoDs ofTN %s (one in anonymous union)", n->string);
continue;
}
goto adef;
}
if (n->base != nn->base // id and typedef
|| nn->base == NAME // both are ids
|| n->tp->check(nn->tp, 0) // non-matching typedefs
)
error(&nn->where, "twoDs of %s (one in anonymous union)", n->string);
continue;
}
n->n_anon = un->string;
nn->n_table = tb;
if (cl->in_class && un->n_sto == STATIC && nn->base != TNAME && nn->n_key != CLASS)
n->n_stclass = STATIC;
}
}
void classdef::make_vec_ctor(Pname default_ctor) {
/* make a non-argument stub ctor for this class that
* invokes the default argument ctor for use with vec_new */
// error('d',"make_vec_ctor(%n )", default_ctor);
Pname tn = Pfct(default_ctor->tp)->f_this;
if (tn->base == ANAME) { // inline ctor ...
tn = new name();
*tn = *(Pfct(default_ctor->tp)->f_this);
tn->base = NAME;
}
Pname cn = this->k_tbl->find_cn(string); // SYM
if (cn)
cn = Pbase(cn->tp)->b_name;
cc->stack();
cc->not = cn;
cc->cot = this;
cc->c_this = tn;
Pexpr th = new expr(THIS, 0, 0);
Pstmt s = new estmt(SM, no_where, 0, 0);
Pexpr e = call_ctor(memtbl, th, default_ctor, 0, REF);
s->e = e;
Pname fn = new name(string);
Pfct f = new fct(void_type, 0, 1);
fn->tp = f;
f->body = new block(curloc, 0, s);
Pname nn = fn->dcl(memtbl, PUBLIC);
nn->n_sto = STATIC;
cc->unstack();
nn->simpl();
nn->dcl_print(0);
this->c_vtor = nn;
delete fn;
}
int stat_init = 0; // in an expression initializing a local static
Pname name::dcl(Ptable tbl, TOK scope)
/*
enter a copy of this name into symbol table "tbl";
- create local symbol tables as needed
"scope" gives the scope in which the declaration was found
- EXTERN, FCT, ARG, PUBLIC, or 0
Compare "scope" with the specified storage class "n_sto"
- AUTO, STATIC, REGISTER, EXTERN, OVERLOAD, FRIEND, or 0
After name::dcl()
n_stclass == 0 class or enum member
REGISTER auto variables declared register
AUTO auto variables not registers
STATIC statically allocated object
n_scope == 0 private class member
PUBLIC public class member
EXTERN name valid in this and other files
STATIC name valid for this file only
FCT name local to a function
ARG name of a function argument
ARGT name of a type defined in an
argument list
ARGS temporary class object with dtor in
initialization of a local static
typecheck function bodies;
typecheck initializers;
note that functions (error recovery) and classes (legal) nest
The return value is used to chain symbol table entries, but cannot
be used for printout because it denotes the sum of all type information
for the name
names of typenames are marked with n_oper==TNAME
WARNING: The handling of scope and storage class is cursed!
*/
{
Pname nn;
Pname odcl = Cdcl;
int sti_vb = 0; // set if initialize with virtual base class
Cdcl = this;
Ptype tx = tp->skiptypedefs();
// error('d',"%n->dcl(%d %k) tp %t ",this,tbl,scope,tp);
switch (base) {
case TNAME:
DB(if (Ddebug >= 1) error('d', &where, "dclTN%n%t scope%k", this, tp, scope););
{
nn = tbl->look(string, 0);
tp->dcl(tbl);
if (tpdef) { // nested
Ptype tx = tpdef;
if (tx->in_class
&& (tx->templ_base == BOUND_TEMPLATE || tx->templ_base == CL_TEMPLATE)) {
delete tx->nested_sig;
tx->nested_sig = make_nested_name(string, tx->in_class);
}
}
// error('d',"%n->dcl TN tp%t nn%n nn->tp%t",this,tp,nn,nn?nn->tp:0);
// error('d'," ll this %d nn %d tbl
// %s",lex_level,nn?nn->lex_level:0,tbl==gtbl?"global
// table":tbl->t_name?tbl->t_name->string:"???"); if(tpdef)error('d',"
// in%t",tpdef->in_class);
/* actual redefinitions are caught in name::tdef() */
if (nn) {
Cdcl = odcl;
return 0;
}
PERM(tp);
nn = new name(string);
nn->base = TNAME;
nn->where = where;
nn->tp = tp;
nn->lex_level = lex_level; // SYM
nn->tpdef = tpdef;
Pname tn = tbl->insert(nn, 0);
PERM(tn);
extern void typedef_check(Pname);
typedef_check(tn);
delete nn;
Cdcl = odcl;
return this;
}
case CATCH: // avoid errors
base = NAME;
scope = ARG;
// no break
case NAME:
DB(if (Ddebug >= 1) {
error('d', &where, "dclN%n%t (q%n) scope%k", this, tp, n_qualifier, scope);
error('d', &where, " n_oper%k n_sto%k n_stclass%k n_scope%k", n_oper, n_sto, n_stclass,
n_scope);
});
switch (n_oper) {
case COMPL:
if (tp->base != FCT) {
error("~%s notF", string);
n_oper = 0;
}
break;
case TNAME:
if (tp->base != FCT)
n_oper = 0;
break;
}
break;
default:
error('i', "NX inN::dcl()");
break;
}
if (n_qualifier) { // c::f()
// class function,
// friend declaration, or
// static member initializer
Pname cn = n_qualifier;
switch (cn->base) {
case TNAME:
break;
case NAME:
cn = gtbl->look(cn->string, 0);
if (cn && cn->base == TNAME)
break;
default:
error("badQr%n for%n", n_qualifier, this);
Cdcl = odcl;
return 0;
}
cn->tp = cn->tp->skiptypedefs();
if (cn->tp->base != COBJ) {
error(&where, "Qr%n not aCN", n_qualifier);
Cdcl = odcl;
return 0;
}
cn = Pbase(cn->tp)->b_name;
if (n_oper)
check_oper(cn);
Pclass cl = Pclass(cn->tp);
if (same_class(cl, cc->cot)) {
n_qualifier = 0;
goto xdr;
} else if ((cl->defined & (DEFINED | SIMPLIFIED)) == 0) {
error("C%nU", cn);
Cdcl = odcl;
return 0;
} else if (cl->c_body == 1) // III
cl->dcl_print(0);
Ptable etbl = cl->memtbl;
Pname x = etbl->look(string, 0);
if (x == 0 || x->n_table != etbl) {
Ptable tt = n_table;
n_table = etbl;
error("%n is not aM of%n", this, cn);
n_table = tt;
Cdcl = odcl;
return 0;
}
if (tp->base == FCT) { // III
if (friend_in_class == 0 && n_sto != FRIEND
&& Pfct(tp)->body == 0) { // c::f(); needed for friend
error("QdN%n inFD", x);
Cdcl = odcl;
return 0;
}
if (Pfct(tp)->body == 0) {
Pfct(tp)->memof = cl;
int xx;
if (x->tp->base == OVERLOAD)
xx = Pgen(x->tp)->find(Pfct(tp), 0) == 0;
else
xx = x->tp->check(tp, 0);
if (xx) {
Ptable tt = n_table;
n_table = etbl;
error("%n ofT%t is not aM of%n", this, tp, cn);
n_table = tt;
Cdcl = odcl;
return 0;
}
}
} else {
if (x->n_stclass != STATIC) { // e.g. int c::i = 7
error("D of non staticCM%n", this);
Cdcl = odcl;
return 0;
}
if (n_sto) {
error("staticCM declared%k", n_sto);
Cdcl = odcl;
return 0;
}
// explicit definition of this static class member
if (cl->class_base == INSTANTIATED)
n_redefined = 1;
tbl = etbl;
}
} // if n_qualifier
xdr:
if (n_oper && tp->base != FCT && n_sto != OVERLOAD)
error("operator%k not aF", n_oper);
/* if a storage class was specified
check that it is legal in the scope
else
provide default storage class
some details must be left until the type of the object is known
*/
n_stclass = n_sto;
n_scope = scope; /* default scope & storage class */
switch (n_sto) {
default:
error('i', "unX %k", n_sto);
case FRIEND: {
Pclass cl = cc->cot;
switch (scope) {
case 0:
case PUBLIC:
break;
default:
error("friend%n not inCD(%k)", this, scope);
base = 0;
Cdcl = odcl;
return 0;
}
switch (n_oper) {
case 0:
case NEW:
case DELETE:
case CTOR:
case DTOR:
case TYPE:
n_sto = 0;
break;
default:
n_sto = OVERLOAD;
}
// error('d',&where,"dcl friend%n tx%t -%k",this,tx,tx->base);
// error('d',&where," n_oper%k n_sto%k scope%k",n_oper,n_sto,scope);
switch (tx->base) {
case COBJ:
nn = Pbase(tx)->b_name;
break;
case CLASS:
nn = this;
break;
case FCT:
Pfct(tx)->def_context = cc->cot;
cc->stack();
cc->not = 0;
cc->tot = 0;
cc->cot = 0;
friend_in_class++;
n_sto = 0;
// XXXXX should enter in next enclosing scope
lex_level = 0;
nn = dcl(gtbl, EXTERN);
if (nn == 0) {
Cdcl = odcl;
return 0;
}
friend_in_class--;
cc->unstack();
if (nn->tp->base == OVERLOAD)
nn = Pgen(nn->tp)->find(Pfct(tx), 1);
break;
default:
error("badT%t of friend%n", tp, this);
Cdcl = odcl;
return 0;
}
PERM(nn);
cl->friend_list = new name_list(nn, cl->friend_list);
Cdcl = odcl;
return nn;
}
case OVERLOAD:
error(strict_opt ? 0 : 'w', "`overload' used (anachronism)");
n_sto = 0;
switch (tp->base) { // ignore overload!
case FCT:
break;
default:
base = 0;
Cdcl = odcl;
return this;
}
break;
case REGISTER:
if (tp->base == FCT) {
error('w', "%n: register (ignored)", this);
goto ddd;
}
// no break
case AUTO:
switch (scope) {
case 0:
case PUBLIC:
case EXTERN:
error("%k not inF", n_sto);
goto ddd;
}
if (n_sto == AUTO) // always redundant
n_sto = 0;
break;
case EXTERN:
switch (scope) {
case 0:
case PUBLIC:
/* extern is provided as a default for functions without body */
if (tp->base != FCT)
error("externM%n", this);
// no break
case ARG:
goto ddd;
case FCT: {
Pname nn = gtbl->look(string, 0);
tp->dcl(tbl);
if (nn && tp->base != FCT && tp->check(nn->tp, 0)) {
error("twoDs of%n;Ts:%t and%t", this, nn->tp, tp);
Cdcl = odcl;
return 0;
}
}
}
n_stclass = STATIC;
n_scope = EXTERN; /* avoid FCT scoped externs to allow better checking */
break;
case STATIC:
switch (scope) {
case ARG:
goto ddd;
case 0:
case PUBLIC:
n_stclass = STATIC;
n_scope = scope;
break;
default:
n_scope = STATIC;
}
break;
case 0:
ddd:
switch (scope) { /* default storage classes */
case EXTERN:
n_scope = EXTERN;
n_stclass = STATIC;
break;
case FCT:
if (tp->base == FCT) {
n_stclass = STATIC;
n_scope = EXTERN;
} else
n_stclass = AUTO;
break;
case ARG:
n_stclass = AUTO;
break;
case 0:
case PUBLIC:
n_stclass = 0;
break;
}
}
/*
now insert the name into the appropriate symbol table,
and compare types with previous declarations of that name
do type dependent adjustments of the scope
*/
static int warn_ldouble = 0;
switch (tx->base) {
case ASM: {
Pbase b = Pbase(tp);
Pname n = tbl->insert(this, 0);
n->assign();
n->use();
char *s = (char *) b->b_name; // save asm string. Shoddy
int ll = strlen(s);
char *s2 = new char[ll + 1];
strcpy(s2, s);
b->b_name = Pname(s2);
Cdcl = odcl;
return this;
}
case CLASS:
if (n_key == REF) { // class x;
// Pclass cl = Pclass(tx);
nn = tbl->insert(this, CLASS); // copy for member lookup
n_key = REF; // changed by table::insert()
// if ( ansi_opt && (cl->defined&(DEFINED))==0) { // "class x;"
// char* su = (cl->csu==UNION || cl->csu==ANON) ? "union" :
//"struct"; if ( cl->nested_sig ) fprintf(out_file,"%s __%s;\n",su,cl->nested_sig); else
//if ( cl->lex_level == 0 ) fprintf(out_file,"%s %s;\n",su,cl->string); else
// fprintf(out_file,"%s %s;\n",su,cl->local_sig);
// }
} else {
if (tx->in_class
&& (tx->templ_base == BOUND_TEMPLATE || tx->templ_base == CL_TEMPLATE)) {
delete tx->nested_sig;
tx->nested_sig = make_nested_name(Pclass(tx)->string, tx->in_class);
}
tp = tx;
nn = dclass(this, tbl);
}
Cdcl = odcl;
return nn;
case ENUM:
if (tx->in_class && (tx->templ_base == BOUND_TEMPLATE || tx->templ_base == CL_TEMPLATE)) {
delete tx->nested_sig;
tx->nested_sig = make_nested_name(Penum(tx)->string, tx->in_class);
}
tp = tx;
nn = denum(this, tbl);
Cdcl = odcl;
return nn;
case FCT:
tp = tx;
nn = dofct(tbl, scope);
if (nn == 0) {
Cdcl = odcl;
return 0;
}
if (pdef_name == 0)
check_def_name(nn, scope);
break;
case FIELD:
switch (n_stclass) {
case 0:
case PUBLIC:
break;
default:
error("%k field", n_stclass);
n_stclass = 0;
}
if (cc->not == 0 || (cc->cot->csu == UNION && !ansi_opt) || cc->cot->csu == ANON) {
if (cc->not )
error('s', "bit-field as member of union");
else
error("bit-field not inC");
PERM(tp);
Cdcl = odcl;
return this;
}
if (string) {
nn = tbl->insert(this, 0);
n_table = nn->n_table;
if (Nold)
error("twoDs of field%n", this);
}
tp->dcl(tbl);
field_align();
break;
case COBJ: {
Pclass cl = Pclass(Pbase(tx)->b_name->tp);
// error('d',"%n %d cl%t %d",this,lex_level,cl,cl->lex_level);
// if (cl->lex_level > lex_level) //SYM now obsolete
// error('i',"'%n'->dcl(%d,%k) C%t is not visible in this
//scope",this,tbl,scope,cl);
if (cl->csu == ANON)
export_anon(this, cl, tbl);
if (cl->c_abstract) {
if (cl->string[0] == '_' && cl->string[1] == '_' && cl->string[2] == 'C')
error('e', "D ofO of abstractC - pure virtual function(s) ");
else
error('e', "D ofO of abstractC%t - pure virtual function(s) ", cl);
for (Pbcl bcl = cl->baselist; bcl; bcl = bcl->next)
for (Pvirt n = bcl->bclass->virt_list; n; n = n->next) {
velem *ivec = n->virt_init;
Pname vn;
for (int i = 0; vn = ivec[i].n; i++) {
Pname n = cl->memtbl->look(vn->string, 0);
if (vn->n_initializer && (n == 0 || n->base == PUBLIC))
error('c', "%n ", vn);
}
}
error('c', "have not been defined\n");
}
goto cde;
}
case VOID:
if (n_scope != ARG) {
error("badBT:%k%n", tx->base, this);
Cdcl = odcl;
return 0;
}
break;
case LDOUBLE:
if (warn_ldouble == 0 && ansi_opt == 0) {
++warn_ldouble;
error('w', "long double supported under ``+a1'' option only, generating ``double%n''",
this);
}
goto cde;
case PTR:
// if (ansi_opt && scope==ARG && Pptr(tx)->typ && Pptr(tx)->typ->base==COBJ)
// {
// Pclass cl=Pclass(Pbase(Pptr(tx)->typ)->b_name->tp);
// if (ansi_opt && (cl->defined&(DEFINED))==0) {
// char* s = cl->csu==UNION || cl->csu==ANON ? "union" : "struct";
// if ( cl->nested_sig )
// fprintf(out_file,"%s __%s;\n",s,cl->nested_sig);
// else
// fprintf(out_file,"%s
//%s;\n",s,cl->local_sig?cl->local_sig:cl->string);
// }
// }
case VEC:
case RPTR:
tp->dcl(tbl);
default:
cde:
nn = tbl->insert(this, 0);
n_table = nn->n_table;
nn->n_redefined = n_redefined;
if (Nold) {
if (nn->base == TNAME && base == NAME) {
if (nn->tpdef && nn->tpdef->in_class && nn->tpdef->in_class->csu == ANON)
error("twoDs of %s (one in anonymous union)", nn->string);
else
error("%n declared as identifier andTdef", nn);
// avoid later errors ...
nn->n_key = HIDDEN;
n_table = 0;
goto cde;