]> gcc.gnu.org Git - gcc.git/blob - gcc/cp/class.c
new
[gcc.git] / gcc / cp / class.c
1 /* Functions related to building classes and their related objects.
2 Copyright (C) 1987, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
3 Contributed by Michael Tiemann (tiemann@cygnus.com)
4
5 This file is part of GNU CC.
6
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
21
22
23 /* High-level class interface. */
24
25 #include "config.h"
26 #include "tree.h"
27 #include <stdio.h>
28 #include "cp-tree.h"
29 #include "flags.h"
30 #include "rtl.h"
31 #include "output.h"
32
33 #include "obstack.h"
34 #define obstack_chunk_alloc xmalloc
35 #define obstack_chunk_free free
36
37 extern struct obstack permanent_obstack;
38
39 /* This is how we tell when two virtual member functions are really the
40 same. */
41 #define SAME_FN(FN1DECL, FN2DECL) (DECL_ASSEMBLER_NAME (FN1DECL) == DECL_ASSEMBLER_NAME (FN2DECL))
42
43 extern void set_class_shadows PROTO ((tree));
44
45 /* Way of stacking class types. */
46 static tree *current_class_base, *current_class_stack;
47 static int current_class_stacksize;
48 int current_class_depth;
49
50 struct class_level
51 {
52 /* The previous class level. */
53 struct class_level *level_chain;
54
55 /* The class instance variable, as a PARM_DECL. */
56 tree decl;
57 /* The class instance variable, as an object. */
58 tree object;
59 /* The virtual function table pointer
60 for the class instance variable. */
61 tree vtable_decl;
62
63 /* Name of the current class. */
64 tree name;
65 /* Type of the current class. */
66 tree type;
67
68 /* Flags for this class level. */
69 int this_is_variable;
70 int memoized_lookups;
71 int save_memoized;
72 int unused;
73 };
74
75 /* The currect_class_ptr is the pointer to the current class.
76 current_class_ref is the actual current class. */
77 tree current_class_ptr, current_class_ref;
78
79 /* The following two can be derived from the previous one */
80 tree current_class_name; /* IDENTIFIER_NODE: name of current class */
81 tree current_class_type; /* _TYPE: the type of the current class */
82 tree previous_class_type; /* _TYPE: the previous type that was a class */
83 tree previous_class_values; /* TREE_LIST: copy of the class_shadowed list
84 when leaving an outermost class scope. */
85
86 struct base_info;
87
88 static tree get_vfield_name PROTO((tree));
89 static void finish_struct_anon PROTO((tree));
90 static tree build_vbase_pointer PROTO((tree, tree));
91 static int complete_type_p PROTO((tree));
92 static int typecode_p PROTO((tree, enum tree_code));
93 static tree build_vtable_entry PROTO((tree, tree));
94 static tree get_vtable_name PROTO((tree));
95 static tree get_derived_offset PROTO((tree, tree));
96 static tree get_basefndecls PROTO((tree, tree));
97 static void set_rtti_entry PROTO((tree, tree, tree));
98 static tree build_vtable PROTO((tree, tree));
99 static void prepare_fresh_vtable PROTO((tree, tree));
100 static void fixup_vtable_deltas1 PROTO((tree, tree));
101 static void fixup_vtable_deltas PROTO((tree, int, tree));
102 static void grow_method PROTO((tree, tree *));
103 static void finish_vtbls PROTO((tree, int, tree));
104 static void modify_vtable_entry PROTO((tree, tree, tree));
105 static tree get_vtable_entry_n PROTO((tree, unsigned HOST_WIDE_INT));
106 static void add_virtual_function PROTO((tree *, tree *, int *, tree, tree));
107 static tree delete_duplicate_fields_1 PROTO((tree, tree));
108 static void delete_duplicate_fields PROTO((tree));
109 static void finish_struct_bits PROTO((tree, int));
110 static int alter_access PROTO((tree, tree, tree));
111 static int overrides PROTO((tree, tree));
112 static int strictly_overrides PROTO((tree, tree));
113 static void merge_overrides PROTO((tree, tree, int, tree));
114 static void override_one_vtable PROTO((tree, tree, tree));
115 static void mark_overriders PROTO((tree, tree));
116 static void check_for_override PROTO((tree, tree));
117 static tree maybe_fixup_vptrs PROTO((tree, tree, tree));
118 static tree get_class_offset_1 PROTO((tree, tree, tree, tree, tree));
119 static tree get_class_offset PROTO((tree, tree, tree, tree));
120 static void modify_one_vtable PROTO((tree, tree, tree, tree));
121 static void modify_all_vtables PROTO((tree, tree, tree));
122 static void modify_all_direct_vtables PROTO((tree, int, tree, tree,
123 tree));
124 static void modify_all_indirect_vtables PROTO((tree, int, int, tree,
125 tree, tree));
126 static void build_class_init_list PROTO((tree));
127 static int finish_base_struct PROTO((tree, struct base_info *, tree));
128
129 /* Way of stacking language names. */
130 tree *current_lang_base, *current_lang_stack;
131 int current_lang_stacksize;
132
133 /* Names of languages we recognize. */
134 tree lang_name_c, lang_name_cplusplus;
135 tree current_lang_name;
136
137 /* When layout out an aggregate type, the size of the
138 basetypes (virtual and non-virtual) is passed to layout_record
139 via this node. */
140 static tree base_layout_decl;
141
142 /* Constants used for access control. */
143 tree access_default_node; /* 0 */
144 tree access_public_node; /* 1 */
145 tree access_protected_node; /* 2 */
146 tree access_private_node; /* 3 */
147 tree access_default_virtual_node; /* 4 */
148 tree access_public_virtual_node; /* 5 */
149 tree access_private_virtual_node; /* 6 */
150
151 /* Variables shared between class.c and call.c. */
152
153 #ifdef GATHER_STATISTICS
154 int n_vtables = 0;
155 int n_vtable_entries = 0;
156 int n_vtable_searches = 0;
157 int n_vtable_elems = 0;
158 int n_convert_harshness = 0;
159 int n_compute_conversion_costs = 0;
160 int n_build_method_call = 0;
161 int n_inner_fields_searched = 0;
162 #endif
163
164 /* Virtual baseclass things. */
165
166 static tree
167 build_vbase_pointer (exp, type)
168 tree exp, type;
169 {
170 char *name;
171
172 name = (char *) alloca (TYPE_NAME_LENGTH (type) + sizeof (VBASE_NAME) + 1);
173 sprintf (name, VBASE_NAME_FORMAT, TYPE_NAME_STRING (type));
174 return build_component_ref (exp, get_identifier (name), NULL_TREE, 0);
175 }
176
177 /* Is the type of the EXPR, the complete type of the object?
178 If we are going to be wrong, we must be conservative, and return 0. */
179
180 static int
181 complete_type_p (expr)
182 tree expr;
183 {
184 tree type = TYPE_MAIN_VARIANT (TREE_TYPE (expr));
185 while (1)
186 {
187 switch (TREE_CODE (expr))
188 {
189 case SAVE_EXPR:
190 case INDIRECT_REF:
191 case ADDR_EXPR:
192 case NOP_EXPR:
193 case CONVERT_EXPR:
194 expr = TREE_OPERAND (expr, 0);
195 continue;
196
197 case CALL_EXPR:
198 if (! TREE_HAS_CONSTRUCTOR (expr))
199 break;
200 /* fall through... */
201 case VAR_DECL:
202 case FIELD_DECL:
203 if (TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
204 && IS_AGGR_TYPE (TREE_TYPE (TREE_TYPE (expr)))
205 && TYPE_MAIN_VARIANT (TREE_TYPE (expr)) == type)
206 return 1;
207 /* fall through... */
208 case TARGET_EXPR:
209 case PARM_DECL:
210 if (IS_AGGR_TYPE (TREE_TYPE (expr))
211 && TYPE_MAIN_VARIANT (TREE_TYPE (expr)) == type)
212 return 1;
213 /* fall through... */
214 case PLUS_EXPR:
215 default:
216 break;
217 }
218 break;
219 }
220 return 0;
221 }
222
223 /* Build multi-level access to EXPR using hierarchy path PATH.
224 CODE is PLUS_EXPR if we are going with the grain,
225 and MINUS_EXPR if we are not (in which case, we cannot traverse
226 virtual baseclass links).
227
228 TYPE is the type we want this path to have on exit.
229
230 ALIAS_THIS is non-zero if EXPR in an expression involving `this'. */
231
232 tree
233 build_vbase_path (code, type, expr, path, alias_this)
234 enum tree_code code;
235 tree type, expr, path;
236 int alias_this;
237 {
238 register int changed = 0;
239 tree last = NULL_TREE, last_virtual = NULL_TREE;
240 int nonnull = 0;
241 int fixed_type_p;
242 tree null_expr = 0, nonnull_expr;
243 tree basetype;
244 tree offset = integer_zero_node;
245
246 if (BINFO_INHERITANCE_CHAIN (path) == NULL_TREE)
247 return build1 (NOP_EXPR, type, expr);
248
249 if (nonnull == 0 && (alias_this && flag_this_is_variable <= 0))
250 nonnull = 1;
251
252 #if 0
253 /* We need additional logic to convert back to the unconverted type
254 (the static type of the complete object), and then convert back
255 to the type we want. Until that is done, or until we can
256 recognize when that is, we cannot do the short cut logic. (mrs) */
257 fixed_type_p = resolves_to_fixed_type_p (expr, &nonnull);
258 #else
259 /* Do this, until we can undo any previous conversions. See net35.C
260 for a testcase. */
261 fixed_type_p = complete_type_p (expr);
262 #endif
263
264 if (!fixed_type_p && TREE_SIDE_EFFECTS (expr))
265 expr = save_expr (expr);
266 nonnull_expr = expr;
267
268 if (BINFO_INHERITANCE_CHAIN (path))
269 {
270 tree reverse_path = NULL_TREE;
271
272 push_expression_obstack ();
273 while (path)
274 {
275 tree r = copy_node (path);
276 BINFO_INHERITANCE_CHAIN (r) = reverse_path;
277 reverse_path = r;
278 path = BINFO_INHERITANCE_CHAIN (path);
279 }
280 path = reverse_path;
281 pop_obstacks ();
282 }
283
284 basetype = BINFO_TYPE (path);
285
286 while (path)
287 {
288 if (TREE_VIA_VIRTUAL (path))
289 {
290 last_virtual = BINFO_TYPE (path);
291 if (code == PLUS_EXPR)
292 {
293 changed = ! fixed_type_p;
294
295 if (changed)
296 {
297 tree ind;
298
299 /* We already check for ambiguous things in the caller, just
300 find a path. */
301 if (last)
302 {
303 tree binfo = get_binfo (last, TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (nonnull_expr))), 0);
304 nonnull_expr = convert_pointer_to_real (binfo, nonnull_expr);
305 }
306 ind = build_indirect_ref (nonnull_expr, NULL_PTR);
307 nonnull_expr = build_vbase_pointer (ind, last_virtual);
308 if (nonnull == 0
309 && (TREE_CODE (type) == POINTER_TYPE
310 || !flag_assume_nonnull_objects)
311 && null_expr == NULL_TREE)
312 {
313 null_expr = build1 (NOP_EXPR, build_pointer_type (last_virtual), integer_zero_node);
314 expr = build (COND_EXPR, build_pointer_type (last_virtual),
315 build (EQ_EXPR, boolean_type_node, expr,
316 integer_zero_node),
317 null_expr, nonnull_expr);
318 }
319 }
320 /* else we'll figure out the offset below. */
321
322 /* Happens in the case of parse errors. */
323 if (nonnull_expr == error_mark_node)
324 return error_mark_node;
325 }
326 else
327 {
328 cp_error ("cannot cast up from virtual baseclass `%T'",
329 last_virtual);
330 return error_mark_node;
331 }
332 }
333 last = path;
334 path = BINFO_INHERITANCE_CHAIN (path);
335 }
336 /* LAST is now the last basetype assoc on the path. */
337
338 /* A pointer to a virtual base member of a non-null object
339 is non-null. Therefore, we only need to test for zeroness once.
340 Make EXPR the canonical expression to deal with here. */
341 if (null_expr)
342 {
343 TREE_OPERAND (expr, 2) = nonnull_expr;
344 TREE_TYPE (expr) = TREE_TYPE (TREE_OPERAND (expr, 1))
345 = TREE_TYPE (nonnull_expr);
346 }
347 else
348 expr = nonnull_expr;
349
350 /* If we go through any virtual base pointers, make sure that
351 casts to BASETYPE from the last virtual base class use
352 the right value for BASETYPE. */
353 if (changed)
354 {
355 tree intype = TREE_TYPE (TREE_TYPE (expr));
356 if (TYPE_MAIN_VARIANT (intype) != BINFO_TYPE (last))
357 {
358 tree binfo = get_binfo (last, TYPE_MAIN_VARIANT (intype), 0);
359 offset = BINFO_OFFSET (binfo);
360 }
361 }
362 else
363 {
364 if (last_virtual)
365 {
366 offset = BINFO_OFFSET (binfo_member (last_virtual,
367 CLASSTYPE_VBASECLASSES (basetype)));
368 offset = size_binop (PLUS_EXPR, offset, BINFO_OFFSET (last));
369 }
370 else
371 offset = BINFO_OFFSET (last);
372 }
373
374 if (TREE_INT_CST_LOW (offset))
375 {
376 /* Bash types to make the backend happy. */
377 offset = cp_convert (type, offset);
378 #if 0
379 /* This shouldn't be necessary. (mrs) */
380 expr = build1 (NOP_EXPR, type, expr);
381 #endif
382
383 /* For multiple inheritance: if `this' can be set by any
384 function, then it could be 0 on entry to any function.
385 Preserve such zeroness here. Otherwise, only in the
386 case of constructors need we worry, and in those cases,
387 it will be zero, or initialized to some valid value to
388 which we may add. */
389 if (nonnull == 0)
390 {
391 if (null_expr)
392 TREE_TYPE (null_expr) = type;
393 else
394 null_expr = build1 (NOP_EXPR, type, integer_zero_node);
395 if (TREE_SIDE_EFFECTS (expr))
396 expr = save_expr (expr);
397
398 return build (COND_EXPR, type,
399 build (EQ_EXPR, boolean_type_node, expr, integer_zero_node),
400 null_expr,
401 build (code, type, expr, offset));
402 }
403 else return build (code, type, expr, offset);
404 }
405
406 /* Cannot change the TREE_TYPE of a NOP_EXPR here, since it may
407 be used multiple times in initialization of multiple inheritance. */
408 if (null_expr)
409 {
410 TREE_TYPE (expr) = type;
411 return expr;
412 }
413 else
414 return build1 (NOP_EXPR, type, expr);
415 }
416
417 /* Virtual function things. */
418
419 /* Build an entry in the virtual function table.
420 DELTA is the offset for the `this' pointer.
421 PFN is an ADDR_EXPR containing a pointer to the virtual function.
422 Note that the index (DELTA2) in the virtual function table
423 is always 0. */
424
425 static tree
426 build_vtable_entry (delta, pfn)
427 tree delta, pfn;
428 {
429 if (flag_vtable_thunks)
430 {
431 HOST_WIDE_INT idelta = TREE_INT_CST_LOW (delta);
432 if (idelta && ! DECL_ABSTRACT_VIRTUAL_P (TREE_OPERAND (pfn, 0)))
433 {
434 pfn = build1 (ADDR_EXPR, vtable_entry_type,
435 make_thunk (pfn, idelta));
436 TREE_READONLY (pfn) = 1;
437 TREE_CONSTANT (pfn) = 1;
438 }
439 #ifdef GATHER_STATISTICS
440 n_vtable_entries += 1;
441 #endif
442 return pfn;
443 }
444 else
445 {
446 extern int flag_huge_objects;
447 tree elems = expr_tree_cons (NULL_TREE, delta,
448 expr_tree_cons (NULL_TREE, integer_zero_node,
449 build_expr_list (NULL_TREE, pfn)));
450 tree entry = build (CONSTRUCTOR, vtable_entry_type, NULL_TREE, elems);
451
452 /* DELTA is constructed by `size_int', which means it may be an
453 unsigned quantity on some platforms. Therefore, we cannot use
454 `int_fits_type_p', because when DELTA is really negative,
455 `force_fit_type' will make it look like a very large number. */
456
457 if ((TREE_INT_CST_LOW (TYPE_MAX_VALUE (delta_type_node))
458 < TREE_INT_CST_LOW (delta))
459 || (TREE_INT_CST_LOW (delta)
460 < TREE_INT_CST_LOW (TYPE_MIN_VALUE (delta_type_node))))
461 if (flag_huge_objects)
462 sorry ("object size exceeds built-in limit for virtual function table implementation");
463 else
464 sorry ("object size exceeds normal limit for virtual function table implementation, recompile all source and use -fhuge-objects");
465
466 TREE_CONSTANT (entry) = 1;
467 TREE_STATIC (entry) = 1;
468 TREE_READONLY (entry) = 1;
469
470 #ifdef GATHER_STATISTICS
471 n_vtable_entries += 1;
472 #endif
473
474 return entry;
475 }
476 }
477
478 /* Given an object INSTANCE, return an expression which yields the
479 virtual function vtable element corresponding to INDEX. There are
480 many special cases for INSTANCE which we take care of here, mainly
481 to avoid creating extra tree nodes when we don't have to. */
482
483 tree
484 build_vtbl_ref (instance, idx)
485 tree instance, idx;
486 {
487 tree vtbl, aref;
488 tree basetype = TREE_TYPE (instance);
489
490 if (TREE_CODE (basetype) == REFERENCE_TYPE)
491 basetype = TREE_TYPE (basetype);
492
493 if (instance == current_class_ref)
494 vtbl = build_indirect_ref (build_vfield_ref (instance, basetype),
495 NULL_PTR);
496 else
497 {
498 if (optimize)
499 {
500 /* Try to figure out what a reference refers to, and
501 access its virtual function table directly. */
502 tree ref = NULL_TREE;
503
504 if (TREE_CODE (instance) == INDIRECT_REF
505 && TREE_CODE (TREE_TYPE (TREE_OPERAND (instance, 0))) == REFERENCE_TYPE)
506 ref = TREE_OPERAND (instance, 0);
507 else if (TREE_CODE (TREE_TYPE (instance)) == REFERENCE_TYPE)
508 ref = instance;
509
510 if (ref && TREE_CODE (ref) == VAR_DECL
511 && DECL_INITIAL (ref))
512 {
513 tree init = DECL_INITIAL (ref);
514
515 while (TREE_CODE (init) == NOP_EXPR
516 || TREE_CODE (init) == NON_LVALUE_EXPR)
517 init = TREE_OPERAND (init, 0);
518 if (TREE_CODE (init) == ADDR_EXPR)
519 {
520 init = TREE_OPERAND (init, 0);
521 if (IS_AGGR_TYPE (TREE_TYPE (init))
522 && (TREE_CODE (init) == PARM_DECL
523 || TREE_CODE (init) == VAR_DECL))
524 instance = init;
525 }
526 }
527 }
528
529 if (IS_AGGR_TYPE (TREE_TYPE (instance))
530 && (TREE_CODE (instance) == RESULT_DECL
531 || TREE_CODE (instance) == PARM_DECL
532 || TREE_CODE (instance) == VAR_DECL))
533 vtbl = TYPE_BINFO_VTABLE (basetype);
534 else
535 vtbl = build_indirect_ref (build_vfield_ref (instance, basetype),
536 NULL_PTR);
537 }
538 assemble_external (vtbl);
539 aref = build_array_ref (vtbl, idx);
540
541 return aref;
542 }
543
544 /* Given an object INSTANCE, return an expression which yields the
545 virtual function corresponding to INDEX. There are many special
546 cases for INSTANCE which we take care of here, mainly to avoid
547 creating extra tree nodes when we don't have to. */
548
549 tree
550 build_vfn_ref (ptr_to_instptr, instance, idx)
551 tree *ptr_to_instptr, instance;
552 tree idx;
553 {
554 tree aref = build_vtbl_ref (instance, idx);
555
556 /* When using thunks, there is no extra delta, and we get the pfn
557 directly. */
558 if (flag_vtable_thunks)
559 return aref;
560
561 if (ptr_to_instptr)
562 {
563 /* Save the intermediate result in a SAVE_EXPR so we don't have to
564 compute each component of the virtual function pointer twice. */
565 if (TREE_CODE (aref) == INDIRECT_REF)
566 TREE_OPERAND (aref, 0) = save_expr (TREE_OPERAND (aref, 0));
567
568 *ptr_to_instptr
569 = build (PLUS_EXPR, TREE_TYPE (*ptr_to_instptr),
570 *ptr_to_instptr,
571 cp_convert (ptrdiff_type_node,
572 build_component_ref (aref, delta_identifier, NULL_TREE, 0)));
573 }
574
575 return build_component_ref (aref, pfn_identifier, NULL_TREE, 0);
576 }
577
578 /* Return the name of the virtual function table (as an IDENTIFIER_NODE)
579 for the given TYPE. */
580
581 static tree
582 get_vtable_name (type)
583 tree type;
584 {
585 tree type_id = build_typename_overload (type);
586 char *buf = (char *) alloca (strlen (VTABLE_NAME_FORMAT)
587 + IDENTIFIER_LENGTH (type_id) + 2);
588 char *ptr = IDENTIFIER_POINTER (type_id);
589 int i;
590 for (i = 0; ptr[i] == OPERATOR_TYPENAME_FORMAT[i]; i++) ;
591 #if 0
592 /* We don't take off the numbers; prepare_fresh_vtable uses the
593 DECL_ASSEMBLER_NAME for the type, which includes the number
594 in `3foo'. If we were to pull them off here, we'd end up with
595 something like `_vt.foo.3bar', instead of a uniform definition. */
596 while (ptr[i] >= '0' && ptr[i] <= '9')
597 i += 1;
598 #endif
599 sprintf (buf, VTABLE_NAME_FORMAT, ptr+i);
600 return get_identifier (buf);
601 }
602
603 /* Return the offset to the main vtable for a given base BINFO. */
604
605 tree
606 get_vfield_offset (binfo)
607 tree binfo;
608 {
609 return size_binop (PLUS_EXPR,
610 size_binop (FLOOR_DIV_EXPR,
611 DECL_FIELD_BITPOS (CLASSTYPE_VFIELD (BINFO_TYPE (binfo))),
612 size_int (BITS_PER_UNIT)),
613 BINFO_OFFSET (binfo));
614 }
615
616 /* Get the offset to the start of the original binfo that we derived
617 this binfo from. If we find TYPE first, return the offset only
618 that far. The shortened search is useful because the this pointer
619 on method calling is expected to point to a DECL_CONTEXT (fndecl)
620 object, and not a baseclass of it. */
621
622 static tree
623 get_derived_offset (binfo, type)
624 tree binfo, type;
625 {
626 tree offset1 = get_vfield_offset (TYPE_BINFO (BINFO_TYPE (binfo)));
627 tree offset2;
628 int i;
629 while (BINFO_BASETYPES (binfo)
630 && (i=CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo))) != -1)
631 {
632 tree binfos = BINFO_BASETYPES (binfo);
633 if (BINFO_TYPE (binfo) == type)
634 break;
635 binfo = TREE_VEC_ELT (binfos, i);
636 }
637 offset2 = get_vfield_offset (TYPE_BINFO (BINFO_TYPE (binfo)));
638 return size_binop (MINUS_EXPR, offset1, offset2);
639 }
640
641 /* Update the rtti info for this class. */
642
643 static void
644 set_rtti_entry (virtuals, offset, type)
645 tree virtuals, offset, type;
646 {
647 tree vfn;
648
649 if (flag_rtti)
650 vfn = build1 (ADDR_EXPR, vfunc_ptr_type_node, get_tinfo_fn (type));
651 else
652 vfn = build1 (NOP_EXPR, vfunc_ptr_type_node, size_zero_node);
653 TREE_CONSTANT (vfn) = 1;
654
655 if (! flag_vtable_thunks)
656 TREE_VALUE (virtuals) = build_vtable_entry (offset, vfn);
657 else
658 {
659 tree voff = build1 (NOP_EXPR, vfunc_ptr_type_node, offset);
660 TREE_CONSTANT (voff) = 1;
661
662 TREE_VALUE (virtuals) = build_vtable_entry (size_zero_node, voff);
663
664 /* The second slot is for the tdesc pointer when thunks are used. */
665 TREE_VALUE (TREE_CHAIN (virtuals))
666 = build_vtable_entry (size_zero_node, vfn);
667 }
668 }
669
670 /* Build a virtual function for type TYPE.
671 If BINFO is non-NULL, build the vtable starting with the initial
672 approximation that it is the same as the one which is the head of
673 the association list. */
674
675 static tree
676 build_vtable (binfo, type)
677 tree binfo, type;
678 {
679 tree name = get_vtable_name (type);
680 tree virtuals, decl;
681
682 if (binfo)
683 {
684 tree offset;
685
686 virtuals = copy_list (BINFO_VIRTUALS (binfo));
687 decl = build_decl (VAR_DECL, name, TREE_TYPE (BINFO_VTABLE (binfo)));
688
689 /* Now do rtti stuff. */
690 offset = get_derived_offset (TYPE_BINFO (type), NULL_TREE);
691 offset = size_binop (MINUS_EXPR, size_zero_node, offset);
692 set_rtti_entry (virtuals, offset, type);
693 }
694 else
695 {
696 virtuals = NULL_TREE;
697 decl = build_decl (VAR_DECL, name, void_type_node);
698 }
699
700 #ifdef GATHER_STATISTICS
701 n_vtables += 1;
702 n_vtable_elems += list_length (virtuals);
703 #endif
704
705 /* Set TREE_PUBLIC and TREE_EXTERN as appropriate. */
706 import_export_vtable (decl, type, 0);
707
708 IDENTIFIER_GLOBAL_VALUE (name) = decl = pushdecl_top_level (decl);
709 /* Initialize the association list for this type, based
710 on our first approximation. */
711 TYPE_BINFO_VTABLE (type) = decl;
712 TYPE_BINFO_VIRTUALS (type) = virtuals;
713
714 DECL_ARTIFICIAL (decl) = 1;
715 TREE_STATIC (decl) = 1;
716 #ifndef WRITABLE_VTABLES
717 /* Make them READONLY by default. (mrs) */
718 TREE_READONLY (decl) = 1;
719 #endif
720 /* At one time the vtable info was grabbed 2 words at a time. This
721 fails on sparc unless you have 8-byte alignment. (tiemann) */
722 DECL_ALIGN (decl) = MAX (TYPE_ALIGN (double_type_node),
723 DECL_ALIGN (decl));
724
725 /* Why is this conditional? (mrs) */
726 if (binfo && write_virtuals >= 0)
727 DECL_VIRTUAL_P (decl) = 1;
728 DECL_CONTEXT (decl) = type;
729
730 binfo = TYPE_BINFO (type);
731 SET_BINFO_NEW_VTABLE_MARKED (binfo);
732 return decl;
733 }
734
735 extern tree signed_size_zero_node;
736
737 /* Give TYPE a new virtual function table which is initialized
738 with a skeleton-copy of its original initialization. The only
739 entry that changes is the `delta' entry, so we can really
740 share a lot of structure.
741
742 FOR_TYPE is the derived type which caused this table to
743 be needed.
744
745 BINFO is the type association which provided TYPE for FOR_TYPE.
746
747 The order in which vtables are built (by calling this function) for
748 an object must remain the same, otherwise a binary incompatibility
749 can result. */
750
751 static void
752 prepare_fresh_vtable (binfo, for_type)
753 tree binfo, for_type;
754 {
755 tree basetype;
756 tree orig_decl = BINFO_VTABLE (binfo);
757 tree name;
758 tree new_decl;
759 tree offset;
760 tree path = binfo;
761 char *buf, *buf2;
762 char joiner = '_';
763 int i;
764
765 #ifdef JOINER
766 joiner = JOINER;
767 #endif
768
769 basetype = TYPE_MAIN_VARIANT (BINFO_TYPE (binfo));
770
771 buf2 = TYPE_ASSEMBLER_NAME_STRING (basetype);
772 i = TYPE_ASSEMBLER_NAME_LENGTH (basetype) + 1;
773
774 /* We know that the vtable that we are going to create doesn't exist
775 yet in the global namespace, and when we finish, it will be
776 pushed into the global namespace. In complex MI hierarchies, we
777 have to loop while the name we are thinking of adding is globally
778 defined, adding more name components to the vtable name as we
779 loop, until the name is unique. This is because in complex MI
780 cases, we might have the same base more than once. This means
781 that the order in which this function is called for vtables must
782 remain the same, otherwise binary compatibility can be
783 compromised. */
784
785 while (1)
786 {
787 char *buf1 = (char *) alloca (TYPE_ASSEMBLER_NAME_LENGTH (for_type)
788 + 1 + i);
789 char *new_buf2;
790
791 sprintf (buf1, "%s%c%s", TYPE_ASSEMBLER_NAME_STRING (for_type), joiner,
792 buf2);
793 buf = (char *) alloca (strlen (VTABLE_NAME_FORMAT) + strlen (buf1) + 1);
794 sprintf (buf, VTABLE_NAME_FORMAT, buf1);
795 name = get_identifier (buf);
796
797 /* If this name doesn't clash, then we can use it, otherwise
798 we add more to the name until it is unique. */
799
800 if (! IDENTIFIER_GLOBAL_VALUE (name))
801 break;
802
803 /* Set values for next loop through, if the name isn't unique. */
804
805 path = BINFO_INHERITANCE_CHAIN (path);
806
807 /* We better not run out of stuff to make it unique. */
808 my_friendly_assert (path != NULL_TREE, 368);
809
810 basetype = TYPE_MAIN_VARIANT (BINFO_TYPE (path));
811
812 if (for_type == basetype)
813 {
814 /* If we run out of basetypes in the path, we have already
815 found created a vtable with that name before, we now
816 resort to tacking on _%d to distinguish them. */
817 int j = 2;
818 i = TYPE_ASSEMBLER_NAME_LENGTH (basetype) + 1 + i + 1 + 3;
819 buf1 = (char *) alloca (i);
820 do {
821 sprintf (buf1, "%s%c%s%c%d",
822 TYPE_ASSEMBLER_NAME_STRING (basetype), joiner,
823 buf2, joiner, j);
824 buf = (char *) alloca (strlen (VTABLE_NAME_FORMAT)
825 + strlen (buf1) + 1);
826 sprintf (buf, VTABLE_NAME_FORMAT, buf1);
827 name = get_identifier (buf);
828
829 /* If this name doesn't clash, then we can use it,
830 otherwise we add something different to the name until
831 it is unique. */
832 } while (++j <= 999 && IDENTIFIER_GLOBAL_VALUE (name));
833
834 /* Hey, they really like MI don't they? Increase the 3
835 above to 6, and the 999 to 999999. :-) */
836 my_friendly_assert (j <= 999, 369);
837
838 break;
839 }
840
841 i = TYPE_ASSEMBLER_NAME_LENGTH (basetype) + 1 + i;
842 new_buf2 = (char *) alloca (i);
843 sprintf (new_buf2, "%s%c%s",
844 TYPE_ASSEMBLER_NAME_STRING (basetype), joiner, buf2);
845 buf2 = new_buf2;
846 }
847
848 new_decl = build_decl (VAR_DECL, name, TREE_TYPE (orig_decl));
849 /* Remember which class this vtable is really for. */
850 DECL_CONTEXT (new_decl) = for_type;
851
852 DECL_ARTIFICIAL (new_decl) = 1;
853 TREE_STATIC (new_decl) = 1;
854 BINFO_VTABLE (binfo) = pushdecl_top_level (new_decl);
855 DECL_VIRTUAL_P (new_decl) = 1;
856 #ifndef WRITABLE_VTABLES
857 /* Make them READONLY by default. (mrs) */
858 TREE_READONLY (new_decl) = 1;
859 #endif
860 DECL_ALIGN (new_decl) = DECL_ALIGN (orig_decl);
861
862 /* Make fresh virtual list, so we can smash it later. */
863 BINFO_VIRTUALS (binfo) = copy_list (BINFO_VIRTUALS (binfo));
864
865 if (TREE_VIA_VIRTUAL (binfo))
866 {
867 tree binfo1 = binfo_member (BINFO_TYPE (binfo),
868 CLASSTYPE_VBASECLASSES (for_type));
869
870 /* XXX - This should never happen, if it does, the caller should
871 ensure that the binfo is from for_type's binfos, not from any
872 base type's. We can remove all this code after a while. */
873 if (binfo1 != binfo)
874 warning ("internal inconsistency: binfo offset error for rtti");
875
876 offset = BINFO_OFFSET (binfo1);
877 }
878 else
879 offset = BINFO_OFFSET (binfo);
880
881 set_rtti_entry (BINFO_VIRTUALS (binfo),
882 size_binop (MINUS_EXPR, signed_size_zero_node, offset),
883 for_type);
884
885 #ifdef GATHER_STATISTICS
886 n_vtables += 1;
887 n_vtable_elems += list_length (BINFO_VIRTUALS (binfo));
888 #endif
889
890 /* Set TREE_PUBLIC and TREE_EXTERN as appropriate. */
891 import_export_vtable (new_decl, for_type, 0);
892
893 if (TREE_VIA_VIRTUAL (binfo))
894 my_friendly_assert (binfo == binfo_member (BINFO_TYPE (binfo),
895 CLASSTYPE_VBASECLASSES (current_class_type)),
896 170);
897 SET_BINFO_NEW_VTABLE_MARKED (binfo);
898 }
899
900 #if 0
901 /* Access the virtual function table entry that logically
902 contains BASE_FNDECL. VIRTUALS is the virtual function table's
903 initializer. We can run off the end, when dealing with virtual
904 destructors in MI situations, return NULL_TREE in that case. */
905
906 static tree
907 get_vtable_entry (virtuals, base_fndecl)
908 tree virtuals, base_fndecl;
909 {
910 unsigned HOST_WIDE_INT n = (HOST_BITS_PER_WIDE_INT >= BITS_PER_WORD
911 ? (TREE_INT_CST_LOW (DECL_VINDEX (base_fndecl))
912 & (((unsigned HOST_WIDE_INT)1<<(BITS_PER_WORD-1))-1))
913 : TREE_INT_CST_LOW (DECL_VINDEX (base_fndecl)));
914
915 #ifdef GATHER_STATISTICS
916 n_vtable_searches += n;
917 #endif
918
919 while (n > 0 && virtuals)
920 {
921 --n;
922 virtuals = TREE_CHAIN (virtuals);
923 }
924 return virtuals;
925 }
926 #endif
927
928 /* Put new entry ENTRY into virtual function table initializer
929 VIRTUALS.
930
931 Also update DECL_VINDEX (FNDECL). */
932
933 static void
934 modify_vtable_entry (old_entry_in_list, new_entry, fndecl)
935 tree old_entry_in_list, new_entry, fndecl;
936 {
937 tree base_fndecl = TREE_OPERAND (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (old_entry_in_list)), 0);
938
939 #ifdef NOTQUITE
940 cp_warning ("replaced %D with %D", DECL_ASSEMBLER_NAME (base_fndecl),
941 DECL_ASSEMBLER_NAME (fndecl));
942 #endif
943 TREE_VALUE (old_entry_in_list) = new_entry;
944
945 /* Now assign virtual dispatch information, if unset. */
946 /* We can dispatch this, through any overridden base function. */
947 if (TREE_CODE (DECL_VINDEX (fndecl)) != INTEGER_CST)
948 {
949 DECL_VINDEX (fndecl) = DECL_VINDEX (base_fndecl);
950 DECL_CONTEXT (fndecl) = DECL_CONTEXT (base_fndecl);
951 }
952 }
953
954 /* Access the virtual function table entry N. VIRTUALS is the virtual
955 function table's initializer. */
956
957 static tree
958 get_vtable_entry_n (virtuals, n)
959 tree virtuals;
960 unsigned HOST_WIDE_INT n;
961 {
962 while (n > 0)
963 {
964 --n;
965 virtuals = TREE_CHAIN (virtuals);
966 }
967 return virtuals;
968 }
969
970 /* Add a virtual function to all the appropriate vtables for the class
971 T. DECL_VINDEX(X) should be error_mark_node, if we want to
972 allocate a new slot in our table. If it is error_mark_node, we
973 know that no other function from another vtable is overridden by X.
974 HAS_VIRTUAL keeps track of how many virtuals there are in our main
975 vtable for the type, and we build upon the PENDING_VIRTUALS list
976 and return it. */
977
978 static void
979 add_virtual_function (pv, phv, has_virtual, fndecl, t)
980 tree *pv, *phv;
981 int *has_virtual;
982 tree fndecl;
983 tree t; /* Structure type. */
984 {
985 tree pending_virtuals = *pv;
986 tree pending_hard_virtuals = *phv;
987
988 /* FUNCTION_TYPEs and OFFSET_TYPEs no longer freely
989 convert to void *. Make such a conversion here. */
990 tree vfn = build1 (ADDR_EXPR, vfunc_ptr_type_node, fndecl);
991 TREE_CONSTANT (vfn) = 1;
992
993 #ifndef DUMB_USER
994 if (current_class_type == 0)
995 cp_warning ("internal problem, current_class_type is zero when adding `%D', please report",
996 fndecl);
997 if (current_class_type && t != current_class_type)
998 cp_warning ("internal problem, current_class_type differs when adding `%D', please report",
999 fndecl);
1000 #endif
1001
1002 /* If the virtual function is a redefinition of a prior one,
1003 figure out in which base class the new definition goes,
1004 and if necessary, make a fresh virtual function table
1005 to hold that entry. */
1006 if (DECL_VINDEX (fndecl) == error_mark_node)
1007 {
1008 tree entry;
1009
1010 /* We remember that this was the base sub-object for rtti. */
1011 CLASSTYPE_RTTI (t) = t;
1012
1013 /* If we are using thunks, use two slots at the front, one
1014 for the offset pointer, one for the tdesc pointer. */
1015 if (*has_virtual == 0 && flag_vtable_thunks)
1016 {
1017 *has_virtual = 1;
1018 }
1019
1020 /* Build a new INT_CST for this DECL_VINDEX. */
1021 {
1022 static tree index_table[256];
1023 tree idx;
1024 /* We skip a slot for the offset/tdesc entry. */
1025 int i = ++(*has_virtual);
1026
1027 if (i >= 256 || index_table[i] == 0)
1028 {
1029 idx = build_int_2 (i, 0);
1030 if (i < 256)
1031 index_table[i] = idx;
1032 }
1033 else
1034 idx = index_table[i];
1035
1036 /* Now assign virtual dispatch information. */
1037 DECL_VINDEX (fndecl) = idx;
1038 DECL_CONTEXT (fndecl) = t;
1039 }
1040 entry = build_vtable_entry (integer_zero_node, vfn);
1041 pending_virtuals = tree_cons (DECL_VINDEX (fndecl), entry, pending_virtuals);
1042 }
1043 /* Might already be INTEGER_CST if declared twice in class. We will
1044 give error later or we've already given it. */
1045 else if (TREE_CODE (DECL_VINDEX (fndecl)) != INTEGER_CST)
1046 {
1047 /* Need an entry in some other virtual function table.
1048 Deal with this after we have laid out our virtual base classes. */
1049 pending_hard_virtuals = temp_tree_cons (fndecl, vfn, pending_hard_virtuals);
1050 }
1051 *pv = pending_virtuals;
1052 *phv = pending_hard_virtuals;
1053 }
1054 \f
1055 /* Obstack on which to build the vector of class methods. */
1056 struct obstack class_obstack;
1057 extern struct obstack *current_obstack;
1058
1059 /* Add method METHOD to class TYPE. This is used when a method
1060 has been defined which did not initially appear in the class definition,
1061 and helps cut down on spurious error messages.
1062
1063 FIELDS is the entry in the METHOD_VEC vector entry of the class type where
1064 the method should be added. */
1065
1066 void
1067 add_method (type, fields, method)
1068 tree type, *fields, method;
1069 {
1070 /* We must make a copy of METHOD here, since we must be sure that
1071 we have exclusive title to this method's DECL_CHAIN. */
1072 tree decl;
1073
1074 push_obstacks (&permanent_obstack, &permanent_obstack);
1075 {
1076 decl = copy_node (method);
1077 if (DECL_RTL (decl) == 0
1078 && (!processing_template_decl
1079 || !uses_template_parms (decl)))
1080 {
1081 make_function_rtl (decl);
1082 DECL_RTL (method) = DECL_RTL (decl);
1083 }
1084 }
1085
1086 if (fields && *fields)
1087 {
1088 /* Take care not to hide destructor. */
1089 DECL_CHAIN (decl) = DECL_CHAIN (*fields);
1090 DECL_CHAIN (*fields) = decl;
1091 }
1092 else if (CLASSTYPE_METHOD_VEC (type) == 0)
1093 {
1094 tree method_vec = make_node (TREE_VEC);
1095 if (TYPE_IDENTIFIER (type) == DECL_NAME (decl))
1096 {
1097 /* ??? Is it possible for there to have been enough room in the
1098 current chunk for the tree_vec structure but not a tree_vec
1099 plus a tree*? Will this work in that case? */
1100 obstack_free (current_obstack, method_vec);
1101 obstack_blank (current_obstack, sizeof (struct tree_vec) + sizeof (tree *));
1102 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl)))
1103 TREE_VEC_ELT (method_vec, 1) = decl;
1104 else
1105 TREE_VEC_ELT (method_vec, 0) = decl;
1106 TREE_VEC_LENGTH (method_vec) = 2;
1107 }
1108 else
1109 {
1110 /* ??? Is it possible for there to have been enough room in the
1111 current chunk for the tree_vec structure but not a tree_vec
1112 plus a tree*? Will this work in that case? */
1113 obstack_free (current_obstack, method_vec);
1114 obstack_blank (current_obstack, sizeof (struct tree_vec) + 2*sizeof (tree *));
1115 TREE_VEC_ELT (method_vec, 2) = decl;
1116 TREE_VEC_LENGTH (method_vec) = 3;
1117 obstack_finish (current_obstack);
1118 }
1119 CLASSTYPE_METHOD_VEC (type) = method_vec;
1120 }
1121 else
1122 {
1123 tree method_vec = CLASSTYPE_METHOD_VEC (type);
1124 int len = TREE_VEC_LENGTH (method_vec);
1125
1126 /* Adding a new ctor or dtor. This is easy because our
1127 METHOD_VEC always has a slot for such entries. */
1128 if (TYPE_IDENTIFIER (type) == DECL_NAME (decl))
1129 {
1130 int idx = !!DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl));
1131 /* TREE_VEC_ELT (method_vec, idx) = decl; */
1132 if (decl != TREE_VEC_ELT (method_vec, idx))
1133 {
1134 DECL_CHAIN (decl) = TREE_VEC_ELT (method_vec, idx);
1135 TREE_VEC_ELT (method_vec, idx) = decl;
1136 }
1137 }
1138 else
1139 {
1140 /* This is trickier. We try to extend the TREE_VEC in-place,
1141 but if that does not work, we copy all its data to a new
1142 TREE_VEC that's large enough. */
1143 struct obstack *ob = &class_obstack;
1144 tree *end = (tree *)obstack_next_free (ob);
1145
1146 if (end != TREE_VEC_END (method_vec))
1147 {
1148 ob = current_obstack;
1149 TREE_VEC_LENGTH (method_vec) += 1;
1150 TREE_VEC_ELT (method_vec, len) = NULL_TREE;
1151 method_vec = copy_node (method_vec);
1152 TREE_VEC_LENGTH (method_vec) -= 1;
1153 }
1154 else
1155 {
1156 tree tmp_vec = (tree) obstack_base (ob);
1157 if (obstack_room (ob) < sizeof (tree))
1158 {
1159 obstack_blank (ob, sizeof (struct tree_common)
1160 + tree_code_length[(int) TREE_VEC]
1161 * sizeof (char *)
1162 + len * sizeof (tree));
1163 tmp_vec = (tree) obstack_base (ob);
1164 bcopy ((char *) method_vec, (char *) tmp_vec,
1165 (sizeof (struct tree_common)
1166 + tree_code_length[(int) TREE_VEC] * sizeof (char *)
1167 + (len-1) * sizeof (tree)));
1168 method_vec = tmp_vec;
1169 }
1170 else
1171 obstack_blank (ob, sizeof (tree));
1172 }
1173
1174 obstack_finish (ob);
1175 TREE_VEC_ELT (method_vec, len) = decl;
1176 TREE_VEC_LENGTH (method_vec) = len + 1;
1177 CLASSTYPE_METHOD_VEC (type) = method_vec;
1178
1179 if (TYPE_BINFO_BASETYPES (type) && CLASSTYPE_BASELINK_VEC (type))
1180 {
1181 /* ??? May be better to know whether these can be extended? */
1182 tree baselink_vec = CLASSTYPE_BASELINK_VEC (type);
1183
1184 TREE_VEC_LENGTH (baselink_vec) += 1;
1185 CLASSTYPE_BASELINK_VEC (type) = copy_node (baselink_vec);
1186 TREE_VEC_LENGTH (baselink_vec) -= 1;
1187
1188 TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (type), len) = 0;
1189 }
1190 }
1191 }
1192 DECL_CONTEXT (decl) = type;
1193 DECL_CLASS_CONTEXT (decl) = type;
1194
1195 pop_obstacks ();
1196 }
1197
1198 /* Subroutines of finish_struct. */
1199
1200 /* Look through the list of fields for this struct, deleting
1201 duplicates as we go. This must be recursive to handle
1202 anonymous unions.
1203
1204 FIELD is the field which may not appear anywhere in FIELDS.
1205 FIELD_PTR, if non-null, is the starting point at which
1206 chained deletions may take place.
1207 The value returned is the first acceptable entry found
1208 in FIELDS.
1209
1210 Note that anonymous fields which are not of UNION_TYPE are
1211 not duplicates, they are just anonymous fields. This happens
1212 when we have unnamed bitfields, for example. */
1213
1214 static tree
1215 delete_duplicate_fields_1 (field, fields)
1216 tree field, fields;
1217 {
1218 tree x;
1219 tree prev = 0;
1220 if (DECL_NAME (field) == 0)
1221 {
1222 if (TREE_CODE (TREE_TYPE (field)) != UNION_TYPE)
1223 return fields;
1224
1225 for (x = TYPE_FIELDS (TREE_TYPE (field)); x; x = TREE_CHAIN (x))
1226 fields = delete_duplicate_fields_1 (x, fields);
1227 return fields;
1228 }
1229 else
1230 {
1231 for (x = fields; x; prev = x, x = TREE_CHAIN (x))
1232 {
1233 if (DECL_NAME (x) == 0)
1234 {
1235 if (TREE_CODE (TREE_TYPE (x)) != UNION_TYPE)
1236 continue;
1237 TYPE_FIELDS (TREE_TYPE (x))
1238 = delete_duplicate_fields_1 (field, TYPE_FIELDS (TREE_TYPE (x)));
1239 if (TYPE_FIELDS (TREE_TYPE (x)) == 0)
1240 {
1241 if (prev == 0)
1242 fields = TREE_CHAIN (fields);
1243 else
1244 TREE_CHAIN (prev) = TREE_CHAIN (x);
1245 }
1246 }
1247 else
1248 {
1249 if (DECL_NAME (field) == DECL_NAME (x))
1250 {
1251 if (TREE_CODE (field) == CONST_DECL
1252 && TREE_CODE (x) == CONST_DECL)
1253 cp_error_at ("duplicate enum value `%D'", x);
1254 else if (TREE_CODE (field) == CONST_DECL
1255 || TREE_CODE (x) == CONST_DECL)
1256 cp_error_at ("duplicate field `%D' (as enum and non-enum)",
1257 x);
1258 else if (TREE_CODE (field) == TYPE_DECL
1259 && TREE_CODE (x) == TYPE_DECL)
1260 {
1261 if (TREE_TYPE (field) == TREE_TYPE (x))
1262 continue;
1263 cp_error_at ("duplicate nested type `%D'", x);
1264 }
1265 else if (TREE_CODE (field) == TYPE_DECL
1266 || TREE_CODE (x) == TYPE_DECL)
1267 {
1268 /* Hide tag decls. */
1269 if ((TREE_CODE (field) == TYPE_DECL
1270 && DECL_ARTIFICIAL (field))
1271 || (TREE_CODE (x) == TYPE_DECL
1272 && DECL_ARTIFICIAL (x)))
1273 continue;
1274 cp_error_at ("duplicate field `%D' (as type and non-type)",
1275 x);
1276 }
1277 else
1278 cp_error_at ("duplicate member `%D'", x);
1279 if (prev == 0)
1280 fields = TREE_CHAIN (fields);
1281 else
1282 TREE_CHAIN (prev) = TREE_CHAIN (x);
1283 }
1284 }
1285 }
1286 }
1287 return fields;
1288 }
1289
1290 static void
1291 delete_duplicate_fields (fields)
1292 tree fields;
1293 {
1294 tree x;
1295 for (x = fields; x && TREE_CHAIN (x); x = TREE_CHAIN (x))
1296 TREE_CHAIN (x) = delete_duplicate_fields_1 (x, TREE_CHAIN (x));
1297 }
1298
1299 /* Change the access of FDECL to ACCESS in T.
1300 Return 1 if change was legit, otherwise return 0. */
1301
1302 static int
1303 alter_access (t, fdecl, access)
1304 tree t;
1305 tree fdecl;
1306 tree access;
1307 {
1308 tree elem = purpose_member (t, DECL_ACCESS (fdecl));
1309 if (elem && TREE_VALUE (elem) != access)
1310 {
1311 if (TREE_CODE (TREE_TYPE (fdecl)) == FUNCTION_DECL)
1312 {
1313 cp_error_at ("conflicting access specifications for method `%D', ignored", TREE_TYPE (fdecl));
1314 }
1315 else
1316 error ("conflicting access specifications for field `%s', ignored",
1317 IDENTIFIER_POINTER (DECL_NAME (fdecl)));
1318 }
1319 else if (TREE_PRIVATE (fdecl))
1320 {
1321 if (access != access_private_node)
1322 cp_error_at ("cannot make private `%D' non-private", fdecl);
1323 goto alter;
1324 }
1325 else if (TREE_PROTECTED (fdecl))
1326 {
1327 if (access != access_protected_node)
1328 cp_error_at ("cannot make protected `%D' non-protected", fdecl);
1329 goto alter;
1330 }
1331 /* ARM 11.3: an access declaration may not be used to restrict access
1332 to a member that is accessible in the base class. */
1333 else if (access != access_public_node)
1334 cp_error_at ("cannot reduce access of public member `%D'", fdecl);
1335 else if (elem == NULL_TREE)
1336 {
1337 alter:
1338 DECL_ACCESS (fdecl) = tree_cons (t, access, DECL_ACCESS (fdecl));
1339 return 1;
1340 }
1341 return 0;
1342 }
1343
1344 /* If FOR_TYPE needs to reinitialize virtual function table pointers
1345 for TYPE's sub-objects, add such reinitializations to BASE_INIT_LIST.
1346 Returns BASE_INIT_LIST appropriately modified. */
1347
1348 static tree
1349 maybe_fixup_vptrs (for_type, binfo, base_init_list)
1350 tree for_type, binfo, base_init_list;
1351 {
1352 /* Now reinitialize any slots that don't fall under our virtual
1353 function table pointer. */
1354 tree vfields = CLASSTYPE_VFIELDS (BINFO_TYPE (binfo));
1355 while (vfields)
1356 {
1357 tree basetype = VF_NORMAL_VALUE (vfields)
1358 ? TYPE_MAIN_VARIANT (VF_NORMAL_VALUE (vfields))
1359 : VF_BASETYPE_VALUE (vfields);
1360
1361 tree base_binfo = get_binfo (basetype, for_type, 0);
1362 /* Punt until this is implemented. */
1363 if (1 /* BINFO_MODIFIED (base_binfo) */)
1364 {
1365 tree base_offset = get_vfield_offset (base_binfo);
1366 if (! tree_int_cst_equal (base_offset, get_vfield_offset (TYPE_BINFO (for_type)))
1367 && ! tree_int_cst_equal (base_offset, get_vfield_offset (binfo)))
1368 base_init_list = tree_cons (error_mark_node, base_binfo,
1369 base_init_list);
1370 }
1371 vfields = TREE_CHAIN (vfields);
1372 }
1373 return base_init_list;
1374 }
1375
1376 /* If TYPE does not have a constructor, then the compiler must
1377 manually deal with all of the initialization this type requires.
1378
1379 If a base initializer exists only to fill in the virtual function
1380 table pointer, then we mark that fact with the TREE_VIRTUAL bit.
1381 This way, we avoid multiple initializations of the same field by
1382 each virtual function table up the class hierarchy.
1383
1384 Virtual base class pointers are not initialized here. They are
1385 initialized only at the "top level" of object creation. If we
1386 initialized them here, we would have to skip a lot of work. */
1387
1388 static void
1389 build_class_init_list (type)
1390 tree type;
1391 {
1392 tree base_init_list = NULL_TREE;
1393 tree member_init_list = NULL_TREE;
1394
1395 /* Since we build member_init_list and base_init_list using
1396 tree_cons, backwards fields the all through work. */
1397 tree x;
1398 tree binfos = BINFO_BASETYPES (TYPE_BINFO (type));
1399 int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
1400
1401 for (x = TYPE_FIELDS (type); x; x = TREE_CHAIN (x))
1402 {
1403 if (TREE_CODE (x) != FIELD_DECL)
1404 continue;
1405
1406 if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (x))
1407 || DECL_INITIAL (x) != NULL_TREE)
1408 member_init_list = tree_cons (x, type, member_init_list);
1409 }
1410 member_init_list = nreverse (member_init_list);
1411
1412 /* We will end up doing this last. Need special marker
1413 to avoid infinite regress. */
1414 if (TYPE_VIRTUAL_P (type))
1415 {
1416 base_init_list = build_tree_list (error_mark_node, TYPE_BINFO (type));
1417 if (CLASSTYPE_NEEDS_VIRTUAL_REINIT (type) == 0)
1418 TREE_VALUE (base_init_list) = NULL_TREE;
1419 TREE_ADDRESSABLE (base_init_list) = 1;
1420 }
1421
1422 /* Each base class which needs to have initialization
1423 of some kind gets to make such requests known here. */
1424 for (i = n_baseclasses-1; i >= 0; i--)
1425 {
1426 tree base_binfo = TREE_VEC_ELT (binfos, i);
1427 tree blist;
1428
1429 /* Don't initialize virtual baseclasses this way. */
1430 if (TREE_VIA_VIRTUAL (base_binfo))
1431 continue;
1432
1433 if (TYPE_HAS_CONSTRUCTOR (BINFO_TYPE (base_binfo)))
1434 {
1435 /* ...and the last shall come first... */
1436 base_init_list = maybe_fixup_vptrs (type, base_binfo, base_init_list);
1437 base_init_list = tree_cons (NULL_TREE, base_binfo, base_init_list);
1438 continue;
1439 }
1440
1441 if ((blist = CLASSTYPE_BASE_INIT_LIST (BINFO_TYPE (base_binfo))) == NULL_TREE)
1442 /* Nothing to initialize. */
1443 continue;
1444
1445 /* ...ditto... */
1446 base_init_list = maybe_fixup_vptrs (type, base_binfo, base_init_list);
1447
1448 /* This is normally true for single inheritance.
1449 The win is we can shrink the chain of initializations
1450 to be done by only converting to the actual type
1451 we are interested in. */
1452 if (TREE_VALUE (blist)
1453 && TREE_CODE (TREE_VALUE (blist)) == TREE_VEC
1454 && tree_int_cst_equal (BINFO_OFFSET (base_binfo),
1455 BINFO_OFFSET (TREE_VALUE (blist))))
1456 {
1457 if (base_init_list)
1458 {
1459 /* Does it do more than just fill in a
1460 virtual function table pointer? */
1461 if (! TREE_ADDRESSABLE (blist))
1462 base_init_list = build_tree_list (blist, base_init_list);
1463 /* Can we get by just with the virtual function table
1464 pointer that it fills in? */
1465 else if (TREE_ADDRESSABLE (base_init_list)
1466 && TREE_VALUE (base_init_list) == 0)
1467 base_init_list = blist;
1468 /* Maybe, but it is not obvious as the previous case. */
1469 else if (! CLASSTYPE_NEEDS_VIRTUAL_REINIT (type))
1470 {
1471 tree last = tree_last (base_init_list);
1472 while (TREE_VALUE (last)
1473 && TREE_CODE (TREE_VALUE (last)) == TREE_LIST)
1474 last = tree_last (TREE_VALUE (last));
1475 if (TREE_VALUE (last) == 0)
1476 base_init_list = build_tree_list (blist, base_init_list);
1477 }
1478 }
1479 else
1480 base_init_list = blist;
1481 }
1482 else
1483 {
1484 /* The function expand_aggr_init knows how to do the
1485 initialization of `basetype' without getting
1486 an explicit `blist'. */
1487 if (base_init_list)
1488 base_init_list = tree_cons (NULL_TREE, base_binfo, base_init_list);
1489 else
1490 base_init_list = CLASSTYPE_BINFO_AS_LIST (BINFO_TYPE (base_binfo));
1491 }
1492 }
1493
1494 if (base_init_list)
1495 if (member_init_list)
1496 CLASSTYPE_BASE_INIT_LIST (type) = build_tree_list (base_init_list, member_init_list);
1497 else
1498 CLASSTYPE_BASE_INIT_LIST (type) = base_init_list;
1499 else if (member_init_list)
1500 CLASSTYPE_BASE_INIT_LIST (type) = member_init_list;
1501 }
1502 \f
1503 struct base_info
1504 {
1505 int has_virtual;
1506 int max_has_virtual;
1507 int n_ancestors;
1508 tree vfield;
1509 tree vfields;
1510 tree rtti;
1511 char cant_have_default_ctor;
1512 char cant_have_const_ctor;
1513 char no_const_asn_ref;
1514 };
1515
1516 /* Record information about type T derived from its base classes.
1517 Store most of that information in T itself, and place the
1518 remaining information in the struct BASE_INFO.
1519
1520 Propagate basetype offsets throughout the lattice. Note that the
1521 lattice topped by T is really a pair: it's a DAG that gives the
1522 structure of the derivation hierarchy, and it's a list of the
1523 virtual baseclasses that appear anywhere in the DAG. When a vbase
1524 type appears in the DAG, it's offset is 0, and it's children start
1525 their offsets from that point. When a vbase type appears in the list,
1526 its offset is the offset it has in the hierarchy, and its children's
1527 offsets include that offset in theirs.
1528
1529 Returns the index of the first base class to have virtual functions,
1530 or -1 if no such base class.
1531
1532 Note that at this point TYPE_BINFO (t) != t_binfo. */
1533
1534 static int
1535 finish_base_struct (t, b, t_binfo)
1536 tree t;
1537 struct base_info *b;
1538 tree t_binfo;
1539 {
1540 tree binfos = BINFO_BASETYPES (t_binfo);
1541 int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
1542 int first_vfn_base_index = -1;
1543 bzero ((char *) b, sizeof (struct base_info));
1544
1545 for (i = 0; i < n_baseclasses; i++)
1546 {
1547 tree base_binfo = TREE_VEC_ELT (binfos, i);
1548 tree basetype = BINFO_TYPE (base_binfo);
1549
1550 /* If the type of basetype is incomplete, then
1551 we already complained about that fact
1552 (and we should have fixed it up as well). */
1553 if (TYPE_SIZE (basetype) == 0)
1554 {
1555 int j;
1556 /* The base type is of incomplete type. It is
1557 probably best to pretend that it does not
1558 exist. */
1559 if (i == n_baseclasses-1)
1560 TREE_VEC_ELT (binfos, i) = NULL_TREE;
1561 TREE_VEC_LENGTH (binfos) -= 1;
1562 n_baseclasses -= 1;
1563 for (j = i; j+1 < n_baseclasses; j++)
1564 TREE_VEC_ELT (binfos, j) = TREE_VEC_ELT (binfos, j+1);
1565 }
1566
1567 if (! TYPE_HAS_CONST_INIT_REF (basetype))
1568 b->cant_have_const_ctor = 1;
1569
1570 if (TYPE_HAS_CONSTRUCTOR (basetype)
1571 && ! TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype))
1572 {
1573 b->cant_have_default_ctor = 1;
1574 if (! TYPE_HAS_CONSTRUCTOR (t))
1575 {
1576 cp_pedwarn ("base `%T' with only non-default constructor",
1577 basetype);
1578 cp_pedwarn ("in class without a constructor");
1579 }
1580 }
1581
1582 if (TYPE_HAS_ASSIGN_REF (basetype)
1583 && !TYPE_HAS_CONST_ASSIGN_REF (basetype))
1584 b->no_const_asn_ref = 1;
1585
1586 b->n_ancestors += CLASSTYPE_N_SUPERCLASSES (basetype);
1587 TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (basetype);
1588 TYPE_NEEDS_DESTRUCTOR (t) |= TYPE_NEEDS_DESTRUCTOR (basetype);
1589 TYPE_HAS_COMPLEX_ASSIGN_REF (t) |= TYPE_HAS_COMPLEX_ASSIGN_REF (basetype);
1590 TYPE_HAS_COMPLEX_INIT_REF (t) |= TYPE_HAS_COMPLEX_INIT_REF (basetype);
1591
1592 TYPE_OVERLOADS_CALL_EXPR (t) |= TYPE_OVERLOADS_CALL_EXPR (basetype);
1593 TYPE_OVERLOADS_ARRAY_REF (t) |= TYPE_OVERLOADS_ARRAY_REF (basetype);
1594 TYPE_OVERLOADS_ARROW (t) |= TYPE_OVERLOADS_ARROW (basetype);
1595
1596 if (! TREE_VIA_VIRTUAL (base_binfo)
1597 && BINFO_BASETYPES (base_binfo))
1598 {
1599 tree base_binfos = BINFO_BASETYPES (base_binfo);
1600 tree chain = NULL_TREE;
1601 int j;
1602
1603 /* Now unshare the structure beneath BASE_BINFO. */
1604 for (j = TREE_VEC_LENGTH (base_binfos)-1;
1605 j >= 0; j--)
1606 {
1607 tree base_base_binfo = TREE_VEC_ELT (base_binfos, j);
1608 if (! TREE_VIA_VIRTUAL (base_base_binfo))
1609 TREE_VEC_ELT (base_binfos, j)
1610 = make_binfo (BINFO_OFFSET (base_base_binfo),
1611 base_base_binfo,
1612 BINFO_VTABLE (base_base_binfo),
1613 BINFO_VIRTUALS (base_base_binfo),
1614 chain);
1615 chain = TREE_VEC_ELT (base_binfos, j);
1616 TREE_VIA_PUBLIC (chain) = TREE_VIA_PUBLIC (base_base_binfo);
1617 TREE_VIA_PROTECTED (chain) = TREE_VIA_PROTECTED (base_base_binfo);
1618 BINFO_INHERITANCE_CHAIN (chain) = base_binfo;
1619 }
1620
1621 /* Completely unshare potentially shared data, and
1622 update what is ours. */
1623 propagate_binfo_offsets (base_binfo, BINFO_OFFSET (base_binfo));
1624 }
1625
1626 if (! TREE_VIA_VIRTUAL (base_binfo))
1627 CLASSTYPE_N_SUPERCLASSES (t) += 1;
1628
1629 if (TYPE_VIRTUAL_P (basetype))
1630 {
1631 /* Ensure that this is set from at least a virtual base
1632 class. */
1633 if (b->rtti == NULL_TREE)
1634 b->rtti = CLASSTYPE_RTTI (basetype);
1635
1636 /* Don't borrow virtuals from virtual baseclasses. */
1637 if (TREE_VIA_VIRTUAL (base_binfo))
1638 continue;
1639
1640 if (first_vfn_base_index < 0)
1641 {
1642 tree vfields;
1643 first_vfn_base_index = i;
1644
1645 /* Update these two, now that we know what vtable we are
1646 going to extend. This is so that we can add virtual
1647 functions, and override them properly. */
1648 BINFO_VTABLE (t_binfo) = TYPE_BINFO_VTABLE (basetype);
1649 BINFO_VIRTUALS (t_binfo) = TYPE_BINFO_VIRTUALS (basetype);
1650 b->has_virtual = CLASSTYPE_VSIZE (basetype);
1651 b->vfield = CLASSTYPE_VFIELD (basetype);
1652 b->vfields = copy_list (CLASSTYPE_VFIELDS (basetype));
1653 vfields = b->vfields;
1654 while (vfields)
1655 {
1656 if (VF_BINFO_VALUE (vfields) == NULL_TREE
1657 || ! TREE_VIA_VIRTUAL (VF_BINFO_VALUE (vfields)))
1658 {
1659 tree value = VF_BASETYPE_VALUE (vfields);
1660 if (DECL_NAME (CLASSTYPE_VFIELD (value))
1661 == DECL_NAME (CLASSTYPE_VFIELD (basetype)))
1662 VF_NORMAL_VALUE (b->vfields) = basetype;
1663 else
1664 VF_NORMAL_VALUE (b->vfields) = VF_NORMAL_VALUE (vfields);
1665 }
1666 vfields = TREE_CHAIN (vfields);
1667 }
1668 CLASSTYPE_VFIELD (t) = b->vfield;
1669 }
1670 else
1671 {
1672 /* Only add unique vfields, and flatten them out as we go. */
1673 tree vfields = CLASSTYPE_VFIELDS (basetype);
1674 while (vfields)
1675 {
1676 if (VF_BINFO_VALUE (vfields) == NULL_TREE
1677 || ! TREE_VIA_VIRTUAL (VF_BINFO_VALUE (vfields)))
1678 {
1679 tree value = VF_BASETYPE_VALUE (vfields);
1680 b->vfields = tree_cons (base_binfo, value, b->vfields);
1681 if (DECL_NAME (CLASSTYPE_VFIELD (value))
1682 == DECL_NAME (CLASSTYPE_VFIELD (basetype)))
1683 VF_NORMAL_VALUE (b->vfields) = basetype;
1684 else
1685 VF_NORMAL_VALUE (b->vfields) = VF_NORMAL_VALUE (vfields);
1686 }
1687 vfields = TREE_CHAIN (vfields);
1688 }
1689
1690 if (b->has_virtual == 0)
1691 {
1692 first_vfn_base_index = i;
1693
1694 /* Update these two, now that we know what vtable we are
1695 going to extend. This is so that we can add virtual
1696 functions, and override them properly. */
1697 BINFO_VTABLE (t_binfo) = TYPE_BINFO_VTABLE (basetype);
1698 BINFO_VIRTUALS (t_binfo) = TYPE_BINFO_VIRTUALS (basetype);
1699 b->has_virtual = CLASSTYPE_VSIZE (basetype);
1700 b->vfield = CLASSTYPE_VFIELD (basetype);
1701 CLASSTYPE_VFIELD (t) = b->vfield;
1702 /* When we install the first one, set the VF_NORMAL_VALUE
1703 to be the current class, as this it is the most derived
1704 class. Hopefully, this is not set to something else
1705 later. (mrs) */
1706 vfields = b->vfields;
1707 while (vfields)
1708 {
1709 if (DECL_NAME (CLASSTYPE_VFIELD (t))
1710 == DECL_NAME (CLASSTYPE_VFIELD (basetype)))
1711 {
1712 VF_NORMAL_VALUE (vfields) = t;
1713 /* There should only be one of them! And it should
1714 always be found, if we get into here. (mrs) */
1715 break;
1716 }
1717 vfields = TREE_CHAIN (vfields);
1718 }
1719 }
1720 }
1721 }
1722 }
1723
1724 /* Must come after offsets are fixed for all bases. */
1725 for (i = 0; i < n_baseclasses; i++)
1726 {
1727 tree base_binfo = TREE_VEC_ELT (binfos, i);
1728 tree basetype = BINFO_TYPE (base_binfo);
1729
1730 if (get_base_distance (basetype, t_binfo, 0, (tree*)0) == -2)
1731 {
1732 cp_warning ("direct base `%T' inaccessible in `%T' due to ambiguity",
1733 basetype, t);
1734 }
1735 }
1736 {
1737 tree v = get_vbase_types (t_binfo);
1738
1739 for (; v; v = TREE_CHAIN (v))
1740 {
1741 tree basetype = BINFO_TYPE (v);
1742 if (get_base_distance (basetype, t_binfo, 0, (tree*)0) == -2)
1743 {
1744 if (extra_warnings)
1745 cp_warning ("virtual base `%T' inaccessible in `%T' due to ambiguity",
1746 basetype, t);
1747 }
1748 }
1749 }
1750
1751 {
1752 tree vfields;
1753 /* Find the base class with the largest number of virtual functions. */
1754 for (vfields = b->vfields; vfields; vfields = TREE_CHAIN (vfields))
1755 {
1756 if (CLASSTYPE_VSIZE (VF_BASETYPE_VALUE (vfields)) > b->max_has_virtual)
1757 b->max_has_virtual = CLASSTYPE_VSIZE (VF_BASETYPE_VALUE (vfields));
1758 if (VF_DERIVED_VALUE (vfields)
1759 && CLASSTYPE_VSIZE (VF_DERIVED_VALUE (vfields)) > b->max_has_virtual)
1760 b->max_has_virtual = CLASSTYPE_VSIZE (VF_DERIVED_VALUE (vfields));
1761 }
1762 }
1763
1764 if (b->vfield == 0)
1765 /* If all virtual functions come only from virtual baseclasses. */
1766 return -1;
1767
1768 /* Update the rtti base if we have a non-virtual base class version
1769 of it. */
1770 b->rtti = CLASSTYPE_RTTI (BINFO_TYPE (TREE_VEC_ELT (binfos, first_vfn_base_index)));
1771
1772 return first_vfn_base_index;
1773 }
1774
1775 static int
1776 typecode_p (type, code)
1777 tree type;
1778 enum tree_code code;
1779 {
1780 return (TREE_CODE (type) == code
1781 || (TREE_CODE (type) == REFERENCE_TYPE
1782 && TREE_CODE (TREE_TYPE (type)) == code));
1783 }
1784 \f
1785 /* Set memoizing fields and bits of T (and its variants) for later use.
1786 MAX_HAS_VIRTUAL is the largest size of any T's virtual function tables. */
1787
1788 static void
1789 finish_struct_bits (t, max_has_virtual)
1790 tree t;
1791 int max_has_virtual;
1792 {
1793 int i, n_baseclasses = CLASSTYPE_N_BASECLASSES (t);
1794
1795 /* Fix up variants (if any). */
1796 tree variants = TYPE_NEXT_VARIANT (t);
1797 while (variants)
1798 {
1799 /* These fields are in the _TYPE part of the node, not in
1800 the TYPE_LANG_SPECIFIC component, so they are not shared. */
1801 TYPE_HAS_CONSTRUCTOR (variants) = TYPE_HAS_CONSTRUCTOR (t);
1802 TYPE_HAS_DESTRUCTOR (variants) = TYPE_HAS_DESTRUCTOR (t);
1803 TYPE_NEEDS_CONSTRUCTING (variants) = TYPE_NEEDS_CONSTRUCTING (t);
1804 TYPE_NEEDS_DESTRUCTOR (variants) = TYPE_NEEDS_DESTRUCTOR (t);
1805
1806 TYPE_USES_COMPLEX_INHERITANCE (variants) = TYPE_USES_COMPLEX_INHERITANCE (t);
1807 TYPE_VIRTUAL_P (variants) = TYPE_VIRTUAL_P (t);
1808 TYPE_USES_VIRTUAL_BASECLASSES (variants) = TYPE_USES_VIRTUAL_BASECLASSES (t);
1809 /* Copy whatever these are holding today. */
1810 TYPE_MIN_VALUE (variants) = TYPE_MIN_VALUE (t);
1811 TYPE_MAX_VALUE (variants) = TYPE_MAX_VALUE (t);
1812 TYPE_FIELDS (variants) = TYPE_FIELDS (t);
1813 TYPE_SIZE (variants) = TYPE_SIZE (t);
1814 variants = TYPE_NEXT_VARIANT (variants);
1815 }
1816
1817 if (n_baseclasses && max_has_virtual)
1818 {
1819 /* Done by `finish_struct' for classes without baseclasses. */
1820 int might_have_abstract_virtuals = CLASSTYPE_ABSTRACT_VIRTUALS (t) != 0;
1821 tree binfos = TYPE_BINFO_BASETYPES (t);
1822 for (i = n_baseclasses-1; i >= 0; i--)
1823 {
1824 might_have_abstract_virtuals
1825 |= (CLASSTYPE_ABSTRACT_VIRTUALS (BINFO_TYPE (TREE_VEC_ELT (binfos, i))) != 0);
1826 if (might_have_abstract_virtuals)
1827 break;
1828 }
1829 if (might_have_abstract_virtuals)
1830 {
1831 /* We use error_mark_node from override_one_vtable to signal
1832 an artificial abstract. */
1833 if (CLASSTYPE_ABSTRACT_VIRTUALS (t) == error_mark_node)
1834 CLASSTYPE_ABSTRACT_VIRTUALS (t) = NULL_TREE;
1835 CLASSTYPE_ABSTRACT_VIRTUALS (t) = get_abstract_virtuals (t);
1836 }
1837 }
1838
1839 if (n_baseclasses)
1840 {
1841 /* Notice whether this class has type conversion functions defined. */
1842 tree binfo = TYPE_BINFO (t);
1843 tree binfos = BINFO_BASETYPES (binfo);
1844 tree basetype;
1845
1846 for (i = n_baseclasses-1; i >= 0; i--)
1847 {
1848 basetype = BINFO_TYPE (TREE_VEC_ELT (binfos, i));
1849
1850 if (TYPE_HAS_CONVERSION (basetype))
1851 {
1852 TYPE_HAS_CONVERSION (t) = 1;
1853 TYPE_HAS_INT_CONVERSION (t) |= TYPE_HAS_INT_CONVERSION (basetype);
1854 TYPE_HAS_REAL_CONVERSION (t) |= TYPE_HAS_REAL_CONVERSION (basetype);
1855 }
1856 if (CLASSTYPE_MAX_DEPTH (basetype) >= CLASSTYPE_MAX_DEPTH (t))
1857 CLASSTYPE_MAX_DEPTH (t) = CLASSTYPE_MAX_DEPTH (basetype) + 1;
1858 }
1859 }
1860
1861 /* If this type has a copy constructor, force its mode to be BLKmode, and
1862 force its TREE_ADDRESSABLE bit to be nonzero. This will cause it to
1863 be passed by invisible reference and prevent it from being returned in
1864 a register.
1865
1866 Also do this if the class has BLKmode but can still be returned in
1867 registers, since function_cannot_inline_p won't let us inline
1868 functions returning such a type. This affects the HP-PA. */
1869 if (! TYPE_HAS_TRIVIAL_INIT_REF (t)
1870 || (TYPE_MODE (t) == BLKmode && ! aggregate_value_p (t)
1871 && CLASSTYPE_NON_AGGREGATE (t)))
1872 {
1873 tree variants;
1874 DECL_MODE (TYPE_MAIN_DECL (t)) = BLKmode;
1875 for (variants = t; variants; variants = TYPE_NEXT_VARIANT (variants))
1876 {
1877 TYPE_MODE (variants) = BLKmode;
1878 TREE_ADDRESSABLE (variants) = 1;
1879 }
1880 }
1881 }
1882
1883 /* Add FNDECL to the method_vec growing on the class_obstack. Used by
1884 finish_struct_methods. Note, FNDECL cannot be a constructor or
1885 destructor, those cases are handled by the caller. */
1886
1887 static void
1888 grow_method (fndecl, method_vec_ptr)
1889 tree fndecl;
1890 tree *method_vec_ptr;
1891 {
1892 tree method_vec = (tree)obstack_base (&class_obstack);
1893
1894 /* Start off past the constructors and destructor. */
1895 tree *testp = &TREE_VEC_ELT (method_vec, 2);
1896
1897 while (testp < (tree *) obstack_next_free (&class_obstack)
1898 && (*testp == NULL_TREE || DECL_NAME (*testp) != DECL_NAME (fndecl)))
1899 testp++;
1900
1901 if (testp < (tree *) obstack_next_free (&class_obstack))
1902 {
1903 tree *p;
1904 for (p = testp; *p; )
1905 p = &DECL_CHAIN (*p);
1906 *p = fndecl;
1907 }
1908 else
1909 {
1910 obstack_ptr_grow (&class_obstack, fndecl);
1911 *method_vec_ptr = (tree)obstack_base (&class_obstack);
1912 }
1913 }
1914
1915 /* Warn about duplicate methods in fn_fields. Also compact method
1916 lists so that lookup can be made faster.
1917
1918 Algorithm: Outer loop builds lists by method name. Inner loop
1919 checks for redundant method names within a list.
1920
1921 Data Structure: List of method lists. The outer list is a
1922 TREE_LIST, whose TREE_PURPOSE field is the field name and the
1923 TREE_VALUE is the DECL_CHAIN of the FUNCTION_DECLs. TREE_CHAIN
1924 links the entire list of methods for TYPE_METHODS. Friends are
1925 chained in the same way as member functions (? TREE_CHAIN or
1926 DECL_CHAIN), but they live in the TREE_TYPE field of the outer
1927 list. That allows them to be quickly deleted, and requires no
1928 extra storage.
1929
1930 If there are any constructors/destructors, they are moved to the
1931 front of the list. This makes pushclass more efficient.
1932
1933 We also link each field which has shares a name with its baseclass
1934 to the head of the list of fields for that base class. This allows
1935 us to reduce search time in places like `build_method_call' to
1936 consider only reasonably likely functions. */
1937
1938 tree
1939 finish_struct_methods (t, fn_fields, nonprivate_method)
1940 tree t;
1941 tree fn_fields;
1942 int nonprivate_method;
1943 {
1944 tree method_vec;
1945 tree save_fn_fields = fn_fields;
1946 tree ctor_name = constructor_name (t);
1947 int i, n_baseclasses = CLASSTYPE_N_BASECLASSES (t);
1948
1949 /* Now prepare to gather fn_fields into vector. */
1950 struct obstack *ambient_obstack = current_obstack;
1951 current_obstack = &class_obstack;
1952 method_vec = make_tree_vec (2);
1953 current_obstack = ambient_obstack;
1954
1955 /* Now make this a live vector. */
1956 obstack_free (&class_obstack, method_vec);
1957
1958 /* Save room for constructors and destructors. */
1959 obstack_blank (&class_obstack, sizeof (struct tree_vec) + sizeof (struct tree *));
1960
1961 /* First fill in entry 0 with the constructors, entry 1 with destructors,
1962 and the next few with type conversion operators (if any). */
1963
1964 for (; fn_fields; fn_fields = TREE_CHAIN (fn_fields))
1965 {
1966 tree fn_name = DECL_NAME (fn_fields);
1967
1968 /* Clear out this flag.
1969
1970 @@ Doug may figure out how to break
1971 @@ this with nested classes and friends. */
1972 DECL_IN_AGGR_P (fn_fields) = 0;
1973
1974 /* Note here that a copy ctor is private, so we don't dare generate
1975 a default copy constructor for a class that has a member
1976 of this type without making sure they have access to it. */
1977 if (fn_name == ctor_name)
1978 {
1979 tree parmtypes = FUNCTION_ARG_CHAIN (fn_fields);
1980 tree parmtype = parmtypes ? TREE_VALUE (parmtypes) : void_type_node;
1981
1982 if (TREE_CODE (parmtype) == REFERENCE_TYPE
1983 && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype)) == t)
1984 {
1985 if (TREE_CHAIN (parmtypes) == NULL_TREE
1986 || TREE_CHAIN (parmtypes) == void_list_node
1987 || TREE_PURPOSE (TREE_CHAIN (parmtypes)))
1988 {
1989 if (TREE_PROTECTED (fn_fields))
1990 TYPE_HAS_NONPUBLIC_CTOR (t) = 1;
1991 else if (TREE_PRIVATE (fn_fields))
1992 TYPE_HAS_NONPUBLIC_CTOR (t) = 2;
1993 }
1994 }
1995 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fn_fields)))
1996 {
1997 /* Destructors go in slot 1. */
1998 DECL_CHAIN (fn_fields) = TREE_VEC_ELT (method_vec, 1);
1999 TREE_VEC_ELT (method_vec, 1) = fn_fields;
2000 }
2001 else
2002 {
2003 /* Constructors go in slot 0. */
2004 DECL_CHAIN (fn_fields) = TREE_VEC_ELT (method_vec, 0);
2005 TREE_VEC_ELT (method_vec, 0) = fn_fields;
2006 }
2007 }
2008 else if (IDENTIFIER_TYPENAME_P (fn_name))
2009 {
2010 tree return_type = TREE_TYPE (TREE_TYPE (fn_fields));
2011
2012 if (typecode_p (return_type, INTEGER_TYPE)
2013 || typecode_p (return_type, BOOLEAN_TYPE)
2014 || typecode_p (return_type, ENUMERAL_TYPE))
2015 TYPE_HAS_INT_CONVERSION (t) = 1;
2016 else if (typecode_p (return_type, REAL_TYPE))
2017 TYPE_HAS_REAL_CONVERSION (t) = 1;
2018
2019 grow_method (fn_fields, &method_vec);
2020 }
2021 }
2022
2023 fn_fields = save_fn_fields;
2024 for (; fn_fields; fn_fields = TREE_CHAIN (fn_fields))
2025 {
2026 tree fn_name = DECL_NAME (fn_fields);
2027
2028 if (fn_name == ctor_name || IDENTIFIER_TYPENAME_P (fn_name))
2029 continue;
2030
2031 if (fn_name == ansi_opname[(int) MODIFY_EXPR])
2032 {
2033 tree parmtype = TREE_VALUE (FUNCTION_ARG_CHAIN (fn_fields));
2034
2035 if (copy_assignment_arg_p (parmtype, DECL_VIRTUAL_P (fn_fields)))
2036 {
2037 if (TREE_PROTECTED (fn_fields))
2038 TYPE_HAS_NONPUBLIC_ASSIGN_REF (t) = 1;
2039 else if (TREE_PRIVATE (fn_fields))
2040 TYPE_HAS_NONPUBLIC_ASSIGN_REF (t) = 2;
2041 }
2042 }
2043
2044 grow_method (fn_fields, &method_vec);
2045 }
2046
2047 TREE_VEC_LENGTH (method_vec) = (tree *)obstack_next_free (&class_obstack)
2048 - (&TREE_VEC_ELT (method_vec, 0));
2049 obstack_finish (&class_obstack);
2050 CLASSTYPE_METHOD_VEC (t) = method_vec;
2051
2052 if (nonprivate_method == 0
2053 && CLASSTYPE_FRIEND_CLASSES (t) == NULL_TREE
2054 && DECL_FRIENDLIST (TYPE_MAIN_DECL (t)) == NULL_TREE)
2055 {
2056 tree binfos = BINFO_BASETYPES (TYPE_BINFO (t));
2057 for (i = 0; i < n_baseclasses; i++)
2058 if (TREE_VIA_PUBLIC (TREE_VEC_ELT (binfos, i))
2059 || TREE_VIA_PROTECTED (TREE_VEC_ELT (binfos, i)))
2060 {
2061 nonprivate_method = 1;
2062 break;
2063 }
2064 if (nonprivate_method == 0
2065 && warn_ctor_dtor_privacy)
2066 cp_warning ("all member functions in class `%T' are private", t);
2067 }
2068
2069 /* Warn if all destructors are private (in which case this class is
2070 effectively unusable. */
2071 if (TYPE_HAS_DESTRUCTOR (t))
2072 {
2073 tree dtor = TREE_VEC_ELT (method_vec, 1);
2074
2075 /* Wild parse errors can cause this to happen. */
2076 if (dtor == NULL_TREE)
2077 TYPE_HAS_DESTRUCTOR (t) = 0;
2078 else if (TREE_PRIVATE (dtor)
2079 && CLASSTYPE_FRIEND_CLASSES (t) == NULL_TREE
2080 && DECL_FRIENDLIST (TYPE_MAIN_DECL (t)) == NULL_TREE
2081 && warn_ctor_dtor_privacy)
2082 cp_warning ("`%#T' only defines a private destructor and has no friends",
2083 t);
2084 }
2085
2086 /* Now for each member function (except for constructors and
2087 destructors), compute where member functions of the same
2088 name reside in base classes. */
2089 if (n_baseclasses != 0
2090 && TREE_VEC_LENGTH (method_vec) > 2)
2091 {
2092 int len = TREE_VEC_LENGTH (method_vec);
2093 tree baselink_vec = make_tree_vec (len);
2094 int any_links = 0;
2095 tree baselink_binfo = build_tree_list (NULL_TREE, TYPE_BINFO (t));
2096
2097 for (i = 2; i < len; i++)
2098 {
2099 TREE_VEC_ELT (baselink_vec, i)
2100 = get_baselinks (baselink_binfo, t, DECL_NAME (TREE_VEC_ELT (method_vec, i)));
2101 if (TREE_VEC_ELT (baselink_vec, i) != 0)
2102 any_links = 1;
2103 }
2104 if (any_links != 0)
2105 CLASSTYPE_BASELINK_VEC (t) = baselink_vec;
2106 else
2107 obstack_free (current_obstack, baselink_vec);
2108 }
2109
2110 /* Now, figure out what any member template specializations were
2111 specializing. */
2112 for (i = 0; i < TREE_VEC_LENGTH (method_vec); ++i)
2113 {
2114 tree fn;
2115 for (fn = TREE_VEC_ELT (method_vec, i);
2116 fn != NULL_TREE;
2117 fn = DECL_CHAIN (fn))
2118 if (DECL_TEMPLATE_SPECIALIZATION (fn))
2119 {
2120 tree f;
2121 tree spec_args;
2122
2123 /* If there is a template, and t uses template parms, we
2124 are dealing with a specialization of a member
2125 template in a template class, and we must grab the
2126 template, rather than the function. */
2127 if (DECL_TI_TEMPLATE (fn) && uses_template_parms (t))
2128 f = DECL_TI_TEMPLATE (fn);
2129 else
2130 f = fn;
2131
2132 /* We want the specialization arguments, which will be the
2133 innermost ones. */
2134 if (DECL_TI_ARGS (f)
2135 && TREE_CODE (DECL_TI_ARGS (f)) == TREE_VEC)
2136 spec_args
2137 = TREE_VEC_ELT (DECL_TI_ARGS (f), 0);
2138 else
2139 spec_args = DECL_TI_ARGS (f);
2140
2141 check_explicit_specialization
2142 (lookup_template_function (DECL_NAME (f), spec_args),
2143 f, 0, 1);
2144
2145 /* Now, the assembler name will be correct for fn, so we
2146 make its RTL. */
2147 DECL_RTL (f) = 0;
2148 make_decl_rtl (f, NULL_PTR, 1);
2149 if (f != fn)
2150 {
2151 DECL_RTL (fn) = 0;
2152 make_decl_rtl (fn, NULL_PTR, 1);
2153 }
2154 }
2155 }
2156
2157 return method_vec;
2158 }
2159
2160 /* Emit error when a duplicate definition of a type is seen. Patch up. */
2161
2162 void
2163 duplicate_tag_error (t)
2164 tree t;
2165 {
2166 cp_error ("redefinition of `%#T'", t);
2167 cp_error_at ("previous definition here", t);
2168
2169 /* Pretend we haven't defined this type. */
2170
2171 /* All of the component_decl's were TREE_CHAINed together in the parser.
2172 finish_struct_methods walks these chains and assembles all methods with
2173 the same base name into DECL_CHAINs. Now we don't need the parser chains
2174 anymore, so we unravel them. */
2175
2176 /* This used to be in finish_struct, but it turns out that the
2177 TREE_CHAIN is used by dbxout_type_methods and perhaps some other
2178 things... */
2179 if (CLASSTYPE_METHOD_VEC (t))
2180 {
2181 tree method_vec = CLASSTYPE_METHOD_VEC (t);
2182 int i, len = TREE_VEC_LENGTH (method_vec);
2183 for (i = 0; i < len; i++)
2184 {
2185 tree unchain = TREE_VEC_ELT (method_vec, i);
2186 while (unchain != NULL_TREE)
2187 {
2188 TREE_CHAIN (unchain) = NULL_TREE;
2189 unchain = DECL_CHAIN (unchain);
2190 }
2191 }
2192 }
2193
2194 if (TYPE_LANG_SPECIFIC (t))
2195 {
2196 tree as_list = CLASSTYPE_AS_LIST (t);
2197 tree binfo = TYPE_BINFO (t);
2198 tree binfo_as_list = CLASSTYPE_BINFO_AS_LIST (t);
2199 int interface_only = CLASSTYPE_INTERFACE_ONLY (t);
2200 int interface_unknown = CLASSTYPE_INTERFACE_UNKNOWN (t);
2201
2202 bzero ((char *) TYPE_LANG_SPECIFIC (t), sizeof (struct lang_type));
2203 BINFO_BASETYPES(binfo) = NULL_TREE;
2204
2205 CLASSTYPE_AS_LIST (t) = as_list;
2206 TYPE_BINFO (t) = binfo;
2207 CLASSTYPE_BINFO_AS_LIST (t) = binfo_as_list;
2208 CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
2209 SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, interface_unknown);
2210 CLASSTYPE_VBASE_SIZE (t) = integer_zero_node;
2211 TYPE_REDEFINED (t) = 1;
2212 }
2213 TYPE_SIZE (t) = NULL_TREE;
2214 TYPE_MODE (t) = VOIDmode;
2215 TYPE_FIELDS (t) = NULL_TREE;
2216 TYPE_METHODS (t) = NULL_TREE;
2217 TYPE_VFIELD (t) = NULL_TREE;
2218 TYPE_CONTEXT (t) = NULL_TREE;
2219 }
2220
2221 /* finish up all new vtables. */
2222
2223 static void
2224 finish_vtbls (binfo, do_self, t)
2225 tree binfo;
2226 int do_self;
2227 tree t;
2228 {
2229 tree binfos = BINFO_BASETYPES (binfo);
2230 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2231
2232 /* Should we use something besides CLASSTYPE_VFIELDS? */
2233 if (do_self && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
2234 {
2235 if (BINFO_NEW_VTABLE_MARKED (binfo))
2236 {
2237 tree decl, context;
2238
2239 decl = BINFO_VTABLE (binfo);
2240 context = DECL_CONTEXT (decl);
2241 DECL_CONTEXT (decl) = 0;
2242 if (write_virtuals >= 0
2243 && DECL_INITIAL (decl) != BINFO_VIRTUALS (binfo))
2244 DECL_INITIAL (decl) = build_nt (CONSTRUCTOR, NULL_TREE,
2245 BINFO_VIRTUALS (binfo));
2246 cp_finish_decl (decl, DECL_INITIAL (decl), NULL_TREE, 0, 0);
2247 DECL_CONTEXT (decl) = context;
2248 }
2249 CLEAR_BINFO_NEW_VTABLE_MARKED (binfo);
2250 }
2251
2252 for (i = 0; i < n_baselinks; i++)
2253 {
2254 tree base_binfo = TREE_VEC_ELT (binfos, i);
2255 int is_not_base_vtable
2256 = i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo));
2257 if (TREE_VIA_VIRTUAL (base_binfo))
2258 {
2259 base_binfo = binfo_member (BINFO_TYPE (base_binfo), CLASSTYPE_VBASECLASSES (t));
2260 }
2261 finish_vtbls (base_binfo, is_not_base_vtable, t);
2262 }
2263 }
2264
2265 /* True if we should override the given BASE_FNDECL with the given
2266 FNDECL. */
2267
2268 static int
2269 overrides (fndecl, base_fndecl)
2270 tree fndecl, base_fndecl;
2271 {
2272 /* Destructors have special names. */
2273 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (base_fndecl))
2274 && DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl)))
2275 return 1;
2276 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (base_fndecl))
2277 || DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl)))
2278 return 0;
2279 if (DECL_NAME (fndecl) == DECL_NAME (base_fndecl))
2280 {
2281 tree types, base_types;
2282 #if 0
2283 retypes = TREE_TYPE (TREE_TYPE (fndecl));
2284 base_retypes = TREE_TYPE (TREE_TYPE (base_fndecl));
2285 #endif
2286 types = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
2287 base_types = TYPE_ARG_TYPES (TREE_TYPE (base_fndecl));
2288 if ((TYPE_READONLY (TREE_TYPE (TREE_VALUE (base_types)))
2289 == TYPE_READONLY (TREE_TYPE (TREE_VALUE (types))))
2290 && compparms (TREE_CHAIN (base_types), TREE_CHAIN (types), 3))
2291 return 1;
2292 }
2293 return 0;
2294 }
2295
2296 static tree
2297 get_class_offset_1 (parent, binfo, context, t, fndecl)
2298 tree parent, binfo, context, t, fndecl;
2299 {
2300 tree binfos = BINFO_BASETYPES (binfo);
2301 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2302 tree rval = NULL_TREE;
2303
2304 if (binfo == parent)
2305 return error_mark_node;
2306
2307 for (i = 0; i < n_baselinks; i++)
2308 {
2309 tree base_binfo = TREE_VEC_ELT (binfos, i);
2310 tree nrval;
2311
2312 if (TREE_VIA_VIRTUAL (base_binfo))
2313 base_binfo = binfo_member (BINFO_TYPE (base_binfo),
2314 CLASSTYPE_VBASECLASSES (t));
2315 nrval = get_class_offset_1 (parent, base_binfo, context, t, fndecl);
2316 /* See if we have a new value */
2317 if (nrval && (nrval != error_mark_node || rval==0))
2318 {
2319 /* Only compare if we have two offsets */
2320 if (rval && rval != error_mark_node
2321 && ! tree_int_cst_equal (nrval, rval))
2322 {
2323 /* Only give error if the two offsets are different */
2324 error ("every virtual function must have a unique final overrider");
2325 cp_error (" found two (or more) `%T' class subobjects in `%T'", context, t);
2326 cp_error (" with virtual `%D' from virtual base class", fndecl);
2327 return rval;
2328 }
2329 rval = nrval;
2330 }
2331
2332 if (rval && BINFO_TYPE (binfo) == context)
2333 {
2334 my_friendly_assert (rval == error_mark_node
2335 || tree_int_cst_equal (rval, BINFO_OFFSET (binfo)), 999);
2336 rval = BINFO_OFFSET (binfo);
2337 }
2338 }
2339 return rval;
2340 }
2341
2342 /* Get the offset to the CONTEXT subobject that is related to the
2343 given BINFO. */
2344
2345 static tree
2346 get_class_offset (context, t, binfo, fndecl)
2347 tree context, t, binfo, fndecl;
2348 {
2349 tree first_binfo = binfo;
2350 tree offset;
2351 int i;
2352
2353 if (context == t)
2354 return integer_zero_node;
2355
2356 if (BINFO_TYPE (binfo) == context)
2357 return BINFO_OFFSET (binfo);
2358
2359 /* Check less derived binfos first. */
2360 while (BINFO_BASETYPES (binfo)
2361 && (i=CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo))) != -1)
2362 {
2363 tree binfos = BINFO_BASETYPES (binfo);
2364 binfo = TREE_VEC_ELT (binfos, i);
2365 if (BINFO_TYPE (binfo) == context)
2366 return BINFO_OFFSET (binfo);
2367 }
2368
2369 /* Ok, not found in the less derived binfos, now check the more
2370 derived binfos. */
2371 offset = get_class_offset_1 (first_binfo, TYPE_BINFO (t), context, t, fndecl);
2372 if (offset==0 || TREE_CODE (offset) != INTEGER_CST)
2373 my_friendly_abort (999); /* we have to find it. */
2374 return offset;
2375 }
2376
2377 /* Skip RTTI information at the front of the virtual list. */
2378
2379 unsigned HOST_WIDE_INT
2380 skip_rtti_stuff (virtuals)
2381 tree *virtuals;
2382 {
2383 int n;
2384
2385 n = 0;
2386 if (*virtuals)
2387 {
2388 /* We always reserve a slot for the offset/tdesc entry. */
2389 ++n;
2390 *virtuals = TREE_CHAIN (*virtuals);
2391 }
2392 if (flag_vtable_thunks && *virtuals)
2393 {
2394 /* The second slot is reserved for the tdesc pointer when thunks
2395 are used. */
2396 ++n;
2397 *virtuals = TREE_CHAIN (*virtuals);
2398 }
2399 return n;
2400 }
2401
2402 static void
2403 modify_one_vtable (binfo, t, fndecl, pfn)
2404 tree binfo, t, fndecl, pfn;
2405 {
2406 tree virtuals = BINFO_VIRTUALS (binfo);
2407 unsigned HOST_WIDE_INT n;
2408
2409 /* update rtti entry */
2410 if (flag_rtti)
2411 {
2412 if (binfo == TYPE_BINFO (t))
2413 {
2414 if (! BINFO_NEW_VTABLE_MARKED (binfo))
2415 build_vtable (TYPE_BINFO (DECL_CONTEXT (CLASSTYPE_VFIELD (t))), t);
2416 }
2417 else
2418 {
2419 if (! BINFO_NEW_VTABLE_MARKED (binfo))
2420 prepare_fresh_vtable (binfo, t);
2421 }
2422 }
2423 if (fndecl == NULL_TREE)
2424 return;
2425
2426 n = skip_rtti_stuff (&virtuals);
2427
2428 while (virtuals)
2429 {
2430 tree current_fndecl = TREE_VALUE (virtuals);
2431 current_fndecl = FNADDR_FROM_VTABLE_ENTRY (current_fndecl);
2432 current_fndecl = TREE_OPERAND (current_fndecl, 0);
2433 if (current_fndecl && overrides (fndecl, current_fndecl))
2434 {
2435 tree base_offset, offset;
2436 tree context = DECL_CLASS_CONTEXT (fndecl);
2437 tree vfield = CLASSTYPE_VFIELD (t);
2438 tree this_offset;
2439
2440 offset = get_class_offset (context, t, binfo, fndecl);
2441
2442 /* Find the right offset for the this pointer based on the
2443 base class we just found. We have to take into
2444 consideration the virtual base class pointers that we
2445 stick in before the virtual function table pointer.
2446
2447 Also, we want just the delta between the most base class
2448 that we derived this vfield from and us. */
2449 base_offset = size_binop (PLUS_EXPR,
2450 get_derived_offset (binfo, DECL_CONTEXT (current_fndecl)),
2451 BINFO_OFFSET (binfo));
2452 this_offset = size_binop (MINUS_EXPR, offset, base_offset);
2453
2454 /* Make sure we can modify the derived association with immunity. */
2455 if (TREE_USED (binfo))
2456 my_friendly_assert (0, 999);
2457
2458 if (binfo == TYPE_BINFO (t))
2459 {
2460 /* In this case, it is *type*'s vtable we are modifying.
2461 We start with the approximation that it's vtable is that
2462 of the immediate base class. */
2463 if (! BINFO_NEW_VTABLE_MARKED (binfo))
2464 build_vtable (TYPE_BINFO (DECL_CONTEXT (vfield)), t);
2465 }
2466 else
2467 {
2468 /* This is our very own copy of `basetype' to play with.
2469 Later, we will fill in all the virtual functions
2470 that override the virtual functions in these base classes
2471 which are not defined by the current type. */
2472 if (! BINFO_NEW_VTABLE_MARKED (binfo))
2473 prepare_fresh_vtable (binfo, t);
2474 }
2475
2476 #ifdef NOTQUITE
2477 cp_warning ("in %D", DECL_NAME (BINFO_VTABLE (binfo)));
2478 #endif
2479 modify_vtable_entry (get_vtable_entry_n (BINFO_VIRTUALS (binfo), n),
2480 build_vtable_entry (this_offset, pfn),
2481 fndecl);
2482 }
2483 ++n;
2484 virtuals = TREE_CHAIN (virtuals);
2485 }
2486 }
2487
2488 /* These are the ones that are not through virtual base classes. */
2489
2490 static void
2491 modify_all_direct_vtables (binfo, do_self, t, fndecl, pfn)
2492 tree binfo;
2493 int do_self;
2494 tree t, fndecl, pfn;
2495 {
2496 tree binfos = BINFO_BASETYPES (binfo);
2497 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2498
2499 /* Should we use something besides CLASSTYPE_VFIELDS? */
2500 if (do_self && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
2501 {
2502 modify_one_vtable (binfo, t, fndecl, pfn);
2503 }
2504
2505 for (i = 0; i < n_baselinks; i++)
2506 {
2507 tree base_binfo = TREE_VEC_ELT (binfos, i);
2508 int is_not_base_vtable
2509 = i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo));
2510 if (! TREE_VIA_VIRTUAL (base_binfo))
2511 modify_all_direct_vtables (base_binfo, is_not_base_vtable, t, fndecl, pfn);
2512 }
2513 }
2514
2515 /* Fixup all the delta entries in this one vtable that need updating. */
2516
2517 static void
2518 fixup_vtable_deltas1 (binfo, t)
2519 tree binfo, t;
2520 {
2521 tree virtuals = BINFO_VIRTUALS (binfo);
2522 unsigned HOST_WIDE_INT n;
2523
2524 n = skip_rtti_stuff (&virtuals);
2525
2526 while (virtuals)
2527 {
2528 tree fndecl = TREE_VALUE (virtuals);
2529 tree pfn = FNADDR_FROM_VTABLE_ENTRY (fndecl);
2530 tree delta = DELTA_FROM_VTABLE_ENTRY (fndecl);
2531 fndecl = TREE_OPERAND (pfn, 0);
2532 if (fndecl)
2533 {
2534 tree base_offset, offset;
2535 tree context = DECL_CLASS_CONTEXT (fndecl);
2536 tree vfield = CLASSTYPE_VFIELD (t);
2537 tree this_offset;
2538
2539 offset = get_class_offset (context, t, binfo, fndecl);
2540
2541 /* Find the right offset for the this pointer based on the
2542 base class we just found. We have to take into
2543 consideration the virtual base class pointers that we
2544 stick in before the virtual function table pointer.
2545
2546 Also, we want just the delta between the most base class
2547 that we derived this vfield from and us. */
2548 base_offset = size_binop (PLUS_EXPR,
2549 get_derived_offset (binfo, DECL_CONTEXT (fndecl)),
2550 BINFO_OFFSET (binfo));
2551 this_offset = size_binop (MINUS_EXPR, offset, base_offset);
2552
2553 if (! tree_int_cst_equal (this_offset, delta))
2554 {
2555 /* Make sure we can modify the derived association with immunity. */
2556 if (TREE_USED (binfo))
2557 my_friendly_assert (0, 999);
2558
2559 if (binfo == TYPE_BINFO (t))
2560 {
2561 /* In this case, it is *type*'s vtable we are modifying.
2562 We start with the approximation that it's vtable is that
2563 of the immediate base class. */
2564 if (! BINFO_NEW_VTABLE_MARKED (binfo))
2565 build_vtable (TYPE_BINFO (DECL_CONTEXT (vfield)), t);
2566 }
2567 else
2568 {
2569 /* This is our very own copy of `basetype' to play with.
2570 Later, we will fill in all the virtual functions
2571 that override the virtual functions in these base classes
2572 which are not defined by the current type. */
2573 if (! BINFO_NEW_VTABLE_MARKED (binfo))
2574 prepare_fresh_vtable (binfo, t);
2575 }
2576
2577 modify_vtable_entry (get_vtable_entry_n (BINFO_VIRTUALS (binfo), n),
2578 build_vtable_entry (this_offset, pfn),
2579 fndecl);
2580 }
2581 }
2582 ++n;
2583 virtuals = TREE_CHAIN (virtuals);
2584 }
2585 }
2586
2587 /* Fixup all the delta entries in all the direct vtables that need updating.
2588 This happens when we have non-overridden virtual functions from a
2589 virtual base class, that are at a different offset, in the new
2590 hierarchy, because the layout of the virtual bases has changed. */
2591
2592 static void
2593 fixup_vtable_deltas (binfo, init_self, t)
2594 tree binfo;
2595 int init_self;
2596 tree t;
2597 {
2598 tree binfos = BINFO_BASETYPES (binfo);
2599 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2600
2601 for (i = 0; i < n_baselinks; i++)
2602 {
2603 tree base_binfo = TREE_VEC_ELT (binfos, i);
2604 int is_not_base_vtable
2605 = i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo));
2606 if (! TREE_VIA_VIRTUAL (base_binfo))
2607 fixup_vtable_deltas (base_binfo, is_not_base_vtable, t);
2608 }
2609 /* Should we use something besides CLASSTYPE_VFIELDS? */
2610 if (init_self && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
2611 {
2612 fixup_vtable_deltas1 (binfo, t);
2613 }
2614 }
2615
2616 /* These are the ones that are through virtual base classes. */
2617
2618 static void
2619 modify_all_indirect_vtables (binfo, do_self, via_virtual, t, fndecl, pfn)
2620 tree binfo;
2621 int do_self, via_virtual;
2622 tree t, fndecl, pfn;
2623 {
2624 tree binfos = BINFO_BASETYPES (binfo);
2625 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2626
2627 /* Should we use something besides CLASSTYPE_VFIELDS? */
2628 if (do_self && via_virtual && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
2629 {
2630 modify_one_vtable (binfo, t, fndecl, pfn);
2631 }
2632
2633 for (i = 0; i < n_baselinks; i++)
2634 {
2635 tree base_binfo = TREE_VEC_ELT (binfos, i);
2636 int is_not_base_vtable
2637 = i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo));
2638 if (TREE_VIA_VIRTUAL (base_binfo))
2639 {
2640 via_virtual = 1;
2641 base_binfo = binfo_member (BINFO_TYPE (base_binfo), CLASSTYPE_VBASECLASSES (t));
2642 }
2643 modify_all_indirect_vtables (base_binfo, is_not_base_vtable, via_virtual, t, fndecl, pfn);
2644 }
2645 }
2646
2647 static void
2648 modify_all_vtables (t, fndecl, vfn)
2649 tree t, fndecl, vfn;
2650 {
2651 /* Do these first, so that we will make use of any non-virtual class's
2652 vtable, over a virtual classes vtable. */
2653 modify_all_direct_vtables (TYPE_BINFO (t), 1, t, fndecl, vfn);
2654 if (TYPE_USES_VIRTUAL_BASECLASSES (t))
2655 modify_all_indirect_vtables (TYPE_BINFO (t), 1, 0, t, fndecl, vfn);
2656 }
2657
2658 /* Here, we already know that they match in every respect.
2659 All we have to check is where they had their declarations. */
2660
2661 static int
2662 strictly_overrides (fndecl1, fndecl2)
2663 tree fndecl1, fndecl2;
2664 {
2665 int distance = get_base_distance (DECL_CLASS_CONTEXT (fndecl2),
2666 DECL_CLASS_CONTEXT (fndecl1),
2667 0, (tree *)0);
2668 if (distance == -2 || distance > 0)
2669 return 1;
2670 return 0;
2671 }
2672
2673 /* Merge overrides for one vtable.
2674 If we want to merge in same function, we are fine.
2675 else
2676 if one has a DECL_CLASS_CONTEXT that is a parent of the
2677 other, than choose the more derived one
2678 else
2679 potentially ill-formed (see 10.3 [class.virtual])
2680 we have to check later to see if there was an
2681 override in this class. If there was ok, if not
2682 then it is ill-formed. (mrs)
2683
2684 We take special care to reuse a vtable, if we can. */
2685
2686 static void
2687 override_one_vtable (binfo, old, t)
2688 tree binfo, old, t;
2689 {
2690 tree virtuals = BINFO_VIRTUALS (binfo);
2691 tree old_virtuals = BINFO_VIRTUALS (old);
2692 enum { REUSE_NEW, REUSE_OLD, UNDECIDED, NEITHER } choose = UNDECIDED;
2693
2694 /* If we have already committed to modifying it, then don't try and
2695 reuse another vtable. */
2696 if (BINFO_NEW_VTABLE_MARKED (binfo))
2697 choose = NEITHER;
2698
2699 skip_rtti_stuff (&virtuals);
2700 skip_rtti_stuff (&old_virtuals);
2701
2702 while (virtuals)
2703 {
2704 tree fndecl = TREE_VALUE (virtuals);
2705 tree old_fndecl = TREE_VALUE (old_virtuals);
2706 fndecl = FNADDR_FROM_VTABLE_ENTRY (fndecl);
2707 old_fndecl = FNADDR_FROM_VTABLE_ENTRY (old_fndecl);
2708 fndecl = TREE_OPERAND (fndecl, 0);
2709 old_fndecl = TREE_OPERAND (old_fndecl, 0);
2710 /* First check to see if they are the same. */
2711 if (DECL_ASSEMBLER_NAME (fndecl) == DECL_ASSEMBLER_NAME (old_fndecl))
2712 {
2713 /* No need to do anything. */
2714 }
2715 else if (strictly_overrides (fndecl, old_fndecl))
2716 {
2717 if (choose == UNDECIDED)
2718 choose = REUSE_NEW;
2719 else if (choose == REUSE_OLD)
2720 {
2721 choose = NEITHER;
2722 if (! BINFO_NEW_VTABLE_MARKED (binfo))
2723 {
2724 prepare_fresh_vtable (binfo, t);
2725 override_one_vtable (binfo, old, t);
2726 return;
2727 }
2728 }
2729 }
2730 else if (strictly_overrides (old_fndecl, fndecl))
2731 {
2732 if (choose == UNDECIDED)
2733 choose = REUSE_OLD;
2734 else if (choose == REUSE_NEW)
2735 {
2736 choose = NEITHER;
2737 if (! BINFO_NEW_VTABLE_MARKED (binfo))
2738 {
2739 prepare_fresh_vtable (binfo, t);
2740 override_one_vtable (binfo, old, t);
2741 return;
2742 }
2743 TREE_VALUE (virtuals) = TREE_VALUE (old_virtuals);
2744 }
2745 else if (choose == NEITHER)
2746 {
2747 TREE_VALUE (virtuals) = TREE_VALUE (old_virtuals);
2748 }
2749 }
2750 else
2751 {
2752 choose = NEITHER;
2753 if (! BINFO_NEW_VTABLE_MARKED (binfo))
2754 {
2755 prepare_fresh_vtable (binfo, t);
2756 override_one_vtable (binfo, old, t);
2757 return;
2758 }
2759 {
2760 /* This MUST be overridden, or the class is ill-formed. */
2761 /* For now, we just make it abstract. */
2762 tree fndecl = TREE_OPERAND (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals)), 0);
2763 tree vfn;
2764
2765 fndecl = copy_node (fndecl);
2766 copy_lang_decl (fndecl);
2767 DECL_ABSTRACT_VIRTUAL_P (fndecl) = 1;
2768 /* Make sure we search for it later. */
2769 if (! CLASSTYPE_ABSTRACT_VIRTUALS (t))
2770 CLASSTYPE_ABSTRACT_VIRTUALS (t) = error_mark_node;
2771
2772 vfn = build1 (ADDR_EXPR, vfunc_ptr_type_node, fndecl);
2773 TREE_CONSTANT (vfn) = 1;
2774
2775 /* We can use integer_zero_node, as we will will core dump
2776 if this is used anyway. */
2777 TREE_VALUE (virtuals) = build_vtable_entry (integer_zero_node, vfn);
2778 }
2779 }
2780 virtuals = TREE_CHAIN (virtuals);
2781 old_virtuals = TREE_CHAIN (old_virtuals);
2782 }
2783
2784 /* Let's reuse the old vtable. */
2785 if (choose == REUSE_OLD)
2786 {
2787 BINFO_VTABLE (binfo) = BINFO_VTABLE (old);
2788 BINFO_VIRTUALS (binfo) = BINFO_VIRTUALS (old);
2789 }
2790 }
2791
2792 /* Merge in overrides for virtual bases.
2793 BINFO is the hierarchy we want to modify, and OLD has the potential
2794 overrides. */
2795
2796 static void
2797 merge_overrides (binfo, old, do_self, t)
2798 tree binfo, old;
2799 int do_self;
2800 tree t;
2801 {
2802 tree binfos = BINFO_BASETYPES (binfo);
2803 tree old_binfos = BINFO_BASETYPES (old);
2804 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2805
2806 /* Should we use something besides CLASSTYPE_VFIELDS? */
2807 if (do_self && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
2808 {
2809 override_one_vtable (binfo, old, t);
2810 }
2811
2812 for (i = 0; i < n_baselinks; i++)
2813 {
2814 tree base_binfo = TREE_VEC_ELT (binfos, i);
2815 tree old_base_binfo = TREE_VEC_ELT (old_binfos, i);
2816 int is_not_base_vtable
2817 = i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo));
2818 if (! TREE_VIA_VIRTUAL (base_binfo))
2819 merge_overrides (base_binfo, old_base_binfo, is_not_base_vtable, t);
2820 }
2821 }
2822
2823 /* Get the base virtual function declarations in T that are either
2824 overridden or hidden by FNDECL as a list. We set TREE_PURPOSE with
2825 the overrider/hider. */
2826
2827 static tree
2828 get_basefndecls (fndecl, t)
2829 tree fndecl, t;
2830 {
2831 tree methods = TYPE_METHODS (t);
2832 tree base_fndecls = NULL_TREE;
2833 tree binfos = BINFO_BASETYPES (TYPE_BINFO (t));
2834 int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2835
2836 while (methods)
2837 {
2838 if (TREE_CODE (methods) == FUNCTION_DECL
2839 && DECL_VINDEX (methods) != NULL_TREE
2840 && DECL_NAME (fndecl) == DECL_NAME (methods))
2841 base_fndecls = temp_tree_cons (fndecl, methods, base_fndecls);
2842
2843 methods = TREE_CHAIN (methods);
2844 }
2845
2846 if (base_fndecls)
2847 return base_fndecls;
2848
2849 for (i = 0; i < n_baseclasses; i++)
2850 {
2851 tree base_binfo = TREE_VEC_ELT (binfos, i);
2852 tree basetype = BINFO_TYPE (base_binfo);
2853
2854 base_fndecls = chainon (get_basefndecls (fndecl, basetype),
2855 base_fndecls);
2856 }
2857
2858 return base_fndecls;
2859 }
2860
2861 /* Mark the functions that have been hidden with their overriders.
2862 Since we start out with all functions already marked with a hider,
2863 no need to mark functions that are just hidden. */
2864
2865 static void
2866 mark_overriders (fndecl, base_fndecls)
2867 tree fndecl, base_fndecls;
2868 {
2869 while (base_fndecls)
2870 {
2871 if (overrides (TREE_VALUE (base_fndecls), fndecl))
2872 TREE_PURPOSE (base_fndecls) = fndecl;
2873
2874 base_fndecls = TREE_CHAIN (base_fndecls);
2875 }
2876 }
2877
2878 /* If this declaration supersedes the declaration of
2879 a method declared virtual in the base class, then
2880 mark this field as being virtual as well. */
2881
2882 static void
2883 check_for_override (decl, ctype)
2884 tree decl, ctype;
2885 {
2886 tree binfos = BINFO_BASETYPES (TYPE_BINFO (ctype));
2887 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2888 int virtualp = DECL_VIRTUAL_P (decl);
2889
2890 for (i = 0; i < n_baselinks; i++)
2891 {
2892 tree base_binfo = TREE_VEC_ELT (binfos, i);
2893 if (TYPE_VIRTUAL_P (BINFO_TYPE (base_binfo))
2894 || flag_all_virtual == 1)
2895 {
2896 tree tmp = get_matching_virtual
2897 (base_binfo, decl,
2898 DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl)));
2899 if (tmp)
2900 {
2901 /* If this function overrides some virtual in some base
2902 class, then the function itself is also necessarily
2903 virtual, even if the user didn't explicitly say so. */
2904 DECL_VIRTUAL_P (decl) = 1;
2905
2906 /* The TMP we really want is the one from the deepest
2907 baseclass on this path, taking care not to
2908 duplicate if we have already found it (via another
2909 path to its virtual baseclass. */
2910 if (TREE_CODE (TREE_TYPE (decl)) == FUNCTION_TYPE)
2911 {
2912 cp_error_at ("method `%D' may not be declared static",
2913 decl);
2914 cp_error_at ("(since `%D' declared virtual in base class.)",
2915 tmp);
2916 break;
2917 }
2918 virtualp = 1;
2919
2920 #if 0 /* The signature of an overriding function is not changed. */
2921 {
2922 /* The argument types may have changed... */
2923 tree type = TREE_TYPE (decl);
2924 tree argtypes = TYPE_ARG_TYPES (type);
2925 tree base_variant = TREE_TYPE (TREE_VALUE (argtypes));
2926 tree raises = TYPE_RAISES_EXCEPTIONS (type);
2927
2928 argtypes = commonparms (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (tmp))),
2929 TREE_CHAIN (argtypes));
2930 /* But the return type has not. */
2931 type = build_cplus_method_type (base_variant, TREE_TYPE (type), argtypes);
2932 if (raises)
2933 type = build_exception_variant (type, raises);
2934 TREE_TYPE (decl) = type;
2935 }
2936 #endif
2937 DECL_VINDEX (decl)
2938 = tree_cons (NULL_TREE, tmp, DECL_VINDEX (decl));
2939 break;
2940 }
2941 }
2942 }
2943 if (virtualp)
2944 {
2945 if (DECL_VINDEX (decl) == NULL_TREE)
2946 DECL_VINDEX (decl) = error_mark_node;
2947 IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)) = 1;
2948 }
2949 }
2950
2951 /* Warn about hidden virtual functions that are not overridden in t.
2952 We know that constructors and destructors don't apply. */
2953
2954 void
2955 warn_hidden (t)
2956 tree t;
2957 {
2958 tree method_vec = CLASSTYPE_METHOD_VEC (t);
2959 int n_methods = method_vec ? TREE_VEC_LENGTH (method_vec) : 0;
2960 int i;
2961
2962 /* We go through each separately named virtual function. */
2963 for (i = 2; i < n_methods; ++i)
2964 {
2965 tree fndecl = TREE_VEC_ELT (method_vec, i);
2966
2967 tree base_fndecls = NULL_TREE;
2968 tree binfos = BINFO_BASETYPES (TYPE_BINFO (t));
2969 int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2970
2971 if (DECL_VINDEX (fndecl) == NULL_TREE)
2972 continue;
2973
2974 /* First we get a list of all possible functions that might be
2975 hidden from each base class. */
2976 for (i = 0; i < n_baseclasses; i++)
2977 {
2978 tree base_binfo = TREE_VEC_ELT (binfos, i);
2979 tree basetype = BINFO_TYPE (base_binfo);
2980
2981 base_fndecls = chainon (get_basefndecls (fndecl, basetype),
2982 base_fndecls);
2983 }
2984
2985 if (TREE_CHAIN (fndecl)
2986 && DECL_NAME (TREE_CHAIN (fndecl)) == DECL_NAME (fndecl))
2987 fndecl = TREE_CHAIN (fndecl);
2988 else
2989 fndecl = NULL_TREE;
2990
2991 /* ...then mark up all the base functions with overriders, preferring
2992 overriders to hiders. */
2993 if (base_fndecls)
2994 while (fndecl)
2995 {
2996 mark_overriders (fndecl, base_fndecls);
2997
2998 if (TREE_CHAIN (fndecl)
2999 && DECL_NAME (TREE_CHAIN (fndecl)) == DECL_NAME (fndecl))
3000 fndecl = TREE_CHAIN (fndecl);
3001 else
3002 fndecl = NULL_TREE;
3003 }
3004
3005 /* Now give a warning for all base functions without overriders,
3006 as they are hidden. */
3007 while (base_fndecls)
3008 {
3009 if (! overrides (TREE_VALUE (base_fndecls),
3010 TREE_PURPOSE (base_fndecls)))
3011 {
3012 /* Here we know it is a hider, and no overrider exists. */
3013 cp_warning_at ("`%D' was hidden", TREE_VALUE (base_fndecls));
3014 cp_warning_at (" by `%D'", TREE_PURPOSE (base_fndecls));
3015 }
3016
3017 base_fndecls = TREE_CHAIN (base_fndecls);
3018 }
3019 }
3020 }
3021
3022 /* Check for things that are invalid. There are probably plenty of other
3023 things we should check for also. */
3024
3025 static void
3026 finish_struct_anon (t)
3027 tree t;
3028 {
3029 tree field;
3030 for (field = TYPE_FIELDS (t); field; field = TREE_CHAIN (field))
3031 {
3032 if (TREE_STATIC (field))
3033 continue;
3034 if (TREE_CODE (field) != FIELD_DECL)
3035 continue;
3036
3037 if (DECL_NAME (field) == NULL_TREE
3038 && TREE_CODE (TREE_TYPE (field)) == UNION_TYPE)
3039 {
3040 tree* uelt = &TYPE_FIELDS (TREE_TYPE (field));
3041 for (; *uelt; uelt = &TREE_CHAIN (*uelt))
3042 {
3043 if (TREE_CODE (*uelt) != FIELD_DECL)
3044 continue;
3045
3046 if (TREE_PRIVATE (*uelt))
3047 cp_pedwarn_at ("private member `%#D' in anonymous union",
3048 *uelt);
3049 else if (TREE_PROTECTED (*uelt))
3050 cp_pedwarn_at ("protected member `%#D' in anonymous union",
3051 *uelt);
3052
3053 TREE_PRIVATE (*uelt) = TREE_PRIVATE (field);
3054 TREE_PROTECTED (*uelt) = TREE_PROTECTED (field);
3055 }
3056 }
3057 }
3058 }
3059
3060 extern int interface_only, interface_unknown;
3061
3062 /* Create a RECORD_TYPE or UNION_TYPE node for a C struct or union declaration
3063 (or C++ class declaration).
3064
3065 For C++, we must handle the building of derived classes.
3066 Also, C++ allows static class members. The way that this is
3067 handled is to keep the field name where it is (as the DECL_NAME
3068 of the field), and place the overloaded decl in the DECL_FIELD_BITPOS
3069 of the field. layout_record and layout_union will know about this.
3070
3071 More C++ hair: inline functions have text in their
3072 DECL_PENDING_INLINE_INFO nodes which must somehow be parsed into
3073 meaningful tree structure. After the struct has been laid out, set
3074 things up so that this can happen.
3075
3076 And still more: virtual functions. In the case of single inheritance,
3077 when a new virtual function is seen which redefines a virtual function
3078 from the base class, the new virtual function is placed into
3079 the virtual function table at exactly the same address that
3080 it had in the base class. When this is extended to multiple
3081 inheritance, the same thing happens, except that multiple virtual
3082 function tables must be maintained. The first virtual function
3083 table is treated in exactly the same way as in the case of single
3084 inheritance. Additional virtual function tables have different
3085 DELTAs, which tell how to adjust `this' to point to the right thing.
3086
3087 LIST_OF_FIELDLISTS is just that. The elements of the list are
3088 TREE_LIST elements, whose TREE_PURPOSE field tells what access
3089 the list has, and the TREE_VALUE slot gives the actual fields.
3090
3091 ATTRIBUTES is the set of decl attributes to be applied, if any.
3092
3093 If flag_all_virtual == 1, then we lay all functions into
3094 the virtual function table, as though they were declared
3095 virtual. Constructors do not lay down in the virtual function table.
3096
3097 If flag_all_virtual == 2, then we lay all functions into
3098 the virtual function table, such that virtual functions
3099 occupy a space by themselves, and then all functions
3100 of the class occupy a space by themselves. This is illustrated
3101 in the following diagram:
3102
3103 class A; class B : A;
3104
3105 Class A's vtbl: Class B's vtbl:
3106 --------------------------------------------------------------------
3107 | A's virtual functions| | B's virtual functions |
3108 | | | (may inherit some from A). |
3109 --------------------------------------------------------------------
3110 | All of A's functions | | All of A's functions |
3111 | (such as a->A::f). | | (such as b->A::f) |
3112 --------------------------------------------------------------------
3113 | B's new virtual functions |
3114 | (not defined in A.) |
3115 -------------------------------
3116 | All of B's functions |
3117 | (such as b->B::f) |
3118 -------------------------------
3119
3120 this allows the program to make references to any function, virtual
3121 or otherwise in a type-consistent manner. */
3122
3123 tree
3124 finish_struct_1 (t, warn_anon)
3125 tree t;
3126 int warn_anon;
3127 {
3128 int old;
3129 tree name = TYPE_IDENTIFIER (t);
3130 enum tree_code code = TREE_CODE (t);
3131 tree fields = TYPE_FIELDS (t);
3132 tree fn_fields = TYPE_METHODS (t);
3133 tree x, last_x, method_vec;
3134 int all_virtual;
3135 int has_virtual;
3136 int max_has_virtual;
3137 tree pending_virtuals = NULL_TREE;
3138 tree pending_hard_virtuals = NULL_TREE;
3139 tree abstract_virtuals = NULL_TREE;
3140 tree vfield;
3141 tree vfields;
3142 int cant_have_default_ctor;
3143 int cant_have_const_ctor;
3144 int no_const_asn_ref;
3145
3146 /* The index of the first base class which has virtual
3147 functions. Only applied to non-virtual baseclasses. */
3148 int first_vfn_base_index;
3149
3150 int n_baseclasses;
3151 int any_default_members = 0;
3152 int const_sans_init = 0;
3153 int ref_sans_init = 0;
3154 int nonprivate_method = 0;
3155 tree t_binfo = TYPE_BINFO (t);
3156 tree access_decls = NULL_TREE;
3157 int aggregate = 1;
3158 int empty = 1;
3159 int has_pointers = 0;
3160
3161 if (warn_anon && code != UNION_TYPE && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t)))
3162 pedwarn ("anonymous class type not used to declare any objects");
3163
3164 if (TYPE_SIZE (t))
3165 {
3166 if (IS_AGGR_TYPE (t))
3167 cp_error ("redefinition of `%#T'", t);
3168 else
3169 my_friendly_abort (172);
3170 popclass (0);
3171 return t;
3172 }
3173
3174 GNU_xref_decl (current_function_decl, t);
3175
3176 /* If this type was previously laid out as a forward reference,
3177 make sure we lay it out again. */
3178
3179 TYPE_SIZE (t) = NULL_TREE;
3180 CLASSTYPE_GOT_SEMICOLON (t) = 0;
3181
3182 #if 0
3183 /* This is in general too late to do this. I moved the main case up to
3184 left_curly, what else needs to move? */
3185 if (! IS_SIGNATURE (t))
3186 {
3187 my_friendly_assert (CLASSTYPE_INTERFACE_ONLY (t) == interface_only, 999);
3188 my_friendly_assert (CLASSTYPE_INTERFACE_KNOWN (t) == ! interface_unknown, 999);
3189 }
3190 #endif
3191
3192 #if 0
3193 if (flag_rtti)
3194 build_t_desc (t, 0);
3195 #endif
3196
3197 TYPE_BINFO (t) = NULL_TREE;
3198
3199 old = suspend_momentary ();
3200
3201 /* Install struct as DECL_FIELD_CONTEXT of each field decl.
3202 Also process specified field sizes.
3203 Set DECL_FIELD_SIZE to the specified size, or 0 if none specified.
3204 The specified size is found in the DECL_INITIAL.
3205 Store 0 there, except for ": 0" fields (so we can find them
3206 and delete them, below). */
3207
3208 if (t_binfo && BINFO_BASETYPES (t_binfo))
3209 n_baseclasses = TREE_VEC_LENGTH (BINFO_BASETYPES (t_binfo));
3210 else
3211 n_baseclasses = 0;
3212
3213 if (n_baseclasses > 0)
3214 {
3215 struct base_info base_info;
3216
3217 /* If using multiple inheritance, this may cause variants of our
3218 basetypes to be used (instead of their canonical forms). */
3219 tree vf = layout_basetypes (t, BINFO_BASETYPES (t_binfo));
3220 last_x = tree_last (vf);
3221 fields = chainon (vf, fields);
3222
3223 first_vfn_base_index = finish_base_struct (t, &base_info, t_binfo);
3224 /* Remember where we got our vfield from. */
3225 CLASSTYPE_VFIELD_PARENT (t) = first_vfn_base_index;
3226 has_virtual = base_info.has_virtual;
3227 max_has_virtual = base_info.max_has_virtual;
3228 CLASSTYPE_N_SUPERCLASSES (t) += base_info.n_ancestors;
3229 vfield = base_info.vfield;
3230 vfields = base_info.vfields;
3231 CLASSTYPE_RTTI (t) = base_info.rtti;
3232 cant_have_default_ctor = base_info.cant_have_default_ctor;
3233 cant_have_const_ctor = base_info.cant_have_const_ctor;
3234 no_const_asn_ref = base_info.no_const_asn_ref;
3235 n_baseclasses = TREE_VEC_LENGTH (BINFO_BASETYPES (t_binfo));
3236 aggregate = 0;
3237 }
3238 else
3239 {
3240 first_vfn_base_index = -1;
3241 has_virtual = 0;
3242 max_has_virtual = has_virtual;
3243 vfield = NULL_TREE;
3244 vfields = NULL_TREE;
3245 CLASSTYPE_RTTI (t) = NULL_TREE;
3246 last_x = NULL_TREE;
3247 cant_have_default_ctor = 0;
3248 cant_have_const_ctor = 0;
3249 no_const_asn_ref = 0;
3250 }
3251
3252 #if 0
3253 /* Both of these should be done before now. */
3254 if (write_virtuals == 3 && CLASSTYPE_INTERFACE_KNOWN (t)
3255 && ! IS_SIGNATURE (t))
3256 {
3257 my_friendly_assert (CLASSTYPE_INTERFACE_ONLY (t) == interface_only, 999);
3258 my_friendly_assert (CLASSTYPE_VTABLE_NEEDS_WRITING (t) == ! interface_only, 999);
3259 }
3260 #endif
3261
3262 /* The three of these are approximations which may later be
3263 modified. Needed at this point to make add_virtual_function
3264 and modify_vtable_entries work. */
3265 TREE_CHAIN (t_binfo) = TYPE_BINFO (t);
3266 TYPE_BINFO (t) = t_binfo;
3267 CLASSTYPE_VFIELDS (t) = vfields;
3268 CLASSTYPE_VFIELD (t) = vfield;
3269
3270 if (IS_SIGNATURE (t))
3271 all_virtual = 0;
3272 else if (flag_all_virtual == 1 && TYPE_OVERLOADS_METHOD_CALL_EXPR (t))
3273 all_virtual = 1;
3274 else
3275 all_virtual = 0;
3276
3277 for (x = TYPE_METHODS (t); x; x = TREE_CHAIN (x))
3278 {
3279 GNU_xref_member (current_class_name, x);
3280
3281 nonprivate_method |= ! TREE_PRIVATE (x);
3282
3283 /* If this was an evil function, don't keep it in class. */
3284 if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (x)))
3285 continue;
3286
3287 DECL_CLASS_CONTEXT (x) = t;
3288
3289 /* Do both of these, even though they're in the same union;
3290 if the insn `r' member and the size `i' member are
3291 different sizes, as on the alpha, the larger of the two
3292 will end up with garbage in it. */
3293 DECL_SAVED_INSNS (x) = NULL_RTX;
3294 DECL_FIELD_SIZE (x) = 0;
3295
3296 check_for_override (x, t);
3297 if (DECL_ABSTRACT_VIRTUAL_P (x) && ! DECL_VINDEX (x))
3298 cp_error_at ("initializer specified for non-virtual method `%D'", x);
3299
3300 /* The name of the field is the original field name
3301 Save this in auxiliary field for later overloading. */
3302 if (DECL_VINDEX (x)
3303 || (all_virtual == 1 && ! DECL_CONSTRUCTOR_P (x)))
3304 {
3305 add_virtual_function (&pending_virtuals, &pending_hard_virtuals,
3306 &has_virtual, x, t);
3307 if (DECL_ABSTRACT_VIRTUAL_P (x))
3308 abstract_virtuals = tree_cons (NULL_TREE, x, abstract_virtuals);
3309 #if 0
3310 /* XXX Why did I comment this out? (jason) */
3311 else
3312 TREE_USED (x) = 1;
3313 #endif
3314 }
3315 }
3316
3317 for (x = TYPE_FIELDS (t); x; x = TREE_CHAIN (x))
3318 {
3319 GNU_xref_member (current_class_name, x);
3320
3321 if (TREE_CODE (x) == FIELD_DECL)
3322 {
3323 DECL_PACKED (x) |= TYPE_PACKED (t);
3324 empty = 0;
3325 }
3326
3327 /* Handle access declarations. */
3328 if (TREE_CODE (x) == USING_DECL)
3329 {
3330 tree ctype = DECL_INITIAL (x);
3331 tree sname = DECL_NAME (x);
3332 tree access
3333 = TREE_PRIVATE (x) ? access_private_node
3334 : TREE_PROTECTED (x) ? access_protected_node
3335 : access_public_node;
3336 tree fdecl, binfo;
3337
3338 if (last_x)
3339 TREE_CHAIN (last_x) = TREE_CHAIN (x);
3340 else
3341 fields = TREE_CHAIN (x);
3342
3343 binfo = binfo_or_else (ctype, t);
3344 if (! binfo)
3345 continue;
3346
3347 if (sname == constructor_name (ctype)
3348 || sname == constructor_name_full (ctype))
3349 cp_error_at ("using-declaration for constructor", x);
3350
3351 fdecl = lookup_field (binfo, sname, 0, 0);
3352 if (! fdecl)
3353 fdecl = lookup_fnfields (binfo, sname, 0);
3354
3355 if (fdecl)
3356 access_decls = scratch_tree_cons (access, fdecl, access_decls);
3357 else
3358 cp_error_at ("no members matching `%D' in `%#T'", x, ctype);
3359 continue;
3360 }
3361
3362 last_x = x;
3363
3364 if (TREE_CODE (x) == TYPE_DECL)
3365 continue;
3366
3367 /* If we've gotten this far, it's a data member, possibly static,
3368 or an enumerator. */
3369
3370 DECL_FIELD_CONTEXT (x) = t;
3371
3372 /* ``A local class cannot have static data members.'' ARM 9.4 */
3373 if (current_function_decl && TREE_STATIC (x))
3374 cp_error_at ("field `%D' in local class cannot be static", x);
3375
3376 /* Perform error checking that did not get done in
3377 grokdeclarator. */
3378 if (TREE_CODE (TREE_TYPE (x)) == FUNCTION_TYPE)
3379 {
3380 cp_error_at ("field `%D' invalidly declared function type",
3381 x);
3382 TREE_TYPE (x) = build_pointer_type (TREE_TYPE (x));
3383 }
3384 else if (TREE_CODE (TREE_TYPE (x)) == METHOD_TYPE)
3385 {
3386 cp_error_at ("field `%D' invalidly declared method type", x);
3387 TREE_TYPE (x) = build_pointer_type (TREE_TYPE (x));
3388 }
3389 else if (TREE_CODE (TREE_TYPE (x)) == OFFSET_TYPE)
3390 {
3391 cp_error_at ("field `%D' invalidly declared offset type", x);
3392 TREE_TYPE (x) = build_pointer_type (TREE_TYPE (x));
3393 }
3394
3395 #if 0
3396 if (DECL_NAME (x) == constructor_name (t))
3397 cant_have_default_ctor = 1;
3398 #endif
3399
3400 if (TREE_TYPE (x) == error_mark_node)
3401 continue;
3402
3403 DECL_SAVED_INSNS (x) = NULL_RTX;
3404 DECL_FIELD_SIZE (x) = 0;
3405
3406 /* When this goes into scope, it will be a non-local reference. */
3407 DECL_NONLOCAL (x) = 1;
3408
3409 if (TREE_CODE (x) == CONST_DECL)
3410 continue;
3411
3412 if (TREE_CODE (x) == VAR_DECL)
3413 {
3414 if (TREE_CODE (t) == UNION_TYPE)
3415 /* Unions cannot have static members. */
3416 cp_error_at ("field `%D' declared static in union", x);
3417
3418 continue;
3419 }
3420
3421 /* Now it can only be a FIELD_DECL. */
3422
3423 if (TREE_PRIVATE (x) || TREE_PROTECTED (x))
3424 aggregate = 0;
3425
3426 /* If this is of reference type, check if it needs an init.
3427 Also do a little ANSI jig if necessary. */
3428 if (TREE_CODE (TREE_TYPE (x)) == REFERENCE_TYPE)
3429 {
3430 if (DECL_INITIAL (x) == NULL_TREE)
3431 ref_sans_init = 1;
3432
3433 /* ARM $12.6.2: [A member initializer list] (or, for an
3434 aggregate, initialization by a brace-enclosed list) is the
3435 only way to initialize nonstatic const and reference
3436 members. */
3437 cant_have_default_ctor = 1;
3438 TYPE_HAS_COMPLEX_ASSIGN_REF (t) = 1;
3439
3440 if (! TYPE_HAS_CONSTRUCTOR (t) && extra_warnings)
3441 {
3442 if (DECL_NAME (x))
3443 cp_warning_at ("non-static reference `%#D' in class without a constructor", x);
3444 else
3445 cp_warning_at ("non-static reference in class without a constructor", x);
3446 }
3447 }
3448
3449 if (TREE_CODE (TREE_TYPE (x)) == POINTER_TYPE)
3450 has_pointers = 1;
3451
3452 /* If any field is const, the structure type is pseudo-const. */
3453 if (TREE_READONLY (x))
3454 {
3455 C_TYPE_FIELDS_READONLY (t) = 1;
3456 if (DECL_INITIAL (x) == NULL_TREE)
3457 const_sans_init = 1;
3458
3459 /* ARM $12.6.2: [A member initializer list] (or, for an
3460 aggregate, initialization by a brace-enclosed list) is the
3461 only way to initialize nonstatic const and reference
3462 members. */
3463 cant_have_default_ctor = 1;
3464 TYPE_HAS_COMPLEX_ASSIGN_REF (t) = 1;
3465
3466 if (! TYPE_HAS_CONSTRUCTOR (t) && !IS_SIGNATURE (t)
3467 && extra_warnings)
3468 {
3469 if (DECL_NAME (x))
3470 cp_warning_at ("non-static const member `%#D' in class without a constructor", x);
3471 else
3472 cp_warning_at ("non-static const member in class without a constructor", x);
3473 }
3474 }
3475 else
3476 {
3477 /* A field that is pseudo-const makes the structure
3478 likewise. */
3479 tree t1 = TREE_TYPE (x);
3480 while (TREE_CODE (t1) == ARRAY_TYPE)
3481 t1 = TREE_TYPE (t1);
3482 if (IS_AGGR_TYPE (t1))
3483 {
3484 if (C_TYPE_FIELDS_READONLY (t1))
3485 C_TYPE_FIELDS_READONLY (t) = 1;
3486 if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (t1))
3487 const_sans_init = 1;
3488 }
3489 }
3490
3491 /* We set DECL_BIT_FIELD tentatively in grokbitfield.
3492 If the type and width are valid, we'll keep it set.
3493 Otherwise, the flag is cleared. */
3494 if (DECL_BIT_FIELD (x))
3495 {
3496 DECL_BIT_FIELD (x) = 0;
3497 /* Invalid bit-field size done by grokfield. */
3498 /* Detect invalid bit-field type. */
3499 if (DECL_INITIAL (x)
3500 && ! INTEGRAL_TYPE_P (TREE_TYPE (x)))
3501 {
3502 cp_error_at ("bit-field `%#D' with non-integral type", x);
3503 DECL_INITIAL (x) = NULL;
3504 }
3505
3506 /* Detect and ignore out of range field width. */
3507 if (DECL_INITIAL (x))
3508 {
3509 tree w = DECL_INITIAL (x);
3510 register int width;
3511
3512 /* Avoid the non_lvalue wrapper added by fold for PLUS_EXPRs. */
3513 STRIP_NOPS (w);
3514
3515 /* detect invalid field size. */
3516 if (TREE_CODE (w) == CONST_DECL)
3517 w = DECL_INITIAL (w);
3518 else if (TREE_READONLY_DECL_P (w))
3519 w = decl_constant_value (w);
3520
3521 if (TREE_CODE (w) != INTEGER_CST)
3522 {
3523 cp_error_at ("bit-field `%D' width not an integer constant",
3524 x);
3525 DECL_INITIAL (x) = NULL_TREE;
3526 }
3527 else if (width = TREE_INT_CST_LOW (w),
3528 width < 0)
3529 {
3530 DECL_INITIAL (x) = NULL;
3531 cp_error_at ("negative width in bit-field `%D'", x);
3532 }
3533 else if (width == 0 && DECL_NAME (x) != 0)
3534 {
3535 DECL_INITIAL (x) = NULL;
3536 cp_error_at ("zero width for bit-field `%D'", x);
3537 }
3538 else if (width
3539 > TYPE_PRECISION (long_long_unsigned_type_node))
3540 {
3541 /* The backend will dump if you try to use something
3542 too big; avoid that. */
3543 DECL_INITIAL (x) = NULL;
3544 sorry ("bit-fields larger than %d bits",
3545 TYPE_PRECISION (long_long_unsigned_type_node));
3546 cp_error_at (" in declaration of `%D'", x);
3547 }
3548 else if (width > TYPE_PRECISION (TREE_TYPE (x))
3549 && TREE_CODE (TREE_TYPE (x)) != ENUMERAL_TYPE)
3550 {
3551 cp_warning_at ("width of `%D' exceeds its type", x);
3552 }
3553 else if (TREE_CODE (TREE_TYPE (x)) == ENUMERAL_TYPE
3554 && ((min_precision (TYPE_MIN_VALUE (TREE_TYPE (x)),
3555 TREE_UNSIGNED (TREE_TYPE (x))) > width)
3556 || (min_precision (TYPE_MAX_VALUE (TREE_TYPE (x)),
3557 TREE_UNSIGNED (TREE_TYPE (x))) > width)))
3558 {
3559 cp_warning_at ("`%D' is too small to hold all values of `%#T'",
3560 x, TREE_TYPE (x));
3561 }
3562
3563 if (DECL_INITIAL (x) == NULL_TREE)
3564 ;
3565 else if (width == 0)
3566 {
3567 #ifdef EMPTY_FIELD_BOUNDARY
3568 DECL_ALIGN (x) = MAX (DECL_ALIGN (x), EMPTY_FIELD_BOUNDARY);
3569 #endif
3570 #ifdef PCC_BITFIELD_TYPE_MATTERS
3571 DECL_ALIGN (x) = MAX (DECL_ALIGN (x),
3572 TYPE_ALIGN (TREE_TYPE (x)));
3573 #endif
3574 }
3575 else
3576 {
3577 DECL_INITIAL (x) = NULL_TREE;
3578 DECL_FIELD_SIZE (x) = width;
3579 DECL_BIT_FIELD (x) = 1;
3580 }
3581 }
3582 else
3583 /* Non-bit-fields are aligned for their type. */
3584 DECL_ALIGN (x) = MAX (DECL_ALIGN (x), TYPE_ALIGN (TREE_TYPE (x)));
3585 }
3586 else
3587 {
3588 tree type = TREE_TYPE (x);
3589
3590 while (TREE_CODE (type) == ARRAY_TYPE)
3591 type = TREE_TYPE (type);
3592
3593 if (TYPE_LANG_SPECIFIC (type) && ! ANON_UNION_P (x)
3594 && ! TYPE_PTRMEMFUNC_P (type))
3595 {
3596 /* Never let anything with uninheritable virtuals
3597 make it through without complaint. */
3598 if (CLASSTYPE_ABSTRACT_VIRTUALS (type))
3599 abstract_virtuals_error (x, type);
3600
3601 /* Don't let signatures make it through either. */
3602 if (IS_SIGNATURE (type))
3603 signature_error (x, type);
3604
3605 if (code == UNION_TYPE)
3606 {
3607 char *fie = NULL;
3608 if (TYPE_NEEDS_CONSTRUCTING (type))
3609 fie = "constructor";
3610 else if (TYPE_NEEDS_DESTRUCTOR (type))
3611 fie = "destructor";
3612 else if (TYPE_HAS_REAL_ASSIGNMENT (type))
3613 fie = "assignment operator";
3614 if (fie)
3615 cp_error_at ("member `%#D' with %s not allowed in union", x,
3616 fie);
3617 }
3618 else
3619 {
3620 TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (type);
3621 TYPE_NEEDS_DESTRUCTOR (t) |= TYPE_NEEDS_DESTRUCTOR (type);
3622 TYPE_HAS_COMPLEX_ASSIGN_REF (t) |= TYPE_HAS_COMPLEX_ASSIGN_REF (type);
3623 TYPE_HAS_COMPLEX_INIT_REF (t) |= TYPE_HAS_COMPLEX_INIT_REF (type);
3624 }
3625
3626 if (!TYPE_HAS_CONST_INIT_REF (type))
3627 cant_have_const_ctor = 1;
3628
3629 if (!TYPE_HAS_CONST_ASSIGN_REF (type))
3630 no_const_asn_ref = 1;
3631
3632 if (TYPE_HAS_CONSTRUCTOR (type)
3633 && ! TYPE_HAS_DEFAULT_CONSTRUCTOR (type))
3634 {
3635 cant_have_default_ctor = 1;
3636 #if 0
3637 /* This is wrong for aggregates. */
3638 if (! TYPE_HAS_CONSTRUCTOR (t))
3639 {
3640 if (DECL_NAME (x))
3641 cp_pedwarn_at ("member `%#D' with only non-default constructor", x);
3642 else
3643 cp_pedwarn_at ("member with only non-default constructor", x);
3644 cp_pedwarn_at ("in class without a constructor",
3645 x);
3646 }
3647 #endif
3648 }
3649 }
3650 if (DECL_INITIAL (x) != NULL_TREE)
3651 {
3652 /* `build_class_init_list' does not recognize
3653 non-FIELD_DECLs. */
3654 if (code == UNION_TYPE && any_default_members != 0)
3655 cp_error_at ("multiple fields in union `%T' initialized");
3656 any_default_members = 1;
3657 }
3658 }
3659 }
3660
3661 /* If this type has any constant members which did not come
3662 with their own initialization, mark that fact here. It is
3663 not an error here, since such types can be saved either by their
3664 constructors, or by fortuitous initialization. */
3665 CLASSTYPE_READONLY_FIELDS_NEED_INIT (t) = const_sans_init;
3666 CLASSTYPE_REF_FIELDS_NEED_INIT (t) = ref_sans_init;
3667 CLASSTYPE_ABSTRACT_VIRTUALS (t) = abstract_virtuals;
3668
3669 /* Synthesize any needed methods. Note that methods will be synthesized
3670 for anonymous unions; grok_x_components undoes that. */
3671
3672 if (! fn_fields)
3673 nonprivate_method = 1;
3674
3675 if (TYPE_NEEDS_DESTRUCTOR (t) && !TYPE_HAS_DESTRUCTOR (t)
3676 && !IS_SIGNATURE (t))
3677 {
3678 /* Here we must cons up a destructor on the fly. */
3679 tree dtor = cons_up_default_function (t, name, 0);
3680 check_for_override (dtor, t);
3681
3682 /* If we couldn't make it work, then pretend we didn't need it. */
3683 if (dtor == void_type_node)
3684 TYPE_NEEDS_DESTRUCTOR (t) = 0;
3685 else
3686 {
3687 /* Link dtor onto end of fn_fields. */
3688
3689 TREE_CHAIN (dtor) = fn_fields;
3690 fn_fields = dtor;
3691
3692 if (DECL_VINDEX (dtor))
3693 add_virtual_function (&pending_virtuals, &pending_hard_virtuals,
3694 &has_virtual, dtor, t);
3695 nonprivate_method = 1;
3696 }
3697 }
3698
3699 /* Effective C++ rule 11. */
3700 if (has_pointers && warn_ecpp && TYPE_HAS_CONSTRUCTOR (t)
3701 && ! (TYPE_HAS_INIT_REF (t) && TYPE_HAS_ASSIGN_REF (t)))
3702 {
3703 cp_warning ("`%#T' has pointer data members", t);
3704
3705 if (! TYPE_HAS_INIT_REF (t))
3706 {
3707 cp_warning (" but does not override `%T(const %T&)'", t, t);
3708 if (! TYPE_HAS_ASSIGN_REF (t))
3709 cp_warning (" or `operator=(const %T&)'", t);
3710 }
3711 else if (! TYPE_HAS_ASSIGN_REF (t))
3712 cp_warning (" but does not override `operator=(const %T&)'", t);
3713 }
3714
3715 TYPE_NEEDS_DESTRUCTOR (t) |= TYPE_HAS_DESTRUCTOR (t);
3716
3717 TYPE_HAS_COMPLEX_INIT_REF (t)
3718 |= (TYPE_HAS_INIT_REF (t) || TYPE_USES_VIRTUAL_BASECLASSES (t)
3719 || has_virtual || any_default_members);
3720 TYPE_NEEDS_CONSTRUCTING (t)
3721 |= (TYPE_HAS_CONSTRUCTOR (t) || TYPE_USES_VIRTUAL_BASECLASSES (t)
3722 || has_virtual || any_default_members);
3723 if (! IS_SIGNATURE (t))
3724 CLASSTYPE_NON_AGGREGATE (t)
3725 = ! aggregate || has_virtual || TYPE_HAS_CONSTRUCTOR (t);
3726
3727 /* ARM $12.1: A default constructor will be generated for a class X
3728 only if no constructor has been declared for class X. So we
3729 check TYPE_HAS_CONSTRUCTOR also, to make sure we don't generate
3730 one if they declared a constructor in this class. */
3731 if (! TYPE_HAS_CONSTRUCTOR (t) && ! cant_have_default_ctor
3732 && ! IS_SIGNATURE (t))
3733 {
3734 tree default_fn = cons_up_default_function (t, name, 2);
3735 TREE_CHAIN (default_fn) = fn_fields;
3736 fn_fields = default_fn;
3737 }
3738
3739 /* Create default copy constructor, if needed. */
3740 if (! TYPE_HAS_INIT_REF (t) && ! IS_SIGNATURE (t))
3741 {
3742 /* ARM 12.18: You get either X(X&) or X(const X&), but
3743 not both. --Chip */
3744 tree default_fn = cons_up_default_function (t, name,
3745 3 + cant_have_const_ctor);
3746 TREE_CHAIN (default_fn) = fn_fields;
3747 fn_fields = default_fn;
3748 }
3749
3750 TYPE_HAS_REAL_ASSIGNMENT (t) |= TYPE_HAS_ASSIGNMENT (t);
3751 TYPE_HAS_REAL_ASSIGN_REF (t) |= TYPE_HAS_ASSIGN_REF (t);
3752 TYPE_HAS_COMPLEX_ASSIGN_REF (t)
3753 |= TYPE_HAS_ASSIGN_REF (t) || TYPE_USES_VIRTUAL_BASECLASSES (t);
3754
3755 if (! TYPE_HAS_ASSIGN_REF (t) && ! IS_SIGNATURE (t))
3756 {
3757 tree default_fn = cons_up_default_function (t, name,
3758 5 + no_const_asn_ref);
3759 TREE_CHAIN (default_fn) = fn_fields;
3760 fn_fields = default_fn;
3761 }
3762
3763 if (fn_fields)
3764 {
3765 TYPE_METHODS (t) = fn_fields;
3766 method_vec = finish_struct_methods (t, fn_fields, nonprivate_method);
3767
3768 if (TYPE_HAS_CONSTRUCTOR (t)
3769 && CLASSTYPE_FRIEND_CLASSES (t) == NULL_TREE
3770 && DECL_FRIENDLIST (TYPE_MAIN_DECL (t)) == NULL_TREE)
3771 {
3772 int nonprivate_ctor = 0;
3773 tree ctor;
3774
3775 for (ctor = TREE_VEC_ELT (method_vec, 0);
3776 ctor;
3777 ctor = DECL_CHAIN (ctor))
3778 if (! TREE_PRIVATE (ctor))
3779 {
3780 nonprivate_ctor = 1;
3781 break;
3782 }
3783
3784 if (nonprivate_ctor == 0 && warn_ctor_dtor_privacy)
3785 cp_warning ("`%#T' only defines private constructors and has no friends",
3786 t);
3787 }
3788 }
3789 else
3790 {
3791 method_vec = 0;
3792
3793 /* Just in case these got accidentally
3794 filled in by syntax errors. */
3795 TYPE_HAS_CONSTRUCTOR (t) = 0;
3796 TYPE_HAS_DESTRUCTOR (t) = 0;
3797 }
3798
3799 {
3800 int n_methods = method_vec ? TREE_VEC_LENGTH (method_vec) : 0;
3801
3802 for (access_decls = nreverse (access_decls); access_decls;
3803 access_decls = TREE_CHAIN (access_decls))
3804 {
3805 tree fdecl = TREE_VALUE (access_decls);
3806 tree flist = NULL_TREE;
3807 tree name;
3808 tree access = TREE_PURPOSE (access_decls);
3809 int i = 2;
3810 tree tmp;
3811
3812 if (TREE_CODE (fdecl) == TREE_LIST)
3813 {
3814 flist = fdecl;
3815 fdecl = TREE_VALUE (flist);
3816 }
3817
3818 name = DECL_NAME (fdecl);
3819
3820 for (; i < n_methods; i++)
3821 if (DECL_NAME (TREE_VEC_ELT (method_vec, i)) == name)
3822 {
3823 cp_error ("cannot adjust access to `%#D' in `%#T'", fdecl, t);
3824 cp_error_at (" because of local method `%#D' with same name",
3825 TREE_VEC_ELT (method_vec, i));
3826 fdecl = NULL_TREE;
3827 break;
3828 }
3829
3830 if (! fdecl)
3831 continue;
3832
3833 for (tmp = fields; tmp; tmp = TREE_CHAIN (tmp))
3834 if (DECL_NAME (tmp) == name)
3835 {
3836 cp_error ("cannot adjust access to `%#D' in `%#T'", fdecl, t);
3837 cp_error_at (" because of local field `%#D' with same name", tmp);
3838 fdecl = NULL_TREE;
3839 break;
3840 }
3841
3842 if (!fdecl)
3843 continue;
3844
3845 /* Make type T see field decl FDECL with access ACCESS.*/
3846 if (flist)
3847 {
3848 fdecl = TREE_VALUE (flist);
3849 while (fdecl)
3850 {
3851 if (alter_access (t, fdecl, access) == 0)
3852 break;
3853 fdecl = DECL_CHAIN (fdecl);
3854 }
3855 }
3856 else
3857 alter_access (t, fdecl, access);
3858 }
3859
3860 }
3861
3862 if (vfield == NULL_TREE && has_virtual)
3863 {
3864 /* We build this decl with ptr_type_node, and
3865 change the type when we know what it should be. */
3866 vfield = build_lang_field_decl (FIELD_DECL, get_vfield_name (t),
3867 ptr_type_node);
3868 /* If you change any of the below, take a look at all the
3869 other VFIELD_BASEs and VTABLE_BASEs in the code, and change
3870 them too. */
3871 DECL_ASSEMBLER_NAME (vfield) = get_identifier (VFIELD_BASE);
3872 CLASSTYPE_VFIELD (t) = vfield;
3873 DECL_VIRTUAL_P (vfield) = 1;
3874 DECL_ARTIFICIAL (vfield) = 1;
3875 DECL_FIELD_CONTEXT (vfield) = t;
3876 DECL_CLASS_CONTEXT (vfield) = t;
3877 DECL_FCONTEXT (vfield) = t;
3878 DECL_SAVED_INSNS (vfield) = NULL_RTX;
3879 DECL_FIELD_SIZE (vfield) = 0;
3880 DECL_ALIGN (vfield) = TYPE_ALIGN (ptr_type_node);
3881 #if 0
3882 /* This is more efficient, but breaks binary compatibility, turn
3883 it on sometime when we don't care. If we turn it on, we also
3884 have to enable the code in dfs_init_vbase_pointers. */
3885 /* vfield is always first entry in structure. */
3886 TREE_CHAIN (vfield) = fields;
3887 fields = vfield;
3888 #else
3889 if (last_x)
3890 {
3891 my_friendly_assert (TREE_CHAIN (last_x) == NULL_TREE, 175);
3892 TREE_CHAIN (last_x) = vfield;
3893 last_x = vfield;
3894 }
3895 else
3896 fields = vfield;
3897 #endif
3898 empty = 0;
3899 vfields = chainon (vfields, CLASSTYPE_AS_LIST (t));
3900 }
3901
3902 /* Now DECL_INITIAL is null on all members except for zero-width bit-fields.
3903 And they have already done their work.
3904
3905 C++: maybe we will support default field initialization some day... */
3906
3907 /* Delete all zero-width bit-fields from the front of the fieldlist */
3908 while (fields && DECL_BIT_FIELD (fields)
3909 && DECL_INITIAL (fields))
3910 fields = TREE_CHAIN (fields);
3911 /* Delete all such fields from the rest of the fields. */
3912 for (x = fields; x;)
3913 {
3914 if (TREE_CHAIN (x) && DECL_BIT_FIELD (TREE_CHAIN (x))
3915 && DECL_INITIAL (TREE_CHAIN (x)))
3916 TREE_CHAIN (x) = TREE_CHAIN (TREE_CHAIN (x));
3917 else
3918 x = TREE_CHAIN (x);
3919 }
3920 /* Delete all duplicate fields from the fields */
3921 delete_duplicate_fields (fields);
3922
3923 /* Catch function/field name conflict. We don't need to do this for a
3924 signature, since it can only contain the fields constructed in
3925 append_signature_fields. */
3926 if (! IS_SIGNATURE (t))
3927 {
3928 int n_methods = method_vec ? TREE_VEC_LENGTH (method_vec) : 0;
3929 for (x = fields; x; x = TREE_CHAIN (x))
3930 {
3931 tree name = DECL_NAME (x);
3932 int i = 2;
3933
3934 if (TREE_CODE (x) == TYPE_DECL && DECL_ARTIFICIAL (x))
3935 continue;
3936
3937 for (; i < n_methods; ++i)
3938 if (DECL_NAME (TREE_VEC_ELT (method_vec, i)) == name)
3939 {
3940 cp_error_at ("data member `%#D' conflicts with", x);
3941 cp_error_at ("function member `%#D'",
3942 TREE_VEC_ELT (method_vec, i));
3943 break;
3944 }
3945 }
3946 }
3947
3948 /* Now we have the final fieldlist for the data fields. Record it,
3949 then lay out the structure or union (including the fields). */
3950
3951 TYPE_FIELDS (t) = fields;
3952
3953 /* Pass layout information about base classes to layout_type, if any. */
3954 if (n_baseclasses)
3955 {
3956 tree pseudo_basetype = TREE_TYPE (base_layout_decl);
3957
3958 TREE_CHAIN (base_layout_decl) = TYPE_FIELDS (t);
3959 TYPE_FIELDS (t) = base_layout_decl;
3960
3961 TYPE_SIZE (pseudo_basetype) = CLASSTYPE_SIZE (t);
3962 TYPE_MODE (pseudo_basetype) = TYPE_MODE (t);
3963 TYPE_ALIGN (pseudo_basetype) = CLASSTYPE_ALIGN (t);
3964 DECL_ALIGN (base_layout_decl) = TYPE_ALIGN (pseudo_basetype);
3965 /* Don't re-use old size. */
3966 DECL_SIZE (base_layout_decl) = NULL_TREE;
3967 }
3968 else if (empty)
3969 {
3970 /* C++: do not let empty structures exist. */
3971 tree decl = build_lang_field_decl
3972 (FIELD_DECL, NULL_TREE, char_type_node);
3973 TREE_CHAIN (decl) = TYPE_FIELDS (t);
3974 TYPE_FIELDS (t) = decl;
3975 }
3976
3977 layout_type (t);
3978
3979 finish_struct_anon (t);
3980
3981 if (n_baseclasses || empty)
3982 TYPE_FIELDS (t) = TREE_CHAIN (TYPE_FIELDS (t));
3983
3984 /* Set the TYPE_DECL for this type to contain the right
3985 value for DECL_OFFSET, so that we can use it as part
3986 of a COMPONENT_REF for multiple inheritance. */
3987
3988 layout_decl (TYPE_MAIN_DECL (t), 0);
3989
3990 /* Now fix up any virtual base class types that we left lying
3991 around. We must get these done before we try to lay out the
3992 virtual function table. */
3993 pending_hard_virtuals = nreverse (pending_hard_virtuals);
3994
3995 if (TYPE_USES_VIRTUAL_BASECLASSES (t))
3996 {
3997 tree vbases;
3998
3999 max_has_virtual = layout_vbasetypes (t, max_has_virtual);
4000 vbases = CLASSTYPE_VBASECLASSES (t);
4001 CLASSTYPE_N_VBASECLASSES (t) = list_length (vbases);
4002
4003 {
4004 /* Now fixup overrides of all functions in vtables from all
4005 direct or indirect virtual base classes. */
4006 tree binfos = BINFO_BASETYPES (TYPE_BINFO (t));
4007 int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
4008
4009 for (i = 0; i < n_baseclasses; i++)
4010 {
4011 tree base_binfo = TREE_VEC_ELT (binfos, i);
4012 tree basetype = BINFO_TYPE (base_binfo);
4013 tree vbases;
4014
4015 vbases = CLASSTYPE_VBASECLASSES (basetype);
4016 while (vbases)
4017 {
4018 merge_overrides (binfo_member (BINFO_TYPE (vbases),
4019 CLASSTYPE_VBASECLASSES (t)),
4020 vbases, 1, t);
4021 vbases = TREE_CHAIN (vbases);
4022 }
4023 }
4024 }
4025 }
4026
4027 /* Set up the DECL_FIELD_BITPOS of the vfield if we need to, as we
4028 might need to know it for setting up the offsets in the vtable
4029 (or in thunks) below. */
4030 if (vfield != NULL_TREE
4031 && DECL_FIELD_CONTEXT (vfield) != t)
4032 {
4033 tree binfo = get_binfo (DECL_FIELD_CONTEXT (vfield), t, 0);
4034 tree offset = BINFO_OFFSET (binfo);
4035
4036 vfield = copy_node (vfield);
4037 copy_lang_decl (vfield);
4038
4039 if (! integer_zerop (offset))
4040 offset = size_binop (MULT_EXPR, offset, size_int (BITS_PER_UNIT));
4041 DECL_FIELD_CONTEXT (vfield) = t;
4042 DECL_CLASS_CONTEXT (vfield) = t;
4043 DECL_FIELD_BITPOS (vfield)
4044 = size_binop (PLUS_EXPR, offset, DECL_FIELD_BITPOS (vfield));
4045 CLASSTYPE_VFIELD (t) = vfield;
4046 }
4047
4048 #ifdef NOTQUITE
4049 cp_warning ("Doing hard virtuals for %T...", t);
4050 #endif
4051
4052 if (has_virtual > max_has_virtual)
4053 max_has_virtual = has_virtual;
4054 if (max_has_virtual > 0)
4055 TYPE_VIRTUAL_P (t) = 1;
4056
4057 if (flag_rtti && TYPE_VIRTUAL_P (t) && !pending_hard_virtuals)
4058 modify_all_vtables (t, NULL_TREE, NULL_TREE);
4059
4060 while (pending_hard_virtuals)
4061 {
4062 modify_all_vtables (t,
4063 TREE_PURPOSE (pending_hard_virtuals),
4064 TREE_VALUE (pending_hard_virtuals));
4065 pending_hard_virtuals = TREE_CHAIN (pending_hard_virtuals);
4066 }
4067
4068 if (TYPE_USES_VIRTUAL_BASECLASSES (t))
4069 {
4070 tree vbases;
4071 /* Now fixup any virtual function entries from virtual bases
4072 that have different deltas. This has to come after we do the
4073 pending hard virtuals, as we might have a function that comes
4074 from multiple virtual base instances that is only overridden
4075 by a hard virtual above. */
4076 vbases = CLASSTYPE_VBASECLASSES (t);
4077 while (vbases)
4078 {
4079 /* We might be able to shorten the amount of work we do by
4080 only doing this for vtables that come from virtual bases
4081 that have differing offsets, but don't want to miss any
4082 entries. */
4083 fixup_vtable_deltas (vbases, 1, t);
4084 vbases = TREE_CHAIN (vbases);
4085 }
4086 }
4087
4088 /* Under our model of GC, every C++ class gets its own virtual
4089 function table, at least virtually. */
4090 if (pending_virtuals)
4091 {
4092 pending_virtuals = nreverse (pending_virtuals);
4093 /* We must enter these virtuals into the table. */
4094 if (first_vfn_base_index < 0)
4095 {
4096 /* The second slot is for the tdesc pointer when thunks are used. */
4097 if (flag_vtable_thunks)
4098 pending_virtuals = tree_cons (NULL_TREE, NULL_TREE, pending_virtuals);
4099
4100 /* The first slot is for the rtti offset. */
4101 pending_virtuals = tree_cons (NULL_TREE, NULL_TREE, pending_virtuals);
4102
4103 set_rtti_entry (pending_virtuals, size_zero_node, t);
4104 build_vtable (NULL_TREE, t);
4105 }
4106 else
4107 {
4108 /* Here we know enough to change the type of our virtual
4109 function table, but we will wait until later this function. */
4110
4111 if (! BINFO_NEW_VTABLE_MARKED (TYPE_BINFO (t)))
4112 build_vtable (TREE_VEC_ELT (TYPE_BINFO_BASETYPES (t), first_vfn_base_index), t);
4113 }
4114
4115 /* If this type has basetypes with constructors, then those
4116 constructors might clobber the virtual function table. But
4117 they don't if the derived class shares the exact vtable of the base
4118 class. */
4119
4120 CLASSTYPE_NEEDS_VIRTUAL_REINIT (t) = 1;
4121 }
4122 else if (first_vfn_base_index >= 0)
4123 {
4124 tree binfo = TREE_VEC_ELT (TYPE_BINFO_BASETYPES (t), first_vfn_base_index);
4125 /* This class contributes nothing new to the virtual function
4126 table. However, it may have declared functions which
4127 went into the virtual function table "inherited" from the
4128 base class. If so, we grab a copy of those updated functions,
4129 and pretend they are ours. */
4130
4131 /* See if we should steal the virtual info from base class. */
4132 if (TYPE_BINFO_VTABLE (t) == NULL_TREE)
4133 TYPE_BINFO_VTABLE (t) = BINFO_VTABLE (binfo);
4134 if (TYPE_BINFO_VIRTUALS (t) == NULL_TREE)
4135 TYPE_BINFO_VIRTUALS (t) = BINFO_VIRTUALS (binfo);
4136 if (TYPE_BINFO_VTABLE (t) != BINFO_VTABLE (binfo))
4137 CLASSTYPE_NEEDS_VIRTUAL_REINIT (t) = 1;
4138 }
4139
4140 if (max_has_virtual || first_vfn_base_index >= 0)
4141 {
4142 CLASSTYPE_VSIZE (t) = has_virtual;
4143 if (first_vfn_base_index >= 0)
4144 {
4145 if (pending_virtuals)
4146 TYPE_BINFO_VIRTUALS (t) = chainon (TYPE_BINFO_VIRTUALS (t),
4147 pending_virtuals);
4148 }
4149 else if (has_virtual)
4150 {
4151 TYPE_BINFO_VIRTUALS (t) = pending_virtuals;
4152 if (write_virtuals >= 0)
4153 DECL_VIRTUAL_P (TYPE_BINFO_VTABLE (t)) = 1;
4154 }
4155 }
4156
4157 /* Now lay out the virtual function table. */
4158 if (has_virtual)
4159 {
4160 tree atype, itype;
4161
4162 if (TREE_TYPE (vfield) == ptr_type_node)
4163 {
4164 /* We must create a pointer to this table because
4165 the one inherited from base class does not exist.
4166 We will fill in the type when we know what it
4167 should really be. Use `size_int' so values are memoized
4168 in common cases. */
4169 itype = build_index_type (size_int (has_virtual));
4170 atype = build_array_type (vtable_entry_type, itype);
4171 layout_type (atype);
4172 TREE_TYPE (vfield) = build_pointer_type (atype);
4173 }
4174 else
4175 {
4176 atype = TREE_TYPE (TREE_TYPE (vfield));
4177
4178 if (has_virtual != TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (atype))))
4179 {
4180 /* We must extend (or create) the boundaries on this array,
4181 because we picked up virtual functions from multiple
4182 base classes. */
4183 itype = build_index_type (size_int (has_virtual));
4184 atype = build_array_type (vtable_entry_type, itype);
4185 layout_type (atype);
4186 vfield = copy_node (vfield);
4187 TREE_TYPE (vfield) = build_pointer_type (atype);
4188 }
4189 }
4190
4191 CLASSTYPE_VFIELD (t) = vfield;
4192 if (TREE_TYPE (TYPE_BINFO_VTABLE (t)) != atype)
4193 {
4194 TREE_TYPE (TYPE_BINFO_VTABLE (t)) = atype;
4195 DECL_SIZE (TYPE_BINFO_VTABLE (t)) = 0;
4196 layout_decl (TYPE_BINFO_VTABLE (t), 0);
4197 /* At one time the vtable info was grabbed 2 words at a time. This
4198 fails on sparc unless you have 8-byte alignment. (tiemann) */
4199 DECL_ALIGN (TYPE_BINFO_VTABLE (t))
4200 = MAX (TYPE_ALIGN (double_type_node),
4201 DECL_ALIGN (TYPE_BINFO_VTABLE (t)));
4202 }
4203 }
4204 else if (first_vfn_base_index >= 0)
4205 CLASSTYPE_VFIELD (t) = vfield;
4206 CLASSTYPE_VFIELDS (t) = vfields;
4207
4208 finish_struct_bits (t, max_has_virtual);
4209
4210 /* Complete the rtl for any static member objects of the type we're
4211 working on. */
4212 for (x = fields; x; x = TREE_CHAIN (x))
4213 {
4214 if (TREE_CODE (x) == VAR_DECL && TREE_STATIC (x)
4215 && TREE_TYPE (x) == t)
4216 {
4217 DECL_MODE (x) = TYPE_MODE (t);
4218 make_decl_rtl (x, NULL, 0);
4219 }
4220 }
4221
4222 if (TYPE_HAS_CONSTRUCTOR (t))
4223 {
4224 tree vfields = CLASSTYPE_VFIELDS (t);
4225
4226 while (vfields)
4227 {
4228 /* Mark the fact that constructor for T
4229 could affect anybody inheriting from T
4230 who wants to initialize vtables for VFIELDS's type. */
4231 if (VF_DERIVED_VALUE (vfields))
4232 TREE_ADDRESSABLE (vfields) = 1;
4233 vfields = TREE_CHAIN (vfields);
4234 }
4235 if (any_default_members != 0)
4236 build_class_init_list (t);
4237 }
4238 else if (TYPE_NEEDS_CONSTRUCTING (t))
4239 build_class_init_list (t);
4240
4241 /* Write out inline function definitions. */
4242 do_inline_function_hair (t, CLASSTYPE_INLINE_FRIENDS (t));
4243 CLASSTYPE_INLINE_FRIENDS (t) = 0;
4244
4245 if (CLASSTYPE_VSIZE (t) != 0)
4246 {
4247 #if 0
4248 /* This is now done above. */
4249 if (DECL_FIELD_CONTEXT (vfield) != t)
4250 {
4251 tree binfo = get_binfo (DECL_FIELD_CONTEXT (vfield), t, 0);
4252 tree offset = BINFO_OFFSET (binfo);
4253
4254 vfield = copy_node (vfield);
4255 copy_lang_decl (vfield);
4256
4257 if (! integer_zerop (offset))
4258 offset = size_binop (MULT_EXPR, offset, size_int (BITS_PER_UNIT));
4259 DECL_FIELD_CONTEXT (vfield) = t;
4260 DECL_CLASS_CONTEXT (vfield) = t;
4261 DECL_FIELD_BITPOS (vfield)
4262 = size_binop (PLUS_EXPR, offset, DECL_FIELD_BITPOS (vfield));
4263 CLASSTYPE_VFIELD (t) = vfield;
4264 }
4265 #endif
4266
4267 /* In addition to this one, all the other vfields should be listed. */
4268 /* Before that can be done, we have to have FIELD_DECLs for them, and
4269 a place to find them. */
4270 TYPE_NONCOPIED_PARTS (t) = build_tree_list (default_conversion (TYPE_BINFO_VTABLE (t)), vfield);
4271
4272 if (warn_nonvdtor && TYPE_HAS_DESTRUCTOR (t)
4273 && DECL_VINDEX (TREE_VEC_ELT (method_vec, 1)) == NULL_TREE)
4274 cp_warning ("`%#T' has virtual functions but non-virtual destructor",
4275 t);
4276 }
4277
4278 /* Make the rtl for any new vtables we have created, and unmark
4279 the base types we marked. */
4280 finish_vtbls (TYPE_BINFO (t), 1, t);
4281 hack_incomplete_structures (t);
4282
4283 #if 0
4284 if (TYPE_NAME (t) && TYPE_IDENTIFIER (t))
4285 undo_template_name_overload (TYPE_IDENTIFIER (t), 1);
4286 #endif
4287
4288 resume_momentary (old);
4289
4290 if (warn_overloaded_virtual)
4291 warn_hidden (t);
4292
4293 #if 0
4294 /* This has to be done after we have sorted out what to do with
4295 the enclosing type. */
4296 if (write_symbols != DWARF_DEBUG)
4297 {
4298 /* Be smarter about nested classes here. If a type is nested,
4299 only output it if we would output the enclosing type. */
4300 if (DECL_CONTEXT (TYPE_MAIN_DECL (t))
4301 && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (TYPE_MAIN_DECL (t)))) == 't')
4302 DECL_IGNORED_P (TYPE_MAIN_DECL (t)) = TREE_ASM_WRITTEN (TYPE_MAIN_DECL (t));
4303 }
4304 #endif
4305
4306 if (write_symbols != DWARF_DEBUG && write_symbols != DWARF2_DEBUG)
4307 {
4308 /* If the type has methods, we want to think about cutting down
4309 the amount of symbol table stuff we output. The value stored in
4310 the TYPE_DECL's DECL_IGNORED_P slot is a first approximation.
4311 For example, if a member function is seen and we decide to
4312 write out that member function, then we can change the value
4313 of the DECL_IGNORED_P slot, and the type will be output when
4314 that member function's debug info is written out.
4315
4316 We can't do this with DWARF, which does not support name
4317 references between translation units. */
4318 if (CLASSTYPE_METHOD_VEC (t))
4319 {
4320 extern tree pending_vtables;
4321
4322 /* Don't output full info about any type
4323 which does not have its implementation defined here. */
4324 if (TYPE_VIRTUAL_P (t) && write_virtuals == 2)
4325 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t))
4326 = (value_member (TYPE_IDENTIFIER (t), pending_vtables) == 0);
4327 else if (CLASSTYPE_INTERFACE_ONLY (t))
4328 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t)) = 1;
4329 #if 0
4330 /* XXX do something about this. */
4331 else if (CLASSTYPE_INTERFACE_UNKNOWN (t))
4332 /* Only a first approximation! */
4333 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t)) = 1;
4334 #endif
4335 }
4336 else if (CLASSTYPE_INTERFACE_ONLY (t))
4337 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t)) = 1;
4338 }
4339
4340 /* Finish debugging output for this type. */
4341 rest_of_type_compilation (t, toplevel_bindings_p ());
4342
4343 return t;
4344 }
4345
4346 tree
4347 finish_struct (t, list_of_fieldlists, attributes, warn_anon)
4348 tree t, list_of_fieldlists, attributes;
4349 int warn_anon;
4350 {
4351 tree fields = NULL_TREE;
4352 tree *tail = &TYPE_METHODS (t);
4353 tree name = TYPE_NAME (t);
4354 tree x, last_x = NULL_TREE;
4355 tree access;
4356 tree dummy = NULL_TREE;
4357
4358 if (TREE_CODE (name) == TYPE_DECL)
4359 {
4360 extern int lineno;
4361
4362 DECL_SOURCE_FILE (name) = input_filename;
4363 /* For TYPE_DECL that are not typedefs (those marked with a line
4364 number of zero, we don't want to mark them as real typedefs.
4365 If this fails one needs to make sure real typedefs have a
4366 previous line number, even if it is wrong, that way the below
4367 will fill in the right line number. (mrs) */
4368 if (DECL_SOURCE_LINE (name))
4369 DECL_SOURCE_LINE (name) = lineno;
4370 CLASSTYPE_SOURCE_LINE (t) = lineno;
4371 name = DECL_NAME (name);
4372 }
4373
4374 /* Append the fields we need for constructing signature tables. */
4375 if (IS_SIGNATURE (t))
4376 append_signature_fields (list_of_fieldlists);
4377
4378 /* Move our self-reference declaration to the end of the field list so
4379 any real field with the same name takes precedence. */
4380 if (list_of_fieldlists
4381 && TREE_VALUE (list_of_fieldlists)
4382 && DECL_ARTIFICIAL (TREE_VALUE (list_of_fieldlists)))
4383 {
4384 dummy = TREE_VALUE (list_of_fieldlists);
4385 list_of_fieldlists = TREE_CHAIN (list_of_fieldlists);
4386 }
4387
4388 if (last_x && list_of_fieldlists)
4389 TREE_CHAIN (last_x) = TREE_VALUE (list_of_fieldlists);
4390
4391 while (list_of_fieldlists)
4392 {
4393 access = TREE_PURPOSE (list_of_fieldlists);
4394
4395 /* For signatures, we made all methods `public' in the parser and
4396 reported an error if a access specifier was used. */
4397 if (access == access_default_node)
4398 {
4399 if (CLASSTYPE_DECLARED_CLASS (t) == 0)
4400 access = access_public_node;
4401 else
4402 access = access_private_node;
4403 }
4404
4405 for (x = TREE_VALUE (list_of_fieldlists); x; x = TREE_CHAIN (x))
4406 {
4407 TREE_PRIVATE (x) = access == access_private_node;
4408 TREE_PROTECTED (x) = access == access_protected_node;
4409
4410 /* Check for inconsistent use of this name in the class body.
4411 Enums, types and static vars have already been checked. */
4412 if (TREE_CODE (x) != TYPE_DECL && TREE_CODE (x) != USING_DECL
4413 && TREE_CODE (x) != CONST_DECL && TREE_CODE (x) != VAR_DECL)
4414 {
4415 tree name = DECL_NAME (x);
4416 tree icv;
4417
4418 /* Don't get confused by access decls. */
4419 if (name && TREE_CODE (name) == IDENTIFIER_NODE)
4420 icv = IDENTIFIER_CLASS_VALUE (name);
4421 else
4422 icv = NULL_TREE;
4423
4424 if (icv
4425 /* Don't complain about constructors. */
4426 && name != constructor_name (current_class_type)
4427 /* Or inherited names. */
4428 && id_in_current_class (name)
4429 /* Or shadowed tags. */
4430 && !(TREE_CODE (icv) == TYPE_DECL
4431 && DECL_CONTEXT (icv) == t))
4432 {
4433 cp_error_at ("declaration of identifier `%D' as `%+#D'",
4434 name, x);
4435 cp_error_at ("conflicts with other use in class as `%#D'",
4436 icv);
4437 }
4438 }
4439
4440 if (TREE_CODE (x) == FUNCTION_DECL
4441 || DECL_FUNCTION_TEMPLATE_P (x))
4442 {
4443 DECL_CLASS_CONTEXT (x) = t;
4444 if (last_x)
4445 TREE_CHAIN (last_x) = TREE_CHAIN (x);
4446 /* Link x onto end of TYPE_METHODS. */
4447 *tail = x;
4448 tail = &TREE_CHAIN (x);
4449 continue;
4450 }
4451
4452 if (TREE_CODE (x) != TYPE_DECL)
4453 DECL_FIELD_CONTEXT (x) = t;
4454
4455 if (! fields)
4456 fields = x;
4457 last_x = x;
4458 }
4459 list_of_fieldlists = TREE_CHAIN (list_of_fieldlists);
4460 /* link the tail while we have it! */
4461 if (last_x)
4462 {
4463 TREE_CHAIN (last_x) = NULL_TREE;
4464
4465 if (list_of_fieldlists
4466 && TREE_VALUE (list_of_fieldlists)
4467 && TREE_CODE (TREE_VALUE (list_of_fieldlists)) != FUNCTION_DECL)
4468 TREE_CHAIN (last_x) = TREE_VALUE (list_of_fieldlists);
4469 }
4470 }
4471
4472 /* Now add the tags, if any, to the list of TYPE_DECLs
4473 defined for this type. */
4474 if (CLASSTYPE_TAGS (t) || dummy)
4475 {
4476 /* The list of tags was built up in pushtag in reverse order; we need
4477 to fix that so that enumerators will be processed in forward order
4478 in template instantiation. */
4479 CLASSTYPE_TAGS (t) = x = nreverse (CLASSTYPE_TAGS (t));
4480 while (x)
4481 {
4482 tree tag = TYPE_MAIN_DECL (TREE_VALUE (x));
4483
4484 TREE_NONLOCAL_FLAG (TREE_VALUE (x)) = 0;
4485 x = TREE_CHAIN (x);
4486 last_x = chainon (last_x, tag);
4487 }
4488 if (dummy)
4489 last_x = chainon (last_x, dummy);
4490 if (fields == NULL_TREE)
4491 fields = last_x;
4492 CLASSTYPE_LOCAL_TYPEDECLS (t) = 1;
4493 }
4494
4495 *tail = NULL_TREE;
4496 TYPE_FIELDS (t) = fields;
4497
4498 cplus_decl_attributes (t, attributes, NULL_TREE);
4499
4500 if (processing_template_decl)
4501 {
4502 tree d = getdecls ();
4503 for (; d; d = TREE_CHAIN (d))
4504 {
4505 /* If this is the decl for the class or one of the template
4506 parms, we've seen all the injected decls. */
4507 if ((TREE_CODE (d) == TYPE_DECL
4508 && (TREE_TYPE (d) == t
4509 || TREE_CODE (TREE_TYPE (d)) == TEMPLATE_TYPE_PARM))
4510 || TREE_CODE (d) == CONST_DECL)
4511 break;
4512 /* Don't inject cache decls. */
4513 else if (IDENTIFIER_TEMPLATE (DECL_NAME (d)))
4514 continue;
4515 DECL_TEMPLATE_INJECT (CLASSTYPE_TI_TEMPLATE (t))
4516 = tree_cons (NULL_TREE, d,
4517 DECL_TEMPLATE_INJECT (CLASSTYPE_TI_TEMPLATE (t)));
4518 }
4519 CLASSTYPE_METHOD_VEC (t)
4520 = finish_struct_methods (t, TYPE_METHODS (t), 1);
4521 TYPE_SIZE (t) = integer_zero_node;
4522 }
4523 else
4524 t = finish_struct_1 (t, warn_anon);
4525
4526 TYPE_BEING_DEFINED (t) = 0;
4527
4528 if (current_class_type)
4529 popclass (0);
4530 else
4531 error ("trying to finish struct, but kicked out due to previous parse errors.");
4532
4533 return t;
4534 }
4535 \f
4536 /* Return non-zero if the effective type of INSTANCE is static.
4537 Used to determine whether the virtual function table is needed
4538 or not.
4539
4540 *NONNULL is set iff INSTANCE can be known to be nonnull, regardless
4541 of our knowledge of its type. */
4542
4543 int
4544 resolves_to_fixed_type_p (instance, nonnull)
4545 tree instance;
4546 int *nonnull;
4547 {
4548 switch (TREE_CODE (instance))
4549 {
4550 case INDIRECT_REF:
4551 /* Check that we are not going through a cast of some sort. */
4552 if (TREE_TYPE (instance)
4553 == TREE_TYPE (TREE_TYPE (TREE_OPERAND (instance, 0))))
4554 instance = TREE_OPERAND (instance, 0);
4555 /* fall through... */
4556 case CALL_EXPR:
4557 /* This is a call to a constructor, hence it's never zero. */
4558 if (TREE_HAS_CONSTRUCTOR (instance))
4559 {
4560 if (nonnull)
4561 *nonnull = 1;
4562 return 1;
4563 }
4564 return 0;
4565
4566 case SAVE_EXPR:
4567 /* This is a call to a constructor, hence it's never zero. */
4568 if (TREE_HAS_CONSTRUCTOR (instance))
4569 {
4570 if (nonnull)
4571 *nonnull = 1;
4572 return 1;
4573 }
4574 return resolves_to_fixed_type_p (TREE_OPERAND (instance, 0), nonnull);
4575
4576 case RTL_EXPR:
4577 /* This is a call to `new', hence it's never zero. */
4578 if (TREE_CALLS_NEW (instance))
4579 {
4580 if (nonnull)
4581 *nonnull = 1;
4582 return 1;
4583 }
4584 return 0;
4585
4586 case PLUS_EXPR:
4587 case MINUS_EXPR:
4588 if (TREE_CODE (TREE_OPERAND (instance, 1)) == INTEGER_CST)
4589 /* Propagate nonnull. */
4590 resolves_to_fixed_type_p (TREE_OPERAND (instance, 0), nonnull);
4591 if (TREE_CODE (TREE_OPERAND (instance, 0)) == ADDR_EXPR)
4592 return resolves_to_fixed_type_p (TREE_OPERAND (instance, 0), nonnull);
4593 return 0;
4594
4595 case NOP_EXPR:
4596 case CONVERT_EXPR:
4597 return resolves_to_fixed_type_p (TREE_OPERAND (instance, 0), nonnull);
4598
4599 case ADDR_EXPR:
4600 if (nonnull)
4601 *nonnull = 1;
4602 return resolves_to_fixed_type_p (TREE_OPERAND (instance, 0), nonnull);
4603
4604 case COMPONENT_REF:
4605 return resolves_to_fixed_type_p (TREE_OPERAND (instance, 1), nonnull);
4606
4607 case VAR_DECL:
4608 case FIELD_DECL:
4609 if (TREE_CODE (TREE_TYPE (instance)) == ARRAY_TYPE
4610 && IS_AGGR_TYPE (TREE_TYPE (TREE_TYPE (instance))))
4611 {
4612 if (nonnull)
4613 *nonnull = 1;
4614 return 1;
4615 }
4616 /* fall through... */
4617 case TARGET_EXPR:
4618 case PARM_DECL:
4619 if (IS_AGGR_TYPE (TREE_TYPE (instance)))
4620 {
4621 if (nonnull)
4622 *nonnull = 1;
4623 return 1;
4624 }
4625 else if (nonnull)
4626 {
4627 if (instance == current_class_ptr
4628 && flag_this_is_variable <= 0)
4629 {
4630 /* Some people still use `this = 0' inside destructors. */
4631 *nonnull = ! DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (current_function_decl));
4632 /* In a constructor, we know our type. */
4633 if (flag_this_is_variable < 0)
4634 return 1;
4635 }
4636 else if (TREE_CODE (TREE_TYPE (instance)) == REFERENCE_TYPE)
4637 /* Reference variables should be references to objects. */
4638 *nonnull = 1;
4639 }
4640 return 0;
4641
4642 default:
4643 return 0;
4644 }
4645 }
4646 \f
4647 void
4648 init_class_processing ()
4649 {
4650 current_class_depth = 0;
4651 current_class_stacksize = 10;
4652 current_class_base = (tree *)xmalloc(current_class_stacksize * sizeof (tree));
4653 current_class_stack = current_class_base;
4654
4655 current_lang_stacksize = 10;
4656 current_lang_base = (tree *)xmalloc(current_lang_stacksize * sizeof (tree));
4657 current_lang_stack = current_lang_base;
4658
4659 access_default_node = build_int_2 (0, 0);
4660 access_public_node = build_int_2 (1, 0);
4661 access_protected_node = build_int_2 (2, 0);
4662 access_private_node = build_int_2 (3, 0);
4663 access_default_virtual_node = build_int_2 (4, 0);
4664 access_public_virtual_node = build_int_2 (5, 0);
4665 access_private_virtual_node = build_int_2 (6, 0);
4666
4667 /* Keep these values lying around. */
4668 base_layout_decl = build_lang_field_decl (FIELD_DECL, NULL_TREE, error_mark_node);
4669 TREE_TYPE (base_layout_decl) = make_node (RECORD_TYPE);
4670
4671 gcc_obstack_init (&class_obstack);
4672 }
4673
4674 /* Set current scope to NAME. CODE tells us if this is a
4675 STRUCT, UNION, or ENUM environment.
4676
4677 NAME may end up being NULL_TREE if this is an anonymous or
4678 late-bound struct (as in "struct { ... } foo;") */
4679
4680 /* Set global variables CURRENT_CLASS_NAME and CURRENT_CLASS_TYPE to
4681 appropriate values, found by looking up the type definition of
4682 NAME (as a CODE).
4683
4684 If MODIFY is 1, we set IDENTIFIER_CLASS_VALUE's of names
4685 which can be seen locally to the class. They are shadowed by
4686 any subsequent local declaration (including parameter names).
4687
4688 If MODIFY is 2, we set IDENTIFIER_CLASS_VALUE's of names
4689 which have static meaning (i.e., static members, static
4690 member functions, enum declarations, etc).
4691
4692 If MODIFY is 3, we set IDENTIFIER_CLASS_VALUE of names
4693 which can be seen locally to the class (as in 1), but
4694 know that we are doing this for declaration purposes
4695 (i.e. friend foo::bar (int)).
4696
4697 So that we may avoid calls to lookup_name, we cache the _TYPE
4698 nodes of local TYPE_DECLs in the TREE_TYPE field of the name.
4699
4700 For multiple inheritance, we perform a two-pass depth-first search
4701 of the type lattice. The first pass performs a pre-order search,
4702 marking types after the type has had its fields installed in
4703 the appropriate IDENTIFIER_CLASS_VALUE slot. The second pass merely
4704 unmarks the marked types. If a field or member function name
4705 appears in an ambiguous way, the IDENTIFIER_CLASS_VALUE of
4706 that name becomes `error_mark_node'. */
4707
4708 void
4709 pushclass (type, modify)
4710 tree type;
4711 int modify;
4712 {
4713 push_memoized_context (type, modify);
4714
4715 current_class_depth++;
4716 *current_class_stack++ = current_class_name;
4717 *current_class_stack++ = current_class_type;
4718 if (current_class_stack >= current_class_base + current_class_stacksize)
4719 {
4720 current_class_base
4721 = (tree *)xrealloc (current_class_base,
4722 sizeof (tree) * (current_class_stacksize + 10));
4723 current_class_stack = current_class_base + current_class_stacksize;
4724 current_class_stacksize += 10;
4725 }
4726
4727 current_class_name = TYPE_NAME (type);
4728 if (TREE_CODE (current_class_name) == TYPE_DECL)
4729 current_class_name = DECL_NAME (current_class_name);
4730 current_class_type = type;
4731
4732 if (previous_class_type != NULL_TREE
4733 && (type != previous_class_type || TYPE_SIZE (previous_class_type) == NULL_TREE)
4734 && current_class_depth == 1)
4735 {
4736 /* Forcibly remove any old class remnants. */
4737 popclass (-1);
4738 previous_class_type = NULL_TREE;
4739 }
4740
4741 pushlevel_class ();
4742
4743 #if 0
4744 if (CLASSTYPE_TEMPLATE_INFO (type))
4745 overload_template_name (type);
4746 #endif
4747
4748 if (modify)
4749 {
4750 tree tags;
4751 tree this_fndecl = current_function_decl;
4752
4753 if (current_function_decl
4754 && DECL_CONTEXT (current_function_decl)
4755 && TREE_CODE (DECL_CONTEXT (current_function_decl)) == FUNCTION_DECL)
4756 current_function_decl = DECL_CONTEXT (current_function_decl);
4757 else
4758 current_function_decl = NULL_TREE;
4759
4760 if (type != previous_class_type || current_class_depth > 1)
4761 {
4762 build_mi_matrix (type);
4763 push_class_decls (type);
4764 free_mi_matrix ();
4765 }
4766 else
4767 {
4768 tree item;
4769
4770 /* Hooray, we successfully cached; let's just install the
4771 cached class_shadowed list, and walk through it to get the
4772 IDENTIFIER_TYPE_VALUEs correct. */
4773 set_class_shadows (previous_class_values);
4774 for (item = previous_class_values; item; item = TREE_CHAIN (item))
4775 {
4776 tree id = TREE_PURPOSE (item);
4777 tree decl = IDENTIFIER_CLASS_VALUE (id);
4778
4779 if (TREE_CODE (decl) == TYPE_DECL)
4780 set_identifier_type_value (id, TREE_TYPE (decl));
4781 }
4782 unuse_fields (type);
4783 }
4784
4785 for (tags = CLASSTYPE_TAGS (type); tags; tags = TREE_CHAIN (tags))
4786 {
4787 TREE_NONLOCAL_FLAG (TREE_VALUE (tags)) = 1;
4788 if (! TREE_PURPOSE (tags))
4789 continue;
4790 pushtag (TREE_PURPOSE (tags), TREE_VALUE (tags), 0);
4791 }
4792
4793 current_function_decl = this_fndecl;
4794 }
4795 }
4796
4797 /* Get out of the current class scope. If we were in a class scope
4798 previously, that is the one popped to. The flag MODIFY tells whether
4799 the current scope declarations needs to be modified as a result of
4800 popping to the previous scope. 0 is used for class definitions. */
4801
4802 void
4803 popclass (modify)
4804 int modify;
4805 {
4806 if (modify < 0)
4807 {
4808 /* Back this old class out completely. */
4809 tree tags = CLASSTYPE_TAGS (previous_class_type);
4810 tree t;
4811
4812 /* This code can be seen as a cache miss. When we've cached a
4813 class' scope's bindings and we can't use them, we need to reset
4814 them. This is it! */
4815 for (t = previous_class_values; t; t = TREE_CHAIN (t))
4816 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (t)) = NULL_TREE;
4817 while (tags)
4818 {
4819 TREE_NONLOCAL_FLAG (TREE_VALUE (tags)) = 0;
4820 tags = TREE_CHAIN (tags);
4821 }
4822 goto ret;
4823 }
4824
4825 if (modify)
4826 {
4827 /* Just remove from this class what didn't make
4828 it into IDENTIFIER_CLASS_VALUE. */
4829 tree tags = CLASSTYPE_TAGS (current_class_type);
4830
4831 while (tags)
4832 {
4833 TREE_NONLOCAL_FLAG (TREE_VALUE (tags)) = 0;
4834 tags = TREE_CHAIN (tags);
4835 }
4836 }
4837
4838 /* Force clearing of IDENTIFIER_CLASS_VALUEs after a class definition,
4839 since not all class decls make it there currently. */
4840 poplevel_class (! modify);
4841
4842 /* Since poplevel_class does the popping of class decls nowadays,
4843 this really only frees the obstack used for these decls.
4844 That's why it had to be moved down here. */
4845 if (modify)
4846 pop_class_decls ();
4847
4848 current_class_depth--;
4849 current_class_type = *--current_class_stack;
4850 current_class_name = *--current_class_stack;
4851
4852 pop_memoized_context (modify);
4853
4854 ret:
4855 ;
4856 }
4857
4858 /* When entering a class scope, all enclosing class scopes' names with
4859 static meaning (static variables, static functions, types and enumerators)
4860 have to be visible. This recursive function calls pushclass for all
4861 enclosing class contexts until global or a local scope is reached.
4862 TYPE is the enclosed class and MODIFY is equivalent with the pushclass
4863 formal of the same name. */
4864
4865 void
4866 push_nested_class (type, modify)
4867 tree type;
4868 int modify;
4869 {
4870 tree context;
4871
4872 if (type == NULL_TREE || type == error_mark_node || ! IS_AGGR_TYPE (type)
4873 || TREE_CODE (type) == TEMPLATE_TYPE_PARM)
4874 return;
4875
4876 context = DECL_CONTEXT (TYPE_MAIN_DECL (type));
4877
4878 if (context && TREE_CODE (context) == RECORD_TYPE)
4879 push_nested_class (context, 2);
4880 pushclass (type, modify);
4881 }
4882
4883 /* Undoes a push_nested_class call. MODIFY is passed on to popclass. */
4884
4885 void
4886 pop_nested_class (modify)
4887 int modify;
4888 {
4889 tree context = DECL_CONTEXT (TYPE_MAIN_DECL (current_class_type));
4890
4891 popclass (modify);
4892 if (context && TREE_CODE (context) == RECORD_TYPE)
4893 pop_nested_class (modify);
4894 }
4895
4896 /* Set global variables CURRENT_LANG_NAME to appropriate value
4897 so that behavior of name-mangling machinery is correct. */
4898
4899 void
4900 push_lang_context (name)
4901 tree name;
4902 {
4903 *current_lang_stack++ = current_lang_name;
4904 if (current_lang_stack >= current_lang_base + current_lang_stacksize)
4905 {
4906 current_lang_base
4907 = (tree *)xrealloc (current_lang_base,
4908 sizeof (tree) * (current_lang_stacksize + 10));
4909 current_lang_stack = current_lang_base + current_lang_stacksize;
4910 current_lang_stacksize += 10;
4911 }
4912
4913 if (name == lang_name_cplusplus)
4914 {
4915 strict_prototype = strict_prototypes_lang_cplusplus;
4916 current_lang_name = name;
4917 }
4918 else if (name == lang_name_c)
4919 {
4920 strict_prototype = strict_prototypes_lang_c;
4921 current_lang_name = name;
4922 }
4923 else
4924 error ("language string `\"%s\"' not recognized", IDENTIFIER_POINTER (name));
4925 }
4926
4927 /* Get out of the current language scope. */
4928
4929 void
4930 pop_lang_context ()
4931 {
4932 current_lang_name = *--current_lang_stack;
4933 if (current_lang_name == lang_name_cplusplus)
4934 strict_prototype = strict_prototypes_lang_cplusplus;
4935 else if (current_lang_name == lang_name_c)
4936 strict_prototype = strict_prototypes_lang_c;
4937 }
4938 \f
4939 /* Type instantiation routines. */
4940
4941 /* This function will instantiate the type of the expression given in
4942 RHS to match the type of LHSTYPE. If errors exist, then return
4943 error_mark_node. If only complain is COMPLAIN is set. If we are
4944 not complaining, never modify rhs, as overload resolution wants to
4945 try many possible instantiations, in hopes that at least one will
4946 work.
4947
4948 This function is used in build_modify_expr, convert_arguments,
4949 build_c_cast, and compute_conversion_costs. */
4950
4951 tree
4952 instantiate_type (lhstype, rhs, complain)
4953 tree lhstype, rhs;
4954 int complain;
4955 {
4956 tree explicit_targs = NULL_TREE;
4957
4958 if (TREE_CODE (lhstype) == UNKNOWN_TYPE)
4959 {
4960 if (complain)
4961 error ("not enough type information");
4962 return error_mark_node;
4963 }
4964
4965 if (TREE_TYPE (rhs) != NULL_TREE && ! (type_unknown_p (rhs)))
4966 return rhs;
4967
4968 rhs = copy_node (rhs);
4969
4970 /* This should really only be used when attempting to distinguish
4971 what sort of a pointer to function we have. For now, any
4972 arithmetic operation which is not supported on pointers
4973 is rejected as an error. */
4974
4975 switch (TREE_CODE (rhs))
4976 {
4977 case TYPE_EXPR:
4978 case CONVERT_EXPR:
4979 case SAVE_EXPR:
4980 case CONSTRUCTOR:
4981 case BUFFER_REF:
4982 my_friendly_abort (177);
4983 return error_mark_node;
4984
4985 case INDIRECT_REF:
4986 case ARRAY_REF:
4987 {
4988 tree new_rhs;
4989
4990 new_rhs = instantiate_type (build_pointer_type (lhstype),
4991 TREE_OPERAND (rhs, 0), complain);
4992 if (new_rhs == error_mark_node)
4993 return error_mark_node;
4994
4995 TREE_TYPE (rhs) = lhstype;
4996 TREE_OPERAND (rhs, 0) = new_rhs;
4997 return rhs;
4998 }
4999
5000 case NOP_EXPR:
5001 rhs = copy_node (TREE_OPERAND (rhs, 0));
5002 TREE_TYPE (rhs) = unknown_type_node;
5003 return instantiate_type (lhstype, rhs, complain);
5004
5005 case COMPONENT_REF:
5006 {
5007 tree field = TREE_OPERAND (rhs, 1);
5008 if (TREE_CODE (field) == TREE_LIST)
5009 {
5010 tree function = instantiate_type (lhstype, field, complain);
5011 if (function == error_mark_node)
5012 return error_mark_node;
5013 my_friendly_assert (TREE_CODE (function) == FUNCTION_DECL, 185);
5014 if (DECL_VINDEX (function))
5015 {
5016 tree base = TREE_OPERAND (rhs, 0);
5017 tree base_ptr = build_unary_op (ADDR_EXPR, base, 0);
5018 if (base_ptr == error_mark_node)
5019 return error_mark_node;
5020 base_ptr = convert_pointer_to (DECL_CONTEXT (function), base_ptr);
5021 if (base_ptr == error_mark_node)
5022 return error_mark_node;
5023 return build_vfn_ref (&base_ptr, base, DECL_VINDEX (function));
5024 }
5025 mark_used (function);
5026 return function;
5027 }
5028
5029 my_friendly_assert (TREE_CODE (field) == FIELD_DECL, 178);
5030 my_friendly_assert (!(TREE_CODE (TREE_TYPE (field)) == FUNCTION_TYPE
5031 || TREE_CODE (TREE_TYPE (field)) == METHOD_TYPE),
5032 179);
5033
5034 TREE_TYPE (rhs) = lhstype;
5035 /* First look for an exact match */
5036
5037 while (field && TREE_TYPE (field) != lhstype)
5038 field = DECL_CHAIN (field);
5039 if (field)
5040 {
5041 TREE_OPERAND (rhs, 1) = field;
5042 mark_used (field);
5043 return rhs;
5044 }
5045
5046 /* No exact match found, look for a compatible function. */
5047 field = TREE_OPERAND (rhs, 1);
5048 while (field && ! comptypes (lhstype, TREE_TYPE (field), 0))
5049 field = DECL_CHAIN (field);
5050 if (field)
5051 {
5052 TREE_OPERAND (rhs, 1) = field;
5053 field = DECL_CHAIN (field);
5054 while (field && ! comptypes (lhstype, TREE_TYPE (field), 0))
5055 field = DECL_CHAIN (field);
5056 if (field)
5057 {
5058 if (complain)
5059 error ("ambiguous overload for COMPONENT_REF requested");
5060 return error_mark_node;
5061 }
5062 }
5063 else
5064 {
5065 if (complain)
5066 error ("no appropriate overload exists for COMPONENT_REF");
5067 return error_mark_node;
5068 }
5069 return rhs;
5070 }
5071
5072 case TEMPLATE_ID_EXPR:
5073 {
5074 explicit_targs = TREE_OPERAND (rhs, 1);
5075 rhs = TREE_OPERAND (rhs, 0);
5076 }
5077 /* fall through */
5078
5079 case TREE_LIST:
5080 {
5081 tree elem, baselink, name;
5082 int globals = overloaded_globals_p (rhs);
5083
5084 /* First look for an exact match. Search either overloaded
5085 functions or member functions. May have to undo what
5086 `default_conversion' might do to lhstype. */
5087
5088 if (TYPE_PTRMEMFUNC_P (lhstype))
5089 lhstype = TYPE_PTRMEMFUNC_FN_TYPE (lhstype);
5090
5091 if (TREE_CODE (lhstype) == POINTER_TYPE)
5092 if (TREE_CODE (TREE_TYPE (lhstype)) == FUNCTION_TYPE
5093 || TREE_CODE (TREE_TYPE (lhstype)) == METHOD_TYPE)
5094 lhstype = TREE_TYPE (lhstype);
5095 else
5096 {
5097 if (complain)
5098 error ("invalid type combination for overload");
5099 return error_mark_node;
5100 }
5101
5102 if (TREE_CODE (lhstype) != FUNCTION_TYPE && globals > 0)
5103 {
5104 if (complain)
5105 cp_error ("cannot resolve overloaded function `%D' based on non-function type",
5106 TREE_PURPOSE (rhs));
5107 return error_mark_node;
5108 }
5109
5110 if (globals > 0)
5111 {
5112 elem = get_first_fn (rhs);
5113 /* If there are explicit_targs, only a template function
5114 can match. */
5115 if (explicit_targs == NULL_TREE)
5116 while (elem)
5117 if (! comptypes (lhstype, TREE_TYPE (elem), 1))
5118 elem = DECL_CHAIN (elem);
5119 else
5120 {
5121 mark_used (elem);
5122 return elem;
5123 }
5124
5125 /* No exact match found, look for a compatible template. */
5126 {
5127 tree save_elem = 0;
5128 for (elem = get_first_fn (rhs); elem; elem = DECL_CHAIN (elem))
5129 if (TREE_CODE (elem) == TEMPLATE_DECL)
5130 {
5131 int n = DECL_NTPARMS (elem);
5132 tree t = make_scratch_vec (n);
5133 int i, d = 0;
5134 i = type_unification
5135 (DECL_INNERMOST_TEMPLATE_PARMS (elem),
5136 &TREE_VEC_ELT (t, 0), TYPE_ARG_TYPES (TREE_TYPE (elem)),
5137 TYPE_ARG_TYPES (lhstype), explicit_targs, &d,
5138 1, 1);
5139 if (i == 0)
5140 {
5141 if (save_elem)
5142 {
5143 cp_error ("ambiguous template instantiation converting to `%#T'", lhstype);
5144 return error_mark_node;
5145 }
5146 save_elem = instantiate_template (elem, t);
5147 /* Check the return type. */
5148 if (! comptypes (TREE_TYPE (lhstype),
5149 TREE_TYPE (TREE_TYPE (save_elem)), 1))
5150 save_elem = 0;
5151 }
5152 }
5153 if (save_elem)
5154 {
5155 mark_used (save_elem);
5156 return save_elem;
5157 }
5158 }
5159
5160 /* If there are explicit_targs, only a template function
5161 can match. */
5162 if (explicit_targs == NULL_TREE)
5163 {
5164 /* No match found, look for a compatible function. */
5165 elem = get_first_fn (rhs);
5166 while (elem && comp_target_types (lhstype,
5167 TREE_TYPE (elem), 1) <= 0)
5168 elem = DECL_CHAIN (elem);
5169 if (elem)
5170 {
5171 tree save_elem = elem;
5172 elem = DECL_CHAIN (elem);
5173 while (elem
5174 && comp_target_types (lhstype,
5175 TREE_TYPE (elem), 0) <= 0)
5176 elem = DECL_CHAIN (elem);
5177 if (elem)
5178 {
5179 if (complain)
5180 {
5181 cp_error
5182 ("cannot resolve overload to target type `%#T'",
5183 lhstype);
5184 cp_error_at (" ambiguity between `%#D'",
5185 save_elem);
5186 cp_error_at (" and `%#D', at least", elem);
5187 }
5188 return error_mark_node;
5189 }
5190 mark_used (save_elem);
5191 return save_elem;
5192 }
5193 }
5194 if (complain)
5195 {
5196 cp_error ("cannot resolve overload to target type `%#T'",
5197 lhstype);
5198 cp_error
5199 (" because no suitable overload of function `%D' exists",
5200 TREE_PURPOSE (rhs));
5201 }
5202 return error_mark_node;
5203 }
5204
5205 if (TREE_NONLOCAL_FLAG (rhs))
5206 {
5207 /* Got to get it as a baselink. */
5208 rhs = lookup_fnfields (TYPE_BINFO (current_class_type),
5209 TREE_PURPOSE (rhs), 0);
5210 }
5211 else
5212 {
5213 my_friendly_assert (TREE_CHAIN (rhs) == NULL_TREE, 181);
5214 if (TREE_CODE (TREE_VALUE (rhs)) == TREE_LIST)
5215 rhs = TREE_VALUE (rhs);
5216 my_friendly_assert (TREE_CODE (TREE_VALUE (rhs)) == FUNCTION_DECL,
5217 182);
5218 }
5219
5220 for (baselink = rhs; baselink;
5221 baselink = next_baselink (baselink))
5222 {
5223 elem = TREE_VALUE (baselink);
5224 while (elem)
5225 if (comptypes (lhstype, TREE_TYPE (elem), 1))
5226 {
5227 mark_used (elem);
5228 return elem;
5229 }
5230 else
5231 elem = DECL_CHAIN (elem);
5232 }
5233
5234 /* No exact match found, look for a compatible method. */
5235 for (baselink = rhs; baselink;
5236 baselink = next_baselink (baselink))
5237 {
5238 elem = TREE_VALUE (baselink);
5239 while (elem && comp_target_types (lhstype,
5240 TREE_TYPE (elem), 1) <= 0)
5241 elem = DECL_CHAIN (elem);
5242 if (elem)
5243 {
5244 tree save_elem = elem;
5245 elem = DECL_CHAIN (elem);
5246 while (elem && comp_target_types (lhstype,
5247 TREE_TYPE (elem), 0) <= 0)
5248 elem = DECL_CHAIN (elem);
5249 if (elem)
5250 {
5251 if (complain)
5252 error ("ambiguous overload for overloaded method requested");
5253 return error_mark_node;
5254 }
5255 mark_used (save_elem);
5256 return save_elem;
5257 }
5258 name = DECL_NAME (TREE_VALUE (rhs));
5259 #if 0
5260 if (TREE_CODE (lhstype) == FUNCTION_TYPE && globals < 0)
5261 {
5262 /* Try to instantiate from non-member functions. */
5263 rhs = lookup_name_nonclass (name);
5264 if (rhs && TREE_CODE (rhs) == TREE_LIST)
5265 {
5266 /* This code seems to be missing a `return'. */
5267 my_friendly_abort (4);
5268 instantiate_type (lhstype, rhs, complain);
5269 }
5270 }
5271 #endif
5272 }
5273 if (complain)
5274 cp_error ("no compatible member functions named `%D'", name);
5275 return error_mark_node;
5276 }
5277
5278 case CALL_EXPR:
5279 /* This is too hard for now. */
5280 my_friendly_abort (183);
5281 return error_mark_node;
5282
5283 case PLUS_EXPR:
5284 case MINUS_EXPR:
5285 case COMPOUND_EXPR:
5286 TREE_OPERAND (rhs, 0)
5287 = instantiate_type (lhstype, TREE_OPERAND (rhs, 0), complain);
5288 if (TREE_OPERAND (rhs, 0) == error_mark_node)
5289 return error_mark_node;
5290 TREE_OPERAND (rhs, 1)
5291 = instantiate_type (lhstype, TREE_OPERAND (rhs, 1), complain);
5292 if (TREE_OPERAND (rhs, 1) == error_mark_node)
5293 return error_mark_node;
5294
5295 TREE_TYPE (rhs) = lhstype;
5296 return rhs;
5297
5298 case MULT_EXPR:
5299 case TRUNC_DIV_EXPR:
5300 case FLOOR_DIV_EXPR:
5301 case CEIL_DIV_EXPR:
5302 case ROUND_DIV_EXPR:
5303 case RDIV_EXPR:
5304 case TRUNC_MOD_EXPR:
5305 case FLOOR_MOD_EXPR:
5306 case CEIL_MOD_EXPR:
5307 case ROUND_MOD_EXPR:
5308 case FIX_ROUND_EXPR:
5309 case FIX_FLOOR_EXPR:
5310 case FIX_CEIL_EXPR:
5311 case FIX_TRUNC_EXPR:
5312 case FLOAT_EXPR:
5313 case NEGATE_EXPR:
5314 case ABS_EXPR:
5315 case MAX_EXPR:
5316 case MIN_EXPR:
5317 case FFS_EXPR:
5318
5319 case BIT_AND_EXPR:
5320 case BIT_IOR_EXPR:
5321 case BIT_XOR_EXPR:
5322 case LSHIFT_EXPR:
5323 case RSHIFT_EXPR:
5324 case LROTATE_EXPR:
5325 case RROTATE_EXPR:
5326
5327 case PREINCREMENT_EXPR:
5328 case PREDECREMENT_EXPR:
5329 case POSTINCREMENT_EXPR:
5330 case POSTDECREMENT_EXPR:
5331 if (complain)
5332 error ("invalid operation on uninstantiated type");
5333 return error_mark_node;
5334
5335 case TRUTH_AND_EXPR:
5336 case TRUTH_OR_EXPR:
5337 case TRUTH_XOR_EXPR:
5338 case LT_EXPR:
5339 case LE_EXPR:
5340 case GT_EXPR:
5341 case GE_EXPR:
5342 case EQ_EXPR:
5343 case NE_EXPR:
5344 case TRUTH_ANDIF_EXPR:
5345 case TRUTH_ORIF_EXPR:
5346 case TRUTH_NOT_EXPR:
5347 if (complain)
5348 error ("not enough type information");
5349 return error_mark_node;
5350
5351 case COND_EXPR:
5352 if (type_unknown_p (TREE_OPERAND (rhs, 0)))
5353 {
5354 if (complain)
5355 error ("not enough type information");
5356 return error_mark_node;
5357 }
5358 TREE_OPERAND (rhs, 1)
5359 = instantiate_type (lhstype, TREE_OPERAND (rhs, 1), complain);
5360 if (TREE_OPERAND (rhs, 1) == error_mark_node)
5361 return error_mark_node;
5362 TREE_OPERAND (rhs, 2)
5363 = instantiate_type (lhstype, TREE_OPERAND (rhs, 2), complain);
5364 if (TREE_OPERAND (rhs, 2) == error_mark_node)
5365 return error_mark_node;
5366
5367 TREE_TYPE (rhs) = lhstype;
5368 return rhs;
5369
5370 case MODIFY_EXPR:
5371 TREE_OPERAND (rhs, 1)
5372 = instantiate_type (lhstype, TREE_OPERAND (rhs, 1), complain);
5373 if (TREE_OPERAND (rhs, 1) == error_mark_node)
5374 return error_mark_node;
5375
5376 TREE_TYPE (rhs) = lhstype;
5377 return rhs;
5378
5379 case ADDR_EXPR:
5380 if (TYPE_PTRMEMFUNC_P (lhstype))
5381 lhstype = TYPE_PTRMEMFUNC_FN_TYPE (lhstype);
5382 else if (TREE_CODE (lhstype) != POINTER_TYPE)
5383 {
5384 if (complain)
5385 error ("type for resolving address of overloaded function must be pointer type");
5386 return error_mark_node;
5387 }
5388 {
5389 tree fn = instantiate_type (TREE_TYPE (lhstype), TREE_OPERAND (rhs, 0), complain);
5390 if (fn == error_mark_node)
5391 return error_mark_node;
5392 mark_addressable (fn);
5393 TREE_TYPE (rhs) = lhstype;
5394 TREE_OPERAND (rhs, 0) = fn;
5395 TREE_CONSTANT (rhs) = staticp (fn);
5396 if (TREE_CODE (lhstype) == POINTER_TYPE
5397 && TREE_CODE (TREE_TYPE (lhstype)) == METHOD_TYPE)
5398 {
5399 build_ptrmemfunc_type (lhstype);
5400 rhs = build_ptrmemfunc (lhstype, rhs, 0);
5401 }
5402 }
5403 return rhs;
5404
5405 case ENTRY_VALUE_EXPR:
5406 my_friendly_abort (184);
5407 return error_mark_node;
5408
5409 case ERROR_MARK:
5410 return error_mark_node;
5411
5412 default:
5413 my_friendly_abort (185);
5414 return error_mark_node;
5415 }
5416 }
5417 \f
5418 /* Return the name of the virtual function pointer field
5419 (as an IDENTIFIER_NODE) for the given TYPE. Note that
5420 this may have to look back through base types to find the
5421 ultimate field name. (For single inheritance, these could
5422 all be the same name. Who knows for multiple inheritance). */
5423
5424 static tree
5425 get_vfield_name (type)
5426 tree type;
5427 {
5428 tree binfo = TYPE_BINFO (type);
5429 char *buf;
5430
5431 while (BINFO_BASETYPES (binfo)
5432 && TYPE_VIRTUAL_P (BINFO_TYPE (BINFO_BASETYPE (binfo, 0)))
5433 && ! TREE_VIA_VIRTUAL (BINFO_BASETYPE (binfo, 0)))
5434 binfo = BINFO_BASETYPE (binfo, 0);
5435
5436 type = BINFO_TYPE (binfo);
5437 buf = (char *) alloca (sizeof (VFIELD_NAME_FORMAT)
5438 + TYPE_NAME_LENGTH (type) + 2);
5439 sprintf (buf, VFIELD_NAME_FORMAT, TYPE_NAME_STRING (type));
5440 return get_identifier (buf);
5441 }
5442
5443 void
5444 print_class_statistics ()
5445 {
5446 #ifdef GATHER_STATISTICS
5447 fprintf (stderr, "convert_harshness = %d\n", n_convert_harshness);
5448 fprintf (stderr, "compute_conversion_costs = %d\n", n_compute_conversion_costs);
5449 fprintf (stderr, "build_method_call = %d (inner = %d)\n",
5450 n_build_method_call, n_inner_fields_searched);
5451 if (n_vtables)
5452 {
5453 fprintf (stderr, "vtables = %d; vtable searches = %d\n",
5454 n_vtables, n_vtable_searches);
5455 fprintf (stderr, "vtable entries = %d; vtable elems = %d\n",
5456 n_vtable_entries, n_vtable_elems);
5457 }
5458 #endif
5459 }
5460
5461 /* Push an obstack which is sufficiently long-lived to hold such class
5462 decls that may be cached in the previous_class_values list. For now, let's
5463 use the permanent obstack, later we may create a dedicated obstack just
5464 for this purpose. The effect is undone by pop_obstacks. */
5465
5466 void
5467 maybe_push_cache_obstack ()
5468 {
5469 push_obstacks_nochange ();
5470 if (current_class_depth == 1)
5471 current_obstack = &permanent_obstack;
5472 }
5473
5474 /* Build a dummy reference to ourselves so Derived::Base (and A::A) works,
5475 according to [class]:
5476 The class-name is also inserted
5477 into the scope of the class itself. For purposes of access checking,
5478 the inserted class name is treated as if it were a public member name. */
5479
5480 tree
5481 build_self_reference ()
5482 {
5483 tree name = constructor_name (current_class_type);
5484 tree value = build_lang_decl (TYPE_DECL, name, current_class_type);
5485 DECL_NONLOCAL (value) = 1;
5486 DECL_CONTEXT (value) = current_class_type;
5487 DECL_CLASS_CONTEXT (value) = current_class_type;
5488 CLASSTYPE_LOCAL_TYPEDECLS (current_class_type) = 1;
5489 DECL_ARTIFICIAL (value) = 1;
5490
5491 pushdecl_class_level (value);
5492 return value;
5493 }
This page took 0.283511 seconds and 5 git commands to generate.