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