-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtree.c
2117 lines (1776 loc) · 55.6 KB
/
tree.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
/* Language-dependent node constructors for parse phase of GNU compiler.
Copyright (C) 1987, 88, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
Hacked by Michael Tiemann ([email protected])
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU CC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include "config.h"
#include <stdio.h>
#include "obstack.h"
#include "tree.h"
#include "cp-tree.h"
#include "flags.h"
#include "rtl.h"
#ifdef __STDC__
#include <stdarg.h>
#else
#include <stdarg.h>
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef NEED_DECLARATION_FREE
extern void free PROTO((void *));
#endif
extern void compiler_error ();
static tree get_identifier_list PROTO((tree));
static tree bot_manip PROTO((tree));
static tree perm_manip PROTO((tree));
static tree build_cplus_array_type_1 PROTO((tree, tree));
static void list_hash_add PROTO((int, tree));
static int list_hash PROTO((tree, tree, tree));
static tree list_hash_lookup PROTO((int, int, int, int, tree, tree,
tree));
#define CEIL(x,y) (((x) + (y) - 1) / (y))
/* Return nonzero if REF is an lvalue valid for this language.
Lvalues can be assigned, unless they have TREE_READONLY.
Lvalues can have their address taken, unless they have DECL_REGISTER. */
int
real_lvalue_p (ref)
tree ref;
{
if (! language_lvalue_valid (ref))
return 0;
if (TREE_CODE (TREE_TYPE (ref)) == REFERENCE_TYPE)
return 1;
if (ref == current_class_ptr && flag_this_is_variable <= 0)
return 0;
switch (TREE_CODE (ref))
{
/* preincrements and predecrements are valid lvals, provided
what they refer to are valid lvals. */
case PREINCREMENT_EXPR:
case PREDECREMENT_EXPR:
case COMPONENT_REF:
case SAVE_EXPR:
case UNSAVE_EXPR:
case TRY_CATCH_EXPR:
case WITH_CLEANUP_EXPR:
return real_lvalue_p (TREE_OPERAND (ref, 0));
case STRING_CST:
return 1;
case VAR_DECL:
if (TREE_READONLY (ref) && ! TREE_STATIC (ref)
&& DECL_LANG_SPECIFIC (ref)
&& DECL_IN_AGGR_P (ref))
return 0;
case INDIRECT_REF:
case ARRAY_REF:
case PARM_DECL:
case RESULT_DECL:
case ERROR_MARK:
if (TREE_CODE (TREE_TYPE (ref)) != FUNCTION_TYPE
&& TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE)
return 1;
break;
/* A currently unresolved scope ref. */
case SCOPE_REF:
my_friendly_abort (103);
case OFFSET_REF:
if (TREE_CODE (TREE_OPERAND (ref, 1)) == FUNCTION_DECL)
return 1;
return real_lvalue_p (TREE_OPERAND (ref, 0))
&& real_lvalue_p (TREE_OPERAND (ref, 1));
break;
case COND_EXPR:
return (real_lvalue_p (TREE_OPERAND (ref, 1))
&& real_lvalue_p (TREE_OPERAND (ref, 2)));
case MODIFY_EXPR:
return 1;
case COMPOUND_EXPR:
return real_lvalue_p (TREE_OPERAND (ref, 1));
case MAX_EXPR:
case MIN_EXPR:
return (real_lvalue_p (TREE_OPERAND (ref, 0))
&& real_lvalue_p (TREE_OPERAND (ref, 1)));
}
return 0;
}
/* This differs from real_lvalue_p in that class rvalues are considered
lvalues. */
int
lvalue_p (ref)
tree ref;
{
if (! language_lvalue_valid (ref))
return 0;
if (TREE_CODE (TREE_TYPE (ref)) == REFERENCE_TYPE)
return 1;
if (ref == current_class_ptr && flag_this_is_variable <= 0)
return 0;
switch (TREE_CODE (ref))
{
/* preincrements and predecrements are valid lvals, provided
what they refer to are valid lvals. */
case PREINCREMENT_EXPR:
case PREDECREMENT_EXPR:
case REALPART_EXPR:
case IMAGPART_EXPR:
case COMPONENT_REF:
case SAVE_EXPR:
case UNSAVE_EXPR:
case TRY_CATCH_EXPR:
case WITH_CLEANUP_EXPR:
return lvalue_p (TREE_OPERAND (ref, 0));
case STRING_CST:
return 1;
case VAR_DECL:
if (TREE_READONLY (ref) && ! TREE_STATIC (ref)
&& DECL_LANG_SPECIFIC (ref)
&& DECL_IN_AGGR_P (ref))
return 0;
case INDIRECT_REF:
case ARRAY_REF:
case PARM_DECL:
case RESULT_DECL:
case ERROR_MARK:
if (TREE_CODE (TREE_TYPE (ref)) != FUNCTION_TYPE
&& TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE)
return 1;
break;
case TARGET_EXPR:
return 1;
case CALL_EXPR:
if (IS_AGGR_TYPE (TREE_TYPE (ref)))
return 1;
break;
/* A currently unresolved scope ref. */
case SCOPE_REF:
my_friendly_abort (103);
case OFFSET_REF:
if (TREE_CODE (TREE_OPERAND (ref, 1)) == FUNCTION_DECL)
return 1;
return lvalue_p (TREE_OPERAND (ref, 0))
&& lvalue_p (TREE_OPERAND (ref, 1));
break;
case COND_EXPR:
return (lvalue_p (TREE_OPERAND (ref, 1))
&& lvalue_p (TREE_OPERAND (ref, 2)));
case MODIFY_EXPR:
return 1;
case COMPOUND_EXPR:
return lvalue_p (TREE_OPERAND (ref, 1));
case MAX_EXPR:
case MIN_EXPR:
return (lvalue_p (TREE_OPERAND (ref, 0))
&& lvalue_p (TREE_OPERAND (ref, 1)));
}
return 0;
}
/* Return nonzero if REF is an lvalue valid for this language;
otherwise, print an error message and return zero. */
int
lvalue_or_else (ref, string)
tree ref;
char *string;
{
int win = lvalue_p (ref);
if (! win)
error ("non-lvalue in %s", string);
return win;
}
/* INIT is a CALL_EXPR which needs info about its target.
TYPE is the type that this initialization should appear to have.
Build an encapsulation of the initialization to perform
and return it so that it can be processed by language-independent
and language-specific expression expanders. */
tree
build_cplus_new (type, init)
tree type;
tree init;
{
tree slot;
tree rval;
if (TREE_CODE (init) != CALL_EXPR && TREE_CODE (init) != NEW_EXPR)
return init;
slot = build (VAR_DECL, type);
layout_decl (slot, 0);
rval = build (NEW_EXPR, type,
TREE_OPERAND (init, 0), TREE_OPERAND (init, 1), slot);
TREE_SIDE_EFFECTS (rval) = 1;
rval = build (TARGET_EXPR, type, slot, rval, NULL_TREE, NULL_TREE);
TREE_SIDE_EFFECTS (rval) = 1;
return rval;
}
/* Recursively search EXP for CALL_EXPRs that need cleanups and replace
these CALL_EXPRs with tree nodes that will perform the cleanups. */
tree
break_out_cleanups (exp)
tree exp;
{
tree tmp = exp;
if (TREE_CODE (tmp) == CALL_EXPR
&& TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (tmp)))
return build_cplus_new (TREE_TYPE (tmp), tmp);
while (TREE_CODE (tmp) == NOP_EXPR
|| TREE_CODE (tmp) == CONVERT_EXPR
|| TREE_CODE (tmp) == NON_LVALUE_EXPR)
{
if (TREE_CODE (TREE_OPERAND (tmp, 0)) == CALL_EXPR
&& TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (TREE_OPERAND (tmp, 0))))
{
TREE_OPERAND (tmp, 0)
= build_cplus_new (TREE_TYPE (TREE_OPERAND (tmp, 0)),
TREE_OPERAND (tmp, 0));
break;
}
else
tmp = TREE_OPERAND (tmp, 0);
}
return exp;
}
/* Recursively perform a preorder search EXP for CALL_EXPRs, making
copies where they are found. Returns a deep copy all nodes transitively
containing CALL_EXPRs. */
tree
break_out_calls (exp)
tree exp;
{
register tree t1, t2;
register enum tree_code code;
register int changed = 0;
register int i;
if (exp == NULL_TREE)
return exp;
code = TREE_CODE (exp);
if (code == CALL_EXPR)
return copy_node (exp);
/* Don't try and defeat a save_expr, as it should only be done once. */
if (code == SAVE_EXPR)
return exp;
switch (TREE_CODE_CLASS (code))
{
default:
abort ();
case 'c': /* a constant */
case 't': /* a type node */
case 'x': /* something random, like an identifier or an ERROR_MARK. */
return exp;
case 'd': /* A decl node */
#if 0 /* This is bogus. jason 9/21/94 */
t1 = break_out_calls (DECL_INITIAL (exp));
if (t1 != DECL_INITIAL (exp))
{
exp = copy_node (exp);
DECL_INITIAL (exp) = t1;
}
#endif
return exp;
case 'b': /* A block node */
{
/* Don't know how to handle these correctly yet. Must do a
break_out_calls on all DECL_INITIAL values for local variables,
and also break_out_calls on all sub-blocks and sub-statements. */
abort ();
}
return exp;
case 'e': /* an expression */
case 'r': /* a reference */
case 's': /* an expression with side effects */
for (i = tree_code_length[(int) code] - 1; i >= 0; i--)
{
t1 = break_out_calls (TREE_OPERAND (exp, i));
if (t1 != TREE_OPERAND (exp, i))
{
exp = copy_node (exp);
TREE_OPERAND (exp, i) = t1;
}
}
return exp;
case '<': /* a comparison expression */
case '2': /* a binary arithmetic expression */
t2 = break_out_calls (TREE_OPERAND (exp, 1));
if (t2 != TREE_OPERAND (exp, 1))
changed = 1;
case '1': /* a unary arithmetic expression */
t1 = break_out_calls (TREE_OPERAND (exp, 0));
if (t1 != TREE_OPERAND (exp, 0))
changed = 1;
if (changed)
{
if (tree_code_length[(int) code] == 1)
return build1 (code, TREE_TYPE (exp), t1);
else
return build (code, TREE_TYPE (exp), t1, t2);
}
return exp;
}
}
extern struct obstack *current_obstack;
extern struct obstack permanent_obstack, class_obstack;
extern struct obstack *saveable_obstack;
extern struct obstack *expression_obstack;
/* Here is how primitive or already-canonicalized types' hash
codes are made. MUST BE CONSISTENT WITH tree.c !!! */
#define TYPE_HASH(TYPE) ((HOST_WIDE_INT) (TYPE) & 0777777)
/* Construct, lay out and return the type of methods belonging to class
BASETYPE and whose arguments are described by ARGTYPES and whose values
are described by RETTYPE. If each type exists already, reuse it. */
tree
build_cplus_method_type (basetype, rettype, argtypes)
tree basetype, rettype, argtypes;
{
register tree t;
tree ptype;
int hashcode;
/* Make a node of the sort we want. */
t = make_node (METHOD_TYPE);
TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
TREE_TYPE (t) = rettype;
if (IS_SIGNATURE (basetype))
ptype = build_signature_pointer_type (TYPE_MAIN_VARIANT (basetype),
TYPE_READONLY (basetype),
TYPE_VOLATILE (basetype));
else
ptype = build_pointer_type (basetype);
/* The actual arglist for this function includes a "hidden" argument
which is "this". Put it into the list of argument types. */
argtypes = tree_cons (NULL_TREE, ptype, argtypes);
TYPE_ARG_TYPES (t) = argtypes;
TREE_SIDE_EFFECTS (argtypes) = 1; /* Mark first argtype as "artificial". */
/* If we already have such a type, use the old one and free this one.
Note that it also frees up the above cons cell if found. */
hashcode = TYPE_HASH (basetype) + TYPE_HASH (rettype) + type_hash_list (argtypes);
t = type_hash_canon (hashcode, t);
if (TYPE_SIZE (t) == 0)
layout_type (t);
return t;
}
static tree
build_cplus_array_type_1 (elt_type, index_type)
tree elt_type;
tree index_type;
{
register struct obstack *ambient_obstack = current_obstack;
register struct obstack *ambient_saveable_obstack = saveable_obstack;
tree t;
/* We need a new one. If both ELT_TYPE and INDEX_TYPE are permanent,
make this permanent too. */
if (TREE_PERMANENT (elt_type)
&& (index_type == 0 || TREE_PERMANENT (index_type)))
{
current_obstack = &permanent_obstack;
saveable_obstack = &permanent_obstack;
}
if (processing_template_decl)
{
t = make_node (ARRAY_TYPE);
TREE_TYPE (t) = elt_type;
TYPE_DOMAIN (t) = index_type;
}
else
t = build_array_type (elt_type, index_type);
/* Push these needs up so that initialization takes place
more easily. */
TYPE_NEEDS_CONSTRUCTING (t) = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (elt_type));
TYPE_NEEDS_DESTRUCTOR (t) = TYPE_NEEDS_DESTRUCTOR (TYPE_MAIN_VARIANT (elt_type));
current_obstack = ambient_obstack;
saveable_obstack = ambient_saveable_obstack;
return t;
}
tree
build_cplus_array_type (elt_type, index_type)
tree elt_type;
tree index_type;
{
tree t;
int constp = TYPE_READONLY (elt_type);
int volatilep = TYPE_VOLATILE (elt_type);
elt_type = TYPE_MAIN_VARIANT (elt_type);
t = build_cplus_array_type_1 (elt_type, index_type);
if (constp || volatilep)
t = cp_build_type_variant (t, constp, volatilep);
return t;
}
/* Make a variant type in the proper way for C/C++, propagating qualifiers
down to the element type of an array. */
tree
cp_build_type_variant (type, constp, volatilep)
tree type;
int constp, volatilep;
{
if (type == error_mark_node)
return type;
if (TREE_CODE (type) == ARRAY_TYPE)
{
tree real_main_variant = TYPE_MAIN_VARIANT (type);
push_obstacks (TYPE_OBSTACK (real_main_variant),
TYPE_OBSTACK (real_main_variant));
type = build_cplus_array_type_1 (cp_build_type_variant
(TREE_TYPE (type), constp, volatilep),
TYPE_DOMAIN (type));
/* TYPE must be on same obstack as REAL_MAIN_VARIANT. If not,
make a copy. (TYPE might have come from the hash table and
REAL_MAIN_VARIANT might be in some function's obstack.) */
if (TYPE_OBSTACK (type) != TYPE_OBSTACK (real_main_variant))
{
type = copy_node (type);
TYPE_POINTER_TO (type) = TYPE_REFERENCE_TO (type) = 0;
}
TYPE_MAIN_VARIANT (type) = real_main_variant;
pop_obstacks ();
return type;
}
return build_type_variant (type, constp, volatilep);
}
/* Add OFFSET to all base types of T.
OFFSET, which is a type offset, is number of bytes.
Note that we don't have to worry about having two paths to the
same base type, since this type owns its association list. */
void
propagate_binfo_offsets (binfo, offset)
tree binfo;
tree offset;
{
tree binfos = BINFO_BASETYPES (binfo);
int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
for (i = 0; i < n_baselinks; /* note increment is done in the loop. */)
{
tree base_binfo = TREE_VEC_ELT (binfos, i);
if (TREE_VIA_VIRTUAL (base_binfo))
i += 1;
else
{
int j;
tree base_binfos = BINFO_BASETYPES (base_binfo);
tree delta;
for (j = i+1; j < n_baselinks; j++)
if (! TREE_VIA_VIRTUAL (TREE_VEC_ELT (binfos, j)))
{
/* The next basetype offset must take into account the space
between the classes, not just the size of each class. */
delta = size_binop (MINUS_EXPR,
BINFO_OFFSET (TREE_VEC_ELT (binfos, j)),
BINFO_OFFSET (base_binfo));
break;
}
#if 0
if (BINFO_OFFSET_ZEROP (base_binfo))
BINFO_OFFSET (base_binfo) = offset;
else
BINFO_OFFSET (base_binfo)
= size_binop (PLUS_EXPR, BINFO_OFFSET (base_binfo), offset);
#else
BINFO_OFFSET (base_binfo) = offset;
#endif
if (base_binfos)
{
int k;
tree chain = NULL_TREE;
/* Now unshare the structure beneath BASE_BINFO. */
for (k = TREE_VEC_LENGTH (base_binfos)-1;
k >= 0; k--)
{
tree base_base_binfo = TREE_VEC_ELT (base_binfos, k);
if (! TREE_VIA_VIRTUAL (base_base_binfo))
TREE_VEC_ELT (base_binfos, k)
= make_binfo (BINFO_OFFSET (base_base_binfo),
base_base_binfo,
BINFO_VTABLE (base_base_binfo),
BINFO_VIRTUALS (base_base_binfo),
chain);
chain = TREE_VEC_ELT (base_binfos, k);
TREE_VIA_PUBLIC (chain) = TREE_VIA_PUBLIC (base_base_binfo);
TREE_VIA_PROTECTED (chain) = TREE_VIA_PROTECTED (base_base_binfo);
BINFO_INHERITANCE_CHAIN (chain) = base_binfo;
}
/* Now propagate the offset to the base types. */
propagate_binfo_offsets (base_binfo, offset);
}
/* Go to our next class that counts for offset propagation. */
i = j;
if (i < n_baselinks)
offset = size_binop (PLUS_EXPR, offset, delta);
}
}
}
/* Compute the actual offsets that our virtual base classes
will have *for this type*. This must be performed after
the fields are laid out, since virtual baseclasses must
lay down at the end of the record.
Returns the maximum number of virtual functions any of the virtual
baseclasses provide. */
int
layout_vbasetypes (rec, max)
tree rec;
int max;
{
/* Get all the virtual base types that this type uses.
The TREE_VALUE slot holds the virtual baseclass type. */
tree vbase_types = get_vbase_types (rec);
#ifdef STRUCTURE_SIZE_BOUNDARY
unsigned record_align = MAX (STRUCTURE_SIZE_BOUNDARY, TYPE_ALIGN (rec));
#else
unsigned record_align = MAX (BITS_PER_UNIT, TYPE_ALIGN (rec));
#endif
int desired_align;
/* Record size so far is CONST_SIZE + VAR_SIZE bits,
where CONST_SIZE is an integer
and VAR_SIZE is a tree expression.
If VAR_SIZE is null, the size is just CONST_SIZE.
Naturally we try to avoid using VAR_SIZE. */
register unsigned const_size = 0;
register tree var_size = 0;
int nonvirtual_const_size;
CLASSTYPE_VBASECLASSES (rec) = vbase_types;
if (TREE_CODE (TYPE_SIZE (rec)) == INTEGER_CST)
const_size = TREE_INT_CST_LOW (TYPE_SIZE (rec));
else
var_size = TYPE_SIZE (rec);
nonvirtual_const_size = const_size;
while (vbase_types)
{
tree basetype = BINFO_TYPE (vbase_types);
tree offset;
desired_align = TYPE_ALIGN (basetype);
record_align = MAX (record_align, desired_align);
if (const_size == 0)
offset = integer_zero_node;
else
{
/* Give each virtual base type the alignment it wants. */
const_size = CEIL (const_size, TYPE_ALIGN (basetype))
* TYPE_ALIGN (basetype);
offset = size_int (CEIL (const_size, BITS_PER_UNIT));
}
if (CLASSTYPE_VSIZE (basetype) > max)
max = CLASSTYPE_VSIZE (basetype);
BINFO_OFFSET (vbase_types) = offset;
if (TREE_CODE (TYPE_SIZE (basetype)) == INTEGER_CST)
{
/* Every virtual baseclass takes a least a UNIT, so that we can
take it's address and get something different for each base. */
const_size += MAX (BITS_PER_UNIT,
TREE_INT_CST_LOW (TYPE_SIZE (basetype))
- TREE_INT_CST_LOW (CLASSTYPE_VBASE_SIZE (basetype)));
}
else if (var_size == 0)
var_size = TYPE_SIZE (basetype);
else
var_size = size_binop (PLUS_EXPR, var_size, TYPE_SIZE (basetype));
vbase_types = TREE_CHAIN (vbase_types);
}
if (const_size)
{
/* Because a virtual base might take a single byte above,
we have to re-adjust the total size to make sure it it
a multiple of the alignment. */
/* Give the whole object the alignment it wants. */
const_size = CEIL (const_size, record_align) * record_align;
}
/* Set the alignment in the complete type. We don't set CLASSTYPE_ALIGN
here, as that is for this class, without any virtual base classes. */
TYPE_ALIGN (rec) = record_align;
if (const_size != nonvirtual_const_size)
{
CLASSTYPE_VBASE_SIZE (rec)
= size_int (const_size - nonvirtual_const_size);
TYPE_SIZE (rec) = size_int (const_size);
}
/* Now propagate offset information throughout the lattice
under the vbase type. */
for (vbase_types = CLASSTYPE_VBASECLASSES (rec); vbase_types;
vbase_types = TREE_CHAIN (vbase_types))
{
tree base_binfos = BINFO_BASETYPES (vbase_types);
BINFO_INHERITANCE_CHAIN (vbase_types) = TYPE_BINFO (rec);
if (base_binfos)
{
tree chain = NULL_TREE;
int j;
/* Now unshare the structure beneath BASE_BINFO. */
for (j = TREE_VEC_LENGTH (base_binfos)-1;
j >= 0; j--)
{
tree base_base_binfo = TREE_VEC_ELT (base_binfos, j);
if (! TREE_VIA_VIRTUAL (base_base_binfo))
TREE_VEC_ELT (base_binfos, j)
= make_binfo (BINFO_OFFSET (base_base_binfo),
base_base_binfo,
BINFO_VTABLE (base_base_binfo),
BINFO_VIRTUALS (base_base_binfo),
chain);
chain = TREE_VEC_ELT (base_binfos, j);
TREE_VIA_PUBLIC (chain) = TREE_VIA_PUBLIC (base_base_binfo);
TREE_VIA_PROTECTED (chain) = TREE_VIA_PROTECTED (base_base_binfo);
BINFO_INHERITANCE_CHAIN (chain) = vbase_types;
}
propagate_binfo_offsets (vbase_types, BINFO_OFFSET (vbase_types));
}
}
return max;
}
/* Lay out the base types of a record type, REC.
Tentatively set the size and alignment of REC
according to the base types alone.
Offsets for immediate nonvirtual baseclasses are also computed here.
TYPE_BINFO (REC) should be NULL_TREE on entry, and this routine
creates a list of base_binfos in TYPE_BINFO (REC) from BINFOS.
Returns list of virtual base classes in a FIELD_DECL chain. */
tree
layout_basetypes (rec, binfos)
tree rec, binfos;
{
/* Chain to hold all the new FIELD_DECLs which point at virtual
base classes. */
tree vbase_decls = NULL_TREE;
#ifdef STRUCTURE_SIZE_BOUNDARY
unsigned record_align = MAX (STRUCTURE_SIZE_BOUNDARY, TYPE_ALIGN (rec));
#else
unsigned record_align = MAX (BITS_PER_UNIT, TYPE_ALIGN (rec));
#endif
/* Record size so far is CONST_SIZE + VAR_SIZE bits, where CONST_SIZE is
an integer and VAR_SIZE is a tree expression. If VAR_SIZE is null,
the size is just CONST_SIZE. Naturally we try to avoid using
VAR_SIZE. And so far, we've been successful. */
#if 0
register tree var_size = 0;
#endif
register unsigned const_size = 0;
int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
/* Handle basetypes almost like fields, but record their
offsets differently. */
for (i = 0; i < n_baseclasses; i++)
{
int inc, desired_align, int_vbase_size;
register tree base_binfo = TREE_VEC_ELT (binfos, i);
register tree basetype = BINFO_TYPE (base_binfo);
tree decl, offset;
if (TYPE_SIZE (basetype) == 0)
{
#if 0
/* This error is now reported in xref_tag, thus giving better
location information. */
error_with_aggr_type (base_binfo,
"base class `%s' has incomplete type");
TREE_VIA_PUBLIC (base_binfo) = 1;
TREE_VIA_PROTECTED (base_binfo) = 0;
TREE_VIA_VIRTUAL (base_binfo) = 0;
/* Should handle this better so that
class A;
class B: private A { virtual void F(); };
does not dump core when compiled. */
my_friendly_abort (121);
#endif
continue;
}
/* All basetypes are recorded in the association list of the
derived type. */
if (TREE_VIA_VIRTUAL (base_binfo))
{
int j;
char *name = (char *)alloca (TYPE_NAME_LENGTH (basetype)
+ sizeof (VBASE_NAME) + 1);
/* The offset for a virtual base class is only used in computing
virtual function tables and for initializing virtual base
pointers. It is built once `get_vbase_types' is called. */
/* If this basetype can come from another vbase pointer
without an additional indirection, we will share
that pointer. If an indirection is involved, we
make our own pointer. */
for (j = 0; j < n_baseclasses; j++)
{
tree other_base_binfo = TREE_VEC_ELT (binfos, j);
if (! TREE_VIA_VIRTUAL (other_base_binfo)
&& binfo_member (basetype,
CLASSTYPE_VBASECLASSES (BINFO_TYPE (other_base_binfo))))
goto got_it;
}
sprintf (name, VBASE_NAME_FORMAT, TYPE_NAME_STRING (basetype));
decl = build_lang_field_decl (FIELD_DECL, get_identifier (name),
build_pointer_type (basetype));
/* If you change any of the below, take a look at all the
other VFIELD_BASEs and VTABLE_BASEs in the code, and change
them too. */
DECL_ASSEMBLER_NAME (decl) = get_identifier (VTABLE_BASE);
DECL_VIRTUAL_P (decl) = 1;
DECL_ARTIFICIAL (decl) = 1;
DECL_FIELD_CONTEXT (decl) = rec;
DECL_CLASS_CONTEXT (decl) = rec;
DECL_FCONTEXT (decl) = basetype;
DECL_SAVED_INSNS (decl) = NULL_RTX;
DECL_FIELD_SIZE (decl) = 0;
DECL_ALIGN (decl) = TYPE_ALIGN (ptr_type_node);
TREE_CHAIN (decl) = vbase_decls;
BINFO_VPTR_FIELD (base_binfo) = decl;
vbase_decls = decl;
got_it:
/* The space this decl occupies has already been accounted for. */
continue;
}
/* Effective C++ rule 14. We only need to check TYPE_VIRTUAL_P
here because the case of virtual functions but non-virtual
dtor is handled in finish_struct_1. */
if (warn_ecpp && ! TYPE_VIRTUAL_P (basetype)
&& TYPE_HAS_DESTRUCTOR (basetype))
cp_warning ("base class `%#T' has a non-virtual destructor", basetype);
if (const_size == 0)
offset = integer_zero_node;
else
{
/* Give each base type the alignment it wants. */
const_size = CEIL (const_size, TYPE_ALIGN (basetype))
* TYPE_ALIGN (basetype);
offset = size_int ((const_size + BITS_PER_UNIT - 1) / BITS_PER_UNIT);
}
BINFO_OFFSET (base_binfo) = offset;
if (CLASSTYPE_VSIZE (basetype))
{
BINFO_VTABLE (base_binfo) = TYPE_BINFO_VTABLE (basetype);
BINFO_VIRTUALS (base_binfo) = TYPE_BINFO_VIRTUALS (basetype);
}
TREE_CHAIN (base_binfo) = TYPE_BINFO (rec);
TYPE_BINFO (rec) = base_binfo;
/* Add only the amount of storage not present in
the virtual baseclasses. */
int_vbase_size = TREE_INT_CST_LOW (CLASSTYPE_VBASE_SIZE (basetype));
if (TREE_INT_CST_LOW (TYPE_SIZE (basetype)) > int_vbase_size)
{
inc = MAX (record_align,
(TREE_INT_CST_LOW (TYPE_SIZE (basetype))
- int_vbase_size));
/* Record must have at least as much alignment as any field. */
desired_align = TYPE_ALIGN (basetype);
record_align = MAX (record_align, desired_align);
const_size += inc;
}
}
if (const_size)
CLASSTYPE_SIZE (rec) = size_int (const_size);
else
CLASSTYPE_SIZE (rec) = integer_zero_node;
CLASSTYPE_ALIGN (rec) = record_align;
return vbase_decls;
}
/* Hashing of lists so that we don't make duplicates.
The entry point is `list_hash_canon'. */
/* Each hash table slot is a bucket containing a chain
of these structures. */
struct list_hash
{
struct list_hash *next; /* Next structure in the bucket. */
int hashcode; /* Hash code of this list. */
tree list; /* The list recorded here. */
};
/* Now here is the hash table. When recording a list, it is added
to the slot whose index is the hash code mod the table size.
Note that the hash table is used for several kinds of lists.
While all these live in the same table, they are completely independent,
and the hash code is computed differently for each of these. */
#define TYPE_HASH_SIZE 59
static struct list_hash *list_hash_table[TYPE_HASH_SIZE];
/* Compute a hash code for a list (chain of TREE_LIST nodes
with goodies in the TREE_PURPOSE, TREE_VALUE, and bits of the
TREE_COMMON slots), by adding the hash codes of the individual entries. */
static int
list_hash (purpose, value, chain)
tree purpose, value, chain;
{
register int hashcode = 0;
if (chain)
hashcode += TYPE_HASH (chain);
if (value)
hashcode += TYPE_HASH (value);
else
hashcode += 1007;
if (purpose)
hashcode += TYPE_HASH (purpose);
else
hashcode += 1009;
return hashcode;
}
/* Look in the type hash table for a type isomorphic to TYPE.
If one is found, return it. Otherwise return 0. */
static tree
list_hash_lookup (hashcode, via_public, via_protected, via_virtual,
purpose, value, chain)
int hashcode, via_public, via_virtual, via_protected;
tree purpose, value, chain;
{
register struct list_hash *h;
for (h = list_hash_table[hashcode % TYPE_HASH_SIZE]; h; h = h->next)
if (h->hashcode == hashcode
&& TREE_VIA_VIRTUAL (h->list) == via_virtual
&& TREE_VIA_PUBLIC (h->list) == via_public
&& TREE_VIA_PROTECTED (h->list) == via_protected
&& TREE_PURPOSE (h->list) == purpose
&& TREE_VALUE (h->list) == value
&& TREE_CHAIN (h->list) == chain)
return h->list;
return 0;
}
/* Add an entry to the list-hash-table
for a list TYPE whose hash code is HASHCODE. */
static void
list_hash_add (hashcode, list)
int hashcode;
tree list;
{
register struct list_hash *h;
h = (struct list_hash *) obstack_alloc (&class_obstack, sizeof (struct list_hash));
h->hashcode = hashcode;
h->list = list;
h->next = list_hash_table[hashcode % TYPE_HASH_SIZE];
list_hash_table[hashcode % TYPE_HASH_SIZE] = h;
}