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