Deleted Added
full compact
class.c (18334) class.c (50397)
1/* Functions related to building classes and their related objects.
1/* Functions related to building classes and their related objects.
2 Copyright (C) 1987, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
2 Copyright (C) 1987, 92, 93, 94, 95, 96, 1997 Free Software Foundation, Inc.
3 Contributed by Michael Tiemann (tiemann@cygnus.com)
4
5This file is part of GNU CC.
6
7GNU CC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.

--- 4 unchanged lines hidden (view full) ---

15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU CC; see the file COPYING. If not, write to
19the Free Software Foundation, 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA. */
21
22
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.

--- 4 unchanged lines hidden (view full) ---

15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU CC; see the file COPYING. If not, write to
19the Free Software Foundation, 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA. */
21
22
23/* High-level class interface. */
23/* High-level class interface. */
24
25#include "config.h"
24
25#include "config.h"
26#include "system.h"
26#include "tree.h"
27#include "tree.h"
27#include <stdio.h>
28#include "cp-tree.h"
29#include "flags.h"
30#include "rtl.h"
31#include "output.h"
28#include "cp-tree.h"
29#include "flags.h"
30#include "rtl.h"
31#include "output.h"
32#include "toplev.h"
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
33
34#include "obstack.h"
35#define obstack_chunk_alloc xmalloc
36#define obstack_chunk_free free
37
38extern struct obstack permanent_obstack;
39
40/* This is how we tell when two virtual member functions are really the
40 same. */
41 same. */
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;

--- 18 unchanged lines hidden (view full) ---

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
42#define SAME_FN(FN1DECL, FN2DECL) (DECL_ASSEMBLER_NAME (FN1DECL) == DECL_ASSEMBLER_NAME (FN2DECL))
43
44extern void set_class_shadows PROTO ((tree));
45
46/* Way of stacking class types. */
47static tree *current_class_base, *current_class_stack;
48static int current_class_stacksize;
49int current_class_depth;

--- 18 unchanged lines hidden (view full) ---

68
69 /* Flags for this class level. */
70 int this_is_variable;
71 int memoized_lookups;
72 int save_memoized;
73 int unused;
74};
75
75tree current_class_decl, C_C_D; /* PARM_DECL: the class instance variable */
76/* The current_class_ptr is the pointer to the current class.
77 current_class_ref is the actual current class. */
78tree current_class_ptr, current_class_ref;
76
77/* The following two can be derived from the previous one */
78tree current_class_name; /* IDENTIFIER_NODE: name of current class */
79tree current_class_type; /* _TYPE: the type of the current class */
80tree previous_class_type; /* _TYPE: the previous type that was a class */
81tree previous_class_values; /* TREE_LIST: copy of the class_shadowed list
82 when leaving an outermost class scope. */
79
80/* The following two can be derived from the previous one */
81tree current_class_name; /* IDENTIFIER_NODE: name of current class */
82tree current_class_type; /* _TYPE: the type of the current class */
83tree previous_class_type; /* _TYPE: the previous type that was a class */
84tree previous_class_values; /* TREE_LIST: copy of the class_shadowed list
85 when leaving an outermost class scope. */
86
87struct base_info;
88
83static tree get_vfield_name PROTO((tree));
89static tree get_vfield_name PROTO((tree));
84tree the_null_vtable_entry;
90static void finish_struct_anon PROTO((tree));
91static tree build_vbase_pointer PROTO((tree, tree));
92static int complete_type_p PROTO((tree));
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));
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));
106static void add_virtual_function PROTO((tree *, tree *, int *, tree, tree));
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, tree));
111static void handle_using_decl PROTO((tree, tree, tree, tree));
112static int overrides PROTO((tree, tree));
113static int strictly_overrides PROTO((tree, tree));
114static void merge_overrides PROTO((tree, tree, int, tree));
115static void override_one_vtable PROTO((tree, tree, tree));
116static void mark_overriders PROTO((tree, tree));
117static void check_for_override PROTO((tree, tree));
118static tree maybe_fixup_vptrs PROTO((tree, tree, tree));
119static tree get_class_offset_1 PROTO((tree, tree, tree, tree, tree));
120static tree get_class_offset PROTO((tree, tree, tree, tree));
121static void modify_one_vtable PROTO((tree, tree, tree, tree));
122static void modify_all_vtables PROTO((tree, tree, tree));
123static void modify_all_direct_vtables PROTO((tree, int, tree, tree,
124 tree));
125static void modify_all_indirect_vtables PROTO((tree, int, int, tree,
126 tree, tree));
127static void build_class_init_list PROTO((tree));
128static int finish_base_struct PROTO((tree, struct base_info *));
85
86/* Way of stacking language names. */
87tree *current_lang_base, *current_lang_stack;
88int current_lang_stacksize;
89
90/* Names of languages we recognize. */
129
130/* Way of stacking language names. */
131tree *current_lang_base, *current_lang_stack;
132int current_lang_stacksize;
133
134/* Names of languages we recognize. */
91tree lang_name_c, lang_name_cplusplus;
135tree lang_name_c, lang_name_cplusplus, lang_name_java;
92tree current_lang_name;
93
136tree current_lang_name;
137
94char *dont_allow_type_definitions;
95
96/* When layout out an aggregate type, the size of the
97 basetypes (virtual and non-virtual) is passed to layout_record
98 via this node. */
99static tree base_layout_decl;
100
138/* When layout out an aggregate type, the size of the
139 basetypes (virtual and non-virtual) is passed to layout_record
140 via this node. */
141static tree base_layout_decl;
142
143/* Constants used for access control. */
144tree access_default_node; /* 0 */
145tree access_public_node; /* 1 */
146tree access_protected_node; /* 2 */
147tree access_private_node; /* 3 */
148tree access_default_virtual_node; /* 4 */
149tree access_public_virtual_node; /* 5 */
150tree access_protected_virtual_node; /* 6 */
151tree access_private_virtual_node; /* 7 */
152
101/* Variables shared between class.c and call.c. */
102
153/* Variables shared between class.c and call.c. */
154
155#ifdef GATHER_STATISTICS
103int n_vtables = 0;
104int n_vtable_entries = 0;
105int n_vtable_searches = 0;
106int n_vtable_elems = 0;
107int n_convert_harshness = 0;
108int n_compute_conversion_costs = 0;
109int n_build_method_call = 0;
110int n_inner_fields_searched = 0;
156int n_vtables = 0;
157int n_vtable_entries = 0;
158int n_vtable_searches = 0;
159int n_vtable_elems = 0;
160int n_convert_harshness = 0;
161int n_compute_conversion_costs = 0;
162int n_build_method_call = 0;
163int n_inner_fields_searched = 0;
164#endif
111
112/* Virtual baseclass things. */
165
166/* Virtual baseclass things. */
113tree
167
168static tree
114build_vbase_pointer (exp, type)
115 tree exp, type;
116{
117 char *name;
118
119 name = (char *) alloca (TYPE_NAME_LENGTH (type) + sizeof (VBASE_NAME) + 1);
120 sprintf (name, VBASE_NAME_FORMAT, TYPE_NAME_STRING (type));
169build_vbase_pointer (exp, type)
170 tree exp, type;
171{
172 char *name;
173
174 name = (char *) alloca (TYPE_NAME_LENGTH (type) + sizeof (VBASE_NAME) + 1);
175 sprintf (name, VBASE_NAME_FORMAT, TYPE_NAME_STRING (type));
121 return build_component_ref (exp, get_identifier (name), 0, 0);
176 return build_component_ref (exp, get_identifier (name), NULL_TREE, 0);
122}
123
124/* Is the type of the EXPR, the complete type of the object?
177}
178
179/* Is the type of the EXPR, the complete type of the object?
125 If we are going to be wrong, we must be conservative, and return 0. */
126int
180 If we are going to be wrong, we must be conservative, and return 0. */
181
182static int
127complete_type_p (expr)
128 tree expr;
129{
130 tree type = TYPE_MAIN_VARIANT (TREE_TYPE (expr));
131 while (1)
132 {
133 switch (TREE_CODE (expr))
134 {
135 case SAVE_EXPR:
136 case INDIRECT_REF:
137 case ADDR_EXPR:
138 case NOP_EXPR:
139 case CONVERT_EXPR:
140 expr = TREE_OPERAND (expr, 0);
141 continue;
142
143 case CALL_EXPR:
144 if (! TREE_HAS_CONSTRUCTOR (expr))
145 break;
183complete_type_p (expr)
184 tree expr;
185{
186 tree type = TYPE_MAIN_VARIANT (TREE_TYPE (expr));
187 while (1)
188 {
189 switch (TREE_CODE (expr))
190 {
191 case SAVE_EXPR:
192 case INDIRECT_REF:
193 case ADDR_EXPR:
194 case NOP_EXPR:
195 case CONVERT_EXPR:
196 expr = TREE_OPERAND (expr, 0);
197 continue;
198
199 case CALL_EXPR:
200 if (! TREE_HAS_CONSTRUCTOR (expr))
201 break;
146 /* fall through... */
202 /* fall through... */
147 case VAR_DECL:
148 case FIELD_DECL:
149 if (TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
150 && IS_AGGR_TYPE (TREE_TYPE (TREE_TYPE (expr)))
151 && TYPE_MAIN_VARIANT (TREE_TYPE (expr)) == type)
152 return 1;
203 case VAR_DECL:
204 case FIELD_DECL:
205 if (TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
206 && IS_AGGR_TYPE (TREE_TYPE (TREE_TYPE (expr)))
207 && TYPE_MAIN_VARIANT (TREE_TYPE (expr)) == type)
208 return 1;
153 /* fall through... */
209 /* fall through... */
154 case TARGET_EXPR:
155 case PARM_DECL:
156 if (IS_AGGR_TYPE (TREE_TYPE (expr))
157 && TYPE_MAIN_VARIANT (TREE_TYPE (expr)) == type)
158 return 1;
210 case TARGET_EXPR:
211 case PARM_DECL:
212 if (IS_AGGR_TYPE (TREE_TYPE (expr))
213 && TYPE_MAIN_VARIANT (TREE_TYPE (expr)) == type)
214 return 1;
159 /* fall through... */
215 /* fall through... */
160 case PLUS_EXPR:
161 default:
162 break;
163 }
164 break;
165 }
166 return 0;
167}
168
169/* Build multi-level access to EXPR using hierarchy path PATH.
170 CODE is PLUS_EXPR if we are going with the grain,
171 and MINUS_EXPR if we are not (in which case, we cannot traverse
172 virtual baseclass links).
173
174 TYPE is the type we want this path to have on exit.
175
176 ALIAS_THIS is non-zero if EXPR in an expression involving `this'. */
216 case PLUS_EXPR:
217 default:
218 break;
219 }
220 break;
221 }
222 return 0;
223}
224
225/* Build multi-level access to EXPR using hierarchy path PATH.
226 CODE is PLUS_EXPR if we are going with the grain,
227 and MINUS_EXPR if we are not (in which case, we cannot traverse
228 virtual baseclass links).
229
230 TYPE is the type we want this path to have on exit.
231
232 ALIAS_THIS is non-zero if EXPR in an expression involving `this'. */
233
177tree
178build_vbase_path (code, type, expr, path, alias_this)
179 enum tree_code code;
180 tree type, expr, path;
181 int alias_this;
182{
183 register int changed = 0;
184 tree last = NULL_TREE, last_virtual = NULL_TREE;
185 int nonnull = 0;
234tree
235build_vbase_path (code, type, expr, path, alias_this)
236 enum tree_code code;
237 tree type, expr, path;
238 int alias_this;
239{
240 register int changed = 0;
241 tree last = NULL_TREE, last_virtual = NULL_TREE;
242 int nonnull = 0;
186 int fixed_type_p = resolves_to_fixed_type_p (expr, &nonnull);
243 int fixed_type_p;
187 tree null_expr = 0, nonnull_expr;
188 tree basetype;
189 tree offset = integer_zero_node;
190
244 tree null_expr = 0, nonnull_expr;
245 tree basetype;
246 tree offset = integer_zero_node;
247
248 if (BINFO_INHERITANCE_CHAIN (path) == NULL_TREE)
249 return build1 (NOP_EXPR, type, expr);
250
191 if (nonnull == 0 && (alias_this && flag_this_is_variable <= 0))
192 nonnull = 1;
193
251 if (nonnull == 0 && (alias_this && flag_this_is_variable <= 0))
252 nonnull = 1;
253
254#if 0
194 /* We need additional logic to convert back to the unconverted type
195 (the static type of the complete object), and then convert back
196 to the type we want. Until that is done, or until we can
197 recognize when that is, we cannot do the short cut logic. (mrs) */
255 /* We need additional logic to convert back to the unconverted type
256 (the static type of the complete object), and then convert back
257 to the type we want. Until that is done, or until we can
258 recognize when that is, we cannot do the short cut logic. (mrs) */
259 fixed_type_p = resolves_to_fixed_type_p (expr, &nonnull);
260#else
198 /* Do this, until we can undo any previous conversions. See net35.C
261 /* Do this, until we can undo any previous conversions. See net35.C
199 for a testcase. */
262 for a testcase. */
200 fixed_type_p = complete_type_p (expr);
263 fixed_type_p = complete_type_p (expr);
264#endif
201
202 if (!fixed_type_p && TREE_SIDE_EFFECTS (expr))
203 expr = save_expr (expr);
204 nonnull_expr = expr;
205
206 if (BINFO_INHERITANCE_CHAIN (path))
207 {
208 tree reverse_path = NULL_TREE;
209
265
266 if (!fixed_type_p && TREE_SIDE_EFFECTS (expr))
267 expr = save_expr (expr);
268 nonnull_expr = expr;
269
270 if (BINFO_INHERITANCE_CHAIN (path))
271 {
272 tree reverse_path = NULL_TREE;
273
274 push_expression_obstack ();
210 while (path)
211 {
212 tree r = copy_node (path);
213 BINFO_INHERITANCE_CHAIN (r) = reverse_path;
214 reverse_path = r;
215 path = BINFO_INHERITANCE_CHAIN (path);
216 }
217 path = reverse_path;
275 while (path)
276 {
277 tree r = copy_node (path);
278 BINFO_INHERITANCE_CHAIN (r) = reverse_path;
279 reverse_path = r;
280 path = BINFO_INHERITANCE_CHAIN (path);
281 }
282 path = reverse_path;
283 pop_obstacks ();
218 }
219
220 basetype = BINFO_TYPE (path);
221
222 while (path)
223 {
224 if (TREE_VIA_VIRTUAL (path))
225 {
226 last_virtual = BINFO_TYPE (path);
227 if (code == PLUS_EXPR)
228 {
229 changed = ! fixed_type_p;
230
231 if (changed)
232 {
284 }
285
286 basetype = BINFO_TYPE (path);
287
288 while (path)
289 {
290 if (TREE_VIA_VIRTUAL (path))
291 {
292 last_virtual = BINFO_TYPE (path);
293 if (code == PLUS_EXPR)
294 {
295 changed = ! fixed_type_p;
296
297 if (changed)
298 {
233 extern int flag_assume_nonnull_objects;
234 tree ind;
235
236 /* We already check for ambiguous things in the caller, just
299 tree ind;
300
301 /* We already check for ambiguous things in the caller, just
237 find a path. */
302 find a path. */
238 if (last)
239 {
240 tree binfo = get_binfo (last, TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (nonnull_expr))), 0);
241 nonnull_expr = convert_pointer_to_real (binfo, nonnull_expr);
242 }
243 ind = build_indirect_ref (nonnull_expr, NULL_PTR);
244 nonnull_expr = build_vbase_pointer (ind, last_virtual);
245 if (nonnull == 0

--- 27 unchanged lines hidden (view full) ---

273 /* LAST is now the last basetype assoc on the path. */
274
275 /* A pointer to a virtual base member of a non-null object
276 is non-null. Therefore, we only need to test for zeroness once.
277 Make EXPR the canonical expression to deal with here. */
278 if (null_expr)
279 {
280 TREE_OPERAND (expr, 2) = nonnull_expr;
303 if (last)
304 {
305 tree binfo = get_binfo (last, TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (nonnull_expr))), 0);
306 nonnull_expr = convert_pointer_to_real (binfo, nonnull_expr);
307 }
308 ind = build_indirect_ref (nonnull_expr, NULL_PTR);
309 nonnull_expr = build_vbase_pointer (ind, last_virtual);
310 if (nonnull == 0

--- 27 unchanged lines hidden (view full) ---

338 /* LAST is now the last basetype assoc on the path. */
339
340 /* A pointer to a virtual base member of a non-null object
341 is non-null. Therefore, we only need to test for zeroness once.
342 Make EXPR the canonical expression to deal with here. */
343 if (null_expr)
344 {
345 TREE_OPERAND (expr, 2) = nonnull_expr;
281 TREE_TYPE (TREE_OPERAND (expr, 1)) = TREE_TYPE (nonnull_expr);
346 TREE_TYPE (expr) = TREE_TYPE (TREE_OPERAND (expr, 1))
347 = TREE_TYPE (nonnull_expr);
282 }
283 else
284 expr = nonnull_expr;
285
286 /* If we go through any virtual base pointers, make sure that
287 casts to BASETYPE from the last virtual base class use
288 the right value for BASETYPE. */
289 if (changed)

--- 15 unchanged lines hidden (view full) ---

305 }
306 else
307 offset = BINFO_OFFSET (last);
308 }
309
310 if (TREE_INT_CST_LOW (offset))
311 {
312 /* Bash types to make the backend happy. */
348 }
349 else
350 expr = nonnull_expr;
351
352 /* If we go through any virtual base pointers, make sure that
353 casts to BASETYPE from the last virtual base class use
354 the right value for BASETYPE. */
355 if (changed)

--- 15 unchanged lines hidden (view full) ---

371 }
372 else
373 offset = BINFO_OFFSET (last);
374 }
375
376 if (TREE_INT_CST_LOW (offset))
377 {
378 /* Bash types to make the backend happy. */
313 offset = convert (type, offset);
379 offset = cp_convert (type, offset);
380#if 0
381 /* This shouldn't be necessary. (mrs) */
314 expr = build1 (NOP_EXPR, type, expr);
382 expr = build1 (NOP_EXPR, type, expr);
383#endif
315
316 /* For multiple inheritance: if `this' can be set by any
317 function, then it could be 0 on entry to any function.
318 Preserve such zeroness here. Otherwise, only in the
319 case of constructors need we worry, and in those cases,
320 it will be zero, or initialized to some valid value to
321 which we may add. */
322 if (nonnull == 0)

--- 21 unchanged lines hidden (view full) ---

344 return expr;
345 }
346 else
347 return build1 (NOP_EXPR, type, expr);
348}
349
350/* Virtual function things. */
351
384
385 /* For multiple inheritance: if `this' can be set by any
386 function, then it could be 0 on entry to any function.
387 Preserve such zeroness here. Otherwise, only in the
388 case of constructors need we worry, and in those cases,
389 it will be zero, or initialized to some valid value to
390 which we may add. */
391 if (nonnull == 0)

--- 21 unchanged lines hidden (view full) ---

413 return expr;
414 }
415 else
416 return build1 (NOP_EXPR, type, expr);
417}
418
419/* Virtual function things. */
420
352/* Virtual functions to be dealt with after laying out our base
353 classes. We do all overrides after we layout virtual base classes.
354 */
355static tree pending_hard_virtuals;
356static int doing_hard_virtuals;
357
358/* Build an entry in the virtual function table.
359 DELTA is the offset for the `this' pointer.
360 PFN is an ADDR_EXPR containing a pointer to the virtual function.
361 Note that the index (DELTA2) in the virtual function table
362 is always 0. */
421/* Build an entry in the virtual function table.
422 DELTA is the offset for the `this' pointer.
423 PFN is an ADDR_EXPR containing a pointer to the virtual function.
424 Note that the index (DELTA2) in the virtual function table
425 is always 0. */
363tree
426
427static tree
364build_vtable_entry (delta, pfn)
365 tree delta, pfn;
366{
428build_vtable_entry (delta, pfn)
429 tree delta, pfn;
430{
367
368 if (flag_vtable_thunks)
369 {
370 HOST_WIDE_INT idelta = TREE_INT_CST_LOW (delta);
431 if (flag_vtable_thunks)
432 {
433 HOST_WIDE_INT idelta = TREE_INT_CST_LOW (delta);
371 extern tree make_thunk ();
372 if (idelta)
434 if (idelta && ! DECL_ABSTRACT_VIRTUAL_P (TREE_OPERAND (pfn, 0)))
373 {
374 pfn = build1 (ADDR_EXPR, vtable_entry_type,
375 make_thunk (pfn, idelta));
376 TREE_READONLY (pfn) = 1;
377 TREE_CONSTANT (pfn) = 1;
378 }
379#ifdef GATHER_STATISTICS
380 n_vtable_entries += 1;
381#endif
382 return pfn;
383 }
384 else
385 {
386 extern int flag_huge_objects;
435 {
436 pfn = build1 (ADDR_EXPR, vtable_entry_type,
437 make_thunk (pfn, idelta));
438 TREE_READONLY (pfn) = 1;
439 TREE_CONSTANT (pfn) = 1;
440 }
441#ifdef GATHER_STATISTICS
442 n_vtable_entries += 1;
443#endif
444 return pfn;
445 }
446 else
447 {
448 extern int flag_huge_objects;
387 tree elems = tree_cons (NULL_TREE, delta,
388 tree_cons (NULL_TREE, integer_zero_node,
389 build_tree_list (NULL_TREE, pfn)));
449 tree elems = expr_tree_cons (NULL_TREE, delta,
450 expr_tree_cons (NULL_TREE, integer_zero_node,
451 build_expr_list (NULL_TREE, pfn)));
390 tree entry = build (CONSTRUCTOR, vtable_entry_type, NULL_TREE, elems);
391
452 tree entry = build (CONSTRUCTOR, vtable_entry_type, NULL_TREE, elems);
453
392 /* DELTA is constructed by `size_int', which means it may be an
393 unsigned quantity on some platforms. Therefore, we cannot use
394 `int_fits_type_p', because when DELTA is really negative,
395 `force_fit_type' will make it look like a very large number. */
454 /* DELTA used to be constructed by `size_int' and/or size_binop,
455 which caused overflow problems when it was negative. That should
456 be fixed now. */
396
457
397 if ((TREE_INT_CST_LOW (TYPE_MAX_VALUE (delta_type_node))
398 < TREE_INT_CST_LOW (delta))
399 || (TREE_INT_CST_LOW (delta)
400 < TREE_INT_CST_LOW (TYPE_MIN_VALUE (delta_type_node))))
401 if (flag_huge_objects)
402 sorry ("object size exceeds built-in limit for virtual function table implementation");
403 else
404 sorry ("object size exceeds normal limit for virtual function table implementation, recompile all source and use -fhuge-objects");
405
458 if (! int_fits_type_p (delta, delta_type_node))
459 {
460 if (flag_huge_objects)
461 sorry ("object size exceeds built-in limit for virtual function table implementation");
462 else
463 sorry ("object size exceeds normal limit for virtual function table implementation, recompile all source and use -fhuge-objects");
464 }
465
406 TREE_CONSTANT (entry) = 1;
407 TREE_STATIC (entry) = 1;
408 TREE_READONLY (entry) = 1;
409
410#ifdef GATHER_STATISTICS
411 n_vtable_entries += 1;
412#endif
413
414 return entry;
415 }
416}
417
418/* Given an object INSTANCE, return an expression which yields the
466 TREE_CONSTANT (entry) = 1;
467 TREE_STATIC (entry) = 1;
468 TREE_READONLY (entry) = 1;
469
470#ifdef GATHER_STATISTICS
471 n_vtable_entries += 1;
472#endif
473
474 return entry;
475 }
476}
477
478/* Given an object INSTANCE, return an expression which yields the
419 virtual function corresponding to INDEX. There are many special
420 cases for INSTANCE which we take care of here, mainly to avoid
421 creating extra tree nodes when we don't have to. */
479 virtual function vtable element corresponding to INDEX. There are
480 many special cases for INSTANCE which we take care of here, mainly
481 to avoid creating extra tree nodes when we don't have to. */
482
422tree
483tree
423build_vfn_ref (ptr_to_instptr, instance, idx)
424 tree *ptr_to_instptr, instance;
425 tree idx;
484build_vtbl_ref (instance, idx)
485 tree instance, idx;
426{
486{
427 extern int building_cleanup;
428 tree vtbl, aref;
429 tree basetype = TREE_TYPE (instance);
430
431 if (TREE_CODE (basetype) == REFERENCE_TYPE)
432 basetype = TREE_TYPE (basetype);
433
487 tree vtbl, aref;
488 tree basetype = TREE_TYPE (instance);
489
490 if (TREE_CODE (basetype) == REFERENCE_TYPE)
491 basetype = TREE_TYPE (basetype);
492
434 if (instance == C_C_D)
493 if (instance == current_class_ref)
435 vtbl = build_indirect_ref (build_vfield_ref (instance, basetype),
436 NULL_PTR);
437 else
438 {
439 if (optimize)
440 {
441 /* Try to figure out what a reference refers to, and
442 access its virtual function table directly. */

--- 31 unchanged lines hidden (view full) ---

474 vtbl = TYPE_BINFO_VTABLE (basetype);
475 else
476 vtbl = build_indirect_ref (build_vfield_ref (instance, basetype),
477 NULL_PTR);
478 }
479 assemble_external (vtbl);
480 aref = build_array_ref (vtbl, idx);
481
494 vtbl = build_indirect_ref (build_vfield_ref (instance, basetype),
495 NULL_PTR);
496 else
497 {
498 if (optimize)
499 {
500 /* Try to figure out what a reference refers to, and
501 access its virtual function table directly. */

--- 31 unchanged lines hidden (view full) ---

533 vtbl = TYPE_BINFO_VTABLE (basetype);
534 else
535 vtbl = build_indirect_ref (build_vfield_ref (instance, basetype),
536 NULL_PTR);
537 }
538 assemble_external (vtbl);
539 aref = build_array_ref (vtbl, idx);
540
482 /* Save the intermediate result in a SAVE_EXPR so we don't have to
483 compute each component of the virtual function pointer twice. */
484 if (!building_cleanup && TREE_CODE (aref) == INDIRECT_REF)
485 TREE_OPERAND (aref, 0) = save_expr (TREE_OPERAND (aref, 0));
541 return aref;
542}
486
543
544/* Given an object INSTANCE, return an expression which yields the
545 virtual function corresponding to INDEX. There are many special
546 cases for INSTANCE which we take care of here, mainly to avoid
547 creating extra tree nodes when we don't have to. */
548
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);
555
556 /* When using thunks, there is no extra delta, and we get the pfn
557 directly. */
487 if (flag_vtable_thunks)
488 return aref;
558 if (flag_vtable_thunks)
559 return aref;
489 else
560
561 if (ptr_to_instptr)
490 {
562 {
491 if (ptr_to_instptr)
492 *ptr_to_instptr
493 = build (PLUS_EXPR, TREE_TYPE (*ptr_to_instptr),
494 *ptr_to_instptr,
495 convert (ptrdiff_type_node,
496 build_component_ref (aref, delta_identifier, 0, 0)));
497 return build_component_ref (aref, pfn_identifier, 0, 0);
563 /* Save the intermediate result in a SAVE_EXPR so we don't have to
564 compute each component of the virtual function pointer twice. */
565 if (TREE_CODE (aref) == INDIRECT_REF)
566 TREE_OPERAND (aref, 0) = save_expr (TREE_OPERAND (aref, 0));
567
568 *ptr_to_instptr
569 = build (PLUS_EXPR, TREE_TYPE (*ptr_to_instptr),
570 *ptr_to_instptr,
571 cp_convert (ptrdiff_type_node,
572 build_component_ref (aref, delta_identifier, NULL_TREE, 0)));
498 }
573 }
574
575 return build_component_ref (aref, pfn_identifier, NULL_TREE, 0);
499}
500
501/* Return the name of the virtual function table (as an IDENTIFIER_NODE)
502 for the given TYPE. */
576}
577
578/* Return the name of the virtual function table (as an IDENTIFIER_NODE)
579 for the given TYPE. */
580
503static tree
504get_vtable_name (type)
505 tree type;
506{
507 tree type_id = build_typename_overload (type);
581static tree
582get_vtable_name (type)
583 tree type;
584{
585 tree type_id = build_typename_overload (type);
508 char *buf = (char *)alloca (strlen (VTABLE_NAME_FORMAT)
509 + IDENTIFIER_LENGTH (type_id) + 2);
586 char *buf = (char *) alloca (strlen (VTABLE_NAME_FORMAT)
587 + IDENTIFIER_LENGTH (type_id) + 2);
510 char *ptr = IDENTIFIER_POINTER (type_id);
511 int i;
512 for (i = 0; ptr[i] == OPERATOR_TYPENAME_FORMAT[i]; i++) ;
513#if 0
514 /* We don't take off the numbers; prepare_fresh_vtable uses the
515 DECL_ASSEMBLER_NAME for the type, which includes the number
516 in `3foo'. If we were to pull them off here, we'd end up with
517 something like `_vt.foo.3bar', instead of a uniform definition. */
518 while (ptr[i] >= '0' && ptr[i] <= '9')
519 i += 1;
520#endif
521 sprintf (buf, VTABLE_NAME_FORMAT, ptr+i);
522 return get_identifier (buf);
523}
524
588 char *ptr = IDENTIFIER_POINTER (type_id);
589 int i;
590 for (i = 0; ptr[i] == OPERATOR_TYPENAME_FORMAT[i]; i++) ;
591#if 0
592 /* We don't take off the numbers; prepare_fresh_vtable uses the
593 DECL_ASSEMBLER_NAME for the type, which includes the number
594 in `3foo'. If we were to pull them off here, we'd end up with
595 something like `_vt.foo.3bar', instead of a uniform definition. */
596 while (ptr[i] >= '0' && ptr[i] <= '9')
597 i += 1;
598#endif
599 sprintf (buf, VTABLE_NAME_FORMAT, ptr+i);
600 return get_identifier (buf);
601}
602
603/* Return the offset to the main vtable for a given base BINFO. */
604
605tree
606get_vfield_offset (binfo)
607 tree binfo;
608{
609 tree tmp
610 = size_binop (FLOOR_DIV_EXPR,
611 DECL_FIELD_BITPOS (CLASSTYPE_VFIELD (BINFO_TYPE (binfo))),
612 size_int (BITS_PER_UNIT));
613 tmp = convert (sizetype, tmp);
614 return size_binop (PLUS_EXPR, tmp, BINFO_OFFSET (binfo));
615}
616
617/* Get the offset to the start of the original binfo that we derived
618 this binfo from. If we find TYPE first, return the offset only
619 that far. The shortened search is useful because the this pointer
620 on method calling is expected to point to a DECL_CONTEXT (fndecl)
621 object, and not a baseclass of it. */
622
623static tree
624get_derived_offset (binfo, type)
625 tree binfo, type;
626{
627 tree offset1 = get_vfield_offset (TYPE_BINFO (BINFO_TYPE (binfo)));
628 tree offset2;
629 int i;
630 while (BINFO_BASETYPES (binfo)
631 && (i=CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo))) != -1)
632 {
633 tree binfos = BINFO_BASETYPES (binfo);
634 if (BINFO_TYPE (binfo) == type)
635 break;
636 binfo = TREE_VEC_ELT (binfos, i);
637 }
638 offset2 = get_vfield_offset (TYPE_BINFO (BINFO_TYPE (binfo)));
639 return size_binop (MINUS_EXPR, offset1, offset2);
640}
641
642/* Update the rtti info for this class. */
643
644static void
645set_rtti_entry (virtuals, offset, type)
646 tree virtuals, offset, type;
647{
648 tree vfn;
649
650 if (flag_rtti)
651 vfn = build1 (ADDR_EXPR, vfunc_ptr_type_node, get_tinfo_fn (type));
652 else
653 vfn = build1 (NOP_EXPR, vfunc_ptr_type_node, size_zero_node);
654 TREE_CONSTANT (vfn) = 1;
655
656 if (! flag_vtable_thunks)
657 TREE_VALUE (virtuals) = build_vtable_entry (offset, vfn);
658 else
659 {
660 tree voff = build1 (NOP_EXPR, vfunc_ptr_type_node, offset);
661 TREE_CONSTANT (voff) = 1;
662
663 TREE_VALUE (virtuals) = build_vtable_entry (integer_zero_node, voff);
664
665 /* The second slot is for the tdesc pointer when thunks are used. */
666 TREE_VALUE (TREE_CHAIN (virtuals))
667 = build_vtable_entry (integer_zero_node, vfn);
668 }
669}
670
525/* Build a virtual function for type TYPE.
526 If BINFO is non-NULL, build the vtable starting with the initial
527 approximation that it is the same as the one which is the head of
528 the association list. */
671/* Build a virtual function for type TYPE.
672 If BINFO is non-NULL, build the vtable starting with the initial
673 approximation that it is the same as the one which is the head of
674 the association list. */
675
529static tree
530build_vtable (binfo, type)
531 tree binfo, type;
532{
533 tree name = get_vtable_name (type);
534 tree virtuals, decl;
535
536 if (binfo)
537 {
676static tree
677build_vtable (binfo, type)
678 tree binfo, type;
679{
680 tree name = get_vtable_name (type);
681 tree virtuals, decl;
682
683 if (binfo)
684 {
685 tree offset;
686
538 virtuals = copy_list (BINFO_VIRTUALS (binfo));
539 decl = build_decl (VAR_DECL, name, TREE_TYPE (BINFO_VTABLE (binfo)));
687 virtuals = copy_list (BINFO_VIRTUALS (binfo));
688 decl = build_decl (VAR_DECL, name, TREE_TYPE (BINFO_VTABLE (binfo)));
689
690 /* Now do rtti stuff. */
691 offset = get_derived_offset (TYPE_BINFO (type), NULL_TREE);
692 offset = ssize_binop (MINUS_EXPR, integer_zero_node, offset);
693 set_rtti_entry (virtuals, offset, type);
540 }
541 else
542 {
543 virtuals = NULL_TREE;
544 decl = build_decl (VAR_DECL, name, void_type_node);
545 }
546
547#ifdef GATHER_STATISTICS
548 n_vtables += 1;
549 n_vtable_elems += list_length (virtuals);
550#endif
551
552 /* Set TREE_PUBLIC and TREE_EXTERN as appropriate. */
553 import_export_vtable (decl, type, 0);
554
694 }
695 else
696 {
697 virtuals = NULL_TREE;
698 decl = build_decl (VAR_DECL, name, void_type_node);
699 }
700
701#ifdef GATHER_STATISTICS
702 n_vtables += 1;
703 n_vtable_elems += list_length (virtuals);
704#endif
705
706 /* Set TREE_PUBLIC and TREE_EXTERN as appropriate. */
707 import_export_vtable (decl, type, 0);
708
555 IDENTIFIER_GLOBAL_VALUE (name) = decl = pushdecl_top_level (decl);
709 decl = pushdecl_top_level (decl);
710 SET_IDENTIFIER_GLOBAL_VALUE (name, decl);
556 /* Initialize the association list for this type, based
557 on our first approximation. */
558 TYPE_BINFO_VTABLE (type) = decl;
559 TYPE_BINFO_VIRTUALS (type) = virtuals;
560
711 /* Initialize the association list for this type, based
712 on our first approximation. */
713 TYPE_BINFO_VTABLE (type) = decl;
714 TYPE_BINFO_VIRTUALS (type) = virtuals;
715
716 DECL_ARTIFICIAL (decl) = 1;
561 TREE_STATIC (decl) = 1;
562#ifndef WRITABLE_VTABLES
563 /* Make them READONLY by default. (mrs) */
564 TREE_READONLY (decl) = 1;
565#endif
566 /* At one time the vtable info was grabbed 2 words at a time. This
567 fails on sparc unless you have 8-byte alignment. (tiemann) */
568 DECL_ALIGN (decl) = MAX (TYPE_ALIGN (double_type_node),

--- 4 unchanged lines hidden (view full) ---

573 DECL_VIRTUAL_P (decl) = 1;
574 DECL_CONTEXT (decl) = type;
575
576 binfo = TYPE_BINFO (type);
577 SET_BINFO_NEW_VTABLE_MARKED (binfo);
578 return decl;
579}
580
717 TREE_STATIC (decl) = 1;
718#ifndef WRITABLE_VTABLES
719 /* Make them READONLY by default. (mrs) */
720 TREE_READONLY (decl) = 1;
721#endif
722 /* At one time the vtable info was grabbed 2 words at a time. This
723 fails on sparc unless you have 8-byte alignment. (tiemann) */
724 DECL_ALIGN (decl) = MAX (TYPE_ALIGN (double_type_node),

--- 4 unchanged lines hidden (view full) ---

729 DECL_VIRTUAL_P (decl) = 1;
730 DECL_CONTEXT (decl) = type;
731
732 binfo = TYPE_BINFO (type);
733 SET_BINFO_NEW_VTABLE_MARKED (binfo);
734 return decl;
735}
736
581/* Given a base type PARENT, and a derived type TYPE, build
582 a name which distinguishes exactly the PARENT member of TYPE's type.
737extern tree signed_size_zero_node;
583
738
584 FORMAT is a string which controls how sprintf formats the name
585 we have generated.
739/* Give TYPE a new virtual function table which is initialized
740 with a skeleton-copy of its original initialization. The only
741 entry that changes is the `delta' entry, so we can really
742 share a lot of structure.
586
743
587 For example, given
744 FOR_TYPE is the derived type which caused this table to
745 be needed.
588
746
589 class A; class B; class C : A, B;
747 BINFO is the type association which provided TYPE for FOR_TYPE.
590
748
591 it is possible to distinguish "A" from "C's A". And given
749 The order in which vtables are built (by calling this function) for
750 an object must remain the same, otherwise a binary incompatibility
751 can result. */
592
752
593 class L;
594 class A : L; class B : L; class C : A, B;
595
596 it is possible to distinguish "L" from "A's L", and also from
597 "C's L from A".
598
599 Make sure to use the DECL_ASSEMBLER_NAME of the TYPE_NAME of the
600 type, as template have DECL_NAMEs like: X<int>, whereas the
601 DECL_ASSEMBLER_NAME is set to be something the assembler can handle.
602 */
603static tree
604build_type_pathname (format, parent, type)
605 char *format;
606 tree parent, type;
753static void
754prepare_fresh_vtable (binfo, for_type)
755 tree binfo, for_type;
607{
756{
608 extern struct obstack temporary_obstack;
609 char *first, *base, *name;
757 tree basetype;
758 tree orig_decl = BINFO_VTABLE (binfo);
759 tree name;
760 tree new_decl;
761 tree offset;
762 tree path = binfo;
763 char *buf, *buf2;
764 char joiner = '_';
610 int i;
765 int i;
611 tree id;
612
766
613 parent = TYPE_MAIN_VARIANT (parent);
614
615 /* Remember where to cut the obstack to. */
616 first = obstack_base (&temporary_obstack);
617
618 /* Put on TYPE+PARENT. */
619 obstack_grow (&temporary_obstack,
620 TYPE_ASSEMBLER_NAME_STRING (type),
621 TYPE_ASSEMBLER_NAME_LENGTH (type));
622#ifdef JOINER
767#ifdef JOINER
623 obstack_1grow (&temporary_obstack, JOINER);
624#else
625 obstack_1grow (&temporary_obstack, '_');
768 joiner = JOINER;
626#endif
769#endif
627 obstack_grow0 (&temporary_obstack,
628 TYPE_ASSEMBLER_NAME_STRING (parent),
629 TYPE_ASSEMBLER_NAME_LENGTH (parent));
630 i = obstack_object_size (&temporary_obstack);
631 base = obstack_base (&temporary_obstack);
632 obstack_finish (&temporary_obstack);
633
770
634 /* Put on FORMAT+TYPE+PARENT. */
635 obstack_blank (&temporary_obstack, strlen (format) + i + 1);
636 name = obstack_base (&temporary_obstack);
637 sprintf (name, format, base);
638 id = get_identifier (name);
639 obstack_free (&temporary_obstack, first);
771 basetype = TYPE_MAIN_VARIANT (BINFO_TYPE (binfo));
640
772
641 return id;
642}
773 buf2 = TYPE_ASSEMBLER_NAME_STRING (basetype);
774 i = TYPE_ASSEMBLER_NAME_LENGTH (basetype) + 1;
643
775
644/* Update the rtti info for this class. */
645static void
646set_rtti_entry (virtuals, offset, type)
647 tree virtuals, offset, type;
648{
649 if (! flag_vtable_thunks)
650 TREE_VALUE (virtuals)
651 = build_vtable_entry (offset,
652 (flag_rtti
653 ? build_t_desc (type, 0)
654 : integer_zero_node));
655 else
776 /* We know that the vtable that we are going to create doesn't exist
777 yet in the global namespace, and when we finish, it will be
778 pushed into the global namespace. In complex MI hierarchies, we
779 have to loop while the name we are thinking of adding is globally
780 defined, adding more name components to the vtable name as we
781 loop, until the name is unique. This is because in complex MI
782 cases, we might have the same base more than once. This means
783 that the order in which this function is called for vtables must
784 remain the same, otherwise binary compatibility can be
785 compromised. */
786
787 while (1)
656 {
788 {
657 tree vfn = build1 (NOP_EXPR, vfunc_ptr_type_node, offset);
658 TREE_CONSTANT (vfn) = 1;
789 char *buf1 = (char *) alloca (TYPE_ASSEMBLER_NAME_LENGTH (for_type)
790 + 1 + i);
791 char *new_buf2;
659
792
660 TREE_VALUE (virtuals)
661 = build_vtable_entry (integer_zero_node, vfn);
662 /* The second slot is for the tdesc pointer when thunks are used. */
663 vfn = flag_rtti
664 ? build_t_desc (type, 0)
665 : integer_zero_node;
666 vfn = build1 (NOP_EXPR, vfunc_ptr_type_node, vfn);
667 TREE_CONSTANT (vfn) = 1;
793 sprintf (buf1, "%s%c%s", TYPE_ASSEMBLER_NAME_STRING (for_type), joiner,
794 buf2);
795 buf = (char *) alloca (strlen (VTABLE_NAME_FORMAT) + strlen (buf1) + 1);
796 sprintf (buf, VTABLE_NAME_FORMAT, buf1);
797 name = get_identifier (buf);
668
798
669 TREE_VALUE (TREE_CHAIN (virtuals))
670 = build_vtable_entry (integer_zero_node, vfn);
671 }
672}
799 /* If this name doesn't clash, then we can use it, otherwise
800 we add more to the name until it is unique. */
673
801
674/* Give TYPE a new virtual function table which is initialized
675 with a skeleton-copy of its original initialization. The only
676 entry that changes is the `delta' entry, so we can really
677 share a lot of structure.
802 if (! IDENTIFIER_GLOBAL_VALUE (name))
803 break;
678
804
679 FOR_TYPE is the derived type which caused this table to
680 be needed.
805 /* Set values for next loop through, if the name isn't unique. */
681
806
682 BINFO is the type association which provided TYPE for FOR_TYPE. */
683static void
684prepare_fresh_vtable (binfo, for_type)
685 tree binfo, for_type;
686{
687 tree basetype = BINFO_TYPE (binfo);
688 tree orig_decl = BINFO_VTABLE (binfo);
689 /* This name is too simplistic. We can have multiple basetypes for
690 for_type, and we really want different names. (mrs) */
691 tree name = build_type_pathname (VTABLE_NAME_FORMAT, basetype, for_type);
692 tree new_decl = build_decl (VAR_DECL, name, TREE_TYPE (orig_decl));
693 tree path, offset;
694 int result;
807 path = BINFO_INHERITANCE_CHAIN (path);
695
808
809 /* We better not run out of stuff to make it unique. */
810 my_friendly_assert (path != NULL_TREE, 368);
811
812 basetype = TYPE_MAIN_VARIANT (BINFO_TYPE (path));
813
814 if (for_type == basetype)
815 {
816 /* If we run out of basetypes in the path, we have already
817 found created a vtable with that name before, we now
818 resort to tacking on _%d to distinguish them. */
819 int j = 2;
820 i = TYPE_ASSEMBLER_NAME_LENGTH (basetype) + 1 + i + 1 + 3;
821 buf1 = (char *) alloca (i);
822 do {
823 sprintf (buf1, "%s%c%s%c%d",
824 TYPE_ASSEMBLER_NAME_STRING (basetype), joiner,
825 buf2, joiner, j);
826 buf = (char *) alloca (strlen (VTABLE_NAME_FORMAT)
827 + strlen (buf1) + 1);
828 sprintf (buf, VTABLE_NAME_FORMAT, buf1);
829 name = get_identifier (buf);
830
831 /* If this name doesn't clash, then we can use it,
832 otherwise we add something different to the name until
833 it is unique. */
834 } while (++j <= 999 && IDENTIFIER_GLOBAL_VALUE (name));
835
836 /* Hey, they really like MI don't they? Increase the 3
837 above to 6, and the 999 to 999999. :-) */
838 my_friendly_assert (j <= 999, 369);
839
840 break;
841 }
842
843 i = TYPE_ASSEMBLER_NAME_LENGTH (basetype) + 1 + i;
844 new_buf2 = (char *) alloca (i);
845 sprintf (new_buf2, "%s%c%s",
846 TYPE_ASSEMBLER_NAME_STRING (basetype), joiner, buf2);
847 buf2 = new_buf2;
848 }
849
850 new_decl = build_decl (VAR_DECL, name, TREE_TYPE (orig_decl));
696 /* Remember which class this vtable is really for. */
697 DECL_CONTEXT (new_decl) = for_type;
698
851 /* Remember which class this vtable is really for. */
852 DECL_CONTEXT (new_decl) = for_type;
853
854 DECL_ARTIFICIAL (new_decl) = 1;
699 TREE_STATIC (new_decl) = 1;
700 BINFO_VTABLE (binfo) = pushdecl_top_level (new_decl);
701 DECL_VIRTUAL_P (new_decl) = 1;
702#ifndef WRITABLE_VTABLES
703 /* Make them READONLY by default. (mrs) */
704 TREE_READONLY (new_decl) = 1;
705#endif
706 DECL_ALIGN (new_decl) = DECL_ALIGN (orig_decl);
707
708 /* Make fresh virtual list, so we can smash it later. */
709 BINFO_VIRTUALS (binfo) = copy_list (BINFO_VIRTUALS (binfo));
710
711 if (TREE_VIA_VIRTUAL (binfo))
855 TREE_STATIC (new_decl) = 1;
856 BINFO_VTABLE (binfo) = pushdecl_top_level (new_decl);
857 DECL_VIRTUAL_P (new_decl) = 1;
858#ifndef WRITABLE_VTABLES
859 /* Make them READONLY by default. (mrs) */
860 TREE_READONLY (new_decl) = 1;
861#endif
862 DECL_ALIGN (new_decl) = DECL_ALIGN (orig_decl);
863
864 /* Make fresh virtual list, so we can smash it later. */
865 BINFO_VIRTUALS (binfo) = copy_list (BINFO_VIRTUALS (binfo));
866
867 if (TREE_VIA_VIRTUAL (binfo))
712 offset = BINFO_OFFSET (binfo_member (BINFO_TYPE (binfo),
713 CLASSTYPE_VBASECLASSES (for_type)));
868 {
869 tree binfo1 = binfo_member (BINFO_TYPE (binfo),
870 CLASSTYPE_VBASECLASSES (for_type));
871
872 /* XXX - This should never happen, if it does, the caller should
873 ensure that the binfo is from for_type's binfos, not from any
874 base type's. We can remove all this code after a while. */
875 if (binfo1 != binfo)
876 warning ("internal inconsistency: binfo offset error for rtti");
877
878 offset = BINFO_OFFSET (binfo1);
879 }
714 else
715 offset = BINFO_OFFSET (binfo);
716
717 set_rtti_entry (BINFO_VIRTUALS (binfo),
880 else
881 offset = BINFO_OFFSET (binfo);
882
883 set_rtti_entry (BINFO_VIRTUALS (binfo),
718 size_binop (MINUS_EXPR, integer_zero_node, offset),
884 ssize_binop (MINUS_EXPR, integer_zero_node, offset),
719 for_type);
720
721#ifdef GATHER_STATISTICS
722 n_vtables += 1;
723 n_vtable_elems += list_length (BINFO_VIRTUALS (binfo));
724#endif
725
726 /* Set TREE_PUBLIC and TREE_EXTERN as appropriate. */
727 import_export_vtable (new_decl, for_type, 0);
728
729 if (TREE_VIA_VIRTUAL (binfo))
730 my_friendly_assert (binfo == binfo_member (BINFO_TYPE (binfo),
731 CLASSTYPE_VBASECLASSES (current_class_type)),
732 170);
733 SET_BINFO_NEW_VTABLE_MARKED (binfo);
734}
735
885 for_type);
886
887#ifdef GATHER_STATISTICS
888 n_vtables += 1;
889 n_vtable_elems += list_length (BINFO_VIRTUALS (binfo));
890#endif
891
892 /* Set TREE_PUBLIC and TREE_EXTERN as appropriate. */
893 import_export_vtable (new_decl, for_type, 0);
894
895 if (TREE_VIA_VIRTUAL (binfo))
896 my_friendly_assert (binfo == binfo_member (BINFO_TYPE (binfo),
897 CLASSTYPE_VBASECLASSES (current_class_type)),
898 170);
899 SET_BINFO_NEW_VTABLE_MARKED (binfo);
900}
901
902#if 0
736/* Access the virtual function table entry that logically
737 contains BASE_FNDECL. VIRTUALS is the virtual function table's
738 initializer. We can run off the end, when dealing with virtual
739 destructors in MI situations, return NULL_TREE in that case. */
903/* Access the virtual function table entry that logically
904 contains BASE_FNDECL. VIRTUALS is the virtual function table's
905 initializer. We can run off the end, when dealing with virtual
906 destructors in MI situations, return NULL_TREE in that case. */
907
740static tree
741get_vtable_entry (virtuals, base_fndecl)
742 tree virtuals, base_fndecl;
743{
744 unsigned HOST_WIDE_INT n = (HOST_BITS_PER_WIDE_INT >= BITS_PER_WORD
745 ? (TREE_INT_CST_LOW (DECL_VINDEX (base_fndecl))
746 & (((unsigned HOST_WIDE_INT)1<<(BITS_PER_WORD-1))-1))
747 : TREE_INT_CST_LOW (DECL_VINDEX (base_fndecl)));

--- 4 unchanged lines hidden (view full) ---

752
753 while (n > 0 && virtuals)
754 {
755 --n;
756 virtuals = TREE_CHAIN (virtuals);
757 }
758 return virtuals;
759}
908static tree
909get_vtable_entry (virtuals, base_fndecl)
910 tree virtuals, base_fndecl;
911{
912 unsigned HOST_WIDE_INT n = (HOST_BITS_PER_WIDE_INT >= BITS_PER_WORD
913 ? (TREE_INT_CST_LOW (DECL_VINDEX (base_fndecl))
914 & (((unsigned HOST_WIDE_INT)1<<(BITS_PER_WORD-1))-1))
915 : TREE_INT_CST_LOW (DECL_VINDEX (base_fndecl)));

--- 4 unchanged lines hidden (view full) ---

920
921 while (n > 0 && virtuals)
922 {
923 --n;
924 virtuals = TREE_CHAIN (virtuals);
925 }
926 return virtuals;
927}
928#endif
760
761/* Put new entry ENTRY into virtual function table initializer
762 VIRTUALS.
763
764 Also update DECL_VINDEX (FNDECL). */
765
766static void
767modify_vtable_entry (old_entry_in_list, new_entry, fndecl)
768 tree old_entry_in_list, new_entry, fndecl;
769{
770 tree base_fndecl = TREE_OPERAND (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (old_entry_in_list)), 0);
771
772#ifdef NOTQUITE
773 cp_warning ("replaced %D with %D", DECL_ASSEMBLER_NAME (base_fndecl),
774 DECL_ASSEMBLER_NAME (fndecl));
775#endif
776 TREE_VALUE (old_entry_in_list) = new_entry;
777
778 /* Now assign virtual dispatch information, if unset. */
929
930/* Put new entry ENTRY into virtual function table initializer
931 VIRTUALS.
932
933 Also update DECL_VINDEX (FNDECL). */
934
935static void
936modify_vtable_entry (old_entry_in_list, new_entry, fndecl)
937 tree old_entry_in_list, new_entry, fndecl;
938{
939 tree base_fndecl = TREE_OPERAND (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (old_entry_in_list)), 0);
940
941#ifdef NOTQUITE
942 cp_warning ("replaced %D with %D", DECL_ASSEMBLER_NAME (base_fndecl),
943 DECL_ASSEMBLER_NAME (fndecl));
944#endif
945 TREE_VALUE (old_entry_in_list) = new_entry;
946
947 /* Now assign virtual dispatch information, if unset. */
779 /* We can dispatch this, through any overridden base function. */
948 /* We can dispatch this, through any overridden base function. */
780 if (TREE_CODE (DECL_VINDEX (fndecl)) != INTEGER_CST)
781 {
782 DECL_VINDEX (fndecl) = DECL_VINDEX (base_fndecl);
783 DECL_CONTEXT (fndecl) = DECL_CONTEXT (base_fndecl);
784 }
785}
786
949 if (TREE_CODE (DECL_VINDEX (fndecl)) != INTEGER_CST)
950 {
951 DECL_VINDEX (fndecl) = DECL_VINDEX (base_fndecl);
952 DECL_CONTEXT (fndecl) = DECL_CONTEXT (base_fndecl);
953 }
954}
955
787/* Access the virtual function table entry i. VIRTUALS is the virtual
956/* Access the virtual function table entry N. VIRTUALS is the virtual
788 function table's initializer. */
957 function table's initializer. */
958
789static tree
790get_vtable_entry_n (virtuals, n)
791 tree virtuals;
792 unsigned HOST_WIDE_INT n;
793{
794 while (n > 0)
795 {
796 --n;

--- 4 unchanged lines hidden (view full) ---

801
802/* Add a virtual function to all the appropriate vtables for the class
803 T. DECL_VINDEX(X) should be error_mark_node, if we want to
804 allocate a new slot in our table. If it is error_mark_node, we
805 know that no other function from another vtable is overridden by X.
806 HAS_VIRTUAL keeps track of how many virtuals there are in our main
807 vtable for the type, and we build upon the PENDING_VIRTUALS list
808 and return it. */
959static tree
960get_vtable_entry_n (virtuals, n)
961 tree virtuals;
962 unsigned HOST_WIDE_INT n;
963{
964 while (n > 0)
965 {
966 --n;

--- 4 unchanged lines hidden (view full) ---

971
972/* Add a virtual function to all the appropriate vtables for the class
973 T. DECL_VINDEX(X) should be error_mark_node, if we want to
974 allocate a new slot in our table. If it is error_mark_node, we
975 know that no other function from another vtable is overridden by X.
976 HAS_VIRTUAL keeps track of how many virtuals there are in our main
977 vtable for the type, and we build upon the PENDING_VIRTUALS list
978 and return it. */
809static tree
810add_virtual_function (pending_virtuals, has_virtual, fndecl, t)
811 tree pending_virtuals;
979
980static void
981add_virtual_function (pv, phv, has_virtual, fndecl, t)
982 tree *pv, *phv;
812 int *has_virtual;
813 tree fndecl;
983 int *has_virtual;
984 tree fndecl;
814 tree t; /* Structure type. */
985 tree t; /* Structure type. */
815{
986{
987 tree pending_virtuals = *pv;
988 tree pending_hard_virtuals = *phv;
989
816 /* FUNCTION_TYPEs and OFFSET_TYPEs no longer freely
817 convert to void *. Make such a conversion here. */
818 tree vfn = build1 (ADDR_EXPR, vfunc_ptr_type_node, fndecl);
819 TREE_CONSTANT (vfn) = 1;
820
821#ifndef DUMB_USER
822 if (current_class_type == 0)
823 cp_warning ("internal problem, current_class_type is zero when adding `%D', please report",

--- 6 unchanged lines hidden (view full) ---

830 /* If the virtual function is a redefinition of a prior one,
831 figure out in which base class the new definition goes,
832 and if necessary, make a fresh virtual function table
833 to hold that entry. */
834 if (DECL_VINDEX (fndecl) == error_mark_node)
835 {
836 tree entry;
837
990 /* FUNCTION_TYPEs and OFFSET_TYPEs no longer freely
991 convert to void *. Make such a conversion here. */
992 tree vfn = build1 (ADDR_EXPR, vfunc_ptr_type_node, fndecl);
993 TREE_CONSTANT (vfn) = 1;
994
995#ifndef DUMB_USER
996 if (current_class_type == 0)
997 cp_warning ("internal problem, current_class_type is zero when adding `%D', please report",

--- 6 unchanged lines hidden (view full) ---

1004 /* If the virtual function is a redefinition of a prior one,
1005 figure out in which base class the new definition goes,
1006 and if necessary, make a fresh virtual function table
1007 to hold that entry. */
1008 if (DECL_VINDEX (fndecl) == error_mark_node)
1009 {
1010 tree entry;
1011
838 if (flag_rtti && *has_virtual == 0)
839 {
840 /* CLASSTYPE_RTTI is only used as a Boolean (NULL or not). */
841 CLASSTYPE_RTTI (t) = integer_one_node;
842 }
1012 /* We remember that this was the base sub-object for rtti. */
1013 CLASSTYPE_RTTI (t) = t;
843
844 /* If we are using thunks, use two slots at the front, one
845 for the offset pointer, one for the tdesc pointer. */
846 if (*has_virtual == 0 && flag_vtable_thunks)
847 {
848 *has_virtual = 1;
849 }
850
851 /* Build a new INT_CST for this DECL_VINDEX. */
852 {
853 static tree index_table[256];
1014
1015 /* If we are using thunks, use two slots at the front, one
1016 for the offset pointer, one for the tdesc pointer. */
1017 if (*has_virtual == 0 && flag_vtable_thunks)
1018 {
1019 *has_virtual = 1;
1020 }
1021
1022 /* Build a new INT_CST for this DECL_VINDEX. */
1023 {
1024 static tree index_table[256];
854 tree index;
1025 tree idx;
855 /* We skip a slot for the offset/tdesc entry. */
856 int i = ++(*has_virtual);
857
858 if (i >= 256 || index_table[i] == 0)
859 {
1026 /* We skip a slot for the offset/tdesc entry. */
1027 int i = ++(*has_virtual);
1028
1029 if (i >= 256 || index_table[i] == 0)
1030 {
860 index = build_int_2 (i, 0);
1031 idx = build_int_2 (i, 0);
861 if (i < 256)
1032 if (i < 256)
862 index_table[i] = index;
1033 index_table[i] = idx;
863 }
864 else
1034 }
1035 else
865 index = index_table[i];
1036 idx = index_table[i];
866
1037
867 /* Now assign virtual dispatch information. */
868 DECL_VINDEX (fndecl) = index;
1038 /* Now assign virtual dispatch information. */
1039 DECL_VINDEX (fndecl) = idx;
869 DECL_CONTEXT (fndecl) = t;
870 }
871 entry = build_vtable_entry (integer_zero_node, vfn);
872 pending_virtuals = tree_cons (DECL_VINDEX (fndecl), entry, pending_virtuals);
873 }
874 /* Might already be INTEGER_CST if declared twice in class. We will
875 give error later or we've already given it. */
876 else if (TREE_CODE (DECL_VINDEX (fndecl)) != INTEGER_CST)
877 {
878 /* Need an entry in some other virtual function table.
879 Deal with this after we have laid out our virtual base classes. */
880 pending_hard_virtuals = temp_tree_cons (fndecl, vfn, pending_hard_virtuals);
881 }
1040 DECL_CONTEXT (fndecl) = t;
1041 }
1042 entry = build_vtable_entry (integer_zero_node, vfn);
1043 pending_virtuals = tree_cons (DECL_VINDEX (fndecl), entry, pending_virtuals);
1044 }
1045 /* Might already be INTEGER_CST if declared twice in class. We will
1046 give error later or we've already given it. */
1047 else if (TREE_CODE (DECL_VINDEX (fndecl)) != INTEGER_CST)
1048 {
1049 /* Need an entry in some other virtual function table.
1050 Deal with this after we have laid out our virtual base classes. */
1051 pending_hard_virtuals = temp_tree_cons (fndecl, vfn, pending_hard_virtuals);
1052 }
882 return pending_virtuals;
1053 *pv = pending_virtuals;
1054 *phv = pending_hard_virtuals;
883}
884
885/* Obstack on which to build the vector of class methods. */
886struct obstack class_obstack;
887extern struct obstack *current_obstack;
888
889/* Add method METHOD to class TYPE. This is used when a method
890 has been defined which did not initially appear in the class definition,
891 and helps cut down on spurious error messages.
892
893 FIELDS is the entry in the METHOD_VEC vector entry of the class type where
894 the method should be added. */
1055}
1056
1057/* Obstack on which to build the vector of class methods. */
1058struct obstack class_obstack;
1059extern struct obstack *current_obstack;
1060
1061/* Add method METHOD to class TYPE. This is used when a method
1062 has been defined which did not initially appear in the class definition,
1063 and helps cut down on spurious error messages.
1064
1065 FIELDS is the entry in the METHOD_VEC vector entry of the class type where
1066 the method should be added. */
1067
895void
896add_method (type, fields, method)
897 tree type, *fields, method;
898{
1068void
1069add_method (type, fields, method)
1070 tree type, *fields, method;
1071{
899 /* We must make a copy of METHOD here, since we must be sure that
900 we have exclusive title to this method's DECL_CHAIN. */
901 tree decl;
902
903 push_obstacks (&permanent_obstack, &permanent_obstack);
1072 push_obstacks (&permanent_obstack, &permanent_obstack);
904 {
905 decl = copy_node (method);
906 if (DECL_RTL (decl) == 0
907 && (!processing_template_decl
908 || !uses_template_parms (decl)))
909 {
910 make_function_rtl (decl);
911 DECL_RTL (method) = DECL_RTL (decl);
912 }
913 }
914
915 if (fields && *fields)
1073
1074 if (fields && *fields)
916 {
917 /* Take care not to hide destructor. */
918 DECL_CHAIN (decl) = DECL_CHAIN (*fields);
919 DECL_CHAIN (*fields) = decl;
920 }
1075 *fields = build_overload (method, *fields);
921 else if (CLASSTYPE_METHOD_VEC (type) == 0)
922 {
923 tree method_vec = make_node (TREE_VEC);
1076 else if (CLASSTYPE_METHOD_VEC (type) == 0)
1077 {
1078 tree method_vec = make_node (TREE_VEC);
924 if (TYPE_IDENTIFIER (type) == DECL_NAME (decl))
1079 if (TYPE_IDENTIFIER (type) == DECL_NAME (method))
925 {
1080 {
926 TREE_VEC_ELT (method_vec, 0) = decl;
927 TREE_VEC_LENGTH (method_vec) = 1;
1081 /* ??? Is it possible for there to have been enough room in the
1082 current chunk for the tree_vec structure but not a tree_vec
1083 plus a tree*? Will this work in that case? */
1084 obstack_free (current_obstack, method_vec);
1085 obstack_blank (current_obstack, sizeof (struct tree_vec) + sizeof (tree *));
1086 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (method)))
1087 TREE_VEC_ELT (method_vec, 1) = method;
1088 else
1089 TREE_VEC_ELT (method_vec, 0) = method;
1090 TREE_VEC_LENGTH (method_vec) = 2;
928 }
929 else
930 {
931 /* ??? Is it possible for there to have been enough room in the
932 current chunk for the tree_vec structure but not a tree_vec
933 plus a tree*? Will this work in that case? */
934 obstack_free (current_obstack, method_vec);
1091 }
1092 else
1093 {
1094 /* ??? Is it possible for there to have been enough room in the
1095 current chunk for the tree_vec structure but not a tree_vec
1096 plus a tree*? Will this work in that case? */
1097 obstack_free (current_obstack, method_vec);
935 obstack_blank (current_obstack, sizeof (struct tree_vec) + sizeof (tree *));
936 TREE_VEC_ELT (method_vec, 1) = decl;
937 TREE_VEC_LENGTH (method_vec) = 2;
1098 obstack_blank (current_obstack, sizeof (struct tree_vec) + 2*sizeof (tree *));
1099 TREE_VEC_ELT (method_vec, 2) = method;
1100 TREE_VEC_LENGTH (method_vec) = 3;
938 obstack_finish (current_obstack);
939 }
940 CLASSTYPE_METHOD_VEC (type) = method_vec;
941 }
942 else
943 {
944 tree method_vec = CLASSTYPE_METHOD_VEC (type);
945 int len = TREE_VEC_LENGTH (method_vec);
946
947 /* Adding a new ctor or dtor. This is easy because our
948 METHOD_VEC always has a slot for such entries. */
1101 obstack_finish (current_obstack);
1102 }
1103 CLASSTYPE_METHOD_VEC (type) = method_vec;
1104 }
1105 else
1106 {
1107 tree method_vec = CLASSTYPE_METHOD_VEC (type);
1108 int len = TREE_VEC_LENGTH (method_vec);
1109
1110 /* Adding a new ctor or dtor. This is easy because our
1111 METHOD_VEC always has a slot for such entries. */
949 if (TYPE_IDENTIFIER (type) == DECL_NAME (decl))
1112 if (TYPE_IDENTIFIER (type) == DECL_NAME (method))
950 {
1113 {
951 /* TREE_VEC_ELT (method_vec, 0) = decl; */
952 if (decl != TREE_VEC_ELT (method_vec, 0))
953 {
954 DECL_CHAIN (decl) = TREE_VEC_ELT (method_vec, 0);
955 TREE_VEC_ELT (method_vec, 0) = decl;
956 }
1114 int idx = !!DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (method));
1115 /* TREE_VEC_ELT (method_vec, idx) = method; */
1116 if (method != TREE_VEC_ELT (method_vec, idx))
1117 TREE_VEC_ELT (method_vec, idx) =
1118 build_overload (method, TREE_VEC_ELT (method_vec, idx));
957 }
958 else
959 {
960 /* This is trickier. We try to extend the TREE_VEC in-place,
961 but if that does not work, we copy all its data to a new
962 TREE_VEC that's large enough. */
963 struct obstack *ob = &class_obstack;
964 tree *end = (tree *)obstack_next_free (ob);

--- 22 unchanged lines hidden (view full) ---

987 + (len-1) * sizeof (tree)));
988 method_vec = tmp_vec;
989 }
990 else
991 obstack_blank (ob, sizeof (tree));
992 }
993
994 obstack_finish (ob);
1119 }
1120 else
1121 {
1122 /* This is trickier. We try to extend the TREE_VEC in-place,
1123 but if that does not work, we copy all its data to a new
1124 TREE_VEC that's large enough. */
1125 struct obstack *ob = &class_obstack;
1126 tree *end = (tree *)obstack_next_free (ob);

--- 22 unchanged lines hidden (view full) ---

1149 + (len-1) * sizeof (tree)));
1150 method_vec = tmp_vec;
1151 }
1152 else
1153 obstack_blank (ob, sizeof (tree));
1154 }
1155
1156 obstack_finish (ob);
995 TREE_VEC_ELT (method_vec, len) = decl;
1157 TREE_VEC_ELT (method_vec, len) = method;
996 TREE_VEC_LENGTH (method_vec) = len + 1;
997 CLASSTYPE_METHOD_VEC (type) = method_vec;
998
999 if (TYPE_BINFO_BASETYPES (type) && CLASSTYPE_BASELINK_VEC (type))
1000 {
1001 /* ??? May be better to know whether these can be extended? */
1002 tree baselink_vec = CLASSTYPE_BASELINK_VEC (type);
1003
1004 TREE_VEC_LENGTH (baselink_vec) += 1;
1005 CLASSTYPE_BASELINK_VEC (type) = copy_node (baselink_vec);
1006 TREE_VEC_LENGTH (baselink_vec) -= 1;
1007
1008 TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (type), len) = 0;
1009 }
1010 }
1011 }
1158 TREE_VEC_LENGTH (method_vec) = len + 1;
1159 CLASSTYPE_METHOD_VEC (type) = method_vec;
1160
1161 if (TYPE_BINFO_BASETYPES (type) && CLASSTYPE_BASELINK_VEC (type))
1162 {
1163 /* ??? May be better to know whether these can be extended? */
1164 tree baselink_vec = CLASSTYPE_BASELINK_VEC (type);
1165
1166 TREE_VEC_LENGTH (baselink_vec) += 1;
1167 CLASSTYPE_BASELINK_VEC (type) = copy_node (baselink_vec);
1168 TREE_VEC_LENGTH (baselink_vec) -= 1;
1169
1170 TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (type), len) = 0;
1171 }
1172 }
1173 }
1012 DECL_CONTEXT (decl) = type;
1013 DECL_CLASS_CONTEXT (decl) = type;
1174 DECL_CONTEXT (method) = type;
1175 DECL_CLASS_CONTEXT (method) = type;
1014
1015 pop_obstacks ();
1016}
1017
1018/* Subroutines of finish_struct. */
1019
1020/* Look through the list of fields for this struct, deleting
1021 duplicates as we go. This must be recursive to handle
1022 anonymous unions.
1023
1024 FIELD is the field which may not appear anywhere in FIELDS.
1025 FIELD_PTR, if non-null, is the starting point at which
1026 chained deletions may take place.
1027 The value returned is the first acceptable entry found
1028 in FIELDS.
1029
1030 Note that anonymous fields which are not of UNION_TYPE are
1031 not duplicates, they are just anonymous fields. This happens
1032 when we have unnamed bitfields, for example. */
1176
1177 pop_obstacks ();
1178}
1179
1180/* Subroutines of finish_struct. */
1181
1182/* Look through the list of fields for this struct, deleting
1183 duplicates as we go. This must be recursive to handle
1184 anonymous unions.
1185
1186 FIELD is the field which may not appear anywhere in FIELDS.
1187 FIELD_PTR, if non-null, is the starting point at which
1188 chained deletions may take place.
1189 The value returned is the first acceptable entry found
1190 in FIELDS.
1191
1192 Note that anonymous fields which are not of UNION_TYPE are
1193 not duplicates, they are just anonymous fields. This happens
1194 when we have unnamed bitfields, for example. */
1195
1033static tree
1034delete_duplicate_fields_1 (field, fields)
1035 tree field, fields;
1036{
1037 tree x;
1038 tree prev = 0;
1039 if (DECL_NAME (field) == 0)
1040 {

--- 28 unchanged lines hidden (view full) ---

1069 {
1070 if (TREE_CODE (field) == CONST_DECL
1071 && TREE_CODE (x) == CONST_DECL)
1072 cp_error_at ("duplicate enum value `%D'", x);
1073 else if (TREE_CODE (field) == CONST_DECL
1074 || TREE_CODE (x) == CONST_DECL)
1075 cp_error_at ("duplicate field `%D' (as enum and non-enum)",
1076 x);
1196static tree
1197delete_duplicate_fields_1 (field, fields)
1198 tree field, fields;
1199{
1200 tree x;
1201 tree prev = 0;
1202 if (DECL_NAME (field) == 0)
1203 {

--- 28 unchanged lines hidden (view full) ---

1232 {
1233 if (TREE_CODE (field) == CONST_DECL
1234 && TREE_CODE (x) == CONST_DECL)
1235 cp_error_at ("duplicate enum value `%D'", x);
1236 else if (TREE_CODE (field) == CONST_DECL
1237 || TREE_CODE (x) == CONST_DECL)
1238 cp_error_at ("duplicate field `%D' (as enum and non-enum)",
1239 x);
1077 else if (TREE_CODE (field) == TYPE_DECL
1078 && TREE_CODE (x) == TYPE_DECL)
1079 cp_error_at ("duplicate nested type `%D'", x);
1080 else if (TREE_CODE (field) == TYPE_DECL
1081 || TREE_CODE (x) == TYPE_DECL)
1082 cp_error_at ("duplicate field `%D' (as type and non-type)",
1083 x);
1240 else if (DECL_DECLARES_TYPE_P (field)
1241 && DECL_DECLARES_TYPE_P (x))
1242 {
1243 if (comptypes (TREE_TYPE (field), TREE_TYPE (x), 1))
1244 continue;
1245 cp_error_at ("duplicate nested type `%D'", x);
1246 }
1247 else if (DECL_DECLARES_TYPE_P (field)
1248 || DECL_DECLARES_TYPE_P (x))
1249 {
1250 /* Hide tag decls. */
1251 if ((TREE_CODE (field) == TYPE_DECL
1252 && DECL_ARTIFICIAL (field))
1253 || (TREE_CODE (x) == TYPE_DECL
1254 && DECL_ARTIFICIAL (x)))
1255 continue;
1256 cp_error_at ("duplicate field `%D' (as type and non-type)",
1257 x);
1258 }
1084 else
1085 cp_error_at ("duplicate member `%D'", x);
1086 if (prev == 0)
1087 fields = TREE_CHAIN (fields);
1088 else
1089 TREE_CHAIN (prev) = TREE_CHAIN (x);
1090 }
1091 }

--- 6 unchanged lines hidden (view full) ---

1098delete_duplicate_fields (fields)
1099 tree fields;
1100{
1101 tree x;
1102 for (x = fields; x && TREE_CHAIN (x); x = TREE_CHAIN (x))
1103 TREE_CHAIN (x) = delete_duplicate_fields_1 (x, TREE_CHAIN (x));
1104}
1105
1259 else
1260 cp_error_at ("duplicate member `%D'", x);
1261 if (prev == 0)
1262 fields = TREE_CHAIN (fields);
1263 else
1264 TREE_CHAIN (prev) = TREE_CHAIN (x);
1265 }
1266 }

--- 6 unchanged lines hidden (view full) ---

1273delete_duplicate_fields (fields)
1274 tree fields;
1275{
1276 tree x;
1277 for (x = fields; x && TREE_CHAIN (x); x = TREE_CHAIN (x))
1278 TREE_CHAIN (x) = delete_duplicate_fields_1 (x, TREE_CHAIN (x));
1279}
1280
1106/* Change the access of FDECL to ACCESS in T.
1107 Return 1 if change was legit, otherwise return 0. */
1281/* Change the access of FDECL to ACCESS in T. The access to FDECL is
1282 along the path given by BINFO. Return 1 if change was legit,
1283 otherwise return 0. */
1284
1108static int
1285static int
1109alter_access (t, fdecl, access)
1286alter_access (t, binfo, fdecl, access)
1110 tree t;
1287 tree t;
1288 tree binfo;
1111 tree fdecl;
1289 tree fdecl;
1112 enum access_type access;
1290 tree access;
1113{
1114 tree elem = purpose_member (t, DECL_ACCESS (fdecl));
1291{
1292 tree elem = purpose_member (t, DECL_ACCESS (fdecl));
1115 if (elem && TREE_VALUE (elem) != (tree)access)
1293 if (elem)
1116 {
1294 {
1117 if (TREE_CODE (TREE_TYPE (fdecl)) == FUNCTION_DECL)
1295 if (TREE_VALUE (elem) != access)
1118 {
1296 {
1119 cp_error_at ("conflicting access specifications for method `%D', ignored", TREE_TYPE (fdecl));
1297 if (TREE_CODE (TREE_TYPE (fdecl)) == FUNCTION_DECL)
1298 cp_error_at ("conflicting access specifications for method `%D', ignored", TREE_TYPE (fdecl));
1299 else
1300 error ("conflicting access specifications for field `%s', ignored",
1301 IDENTIFIER_POINTER (DECL_NAME (fdecl)));
1120 }
1121 else
1302 }
1303 else
1122 error ("conflicting access specifications for field `%s', ignored",
1123 IDENTIFIER_POINTER (DECL_NAME (fdecl)));
1304 {
1305 /* They're changing the access to the same thing they changed
1306 it to before. That's OK. */
1307 ;
1308 }
1124 }
1309 }
1125 else if (TREE_PRIVATE (fdecl))
1310 else
1126 {
1311 {
1127 if (access != access_private)
1128 cp_error_at ("cannot make private `%D' non-private", fdecl);
1129 goto alter;
1130 }
1131 else if (TREE_PROTECTED (fdecl))
1132 {
1133 if (access != access_protected)
1134 cp_error_at ("cannot make protected `%D' non-protected", fdecl);
1135 goto alter;
1136 }
1137 /* ARM 11.3: an access declaration may not be used to restrict access
1138 to a member that is accessible in the base class. */
1139 else if (access != access_public)
1140 cp_error_at ("cannot reduce access of public member `%D'", fdecl);
1141 else if (elem == NULL_TREE)
1142 {
1143 alter:
1144 DECL_ACCESS (fdecl) = tree_cons (t, (tree)access,
1145 DECL_ACCESS (fdecl));
1312 enforce_access (binfo, fdecl);
1313
1314 DECL_ACCESS (fdecl) = tree_cons (t, access, DECL_ACCESS (fdecl));
1146 return 1;
1147 }
1148 return 0;
1149}
1150
1315 return 1;
1316 }
1317 return 0;
1318}
1319
1151/* Return the offset to the main vtable for a given base BINFO. */
1152tree
1153get_vfield_offset (binfo)
1154 tree binfo;
1155{
1156 return size_binop (PLUS_EXPR,
1157 size_binop (FLOOR_DIV_EXPR,
1158 DECL_FIELD_BITPOS (CLASSTYPE_VFIELD (BINFO_TYPE (binfo))),
1159 size_int (BITS_PER_UNIT)),
1160 BINFO_OFFSET (binfo));
1161}
1320/* Process the USING_DECL, which is a member of T. The METHOD_VEC, if
1321 non-NULL, is the methods of T. The FIELDS are the fields of T.
1322 Returns 1 if the USING_DECL was valid, 0 otherwise. */
1162
1323
1163/* Get the offset to the start of the original binfo that we derived
1164 this binfo from. If we find TYPE first, return the offset only
1165 that far. The shortened search is useful because the this pointer
1166 on method calling is expected to point to a DECL_CONTEXT (fndecl)
1167 object, and not a baseclass of it. */
1168static tree
1169get_derived_offset (binfo, type)
1170 tree binfo, type;
1324void
1325handle_using_decl (using_decl, t, method_vec, fields)
1326 tree using_decl;
1327 tree t;
1328 tree method_vec;
1329 tree fields;
1171{
1330{
1172 tree offset1 = get_vfield_offset (TYPE_BINFO (BINFO_TYPE (binfo)));
1173 tree offset2;
1331 tree ctype = DECL_INITIAL (using_decl);
1332 tree name = DECL_NAME (using_decl);
1333 tree access
1334 = TREE_PRIVATE (using_decl) ? access_private_node
1335 : TREE_PROTECTED (using_decl) ? access_protected_node
1336 : access_public_node;
1337 tree fdecl, binfo;
1338 tree flist = NULL_TREE;
1339 tree tmp;
1174 int i;
1340 int i;
1175 while (BINFO_BASETYPES (binfo)
1176 && (i=CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo))) != -1)
1341 int n_methods;
1342
1343 binfo = binfo_or_else (ctype, t);
1344 if (! binfo)
1345 return;
1346
1347 if (name == constructor_name (ctype)
1348 || name == constructor_name_full (ctype))
1349 cp_error_at ("using-declaration for constructor", using_decl);
1350
1351 fdecl = lookup_member (binfo, name, 0, 0);
1352
1353 if (!fdecl)
1177 {
1354 {
1178 tree binfos = BINFO_BASETYPES (binfo);
1179 if (BINFO_TYPE (binfo) == type)
1180 break;
1181 binfo = TREE_VEC_ELT (binfos, i);
1355 cp_error_at ("no members matching `%D' in `%#T'", using_decl, ctype);
1356 return;
1182 }
1357 }
1183 offset2 = get_vfield_offset (TYPE_BINFO (BINFO_TYPE (binfo)));
1184 return size_binop (MINUS_EXPR, offset1, offset2);
1358
1359 /* Functions are represented as TREE_LIST, with the purpose
1360 being the type and the value the functions. Other members
1361 come as themselves. */
1362 if (TREE_CODE (fdecl) == TREE_LIST)
1363 /* Ignore base type this came from. */
1364 fdecl = TREE_VALUE (fdecl);
1365
1366 if (TREE_CODE (fdecl) == OVERLOAD)
1367 {
1368 /* We later iterate over all functions. */
1369 flist = fdecl;
1370 fdecl = OVL_FUNCTION (flist);
1371 }
1372
1373 name = DECL_NAME (fdecl);
1374 n_methods = method_vec ? TREE_VEC_LENGTH (method_vec) : 0;
1375 for (i = 2; i < n_methods; i++)
1376 if (DECL_NAME (OVL_CURRENT (TREE_VEC_ELT (method_vec, i)))
1377 == name)
1378 {
1379 cp_error ("cannot adjust access to `%#D' in `%#T'", fdecl, t);
1380 cp_error_at (" because of local method `%#D' with same name",
1381 OVL_CURRENT (TREE_VEC_ELT (method_vec, i)));
1382 return;
1383 }
1384
1385 if (! DECL_LANG_SPECIFIC (fdecl))
1386 /* We don't currently handle DECL_ACCESS for TYPE_DECLs; just return. */
1387 return;
1388
1389 for (tmp = fields; tmp; tmp = TREE_CHAIN (tmp))
1390 if (DECL_NAME (tmp) == name)
1391 {
1392 cp_error ("cannot adjust access to `%#D' in `%#T'", fdecl, t);
1393 cp_error_at (" because of local field `%#D' with same name", tmp);
1394 return;
1395 }
1396
1397 /* Make type T see field decl FDECL with access ACCESS.*/
1398 if (flist)
1399 {
1400 while (flist)
1401 {
1402 if (alter_access (t, binfo, OVL_FUNCTION (flist),
1403 access) == 0)
1404 return;
1405 flist = OVL_CHAIN (flist);
1406 }
1407 }
1408 else
1409 alter_access (t, binfo, fdecl, access);
1185}
1186
1187/* If FOR_TYPE needs to reinitialize virtual function table pointers
1188 for TYPE's sub-objects, add such reinitializations to BASE_INIT_LIST.
1189 Returns BASE_INIT_LIST appropriately modified. */
1190
1191static tree
1192maybe_fixup_vptrs (for_type, binfo, base_init_list)

--- 4 unchanged lines hidden (view full) ---

1197 tree vfields = CLASSTYPE_VFIELDS (BINFO_TYPE (binfo));
1198 while (vfields)
1199 {
1200 tree basetype = VF_NORMAL_VALUE (vfields)
1201 ? TYPE_MAIN_VARIANT (VF_NORMAL_VALUE (vfields))
1202 : VF_BASETYPE_VALUE (vfields);
1203
1204 tree base_binfo = get_binfo (basetype, for_type, 0);
1410}
1411
1412/* If FOR_TYPE needs to reinitialize virtual function table pointers
1413 for TYPE's sub-objects, add such reinitializations to BASE_INIT_LIST.
1414 Returns BASE_INIT_LIST appropriately modified. */
1415
1416static tree
1417maybe_fixup_vptrs (for_type, binfo, base_init_list)

--- 4 unchanged lines hidden (view full) ---

1422 tree vfields = CLASSTYPE_VFIELDS (BINFO_TYPE (binfo));
1423 while (vfields)
1424 {
1425 tree basetype = VF_NORMAL_VALUE (vfields)
1426 ? TYPE_MAIN_VARIANT (VF_NORMAL_VALUE (vfields))
1427 : VF_BASETYPE_VALUE (vfields);
1428
1429 tree base_binfo = get_binfo (basetype, for_type, 0);
1205 /* Punt until this is implemented. */
1430 /* Punt until this is implemented. */
1206 if (1 /* BINFO_MODIFIED (base_binfo) */)
1207 {
1208 tree base_offset = get_vfield_offset (base_binfo);
1209 if (! tree_int_cst_equal (base_offset, get_vfield_offset (TYPE_BINFO (for_type)))
1210 && ! tree_int_cst_equal (base_offset, get_vfield_offset (binfo)))
1211 base_init_list = tree_cons (error_mark_node, base_binfo,
1212 base_init_list);
1213 }

--- 116 unchanged lines hidden (view full) ---

1330 if (base_init_list)
1331 base_init_list = tree_cons (NULL_TREE, base_binfo, base_init_list);
1332 else
1333 base_init_list = CLASSTYPE_BINFO_AS_LIST (BINFO_TYPE (base_binfo));
1334 }
1335 }
1336
1337 if (base_init_list)
1431 if (1 /* BINFO_MODIFIED (base_binfo) */)
1432 {
1433 tree base_offset = get_vfield_offset (base_binfo);
1434 if (! tree_int_cst_equal (base_offset, get_vfield_offset (TYPE_BINFO (for_type)))
1435 && ! tree_int_cst_equal (base_offset, get_vfield_offset (binfo)))
1436 base_init_list = tree_cons (error_mark_node, base_binfo,
1437 base_init_list);
1438 }

--- 116 unchanged lines hidden (view full) ---

1555 if (base_init_list)
1556 base_init_list = tree_cons (NULL_TREE, base_binfo, base_init_list);
1557 else
1558 base_init_list = CLASSTYPE_BINFO_AS_LIST (BINFO_TYPE (base_binfo));
1559 }
1560 }
1561
1562 if (base_init_list)
1338 if (member_init_list)
1339 CLASSTYPE_BASE_INIT_LIST (type) = build_tree_list (base_init_list, member_init_list);
1340 else
1341 CLASSTYPE_BASE_INIT_LIST (type) = base_init_list;
1563 {
1564 if (member_init_list)
1565 CLASSTYPE_BASE_INIT_LIST (type) =
1566 build_tree_list (base_init_list, member_init_list);
1567 else
1568 CLASSTYPE_BASE_INIT_LIST (type) = base_init_list;
1569 }
1342 else if (member_init_list)
1343 CLASSTYPE_BASE_INIT_LIST (type) = member_init_list;
1344}
1345
1346struct base_info
1347{
1348 int has_virtual;
1349 int max_has_virtual;
1350 int n_ancestors;
1351 tree vfield;
1352 tree vfields;
1570 else if (member_init_list)
1571 CLASSTYPE_BASE_INIT_LIST (type) = member_init_list;
1572}
1573
1574struct base_info
1575{
1576 int has_virtual;
1577 int max_has_virtual;
1578 int n_ancestors;
1579 tree vfield;
1580 tree vfields;
1581 tree rtti;
1353 char cant_have_default_ctor;
1354 char cant_have_const_ctor;
1582 char cant_have_default_ctor;
1583 char cant_have_const_ctor;
1355 char cant_synth_copy_ctor;
1356 char cant_synth_asn_ref;
1357 char no_const_asn_ref;
1584 char no_const_asn_ref;
1358 char needs_virtual_dtor;
1359};
1360
1361/* Record information about type T derived from its base classes.
1362 Store most of that information in T itself, and place the
1363 remaining information in the struct BASE_INFO.
1364
1365 Propagate basetype offsets throughout the lattice. Note that the
1366 lattice topped by T is really a pair: it's a DAG that gives the
1367 structure of the derivation hierarchy, and it's a list of the
1368 virtual baseclasses that appear anywhere in the DAG. When a vbase
1369 type appears in the DAG, it's offset is 0, and it's children start
1370 their offsets from that point. When a vbase type appears in the list,
1371 its offset is the offset it has in the hierarchy, and its children's
1372 offsets include that offset in theirs.
1373
1374 Returns the index of the first base class to have virtual functions,
1585};
1586
1587/* Record information about type T derived from its base classes.
1588 Store most of that information in T itself, and place the
1589 remaining information in the struct BASE_INFO.
1590
1591 Propagate basetype offsets throughout the lattice. Note that the
1592 lattice topped by T is really a pair: it's a DAG that gives the
1593 structure of the derivation hierarchy, and it's a list of the
1594 virtual baseclasses that appear anywhere in the DAG. When a vbase
1595 type appears in the DAG, it's offset is 0, and it's children start
1596 their offsets from that point. When a vbase type appears in the list,
1597 its offset is the offset it has in the hierarchy, and its children's
1598 offsets include that offset in theirs.
1599
1600 Returns the index of the first base class to have virtual functions,
1375 or -1 if no such base class.
1601 or -1 if no such base class. */
1376
1602
1377 Note that at this point TYPE_BINFO (t) != t_binfo. */
1378
1379static int
1603static int
1380finish_base_struct (t, b, t_binfo)
1604finish_base_struct (t, b)
1381 tree t;
1382 struct base_info *b;
1605 tree t;
1606 struct base_info *b;
1383 tree t_binfo;
1384{
1607{
1385 tree binfos = BINFO_BASETYPES (t_binfo);
1608 tree binfos = TYPE_BINFO_BASETYPES (t);
1386 int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
1387 int first_vfn_base_index = -1;
1388 bzero ((char *) b, sizeof (struct base_info));
1389
1390 for (i = 0; i < n_baseclasses; i++)
1391 {
1392 tree base_binfo = TREE_VEC_ELT (binfos, i);
1393 tree basetype = BINFO_TYPE (base_binfo);
1394
1609 int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
1610 int first_vfn_base_index = -1;
1611 bzero ((char *) b, sizeof (struct base_info));
1612
1613 for (i = 0; i < n_baseclasses; i++)
1614 {
1615 tree base_binfo = TREE_VEC_ELT (binfos, i);
1616 tree basetype = BINFO_TYPE (base_binfo);
1617
1618 /* Effective C++ rule 14. We only need to check TYPE_VIRTUAL_P
1619 here because the case of virtual functions but non-virtual
1620 dtor is handled in finish_struct_1. */
1621 if (warn_ecpp && ! TYPE_VIRTUAL_P (basetype)
1622 && TYPE_HAS_DESTRUCTOR (basetype))
1623 cp_warning ("base class `%#T' has a non-virtual destructor", basetype);
1624
1395 /* If the type of basetype is incomplete, then
1396 we already complained about that fact
1397 (and we should have fixed it up as well). */
1398 if (TYPE_SIZE (basetype) == 0)
1399 {
1400 int j;
1401 /* The base type is of incomplete type. It is
1402 probably best to pretend that it does not
1403 exist. */
1404 if (i == n_baseclasses-1)
1405 TREE_VEC_ELT (binfos, i) = NULL_TREE;
1406 TREE_VEC_LENGTH (binfos) -= 1;
1407 n_baseclasses -= 1;
1408 for (j = i; j+1 < n_baseclasses; j++)
1409 TREE_VEC_ELT (binfos, j) = TREE_VEC_ELT (binfos, j+1);
1410 }
1411
1625 /* If the type of basetype is incomplete, then
1626 we already complained about that fact
1627 (and we should have fixed it up as well). */
1628 if (TYPE_SIZE (basetype) == 0)
1629 {
1630 int j;
1631 /* The base type is of incomplete type. It is
1632 probably best to pretend that it does not
1633 exist. */
1634 if (i == n_baseclasses-1)
1635 TREE_VEC_ELT (binfos, i) = NULL_TREE;
1636 TREE_VEC_LENGTH (binfos) -= 1;
1637 n_baseclasses -= 1;
1638 for (j = i; j+1 < n_baseclasses; j++)
1639 TREE_VEC_ELT (binfos, j) = TREE_VEC_ELT (binfos, j+1);
1640 }
1641
1412 if (TYPE_HAS_INIT_REF (basetype)
1413 && !TYPE_HAS_CONST_INIT_REF (basetype))
1642 if (! TYPE_HAS_CONST_INIT_REF (basetype))
1414 b->cant_have_const_ctor = 1;
1643 b->cant_have_const_ctor = 1;
1415 if (! TYPE_HAS_INIT_REF (basetype)
1416 || (TYPE_HAS_NONPUBLIC_CTOR (basetype) == 2
1417 && ! is_friend_type (t, basetype)))
1418 b->cant_synth_copy_ctor = 1;
1419
1420 if (TYPE_HAS_CONSTRUCTOR (basetype)
1421 && ! TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype))
1422 {
1423 b->cant_have_default_ctor = 1;
1424 if (! TYPE_HAS_CONSTRUCTOR (t))
1425 {
1426 cp_pedwarn ("base `%T' with only non-default constructor",
1427 basetype);
1428 cp_pedwarn ("in class without a constructor");
1429 }
1430 }
1431
1432 if (TYPE_HAS_ASSIGN_REF (basetype)
1433 && !TYPE_HAS_CONST_ASSIGN_REF (basetype))
1434 b->no_const_asn_ref = 1;
1644
1645 if (TYPE_HAS_CONSTRUCTOR (basetype)
1646 && ! TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype))
1647 {
1648 b->cant_have_default_ctor = 1;
1649 if (! TYPE_HAS_CONSTRUCTOR (t))
1650 {
1651 cp_pedwarn ("base `%T' with only non-default constructor",
1652 basetype);
1653 cp_pedwarn ("in class without a constructor");
1654 }
1655 }
1656
1657 if (TYPE_HAS_ASSIGN_REF (basetype)
1658 && !TYPE_HAS_CONST_ASSIGN_REF (basetype))
1659 b->no_const_asn_ref = 1;
1435 if (! TYPE_HAS_ASSIGN_REF (basetype)
1436 || TYPE_HAS_ABSTRACT_ASSIGN_REF (basetype)
1437 || (TYPE_HAS_NONPUBLIC_ASSIGN_REF (basetype) == 2
1438 && ! is_friend_type (t, basetype)))
1439 b->cant_synth_asn_ref = 1;
1440
1441 b->n_ancestors += CLASSTYPE_N_SUPERCLASSES (basetype);
1442 TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (basetype);
1443 TYPE_NEEDS_DESTRUCTOR (t) |= TYPE_NEEDS_DESTRUCTOR (basetype);
1444 TYPE_HAS_COMPLEX_ASSIGN_REF (t) |= TYPE_HAS_COMPLEX_ASSIGN_REF (basetype);
1445 TYPE_HAS_COMPLEX_INIT_REF (t) |= TYPE_HAS_COMPLEX_INIT_REF (basetype);
1446
1447 TYPE_OVERLOADS_CALL_EXPR (t) |= TYPE_OVERLOADS_CALL_EXPR (basetype);
1448 TYPE_OVERLOADS_ARRAY_REF (t) |= TYPE_OVERLOADS_ARRAY_REF (basetype);
1449 TYPE_OVERLOADS_ARROW (t) |= TYPE_OVERLOADS_ARROW (basetype);
1450
1660
1661 b->n_ancestors += CLASSTYPE_N_SUPERCLASSES (basetype);
1662 TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (basetype);
1663 TYPE_NEEDS_DESTRUCTOR (t) |= TYPE_NEEDS_DESTRUCTOR (basetype);
1664 TYPE_HAS_COMPLEX_ASSIGN_REF (t) |= TYPE_HAS_COMPLEX_ASSIGN_REF (basetype);
1665 TYPE_HAS_COMPLEX_INIT_REF (t) |= TYPE_HAS_COMPLEX_INIT_REF (basetype);
1666
1667 TYPE_OVERLOADS_CALL_EXPR (t) |= TYPE_OVERLOADS_CALL_EXPR (basetype);
1668 TYPE_OVERLOADS_ARRAY_REF (t) |= TYPE_OVERLOADS_ARRAY_REF (basetype);
1669 TYPE_OVERLOADS_ARROW (t) |= TYPE_OVERLOADS_ARROW (basetype);
1670
1451 if (! TREE_VIA_VIRTUAL (base_binfo)
1452#if 0
1453 /* This cannot be done, as prepare_fresh_vtable wants to modify
1454 binfos associated with vfields anywhere in the hierarchy, not
1455 just immediate base classes. Due to unsharing, the compiler
1456 might consume 3% more memory on a real program.
1457 */
1458 && ! BINFO_OFFSET_ZEROP (base_binfo)
1459#endif
1460 && BINFO_BASETYPES (base_binfo))
1461 {
1462 tree base_binfos = BINFO_BASETYPES (base_binfo);
1463 tree chain = NULL_TREE;
1464 int j;
1465
1466 /* Now unshare the structure beneath BASE_BINFO. */
1467 for (j = TREE_VEC_LENGTH (base_binfos)-1;
1468 j >= 0; j--)
1469 {
1470 tree base_base_binfo = TREE_VEC_ELT (base_binfos, j);
1471 if (! TREE_VIA_VIRTUAL (base_base_binfo))
1472 TREE_VEC_ELT (base_binfos, j)
1473 = make_binfo (BINFO_OFFSET (base_base_binfo),
1474 base_base_binfo,
1475 BINFO_VTABLE (base_base_binfo),
1476 BINFO_VIRTUALS (base_base_binfo),
1477 chain);
1478 chain = TREE_VEC_ELT (base_binfos, j);
1479 TREE_VIA_PUBLIC (chain) = TREE_VIA_PUBLIC (base_base_binfo);
1480 TREE_VIA_PROTECTED (chain) = TREE_VIA_PROTECTED (base_base_binfo);
1481 BINFO_INHERITANCE_CHAIN (chain) = base_binfo;
1482 }
1483
1484 /* Completely unshare potentially shared data, and
1485 update what is ours. */
1486 propagate_binfo_offsets (base_binfo, BINFO_OFFSET (base_binfo));
1487 }
1488
1489 if (! TREE_VIA_VIRTUAL (base_binfo))
1490 CLASSTYPE_N_SUPERCLASSES (t) += 1;
1491
1492 if (TYPE_VIRTUAL_P (basetype))
1493 {
1671 if (! TREE_VIA_VIRTUAL (base_binfo))
1672 CLASSTYPE_N_SUPERCLASSES (t) += 1;
1673
1674 if (TYPE_VIRTUAL_P (basetype))
1675 {
1494 /* If there's going to be a destructor needed, make
1495 sure it will be virtual. */
1496 b->needs_virtual_dtor = 1;
1676 /* Ensure that this is set from at least a virtual base
1677 class. */
1678 if (b->rtti == NULL_TREE)
1679 b->rtti = CLASSTYPE_RTTI (basetype);
1497
1498 /* Don't borrow virtuals from virtual baseclasses. */
1499 if (TREE_VIA_VIRTUAL (base_binfo))
1500 continue;
1501
1502 if (first_vfn_base_index < 0)
1503 {
1504 tree vfields;
1505 first_vfn_base_index = i;
1506
1507 /* Update these two, now that we know what vtable we are
1508 going to extend. This is so that we can add virtual
1509 functions, and override them properly. */
1680
1681 /* Don't borrow virtuals from virtual baseclasses. */
1682 if (TREE_VIA_VIRTUAL (base_binfo))
1683 continue;
1684
1685 if (first_vfn_base_index < 0)
1686 {
1687 tree vfields;
1688 first_vfn_base_index = i;
1689
1690 /* Update these two, now that we know what vtable we are
1691 going to extend. This is so that we can add virtual
1692 functions, and override them properly. */
1510 BINFO_VTABLE (t_binfo) = TYPE_BINFO_VTABLE (basetype);
1511 BINFO_VIRTUALS (t_binfo) = TYPE_BINFO_VIRTUALS (basetype);
1693 TYPE_BINFO_VTABLE (t) = TYPE_BINFO_VTABLE (basetype);
1694 TYPE_BINFO_VIRTUALS (t) = TYPE_BINFO_VIRTUALS (basetype);
1512 b->has_virtual = CLASSTYPE_VSIZE (basetype);
1513 b->vfield = CLASSTYPE_VFIELD (basetype);
1514 b->vfields = copy_list (CLASSTYPE_VFIELDS (basetype));
1515 vfields = b->vfields;
1516 while (vfields)
1517 {
1518 if (VF_BINFO_VALUE (vfields) == NULL_TREE
1519 || ! TREE_VIA_VIRTUAL (VF_BINFO_VALUE (vfields)))

--- 31 unchanged lines hidden (view full) ---

1551
1552 if (b->has_virtual == 0)
1553 {
1554 first_vfn_base_index = i;
1555
1556 /* Update these two, now that we know what vtable we are
1557 going to extend. This is so that we can add virtual
1558 functions, and override them properly. */
1695 b->has_virtual = CLASSTYPE_VSIZE (basetype);
1696 b->vfield = CLASSTYPE_VFIELD (basetype);
1697 b->vfields = copy_list (CLASSTYPE_VFIELDS (basetype));
1698 vfields = b->vfields;
1699 while (vfields)
1700 {
1701 if (VF_BINFO_VALUE (vfields) == NULL_TREE
1702 || ! TREE_VIA_VIRTUAL (VF_BINFO_VALUE (vfields)))

--- 31 unchanged lines hidden (view full) ---

1734
1735 if (b->has_virtual == 0)
1736 {
1737 first_vfn_base_index = i;
1738
1739 /* Update these two, now that we know what vtable we are
1740 going to extend. This is so that we can add virtual
1741 functions, and override them properly. */
1559 BINFO_VTABLE (t_binfo) = TYPE_BINFO_VTABLE (basetype);
1560 BINFO_VIRTUALS (t_binfo) = TYPE_BINFO_VIRTUALS (basetype);
1742 TYPE_BINFO_VTABLE (t) = TYPE_BINFO_VTABLE (basetype);
1743 TYPE_BINFO_VIRTUALS (t) = TYPE_BINFO_VIRTUALS (basetype);
1561 b->has_virtual = CLASSTYPE_VSIZE (basetype);
1562 b->vfield = CLASSTYPE_VFIELD (basetype);
1563 CLASSTYPE_VFIELD (t) = b->vfield;
1564 /* When we install the first one, set the VF_NORMAL_VALUE
1565 to be the current class, as this it is the most derived
1566 class. Hopefully, this is not set to something else
1567 later. (mrs) */
1568 vfields = b->vfields;

--- 9 unchanged lines hidden (view full) ---

1578 }
1579 vfields = TREE_CHAIN (vfields);
1580 }
1581 }
1582 }
1583 }
1584 }
1585
1744 b->has_virtual = CLASSTYPE_VSIZE (basetype);
1745 b->vfield = CLASSTYPE_VFIELD (basetype);
1746 CLASSTYPE_VFIELD (t) = b->vfield;
1747 /* When we install the first one, set the VF_NORMAL_VALUE
1748 to be the current class, as this it is the most derived
1749 class. Hopefully, this is not set to something else
1750 later. (mrs) */
1751 vfields = b->vfields;

--- 9 unchanged lines hidden (view full) ---

1761 }
1762 vfields = TREE_CHAIN (vfields);
1763 }
1764 }
1765 }
1766 }
1767 }
1768
1586 /* Must come after offsets are fixed for all bases. */
1769 /* This comment said "Must come after offsets are fixed for all bases."
1770 Well, now this happens before the offsets are fixed, but it seems to
1771 work fine. Guess we'll see... */
1587 for (i = 0; i < n_baseclasses; i++)
1588 {
1589 tree base_binfo = TREE_VEC_ELT (binfos, i);
1590 tree basetype = BINFO_TYPE (base_binfo);
1591
1772 for (i = 0; i < n_baseclasses; i++)
1773 {
1774 tree base_binfo = TREE_VEC_ELT (binfos, i);
1775 tree basetype = BINFO_TYPE (base_binfo);
1776
1592 if (get_base_distance (basetype, t_binfo, 0, (tree*)0) == -2)
1777 if (get_base_distance (basetype, t, 0, (tree*)0) == -2)
1593 {
1594 cp_warning ("direct base `%T' inaccessible in `%T' due to ambiguity",
1595 basetype, t);
1778 {
1779 cp_warning ("direct base `%T' inaccessible in `%T' due to ambiguity",
1780 basetype, t);
1596 b->cant_synth_asn_ref = 1;
1597 b->cant_synth_copy_ctor = 1;
1598 }
1599 }
1600 {
1781 }
1782 }
1783 {
1601 tree v = get_vbase_types (t_binfo);
1784 tree v = get_vbase_types (t);
1602
1603 for (; v; v = TREE_CHAIN (v))
1604 {
1605 tree basetype = BINFO_TYPE (v);
1785
1786 for (; v; v = TREE_CHAIN (v))
1787 {
1788 tree basetype = BINFO_TYPE (v);
1606 if (get_base_distance (basetype, t_binfo, 0, (tree*)0) == -2)
1789 if (get_base_distance (basetype, t, 0, (tree*)0) == -2)
1607 {
1608 if (extra_warnings)
1609 cp_warning ("virtual base `%T' inaccessible in `%T' due to ambiguity",
1610 basetype, t);
1790 {
1791 if (extra_warnings)
1792 cp_warning ("virtual base `%T' inaccessible in `%T' due to ambiguity",
1793 basetype, t);
1611 b->cant_synth_asn_ref = 1;
1612 b->cant_synth_copy_ctor = 1;
1613 }
1614 }
1615 }
1616
1617 {
1618 tree vfields;
1619 /* Find the base class with the largest number of virtual functions. */
1620 for (vfields = b->vfields; vfields; vfields = TREE_CHAIN (vfields))

--- 4 unchanged lines hidden (view full) ---

1625 && CLASSTYPE_VSIZE (VF_DERIVED_VALUE (vfields)) > b->max_has_virtual)
1626 b->max_has_virtual = CLASSTYPE_VSIZE (VF_DERIVED_VALUE (vfields));
1627 }
1628 }
1629
1630 if (b->vfield == 0)
1631 /* If all virtual functions come only from virtual baseclasses. */
1632 return -1;
1794 }
1795 }
1796 }
1797
1798 {
1799 tree vfields;
1800 /* Find the base class with the largest number of virtual functions. */
1801 for (vfields = b->vfields; vfields; vfields = TREE_CHAIN (vfields))

--- 4 unchanged lines hidden (view full) ---

1806 && CLASSTYPE_VSIZE (VF_DERIVED_VALUE (vfields)) > b->max_has_virtual)
1807 b->max_has_virtual = CLASSTYPE_VSIZE (VF_DERIVED_VALUE (vfields));
1808 }
1809 }
1810
1811 if (b->vfield == 0)
1812 /* If all virtual functions come only from virtual baseclasses. */
1813 return -1;
1814
1815 /* Update the rtti base if we have a non-virtual base class version
1816 of it. */
1817 b->rtti = CLASSTYPE_RTTI (BINFO_TYPE (TREE_VEC_ELT (binfos, first_vfn_base_index)));
1818
1633 return first_vfn_base_index;
1634}
1819 return first_vfn_base_index;
1820}
1635
1636static int
1637typecode_p (type, code)
1638 tree type;
1639 enum tree_code code;
1640{
1641 return (TREE_CODE (type) == code
1642 || (TREE_CODE (type) == REFERENCE_TYPE
1643 && TREE_CODE (TREE_TYPE (type)) == code));
1644}
1645
1646/* Set memoizing fields and bits of T (and its variants) for later use.
1647 MAX_HAS_VIRTUAL is the largest size of any T's virtual function tables. */
1821
1822/* Set memoizing fields and bits of T (and its variants) for later use.
1823 MAX_HAS_VIRTUAL is the largest size of any T's virtual function tables. */
1824
1648static void
1649finish_struct_bits (t, max_has_virtual)
1650 tree t;
1651 int max_has_virtual;
1652{
1653 int i, n_baseclasses = CLASSTYPE_N_BASECLASSES (t);
1825static void
1826finish_struct_bits (t, max_has_virtual)
1827 tree t;
1828 int max_has_virtual;
1829{
1830 int i, n_baseclasses = CLASSTYPE_N_BASECLASSES (t);
1654 tree method_vec = CLASSTYPE_METHOD_VEC (t);
1655
1656 /* Fix up variants (if any). */
1657 tree variants = TYPE_NEXT_VARIANT (t);
1658 while (variants)
1659 {
1660 /* These fields are in the _TYPE part of the node, not in
1661 the TYPE_LANG_SPECIFIC component, so they are not shared. */
1662 TYPE_HAS_CONSTRUCTOR (variants) = TYPE_HAS_CONSTRUCTOR (t);
1663 TYPE_HAS_DESTRUCTOR (variants) = TYPE_HAS_DESTRUCTOR (t);
1664 TYPE_NEEDS_CONSTRUCTING (variants) = TYPE_NEEDS_CONSTRUCTING (t);
1665 TYPE_NEEDS_DESTRUCTOR (variants) = TYPE_NEEDS_DESTRUCTOR (t);
1666
1667 TYPE_USES_COMPLEX_INHERITANCE (variants) = TYPE_USES_COMPLEX_INHERITANCE (t);
1668 TYPE_VIRTUAL_P (variants) = TYPE_VIRTUAL_P (t);
1669 TYPE_USES_VIRTUAL_BASECLASSES (variants) = TYPE_USES_VIRTUAL_BASECLASSES (t);
1670 /* Copy whatever these are holding today. */
1671 TYPE_MIN_VALUE (variants) = TYPE_MIN_VALUE (t);
1672 TYPE_MAX_VALUE (variants) = TYPE_MAX_VALUE (t);
1831
1832 /* Fix up variants (if any). */
1833 tree variants = TYPE_NEXT_VARIANT (t);
1834 while (variants)
1835 {
1836 /* These fields are in the _TYPE part of the node, not in
1837 the TYPE_LANG_SPECIFIC component, so they are not shared. */
1838 TYPE_HAS_CONSTRUCTOR (variants) = TYPE_HAS_CONSTRUCTOR (t);
1839 TYPE_HAS_DESTRUCTOR (variants) = TYPE_HAS_DESTRUCTOR (t);
1840 TYPE_NEEDS_CONSTRUCTING (variants) = TYPE_NEEDS_CONSTRUCTING (t);
1841 TYPE_NEEDS_DESTRUCTOR (variants) = TYPE_NEEDS_DESTRUCTOR (t);
1842
1843 TYPE_USES_COMPLEX_INHERITANCE (variants) = TYPE_USES_COMPLEX_INHERITANCE (t);
1844 TYPE_VIRTUAL_P (variants) = TYPE_VIRTUAL_P (t);
1845 TYPE_USES_VIRTUAL_BASECLASSES (variants) = TYPE_USES_VIRTUAL_BASECLASSES (t);
1846 /* Copy whatever these are holding today. */
1847 TYPE_MIN_VALUE (variants) = TYPE_MIN_VALUE (t);
1848 TYPE_MAX_VALUE (variants) = TYPE_MAX_VALUE (t);
1849 TYPE_FIELDS (variants) = TYPE_FIELDS (t);
1850 TYPE_SIZE (variants) = TYPE_SIZE (t);
1851 TYPE_SIZE_UNIT (variants) = TYPE_SIZE_UNIT (t);
1673 variants = TYPE_NEXT_VARIANT (variants);
1674 }
1675
1676 if (n_baseclasses && max_has_virtual)
1677 {
1678 /* Done by `finish_struct' for classes without baseclasses. */
1679 int might_have_abstract_virtuals = CLASSTYPE_ABSTRACT_VIRTUALS (t) != 0;
1680 tree binfos = TYPE_BINFO_BASETYPES (t);
1681 for (i = n_baseclasses-1; i >= 0; i--)
1682 {
1683 might_have_abstract_virtuals
1684 |= (CLASSTYPE_ABSTRACT_VIRTUALS (BINFO_TYPE (TREE_VEC_ELT (binfos, i))) != 0);
1685 if (might_have_abstract_virtuals)
1686 break;
1687 }
1688 if (might_have_abstract_virtuals)
1689 {
1690 /* We use error_mark_node from override_one_vtable to signal
1852 variants = TYPE_NEXT_VARIANT (variants);
1853 }
1854
1855 if (n_baseclasses && max_has_virtual)
1856 {
1857 /* Done by `finish_struct' for classes without baseclasses. */
1858 int might_have_abstract_virtuals = CLASSTYPE_ABSTRACT_VIRTUALS (t) != 0;
1859 tree binfos = TYPE_BINFO_BASETYPES (t);
1860 for (i = n_baseclasses-1; i >= 0; i--)
1861 {
1862 might_have_abstract_virtuals
1863 |= (CLASSTYPE_ABSTRACT_VIRTUALS (BINFO_TYPE (TREE_VEC_ELT (binfos, i))) != 0);
1864 if (might_have_abstract_virtuals)
1865 break;
1866 }
1867 if (might_have_abstract_virtuals)
1868 {
1869 /* We use error_mark_node from override_one_vtable to signal
1691 an artificial abstract. */
1870 an artificial abstract. */
1692 if (CLASSTYPE_ABSTRACT_VIRTUALS (t) == error_mark_node)
1693 CLASSTYPE_ABSTRACT_VIRTUALS (t) = NULL_TREE;
1694 CLASSTYPE_ABSTRACT_VIRTUALS (t) = get_abstract_virtuals (t);
1695 }
1696 }
1697
1698 if (n_baseclasses)
1699 {
1700 /* Notice whether this class has type conversion functions defined. */
1701 tree binfo = TYPE_BINFO (t);
1702 tree binfos = BINFO_BASETYPES (binfo);
1703 tree basetype;
1704
1705 for (i = n_baseclasses-1; i >= 0; i--)
1706 {
1707 basetype = BINFO_TYPE (TREE_VEC_ELT (binfos, i));
1708
1871 if (CLASSTYPE_ABSTRACT_VIRTUALS (t) == error_mark_node)
1872 CLASSTYPE_ABSTRACT_VIRTUALS (t) = NULL_TREE;
1873 CLASSTYPE_ABSTRACT_VIRTUALS (t) = get_abstract_virtuals (t);
1874 }
1875 }
1876
1877 if (n_baseclasses)
1878 {
1879 /* Notice whether this class has type conversion functions defined. */
1880 tree binfo = TYPE_BINFO (t);
1881 tree binfos = BINFO_BASETYPES (binfo);
1882 tree basetype;
1883
1884 for (i = n_baseclasses-1; i >= 0; i--)
1885 {
1886 basetype = BINFO_TYPE (TREE_VEC_ELT (binfos, i));
1887
1709 if (TYPE_HAS_CONVERSION (basetype))
1710 {
1711 TYPE_HAS_CONVERSION (t) = 1;
1712 TYPE_HAS_INT_CONVERSION (t) |= TYPE_HAS_INT_CONVERSION (basetype);
1713 TYPE_HAS_REAL_CONVERSION (t) |= TYPE_HAS_REAL_CONVERSION (basetype);
1714 }
1888 TYPE_HAS_CONVERSION (t) |= TYPE_HAS_CONVERSION (basetype);
1715 if (CLASSTYPE_MAX_DEPTH (basetype) >= CLASSTYPE_MAX_DEPTH (t))
1716 CLASSTYPE_MAX_DEPTH (t) = CLASSTYPE_MAX_DEPTH (basetype) + 1;
1717 }
1718 }
1719
1720 /* If this type has a copy constructor, force its mode to be BLKmode, and
1721 force its TREE_ADDRESSABLE bit to be nonzero. This will cause it to
1722 be passed by invisible reference and prevent it from being returned in
1889 if (CLASSTYPE_MAX_DEPTH (basetype) >= CLASSTYPE_MAX_DEPTH (t))
1890 CLASSTYPE_MAX_DEPTH (t) = CLASSTYPE_MAX_DEPTH (basetype) + 1;
1891 }
1892 }
1893
1894 /* If this type has a copy constructor, force its mode to be BLKmode, and
1895 force its TREE_ADDRESSABLE bit to be nonzero. This will cause it to
1896 be passed by invisible reference and prevent it from being returned in
1723 a register. */
1724 if (! TYPE_HAS_TRIVIAL_INIT_REF (t))
1897 a register.
1898
1899 Also do this if the class has BLKmode but can still be returned in
1900 registers, since function_cannot_inline_p won't let us inline
1901 functions returning such a type. This affects the HP-PA. */
1902 if (! TYPE_HAS_TRIVIAL_INIT_REF (t)
1903 || (TYPE_MODE (t) == BLKmode && ! aggregate_value_p (t)
1904 && CLASSTYPE_NON_AGGREGATE (t)))
1725 {
1726 tree variants;
1905 {
1906 tree variants;
1727 if (TREE_CODE (TYPE_NAME (t)) == TYPE_DECL)
1728 DECL_MODE (TYPE_NAME (t)) = BLKmode;
1907 DECL_MODE (TYPE_MAIN_DECL (t)) = BLKmode;
1729 for (variants = t; variants; variants = TYPE_NEXT_VARIANT (variants))
1730 {
1731 TYPE_MODE (variants) = BLKmode;
1732 TREE_ADDRESSABLE (variants) = 1;
1733 }
1734 }
1735}
1736
1908 for (variants = t; variants; variants = TYPE_NEXT_VARIANT (variants))
1909 {
1910 TYPE_MODE (variants) = BLKmode;
1911 TREE_ADDRESSABLE (variants) = 1;
1912 }
1913 }
1914}
1915
1737/* Add FN to the method_vec growing on the class_obstack. Used by
1738 finish_struct_methods. */
1916/* Add FNDECL to the method_vec growing on the class_obstack. Used by
1917 finish_struct_methods. Note, FNDECL cannot be a constructor or
1918 destructor, those cases are handled by the caller. */
1919
1739static void
1920static void
1740grow_method (fn, method_vec_ptr)
1741 tree fn;
1921grow_method (fndecl, method_vec_ptr)
1922 tree fndecl;
1742 tree *method_vec_ptr;
1743{
1744 tree method_vec = (tree)obstack_base (&class_obstack);
1923 tree *method_vec_ptr;
1924{
1925 tree method_vec = (tree)obstack_base (&class_obstack);
1745 tree *testp = &TREE_VEC_ELT (method_vec, 0);
1746 if (*testp == NULL_TREE)
1926
1927 /* Start off past the constructors and destructor. */
1928 tree *testp = &TREE_VEC_ELT (method_vec, 2);
1929
1930 while (testp < (tree *) obstack_next_free (&class_obstack)
1931 && (*testp == NULL_TREE || DECL_NAME (OVL_CURRENT (*testp)) != DECL_NAME (fndecl)))
1747 testp++;
1932 testp++;
1748 while (((HOST_WIDE_INT) testp
1749 < (HOST_WIDE_INT) obstack_next_free (&class_obstack))
1750 && DECL_NAME (*testp) != DECL_NAME (fn))
1751 testp++;
1752 if ((HOST_WIDE_INT) testp
1753 < (HOST_WIDE_INT) obstack_next_free (&class_obstack))
1754 {
1755 tree x, prev_x;
1756
1933
1757 for (x = *testp; x; x = DECL_CHAIN (x))
1758 {
1759 if (DECL_NAME (fn) == ansi_opname[(int) DELETE_EXPR]
1760 || DECL_NAME (fn) == ansi_opname[(int) VEC_DELETE_EXPR])
1761 {
1762 /* ANSI C++ June 5 1992 WP 12.5.5.1 */
1763 cp_error_at ("`%D' overloaded", fn);
1764 cp_error_at ("previous declaration as `%D' here", x);
1765 }
1766 if (DECL_ASSEMBLER_NAME (fn)==DECL_ASSEMBLER_NAME (x))
1767 {
1768 /* We complain about multiple destructors on sight,
1769 so we do not repeat the warning here. Friend-friend
1770 ambiguities are warned about outside this loop. */
1771 if (!DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fn)))
1772 cp_error_at ("ambiguous method `%#D' in structure", fn);
1773 break;
1774 }
1775 prev_x = x;
1776 }
1777 if (x == 0)
1778 {
1779 if (*testp)
1780 DECL_CHAIN (prev_x) = fn;
1781 else
1782 *testp = fn;
1783 }
1784 }
1934 if (testp < (tree *) obstack_next_free (&class_obstack))
1935 *testp = build_overload (fndecl, *testp);
1785 else
1786 {
1936 else
1937 {
1787 obstack_ptr_grow (&class_obstack, fn);
1938 obstack_ptr_grow (&class_obstack, fndecl);
1788 *method_vec_ptr = (tree)obstack_base (&class_obstack);
1789 }
1790}
1791
1792/* Warn about duplicate methods in fn_fields. Also compact method
1793 lists so that lookup can be made faster.
1794
1795 Algorithm: Outer loop builds lists by method name. Inner loop

--- 11 unchanged lines hidden (view full) ---

1807 If there are any constructors/destructors, they are moved to the
1808 front of the list. This makes pushclass more efficient.
1809
1810 We also link each field which has shares a name with its baseclass
1811 to the head of the list of fields for that base class. This allows
1812 us to reduce search time in places like `build_method_call' to
1813 consider only reasonably likely functions. */
1814
1939 *method_vec_ptr = (tree)obstack_base (&class_obstack);
1940 }
1941}
1942
1943/* Warn about duplicate methods in fn_fields. Also compact method
1944 lists so that lookup can be made faster.
1945
1946 Algorithm: Outer loop builds lists by method name. Inner loop

--- 11 unchanged lines hidden (view full) ---

1958 If there are any constructors/destructors, they are moved to the
1959 front of the list. This makes pushclass more efficient.
1960
1961 We also link each field which has shares a name with its baseclass
1962 to the head of the list of fields for that base class. This allows
1963 us to reduce search time in places like `build_method_call' to
1964 consider only reasonably likely functions. */
1965
1815static tree
1966tree
1816finish_struct_methods (t, fn_fields, nonprivate_method)
1817 tree t;
1818 tree fn_fields;
1819 int nonprivate_method;
1820{
1821 tree method_vec;
1967finish_struct_methods (t, fn_fields, nonprivate_method)
1968 tree t;
1969 tree fn_fields;
1970 int nonprivate_method;
1971{
1972 tree method_vec;
1822 tree save_fn_fields = tree_cons (NULL_TREE, NULL_TREE, fn_fields);
1823 tree lastp;
1824 tree name = constructor_name (t);
1973 tree save_fn_fields = fn_fields;
1974 tree ctor_name = constructor_name (t);
1825 int i, n_baseclasses = CLASSTYPE_N_BASECLASSES (t);
1826
1827 /* Now prepare to gather fn_fields into vector. */
1828 struct obstack *ambient_obstack = current_obstack;
1829 current_obstack = &class_obstack;
1975 int i, n_baseclasses = CLASSTYPE_N_BASECLASSES (t);
1976
1977 /* Now prepare to gather fn_fields into vector. */
1978 struct obstack *ambient_obstack = current_obstack;
1979 current_obstack = &class_obstack;
1830 method_vec = make_node (TREE_VEC);
1831 /* Room has been saved for constructors and destructors. */
1980 method_vec = make_tree_vec (2);
1832 current_obstack = ambient_obstack;
1981 current_obstack = ambient_obstack;
1982
1833 /* Now make this a live vector. */
1834 obstack_free (&class_obstack, method_vec);
1983 /* Now make this a live vector. */
1984 obstack_free (&class_obstack, method_vec);
1835 obstack_blank (&class_obstack, sizeof (struct tree_vec));
1836
1985
1837 /* First fill in entry 0 with the constructors, and the next few with
1838 type conversion operators (if any). */
1986 /* Save room for constructors and destructors. */
1987 obstack_blank (&class_obstack, sizeof (struct tree_vec) + sizeof (struct tree *));
1839
1988
1840 for (lastp = save_fn_fields; fn_fields; fn_fields = TREE_CHAIN (lastp))
1989 /* First fill in entry 0 with the constructors, entry 1 with destructors,
1990 and the next few with type conversion operators (if any). */
1991
1992 for (; fn_fields; fn_fields = TREE_CHAIN (fn_fields))
1841 {
1842 tree fn_name = DECL_NAME (fn_fields);
1993 {
1994 tree fn_name = DECL_NAME (fn_fields);
1843 if (fn_name == NULL_TREE)
1844 fn_name = name;
1845
1846 /* Clear out this flag.
1847
1848 @@ Doug may figure out how to break
1849 @@ this with nested classes and friends. */
1850 DECL_IN_AGGR_P (fn_fields) = 0;
1851
1852 /* Note here that a copy ctor is private, so we don't dare generate
1853 a default copy constructor for a class that has a member
1854 of this type without making sure they have access to it. */
1995
1996 /* Clear out this flag.
1997
1998 @@ Doug may figure out how to break
1999 @@ this with nested classes and friends. */
2000 DECL_IN_AGGR_P (fn_fields) = 0;
2001
2002 /* Note here that a copy ctor is private, so we don't dare generate
2003 a default copy constructor for a class that has a member
2004 of this type without making sure they have access to it. */
1855 if (fn_name == name)
2005 if (fn_name == ctor_name)
1856 {
1857 tree parmtypes = FUNCTION_ARG_CHAIN (fn_fields);
1858 tree parmtype = parmtypes ? TREE_VALUE (parmtypes) : void_type_node;
1859
1860 if (TREE_CODE (parmtype) == REFERENCE_TYPE
1861 && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype)) == t)
1862 {
1863 if (TREE_CHAIN (parmtypes) == NULL_TREE
1864 || TREE_CHAIN (parmtypes) == void_list_node
1865 || TREE_PURPOSE (TREE_CHAIN (parmtypes)))
1866 {
1867 if (TREE_PROTECTED (fn_fields))
1868 TYPE_HAS_NONPUBLIC_CTOR (t) = 1;
1869 else if (TREE_PRIVATE (fn_fields))
1870 TYPE_HAS_NONPUBLIC_CTOR (t) = 2;
1871 }
1872 }
2006 {
2007 tree parmtypes = FUNCTION_ARG_CHAIN (fn_fields);
2008 tree parmtype = parmtypes ? TREE_VALUE (parmtypes) : void_type_node;
2009
2010 if (TREE_CODE (parmtype) == REFERENCE_TYPE
2011 && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype)) == t)
2012 {
2013 if (TREE_CHAIN (parmtypes) == NULL_TREE
2014 || TREE_CHAIN (parmtypes) == void_list_node
2015 || TREE_PURPOSE (TREE_CHAIN (parmtypes)))
2016 {
2017 if (TREE_PROTECTED (fn_fields))
2018 TYPE_HAS_NONPUBLIC_CTOR (t) = 1;
2019 else if (TREE_PRIVATE (fn_fields))
2020 TYPE_HAS_NONPUBLIC_CTOR (t) = 2;
2021 }
2022 }
1873 /* Constructors are handled easily in search routines. */
1874 DECL_CHAIN (fn_fields) = TREE_VEC_ELT (method_vec, 0);
1875 TREE_VEC_ELT (method_vec, 0) = fn_fields;
2023 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fn_fields)))
2024 {
2025 /* Destructors go in slot 1. */
2026 TREE_VEC_ELT (method_vec, 1) =
2027 build_overload (fn_fields, TREE_VEC_ELT (method_vec, 1));
2028 }
2029 else
2030 {
2031 /* Constructors go in slot 0. */
2032 TREE_VEC_ELT (method_vec, 0) =
2033 build_overload (fn_fields, TREE_VEC_ELT (method_vec, 0));
2034 }
1876 }
1877 else if (IDENTIFIER_TYPENAME_P (fn_name))
2035 }
2036 else if (IDENTIFIER_TYPENAME_P (fn_name))
1878 {
1879 tree return_type = TREE_TYPE (TREE_TYPE (fn_fields));
1880
1881 if (typecode_p (return_type, INTEGER_TYPE)
1882 || typecode_p (return_type, BOOLEAN_TYPE)
1883 || typecode_p (return_type, ENUMERAL_TYPE))
1884 TYPE_HAS_INT_CONVERSION (t) = 1;
1885 else if (typecode_p (return_type, REAL_TYPE))
1886 TYPE_HAS_REAL_CONVERSION (t) = 1;
1887
1888 grow_method (fn_fields, &method_vec);
1889 }
1890 else
1891 {
1892 lastp = fn_fields;
1893 continue;
1894 }
1895
1896 TREE_CHAIN (lastp) = TREE_CHAIN (fn_fields);
1897 TREE_CHAIN (fn_fields) = NULL_TREE;
2037 grow_method (fn_fields, &method_vec);
1898 }
1899
2038 }
2039
1900 fn_fields = TREE_CHAIN (save_fn_fields);
1901 while (fn_fields)
2040 fn_fields = save_fn_fields;
2041 for (; fn_fields; fn_fields = TREE_CHAIN (fn_fields))
1902 {
2042 {
1903 tree nextp;
1904 tree fn_name = DECL_NAME (fn_fields);
2043 tree fn_name = DECL_NAME (fn_fields);
1905 if (fn_name == NULL_TREE)
1906 fn_name = name;
1907
2044
1908 nextp = TREE_CHAIN (fn_fields);
1909 TREE_CHAIN (fn_fields) = NULL_TREE;
2045 if (fn_name == ctor_name || IDENTIFIER_TYPENAME_P (fn_name))
2046 continue;
1910
1911 if (fn_name == ansi_opname[(int) MODIFY_EXPR])
1912 {
1913 tree parmtype = TREE_VALUE (FUNCTION_ARG_CHAIN (fn_fields));
1914
1915 if (copy_assignment_arg_p (parmtype, DECL_VIRTUAL_P (fn_fields)))
1916 {
1917 if (TREE_PROTECTED (fn_fields))
1918 TYPE_HAS_NONPUBLIC_ASSIGN_REF (t) = 1;
1919 else if (TREE_PRIVATE (fn_fields))
1920 TYPE_HAS_NONPUBLIC_ASSIGN_REF (t) = 2;
1921 }
1922 }
1923
1924 grow_method (fn_fields, &method_vec);
2047
2048 if (fn_name == ansi_opname[(int) MODIFY_EXPR])
2049 {
2050 tree parmtype = TREE_VALUE (FUNCTION_ARG_CHAIN (fn_fields));
2051
2052 if (copy_assignment_arg_p (parmtype, DECL_VIRTUAL_P (fn_fields)))
2053 {
2054 if (TREE_PROTECTED (fn_fields))
2055 TYPE_HAS_NONPUBLIC_ASSIGN_REF (t) = 1;
2056 else if (TREE_PRIVATE (fn_fields))
2057 TYPE_HAS_NONPUBLIC_ASSIGN_REF (t) = 2;
2058 }
2059 }
2060
2061 grow_method (fn_fields, &method_vec);
1925 fn_fields = nextp;
1926 }
1927
1928 TREE_VEC_LENGTH (method_vec) = (tree *)obstack_next_free (&class_obstack)
1929 - (&TREE_VEC_ELT (method_vec, 0));
1930 obstack_finish (&class_obstack);
1931 CLASSTYPE_METHOD_VEC (t) = method_vec;
1932
1933 if (nonprivate_method == 0
1934 && CLASSTYPE_FRIEND_CLASSES (t) == NULL_TREE
2062 }
2063
2064 TREE_VEC_LENGTH (method_vec) = (tree *)obstack_next_free (&class_obstack)
2065 - (&TREE_VEC_ELT (method_vec, 0));
2066 obstack_finish (&class_obstack);
2067 CLASSTYPE_METHOD_VEC (t) = method_vec;
2068
2069 if (nonprivate_method == 0
2070 && CLASSTYPE_FRIEND_CLASSES (t) == NULL_TREE
1935 && DECL_FRIENDLIST (TYPE_NAME (t)) == NULL_TREE)
2071 && DECL_FRIENDLIST (TYPE_MAIN_DECL (t)) == NULL_TREE)
1936 {
1937 tree binfos = BINFO_BASETYPES (TYPE_BINFO (t));
1938 for (i = 0; i < n_baseclasses; i++)
1939 if (TREE_VIA_PUBLIC (TREE_VEC_ELT (binfos, i))
1940 || TREE_VIA_PROTECTED (TREE_VEC_ELT (binfos, i)))
1941 {
1942 nonprivate_method = 1;
1943 break;
1944 }
2072 {
2073 tree binfos = BINFO_BASETYPES (TYPE_BINFO (t));
2074 for (i = 0; i < n_baseclasses; i++)
2075 if (TREE_VIA_PUBLIC (TREE_VEC_ELT (binfos, i))
2076 || TREE_VIA_PROTECTED (TREE_VEC_ELT (binfos, i)))
2077 {
2078 nonprivate_method = 1;
2079 break;
2080 }
1945 if (nonprivate_method == 0)
2081 if (nonprivate_method == 0
2082 && warn_ctor_dtor_privacy)
1946 cp_warning ("all member functions in class `%T' are private", t);
1947 }
1948
2083 cp_warning ("all member functions in class `%T' are private", t);
2084 }
2085
1949 /* If there are constructors (and destructors), they are at the
1950 front. Place destructors at very front. Also warn if all
1951 constructors and/or destructors are private (in which case this
1952 class is effectively unusable. */
2086 /* Warn if all destructors are private (in which case this class is
2087 effectively unusable. */
1953 if (TYPE_HAS_DESTRUCTOR (t))
1954 {
2088 if (TYPE_HAS_DESTRUCTOR (t))
2089 {
1955 tree dtor, prev;
2090 tree dtor = TREE_VEC_ELT (method_vec, 1);
1956
2091
1957 for (dtor = TREE_VEC_ELT (method_vec, 0);
1958 dtor;
1959 prev = dtor, dtor = DECL_CHAIN (dtor))
1960 {
1961 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (dtor)))
1962 {
1963 if (TREE_PRIVATE (dtor)
1964 && CLASSTYPE_FRIEND_CLASSES (t) == NULL_TREE
1965 && DECL_FRIENDLIST (TYPE_NAME (t)) == NULL_TREE
1966 && warn_ctor_dtor_privacy)
1967 cp_warning ("`%#T' only defines a private destructor and has no friends",
1968 t);
1969 break;
1970 }
1971 }
1972
1973 /* Wild parse errors can cause this to happen. */
1974 if (dtor == NULL_TREE)
1975 TYPE_HAS_DESTRUCTOR (t) = 0;
2092 /* Wild parse errors can cause this to happen. */
2093 if (dtor == NULL_TREE)
2094 TYPE_HAS_DESTRUCTOR (t) = 0;
1976 else if (dtor != TREE_VEC_ELT (method_vec, 0))
1977 {
1978 DECL_CHAIN (prev) = DECL_CHAIN (dtor);
1979 DECL_CHAIN (dtor) = TREE_VEC_ELT (method_vec, 0);
1980 TREE_VEC_ELT (method_vec, 0) = dtor;
1981 }
2095 else if (TREE_PRIVATE (dtor)
2096 && CLASSTYPE_FRIEND_CLASSES (t) == NULL_TREE
2097 && DECL_FRIENDLIST (TYPE_MAIN_DECL (t)) == NULL_TREE
2098 && warn_ctor_dtor_privacy)
2099 cp_warning ("`%#T' only defines a private destructor and has no friends",
2100 t);
1982 }
1983
1984 /* Now for each member function (except for constructors and
1985 destructors), compute where member functions of the same
1986 name reside in base classes. */
1987 if (n_baseclasses != 0
2101 }
2102
2103 /* Now for each member function (except for constructors and
2104 destructors), compute where member functions of the same
2105 name reside in base classes. */
2106 if (n_baseclasses != 0
1988 && TREE_VEC_LENGTH (method_vec) > 1)
2107 && TREE_VEC_LENGTH (method_vec) > 2)
1989 {
1990 int len = TREE_VEC_LENGTH (method_vec);
1991 tree baselink_vec = make_tree_vec (len);
1992 int any_links = 0;
1993 tree baselink_binfo = build_tree_list (NULL_TREE, TYPE_BINFO (t));
1994
2108 {
2109 int len = TREE_VEC_LENGTH (method_vec);
2110 tree baselink_vec = make_tree_vec (len);
2111 int any_links = 0;
2112 tree baselink_binfo = build_tree_list (NULL_TREE, TYPE_BINFO (t));
2113
1995 for (i = 1; i < len; i++)
2114 for (i = 2; i < len; i++)
1996 {
1997 TREE_VEC_ELT (baselink_vec, i)
2115 {
2116 TREE_VEC_ELT (baselink_vec, i)
1998 = get_baselinks (baselink_binfo, t, DECL_NAME (TREE_VEC_ELT (method_vec, i)));
2117 = get_baselinks (baselink_binfo, t,
2118 DECL_NAME (OVL_CURRENT (TREE_VEC_ELT (method_vec, i))));
1999 if (TREE_VEC_ELT (baselink_vec, i) != 0)
2000 any_links = 1;
2001 }
2002 if (any_links != 0)
2003 CLASSTYPE_BASELINK_VEC (t) = baselink_vec;
2004 else
2005 obstack_free (current_obstack, baselink_vec);
2006 }
2007
2119 if (TREE_VEC_ELT (baselink_vec, i) != 0)
2120 any_links = 1;
2121 }
2122 if (any_links != 0)
2123 CLASSTYPE_BASELINK_VEC (t) = baselink_vec;
2124 else
2125 obstack_free (current_obstack, baselink_vec);
2126 }
2127
2008 /* Now add the methods to the TYPE_METHODS of T, arranged in a chain. */
2009 {
2010 tree x, last_x = NULL_TREE;
2011 int limit = TREE_VEC_LENGTH (method_vec);
2012
2013 for (i = 1; i < limit; i++)
2014 {
2015 for (x = TREE_VEC_ELT (method_vec, i); x; x = DECL_CHAIN (x))
2016 {
2017 if (last_x != NULL_TREE)
2018 TREE_CHAIN (last_x) = x;
2019 last_x = x;
2020 }
2021 }
2022
2023 /* Put ctors and dtors at the front of the list. */
2024 x = TREE_VEC_ELT (method_vec, 0);
2025 if (x)
2026 {
2027 while (DECL_CHAIN (x))
2028 {
2029 /* Let's avoid being circular about this. */
2030 if (x == DECL_CHAIN (x))
2031 break;
2032 TREE_CHAIN (x) = DECL_CHAIN (x);
2033 x = DECL_CHAIN (x);
2034 }
2035 if (TREE_VEC_LENGTH (method_vec) > 1)
2036 TREE_CHAIN (x) = TREE_VEC_ELT (method_vec, 1);
2037 else
2038 TREE_CHAIN (x) = NULL_TREE;
2039 }
2040 }
2041
2042 TYPE_METHODS (t) = method_vec;
2043
2044 return method_vec;
2045}
2046
2128 return method_vec;
2129}
2130
2047/* Emit error when a duplicate definition of a type is seen. Patch up. */
2131/* Emit error when a duplicate definition of a type is seen. Patch up. */
2048
2049void
2050duplicate_tag_error (t)
2051 tree t;
2052{
2053 cp_error ("redefinition of `%#T'", t);
2054 cp_error_at ("previous definition here", t);
2055
2056 /* Pretend we haven't defined this type. */
2057
2058 /* All of the component_decl's were TREE_CHAINed together in the parser.
2059 finish_struct_methods walks these chains and assembles all methods with
2060 the same base name into DECL_CHAINs. Now we don't need the parser chains
2132
2133void
2134duplicate_tag_error (t)
2135 tree t;
2136{
2137 cp_error ("redefinition of `%#T'", t);
2138 cp_error_at ("previous definition here", t);
2139
2140 /* Pretend we haven't defined this type. */
2141
2142 /* All of the component_decl's were TREE_CHAINed together in the parser.
2143 finish_struct_methods walks these chains and assembles all methods with
2144 the same base name into DECL_CHAINs. Now we don't need the parser chains
2061 anymore, so we unravel them.
2062 */
2063 /*
2064 * This used to be in finish_struct, but it turns out that the
2065 * TREE_CHAIN is used by dbxout_type_methods and perhaps some other things...
2066 */
2067 if (CLASSTYPE_METHOD_VEC(t))
2145 anymore, so we unravel them. */
2146
2147 /* This used to be in finish_struct, but it turns out that the
2148 TREE_CHAIN is used by dbxout_type_methods and perhaps some other
2149 things... */
2150 if (CLASSTYPE_METHOD_VEC (t))
2068 {
2151 {
2069 tree tv = CLASSTYPE_METHOD_VEC(t);
2070 int i, len = TREE_VEC_LENGTH (tv);
2152 tree method_vec = CLASSTYPE_METHOD_VEC (t);
2153 int i, len = TREE_VEC_LENGTH (method_vec);
2071 for (i = 0; i < len; i++)
2072 {
2154 for (i = 0; i < len; i++)
2155 {
2073 tree unchain = TREE_VEC_ELT (tv, i);
2156 tree unchain = TREE_VEC_ELT (method_vec, i);
2074 while (unchain != NULL_TREE)
2075 {
2157 while (unchain != NULL_TREE)
2158 {
2076 TREE_CHAIN (unchain) = NULL_TREE;
2077 unchain = DECL_CHAIN(unchain);
2159 TREE_CHAIN (OVL_CURRENT (unchain)) = NULL_TREE;
2160 unchain = OVL_NEXT (unchain);
2078 }
2079 }
2080 }
2081
2082 if (TYPE_LANG_SPECIFIC (t))
2083 {
2084 tree as_list = CLASSTYPE_AS_LIST (t);
2085 tree binfo = TYPE_BINFO (t);

--- 4 unchanged lines hidden (view full) ---

2090 bzero ((char *) TYPE_LANG_SPECIFIC (t), sizeof (struct lang_type));
2091 BINFO_BASETYPES(binfo) = NULL_TREE;
2092
2093 CLASSTYPE_AS_LIST (t) = as_list;
2094 TYPE_BINFO (t) = binfo;
2095 CLASSTYPE_BINFO_AS_LIST (t) = binfo_as_list;
2096 CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
2097 SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, interface_unknown);
2161 }
2162 }
2163 }
2164
2165 if (TYPE_LANG_SPECIFIC (t))
2166 {
2167 tree as_list = CLASSTYPE_AS_LIST (t);
2168 tree binfo = TYPE_BINFO (t);

--- 4 unchanged lines hidden (view full) ---

2173 bzero ((char *) TYPE_LANG_SPECIFIC (t), sizeof (struct lang_type));
2174 BINFO_BASETYPES(binfo) = NULL_TREE;
2175
2176 CLASSTYPE_AS_LIST (t) = as_list;
2177 TYPE_BINFO (t) = binfo;
2178 CLASSTYPE_BINFO_AS_LIST (t) = binfo_as_list;
2179 CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
2180 SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, interface_unknown);
2098 CLASSTYPE_VBASE_SIZE (t) = integer_zero_node;
2099 TYPE_REDEFINED (t) = 1;
2100 }
2101 TYPE_SIZE (t) = NULL_TREE;
2102 TYPE_MODE (t) = VOIDmode;
2103 TYPE_FIELDS (t) = NULL_TREE;
2104 TYPE_METHODS (t) = NULL_TREE;
2105 TYPE_VFIELD (t) = NULL_TREE;
2106 TYPE_CONTEXT (t) = NULL_TREE;
2107}
2108
2181 TYPE_REDEFINED (t) = 1;
2182 }
2183 TYPE_SIZE (t) = NULL_TREE;
2184 TYPE_MODE (t) = VOIDmode;
2185 TYPE_FIELDS (t) = NULL_TREE;
2186 TYPE_METHODS (t) = NULL_TREE;
2187 TYPE_VFIELD (t) = NULL_TREE;
2188 TYPE_CONTEXT (t) = NULL_TREE;
2189}
2190
2109/* finish up all new vtables. */
2191/* finish up all new vtables. */
2192
2110static void
2111finish_vtbls (binfo, do_self, t)
2193static void
2194finish_vtbls (binfo, do_self, t)
2112 tree binfo, t;
2195 tree binfo;
2113 int do_self;
2196 int do_self;
2197 tree t;
2114{
2115 tree binfos = BINFO_BASETYPES (binfo);
2116 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2117
2118 /* Should we use something besides CLASSTYPE_VFIELDS? */
2119 if (do_self && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
2120 {
2121 if (BINFO_NEW_VTABLE_MARKED (binfo))

--- 11 unchanged lines hidden (view full) ---

2133 DECL_CONTEXT (decl) = context;
2134 }
2135 CLEAR_BINFO_NEW_VTABLE_MARKED (binfo);
2136 }
2137
2138 for (i = 0; i < n_baselinks; i++)
2139 {
2140 tree base_binfo = TREE_VEC_ELT (binfos, i);
2198{
2199 tree binfos = BINFO_BASETYPES (binfo);
2200 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2201
2202 /* Should we use something besides CLASSTYPE_VFIELDS? */
2203 if (do_self && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
2204 {
2205 if (BINFO_NEW_VTABLE_MARKED (binfo))

--- 11 unchanged lines hidden (view full) ---

2217 DECL_CONTEXT (decl) = context;
2218 }
2219 CLEAR_BINFO_NEW_VTABLE_MARKED (binfo);
2220 }
2221
2222 for (i = 0; i < n_baselinks; i++)
2223 {
2224 tree base_binfo = TREE_VEC_ELT (binfos, i);
2141 int is_not_base_vtable =
2142 i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo));
2225 int is_not_base_vtable
2226 = i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo));
2143 if (TREE_VIA_VIRTUAL (base_binfo))
2144 {
2145 base_binfo = binfo_member (BINFO_TYPE (base_binfo), CLASSTYPE_VBASECLASSES (t));
2146 }
2147 finish_vtbls (base_binfo, is_not_base_vtable, t);
2148 }
2149}
2150
2151/* True if we should override the given BASE_FNDECL with the given
2152 FNDECL. */
2227 if (TREE_VIA_VIRTUAL (base_binfo))
2228 {
2229 base_binfo = binfo_member (BINFO_TYPE (base_binfo), CLASSTYPE_VBASECLASSES (t));
2230 }
2231 finish_vtbls (base_binfo, is_not_base_vtable, t);
2232 }
2233}
2234
2235/* True if we should override the given BASE_FNDECL with the given
2236 FNDECL. */
2237
2153static int
2154overrides (fndecl, base_fndecl)
2155 tree fndecl, base_fndecl;
2156{
2238static int
2239overrides (fndecl, base_fndecl)
2240 tree fndecl, base_fndecl;
2241{
2157 /* Destructors have special names. */
2158 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (base_fndecl)) &&
2159 DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl)))
2242 /* Destructors have special names. */
2243 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (base_fndecl))
2244 && DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl)))
2160 return 1;
2245 return 1;
2161 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (base_fndecl)) ||
2162 DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl)))
2246 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (base_fndecl))
2247 || DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl)))
2163 return 0;
2164 if (DECL_NAME (fndecl) == DECL_NAME (base_fndecl))
2165 {
2248 return 0;
2249 if (DECL_NAME (fndecl) == DECL_NAME (base_fndecl))
2250 {
2166 tree rettype, base_rettype, types, base_types;
2251 tree types, base_types;
2167#if 0
2168 retypes = TREE_TYPE (TREE_TYPE (fndecl));
2169 base_retypes = TREE_TYPE (TREE_TYPE (base_fndecl));
2170#endif
2171 types = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
2172 base_types = TYPE_ARG_TYPES (TREE_TYPE (base_fndecl));
2173 if ((TYPE_READONLY (TREE_TYPE (TREE_VALUE (base_types)))
2174 == TYPE_READONLY (TREE_TYPE (TREE_VALUE (types))))

--- 46 unchanged lines hidden (view full) ---

2221 rval = BINFO_OFFSET (binfo);
2222 }
2223 }
2224 return rval;
2225}
2226
2227/* Get the offset to the CONTEXT subobject that is related to the
2228 given BINFO. */
2252#if 0
2253 retypes = TREE_TYPE (TREE_TYPE (fndecl));
2254 base_retypes = TREE_TYPE (TREE_TYPE (base_fndecl));
2255#endif
2256 types = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
2257 base_types = TYPE_ARG_TYPES (TREE_TYPE (base_fndecl));
2258 if ((TYPE_READONLY (TREE_TYPE (TREE_VALUE (base_types)))
2259 == TYPE_READONLY (TREE_TYPE (TREE_VALUE (types))))

--- 46 unchanged lines hidden (view full) ---

2306 rval = BINFO_OFFSET (binfo);
2307 }
2308 }
2309 return rval;
2310}
2311
2312/* Get the offset to the CONTEXT subobject that is related to the
2313 given BINFO. */
2314
2229static tree
2230get_class_offset (context, t, binfo, fndecl)
2231 tree context, t, binfo, fndecl;
2232{
2233 tree first_binfo = binfo;
2234 tree offset;
2235 int i;
2236

--- 9 unchanged lines hidden (view full) ---

2246 {
2247 tree binfos = BINFO_BASETYPES (binfo);
2248 binfo = TREE_VEC_ELT (binfos, i);
2249 if (BINFO_TYPE (binfo) == context)
2250 return BINFO_OFFSET (binfo);
2251 }
2252
2253 /* Ok, not found in the less derived binfos, now check the more
2315static tree
2316get_class_offset (context, t, binfo, fndecl)
2317 tree context, t, binfo, fndecl;
2318{
2319 tree first_binfo = binfo;
2320 tree offset;
2321 int i;
2322

--- 9 unchanged lines hidden (view full) ---

2332 {
2333 tree binfos = BINFO_BASETYPES (binfo);
2334 binfo = TREE_VEC_ELT (binfos, i);
2335 if (BINFO_TYPE (binfo) == context)
2336 return BINFO_OFFSET (binfo);
2337 }
2338
2339 /* Ok, not found in the less derived binfos, now check the more
2254 derived binfos. */
2340 derived binfos. */
2255 offset = get_class_offset_1 (first_binfo, TYPE_BINFO (t), context, t, fndecl);
2256 if (offset==0 || TREE_CODE (offset) != INTEGER_CST)
2257 my_friendly_abort (999); /* we have to find it. */
2258 return offset;
2259}
2260
2261/* Skip RTTI information at the front of the virtual list. */
2341 offset = get_class_offset_1 (first_binfo, TYPE_BINFO (t), context, t, fndecl);
2342 if (offset==0 || TREE_CODE (offset) != INTEGER_CST)
2343 my_friendly_abort (999); /* we have to find it. */
2344 return offset;
2345}
2346
2347/* Skip RTTI information at the front of the virtual list. */
2348
2262unsigned HOST_WIDE_INT
2263skip_rtti_stuff (virtuals)
2264 tree *virtuals;
2265{
2266 int n;
2267
2268 n = 0;
2269 if (*virtuals)

--- 12 unchanged lines hidden (view full) ---

2282 return n;
2283}
2284
2285static void
2286modify_one_vtable (binfo, t, fndecl, pfn)
2287 tree binfo, t, fndecl, pfn;
2288{
2289 tree virtuals = BINFO_VIRTUALS (binfo);
2349unsigned HOST_WIDE_INT
2350skip_rtti_stuff (virtuals)
2351 tree *virtuals;
2352{
2353 int n;
2354
2355 n = 0;
2356 if (*virtuals)

--- 12 unchanged lines hidden (view full) ---

2369 return n;
2370}
2371
2372static void
2373modify_one_vtable (binfo, t, fndecl, pfn)
2374 tree binfo, t, fndecl, pfn;
2375{
2376 tree virtuals = BINFO_VIRTUALS (binfo);
2290 tree old_rtti;
2291 unsigned HOST_WIDE_INT n;
2292
2293 /* update rtti entry */
2294 if (flag_rtti)
2295 {
2296 if (binfo == TYPE_BINFO (t))
2297 {
2298 if (! BINFO_NEW_VTABLE_MARKED (binfo))

--- 29 unchanged lines hidden (view full) ---

2328 consideration the virtual base class pointers that we
2329 stick in before the virtual function table pointer.
2330
2331 Also, we want just the delta between the most base class
2332 that we derived this vfield from and us. */
2333 base_offset = size_binop (PLUS_EXPR,
2334 get_derived_offset (binfo, DECL_CONTEXT (current_fndecl)),
2335 BINFO_OFFSET (binfo));
2377 unsigned HOST_WIDE_INT n;
2378
2379 /* update rtti entry */
2380 if (flag_rtti)
2381 {
2382 if (binfo == TYPE_BINFO (t))
2383 {
2384 if (! BINFO_NEW_VTABLE_MARKED (binfo))

--- 29 unchanged lines hidden (view full) ---

2414 consideration the virtual base class pointers that we
2415 stick in before the virtual function table pointer.
2416
2417 Also, we want just the delta between the most base class
2418 that we derived this vfield from and us. */
2419 base_offset = size_binop (PLUS_EXPR,
2420 get_derived_offset (binfo, DECL_CONTEXT (current_fndecl)),
2421 BINFO_OFFSET (binfo));
2336 this_offset = size_binop (MINUS_EXPR, offset, base_offset);
2422 this_offset = ssize_binop (MINUS_EXPR, offset, base_offset);
2337
2338 /* Make sure we can modify the derived association with immunity. */
2339 if (TREE_USED (binfo))
2340 my_friendly_assert (0, 999);
2341
2342 if (binfo == TYPE_BINFO (t))
2343 {
2344 /* In this case, it is *type*'s vtable we are modifying.

--- 19 unchanged lines hidden (view full) ---

2364 build_vtable_entry (this_offset, pfn),
2365 fndecl);
2366 }
2367 ++n;
2368 virtuals = TREE_CHAIN (virtuals);
2369 }
2370}
2371
2423
2424 /* Make sure we can modify the derived association with immunity. */
2425 if (TREE_USED (binfo))
2426 my_friendly_assert (0, 999);
2427
2428 if (binfo == TYPE_BINFO (t))
2429 {
2430 /* In this case, it is *type*'s vtable we are modifying.

--- 19 unchanged lines hidden (view full) ---

2450 build_vtable_entry (this_offset, pfn),
2451 fndecl);
2452 }
2453 ++n;
2454 virtuals = TREE_CHAIN (virtuals);
2455 }
2456}
2457
2372/* These are the ones that are not through virtual base classes. */
2458/* These are the ones that are not through virtual base classes. */
2459
2373static void
2374modify_all_direct_vtables (binfo, do_self, t, fndecl, pfn)
2460static void
2461modify_all_direct_vtables (binfo, do_self, t, fndecl, pfn)
2375 tree binfo, t, fndecl, pfn;
2462 tree binfo;
2376 int do_self;
2463 int do_self;
2464 tree t, fndecl, pfn;
2377{
2378 tree binfos = BINFO_BASETYPES (binfo);
2379 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2380
2381 /* Should we use something besides CLASSTYPE_VFIELDS? */
2382 if (do_self && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
2383 {
2384 modify_one_vtable (binfo, t, fndecl, pfn);
2385 }
2386
2387 for (i = 0; i < n_baselinks; i++)
2388 {
2389 tree base_binfo = TREE_VEC_ELT (binfos, i);
2465{
2466 tree binfos = BINFO_BASETYPES (binfo);
2467 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2468
2469 /* Should we use something besides CLASSTYPE_VFIELDS? */
2470 if (do_self && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
2471 {
2472 modify_one_vtable (binfo, t, fndecl, pfn);
2473 }
2474
2475 for (i = 0; i < n_baselinks; i++)
2476 {
2477 tree base_binfo = TREE_VEC_ELT (binfos, i);
2390 int is_not_base_vtable =
2391 i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo));
2478 int is_not_base_vtable
2479 = i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo));
2392 if (! TREE_VIA_VIRTUAL (base_binfo))
2393 modify_all_direct_vtables (base_binfo, is_not_base_vtable, t, fndecl, pfn);
2394 }
2395}
2396
2397/* Fixup all the delta entries in this one vtable that need updating. */
2480 if (! TREE_VIA_VIRTUAL (base_binfo))
2481 modify_all_direct_vtables (base_binfo, is_not_base_vtable, t, fndecl, pfn);
2482 }
2483}
2484
2485/* Fixup all the delta entries in this one vtable that need updating. */
2486
2398static void
2399fixup_vtable_deltas1 (binfo, t)
2400 tree binfo, t;
2401{
2402 tree virtuals = BINFO_VIRTUALS (binfo);
2403 unsigned HOST_WIDE_INT n;
2404
2405 n = skip_rtti_stuff (&virtuals);

--- 16 unchanged lines hidden (view full) ---

2422 /* Find the right offset for the this pointer based on the
2423 base class we just found. We have to take into
2424 consideration the virtual base class pointers that we
2425 stick in before the virtual function table pointer.
2426
2427 Also, we want just the delta between the most base class
2428 that we derived this vfield from and us. */
2429 base_offset = size_binop (PLUS_EXPR,
2487static void
2488fixup_vtable_deltas1 (binfo, t)
2489 tree binfo, t;
2490{
2491 tree virtuals = BINFO_VIRTUALS (binfo);
2492 unsigned HOST_WIDE_INT n;
2493
2494 n = skip_rtti_stuff (&virtuals);

--- 16 unchanged lines hidden (view full) ---

2511 /* Find the right offset for the this pointer based on the
2512 base class we just found. We have to take into
2513 consideration the virtual base class pointers that we
2514 stick in before the virtual function table pointer.
2515
2516 Also, we want just the delta between the most base class
2517 that we derived this vfield from and us. */
2518 base_offset = size_binop (PLUS_EXPR,
2430 get_derived_offset (binfo, DECL_CONTEXT (fndecl)),
2519 get_derived_offset (binfo,
2520 DECL_CONTEXT (fndecl)),
2431 BINFO_OFFSET (binfo));
2521 BINFO_OFFSET (binfo));
2432 this_offset = size_binop (MINUS_EXPR, offset, base_offset);
2522 this_offset = ssize_binop (MINUS_EXPR, offset, base_offset);
2433
2434 if (! tree_int_cst_equal (this_offset, delta))
2435 {
2436 /* Make sure we can modify the derived association with immunity. */
2437 if (TREE_USED (binfo))
2438 my_friendly_assert (0, 999);
2439
2440 if (binfo == TYPE_BINFO (t))

--- 23 unchanged lines hidden (view full) ---

2464 virtuals = TREE_CHAIN (virtuals);
2465 }
2466}
2467
2468/* Fixup all the delta entries in all the direct vtables that need updating.
2469 This happens when we have non-overridden virtual functions from a
2470 virtual base class, that are at a different offset, in the new
2471 hierarchy, because the layout of the virtual bases has changed. */
2523
2524 if (! tree_int_cst_equal (this_offset, delta))
2525 {
2526 /* Make sure we can modify the derived association with immunity. */
2527 if (TREE_USED (binfo))
2528 my_friendly_assert (0, 999);
2529
2530 if (binfo == TYPE_BINFO (t))

--- 23 unchanged lines hidden (view full) ---

2554 virtuals = TREE_CHAIN (virtuals);
2555 }
2556}
2557
2558/* Fixup all the delta entries in all the direct vtables that need updating.
2559 This happens when we have non-overridden virtual functions from a
2560 virtual base class, that are at a different offset, in the new
2561 hierarchy, because the layout of the virtual bases has changed. */
2562
2472static void
2473fixup_vtable_deltas (binfo, init_self, t)
2563static void
2564fixup_vtable_deltas (binfo, init_self, t)
2474 tree binfo, t;
2565 tree binfo;
2475 int init_self;
2566 int init_self;
2567 tree t;
2476{
2477 tree binfos = BINFO_BASETYPES (binfo);
2478 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2479
2480 for (i = 0; i < n_baselinks; i++)
2481 {
2482 tree base_binfo = TREE_VEC_ELT (binfos, i);
2568{
2569 tree binfos = BINFO_BASETYPES (binfo);
2570 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2571
2572 for (i = 0; i < n_baselinks; i++)
2573 {
2574 tree base_binfo = TREE_VEC_ELT (binfos, i);
2483 int is_not_base_vtable =
2484 i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo));
2575 int is_not_base_vtable
2576 = i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo));
2485 if (! TREE_VIA_VIRTUAL (base_binfo))
2486 fixup_vtable_deltas (base_binfo, is_not_base_vtable, t);
2487 }
2488 /* Should we use something besides CLASSTYPE_VFIELDS? */
2489 if (init_self && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
2490 {
2491 fixup_vtable_deltas1 (binfo, t);
2492 }
2493}
2494
2577 if (! TREE_VIA_VIRTUAL (base_binfo))
2578 fixup_vtable_deltas (base_binfo, is_not_base_vtable, t);
2579 }
2580 /* Should we use something besides CLASSTYPE_VFIELDS? */
2581 if (init_self && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
2582 {
2583 fixup_vtable_deltas1 (binfo, t);
2584 }
2585}
2586
2495/* These are the ones that are through virtual base classes. */
2587/* These are the ones that are through virtual base classes. */
2588
2496static void
2497modify_all_indirect_vtables (binfo, do_self, via_virtual, t, fndecl, pfn)
2589static void
2590modify_all_indirect_vtables (binfo, do_self, via_virtual, t, fndecl, pfn)
2498 tree binfo, t, fndecl, pfn;
2591 tree binfo;
2499 int do_self, via_virtual;
2592 int do_self, via_virtual;
2593 tree t, fndecl, pfn;
2500{
2501 tree binfos = BINFO_BASETYPES (binfo);
2502 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2503
2504 /* Should we use something besides CLASSTYPE_VFIELDS? */
2505 if (do_self && via_virtual && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
2506 {
2507 modify_one_vtable (binfo, t, fndecl, pfn);
2508 }
2509
2510 for (i = 0; i < n_baselinks; i++)
2511 {
2512 tree base_binfo = TREE_VEC_ELT (binfos, i);
2594{
2595 tree binfos = BINFO_BASETYPES (binfo);
2596 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2597
2598 /* Should we use something besides CLASSTYPE_VFIELDS? */
2599 if (do_self && via_virtual && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
2600 {
2601 modify_one_vtable (binfo, t, fndecl, pfn);
2602 }
2603
2604 for (i = 0; i < n_baselinks; i++)
2605 {
2606 tree base_binfo = TREE_VEC_ELT (binfos, i);
2513 int is_not_base_vtable =
2514 i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo));
2607 int is_not_base_vtable
2608 = i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo));
2515 if (TREE_VIA_VIRTUAL (base_binfo))
2516 {
2517 via_virtual = 1;
2518 base_binfo = binfo_member (BINFO_TYPE (base_binfo), CLASSTYPE_VBASECLASSES (t));
2519 }
2520 modify_all_indirect_vtables (base_binfo, is_not_base_vtable, via_virtual, t, fndecl, pfn);
2521 }
2522}
2523
2524static void
2525modify_all_vtables (t, fndecl, vfn)
2526 tree t, fndecl, vfn;
2527{
2528 /* Do these first, so that we will make use of any non-virtual class's
2609 if (TREE_VIA_VIRTUAL (base_binfo))
2610 {
2611 via_virtual = 1;
2612 base_binfo = binfo_member (BINFO_TYPE (base_binfo), CLASSTYPE_VBASECLASSES (t));
2613 }
2614 modify_all_indirect_vtables (base_binfo, is_not_base_vtable, via_virtual, t, fndecl, pfn);
2615 }
2616}
2617
2618static void
2619modify_all_vtables (t, fndecl, vfn)
2620 tree t, fndecl, vfn;
2621{
2622 /* Do these first, so that we will make use of any non-virtual class's
2529 vtable, over a virtual classes vtable. */
2623 vtable, over a virtual classes vtable. */
2530 modify_all_direct_vtables (TYPE_BINFO (t), 1, t, fndecl, vfn);
2531 if (TYPE_USES_VIRTUAL_BASECLASSES (t))
2532 modify_all_indirect_vtables (TYPE_BINFO (t), 1, 0, t, fndecl, vfn);
2533}
2534
2535/* Here, we already know that they match in every respect.
2536 All we have to check is where they had their declarations. */
2624 modify_all_direct_vtables (TYPE_BINFO (t), 1, t, fndecl, vfn);
2625 if (TYPE_USES_VIRTUAL_BASECLASSES (t))
2626 modify_all_indirect_vtables (TYPE_BINFO (t), 1, 0, t, fndecl, vfn);
2627}
2628
2629/* Here, we already know that they match in every respect.
2630 All we have to check is where they had their declarations. */
2631
2537static int
2538strictly_overrides (fndecl1, fndecl2)
2539 tree fndecl1, fndecl2;
2540{
2541 int distance = get_base_distance (DECL_CLASS_CONTEXT (fndecl2),
2542 DECL_CLASS_CONTEXT (fndecl1),
2543 0, (tree *)0);
2544 if (distance == -2 || distance > 0)

--- 8 unchanged lines hidden (view full) ---

2553 other, than choose the more derived one
2554 else
2555 potentially ill-formed (see 10.3 [class.virtual])
2556 we have to check later to see if there was an
2557 override in this class. If there was ok, if not
2558 then it is ill-formed. (mrs)
2559
2560 We take special care to reuse a vtable, if we can. */
2632static int
2633strictly_overrides (fndecl1, fndecl2)
2634 tree fndecl1, fndecl2;
2635{
2636 int distance = get_base_distance (DECL_CLASS_CONTEXT (fndecl2),
2637 DECL_CLASS_CONTEXT (fndecl1),
2638 0, (tree *)0);
2639 if (distance == -2 || distance > 0)

--- 8 unchanged lines hidden (view full) ---

2648 other, than choose the more derived one
2649 else
2650 potentially ill-formed (see 10.3 [class.virtual])
2651 we have to check later to see if there was an
2652 override in this class. If there was ok, if not
2653 then it is ill-formed. (mrs)
2654
2655 We take special care to reuse a vtable, if we can. */
2656
2561static void
2562override_one_vtable (binfo, old, t)
2563 tree binfo, old, t;
2564{
2565 tree virtuals = BINFO_VIRTUALS (binfo);
2566 tree old_virtuals = BINFO_VIRTUALS (old);
2567 enum { REUSE_NEW, REUSE_OLD, UNDECIDED, NEITHER } choose = UNDECIDED;
2568
2569 /* If we have already committed to modifying it, then don't try and
2657static void
2658override_one_vtable (binfo, old, t)
2659 tree binfo, old, t;
2660{
2661 tree virtuals = BINFO_VIRTUALS (binfo);
2662 tree old_virtuals = BINFO_VIRTUALS (old);
2663 enum { REUSE_NEW, REUSE_OLD, UNDECIDED, NEITHER } choose = UNDECIDED;
2664
2665 /* If we have already committed to modifying it, then don't try and
2570 reuse another vtable. */
2666 reuse another vtable. */
2571 if (BINFO_NEW_VTABLE_MARKED (binfo))
2572 choose = NEITHER;
2573
2574 skip_rtti_stuff (&virtuals);
2575 skip_rtti_stuff (&old_virtuals);
2576
2577 while (virtuals)
2578 {
2579 tree fndecl = TREE_VALUE (virtuals);
2580 tree old_fndecl = TREE_VALUE (old_virtuals);
2581 fndecl = FNADDR_FROM_VTABLE_ENTRY (fndecl);
2582 old_fndecl = FNADDR_FROM_VTABLE_ENTRY (old_fndecl);
2583 fndecl = TREE_OPERAND (fndecl, 0);
2584 old_fndecl = TREE_OPERAND (old_fndecl, 0);
2667 if (BINFO_NEW_VTABLE_MARKED (binfo))
2668 choose = NEITHER;
2669
2670 skip_rtti_stuff (&virtuals);
2671 skip_rtti_stuff (&old_virtuals);
2672
2673 while (virtuals)
2674 {
2675 tree fndecl = TREE_VALUE (virtuals);
2676 tree old_fndecl = TREE_VALUE (old_virtuals);
2677 fndecl = FNADDR_FROM_VTABLE_ENTRY (fndecl);
2678 old_fndecl = FNADDR_FROM_VTABLE_ENTRY (old_fndecl);
2679 fndecl = TREE_OPERAND (fndecl, 0);
2680 old_fndecl = TREE_OPERAND (old_fndecl, 0);
2585 /* First check to see if they are the same. */
2681 /* First check to see if they are the same. */
2586 if (DECL_ASSEMBLER_NAME (fndecl) == DECL_ASSEMBLER_NAME (old_fndecl))
2587 {
2682 if (DECL_ASSEMBLER_NAME (fndecl) == DECL_ASSEMBLER_NAME (old_fndecl))
2683 {
2588 /* No need to do anything. */
2684 /* No need to do anything. */
2589 }
2590 else if (strictly_overrides (fndecl, old_fndecl))
2591 {
2592 if (choose == UNDECIDED)
2593 choose = REUSE_NEW;
2594 else if (choose == REUSE_OLD)
2595 {
2596 choose = NEITHER;

--- 38 unchanged lines hidden (view full) ---

2635 /* This MUST be overridden, or the class is ill-formed. */
2636 /* For now, we just make it abstract. */
2637 tree fndecl = TREE_OPERAND (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals)), 0);
2638 tree vfn;
2639
2640 fndecl = copy_node (fndecl);
2641 copy_lang_decl (fndecl);
2642 DECL_ABSTRACT_VIRTUAL_P (fndecl) = 1;
2685 }
2686 else if (strictly_overrides (fndecl, old_fndecl))
2687 {
2688 if (choose == UNDECIDED)
2689 choose = REUSE_NEW;
2690 else if (choose == REUSE_OLD)
2691 {
2692 choose = NEITHER;

--- 38 unchanged lines hidden (view full) ---

2731 /* This MUST be overridden, or the class is ill-formed. */
2732 /* For now, we just make it abstract. */
2733 tree fndecl = TREE_OPERAND (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals)), 0);
2734 tree vfn;
2735
2736 fndecl = copy_node (fndecl);
2737 copy_lang_decl (fndecl);
2738 DECL_ABSTRACT_VIRTUAL_P (fndecl) = 1;
2643 /* Make sure we search for it later. */
2739 DECL_NEEDS_FINAL_OVERRIDER_P (fndecl) = 1;
2740 /* Make sure we search for it later. */
2644 if (! CLASSTYPE_ABSTRACT_VIRTUALS (t))
2645 CLASSTYPE_ABSTRACT_VIRTUALS (t) = error_mark_node;
2646
2647 vfn = build1 (ADDR_EXPR, vfunc_ptr_type_node, fndecl);
2648 TREE_CONSTANT (vfn) = 1;
2649
2741 if (! CLASSTYPE_ABSTRACT_VIRTUALS (t))
2742 CLASSTYPE_ABSTRACT_VIRTUALS (t) = error_mark_node;
2743
2744 vfn = build1 (ADDR_EXPR, vfunc_ptr_type_node, fndecl);
2745 TREE_CONSTANT (vfn) = 1;
2746
2650 /* We can use integer_zero_node, as we will will core dump
2651 if this is used anyway. */
2747 /* We can use integer_zero_node, as we will core dump
2748 if this is used anyway. */
2652 TREE_VALUE (virtuals) = build_vtable_entry (integer_zero_node, vfn);
2653 }
2654 }
2655 virtuals = TREE_CHAIN (virtuals);
2656 old_virtuals = TREE_CHAIN (old_virtuals);
2657 }
2658
2749 TREE_VALUE (virtuals) = build_vtable_entry (integer_zero_node, vfn);
2750 }
2751 }
2752 virtuals = TREE_CHAIN (virtuals);
2753 old_virtuals = TREE_CHAIN (old_virtuals);
2754 }
2755
2659 /* Let's reuse the old vtable. */
2756 /* Let's reuse the old vtable. */
2660 if (choose == REUSE_OLD)
2661 {
2662 BINFO_VTABLE (binfo) = BINFO_VTABLE (old);
2663 BINFO_VIRTUALS (binfo) = BINFO_VIRTUALS (old);
2664 }
2665}
2666
2667/* Merge in overrides for virtual bases.
2668 BINFO is the hierarchy we want to modify, and OLD has the potential
2669 overrides. */
2757 if (choose == REUSE_OLD)
2758 {
2759 BINFO_VTABLE (binfo) = BINFO_VTABLE (old);
2760 BINFO_VIRTUALS (binfo) = BINFO_VIRTUALS (old);
2761 }
2762}
2763
2764/* Merge in overrides for virtual bases.
2765 BINFO is the hierarchy we want to modify, and OLD has the potential
2766 overrides. */
2767
2670static void
2671merge_overrides (binfo, old, do_self, t)
2768static void
2769merge_overrides (binfo, old, do_self, t)
2672 tree binfo, old, t;
2770 tree binfo, old;
2673 int do_self;
2771 int do_self;
2772 tree t;
2674{
2675 tree binfos = BINFO_BASETYPES (binfo);
2676 tree old_binfos = BINFO_BASETYPES (old);
2677 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2678
2679 /* Should we use something besides CLASSTYPE_VFIELDS? */
2680 if (do_self && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
2681 {
2682 override_one_vtable (binfo, old, t);
2683 }
2684
2685 for (i = 0; i < n_baselinks; i++)
2686 {
2687 tree base_binfo = TREE_VEC_ELT (binfos, i);
2688 tree old_base_binfo = TREE_VEC_ELT (old_binfos, i);
2773{
2774 tree binfos = BINFO_BASETYPES (binfo);
2775 tree old_binfos = BINFO_BASETYPES (old);
2776 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2777
2778 /* Should we use something besides CLASSTYPE_VFIELDS? */
2779 if (do_self && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
2780 {
2781 override_one_vtable (binfo, old, t);
2782 }
2783
2784 for (i = 0; i < n_baselinks; i++)
2785 {
2786 tree base_binfo = TREE_VEC_ELT (binfos, i);
2787 tree old_base_binfo = TREE_VEC_ELT (old_binfos, i);
2689 int is_not_base_vtable =
2690 i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo));
2788 int is_not_base_vtable
2789 = i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo));
2691 if (! TREE_VIA_VIRTUAL (base_binfo))
2692 merge_overrides (base_binfo, old_base_binfo, is_not_base_vtable, t);
2693 }
2694}
2695
2790 if (! TREE_VIA_VIRTUAL (base_binfo))
2791 merge_overrides (base_binfo, old_base_binfo, is_not_base_vtable, t);
2792 }
2793}
2794
2795/* Get the base virtual function declarations in T that are either
2796 overridden or hidden by FNDECL as a list. We set TREE_PURPOSE with
2797 the overrider/hider. */
2798
2799static tree
2800get_basefndecls (fndecl, t)
2801 tree fndecl, t;
2802{
2803 tree methods = TYPE_METHODS (t);
2804 tree base_fndecls = NULL_TREE;
2805 tree binfos = BINFO_BASETYPES (TYPE_BINFO (t));
2806 int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2807
2808 while (methods)
2809 {
2810 if (TREE_CODE (methods) == FUNCTION_DECL
2811 && DECL_VINDEX (methods) != NULL_TREE
2812 && DECL_NAME (fndecl) == DECL_NAME (methods))
2813 base_fndecls = temp_tree_cons (fndecl, methods, base_fndecls);
2814
2815 methods = TREE_CHAIN (methods);
2816 }
2817
2818 if (base_fndecls)
2819 return base_fndecls;
2820
2821 for (i = 0; i < n_baseclasses; i++)
2822 {
2823 tree base_binfo = TREE_VEC_ELT (binfos, i);
2824 tree basetype = BINFO_TYPE (base_binfo);
2825
2826 base_fndecls = chainon (get_basefndecls (fndecl, basetype),
2827 base_fndecls);
2828 }
2829
2830 return base_fndecls;
2831}
2832
2833/* Mark the functions that have been hidden with their overriders.
2834 Since we start out with all functions already marked with a hider,
2835 no need to mark functions that are just hidden. */
2836
2837static void
2838mark_overriders (fndecl, base_fndecls)
2839 tree fndecl, base_fndecls;
2840{
2841 while (base_fndecls)
2842 {
2843 if (overrides (TREE_VALUE (base_fndecls), fndecl))
2844 TREE_PURPOSE (base_fndecls) = fndecl;
2845
2846 base_fndecls = TREE_CHAIN (base_fndecls);
2847 }
2848}
2849
2850/* If this declaration supersedes the declaration of
2851 a method declared virtual in the base class, then
2852 mark this field as being virtual as well. */
2853
2854static void
2855check_for_override (decl, ctype)
2856 tree decl, ctype;
2857{
2858 tree binfos = BINFO_BASETYPES (TYPE_BINFO (ctype));
2859 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2860 int virtualp = DECL_VIRTUAL_P (decl);
2861
2862 for (i = 0; i < n_baselinks; i++)
2863 {
2864 tree base_binfo = TREE_VEC_ELT (binfos, i);
2865 if (TYPE_VIRTUAL_P (BINFO_TYPE (base_binfo))
2866 || flag_all_virtual == 1)
2867 {
2868 tree tmp = get_matching_virtual
2869 (base_binfo, decl,
2870 DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl)));
2871 if (tmp)
2872 {
2873 /* If this function overrides some virtual in some base
2874 class, then the function itself is also necessarily
2875 virtual, even if the user didn't explicitly say so. */
2876 DECL_VIRTUAL_P (decl) = 1;
2877
2878 /* The TMP we really want is the one from the deepest
2879 baseclass on this path, taking care not to
2880 duplicate if we have already found it (via another
2881 path to its virtual baseclass. */
2882 if (TREE_CODE (TREE_TYPE (decl)) == FUNCTION_TYPE)
2883 {
2884 cp_error_at ("method `%D' may not be declared static",
2885 decl);
2886 cp_error_at ("(since `%D' declared virtual in base class.)",
2887 tmp);
2888 break;
2889 }
2890 virtualp = 1;
2891
2892#if 0 /* The signature of an overriding function is not changed. */
2893 {
2894 /* The argument types may have changed... */
2895 tree type = TREE_TYPE (decl);
2896 tree argtypes = TYPE_ARG_TYPES (type);
2897 tree base_variant = TREE_TYPE (TREE_VALUE (argtypes));
2898 tree raises = TYPE_RAISES_EXCEPTIONS (type);
2899
2900 argtypes = commonparms (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (tmp))),
2901 TREE_CHAIN (argtypes));
2902 /* But the return type has not. */
2903 type = build_cplus_method_type (base_variant, TREE_TYPE (type), argtypes);
2904 if (raises)
2905 type = build_exception_variant (type, raises);
2906 TREE_TYPE (decl) = type;
2907 }
2908#endif
2909 DECL_VINDEX (decl)
2910 = tree_cons (NULL_TREE, tmp, DECL_VINDEX (decl));
2911 break;
2912 }
2913 }
2914 }
2915 if (virtualp)
2916 {
2917 if (DECL_VINDEX (decl) == NULL_TREE)
2918 DECL_VINDEX (decl) = error_mark_node;
2919 IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)) = 1;
2920 }
2921}
2922
2923/* Warn about hidden virtual functions that are not overridden in t.
2924 We know that constructors and destructors don't apply. */
2925
2926void
2927warn_hidden (t)
2928 tree t;
2929{
2930 tree method_vec = CLASSTYPE_METHOD_VEC (t);
2931 int n_methods = method_vec ? TREE_VEC_LENGTH (method_vec) : 0;
2932 int i;
2933
2934 /* We go through each separately named virtual function. */
2935 for (i = 2; i < n_methods; ++i)
2936 {
2937 tree fns = TREE_VEC_ELT (method_vec, i);
2938 tree fndecl;
2939
2940 tree base_fndecls = NULL_TREE;
2941 tree binfos = BINFO_BASETYPES (TYPE_BINFO (t));
2942 int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2943
2944 fndecl = OVL_CURRENT (fns);
2945 if (DECL_VINDEX (fndecl) == NULL_TREE)
2946 continue;
2947
2948 /* First we get a list of all possible functions that might be
2949 hidden from each base class. */
2950 for (i = 0; i < n_baseclasses; i++)
2951 {
2952 tree base_binfo = TREE_VEC_ELT (binfos, i);
2953 tree basetype = BINFO_TYPE (base_binfo);
2954
2955 base_fndecls = chainon (get_basefndecls (fndecl, basetype),
2956 base_fndecls);
2957 }
2958
2959 fns = OVL_NEXT (fns);
2960 if (fns)
2961 fndecl = OVL_CURRENT (fns);
2962 else
2963 fndecl = NULL_TREE;
2964
2965 /* ...then mark up all the base functions with overriders, preferring
2966 overriders to hiders. */
2967 if (base_fndecls)
2968 while (fndecl)
2969 {
2970 mark_overriders (fndecl, base_fndecls);
2971
2972 fns = OVL_NEXT (fns);
2973 if (fns)
2974 fndecl = OVL_CURRENT (fns);
2975 else
2976 fndecl = NULL_TREE;
2977 }
2978
2979 /* Now give a warning for all base functions without overriders,
2980 as they are hidden. */
2981 while (base_fndecls)
2982 {
2983 if (! overrides (TREE_VALUE (base_fndecls),
2984 TREE_PURPOSE (base_fndecls)))
2985 {
2986 /* Here we know it is a hider, and no overrider exists. */
2987 cp_warning_at ("`%D' was hidden", TREE_VALUE (base_fndecls));
2988 cp_warning_at (" by `%D'", TREE_PURPOSE (base_fndecls));
2989 }
2990
2991 base_fndecls = TREE_CHAIN (base_fndecls);
2992 }
2993 }
2994}
2995
2996/* Check for things that are invalid. There are probably plenty of other
2997 things we should check for also. */
2998
2999static void
3000finish_struct_anon (t)
3001 tree t;
3002{
3003 tree field;
3004 for (field = TYPE_FIELDS (t); field; field = TREE_CHAIN (field))
3005 {
3006 if (TREE_STATIC (field))
3007 continue;
3008 if (TREE_CODE (field) != FIELD_DECL)
3009 continue;
3010
3011 if (DECL_NAME (field) == NULL_TREE
3012 && TREE_CODE (TREE_TYPE (field)) == UNION_TYPE)
3013 {
3014 tree* uelt = &TYPE_FIELDS (TREE_TYPE (field));
3015 for (; *uelt; uelt = &TREE_CHAIN (*uelt))
3016 {
3017 if (TREE_CODE (*uelt) != FIELD_DECL)
3018 continue;
3019
3020 if (TREE_PRIVATE (*uelt))
3021 cp_pedwarn_at ("private member `%#D' in anonymous union",
3022 *uelt);
3023 else if (TREE_PROTECTED (*uelt))
3024 cp_pedwarn_at ("protected member `%#D' in anonymous union",
3025 *uelt);
3026
3027 TREE_PRIVATE (*uelt) = TREE_PRIVATE (field);
3028 TREE_PROTECTED (*uelt) = TREE_PROTECTED (field);
3029 }
3030 }
3031 }
3032}
3033
2696extern int interface_only, interface_unknown;
2697
2698/* Create a RECORD_TYPE or UNION_TYPE node for a C struct or union declaration
2699 (or C++ class declaration).
2700
2701 For C++, we must handle the building of derived classes.
2702 Also, C++ allows static class members. The way that this is
2703 handled is to keep the field name where it is (as the DECL_NAME

--- 15 unchanged lines hidden (view full) ---

2719 table is treated in exactly the same way as in the case of single
2720 inheritance. Additional virtual function tables have different
2721 DELTAs, which tell how to adjust `this' to point to the right thing.
2722
2723 LIST_OF_FIELDLISTS is just that. The elements of the list are
2724 TREE_LIST elements, whose TREE_PURPOSE field tells what access
2725 the list has, and the TREE_VALUE slot gives the actual fields.
2726
3034extern int interface_only, interface_unknown;
3035
3036/* Create a RECORD_TYPE or UNION_TYPE node for a C struct or union declaration
3037 (or C++ class declaration).
3038
3039 For C++, we must handle the building of derived classes.
3040 Also, C++ allows static class members. The way that this is
3041 handled is to keep the field name where it is (as the DECL_NAME

--- 15 unchanged lines hidden (view full) ---

3057 table is treated in exactly the same way as in the case of single
3058 inheritance. Additional virtual function tables have different
3059 DELTAs, which tell how to adjust `this' to point to the right thing.
3060
3061 LIST_OF_FIELDLISTS is just that. The elements of the list are
3062 TREE_LIST elements, whose TREE_PURPOSE field tells what access
3063 the list has, and the TREE_VALUE slot gives the actual fields.
3064
3065 ATTRIBUTES is the set of decl attributes to be applied, if any.
3066
2727 If flag_all_virtual == 1, then we lay all functions into
2728 the virtual function table, as though they were declared
2729 virtual. Constructors do not lay down in the virtual function table.
2730
2731 If flag_all_virtual == 2, then we lay all functions into
2732 the virtual function table, such that virtual functions
2733 occupy a space by themselves, and then all functions
2734 of the class occupy a space by themselves. This is illustrated

--- 20 unchanged lines hidden (view full) ---

2755 or otherwise in a type-consistent manner. */
2756
2757tree
2758finish_struct_1 (t, warn_anon)
2759 tree t;
2760 int warn_anon;
2761{
2762 int old;
3067 If flag_all_virtual == 1, then we lay all functions into
3068 the virtual function table, as though they were declared
3069 virtual. Constructors do not lay down in the virtual function table.
3070
3071 If flag_all_virtual == 2, then we lay all functions into
3072 the virtual function table, such that virtual functions
3073 occupy a space by themselves, and then all functions
3074 of the class occupy a space by themselves. This is illustrated

--- 20 unchanged lines hidden (view full) ---

3095 or otherwise in a type-consistent manner. */
3096
3097tree
3098finish_struct_1 (t, warn_anon)
3099 tree t;
3100 int warn_anon;
3101{
3102 int old;
2763 int round_up_size = 1;
2764
2765 tree name = TYPE_IDENTIFIER (t);
2766 enum tree_code code = TREE_CODE (t);
2767 tree fields = TYPE_FIELDS (t);
3103 tree name = TYPE_IDENTIFIER (t);
3104 enum tree_code code = TREE_CODE (t);
3105 tree fields = TYPE_FIELDS (t);
2768 tree fn_fields = CLASSTYPE_METHODS (t);
3106 tree fn_fields = TYPE_METHODS (t);
2769 tree x, last_x, method_vec;
3107 tree x, last_x, method_vec;
2770 int needs_virtual_dtor;
2771 int all_virtual;
2772 int has_virtual;
2773 int max_has_virtual;
2774 tree pending_virtuals = NULL_TREE;
3108 int all_virtual;
3109 int has_virtual;
3110 int max_has_virtual;
3111 tree pending_virtuals = NULL_TREE;
3112 tree pending_hard_virtuals = NULL_TREE;
2775 tree abstract_virtuals = NULL_TREE;
2776 tree vfield;
2777 tree vfields;
2778 int cant_have_default_ctor;
2779 int cant_have_const_ctor;
3113 tree abstract_virtuals = NULL_TREE;
3114 tree vfield;
3115 tree vfields;
3116 int cant_have_default_ctor;
3117 int cant_have_const_ctor;
2780 int cant_synth_copy_ctor;
2781 int cant_synth_asn_ref;
2782 int no_const_asn_ref;
2783
2784 /* The index of the first base class which has virtual
2785 functions. Only applied to non-virtual baseclasses. */
2786 int first_vfn_base_index;
2787
2788 int n_baseclasses;
2789 int any_default_members = 0;
2790 int const_sans_init = 0;
2791 int ref_sans_init = 0;
2792 int nonprivate_method = 0;
3118 int no_const_asn_ref;
3119
3120 /* The index of the first base class which has virtual
3121 functions. Only applied to non-virtual baseclasses. */
3122 int first_vfn_base_index;
3123
3124 int n_baseclasses;
3125 int any_default_members = 0;
3126 int const_sans_init = 0;
3127 int ref_sans_init = 0;
3128 int nonprivate_method = 0;
2793 tree t_binfo = TYPE_BINFO (t);
2794 tree access_decls = NULL_TREE;
2795 int aggregate = 1;
3129 tree access_decls = NULL_TREE;
3130 int aggregate = 1;
3131 int empty = 1;
3132 int has_pointers = 0;
2796
2797 if (warn_anon && code != UNION_TYPE && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t)))
2798 pedwarn ("anonymous class type not used to declare any objects");
2799
2800 if (TYPE_SIZE (t))
2801 {
2802 if (IS_AGGR_TYPE (t))
2803 cp_error ("redefinition of `%#T'", t);
2804 else
2805 my_friendly_abort (172);
2806 popclass (0);
2807 return t;
2808 }
2809
3133
3134 if (warn_anon && code != UNION_TYPE && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t)))
3135 pedwarn ("anonymous class type not used to declare any objects");
3136
3137 if (TYPE_SIZE (t))
3138 {
3139 if (IS_AGGR_TYPE (t))
3140 cp_error ("redefinition of `%#T'", t);
3141 else
3142 my_friendly_abort (172);
3143 popclass (0);
3144 return t;
3145 }
3146
2810 if (dont_allow_type_definitions)
2811 {
2812 pedwarn ("types cannot be defined %s",
2813 dont_allow_type_definitions);
2814 }
2815
2816 GNU_xref_decl (current_function_decl, t);
2817
2818 /* If this type was previously laid out as a forward reference,
2819 make sure we lay it out again. */
2820
2821 TYPE_SIZE (t) = NULL_TREE;
2822 CLASSTYPE_GOT_SEMICOLON (t) = 0;
2823
2824#if 0
2825 /* This is in general too late to do this. I moved the main case up to
2826 left_curly, what else needs to move? */
2827 if (! IS_SIGNATURE (t))
2828 {
2829 my_friendly_assert (CLASSTYPE_INTERFACE_ONLY (t) == interface_only, 999);
2830 my_friendly_assert (CLASSTYPE_INTERFACE_KNOWN (t) == ! interface_unknown, 999);
2831 }
2832#endif
2833
3147 GNU_xref_decl (current_function_decl, t);
3148
3149 /* If this type was previously laid out as a forward reference,
3150 make sure we lay it out again. */
3151
3152 TYPE_SIZE (t) = NULL_TREE;
3153 CLASSTYPE_GOT_SEMICOLON (t) = 0;
3154
3155#if 0
3156 /* This is in general too late to do this. I moved the main case up to
3157 left_curly, what else needs to move? */
3158 if (! IS_SIGNATURE (t))
3159 {
3160 my_friendly_assert (CLASSTYPE_INTERFACE_ONLY (t) == interface_only, 999);
3161 my_friendly_assert (CLASSTYPE_INTERFACE_KNOWN (t) == ! interface_unknown, 999);
3162 }
3163#endif
3164
2834#if 0
2835 if (flag_rtti)
2836 build_t_desc (t, 0);
2837#endif
2838
2839 TYPE_BINFO (t) = NULL_TREE;
2840
2841 old = suspend_momentary ();
2842
2843 /* Install struct as DECL_FIELD_CONTEXT of each field decl.
2844 Also process specified field sizes.
2845 Set DECL_FIELD_SIZE to the specified size, or 0 if none specified.
2846 The specified size is found in the DECL_INITIAL.
2847 Store 0 there, except for ": 0" fields (so we can find them
2848 and delete them, below). */
2849
3165 old = suspend_momentary ();
3166
3167 /* Install struct as DECL_FIELD_CONTEXT of each field decl.
3168 Also process specified field sizes.
3169 Set DECL_FIELD_SIZE to the specified size, or 0 if none specified.
3170 The specified size is found in the DECL_INITIAL.
3171 Store 0 there, except for ": 0" fields (so we can find them
3172 and delete them, below). */
3173
2850 if (t_binfo && BINFO_BASETYPES (t_binfo))
2851 n_baseclasses = TREE_VEC_LENGTH (BINFO_BASETYPES (t_binfo));
3174 if (TYPE_BINFO_BASETYPES (t))
3175 n_baseclasses = TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (t));
2852 else
2853 n_baseclasses = 0;
2854
2855 if (n_baseclasses > 0)
2856 {
2857 struct base_info base_info;
2858
3176 else
3177 n_baseclasses = 0;
3178
3179 if (n_baseclasses > 0)
3180 {
3181 struct base_info base_info;
3182
2859 /* If using multiple inheritance, this may cause variants of our
2860 basetypes to be used (instead of their canonical forms). */
2861 tree vf = layout_basetypes (t, BINFO_BASETYPES (t_binfo));
2862 last_x = tree_last (vf);
2863 fields = chainon (vf, fields);
2864
2865 first_vfn_base_index = finish_base_struct (t, &base_info, t_binfo);
2866 /* Remember where we got our vfield from */
3183 first_vfn_base_index = finish_base_struct (t, &base_info);
3184 /* Remember where we got our vfield from. */
2867 CLASSTYPE_VFIELD_PARENT (t) = first_vfn_base_index;
2868 has_virtual = base_info.has_virtual;
2869 max_has_virtual = base_info.max_has_virtual;
2870 CLASSTYPE_N_SUPERCLASSES (t) += base_info.n_ancestors;
2871 vfield = base_info.vfield;
2872 vfields = base_info.vfields;
3185 CLASSTYPE_VFIELD_PARENT (t) = first_vfn_base_index;
3186 has_virtual = base_info.has_virtual;
3187 max_has_virtual = base_info.max_has_virtual;
3188 CLASSTYPE_N_SUPERCLASSES (t) += base_info.n_ancestors;
3189 vfield = base_info.vfield;
3190 vfields = base_info.vfields;
3191 CLASSTYPE_RTTI (t) = base_info.rtti;
2873 cant_have_default_ctor = base_info.cant_have_default_ctor;
2874 cant_have_const_ctor = base_info.cant_have_const_ctor;
3192 cant_have_default_ctor = base_info.cant_have_default_ctor;
3193 cant_have_const_ctor = base_info.cant_have_const_ctor;
2875 cant_synth_copy_ctor = base_info.cant_synth_copy_ctor;
2876 cant_synth_asn_ref = base_info.cant_synth_asn_ref;
2877 no_const_asn_ref = base_info.no_const_asn_ref;
3194 no_const_asn_ref = base_info.no_const_asn_ref;
2878 needs_virtual_dtor = base_info.needs_virtual_dtor;
2879 n_baseclasses = TREE_VEC_LENGTH (BINFO_BASETYPES (t_binfo));
2880 aggregate = 0;
2881 }
2882 else
2883 {
2884 first_vfn_base_index = -1;
2885 has_virtual = 0;
2886 max_has_virtual = has_virtual;
2887 vfield = NULL_TREE;
2888 vfields = NULL_TREE;
3195 aggregate = 0;
3196 }
3197 else
3198 {
3199 first_vfn_base_index = -1;
3200 has_virtual = 0;
3201 max_has_virtual = has_virtual;
3202 vfield = NULL_TREE;
3203 vfields = NULL_TREE;
2889 last_x = NULL_TREE;
3204 CLASSTYPE_RTTI (t) = NULL_TREE;
2890 cant_have_default_ctor = 0;
2891 cant_have_const_ctor = 0;
3205 cant_have_default_ctor = 0;
3206 cant_have_const_ctor = 0;
2892 cant_synth_copy_ctor = 0;
2893 cant_synth_asn_ref = 0;
2894 no_const_asn_ref = 0;
3207 no_const_asn_ref = 0;
2895 needs_virtual_dtor = 0;
2896 }
2897
2898#if 0
2899 /* Both of these should be done before now. */
2900 if (write_virtuals == 3 && CLASSTYPE_INTERFACE_KNOWN (t)
2901 && ! IS_SIGNATURE (t))
2902 {
2903 my_friendly_assert (CLASSTYPE_INTERFACE_ONLY (t) == interface_only, 999);
2904 my_friendly_assert (CLASSTYPE_VTABLE_NEEDS_WRITING (t) == ! interface_only, 999);
2905 }
2906#endif
2907
2908 /* The three of these are approximations which may later be
2909 modified. Needed at this point to make add_virtual_function
2910 and modify_vtable_entries work. */
3208 }
3209
3210#if 0
3211 /* Both of these should be done before now. */
3212 if (write_virtuals == 3 && CLASSTYPE_INTERFACE_KNOWN (t)
3213 && ! IS_SIGNATURE (t))
3214 {
3215 my_friendly_assert (CLASSTYPE_INTERFACE_ONLY (t) == interface_only, 999);
3216 my_friendly_assert (CLASSTYPE_VTABLE_NEEDS_WRITING (t) == ! interface_only, 999);
3217 }
3218#endif
3219
3220 /* The three of these are approximations which may later be
3221 modified. Needed at this point to make add_virtual_function
3222 and modify_vtable_entries work. */
2911 TREE_CHAIN (t_binfo) = TYPE_BINFO (t);
2912 TYPE_BINFO (t) = t_binfo;
2913 CLASSTYPE_VFIELDS (t) = vfields;
2914 CLASSTYPE_VFIELD (t) = vfield;
2915
2916 if (IS_SIGNATURE (t))
2917 all_virtual = 0;
3223 CLASSTYPE_VFIELDS (t) = vfields;
3224 CLASSTYPE_VFIELD (t) = vfield;
3225
3226 if (IS_SIGNATURE (t))
3227 all_virtual = 0;
2918 else if (flag_all_virtual == 1 && TYPE_OVERLOADS_METHOD_CALL_EXPR (t))
3228 else if (flag_all_virtual == 1)
2919 all_virtual = 1;
2920 else
2921 all_virtual = 0;
2922
3229 all_virtual = 1;
3230 else
3231 all_virtual = 0;
3232
2923 for (x = CLASSTYPE_METHODS (t); x; x = TREE_CHAIN (x))
3233 for (x = TYPE_METHODS (t); x; x = TREE_CHAIN (x))
2924 {
2925 GNU_xref_member (current_class_name, x);
2926
2927 nonprivate_method |= ! TREE_PRIVATE (x);
2928
2929 /* If this was an evil function, don't keep it in class. */
2930 if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (x)))
2931 continue;
2932
2933 DECL_CLASS_CONTEXT (x) = t;
2934
2935 /* Do both of these, even though they're in the same union;
2936 if the insn `r' member and the size `i' member are
2937 different sizes, as on the alpha, the larger of the two
2938 will end up with garbage in it. */
2939 DECL_SAVED_INSNS (x) = NULL_RTX;
2940 DECL_FIELD_SIZE (x) = 0;
2941
3234 {
3235 GNU_xref_member (current_class_name, x);
3236
3237 nonprivate_method |= ! TREE_PRIVATE (x);
3238
3239 /* If this was an evil function, don't keep it in class. */
3240 if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (x)))
3241 continue;
3242
3243 DECL_CLASS_CONTEXT (x) = t;
3244
3245 /* Do both of these, even though they're in the same union;
3246 if the insn `r' member and the size `i' member are
3247 different sizes, as on the alpha, the larger of the two
3248 will end up with garbage in it. */
3249 DECL_SAVED_INSNS (x) = NULL_RTX;
3250 DECL_FIELD_SIZE (x) = 0;
3251
3252 check_for_override (x, t);
3253 if (DECL_ABSTRACT_VIRTUAL_P (x) && ! DECL_VINDEX (x))
3254 cp_error_at ("initializer specified for non-virtual method `%D'", x);
3255
2942 /* The name of the field is the original field name
2943 Save this in auxiliary field for later overloading. */
2944 if (DECL_VINDEX (x)
2945 || (all_virtual == 1 && ! DECL_CONSTRUCTOR_P (x)))
2946 {
3256 /* The name of the field is the original field name
3257 Save this in auxiliary field for later overloading. */
3258 if (DECL_VINDEX (x)
3259 || (all_virtual == 1 && ! DECL_CONSTRUCTOR_P (x)))
3260 {
2947 pending_virtuals = add_virtual_function (pending_virtuals,
2948 &has_virtual, x, t);
3261 add_virtual_function (&pending_virtuals, &pending_hard_virtuals,
3262 &has_virtual, x, t);
2949 if (DECL_ABSTRACT_VIRTUAL_P (x))
2950 abstract_virtuals = tree_cons (NULL_TREE, x, abstract_virtuals);
3263 if (DECL_ABSTRACT_VIRTUAL_P (x))
3264 abstract_virtuals = tree_cons (NULL_TREE, x, abstract_virtuals);
3265#if 0
3266 /* XXX Why did I comment this out? (jason) */
2951 else
2952 TREE_USED (x) = 1;
3267 else
3268 TREE_USED (x) = 1;
3269#endif
2953 }
2954 }
2955
3270 }
3271 }
3272
2956 for (x = TYPE_FIELDS (t); x; x = TREE_CHAIN (x))
3273 if (n_baseclasses)
3274 fields = chainon (build_vbase_pointer_fields (t), fields);
3275
3276 last_x = NULL_TREE;
3277 for (x = fields; x; x = TREE_CHAIN (x))
2957 {
2958 GNU_xref_member (current_class_name, x);
2959
3278 {
3279 GNU_xref_member (current_class_name, x);
3280
2960 /* Handle access declarations. */
2961 if (DECL_NAME (x) && TREE_CODE (DECL_NAME (x)) == SCOPE_REF)
3281 if (TREE_CODE (x) == FIELD_DECL)
2962 {
3282 {
2963 tree fdecl = TREE_OPERAND (DECL_NAME (x), 1);
2964 enum access_type access
2965 = TREE_PRIVATE (x) ? access_private :
2966 TREE_PROTECTED (x) ? access_protected : access_public;
3283 DECL_PACKED (x) |= TYPE_PACKED (t);
3284 empty = 0;
3285 }
2967
3286
3287 if (TREE_CODE (x) == USING_DECL)
3288 {
3289 /* Save access declarations for later. */
2968 if (last_x)
2969 TREE_CHAIN (last_x) = TREE_CHAIN (x);
2970 else
2971 fields = TREE_CHAIN (x);
3290 if (last_x)
3291 TREE_CHAIN (last_x) = TREE_CHAIN (x);
3292 else
3293 fields = TREE_CHAIN (x);
2972
2973 access_decls = tree_cons ((tree) access, fdecl, access_decls);
3294
3295 access_decls = scratch_tree_cons (NULL_TREE, x, access_decls);
2974 continue;
2975 }
2976
2977 last_x = x;
2978
3296 continue;
3297 }
3298
3299 last_x = x;
3300
2979 if (TREE_CODE (x) == TYPE_DECL)
3301 if (TREE_CODE (x) == TYPE_DECL
3302 || TREE_CODE (x) == TEMPLATE_DECL)
2980 continue;
2981
2982 /* If we've gotten this far, it's a data member, possibly static,
3303 continue;
3304
3305 /* If we've gotten this far, it's a data member, possibly static,
2983 or an enumerator. */
3306 or an enumerator. */
2984
2985 DECL_FIELD_CONTEXT (x) = t;
2986
2987 /* ``A local class cannot have static data members.'' ARM 9.4 */
2988 if (current_function_decl && TREE_STATIC (x))
2989 cp_error_at ("field `%D' in local class cannot be static", x);
2990
2991 /* Perform error checking that did not get done in

--- 12 unchanged lines hidden (view full) ---

3004 else if (TREE_CODE (TREE_TYPE (x)) == OFFSET_TYPE)
3005 {
3006 cp_error_at ("field `%D' invalidly declared offset type", x);
3007 TREE_TYPE (x) = build_pointer_type (TREE_TYPE (x));
3008 }
3009
3010#if 0
3011 if (DECL_NAME (x) == constructor_name (t))
3307
3308 DECL_FIELD_CONTEXT (x) = t;
3309
3310 /* ``A local class cannot have static data members.'' ARM 9.4 */
3311 if (current_function_decl && TREE_STATIC (x))
3312 cp_error_at ("field `%D' in local class cannot be static", x);
3313
3314 /* Perform error checking that did not get done in

--- 12 unchanged lines hidden (view full) ---

3327 else if (TREE_CODE (TREE_TYPE (x)) == OFFSET_TYPE)
3328 {
3329 cp_error_at ("field `%D' invalidly declared offset type", x);
3330 TREE_TYPE (x) = build_pointer_type (TREE_TYPE (x));
3331 }
3332
3333#if 0
3334 if (DECL_NAME (x) == constructor_name (t))
3012 cant_have_default_ctor = cant_synth_copy_ctor = 1;
3335 cant_have_default_ctor = 1;
3013#endif
3014
3015 if (TREE_TYPE (x) == error_mark_node)
3016 continue;
3017
3018 DECL_SAVED_INSNS (x) = NULL_RTX;
3019 DECL_FIELD_SIZE (x) = 0;
3020

--- 23 unchanged lines hidden (view full) ---

3044 {
3045 if (DECL_INITIAL (x) == NULL_TREE)
3046 ref_sans_init = 1;
3047
3048 /* ARM $12.6.2: [A member initializer list] (or, for an
3049 aggregate, initialization by a brace-enclosed list) is the
3050 only way to initialize nonstatic const and reference
3051 members. */
3336#endif
3337
3338 if (TREE_TYPE (x) == error_mark_node)
3339 continue;
3340
3341 DECL_SAVED_INSNS (x) = NULL_RTX;
3342 DECL_FIELD_SIZE (x) = 0;
3343

--- 23 unchanged lines hidden (view full) ---

3367 {
3368 if (DECL_INITIAL (x) == NULL_TREE)
3369 ref_sans_init = 1;
3370
3371 /* ARM $12.6.2: [A member initializer list] (or, for an
3372 aggregate, initialization by a brace-enclosed list) is the
3373 only way to initialize nonstatic const and reference
3374 members. */
3052 cant_synth_asn_ref = 1;
3053 cant_have_default_ctor = 1;
3375 cant_have_default_ctor = 1;
3376 TYPE_HAS_COMPLEX_ASSIGN_REF (t) = 1;
3054
3055 if (! TYPE_HAS_CONSTRUCTOR (t) && extra_warnings)
3056 {
3057 if (DECL_NAME (x))
3058 cp_warning_at ("non-static reference `%#D' in class without a constructor", x);
3059 else
3060 cp_warning_at ("non-static reference in class without a constructor", x);
3061 }
3062 }
3063
3377
3378 if (! TYPE_HAS_CONSTRUCTOR (t) && extra_warnings)
3379 {
3380 if (DECL_NAME (x))
3381 cp_warning_at ("non-static reference `%#D' in class without a constructor", x);
3382 else
3383 cp_warning_at ("non-static reference in class without a constructor", x);
3384 }
3385 }
3386
3387 if (TREE_CODE (TREE_TYPE (x)) == POINTER_TYPE)
3388 has_pointers = 1;
3389
3064 /* If any field is const, the structure type is pseudo-const. */
3065 if (TREE_READONLY (x))
3066 {
3067 C_TYPE_FIELDS_READONLY (t) = 1;
3068 if (DECL_INITIAL (x) == NULL_TREE)
3069 const_sans_init = 1;
3070
3071 /* ARM $12.6.2: [A member initializer list] (or, for an
3072 aggregate, initialization by a brace-enclosed list) is the
3073 only way to initialize nonstatic const and reference
3074 members. */
3390 /* If any field is const, the structure type is pseudo-const. */
3391 if (TREE_READONLY (x))
3392 {
3393 C_TYPE_FIELDS_READONLY (t) = 1;
3394 if (DECL_INITIAL (x) == NULL_TREE)
3395 const_sans_init = 1;
3396
3397 /* ARM $12.6.2: [A member initializer list] (or, for an
3398 aggregate, initialization by a brace-enclosed list) is the
3399 only way to initialize nonstatic const and reference
3400 members. */
3075 cant_synth_asn_ref = 1;
3076 cant_have_default_ctor = 1;
3401 cant_have_default_ctor = 1;
3402 TYPE_HAS_COMPLEX_ASSIGN_REF (t) = 1;
3077
3078 if (! TYPE_HAS_CONSTRUCTOR (t) && !IS_SIGNATURE (t)
3079 && extra_warnings)
3080 {
3081 if (DECL_NAME (x))
3082 cp_warning_at ("non-static const member `%#D' in class without a constructor", x);
3083 else
3084 cp_warning_at ("non-static const member in class without a constructor", x);

--- 28 unchanged lines hidden (view full) ---

3113 {
3114 cp_error_at ("bit-field `%#D' with non-integral type", x);
3115 DECL_INITIAL (x) = NULL;
3116 }
3117
3118 /* Detect and ignore out of range field width. */
3119 if (DECL_INITIAL (x))
3120 {
3403
3404 if (! TYPE_HAS_CONSTRUCTOR (t) && !IS_SIGNATURE (t)
3405 && extra_warnings)
3406 {
3407 if (DECL_NAME (x))
3408 cp_warning_at ("non-static const member `%#D' in class without a constructor", x);
3409 else
3410 cp_warning_at ("non-static const member in class without a constructor", x);

--- 28 unchanged lines hidden (view full) ---

3439 {
3440 cp_error_at ("bit-field `%#D' with non-integral type", x);
3441 DECL_INITIAL (x) = NULL;
3442 }
3443
3444 /* Detect and ignore out of range field width. */
3445 if (DECL_INITIAL (x))
3446 {
3121 register int width = TREE_INT_CST_LOW (DECL_INITIAL (x));
3447 tree w = DECL_INITIAL (x);
3448 register int width = 0;
3122
3449
3123 if (width < 0)
3450 /* Avoid the non_lvalue wrapper added by fold for PLUS_EXPRs. */
3451 STRIP_NOPS (w);
3452
3453 /* detect invalid field size. */
3454 if (TREE_CODE (w) == CONST_DECL)
3455 w = DECL_INITIAL (w);
3456 else if (TREE_READONLY_DECL_P (w))
3457 w = decl_constant_value (w);
3458
3459 if (TREE_CODE (w) != INTEGER_CST)
3124 {
3460 {
3461 cp_error_at ("bit-field `%D' width not an integer constant",
3462 x);
3463 DECL_INITIAL (x) = NULL_TREE;
3464 }
3465 else if (width = TREE_INT_CST_LOW (w),
3466 width < 0)
3467 {
3125 DECL_INITIAL (x) = NULL;
3126 cp_error_at ("negative width in bit-field `%D'", x);
3127 }
3128 else if (width == 0 && DECL_NAME (x) != 0)
3129 {
3130 DECL_INITIAL (x) = NULL;
3131 cp_error_at ("zero width for bit-field `%D'", x);
3132 }
3133 else if (width
3134 > TYPE_PRECISION (long_long_unsigned_type_node))
3135 {
3136 /* The backend will dump if you try to use something
3137 too big; avoid that. */
3138 DECL_INITIAL (x) = NULL;
3139 sorry ("bit-fields larger than %d bits",
3140 TYPE_PRECISION (long_long_unsigned_type_node));
3141 cp_error_at (" in declaration of `%D'", x);
3142 }
3143 else if (width > TYPE_PRECISION (TREE_TYPE (x))
3468 DECL_INITIAL (x) = NULL;
3469 cp_error_at ("negative width in bit-field `%D'", x);
3470 }
3471 else if (width == 0 && DECL_NAME (x) != 0)
3472 {
3473 DECL_INITIAL (x) = NULL;
3474 cp_error_at ("zero width for bit-field `%D'", x);
3475 }
3476 else if (width
3477 > TYPE_PRECISION (long_long_unsigned_type_node))
3478 {
3479 /* The backend will dump if you try to use something
3480 too big; avoid that. */
3481 DECL_INITIAL (x) = NULL;
3482 sorry ("bit-fields larger than %d bits",
3483 TYPE_PRECISION (long_long_unsigned_type_node));
3484 cp_error_at (" in declaration of `%D'", x);
3485 }
3486 else if (width > TYPE_PRECISION (TREE_TYPE (x))
3144 && TREE_CODE (TREE_TYPE (x)) != ENUMERAL_TYPE)
3487 && TREE_CODE (TREE_TYPE (x)) != ENUMERAL_TYPE
3488 && TREE_CODE (TREE_TYPE (x)) != BOOLEAN_TYPE)
3145 {
3146 cp_warning_at ("width of `%D' exceeds its type", x);
3147 }
3148 else if (TREE_CODE (TREE_TYPE (x)) == ENUMERAL_TYPE
3149 && ((min_precision (TYPE_MIN_VALUE (TREE_TYPE (x)),
3150 TREE_UNSIGNED (TREE_TYPE (x))) > width)
3151 || (min_precision (TYPE_MAX_VALUE (TREE_TYPE (x)),
3152 TREE_UNSIGNED (TREE_TYPE (x))) > width)))
3153 {
3154 cp_warning_at ("`%D' is too small to hold all values of `%#T'",
3155 x, TREE_TYPE (x));
3156 }
3489 {
3490 cp_warning_at ("width of `%D' exceeds its type", x);
3491 }
3492 else if (TREE_CODE (TREE_TYPE (x)) == ENUMERAL_TYPE
3493 && ((min_precision (TYPE_MIN_VALUE (TREE_TYPE (x)),
3494 TREE_UNSIGNED (TREE_TYPE (x))) > width)
3495 || (min_precision (TYPE_MAX_VALUE (TREE_TYPE (x)),
3496 TREE_UNSIGNED (TREE_TYPE (x))) > width)))
3497 {
3498 cp_warning_at ("`%D' is too small to hold all values of `%#T'",
3499 x, TREE_TYPE (x));
3500 }
3157 }
3158
3501
3159 /* Process valid field width. */
3160 if (DECL_INITIAL (x))
3161 {
3162 register int width = TREE_INT_CST_LOW (DECL_INITIAL (x));
3163
3164 if (width == 0)
3502 if (DECL_INITIAL (x) == NULL_TREE)
3503 ;
3504 else if (width == 0)
3165 {
3166#ifdef EMPTY_FIELD_BOUNDARY
3505 {
3506#ifdef EMPTY_FIELD_BOUNDARY
3167 /* field size 0 => mark following field as "aligned" */
3168 if (TREE_CHAIN (x))
3169 DECL_ALIGN (TREE_CHAIN (x))
3170 = MAX (DECL_ALIGN (TREE_CHAIN (x)), EMPTY_FIELD_BOUNDARY);
3171 /* field of size 0 at the end => round up the size. */
3172 else
3173 round_up_size = EMPTY_FIELD_BOUNDARY;
3507 DECL_ALIGN (x) = MAX (DECL_ALIGN (x), EMPTY_FIELD_BOUNDARY);
3174#endif
3175#ifdef PCC_BITFIELD_TYPE_MATTERS
3176 DECL_ALIGN (x) = MAX (DECL_ALIGN (x),
3177 TYPE_ALIGN (TREE_TYPE (x)));
3178#endif
3179 }
3180 else
3181 {
3182 DECL_INITIAL (x) = NULL_TREE;
3183 DECL_FIELD_SIZE (x) = width;
3184 DECL_BIT_FIELD (x) = 1;
3508#endif
3509#ifdef PCC_BITFIELD_TYPE_MATTERS
3510 DECL_ALIGN (x) = MAX (DECL_ALIGN (x),
3511 TYPE_ALIGN (TREE_TYPE (x)));
3512#endif
3513 }
3514 else
3515 {
3516 DECL_INITIAL (x) = NULL_TREE;
3517 DECL_FIELD_SIZE (x) = width;
3518 DECL_BIT_FIELD (x) = 1;
3185 /* Traditionally a bit field is unsigned
3186 even if declared signed. */
3187 if (flag_traditional
3188 && TREE_CODE (TREE_TYPE (x)) == INTEGER_TYPE)
3189 TREE_TYPE (x) = unsigned_type_node;
3190 }
3191 }
3192 else
3193 /* Non-bit-fields are aligned for their type. */
3194 DECL_ALIGN (x) = MAX (DECL_ALIGN (x), TYPE_ALIGN (TREE_TYPE (x)));
3195 }
3196 else
3197 {
3198 tree type = TREE_TYPE (x);
3199
3519 }
3520 }
3521 else
3522 /* Non-bit-fields are aligned for their type. */
3523 DECL_ALIGN (x) = MAX (DECL_ALIGN (x), TYPE_ALIGN (TREE_TYPE (x)));
3524 }
3525 else
3526 {
3527 tree type = TREE_TYPE (x);
3528
3200 if (TREE_CODE (type) == ARRAY_TYPE)
3529 while (TREE_CODE (type) == ARRAY_TYPE)
3201 type = TREE_TYPE (type);
3202
3203 if (TYPE_LANG_SPECIFIC (type) && ! ANON_UNION_P (x)
3204 && ! TYPE_PTRMEMFUNC_P (type))
3205 {
3206 /* Never let anything with uninheritable virtuals
3207 make it through without complaint. */
3208 if (CLASSTYPE_ABSTRACT_VIRTUALS (type))

--- 5 unchanged lines hidden (view full) ---

3214
3215 if (code == UNION_TYPE)
3216 {
3217 char *fie = NULL;
3218 if (TYPE_NEEDS_CONSTRUCTING (type))
3219 fie = "constructor";
3220 else if (TYPE_NEEDS_DESTRUCTOR (type))
3221 fie = "destructor";
3530 type = TREE_TYPE (type);
3531
3532 if (TYPE_LANG_SPECIFIC (type) && ! ANON_UNION_P (x)
3533 && ! TYPE_PTRMEMFUNC_P (type))
3534 {
3535 /* Never let anything with uninheritable virtuals
3536 make it through without complaint. */
3537 if (CLASSTYPE_ABSTRACT_VIRTUALS (type))

--- 5 unchanged lines hidden (view full) ---

3543
3544 if (code == UNION_TYPE)
3545 {
3546 char *fie = NULL;
3547 if (TYPE_NEEDS_CONSTRUCTING (type))
3548 fie = "constructor";
3549 else if (TYPE_NEEDS_DESTRUCTOR (type))
3550 fie = "destructor";
3222 else if (TYPE_HAS_REAL_ASSIGNMENT (type))
3223 fie = "assignment operator";
3551 else if (TYPE_HAS_COMPLEX_ASSIGN_REF (type))
3552 fie = "copy assignment operator";
3224 if (fie)
3225 cp_error_at ("member `%#D' with %s not allowed in union", x,
3226 fie);
3227 }
3228 else
3229 {
3230 TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (type);
3231 TYPE_NEEDS_DESTRUCTOR (t) |= TYPE_NEEDS_DESTRUCTOR (type);
3232 TYPE_HAS_COMPLEX_ASSIGN_REF (t) |= TYPE_HAS_COMPLEX_ASSIGN_REF (type);
3233 TYPE_HAS_COMPLEX_INIT_REF (t) |= TYPE_HAS_COMPLEX_INIT_REF (type);
3234 }
3235
3553 if (fie)
3554 cp_error_at ("member `%#D' with %s not allowed in union", x,
3555 fie);
3556 }
3557 else
3558 {
3559 TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (type);
3560 TYPE_NEEDS_DESTRUCTOR (t) |= TYPE_NEEDS_DESTRUCTOR (type);
3561 TYPE_HAS_COMPLEX_ASSIGN_REF (t) |= TYPE_HAS_COMPLEX_ASSIGN_REF (type);
3562 TYPE_HAS_COMPLEX_INIT_REF (t) |= TYPE_HAS_COMPLEX_INIT_REF (type);
3563 }
3564
3236 if (! TYPE_HAS_INIT_REF (type)
3237 || (TYPE_HAS_NONPUBLIC_CTOR (type)
3238 && ! is_friend (t, type)))
3239 cant_synth_copy_ctor = 1;
3240 else if (!TYPE_HAS_CONST_INIT_REF (type))
3565 if (!TYPE_HAS_CONST_INIT_REF (type))
3241 cant_have_const_ctor = 1;
3242
3566 cant_have_const_ctor = 1;
3567
3243 if (! TYPE_HAS_ASSIGN_REF (type)
3244 || (TYPE_HAS_NONPUBLIC_ASSIGN_REF (type)
3245 && ! is_friend (t, type)))
3246 cant_synth_asn_ref = 1;
3247 else if (!TYPE_HAS_CONST_ASSIGN_REF (type))
3568 if (!TYPE_HAS_CONST_ASSIGN_REF (type))
3248 no_const_asn_ref = 1;
3249
3250 if (TYPE_HAS_CONSTRUCTOR (type)
3251 && ! TYPE_HAS_DEFAULT_CONSTRUCTOR (type))
3252 {
3253 cant_have_default_ctor = 1;
3254#if 0
3255 /* This is wrong for aggregates. */

--- 33 unchanged lines hidden (view full) ---

3289
3290 if (! fn_fields)
3291 nonprivate_method = 1;
3292
3293 if (TYPE_NEEDS_DESTRUCTOR (t) && !TYPE_HAS_DESTRUCTOR (t)
3294 && !IS_SIGNATURE (t))
3295 {
3296 /* Here we must cons up a destructor on the fly. */
3569 no_const_asn_ref = 1;
3570
3571 if (TYPE_HAS_CONSTRUCTOR (type)
3572 && ! TYPE_HAS_DEFAULT_CONSTRUCTOR (type))
3573 {
3574 cant_have_default_ctor = 1;
3575#if 0
3576 /* This is wrong for aggregates. */

--- 33 unchanged lines hidden (view full) ---

3610
3611 if (! fn_fields)
3612 nonprivate_method = 1;
3613
3614 if (TYPE_NEEDS_DESTRUCTOR (t) && !TYPE_HAS_DESTRUCTOR (t)
3615 && !IS_SIGNATURE (t))
3616 {
3617 /* Here we must cons up a destructor on the fly. */
3297 tree dtor = cons_up_default_function (t, name, needs_virtual_dtor != 0);
3618 tree dtor = cons_up_default_function (t, name, 0);
3619 check_for_override (dtor, t);
3298
3299 /* If we couldn't make it work, then pretend we didn't need it. */
3300 if (dtor == void_type_node)
3301 TYPE_NEEDS_DESTRUCTOR (t) = 0;
3302 else
3303 {
3620
3621 /* If we couldn't make it work, then pretend we didn't need it. */
3622 if (dtor == void_type_node)
3623 TYPE_NEEDS_DESTRUCTOR (t) = 0;
3624 else
3625 {
3304 /* Link dtor onto end of fn_fields. */
3626 /* Link dtor onto end of fn_fields. */
3305
3306 TREE_CHAIN (dtor) = fn_fields;
3307 fn_fields = dtor;
3308
3627
3628 TREE_CHAIN (dtor) = fn_fields;
3629 fn_fields = dtor;
3630
3309 if (DECL_VINDEX (dtor) == NULL_TREE
3310 && (needs_virtual_dtor
3311 || pending_virtuals != NULL_TREE
3312 || pending_hard_virtuals != NULL_TREE))
3313 DECL_VINDEX (dtor) = error_mark_node;
3314 if (DECL_VINDEX (dtor))
3631 if (DECL_VINDEX (dtor))
3315 pending_virtuals = add_virtual_function (pending_virtuals,
3316 &has_virtual, dtor, t);
3632 add_virtual_function (&pending_virtuals, &pending_hard_virtuals,
3633 &has_virtual, dtor, t);
3317 nonprivate_method = 1;
3318 }
3319 }
3320
3634 nonprivate_method = 1;
3635 }
3636 }
3637
3638 /* Effective C++ rule 11. */
3639 if (has_pointers && warn_ecpp && TYPE_HAS_CONSTRUCTOR (t)
3640 && ! (TYPE_HAS_INIT_REF (t) && TYPE_HAS_ASSIGN_REF (t)))
3641 {
3642 cp_warning ("`%#T' has pointer data members", t);
3643
3644 if (! TYPE_HAS_INIT_REF (t))
3645 {
3646 cp_warning (" but does not override `%T(const %T&)'", t, t);
3647 if (! TYPE_HAS_ASSIGN_REF (t))
3648 cp_warning (" or `operator=(const %T&)'", t);
3649 }
3650 else if (! TYPE_HAS_ASSIGN_REF (t))
3651 cp_warning (" but does not override `operator=(const %T&)'", t);
3652 }
3653
3321 TYPE_NEEDS_DESTRUCTOR (t) |= TYPE_HAS_DESTRUCTOR (t);
3654 TYPE_NEEDS_DESTRUCTOR (t) |= TYPE_HAS_DESTRUCTOR (t);
3322 if (flag_rtti && (max_has_virtual > 0 || needs_virtual_dtor) &&
3323 has_virtual == 0)
3324 has_virtual = 1;
3325
3326 TYPE_HAS_COMPLEX_INIT_REF (t)
3327 |= (TYPE_HAS_INIT_REF (t) || TYPE_USES_VIRTUAL_BASECLASSES (t)
3655
3656 TYPE_HAS_COMPLEX_INIT_REF (t)
3657 |= (TYPE_HAS_INIT_REF (t) || TYPE_USES_VIRTUAL_BASECLASSES (t)
3328 || any_default_members);
3658 || has_virtual || any_default_members);
3329 TYPE_NEEDS_CONSTRUCTING (t)
3330 |= (TYPE_HAS_CONSTRUCTOR (t) || TYPE_USES_VIRTUAL_BASECLASSES (t)
3659 TYPE_NEEDS_CONSTRUCTING (t)
3660 |= (TYPE_HAS_CONSTRUCTOR (t) || TYPE_USES_VIRTUAL_BASECLASSES (t)
3331 || has_virtual || any_default_members || first_vfn_base_index >= 0);
3661 || has_virtual || any_default_members);
3332 if (! IS_SIGNATURE (t))
3333 CLASSTYPE_NON_AGGREGATE (t)
3334 = ! aggregate || has_virtual || TYPE_HAS_CONSTRUCTOR (t);
3335
3336 /* ARM $12.1: A default constructor will be generated for a class X
3337 only if no constructor has been declared for class X. So we
3338 check TYPE_HAS_CONSTRUCTOR also, to make sure we don't generate
3339 one if they declared a constructor in this class. */
3340 if (! TYPE_HAS_CONSTRUCTOR (t) && ! cant_have_default_ctor
3341 && ! IS_SIGNATURE (t))
3342 {
3343 tree default_fn = cons_up_default_function (t, name, 2);
3344 TREE_CHAIN (default_fn) = fn_fields;
3345 fn_fields = default_fn;
3346 }
3347
3348 /* Create default copy constructor, if needed. */
3662 if (! IS_SIGNATURE (t))
3663 CLASSTYPE_NON_AGGREGATE (t)
3664 = ! aggregate || has_virtual || TYPE_HAS_CONSTRUCTOR (t);
3665
3666 /* ARM $12.1: A default constructor will be generated for a class X
3667 only if no constructor has been declared for class X. So we
3668 check TYPE_HAS_CONSTRUCTOR also, to make sure we don't generate
3669 one if they declared a constructor in this class. */
3670 if (! TYPE_HAS_CONSTRUCTOR (t) && ! cant_have_default_ctor
3671 && ! IS_SIGNATURE (t))
3672 {
3673 tree default_fn = cons_up_default_function (t, name, 2);
3674 TREE_CHAIN (default_fn) = fn_fields;
3675 fn_fields = default_fn;
3676 }
3677
3678 /* Create default copy constructor, if needed. */
3349 if (! TYPE_HAS_INIT_REF (t) && ! cant_synth_copy_ctor
3350 && ! IS_SIGNATURE (t))
3679 if (! TYPE_HAS_INIT_REF (t) && ! IS_SIGNATURE (t) && ! TYPE_FOR_JAVA (t))
3351 {
3352 /* ARM 12.18: You get either X(X&) or X(const X&), but
3353 not both. --Chip */
3354 tree default_fn = cons_up_default_function (t, name,
3355 3 + cant_have_const_ctor);
3356 TREE_CHAIN (default_fn) = fn_fields;
3357 fn_fields = default_fn;
3358 }
3359
3360 TYPE_HAS_REAL_ASSIGNMENT (t) |= TYPE_HAS_ASSIGNMENT (t);
3361 TYPE_HAS_REAL_ASSIGN_REF (t) |= TYPE_HAS_ASSIGN_REF (t);
3362 TYPE_HAS_COMPLEX_ASSIGN_REF (t)
3363 |= TYPE_HAS_ASSIGN_REF (t) || TYPE_USES_VIRTUAL_BASECLASSES (t);
3364
3680 {
3681 /* ARM 12.18: You get either X(X&) or X(const X&), but
3682 not both. --Chip */
3683 tree default_fn = cons_up_default_function (t, name,
3684 3 + cant_have_const_ctor);
3685 TREE_CHAIN (default_fn) = fn_fields;
3686 fn_fields = default_fn;
3687 }
3688
3689 TYPE_HAS_REAL_ASSIGNMENT (t) |= TYPE_HAS_ASSIGNMENT (t);
3690 TYPE_HAS_REAL_ASSIGN_REF (t) |= TYPE_HAS_ASSIGN_REF (t);
3691 TYPE_HAS_COMPLEX_ASSIGN_REF (t)
3692 |= TYPE_HAS_ASSIGN_REF (t) || TYPE_USES_VIRTUAL_BASECLASSES (t);
3693
3365 if (! TYPE_HAS_ASSIGN_REF (t) && ! cant_synth_asn_ref
3366 && ! IS_SIGNATURE (t))
3694 if (! TYPE_HAS_ASSIGN_REF (t) && ! IS_SIGNATURE (t) && ! TYPE_FOR_JAVA (t))
3367 {
3368 tree default_fn = cons_up_default_function (t, name,
3369 5 + no_const_asn_ref);
3370 TREE_CHAIN (default_fn) = fn_fields;
3371 fn_fields = default_fn;
3372 }
3373
3374 if (fn_fields)
3375 {
3695 {
3696 tree default_fn = cons_up_default_function (t, name,
3697 5 + no_const_asn_ref);
3698 TREE_CHAIN (default_fn) = fn_fields;
3699 fn_fields = default_fn;
3700 }
3701
3702 if (fn_fields)
3703 {
3704 TYPE_METHODS (t) = fn_fields;
3376 method_vec = finish_struct_methods (t, fn_fields, nonprivate_method);
3377
3378 if (TYPE_HAS_CONSTRUCTOR (t)
3379 && CLASSTYPE_FRIEND_CLASSES (t) == NULL_TREE
3705 method_vec = finish_struct_methods (t, fn_fields, nonprivate_method);
3706
3707 if (TYPE_HAS_CONSTRUCTOR (t)
3708 && CLASSTYPE_FRIEND_CLASSES (t) == NULL_TREE
3380 && DECL_FRIENDLIST (TYPE_NAME (t)) == NULL_TREE)
3709 && DECL_FRIENDLIST (TYPE_MAIN_DECL (t)) == NULL_TREE)
3381 {
3382 int nonprivate_ctor = 0;
3383 tree ctor;
3384
3385 for (ctor = TREE_VEC_ELT (method_vec, 0);
3386 ctor;
3710 {
3711 int nonprivate_ctor = 0;
3712 tree ctor;
3713
3714 for (ctor = TREE_VEC_ELT (method_vec, 0);
3715 ctor;
3387 ctor = DECL_CHAIN (ctor))
3388 if (! TREE_PRIVATE (ctor))
3716 ctor = OVL_NEXT (ctor))
3717 if (! TREE_PRIVATE (OVL_CURRENT (ctor)))
3389 {
3390 nonprivate_ctor = 1;
3391 break;
3392 }
3393
3394 if (nonprivate_ctor == 0 && warn_ctor_dtor_privacy)
3395 cp_warning ("`%#T' only defines private constructors and has no friends",
3396 t);

--- 4 unchanged lines hidden (view full) ---

3401 method_vec = 0;
3402
3403 /* Just in case these got accidentally
3404 filled in by syntax errors. */
3405 TYPE_HAS_CONSTRUCTOR (t) = 0;
3406 TYPE_HAS_DESTRUCTOR (t) = 0;
3407 }
3408
3718 {
3719 nonprivate_ctor = 1;
3720 break;
3721 }
3722
3723 if (nonprivate_ctor == 0 && warn_ctor_dtor_privacy)
3724 cp_warning ("`%#T' only defines private constructors and has no friends",
3725 t);

--- 4 unchanged lines hidden (view full) ---

3730 method_vec = 0;
3731
3732 /* Just in case these got accidentally
3733 filled in by syntax errors. */
3734 TYPE_HAS_CONSTRUCTOR (t) = 0;
3735 TYPE_HAS_DESTRUCTOR (t) = 0;
3736 }
3737
3409 {
3410 int n_methods = method_vec ? TREE_VEC_LENGTH (method_vec) : 0;
3411
3412 for (access_decls = nreverse (access_decls); access_decls;
3413 access_decls = TREE_CHAIN (access_decls))
3414 {
3415 tree fdecl = TREE_VALUE (access_decls);
3416 tree flist = NULL_TREE;
3417 tree name;
3418 enum access_type access = (enum access_type)TREE_PURPOSE(access_decls);
3419 int i = TREE_VEC_ELT (method_vec, 0) ? 0 : 1;
3420 tree tmp;
3738 for (access_decls = nreverse (access_decls); access_decls;
3739 access_decls = TREE_CHAIN (access_decls))
3740 handle_using_decl (TREE_VALUE (access_decls), t, method_vec, fields);
3421
3741
3422 if (TREE_CODE (fdecl) == TREE_LIST)
3423 {
3424 flist = fdecl;
3425 fdecl = TREE_VALUE (flist);
3426 }
3427
3428 name = DECL_NAME (fdecl);
3429
3430 for (; i < n_methods; i++)
3431 if (DECL_NAME (TREE_VEC_ELT (method_vec, i)) == name)
3432 {
3433 cp_error ("cannot adjust access to `%#D' in `%#T'", fdecl, t);
3434 cp_error_at (" because of local method `%#D' with same name",
3435 TREE_VEC_ELT (method_vec, i));
3436 fdecl = NULL_TREE;
3437 break;
3438 }
3439
3440 if (! fdecl)
3441 continue;
3442
3443 for (tmp = fields; tmp; tmp = TREE_CHAIN (tmp))
3444 if (DECL_NAME (tmp) == name)
3445 {
3446 cp_error ("cannot adjust access to `%#D' in `%#T'", fdecl, t);
3447 cp_error_at (" because of local field `%#D' with same name", tmp);
3448 fdecl = NULL_TREE;
3449 break;
3450 }
3451
3452 if (!fdecl)
3453 continue;
3454
3455 /* Make type T see field decl FDECL with access ACCESS.*/
3456 if (flist)
3457 {
3458 fdecl = TREE_VALUE (flist);
3459 while (fdecl)
3460 {
3461 if (alter_access (t, fdecl, access) == 0)
3462 break;
3463 fdecl = DECL_CHAIN (fdecl);
3464 }
3465 }
3466 else
3467 alter_access (t, fdecl, access);
3468 }
3469
3470 }
3471
3472 if (vfield == NULL_TREE && has_virtual)
3473 {
3474 /* We build this decl with ptr_type_node, and
3475 change the type when we know what it should be. */
3476 vfield = build_lang_field_decl (FIELD_DECL, get_vfield_name (t),
3477 ptr_type_node);
3478 /* If you change any of the below, take a look at all the
3479 other VFIELD_BASEs and VTABLE_BASEs in the code, and change
3742 if (vfield == NULL_TREE && has_virtual)
3743 {
3744 /* We build this decl with ptr_type_node, and
3745 change the type when we know what it should be. */
3746 vfield = build_lang_field_decl (FIELD_DECL, get_vfield_name (t),
3747 ptr_type_node);
3748 /* If you change any of the below, take a look at all the
3749 other VFIELD_BASEs and VTABLE_BASEs in the code, and change
3480 them too. */
3750 them too. */
3481 DECL_ASSEMBLER_NAME (vfield) = get_identifier (VFIELD_BASE);
3482 CLASSTYPE_VFIELD (t) = vfield;
3483 DECL_VIRTUAL_P (vfield) = 1;
3751 DECL_ASSEMBLER_NAME (vfield) = get_identifier (VFIELD_BASE);
3752 CLASSTYPE_VFIELD (t) = vfield;
3753 DECL_VIRTUAL_P (vfield) = 1;
3754 DECL_ARTIFICIAL (vfield) = 1;
3484 DECL_FIELD_CONTEXT (vfield) = t;
3485 DECL_CLASS_CONTEXT (vfield) = t;
3486 DECL_FCONTEXT (vfield) = t;
3487 DECL_SAVED_INSNS (vfield) = NULL_RTX;
3488 DECL_FIELD_SIZE (vfield) = 0;
3489 DECL_ALIGN (vfield) = TYPE_ALIGN (ptr_type_node);
3755 DECL_FIELD_CONTEXT (vfield) = t;
3756 DECL_CLASS_CONTEXT (vfield) = t;
3757 DECL_FCONTEXT (vfield) = t;
3758 DECL_SAVED_INSNS (vfield) = NULL_RTX;
3759 DECL_FIELD_SIZE (vfield) = 0;
3760 DECL_ALIGN (vfield) = TYPE_ALIGN (ptr_type_node);
3490 if (CLASSTYPE_RTTI (t))
3761#if 0
3762 /* This is more efficient, but breaks binary compatibility, turn
3763 it on sometime when we don't care. If we turn it on, we also
3764 have to enable the code in dfs_init_vbase_pointers. */
3765 /* vfield is always first entry in structure. */
3766 TREE_CHAIN (vfield) = fields;
3767 fields = vfield;
3768#else
3769 if (last_x)
3491 {
3770 {
3492 /* vfield is always first entry in structure. */
3493 TREE_CHAIN (vfield) = fields;
3494 fields = vfield;
3495 }
3496 else if (last_x)
3497 {
3498 my_friendly_assert (TREE_CHAIN (last_x) == NULL_TREE, 175);
3499 TREE_CHAIN (last_x) = vfield;
3500 last_x = vfield;
3501 }
3502 else
3503 fields = vfield;
3771 my_friendly_assert (TREE_CHAIN (last_x) == NULL_TREE, 175);
3772 TREE_CHAIN (last_x) = vfield;
3773 last_x = vfield;
3774 }
3775 else
3776 fields = vfield;
3777#endif
3778 empty = 0;
3504 vfields = chainon (vfields, CLASSTYPE_AS_LIST (t));
3505 }
3506
3507 /* Now DECL_INITIAL is null on all members except for zero-width bit-fields.
3508 And they have already done their work.
3509
3510 C++: maybe we will support default field initialization some day... */
3511

--- 17 unchanged lines hidden (view full) ---

3529 signature, since it can only contain the fields constructed in
3530 append_signature_fields. */
3531 if (! IS_SIGNATURE (t))
3532 {
3533 int n_methods = method_vec ? TREE_VEC_LENGTH (method_vec) : 0;
3534 for (x = fields; x; x = TREE_CHAIN (x))
3535 {
3536 tree name = DECL_NAME (x);
3779 vfields = chainon (vfields, CLASSTYPE_AS_LIST (t));
3780 }
3781
3782 /* Now DECL_INITIAL is null on all members except for zero-width bit-fields.
3783 And they have already done their work.
3784
3785 C++: maybe we will support default field initialization some day... */
3786

--- 17 unchanged lines hidden (view full) ---

3804 signature, since it can only contain the fields constructed in
3805 append_signature_fields. */
3806 if (! IS_SIGNATURE (t))
3807 {
3808 int n_methods = method_vec ? TREE_VEC_LENGTH (method_vec) : 0;
3809 for (x = fields; x; x = TREE_CHAIN (x))
3810 {
3811 tree name = DECL_NAME (x);
3537 int i = /*TREE_VEC_ELT (method_vec, 0) ? 0 : */ 1;
3812 int i = 2;
3813
3814 if (TREE_CODE (x) == TYPE_DECL && DECL_ARTIFICIAL (x))
3815 continue;
3816
3538 for (; i < n_methods; ++i)
3817 for (; i < n_methods; ++i)
3539 if (DECL_NAME (TREE_VEC_ELT (method_vec, i)) == name)
3818 if (DECL_NAME (OVL_CURRENT (TREE_VEC_ELT (method_vec, i)))
3819 == name)
3540 {
3541 cp_error_at ("data member `%#D' conflicts with", x);
3542 cp_error_at ("function member `%#D'",
3820 {
3821 cp_error_at ("data member `%#D' conflicts with", x);
3822 cp_error_at ("function member `%#D'",
3543 TREE_VEC_ELT (method_vec, i));
3823 OVL_CURRENT (TREE_VEC_ELT (method_vec, i)));
3544 break;
3545 }
3546 }
3547 }
3548
3549 /* Now we have the final fieldlist for the data fields. Record it,
3550 then lay out the structure or union (including the fields). */
3551
3552 TYPE_FIELDS (t) = fields;
3553
3824 break;
3825 }
3826 }
3827 }
3828
3829 /* Now we have the final fieldlist for the data fields. Record it,
3830 then lay out the structure or union (including the fields). */
3831
3832 TYPE_FIELDS (t) = fields;
3833
3554 /* If there's a :0 field at the end, round the size to the
3555 EMPTY_FIELD_BOUNDARY. */
3556 TYPE_ALIGN (t) = round_up_size;
3557
3558 /* Pass layout information about base classes to layout_type, if any. */
3559 if (n_baseclasses)
3560 {
3834 if (n_baseclasses)
3835 {
3561 tree pseudo_basetype = TREE_TYPE (base_layout_decl);
3836 last_x = build_base_fields (t);
3562
3837
3563 TREE_CHAIN (base_layout_decl) = TYPE_FIELDS (t);
3564 TYPE_FIELDS (t) = base_layout_decl;
3565
3566 TYPE_SIZE (pseudo_basetype) = CLASSTYPE_SIZE (t);
3567 TYPE_MODE (pseudo_basetype) = TYPE_MODE (t);
3568 TYPE_ALIGN (pseudo_basetype) = CLASSTYPE_ALIGN (t);
3569 DECL_ALIGN (base_layout_decl) = TYPE_ALIGN (pseudo_basetype);
3570 /* Don't re-use old size. */
3571 DECL_SIZE (base_layout_decl) = NULL_TREE;
3838 /* If all our bases are empty, we can be empty too. */
3839 for (x = last_x; empty && x; x = TREE_CHAIN (x))
3840 if (DECL_SIZE (x) != integer_zero_node)
3841 empty = 0;
3572 }
3842 }
3843 if (empty)
3844 {
3845 /* C++: do not let empty structures exist. */
3846 tree decl = build_lang_field_decl
3847 (FIELD_DECL, NULL_TREE, char_type_node);
3848 TREE_CHAIN (decl) = fields;
3849 TYPE_FIELDS (t) = decl;
3850 }
3851 if (n_baseclasses)
3852 TYPE_FIELDS (t) = chainon (last_x, TYPE_FIELDS (t));
3573
3574 layout_type (t);
3575
3853
3854 layout_type (t);
3855
3576 {
3577 tree field;
3578 for (field = TYPE_FIELDS (t); field; field = TREE_CHAIN (field))
3579 {
3580 if (TREE_STATIC (field))
3581 continue;
3582 if (TREE_CODE (field) != FIELD_DECL)
3583 continue;
3856 /* Remember the size and alignment of the class before adding
3857 the virtual bases. */
3858 if (empty && flag_new_abi)
3859 CLASSTYPE_SIZE (t) = integer_zero_node;
3860 else if (flag_new_abi && TYPE_HAS_COMPLEX_INIT_REF (t)
3861 && TYPE_HAS_COMPLEX_ASSIGN_REF (t))
3862 CLASSTYPE_SIZE (t) = TYPE_BINFO_SIZE (t);
3863 else
3864 CLASSTYPE_SIZE (t) = TYPE_SIZE (t);
3865 CLASSTYPE_ALIGN (t) = TYPE_ALIGN (t);
3584
3866
3585 /* If this field is an anonymous union,
3586 give each union-member the same position as the union has.
3867 finish_struct_anon (t);
3587
3868
3588 ??? This is a real kludge because it makes the structure
3589 of the types look strange. This feature is only used by
3590 C++, which should have build_component_ref build two
3591 COMPONENT_REF operations, one for the union and one for
3592 the inner field. We set the offset of this field to zero
3593 so that either the old or the correct method will work.
3594 Setting DECL_FIELD_CONTEXT is wrong unless the inner fields are
3595 moved into the type of this field, but nothing seems to break
3596 by doing this. */
3597
3598 if (DECL_NAME (field) == NULL_TREE
3599 && TREE_CODE (TREE_TYPE (field)) == UNION_TYPE)
3600 {
3601 tree uelt = TYPE_FIELDS (TREE_TYPE (field));
3602 for (; uelt; uelt = TREE_CHAIN (uelt))
3603 {
3604 if (TREE_CODE (uelt) != FIELD_DECL)
3605 continue;
3606
3607 if (TREE_PRIVATE (uelt))
3608 cp_pedwarn_at ("private member `%#D' in anonymous union",
3609 uelt);
3610 else if (TREE_PROTECTED (uelt))
3611 cp_pedwarn_at ("protected member `%#D' in anonymous union",
3612 uelt);
3613
3614 DECL_FIELD_CONTEXT (uelt) = DECL_FIELD_CONTEXT (field);
3615 DECL_FIELD_BITPOS (uelt) = DECL_FIELD_BITPOS (field);
3616 }
3617
3618 DECL_FIELD_BITPOS (field) = integer_zero_node;
3619 }
3620 }
3621 }
3622
3623 if (n_baseclasses)
3624 TYPE_FIELDS (t) = TREE_CHAIN (TYPE_FIELDS (t));
3625
3626 /* C++: do not let empty structures exist. */
3627 if (integer_zerop (TYPE_SIZE (t)))
3628 TYPE_SIZE (t) = TYPE_SIZE (char_type_node);
3629
3630 /* Set the TYPE_DECL for this type to contain the right
3631 value for DECL_OFFSET, so that we can use it as part
3632 of a COMPONENT_REF for multiple inheritance. */
3633
3869 /* Set the TYPE_DECL for this type to contain the right
3870 value for DECL_OFFSET, so that we can use it as part
3871 of a COMPONENT_REF for multiple inheritance. */
3872
3634 if (TREE_CODE (TYPE_NAME (t)) == TYPE_DECL)
3635 layout_decl (TYPE_NAME (t), 0);
3873 layout_decl (TYPE_MAIN_DECL (t), 0);
3636
3637 /* Now fix up any virtual base class types that we left lying
3638 around. We must get these done before we try to lay out the
3639 virtual function table. */
3874
3875 /* Now fix up any virtual base class types that we left lying
3876 around. We must get these done before we try to lay out the
3877 virtual function table. */
3640 doing_hard_virtuals = 1;
3641 pending_hard_virtuals = nreverse (pending_hard_virtuals);
3642
3878 pending_hard_virtuals = nreverse (pending_hard_virtuals);
3879
3880 if (n_baseclasses)
3881 /* layout_basetypes will remove the base subobject fields. */
3882 max_has_virtual = layout_basetypes (t, max_has_virtual);
3883 else if (empty)
3884 TYPE_FIELDS (t) = fields;
3885
3643 if (TYPE_USES_VIRTUAL_BASECLASSES (t))
3644 {
3645 tree vbases;
3646
3886 if (TYPE_USES_VIRTUAL_BASECLASSES (t))
3887 {
3888 tree vbases;
3889
3647 max_has_virtual = layout_vbasetypes (t, max_has_virtual);
3648 vbases = CLASSTYPE_VBASECLASSES (t);
3649 CLASSTYPE_N_VBASECLASSES (t) = list_length (vbases);
3650
3890 vbases = CLASSTYPE_VBASECLASSES (t);
3891 CLASSTYPE_N_VBASECLASSES (t) = list_length (vbases);
3892
3651 /* The rtti code should do this. (mrs) */
3652#if 0
3653 while (vbases)
3654 {
3655 /* Update rtti info with offsets for virtual baseclasses. */
3656 if (flag_rtti && ! BINFO_NEW_VTABLE_MARKED (vbases))
3657 prepare_fresh_vtable (vbases, t);
3658 vbases = TREE_CHAIN (vbases);
3659 }
3660#endif
3661
3662 {
3663 /* Now fixup overrides of all functions in vtables from all
3664 direct or indirect virtual base classes. */
3665 tree binfos = BINFO_BASETYPES (TYPE_BINFO (t));
3666 int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
3667
3668 for (i = 0; i < n_baseclasses; i++)
3669 {

--- 6 unchanged lines hidden (view full) ---

3676 {
3677 merge_overrides (binfo_member (BINFO_TYPE (vbases),
3678 CLASSTYPE_VBASECLASSES (t)),
3679 vbases, 1, t);
3680 vbases = TREE_CHAIN (vbases);
3681 }
3682 }
3683 }
3893 {
3894 /* Now fixup overrides of all functions in vtables from all
3895 direct or indirect virtual base classes. */
3896 tree binfos = BINFO_BASETYPES (TYPE_BINFO (t));
3897 int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
3898
3899 for (i = 0; i < n_baseclasses; i++)
3900 {

--- 6 unchanged lines hidden (view full) ---

3907 {
3908 merge_overrides (binfo_member (BINFO_TYPE (vbases),
3909 CLASSTYPE_VBASECLASSES (t)),
3910 vbases, 1, t);
3911 vbases = TREE_CHAIN (vbases);
3912 }
3913 }
3914 }
3684
3685 /* Now fixup any virtual function entries from virtual bases
3686 that have different deltas. */
3687 vbases = CLASSTYPE_VBASECLASSES (t);
3688 while (vbases)
3689 {
3690 /* We might be able to shorten the amount of work we do by
3691 only doing this for vtables that come from virtual bases
3692 that have differing offsets, but don't want to miss any
3693 entries. */
3694 fixup_vtable_deltas (vbases, 1, t);
3695 vbases = TREE_CHAIN (vbases);
3696 }
3697 }
3698
3699 /* Set up the DECL_FIELD_BITPOS of the vfield if we need to, as we
3700 might need to know it for setting up the offsets in the vtable
3701 (or in thunks) below. */
3702 if (vfield != NULL_TREE
3703 && DECL_FIELD_CONTEXT (vfield) != t)
3704 {

--- 26 unchanged lines hidden (view full) ---

3731
3732 while (pending_hard_virtuals)
3733 {
3734 modify_all_vtables (t,
3735 TREE_PURPOSE (pending_hard_virtuals),
3736 TREE_VALUE (pending_hard_virtuals));
3737 pending_hard_virtuals = TREE_CHAIN (pending_hard_virtuals);
3738 }
3915 }
3916
3917 /* Set up the DECL_FIELD_BITPOS of the vfield if we need to, as we
3918 might need to know it for setting up the offsets in the vtable
3919 (or in thunks) below. */
3920 if (vfield != NULL_TREE
3921 && DECL_FIELD_CONTEXT (vfield) != t)
3922 {

--- 26 unchanged lines hidden (view full) ---

3949
3950 while (pending_hard_virtuals)
3951 {
3952 modify_all_vtables (t,
3953 TREE_PURPOSE (pending_hard_virtuals),
3954 TREE_VALUE (pending_hard_virtuals));
3955 pending_hard_virtuals = TREE_CHAIN (pending_hard_virtuals);
3956 }
3739 doing_hard_virtuals = 0;
3957
3958 if (TYPE_USES_VIRTUAL_BASECLASSES (t))
3959 {
3960 tree vbases;
3961 /* Now fixup any virtual function entries from virtual bases
3962 that have different deltas. This has to come after we do the
3963 pending hard virtuals, as we might have a function that comes
3964 from multiple virtual base instances that is only overridden
3965 by a hard virtual above. */
3966 vbases = CLASSTYPE_VBASECLASSES (t);
3967 while (vbases)
3968 {
3969 /* We might be able to shorten the amount of work we do by
3970 only doing this for vtables that come from virtual bases
3971 that have differing offsets, but don't want to miss any
3972 entries. */
3973 fixup_vtable_deltas (vbases, 1, t);
3974 vbases = TREE_CHAIN (vbases);
3975 }
3976 }
3740
3741 /* Under our model of GC, every C++ class gets its own virtual
3742 function table, at least virtually. */
3977
3978 /* Under our model of GC, every C++ class gets its own virtual
3979 function table, at least virtually. */
3743 if (pending_virtuals || (flag_rtti && TYPE_VIRTUAL_P (t)))
3980 if (pending_virtuals)
3744 {
3745 pending_virtuals = nreverse (pending_virtuals);
3746 /* We must enter these virtuals into the table. */
3747 if (first_vfn_base_index < 0)
3748 {
3981 {
3982 pending_virtuals = nreverse (pending_virtuals);
3983 /* We must enter these virtuals into the table. */
3984 if (first_vfn_base_index < 0)
3985 {
3749 /* The first slot is for the rtti offset. */
3750 pending_virtuals = tree_cons (NULL_TREE, NULL_TREE, pending_virtuals);
3751
3752 /* The second slot is for the tdesc pointer when thunks are used. */
3753 if (flag_vtable_thunks)
3754 pending_virtuals = tree_cons (NULL_TREE, NULL_TREE, pending_virtuals);
3755
3986 /* The second slot is for the tdesc pointer when thunks are used. */
3987 if (flag_vtable_thunks)
3988 pending_virtuals = tree_cons (NULL_TREE, NULL_TREE, pending_virtuals);
3989
3756 set_rtti_entry (pending_virtuals, integer_zero_node, t);
3990 /* The first slot is for the rtti offset. */
3991 pending_virtuals = tree_cons (NULL_TREE, NULL_TREE, pending_virtuals);
3992
3993 set_rtti_entry (pending_virtuals,
3994 convert (ssizetype, integer_zero_node), t);
3757 build_vtable (NULL_TREE, t);
3758 }
3759 else
3760 {
3995 build_vtable (NULL_TREE, t);
3996 }
3997 else
3998 {
3761 tree offset;
3762 /* Here we know enough to change the type of our virtual
3763 function table, but we will wait until later this function. */
3764
3765 if (! BINFO_NEW_VTABLE_MARKED (TYPE_BINFO (t)))
3766 build_vtable (TREE_VEC_ELT (TYPE_BINFO_BASETYPES (t), first_vfn_base_index), t);
3999 /* Here we know enough to change the type of our virtual
4000 function table, but we will wait until later this function. */
4001
4002 if (! BINFO_NEW_VTABLE_MARKED (TYPE_BINFO (t)))
4003 build_vtable (TREE_VEC_ELT (TYPE_BINFO_BASETYPES (t), first_vfn_base_index), t);
3767
3768 offset = get_derived_offset (TYPE_BINFO (t), NULL_TREE);
3769 offset = size_binop (MINUS_EXPR, integer_zero_node, offset);
3770 set_rtti_entry (TYPE_BINFO_VIRTUALS (t), offset, t);
3771 }
3772
3773 /* If this type has basetypes with constructors, then those
3774 constructors might clobber the virtual function table. But
3775 they don't if the derived class shares the exact vtable of the base
3776 class. */
3777
3778 CLASSTYPE_NEEDS_VIRTUAL_REINIT (t) = 1;

--- 93 unchanged lines hidden (view full) ---

3872 if (TREE_CODE (x) == VAR_DECL && TREE_STATIC (x)
3873 && TREE_TYPE (x) == t)
3874 {
3875 DECL_MODE (x) = TYPE_MODE (t);
3876 make_decl_rtl (x, NULL, 0);
3877 }
3878 }
3879
4004 }
4005
4006 /* If this type has basetypes with constructors, then those
4007 constructors might clobber the virtual function table. But
4008 they don't if the derived class shares the exact vtable of the base
4009 class. */
4010
4011 CLASSTYPE_NEEDS_VIRTUAL_REINIT (t) = 1;

--- 93 unchanged lines hidden (view full) ---

4105 if (TREE_CODE (x) == VAR_DECL && TREE_STATIC (x)
4106 && TREE_TYPE (x) == t)
4107 {
4108 DECL_MODE (x) = TYPE_MODE (t);
4109 make_decl_rtl (x, NULL, 0);
4110 }
4111 }
4112
3880 /* Now add the tags, if any, to the list of TYPE_DECLs
3881 defined for this type. */
3882 if (CLASSTYPE_TAGS (t))
3883 {
3884 x = CLASSTYPE_TAGS (t);
3885 last_x = tree_last (TYPE_FIELDS (t));
3886 while (x)
3887 {
3888 tree tag = TYPE_NAME (TREE_VALUE (x));
3889
3890 /* Check to see if it is already there. This will be the case if
3891 was do enum { red; } color; */
3892 if (chain_member (tag, TYPE_FIELDS (t)))
3893 {
3894 x = TREE_CHAIN (x);
3895 continue;
3896 }
3897
3898#ifdef DWARF_DEBUGGING_INFO
3899 if (write_symbols == DWARF_DEBUG)
3900 {
3901 /* Notify dwarfout.c that this TYPE_DECL node represent a
3902 gratuitous typedef. */
3903 DECL_IGNORED_P (tag) = 1;
3904 }
3905#endif /* DWARF_DEBUGGING_INFO */
3906
3907 TREE_NONLOCAL_FLAG (TREE_VALUE (x)) = 0;
3908 x = TREE_CHAIN (x);
3909 last_x = chainon (last_x, tag);
3910 }
3911 if (TYPE_FIELDS (t) == NULL_TREE)
3912 TYPE_FIELDS (t) = last_x;
3913 CLASSTYPE_LOCAL_TYPEDECLS (t) = 1;
3914 }
3915
3916 if (TYPE_HAS_CONSTRUCTOR (t))
3917 {
3918 tree vfields = CLASSTYPE_VFIELDS (t);
3919
3920 while (vfields)
3921 {
3922 /* Mark the fact that constructor for T
3923 could affect anybody inheriting from T
3924 who wants to initialize vtables for VFIELDS's type. */
3925 if (VF_DERIVED_VALUE (vfields))
3926 TREE_ADDRESSABLE (vfields) = 1;
3927 vfields = TREE_CHAIN (vfields);
3928 }
3929 if (any_default_members != 0)
3930 build_class_init_list (t);
3931 }
3932 else if (TYPE_NEEDS_CONSTRUCTING (t))
3933 build_class_init_list (t);
3934
4113 if (TYPE_HAS_CONSTRUCTOR (t))
4114 {
4115 tree vfields = CLASSTYPE_VFIELDS (t);
4116
4117 while (vfields)
4118 {
4119 /* Mark the fact that constructor for T
4120 could affect anybody inheriting from T
4121 who wants to initialize vtables for VFIELDS's type. */
4122 if (VF_DERIVED_VALUE (vfields))
4123 TREE_ADDRESSABLE (vfields) = 1;
4124 vfields = TREE_CHAIN (vfields);
4125 }
4126 if (any_default_members != 0)
4127 build_class_init_list (t);
4128 }
4129 else if (TYPE_NEEDS_CONSTRUCTING (t))
4130 build_class_init_list (t);
4131
3935 if (! IS_SIGNATURE (t))
3936 embrace_waiting_friends (t);
3937
3938 /* Write out inline function definitions. */
3939 do_inline_function_hair (t, CLASSTYPE_INLINE_FRIENDS (t));
3940 CLASSTYPE_INLINE_FRIENDS (t) = 0;
3941
3942 if (CLASSTYPE_VSIZE (t) != 0)
3943 {
3944#if 0
4132 /* Write out inline function definitions. */
4133 do_inline_function_hair (t, CLASSTYPE_INLINE_FRIENDS (t));
4134 CLASSTYPE_INLINE_FRIENDS (t) = 0;
4135
4136 if (CLASSTYPE_VSIZE (t) != 0)
4137 {
4138#if 0
3945 /* This is now done above. */
4139 /* This is now done above. */
3946 if (DECL_FIELD_CONTEXT (vfield) != t)
3947 {
3948 tree binfo = get_binfo (DECL_FIELD_CONTEXT (vfield), t, 0);
3949 tree offset = BINFO_OFFSET (binfo);
3950
3951 vfield = copy_node (vfield);
3952 copy_lang_decl (vfield);
3953
3954 if (! integer_zerop (offset))
3955 offset = size_binop (MULT_EXPR, offset, size_int (BITS_PER_UNIT));
3956 DECL_FIELD_CONTEXT (vfield) = t;
3957 DECL_CLASS_CONTEXT (vfield) = t;
3958 DECL_FIELD_BITPOS (vfield)
3959 = size_binop (PLUS_EXPR, offset, DECL_FIELD_BITPOS (vfield));
3960 CLASSTYPE_VFIELD (t) = vfield;
3961 }
3962#endif
3963
4140 if (DECL_FIELD_CONTEXT (vfield) != t)
4141 {
4142 tree binfo = get_binfo (DECL_FIELD_CONTEXT (vfield), t, 0);
4143 tree offset = BINFO_OFFSET (binfo);
4144
4145 vfield = copy_node (vfield);
4146 copy_lang_decl (vfield);
4147
4148 if (! integer_zerop (offset))
4149 offset = size_binop (MULT_EXPR, offset, size_int (BITS_PER_UNIT));
4150 DECL_FIELD_CONTEXT (vfield) = t;
4151 DECL_CLASS_CONTEXT (vfield) = t;
4152 DECL_FIELD_BITPOS (vfield)
4153 = size_binop (PLUS_EXPR, offset, DECL_FIELD_BITPOS (vfield));
4154 CLASSTYPE_VFIELD (t) = vfield;
4155 }
4156#endif
4157
3964 /* In addition to this one, all the other vfields should be listed. */
4158 /* In addition to this one, all the other vfields should be listed. */
3965 /* Before that can be done, we have to have FIELD_DECLs for them, and
3966 a place to find them. */
3967 TYPE_NONCOPIED_PARTS (t) = build_tree_list (default_conversion (TYPE_BINFO_VTABLE (t)), vfield);
3968
3969 if (warn_nonvdtor && TYPE_HAS_DESTRUCTOR (t)
4159 /* Before that can be done, we have to have FIELD_DECLs for them, and
4160 a place to find them. */
4161 TYPE_NONCOPIED_PARTS (t) = build_tree_list (default_conversion (TYPE_BINFO_VTABLE (t)), vfield);
4162
4163 if (warn_nonvdtor && TYPE_HAS_DESTRUCTOR (t)
3970 && DECL_VINDEX (TREE_VEC_ELT (method_vec, 0)) == NULL_TREE)
4164 && DECL_VINDEX (TREE_VEC_ELT (method_vec, 1)) == NULL_TREE)
3971 cp_warning ("`%#T' has virtual functions but non-virtual destructor",
3972 t);
3973 }
3974
3975 /* Make the rtl for any new vtables we have created, and unmark
3976 the base types we marked. */
3977 finish_vtbls (TYPE_BINFO (t), 1, t);
4165 cp_warning ("`%#T' has virtual functions but non-virtual destructor",
4166 t);
4167 }
4168
4169 /* Make the rtl for any new vtables we have created, and unmark
4170 the base types we marked. */
4171 finish_vtbls (TYPE_BINFO (t), 1, t);
3978 TYPE_BEING_DEFINED (t) = 0;
3979 hack_incomplete_structures (t);
3980
3981#if 0
3982 if (TYPE_NAME (t) && TYPE_IDENTIFIER (t))
3983 undo_template_name_overload (TYPE_IDENTIFIER (t), 1);
3984#endif
4172 hack_incomplete_structures (t);
4173
4174#if 0
4175 if (TYPE_NAME (t) && TYPE_IDENTIFIER (t))
4176 undo_template_name_overload (TYPE_IDENTIFIER (t), 1);
4177#endif
3985 if (current_class_type)
3986 popclass (0);
3987 else
3988 error ("trying to finish struct, but kicked out due to previous parse errors.");
3989
3990 resume_momentary (old);
3991
4178
4179 resume_momentary (old);
4180
3992 if (flag_cadillac)
3993 cadillac_finish_struct (t);
4181 if (warn_overloaded_virtual)
4182 warn_hidden (t);
3994
3995#if 0
3996 /* This has to be done after we have sorted out what to do with
3997 the enclosing type. */
3998 if (write_symbols != DWARF_DEBUG)
3999 {
4000 /* Be smarter about nested classes here. If a type is nested,
4001 only output it if we would output the enclosing type. */
4183
4184#if 0
4185 /* This has to be done after we have sorted out what to do with
4186 the enclosing type. */
4187 if (write_symbols != DWARF_DEBUG)
4188 {
4189 /* Be smarter about nested classes here. If a type is nested,
4190 only output it if we would output the enclosing type. */
4002 if (DECL_CONTEXT (TYPE_NAME (t))
4003 && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (TYPE_NAME (t)))) == 't')
4004 DECL_IGNORED_P (TYPE_NAME (t)) = TREE_ASM_WRITTEN (TYPE_NAME (t));
4191 if (DECL_CLASS_SCOPE_P (TYPE_MAIN_DECL (t)))
4192 DECL_IGNORED_P (TYPE_MAIN_DECL (t)) = TREE_ASM_WRITTEN (TYPE_MAIN_DECL (t));
4005 }
4006#endif
4007
4193 }
4194#endif
4195
4008 if (write_symbols != DWARF_DEBUG)
4196 if (write_symbols != DWARF_DEBUG && write_symbols != DWARF2_DEBUG)
4009 {
4010 /* If the type has methods, we want to think about cutting down
4011 the amount of symbol table stuff we output. The value stored in
4012 the TYPE_DECL's DECL_IGNORED_P slot is a first approximation.
4013 For example, if a member function is seen and we decide to
4014 write out that member function, then we can change the value
4015 of the DECL_IGNORED_P slot, and the type will be output when
4197 {
4198 /* If the type has methods, we want to think about cutting down
4199 the amount of symbol table stuff we output. The value stored in
4200 the TYPE_DECL's DECL_IGNORED_P slot is a first approximation.
4201 For example, if a member function is seen and we decide to
4202 write out that member function, then we can change the value
4203 of the DECL_IGNORED_P slot, and the type will be output when
4016 that member function's debug info is written out. */
4204 that member function's debug info is written out.
4205
4206 We can't do this with DWARF, which does not support name
4207 references between translation units. */
4017 if (CLASSTYPE_METHOD_VEC (t))
4018 {
4019 extern tree pending_vtables;
4020
4021 /* Don't output full info about any type
4022 which does not have its implementation defined here. */
4023 if (TYPE_VIRTUAL_P (t) && write_virtuals == 2)
4208 if (CLASSTYPE_METHOD_VEC (t))
4209 {
4210 extern tree pending_vtables;
4211
4212 /* Don't output full info about any type
4213 which does not have its implementation defined here. */
4214 if (TYPE_VIRTUAL_P (t) && write_virtuals == 2)
4024 TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (t))
4215 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t))
4025 = (value_member (TYPE_IDENTIFIER (t), pending_vtables) == 0);
4026 else if (CLASSTYPE_INTERFACE_ONLY (t))
4216 = (value_member (TYPE_IDENTIFIER (t), pending_vtables) == 0);
4217 else if (CLASSTYPE_INTERFACE_ONLY (t))
4027 TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (t)) = 1;
4218 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t)) = 1;
4219#if 0
4220 /* XXX do something about this. */
4028 else if (CLASSTYPE_INTERFACE_UNKNOWN (t))
4029 /* Only a first approximation! */
4221 else if (CLASSTYPE_INTERFACE_UNKNOWN (t))
4222 /* Only a first approximation! */
4030 TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (t)) = 1;
4223 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t)) = 1;
4224#endif
4031 }
4032 else if (CLASSTYPE_INTERFACE_ONLY (t))
4225 }
4226 else if (CLASSTYPE_INTERFACE_ONLY (t))
4033 TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (t)) = 1;
4227 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t)) = 1;
4034 }
4035
4036 /* Finish debugging output for this type. */
4037 rest_of_type_compilation (t, toplevel_bindings_p ());
4038
4039 return t;
4040}
4041
4042tree
4228 }
4229
4230 /* Finish debugging output for this type. */
4231 rest_of_type_compilation (t, toplevel_bindings_p ());
4232
4233 return t;
4234}
4235
4236tree
4043finish_struct (t, list_of_fieldlists, warn_anon)
4044 tree t;
4045 tree list_of_fieldlists;
4237finish_struct (t, list_of_fieldlists, attributes, warn_anon)
4238 tree t, list_of_fieldlists, attributes;
4046 int warn_anon;
4047{
4239 int warn_anon;
4240{
4048 tree fields = NULL_TREE, fn_fields, *tail;
4049 tree *tail_user_methods = &CLASSTYPE_METHODS (t);
4241 tree fields = NULL_TREE;
4242 tree *tail = &TYPE_METHODS (t);
4243 tree specializations = NULL_TREE;
4244 tree *specialization_tail = &specializations;
4050 tree name = TYPE_NAME (t);
4051 tree x, last_x = NULL_TREE;
4245 tree name = TYPE_NAME (t);
4246 tree x, last_x = NULL_TREE;
4052 enum access_type access;
4247 tree access;
4248 tree dummy = NULL_TREE;
4249 tree next_x = NULL_TREE;
4053
4054 if (TREE_CODE (name) == TYPE_DECL)
4055 {
4056 extern int lineno;
4057
4058 DECL_SOURCE_FILE (name) = input_filename;
4059 /* For TYPE_DECL that are not typedefs (those marked with a line
4060 number of zero, we don't want to mark them as real typedefs.

--- 5 unchanged lines hidden (view full) ---

4066 CLASSTYPE_SOURCE_LINE (t) = lineno;
4067 name = DECL_NAME (name);
4068 }
4069
4070 /* Append the fields we need for constructing signature tables. */
4071 if (IS_SIGNATURE (t))
4072 append_signature_fields (list_of_fieldlists);
4073
4250
4251 if (TREE_CODE (name) == TYPE_DECL)
4252 {
4253 extern int lineno;
4254
4255 DECL_SOURCE_FILE (name) = input_filename;
4256 /* For TYPE_DECL that are not typedefs (those marked with a line
4257 number of zero, we don't want to mark them as real typedefs.

--- 5 unchanged lines hidden (view full) ---

4263 CLASSTYPE_SOURCE_LINE (t) = lineno;
4264 name = DECL_NAME (name);
4265 }
4266
4267 /* Append the fields we need for constructing signature tables. */
4268 if (IS_SIGNATURE (t))
4269 append_signature_fields (list_of_fieldlists);
4270
4074 tail = &fn_fields;
4075 if (last_x && list_of_fieldlists)
4076 TREE_CHAIN (last_x) = TREE_VALUE (list_of_fieldlists);
4077
4078 /* For signatures, we made all methods `public' in the parser and
4079 reported an error if a access specifier was used. */
4080 if (CLASSTYPE_DECLARED_CLASS (t) == 0)
4271 /* Move our self-reference declaration to the end of the field list so
4272 any real field with the same name takes precedence. */
4273 if (list_of_fieldlists
4274 && TREE_VALUE (list_of_fieldlists)
4275 && DECL_ARTIFICIAL (TREE_VALUE (list_of_fieldlists)))
4081 {
4276 {
4082 if (list_of_fieldlists
4083 && TREE_PURPOSE (list_of_fieldlists) == (tree)access_default)
4084 TREE_PURPOSE (list_of_fieldlists) = (tree)access_public;
4277 dummy = TREE_VALUE (list_of_fieldlists);
4278 list_of_fieldlists = TREE_CHAIN (list_of_fieldlists);
4085 }
4279 }
4086 else if (list_of_fieldlists
4087 && TREE_PURPOSE (list_of_fieldlists) == (tree)access_default)
4088 TREE_PURPOSE (list_of_fieldlists) = (tree)access_private;
4089
4280
4281 if (last_x && list_of_fieldlists)
4282 TREE_CHAIN (last_x) = TREE_VALUE (list_of_fieldlists);
4283
4090 while (list_of_fieldlists)
4091 {
4284 while (list_of_fieldlists)
4285 {
4092 access = (enum access_type)TREE_PURPOSE (list_of_fieldlists);
4286 access = TREE_PURPOSE (list_of_fieldlists);
4093
4287
4094 for (x = TREE_VALUE (list_of_fieldlists); x; x = TREE_CHAIN (x))
4288 /* For signatures, we made all methods `public' in the parser and
4289 reported an error if a access specifier was used. */
4290 if (access == access_default_node)
4095 {
4291 {
4096 TREE_PRIVATE (x) = access == access_private;
4097 TREE_PROTECTED (x) = access == access_protected;
4292 if (CLASSTYPE_DECLARED_CLASS (t) == 0)
4293 access = access_public_node;
4294 else
4295 access = access_private_node;
4296 }
4098
4297
4099 /* Check for inconsistent use of this name in the class body.
4298 for (x = TREE_VALUE (list_of_fieldlists); x; x = next_x)
4299 {
4300 next_x = TREE_CHAIN (x);
4301
4302 TREE_PRIVATE (x) = access == access_private_node;
4303 TREE_PROTECTED (x) = access == access_protected_node;
4304
4305 if (TREE_CODE (x) == TEMPLATE_DECL)
4306 {
4307 TREE_PRIVATE (DECL_RESULT (x)) = TREE_PRIVATE (x);
4308 TREE_PROTECTED (DECL_RESULT (x)) = TREE_PROTECTED (x);
4309 }
4310
4311 /* A name N used in a class S shall refer to the same declaration
4312 in its context and when re-evaluated in the completed scope of S.
4313
4100 Enums, types and static vars have already been checked. */
4314 Enums, types and static vars have already been checked. */
4101 if (TREE_CODE (x) != TYPE_DECL
4315 if (TREE_CODE (x) != TYPE_DECL && TREE_CODE (x) != USING_DECL
4316 && ! (TREE_CODE (x) == TEMPLATE_DECL
4317 && TREE_CODE (DECL_RESULT (x)) == TYPE_DECL)
4102 && TREE_CODE (x) != CONST_DECL && TREE_CODE (x) != VAR_DECL)
4103 {
4104 tree name = DECL_NAME (x);
4105 tree icv;
4106
4107 /* Don't get confused by access decls. */
4108 if (name && TREE_CODE (name) == IDENTIFIER_NODE)
4109 icv = IDENTIFIER_CLASS_VALUE (name);
4110 else
4111 icv = NULL_TREE;
4112
4113 if (icv
4318 && TREE_CODE (x) != CONST_DECL && TREE_CODE (x) != VAR_DECL)
4319 {
4320 tree name = DECL_NAME (x);
4321 tree icv;
4322
4323 /* Don't get confused by access decls. */
4324 if (name && TREE_CODE (name) == IDENTIFIER_NODE)
4325 icv = IDENTIFIER_CLASS_VALUE (name);
4326 else
4327 icv = NULL_TREE;
4328
4329 if (icv
4330 && flag_optional_diags
4114 /* Don't complain about constructors. */
4115 && name != constructor_name (current_class_type)
4116 /* Or inherited names. */
4117 && id_in_current_class (name)
4118 /* Or shadowed tags. */
4119 && !(TREE_CODE (icv) == TYPE_DECL
4120 && DECL_CONTEXT (icv) == t))
4121 {
4331 /* Don't complain about constructors. */
4332 && name != constructor_name (current_class_type)
4333 /* Or inherited names. */
4334 && id_in_current_class (name)
4335 /* Or shadowed tags. */
4336 && !(TREE_CODE (icv) == TYPE_DECL
4337 && DECL_CONTEXT (icv) == t))
4338 {
4122 cp_error_at ("declaration of identifier `%D' as `%+#D'",
4123 name, x);
4124 cp_error_at ("conflicts with other use in class as `%#D'",
4125 icv);
4339 cp_pedwarn_at ("declaration of identifier `%D' as `%+#D'",
4340 name, x);
4341 cp_pedwarn_at ("conflicts with other use in class as `%#D'",
4342 icv);
4126 }
4127 }
4128
4343 }
4344 }
4345
4129 if (TREE_CODE (x) == FUNCTION_DECL)
4346 if (TREE_CODE (x) == FUNCTION_DECL
4347 || DECL_FUNCTION_TEMPLATE_P (x))
4130 {
4348 {
4349 DECL_CLASS_CONTEXT (x) = t;
4350
4131 if (last_x)
4351 if (last_x)
4132 TREE_CHAIN (last_x) = TREE_CHAIN (x);
4133 /* Link x onto end of fn_fields and CLASSTYPE_METHODS. */
4352 TREE_CHAIN (last_x) = next_x;
4353
4354 if (DECL_TEMPLATE_SPECIALIZATION (x))
4355 /* We don't enter the specialization into the class
4356 method vector since specializations don't affect
4357 overloading. Instead we keep track of the
4358 specializations, and process them after the method
4359 vector is complete. */
4360 {
4361 *specialization_tail = x;
4362 specialization_tail = &TREE_CHAIN (x);
4363 TREE_CHAIN (x) = NULL_TREE;
4364 continue;
4365 }
4366
4367 /* Link x onto end of TYPE_METHODS. */
4134 *tail = x;
4135 tail = &TREE_CHAIN (x);
4368 *tail = x;
4369 tail = &TREE_CHAIN (x);
4136 *tail_user_methods = x;
4137 tail_user_methods = &DECL_NEXT_METHOD (x);
4138 continue;
4139 }
4140
4370 continue;
4371 }
4372
4141#if 0
4142 /* Handle access declarations. */
4143 if (DECL_NAME (x) && TREE_CODE (DECL_NAME (x)) == SCOPE_REF)
4144 {
4145 tree n = DECL_NAME (x);
4146 x = build_decl
4147 (USING_DECL, DECL_NAME (TREE_OPERAND (n, 1)), TREE_TYPE (x));
4148 DECL_RESULT (x) = n;
4149 }
4150#endif
4373 if (TREE_CODE (x) != TYPE_DECL)
4374 DECL_FIELD_CONTEXT (x) = t;
4151
4152 if (! fields)
4153 fields = x;
4154 last_x = x;
4155 }
4156 list_of_fieldlists = TREE_CHAIN (list_of_fieldlists);
4157 /* link the tail while we have it! */
4158 if (last_x)
4159 {
4160 TREE_CHAIN (last_x) = NULL_TREE;
4161
4162 if (list_of_fieldlists
4163 && TREE_VALUE (list_of_fieldlists)
4164 && TREE_CODE (TREE_VALUE (list_of_fieldlists)) != FUNCTION_DECL)
4165 TREE_CHAIN (last_x) = TREE_VALUE (list_of_fieldlists);
4166 }
4167 }
4168
4375
4376 if (! fields)
4377 fields = x;
4378 last_x = x;
4379 }
4380 list_of_fieldlists = TREE_CHAIN (list_of_fieldlists);
4381 /* link the tail while we have it! */
4382 if (last_x)
4383 {
4384 TREE_CHAIN (last_x) = NULL_TREE;
4385
4386 if (list_of_fieldlists
4387 && TREE_VALUE (list_of_fieldlists)
4388 && TREE_CODE (TREE_VALUE (list_of_fieldlists)) != FUNCTION_DECL)
4389 TREE_CHAIN (last_x) = TREE_VALUE (list_of_fieldlists);
4390 }
4391 }
4392
4393 /* Now add the tags, if any, to the list of TYPE_DECLs
4394 defined for this type. */
4395 if (CLASSTYPE_TAGS (t) || dummy)
4396 {
4397 /* The list of tags was built up in pushtag in reverse order; we need
4398 to fix that so that enumerators will be processed in forward order
4399 in template instantiation. */
4400 CLASSTYPE_TAGS (t) = x = nreverse (CLASSTYPE_TAGS (t));
4401 while (x)
4402 {
4403 tree tag_type = TREE_VALUE (x);
4404 tree tag = TYPE_MAIN_DECL (TREE_VALUE (x));
4405
4406 if (IS_AGGR_TYPE_CODE (TREE_CODE (tag_type))
4407 && CLASSTYPE_IS_TEMPLATE (tag_type))
4408 tag = CLASSTYPE_TI_TEMPLATE (tag_type);
4409
4410 TREE_NONLOCAL_FLAG (tag_type) = 0;
4411 x = TREE_CHAIN (x);
4412 last_x = chainon (last_x, tag);
4413 }
4414 if (dummy)
4415 last_x = chainon (last_x, dummy);
4416 if (fields == NULL_TREE)
4417 fields = last_x;
4418 CLASSTYPE_LOCAL_TYPEDECLS (t) = 1;
4419 }
4420
4169 *tail = NULL_TREE;
4421 *tail = NULL_TREE;
4170 *tail_user_methods = NULL_TREE;
4171 TYPE_FIELDS (t) = fields;
4172
4422 TYPE_FIELDS (t) = fields;
4423
4173 if (0 && processing_template_defn)
4424 cplus_decl_attributes (t, attributes, NULL_TREE);
4425
4426 if (processing_template_decl)
4174 {
4427 {
4175 CLASSTYPE_METHOD_VEC (t) = finish_struct_methods (t, fn_fields, 1);
4176 return t;
4428 tree d = getdecls ();
4429 for (; d; d = TREE_CHAIN (d))
4430 {
4431 /* If this is the decl for the class or one of the template
4432 parms, we've seen all the injected decls. */
4433 if ((TREE_CODE (d) == TYPE_DECL
4434 && (TREE_TYPE (d) == t
4435 || TREE_CODE (TREE_TYPE (d)) == TEMPLATE_TYPE_PARM
4436 || TREE_CODE (TREE_TYPE (d)) == TEMPLATE_TEMPLATE_PARM))
4437 || TREE_CODE (d) == CONST_DECL)
4438 break;
4439 /* Don't inject cache decls. */
4440 else if (IDENTIFIER_TEMPLATE (DECL_NAME (d)))
4441 continue;
4442 DECL_TEMPLATE_INJECT (CLASSTYPE_TI_TEMPLATE (t))
4443 = tree_cons (NULL_TREE, d,
4444 DECL_TEMPLATE_INJECT (CLASSTYPE_TI_TEMPLATE (t)));
4445 }
4446 CLASSTYPE_METHOD_VEC (t)
4447 = finish_struct_methods (t, TYPE_METHODS (t), 1);
4448 TYPE_SIZE (t) = integer_zero_node;
4449 }
4450 else
4451 t = finish_struct_1 (t, warn_anon);
4452
4453 TYPE_BEING_DEFINED (t) = 0;
4454
4455 /* Now, figure out which member templates we're specializing. */
4456 for (x = specializations; x != NULL_TREE; x = TREE_CHAIN (x))
4457 {
4458 tree spec_args;
4459 tree fn;
4460 int pending_specialization;
4461
4462 if (uses_template_parms (t))
4463 /* If t is a template class, and x is a specialization, then x
4464 is itself really a template. Due to the vagaries of the
4465 parser, however, we will have a handle to a function
4466 declaration, rather than the template declaration, at this
4467 point. */
4468 {
4469 my_friendly_assert (DECL_TEMPLATE_INFO (x) != NULL_TREE, 0);
4470 my_friendly_assert (DECL_TI_TEMPLATE (x) != NULL_TREE, 0);
4471 fn = DECL_TI_TEMPLATE (x);
4472 }
4473 else
4474 fn = x;
4475
4476 /* We want the specialization arguments, which will be the
4477 innermost ones. */
4478 if (DECL_TI_ARGS (fn) && TREE_CODE (DECL_TI_ARGS (fn)) == TREE_VEC)
4479 spec_args
4480 = TREE_VEC_ELT (DECL_TI_ARGS (fn), 0);
4481 else
4482 spec_args = DECL_TI_ARGS (fn);
4483
4484 pending_specialization
4485 = TI_PENDING_SPECIALIZATION_FLAG (DECL_TEMPLATE_INFO (fn));
4486 check_explicit_specialization
4487 (lookup_template_function (DECL_NAME (fn), spec_args),
4488 fn, 0, 1 | (8 * pending_specialization));
4489 TI_PENDING_SPECIALIZATION_FLAG (DECL_TEMPLATE_INFO (fn)) = 0;
4490
4491 /* Now, the assembler name will be correct for fn, so we
4492 make its RTL. */
4493 DECL_RTL (fn) = 0;
4494 make_decl_rtl (fn, NULL_PTR, 1);
4495
4496 if (x != fn)
4497 {
4498 DECL_RTL (x) = 0;
4499 make_decl_rtl (x, NULL_PTR, 1);
4500 }
4177 }
4501 }
4502
4503 if (current_class_type)
4504 popclass (0);
4178 else
4505 else
4179 return finish_struct_1 (t, warn_anon);
4506 error ("trying to finish struct, but kicked out due to previous parse errors.");
4507
4508 return t;
4180}
4181
4182/* Return non-zero if the effective type of INSTANCE is static.
4183 Used to determine whether the virtual function table is needed
4184 or not.
4185
4186 *NONNULL is set iff INSTANCE can be known to be nonnull, regardless
4187 of our knowledge of its type. */
4509}
4510
4511/* Return non-zero if the effective type of INSTANCE is static.
4512 Used to determine whether the virtual function table is needed
4513 or not.
4514
4515 *NONNULL is set iff INSTANCE can be known to be nonnull, regardless
4516 of our knowledge of its type. */
4517
4188int
4189resolves_to_fixed_type_p (instance, nonnull)
4190 tree instance;
4191 int *nonnull;
4192{
4193 switch (TREE_CODE (instance))
4194 {
4195 case INDIRECT_REF:

--- 18 unchanged lines hidden (view full) ---

4214 {
4215 if (nonnull)
4216 *nonnull = 1;
4217 return 1;
4218 }
4219 return resolves_to_fixed_type_p (TREE_OPERAND (instance, 0), nonnull);
4220
4221 case RTL_EXPR:
4518int
4519resolves_to_fixed_type_p (instance, nonnull)
4520 tree instance;
4521 int *nonnull;
4522{
4523 switch (TREE_CODE (instance))
4524 {
4525 case INDIRECT_REF:

--- 18 unchanged lines hidden (view full) ---

4544 {
4545 if (nonnull)
4546 *nonnull = 1;
4547 return 1;
4548 }
4549 return resolves_to_fixed_type_p (TREE_OPERAND (instance, 0), nonnull);
4550
4551 case RTL_EXPR:
4222 /* This is a call to `new', hence it's never zero. */
4223 if (TREE_CALLS_NEW (instance))
4224 {
4225 if (nonnull)
4226 *nonnull = 1;
4227 return 1;
4228 }
4229 return 0;
4230
4231 case PLUS_EXPR:
4232 case MINUS_EXPR:
4233 if (TREE_CODE (TREE_OPERAND (instance, 1)) == INTEGER_CST)
4234 /* Propagate nonnull. */
4235 resolves_to_fixed_type_p (TREE_OPERAND (instance, 0), nonnull);
4236 if (TREE_CODE (TREE_OPERAND (instance, 0)) == ADDR_EXPR)

--- 7 unchanged lines hidden (view full) ---

4244 case ADDR_EXPR:
4245 if (nonnull)
4246 *nonnull = 1;
4247 return resolves_to_fixed_type_p (TREE_OPERAND (instance, 0), nonnull);
4248
4249 case COMPONENT_REF:
4250 return resolves_to_fixed_type_p (TREE_OPERAND (instance, 1), nonnull);
4251
4552 return 0;
4553
4554 case PLUS_EXPR:
4555 case MINUS_EXPR:
4556 if (TREE_CODE (TREE_OPERAND (instance, 1)) == INTEGER_CST)
4557 /* Propagate nonnull. */
4558 resolves_to_fixed_type_p (TREE_OPERAND (instance, 0), nonnull);
4559 if (TREE_CODE (TREE_OPERAND (instance, 0)) == ADDR_EXPR)

--- 7 unchanged lines hidden (view full) ---

4567 case ADDR_EXPR:
4568 if (nonnull)
4569 *nonnull = 1;
4570 return resolves_to_fixed_type_p (TREE_OPERAND (instance, 0), nonnull);
4571
4572 case COMPONENT_REF:
4573 return resolves_to_fixed_type_p (TREE_OPERAND (instance, 1), nonnull);
4574
4252 case WITH_CLEANUP_EXPR:
4253 if (TREE_CODE (TREE_OPERAND (instance, 0)) == ADDR_EXPR)
4254 return resolves_to_fixed_type_p (TREE_OPERAND (instance, 0), nonnull);
4255 /* fall through... */
4256 case VAR_DECL:
4257 case FIELD_DECL:
4258 if (TREE_CODE (TREE_TYPE (instance)) == ARRAY_TYPE
4259 && IS_AGGR_TYPE (TREE_TYPE (TREE_TYPE (instance))))
4260 {
4261 if (nonnull)
4262 *nonnull = 1;
4263 return 1;
4264 }
4575 case VAR_DECL:
4576 case FIELD_DECL:
4577 if (TREE_CODE (TREE_TYPE (instance)) == ARRAY_TYPE
4578 && IS_AGGR_TYPE (TREE_TYPE (TREE_TYPE (instance))))
4579 {
4580 if (nonnull)
4581 *nonnull = 1;
4582 return 1;
4583 }
4265 /* fall through... */
4584 /* fall through... */
4266 case TARGET_EXPR:
4267 case PARM_DECL:
4268 if (IS_AGGR_TYPE (TREE_TYPE (instance)))
4269 {
4270 if (nonnull)
4271 *nonnull = 1;
4272 return 1;
4273 }
4274 else if (nonnull)
4275 {
4585 case TARGET_EXPR:
4586 case PARM_DECL:
4587 if (IS_AGGR_TYPE (TREE_TYPE (instance)))
4588 {
4589 if (nonnull)
4590 *nonnull = 1;
4591 return 1;
4592 }
4593 else if (nonnull)
4594 {
4276 if (instance == current_class_decl
4595 if (instance == current_class_ptr
4277 && flag_this_is_variable <= 0)
4278 {
4279 /* Some people still use `this = 0' inside destructors. */
4280 *nonnull = ! DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (current_function_decl));
4281 /* In a constructor, we know our type. */
4282 if (flag_this_is_variable < 0)
4283 return 1;
4284 }

--- 15 unchanged lines hidden (view full) ---

4300 current_class_stacksize = 10;
4301 current_class_base = (tree *)xmalloc(current_class_stacksize * sizeof (tree));
4302 current_class_stack = current_class_base;
4303
4304 current_lang_stacksize = 10;
4305 current_lang_base = (tree *)xmalloc(current_lang_stacksize * sizeof (tree));
4306 current_lang_stack = current_lang_base;
4307
4596 && flag_this_is_variable <= 0)
4597 {
4598 /* Some people still use `this = 0' inside destructors. */
4599 *nonnull = ! DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (current_function_decl));
4600 /* In a constructor, we know our type. */
4601 if (flag_this_is_variable < 0)
4602 return 1;
4603 }

--- 15 unchanged lines hidden (view full) ---

4619 current_class_stacksize = 10;
4620 current_class_base = (tree *)xmalloc(current_class_stacksize * sizeof (tree));
4621 current_class_stack = current_class_base;
4622
4623 current_lang_stacksize = 10;
4624 current_lang_base = (tree *)xmalloc(current_lang_stacksize * sizeof (tree));
4625 current_lang_stack = current_lang_base;
4626
4627 access_default_node = build_int_2 (0, 0);
4628 access_public_node = build_int_2 (1, 0);
4629 access_protected_node = build_int_2 (2, 0);
4630 access_private_node = build_int_2 (3, 0);
4631 access_default_virtual_node = build_int_2 (4, 0);
4632 access_public_virtual_node = build_int_2 (5, 0);
4633 access_protected_virtual_node = build_int_2 (6, 0);
4634 access_private_virtual_node = build_int_2 (7, 0);
4635
4308 /* Keep these values lying around. */
4636 /* Keep these values lying around. */
4309 the_null_vtable_entry = build_vtable_entry (integer_zero_node, integer_zero_node);
4310 base_layout_decl = build_lang_field_decl (FIELD_DECL, NULL_TREE, error_mark_node);
4311 TREE_TYPE (base_layout_decl) = make_node (RECORD_TYPE);
4312
4313 gcc_obstack_init (&class_obstack);
4314}
4315
4316/* Set current scope to NAME. CODE tells us if this is a
4317 STRUCT, UNION, or ENUM environment.

--- 29 unchanged lines hidden (view full) ---

4347 appears in an ambiguous way, the IDENTIFIER_CLASS_VALUE of
4348 that name becomes `error_mark_node'. */
4349
4350void
4351pushclass (type, modify)
4352 tree type;
4353 int modify;
4354{
4637 base_layout_decl = build_lang_field_decl (FIELD_DECL, NULL_TREE, error_mark_node);
4638 TREE_TYPE (base_layout_decl) = make_node (RECORD_TYPE);
4639
4640 gcc_obstack_init (&class_obstack);
4641}
4642
4643/* Set current scope to NAME. CODE tells us if this is a
4644 STRUCT, UNION, or ENUM environment.

--- 29 unchanged lines hidden (view full) ---

4674 appears in an ambiguous way, the IDENTIFIER_CLASS_VALUE of
4675 that name becomes `error_mark_node'. */
4676
4677void
4678pushclass (type, modify)
4679 tree type;
4680 int modify;
4681{
4682 type = TYPE_MAIN_VARIANT (type);
4355 push_memoized_context (type, modify);
4356
4357 current_class_depth++;
4358 *current_class_stack++ = current_class_name;
4359 *current_class_stack++ = current_class_type;
4360 if (current_class_stack >= current_class_base + current_class_stacksize)
4361 {
4683 push_memoized_context (type, modify);
4684
4685 current_class_depth++;
4686 *current_class_stack++ = current_class_name;
4687 *current_class_stack++ = current_class_type;
4688 if (current_class_stack >= current_class_base + current_class_stacksize)
4689 {
4362 current_class_base =
4363 (tree *)xrealloc (current_class_base,
4364 sizeof (tree) * (current_class_stacksize + 10));
4690 current_class_base
4691 = (tree *)xrealloc (current_class_base,
4692 sizeof (tree) * (current_class_stacksize + 10));
4365 current_class_stack = current_class_base + current_class_stacksize;
4366 current_class_stacksize += 10;
4367 }
4368
4369 current_class_name = TYPE_NAME (type);
4370 if (TREE_CODE (current_class_name) == TYPE_DECL)
4371 current_class_name = DECL_NAME (current_class_name);
4372 current_class_type = type;

--- 4 unchanged lines hidden (view full) ---

4377 {
4378 /* Forcibly remove any old class remnants. */
4379 popclass (-1);
4380 previous_class_type = NULL_TREE;
4381 }
4382
4383 pushlevel_class ();
4384
4693 current_class_stack = current_class_base + current_class_stacksize;
4694 current_class_stacksize += 10;
4695 }
4696
4697 current_class_name = TYPE_NAME (type);
4698 if (TREE_CODE (current_class_name) == TYPE_DECL)
4699 current_class_name = DECL_NAME (current_class_name);
4700 current_class_type = type;

--- 4 unchanged lines hidden (view full) ---

4705 {
4706 /* Forcibly remove any old class remnants. */
4707 popclass (-1);
4708 previous_class_type = NULL_TREE;
4709 }
4710
4711 pushlevel_class ();
4712
4713#if 0
4714 if (CLASSTYPE_TEMPLATE_INFO (type))
4715 overload_template_name (type);
4716#endif
4717
4385 if (modify)
4386 {
4387 tree tags;
4388 tree this_fndecl = current_function_decl;
4389
4390 if (current_function_decl
4391 && DECL_CONTEXT (current_function_decl)
4392 && TREE_CODE (DECL_CONTEXT (current_function_decl)) == FUNCTION_DECL)
4393 current_function_decl = DECL_CONTEXT (current_function_decl);
4394 else
4395 current_function_decl = NULL_TREE;
4396
4718 if (modify)
4719 {
4720 tree tags;
4721 tree this_fndecl = current_function_decl;
4722
4723 if (current_function_decl
4724 && DECL_CONTEXT (current_function_decl)
4725 && TREE_CODE (DECL_CONTEXT (current_function_decl)) == FUNCTION_DECL)
4726 current_function_decl = DECL_CONTEXT (current_function_decl);
4727 else
4728 current_function_decl = NULL_TREE;
4729
4397 if (TREE_CODE (type) == UNINSTANTIATED_P_TYPE)
4398 declare_uninstantiated_type_level ();
4399 else if (type != previous_class_type || current_class_depth > 1)
4730 if (type != previous_class_type || current_class_depth > 1)
4400 {
4731 {
4732#ifdef MI_MATRIX
4401 build_mi_matrix (type);
4402 push_class_decls (type);
4403 free_mi_matrix ();
4733 build_mi_matrix (type);
4734 push_class_decls (type);
4735 free_mi_matrix ();
4404 if (current_class_depth == 1)
4405 previous_class_type = type;
4736#else
4737 push_class_decls (type);
4738#endif
4406 }
4407 else
4408 {
4409 tree item;
4410
4411 /* Hooray, we successfully cached; let's just install the
4412 cached class_shadowed list, and walk through it to get the
4413 IDENTIFIER_TYPE_VALUEs correct. */

--- 4 unchanged lines hidden (view full) ---

4418 tree decl = IDENTIFIER_CLASS_VALUE (id);
4419
4420 if (TREE_CODE (decl) == TYPE_DECL)
4421 set_identifier_type_value (id, TREE_TYPE (decl));
4422 }
4423 unuse_fields (type);
4424 }
4425
4739 }
4740 else
4741 {
4742 tree item;
4743
4744 /* Hooray, we successfully cached; let's just install the
4745 cached class_shadowed list, and walk through it to get the
4746 IDENTIFIER_TYPE_VALUEs correct. */

--- 4 unchanged lines hidden (view full) ---

4751 tree decl = IDENTIFIER_CLASS_VALUE (id);
4752
4753 if (TREE_CODE (decl) == TYPE_DECL)
4754 set_identifier_type_value (id, TREE_TYPE (decl));
4755 }
4756 unuse_fields (type);
4757 }
4758
4426 if (IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (type)))
4427 overload_template_name (current_class_name, 0);
4428
4429 for (tags = CLASSTYPE_TAGS (type); tags; tags = TREE_CHAIN (tags))
4430 {
4759 for (tags = CLASSTYPE_TAGS (type); tags; tags = TREE_CHAIN (tags))
4760 {
4431 TREE_NONLOCAL_FLAG (TREE_VALUE (tags)) = 1;
4761 tree tag_type = TREE_VALUE (tags);
4762
4763 TREE_NONLOCAL_FLAG (tag_type) = 1;
4432 if (! TREE_PURPOSE (tags))
4433 continue;
4764 if (! TREE_PURPOSE (tags))
4765 continue;
4434 pushtag (TREE_PURPOSE (tags), TREE_VALUE (tags), 0);
4766 if (! (IS_AGGR_TYPE_CODE (TREE_CODE (tag_type))
4767 && CLASSTYPE_IS_TEMPLATE (tag_type)))
4768 pushtag (TREE_PURPOSE (tags), tag_type, 0);
4769 else
4770 pushdecl_class_level (CLASSTYPE_TI_TEMPLATE (tag_type));
4435 }
4436
4437 current_function_decl = this_fndecl;
4438 }
4771 }
4772
4773 current_function_decl = this_fndecl;
4774 }
4439
4440 if (flag_cadillac)
4441 cadillac_push_class (type);
4442}
4443
4444/* Get out of the current class scope. If we were in a class scope
4445 previously, that is the one popped to. The flag MODIFY tells whether
4446 the current scope declarations needs to be modified as a result of
4447 popping to the previous scope. 0 is used for class definitions. */
4775}
4776
4777/* Get out of the current class scope. If we were in a class scope
4778 previously, that is the one popped to. The flag MODIFY tells whether
4779 the current scope declarations needs to be modified as a result of
4780 popping to the previous scope. 0 is used for class definitions. */
4781
4448void
4449popclass (modify)
4450 int modify;
4451{
4782void
4783popclass (modify)
4784 int modify;
4785{
4452 if (flag_cadillac)
4453 cadillac_pop_class ();
4454
4455 if (modify < 0)
4456 {
4457 /* Back this old class out completely. */
4458 tree tags = CLASSTYPE_TAGS (previous_class_type);
4459 tree t;
4460
4461 /* This code can be seen as a cache miss. When we've cached a
4462 class' scope's bindings and we can't use them, we need to reset

--- 14 unchanged lines hidden (view full) ---

4477 it into IDENTIFIER_CLASS_VALUE. */
4478 tree tags = CLASSTYPE_TAGS (current_class_type);
4479
4480 while (tags)
4481 {
4482 TREE_NONLOCAL_FLAG (TREE_VALUE (tags)) = 0;
4483 tags = TREE_CHAIN (tags);
4484 }
4786 if (modify < 0)
4787 {
4788 /* Back this old class out completely. */
4789 tree tags = CLASSTYPE_TAGS (previous_class_type);
4790 tree t;
4791
4792 /* This code can be seen as a cache miss. When we've cached a
4793 class' scope's bindings and we can't use them, we need to reset

--- 14 unchanged lines hidden (view full) ---

4808 it into IDENTIFIER_CLASS_VALUE. */
4809 tree tags = CLASSTYPE_TAGS (current_class_type);
4810
4811 while (tags)
4812 {
4813 TREE_NONLOCAL_FLAG (TREE_VALUE (tags)) = 0;
4814 tags = TREE_CHAIN (tags);
4815 }
4485 if (IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (current_class_type)))
4486 undo_template_name_overload (current_class_name, 0);
4487 }
4488
4489 /* Force clearing of IDENTIFIER_CLASS_VALUEs after a class definition,
4490 since not all class decls make it there currently. */
4491 poplevel_class (! modify);
4492
4493 /* Since poplevel_class does the popping of class decls nowadays,
4494 this really only frees the obstack used for these decls.
4495 That's why it had to be moved down here. */
4496 if (modify)
4816 }
4817
4818 /* Force clearing of IDENTIFIER_CLASS_VALUEs after a class definition,
4819 since not all class decls make it there currently. */
4820 poplevel_class (! modify);
4821
4822 /* Since poplevel_class does the popping of class decls nowadays,
4823 this really only frees the obstack used for these decls.
4824 That's why it had to be moved down here. */
4825 if (modify)
4497 pop_class_decls (current_class_type);
4826 pop_class_decls ();
4498
4499 current_class_depth--;
4500 current_class_type = *--current_class_stack;
4501 current_class_name = *--current_class_stack;
4502
4503 pop_memoized_context (modify);
4504
4505 ret:
4506 ;
4507}
4508
4827
4828 current_class_depth--;
4829 current_class_type = *--current_class_stack;
4830 current_class_name = *--current_class_stack;
4831
4832 pop_memoized_context (modify);
4833
4834 ret:
4835 ;
4836}
4837
4838/* Returns 1 if current_class_type is either T or a nested type of T. */
4839
4840int
4841currently_open_class (t)
4842 tree t;
4843{
4844 int i;
4845 if (t == current_class_type)
4846 return 1;
4847 for (i = 0; i < current_class_depth; ++i)
4848 if (current_class_stack [-i*2 - 1] == t)
4849 return 1;
4850 return 0;
4851}
4852
4509/* When entering a class scope, all enclosing class scopes' names with
4510 static meaning (static variables, static functions, types and enumerators)
4511 have to be visible. This recursive function calls pushclass for all
4512 enclosing class contexts until global or a local scope is reached.
4513 TYPE is the enclosed class and MODIFY is equivalent with the pushclass
4514 formal of the same name. */
4515
4516void
4517push_nested_class (type, modify)
4518 tree type;
4519 int modify;
4520{
4521 tree context;
4522
4853/* When entering a class scope, all enclosing class scopes' names with
4854 static meaning (static variables, static functions, types and enumerators)
4855 have to be visible. This recursive function calls pushclass for all
4856 enclosing class contexts until global or a local scope is reached.
4857 TYPE is the enclosed class and MODIFY is equivalent with the pushclass
4858 formal of the same name. */
4859
4860void
4861push_nested_class (type, modify)
4862 tree type;
4863 int modify;
4864{
4865 tree context;
4866
4523 if (type == NULL_TREE || type == error_mark_node || ! IS_AGGR_TYPE (type))
4867 my_friendly_assert (!type || TREE_CODE (type) != NAMESPACE_DECL, 980711);
4868
4869 if (type == NULL_TREE || type == error_mark_node || ! IS_AGGR_TYPE (type)
4870 || TREE_CODE (type) == TEMPLATE_TYPE_PARM
4871 || TREE_CODE (type) == TEMPLATE_TEMPLATE_PARM)
4524 return;
4525
4872 return;
4873
4526 context = DECL_CONTEXT (TYPE_NAME (type));
4874 context = DECL_CONTEXT (TYPE_MAIN_DECL (type));
4527
4528 if (context && TREE_CODE (context) == RECORD_TYPE)
4529 push_nested_class (context, 2);
4530 pushclass (type, modify);
4531}
4532
4533/* Undoes a push_nested_class call. MODIFY is passed on to popclass. */
4534
4535void
4536pop_nested_class (modify)
4537 int modify;
4538{
4875
4876 if (context && TREE_CODE (context) == RECORD_TYPE)
4877 push_nested_class (context, 2);
4878 pushclass (type, modify);
4879}
4880
4881/* Undoes a push_nested_class call. MODIFY is passed on to popclass. */
4882
4883void
4884pop_nested_class (modify)
4885 int modify;
4886{
4539 tree context = DECL_CONTEXT (TYPE_NAME (current_class_type));
4887 tree context = DECL_CONTEXT (TYPE_MAIN_DECL (current_class_type));
4540
4541 popclass (modify);
4542 if (context && TREE_CODE (context) == RECORD_TYPE)
4543 pop_nested_class (modify);
4544}
4545
4546/* Set global variables CURRENT_LANG_NAME to appropriate value
4547 so that behavior of name-mangling machinery is correct. */
4548
4549void
4550push_lang_context (name)
4551 tree name;
4552{
4553 *current_lang_stack++ = current_lang_name;
4554 if (current_lang_stack >= current_lang_base + current_lang_stacksize)
4555 {
4888
4889 popclass (modify);
4890 if (context && TREE_CODE (context) == RECORD_TYPE)
4891 pop_nested_class (modify);
4892}
4893
4894/* Set global variables CURRENT_LANG_NAME to appropriate value
4895 so that behavior of name-mangling machinery is correct. */
4896
4897void
4898push_lang_context (name)
4899 tree name;
4900{
4901 *current_lang_stack++ = current_lang_name;
4902 if (current_lang_stack >= current_lang_base + current_lang_stacksize)
4903 {
4556 current_lang_base =
4557 (tree *)xrealloc (current_lang_base,
4558 sizeof (tree) * (current_lang_stacksize + 10));
4904 current_lang_base
4905 = (tree *)xrealloc (current_lang_base,
4906 sizeof (tree) * (current_lang_stacksize + 10));
4559 current_lang_stack = current_lang_base + current_lang_stacksize;
4560 current_lang_stacksize += 10;
4561 }
4562
4907 current_lang_stack = current_lang_base + current_lang_stacksize;
4908 current_lang_stacksize += 10;
4909 }
4910
4563 if (name == lang_name_cplusplus)
4911 if (name == lang_name_cplusplus || name == lang_name_java)
4564 {
4565 strict_prototype = strict_prototypes_lang_cplusplus;
4566 current_lang_name = name;
4567 }
4568 else if (name == lang_name_c)
4569 {
4570 strict_prototype = strict_prototypes_lang_c;
4571 current_lang_name = name;
4572 }
4573 else
4574 error ("language string `\"%s\"' not recognized", IDENTIFIER_POINTER (name));
4912 {
4913 strict_prototype = strict_prototypes_lang_cplusplus;
4914 current_lang_name = name;
4915 }
4916 else if (name == lang_name_c)
4917 {
4918 strict_prototype = strict_prototypes_lang_c;
4919 current_lang_name = name;
4920 }
4921 else
4922 error ("language string `\"%s\"' not recognized", IDENTIFIER_POINTER (name));
4575
4576 if (flag_cadillac)
4577 cadillac_push_lang (name);
4578}
4579
4580/* Get out of the current language scope. */
4923}
4924
4925/* Get out of the current language scope. */
4926
4581void
4582pop_lang_context ()
4583{
4927void
4928pop_lang_context ()
4929{
4584 if (flag_cadillac)
4585 cadillac_pop_lang ();
4586
4587 current_lang_name = *--current_lang_stack;
4930 current_lang_name = *--current_lang_stack;
4588 if (current_lang_name == lang_name_cplusplus)
4931 if (current_lang_name == lang_name_cplusplus
4932 || current_lang_name == lang_name_java)
4589 strict_prototype = strict_prototypes_lang_cplusplus;
4590 else if (current_lang_name == lang_name_c)
4591 strict_prototype = strict_prototypes_lang_c;
4592}
4933 strict_prototype = strict_prototypes_lang_cplusplus;
4934 else if (current_lang_name == lang_name_c)
4935 strict_prototype = strict_prototypes_lang_c;
4936}
4937
4938/* Type instantiation routines. */
4593
4939
4594int
4595root_lang_context_p ()
4940static tree
4941validate_lhs (lhstype, complain)
4942 tree lhstype;
4943 int complain;
4596{
4944{
4597 return current_lang_stack == current_lang_base;
4945 if (TYPE_PTRMEMFUNC_P (lhstype))
4946 lhstype = TYPE_PTRMEMFUNC_FN_TYPE (lhstype);
4947
4948 if (TREE_CODE (lhstype) == POINTER_TYPE)
4949 {
4950 if (TREE_CODE (TREE_TYPE (lhstype)) == FUNCTION_TYPE
4951 || TREE_CODE (TREE_TYPE (lhstype)) == METHOD_TYPE)
4952 lhstype = TREE_TYPE (lhstype);
4953 else
4954 {
4955 if (complain)
4956 error ("invalid type combination for overload");
4957 return error_mark_node;
4958 }
4959 }
4960 return lhstype;
4598}
4961}
4599
4600/* Type instantiation routines. */
4601
4962
4602/* This function will instantiate the type of the expression given
4603 in RHS to match the type of LHSTYPE. If LHSTYPE is NULL_TREE,
4604 or other errors exist, the TREE_TYPE of RHS will be ERROR_MARK_NODE.
4963/* This function will instantiate the type of the expression given in
4964 RHS to match the type of LHSTYPE. If errors exist, then return
4965 error_mark_node. If only complain is COMPLAIN is set. If we are
4966 not complaining, never modify rhs, as overload resolution wants to
4967 try many possible instantiations, in hopes that at least one will
4968 work.
4605
4606 This function is used in build_modify_expr, convert_arguments,
4607 build_c_cast, and compute_conversion_costs. */
4969
4970 This function is used in build_modify_expr, convert_arguments,
4971 build_c_cast, and compute_conversion_costs. */
4972
4608tree
4609instantiate_type (lhstype, rhs, complain)
4610 tree lhstype, rhs;
4611 int complain;
4612{
4973tree
4974instantiate_type (lhstype, rhs, complain)
4975 tree lhstype, rhs;
4976 int complain;
4977{
4978 tree explicit_targs = NULL_TREE;
4979 int template_only = 0;
4980
4613 if (TREE_CODE (lhstype) == UNKNOWN_TYPE)
4614 {
4615 if (complain)
4616 error ("not enough type information");
4617 return error_mark_node;
4618 }
4619
4620 if (TREE_TYPE (rhs) != NULL_TREE && ! (type_unknown_p (rhs)))
4981 if (TREE_CODE (lhstype) == UNKNOWN_TYPE)
4982 {
4983 if (complain)
4984 error ("not enough type information");
4985 return error_mark_node;
4986 }
4987
4988 if (TREE_TYPE (rhs) != NULL_TREE && ! (type_unknown_p (rhs)))
4621 return rhs;
4989 {
4990 if (comptypes (lhstype, TREE_TYPE (rhs), 1))
4991 return rhs;
4992 if (complain)
4993 cp_error ("argument of type `%T' does not match `%T'",
4994 TREE_TYPE (rhs), lhstype);
4995 return error_mark_node;
4996 }
4622
4997
4998 /* We don't overwrite rhs if it is an overloaded function.
4999 Copying it would destroy the tree link. */
5000 if (TREE_CODE (rhs) != OVERLOAD)
5001 rhs = copy_node (rhs);
5002
4623 /* This should really only be used when attempting to distinguish
4624 what sort of a pointer to function we have. For now, any
4625 arithmetic operation which is not supported on pointers
4626 is rejected as an error. */
4627
4628 switch (TREE_CODE (rhs))
4629 {
4630 case TYPE_EXPR:
4631 case CONVERT_EXPR:
4632 case SAVE_EXPR:
4633 case CONSTRUCTOR:
4634 case BUFFER_REF:
4635 my_friendly_abort (177);
4636 return error_mark_node;
4637
4638 case INDIRECT_REF:
4639 case ARRAY_REF:
5003 /* This should really only be used when attempting to distinguish
5004 what sort of a pointer to function we have. For now, any
5005 arithmetic operation which is not supported on pointers
5006 is rejected as an error. */
5007
5008 switch (TREE_CODE (rhs))
5009 {
5010 case TYPE_EXPR:
5011 case CONVERT_EXPR:
5012 case SAVE_EXPR:
5013 case CONSTRUCTOR:
5014 case BUFFER_REF:
5015 my_friendly_abort (177);
5016 return error_mark_node;
5017
5018 case INDIRECT_REF:
5019 case ARRAY_REF:
4640 TREE_TYPE (rhs) = lhstype;
4641 lhstype = build_pointer_type (lhstype);
4642 TREE_OPERAND (rhs, 0)
4643 = instantiate_type (lhstype, TREE_OPERAND (rhs, 0), complain);
4644 if (TREE_OPERAND (rhs, 0) == error_mark_node)
4645 return error_mark_node;
5020 {
5021 tree new_rhs;
4646
5022
4647 return rhs;
5023 new_rhs = instantiate_type (build_pointer_type (lhstype),
5024 TREE_OPERAND (rhs, 0), complain);
5025 if (new_rhs == error_mark_node)
5026 return error_mark_node;
4648
5027
5028 TREE_TYPE (rhs) = lhstype;
5029 TREE_OPERAND (rhs, 0) = new_rhs;
5030 return rhs;
5031 }
5032
4649 case NOP_EXPR:
4650 rhs = copy_node (TREE_OPERAND (rhs, 0));
4651 TREE_TYPE (rhs) = unknown_type_node;
4652 return instantiate_type (lhstype, rhs, complain);
4653
4654 case COMPONENT_REF:
4655 {
4656 tree field = TREE_OPERAND (rhs, 1);

--- 9 unchanged lines hidden (view full) ---

4666 tree base_ptr = build_unary_op (ADDR_EXPR, base, 0);
4667 if (base_ptr == error_mark_node)
4668 return error_mark_node;
4669 base_ptr = convert_pointer_to (DECL_CONTEXT (function), base_ptr);
4670 if (base_ptr == error_mark_node)
4671 return error_mark_node;
4672 return build_vfn_ref (&base_ptr, base, DECL_VINDEX (function));
4673 }
5033 case NOP_EXPR:
5034 rhs = copy_node (TREE_OPERAND (rhs, 0));
5035 TREE_TYPE (rhs) = unknown_type_node;
5036 return instantiate_type (lhstype, rhs, complain);
5037
5038 case COMPONENT_REF:
5039 {
5040 tree field = TREE_OPERAND (rhs, 1);

--- 9 unchanged lines hidden (view full) ---

5050 tree base_ptr = build_unary_op (ADDR_EXPR, base, 0);
5051 if (base_ptr == error_mark_node)
5052 return error_mark_node;
5053 base_ptr = convert_pointer_to (DECL_CONTEXT (function), base_ptr);
5054 if (base_ptr == error_mark_node)
5055 return error_mark_node;
5056 return build_vfn_ref (&base_ptr, base, DECL_VINDEX (function));
5057 }
5058 mark_used (function);
4674 return function;
4675 }
4676
5059 return function;
5060 }
5061
5062 /* I could not trigger this code. MvL */
5063 my_friendly_abort (980326);
5064#if 0
4677 my_friendly_assert (TREE_CODE (field) == FIELD_DECL, 178);
4678 my_friendly_assert (!(TREE_CODE (TREE_TYPE (field)) == FUNCTION_TYPE
4679 || TREE_CODE (TREE_TYPE (field)) == METHOD_TYPE),
4680 179);
4681
4682 TREE_TYPE (rhs) = lhstype;
4683 /* First look for an exact match */
4684
4685 while (field && TREE_TYPE (field) != lhstype)
4686 field = DECL_CHAIN (field);
4687 if (field)
4688 {
4689 TREE_OPERAND (rhs, 1) = field;
5065 my_friendly_assert (TREE_CODE (field) == FIELD_DECL, 178);
5066 my_friendly_assert (!(TREE_CODE (TREE_TYPE (field)) == FUNCTION_TYPE
5067 || TREE_CODE (TREE_TYPE (field)) == METHOD_TYPE),
5068 179);
5069
5070 TREE_TYPE (rhs) = lhstype;
5071 /* First look for an exact match */
5072
5073 while (field && TREE_TYPE (field) != lhstype)
5074 field = DECL_CHAIN (field);
5075 if (field)
5076 {
5077 TREE_OPERAND (rhs, 1) = field;
5078 mark_used (field);
4690 return rhs;
4691 }
4692
4693 /* No exact match found, look for a compatible function. */
4694 field = TREE_OPERAND (rhs, 1);
4695 while (field && ! comptypes (lhstype, TREE_TYPE (field), 0))
4696 field = DECL_CHAIN (field);
4697 if (field)

--- 10 unchanged lines hidden (view full) ---

4708 }
4709 }
4710 else
4711 {
4712 if (complain)
4713 error ("no appropriate overload exists for COMPONENT_REF");
4714 return error_mark_node;
4715 }
5079 return rhs;
5080 }
5081
5082 /* No exact match found, look for a compatible function. */
5083 field = TREE_OPERAND (rhs, 1);
5084 while (field && ! comptypes (lhstype, TREE_TYPE (field), 0))
5085 field = DECL_CHAIN (field);
5086 if (field)

--- 10 unchanged lines hidden (view full) ---

5097 }
5098 }
5099 else
5100 {
5101 if (complain)
5102 error ("no appropriate overload exists for COMPONENT_REF");
5103 return error_mark_node;
5104 }
5105#endif
4716 return rhs;
4717 }
4718
5106 return rhs;
5107 }
5108
4719 case TREE_LIST:
5109 case OFFSET_REF:
5110 /* This can happen if we are forming a pointer-to-member for a
5111 member template. */
5112 rhs = TREE_OPERAND (rhs, 1);
5113 my_friendly_assert (TREE_CODE (rhs) == TEMPLATE_ID_EXPR, 0);
5114
5115 /* Fall through. */
5116
5117 case TEMPLATE_ID_EXPR:
4720 {
5118 {
4721 tree elem, baselink, name;
4722 int globals = overloaded_globals_p (rhs);
5119 explicit_targs = TREE_OPERAND (rhs, 1);
5120 template_only = 1;
5121 rhs = TREE_OPERAND (rhs, 0);
5122 }
5123 /* fall through */
5124 my_friendly_assert (TREE_CODE (rhs) == OVERLOAD, 980401);
4723
5125
4724#if 0 /* obsolete */
4725 /* If there's only one function we know about, return that. */
4726 if (globals > 0 && TREE_CHAIN (rhs) == NULL_TREE)
4727 return TREE_VALUE (rhs);
4728#endif
5126 case OVERLOAD:
5127 {
5128 tree elem, elems;
4729
5129
4730 /* First look for an exact match. Search either overloaded
4731 functions or member functions. May have to undo what
4732 `default_conversion' might do to lhstype. */
5130 /* Check that the LHSTYPE and the RHS are reasonable. */
5131 lhstype = validate_lhs (lhstype, complain);
5132 if (lhstype == error_mark_node)
5133 return lhstype;
4733
5134
4734 if (TYPE_PTRMEMFUNC_P (lhstype))
4735 lhstype = TYPE_PTRMEMFUNC_FN_TYPE (lhstype);
4736
4737 if (TREE_CODE (lhstype) == POINTER_TYPE)
4738 if (TREE_CODE (TREE_TYPE (lhstype)) == FUNCTION_TYPE
4739 || TREE_CODE (TREE_TYPE (lhstype)) == METHOD_TYPE)
4740 lhstype = TREE_TYPE (lhstype);
4741 else
4742 {
4743 if (complain)
4744 error ("invalid type combination for overload");
4745 return error_mark_node;
4746 }
4747
4748 if (TREE_CODE (lhstype) != FUNCTION_TYPE && globals > 0)
5135 if (TREE_CODE (lhstype) != FUNCTION_TYPE
5136 && TREE_CODE (lhstype) != METHOD_TYPE)
4749 {
4750 if (complain)
5137 {
5138 if (complain)
4751 cp_error ("cannot resolve overloaded function `%D' based on non-function type",
4752 TREE_PURPOSE (rhs));
5139 cp_error("cannot resolve overloaded function `%D' "
5140 "based on non-function type",
5141 DECL_NAME (OVL_FUNCTION (rhs)));
4753 return error_mark_node;
4754 }
5142 return error_mark_node;
5143 }
4755
4756 if (globals > 0)
5144
5145 /* Look for an exact match, by searching through the
5146 overloaded functions. */
5147 if (template_only)
5148 /* If we're processing a template-id, only a template
5149 function can match, so we don't look through the
5150 overloaded functions. */
5151 ;
5152 else for (elems = rhs; elems; elems = OVL_CHAIN (elems))
4757 {
5153 {
4758 elem = get_first_fn (rhs);
4759 while (elem)
4760 if (! comptypes (lhstype, TREE_TYPE (elem), 1))
4761 elem = DECL_CHAIN (elem);
4762 else
5154 elem = OVL_FUNCTION (elems);
5155 if (comptypes (lhstype, TREE_TYPE (elem), 1))
5156 {
5157 mark_used (elem);
4763 return elem;
5158 return elem;
5159 }
5160 }
4764
5161
4765 /* No exact match found, look for a compatible template. */
4766 {
4767 tree save_elem = 0;
4768 for (elem = get_first_fn (rhs); elem; elem = DECL_CHAIN (elem))
4769 if (TREE_CODE (elem) == TEMPLATE_DECL)
5162 /* No overloaded function was an exact match. See if we can
5163 instantiate some template to match. */
5164 {
5165 tree save_elem = 0;
5166 elems = rhs;
5167 if (TREE_CODE (elems) == TREE_LIST)
5168 elems = TREE_VALUE (rhs);
5169 for (; elems; elems = OVL_NEXT (elems))
5170 if (TREE_CODE (elem = OVL_CURRENT (elems)) == TEMPLATE_DECL)
5171 {
5172 int n = DECL_NTPARMS (elem);
5173 tree t = make_scratch_vec (n);
5174 int i;
5175 i = type_unification
5176 (DECL_INNERMOST_TEMPLATE_PARMS (elem), t,
5177 TYPE_ARG_TYPES (TREE_TYPE (elem)),
5178 TYPE_ARG_TYPES (lhstype), explicit_targs, DEDUCE_EXACT, 1);
5179 if (i == 0)
4770 {
5180 {
4771 int n = TREE_VEC_LENGTH (DECL_TEMPLATE_PARMS (elem));
4772 tree *t = (tree *) alloca (sizeof (tree) * n);
4773 int i, d = 0;
4774 i = type_unification (DECL_TEMPLATE_PARMS (elem), t,
4775 TYPE_ARG_TYPES (TREE_TYPE (elem)),
4776 TYPE_ARG_TYPES (lhstype), &d, 0);
4777 if (i == 0)
5181 if (save_elem)
4778 {
5182 {
4779 if (save_elem)
4780 {
4781 cp_error ("ambiguous template instantiation converting to `%#T'", lhstype);
4782 return error_mark_node;
4783 }
4784 save_elem = instantiate_template (elem, t);
4785 /* Check the return type. */
4786 if (! comptypes (TREE_TYPE (lhstype),
4787 TREE_TYPE (TREE_TYPE (save_elem)), 1))
4788 save_elem = 0;
5183 cp_error ("ambiguous template instantiation converting to `%#T'", lhstype);
5184 return error_mark_node;
4789 }
5185 }
5186 save_elem = instantiate_template (elem, t);
5187 /* Check the return type. */
5188 if (! comptypes (TREE_TYPE (lhstype),
5189 TREE_TYPE (TREE_TYPE (save_elem)), 1))
5190 save_elem = 0;
4790 }
5191 }
4791 if (save_elem)
4792 return save_elem;
5192 }
5193 if (save_elem)
5194 {
5195 mark_used (save_elem);
5196 return save_elem;
4793 }
5197 }
5198 }
4794
5199
4795 /* No match found, look for a compatible function. */
4796 elem = get_first_fn (rhs);
4797 while (elem && comp_target_types (lhstype,
4798 TREE_TYPE (elem), 1) <= 0)
4799 elem = DECL_CHAIN (elem);
4800 if (elem)
5200 /* There's no exact match, and no templates can be
5201 instantiated to match. The last thing we try is to see if
5202 some ordinary overloaded function is close enough. If
5203 we're only looking for template functions, we don't do
5204 this. */
5205 if (!template_only)
5206 {
5207 for (elems = rhs; elems; elems = OVL_NEXT (elems))
4801 {
5208 {
5209 elem = OVL_CURRENT (elems);
5210 if (comp_target_types (lhstype, TREE_TYPE (elem), 1) > 0)
5211 break;
5212 }
5213 if (elems)
5214 {
4802 tree save_elem = elem;
5215 tree save_elem = elem;
4803 elem = DECL_CHAIN (elem);
4804 while (elem && comp_target_types (lhstype,
4805 TREE_TYPE (elem), 0) <= 0)
4806 elem = DECL_CHAIN (elem);
4807 if (elem)
5216 for (elems = OVL_CHAIN (elems); elems;
5217 elems = OVL_CHAIN (elems))
4808 {
5218 {
5219 elem = OVL_FUNCTION (elems);
5220 if (comp_target_types (lhstype, TREE_TYPE (elem), 0) > 0)
5221 break;
5222 }
5223 if (elems)
5224 {
4809 if (complain)
4810 {
5225 if (complain)
5226 {
4811 cp_error ("cannot resolve overload to target type `%#T'",
4812 lhstype);
4813 cp_error_at (" ambiguity between `%#D'", save_elem);
5227 cp_error
5228 ("cannot resolve overload to target type `%#T'",
5229 lhstype);
5230 cp_error_at (" ambiguity between `%#D'", save_elem);
4814 cp_error_at (" and `%#D', at least", elem);
4815 }
4816 return error_mark_node;
4817 }
5231 cp_error_at (" and `%#D', at least", elem);
5232 }
5233 return error_mark_node;
5234 }
5235 mark_used (save_elem);
4818 return save_elem;
4819 }
5236 return save_elem;
5237 }
4820 if (complain)
4821 {
4822 cp_error ("cannot resolve overload to target type `%#T'",
4823 lhstype);
4824 cp_error (" because no suitable overload of function `%D' exists",
4825 TREE_PURPOSE (rhs));
4826 }
4827 return error_mark_node;
4828 }
4829
5238 }
5239
4830 if (TREE_NONLOCAL_FLAG (rhs))
5240 /* We failed to find a match. */
5241 if (complain)
4831 {
5242 {
4832 /* Got to get it as a baselink. */
4833 rhs = lookup_fnfields (TYPE_BINFO (current_class_type),
4834 TREE_PURPOSE (rhs), 0);
5243 cp_error ("cannot resolve overload to target type `%#T'", lhstype);
5244 cp_error
5245 (" because no suitable overload of function `%D' exists",
5246 DECL_NAME (OVL_FUNCTION (rhs)));
4835 }
5247 }
4836 else
5248 return error_mark_node;
5249 }
5250
5251 case TREE_LIST:
5252 {
5253 tree elem, baselink, name = NULL_TREE;
5254
5255 if (TREE_PURPOSE (rhs) == error_mark_node)
4837 {
5256 {
4838 my_friendly_assert (TREE_CHAIN (rhs) == NULL_TREE, 181);
4839 if (TREE_CODE (TREE_VALUE (rhs)) == TREE_LIST)
4840 rhs = TREE_VALUE (rhs);
4841 my_friendly_assert (TREE_CODE (TREE_VALUE (rhs)) == FUNCTION_DECL,
4842 182);
5257 /* Make sure we don't drop the non-local flag, as the old code
5258 would rely on it. */
5259 int nl = TREE_NONLOCAL_FLAG (rhs);
5260 /* We don't need the type of this node. */
5261 rhs = TREE_VALUE (rhs);
5262 my_friendly_assert (TREE_NONLOCAL_FLAG (rhs) == nl, 980331);
4843 }
4844
5263 }
5264
5265 /* Now we should have a baselink. */
5266 my_friendly_assert (TREE_CODE (TREE_PURPOSE (rhs)) == TREE_VEC,
5267 980331);
5268 /* First look for an exact match. Search member functions.
5269 May have to undo what `default_conversion' might do to
5270 lhstype. */
5271
5272 lhstype = validate_lhs (lhstype, complain);
5273 if (lhstype == error_mark_node)
5274 return lhstype;
5275
5276 my_friendly_assert (TREE_CHAIN (rhs) == NULL_TREE, 181);
5277 my_friendly_assert (TREE_CODE (TREE_VALUE (rhs)) == FUNCTION_DECL
5278 || TREE_CODE (TREE_VALUE (rhs)) == OVERLOAD,
5279 182);
5280
4845 for (baselink = rhs; baselink;
4846 baselink = next_baselink (baselink))
4847 {
4848 elem = TREE_VALUE (baselink);
4849 while (elem)
5281 for (baselink = rhs; baselink;
5282 baselink = next_baselink (baselink))
5283 {
5284 elem = TREE_VALUE (baselink);
5285 while (elem)
4850 if (comptypes (lhstype, TREE_TYPE (elem), 1))
4851 return elem;
5286 if (comptypes (lhstype, TREE_TYPE (OVL_CURRENT (elem)), 1))
5287 {
5288 mark_used (OVL_CURRENT (elem));
5289 return OVL_CURRENT (elem);
5290 }
4852 else
5291 else
4853 elem = DECL_CHAIN (elem);
5292 elem = OVL_NEXT (elem);
4854 }
4855
4856 /* No exact match found, look for a compatible method. */
4857 for (baselink = rhs; baselink;
4858 baselink = next_baselink (baselink))
4859 {
4860 elem = TREE_VALUE (baselink);
5293 }
5294
5295 /* No exact match found, look for a compatible method. */
5296 for (baselink = rhs; baselink;
5297 baselink = next_baselink (baselink))
5298 {
5299 elem = TREE_VALUE (baselink);
4861 while (elem && comp_target_types (lhstype,
4862 TREE_TYPE (elem), 1) <= 0)
4863 elem = DECL_CHAIN (elem);
5300 for (; elem; elem = OVL_NEXT (elem))
5301 if (comp_target_types (lhstype,
5302 TREE_TYPE (OVL_CURRENT (elem)), 1) > 0)
5303 break;
4864 if (elem)
4865 {
5304 if (elem)
5305 {
4866 tree save_elem = elem;
4867 elem = DECL_CHAIN (elem);
4868 while (elem && comp_target_types (lhstype,
4869 TREE_TYPE (elem), 0) <= 0)
4870 elem = DECL_CHAIN (elem);
5306 tree save_elem = OVL_CURRENT (elem);
5307 for (elem = OVL_NEXT (elem); elem; elem = OVL_NEXT (elem))
5308 if (comp_target_types (lhstype,
5309 TREE_TYPE (OVL_CURRENT (elem)), 0) > 0)
5310 break;
4871 if (elem)
4872 {
4873 if (complain)
4874 error ("ambiguous overload for overloaded method requested");
4875 return error_mark_node;
4876 }
5311 if (elem)
5312 {
5313 if (complain)
5314 error ("ambiguous overload for overloaded method requested");
5315 return error_mark_node;
5316 }
5317 mark_used (save_elem);
4877 return save_elem;
4878 }
5318 return save_elem;
5319 }
4879 name = DECL_NAME (TREE_VALUE (rhs));
5320 name = rhs;
5321 while (TREE_CODE (name) == TREE_LIST)
5322 name = TREE_VALUE (name);
5323 name = DECL_NAME (OVL_CURRENT (name));
4880#if 0
4881 if (TREE_CODE (lhstype) == FUNCTION_TYPE && globals < 0)
4882 {
4883 /* Try to instantiate from non-member functions. */
4884 rhs = lookup_name_nonclass (name);
4885 if (rhs && TREE_CODE (rhs) == TREE_LIST)
4886 {
4887 /* This code seems to be missing a `return'. */

--- 113 unchanged lines hidden (view full) ---

5001 if (TYPE_PTRMEMFUNC_P (lhstype))
5002 lhstype = TYPE_PTRMEMFUNC_FN_TYPE (lhstype);
5003 else if (TREE_CODE (lhstype) != POINTER_TYPE)
5004 {
5005 if (complain)
5006 error ("type for resolving address of overloaded function must be pointer type");
5007 return error_mark_node;
5008 }
5324#if 0
5325 if (TREE_CODE (lhstype) == FUNCTION_TYPE && globals < 0)
5326 {
5327 /* Try to instantiate from non-member functions. */
5328 rhs = lookup_name_nonclass (name);
5329 if (rhs && TREE_CODE (rhs) == TREE_LIST)
5330 {
5331 /* This code seems to be missing a `return'. */

--- 113 unchanged lines hidden (view full) ---

5445 if (TYPE_PTRMEMFUNC_P (lhstype))
5446 lhstype = TYPE_PTRMEMFUNC_FN_TYPE (lhstype);
5447 else if (TREE_CODE (lhstype) != POINTER_TYPE)
5448 {
5449 if (complain)
5450 error ("type for resolving address of overloaded function must be pointer type");
5451 return error_mark_node;
5452 }
5009 TREE_TYPE (rhs) = lhstype;
5010 lhstype = TREE_TYPE (lhstype);
5011 {
5453 {
5012 tree fn = instantiate_type (lhstype, TREE_OPERAND (rhs, 0), complain);
5454 tree fn = instantiate_type (TREE_TYPE (lhstype), TREE_OPERAND (rhs, 0), complain);
5013 if (fn == error_mark_node)
5014 return error_mark_node;
5015 mark_addressable (fn);
5455 if (fn == error_mark_node)
5456 return error_mark_node;
5457 mark_addressable (fn);
5458 TREE_TYPE (rhs) = lhstype;
5016 TREE_OPERAND (rhs, 0) = fn;
5017 TREE_CONSTANT (rhs) = staticp (fn);
5459 TREE_OPERAND (rhs, 0) = fn;
5460 TREE_CONSTANT (rhs) = staticp (fn);
5461 if (TREE_CODE (lhstype) == POINTER_TYPE
5462 && TREE_CODE (TREE_TYPE (lhstype)) == METHOD_TYPE)
5463 {
5464 build_ptrmemfunc_type (lhstype);
5465 rhs = build_ptrmemfunc (lhstype, rhs, 0);
5466 }
5018 }
5019 return rhs;
5020
5021 case ENTRY_VALUE_EXPR:
5022 my_friendly_abort (184);
5023 return error_mark_node;
5024
5025 case ERROR_MARK:

--- 5 unchanged lines hidden (view full) ---

5031 }
5032}
5033
5034/* Return the name of the virtual function pointer field
5035 (as an IDENTIFIER_NODE) for the given TYPE. Note that
5036 this may have to look back through base types to find the
5037 ultimate field name. (For single inheritance, these could
5038 all be the same name. Who knows for multiple inheritance). */
5467 }
5468 return rhs;
5469
5470 case ENTRY_VALUE_EXPR:
5471 my_friendly_abort (184);
5472 return error_mark_node;
5473
5474 case ERROR_MARK:

--- 5 unchanged lines hidden (view full) ---

5480 }
5481}
5482
5483/* Return the name of the virtual function pointer field
5484 (as an IDENTIFIER_NODE) for the given TYPE. Note that
5485 this may have to look back through base types to find the
5486 ultimate field name. (For single inheritance, these could
5487 all be the same name. Who knows for multiple inheritance). */
5488
5039static tree
5040get_vfield_name (type)
5041 tree type;
5042{
5043 tree binfo = TYPE_BINFO (type);
5044 char *buf;
5045
5046 while (BINFO_BASETYPES (binfo)
5047 && TYPE_VIRTUAL_P (BINFO_TYPE (BINFO_BASETYPE (binfo, 0)))
5048 && ! TREE_VIA_VIRTUAL (BINFO_BASETYPE (binfo, 0)))
5049 binfo = BINFO_BASETYPE (binfo, 0);
5050
5051 type = BINFO_TYPE (binfo);
5489static tree
5490get_vfield_name (type)
5491 tree type;
5492{
5493 tree binfo = TYPE_BINFO (type);
5494 char *buf;
5495
5496 while (BINFO_BASETYPES (binfo)
5497 && TYPE_VIRTUAL_P (BINFO_TYPE (BINFO_BASETYPE (binfo, 0)))
5498 && ! TREE_VIA_VIRTUAL (BINFO_BASETYPE (binfo, 0)))
5499 binfo = BINFO_BASETYPE (binfo, 0);
5500
5501 type = BINFO_TYPE (binfo);
5052 buf = (char *)alloca (sizeof (VFIELD_NAME_FORMAT)
5053 + TYPE_NAME_LENGTH (type) + 2);
5502 buf = (char *) alloca (sizeof (VFIELD_NAME_FORMAT)
5503 + TYPE_NAME_LENGTH (type) + 2);
5054 sprintf (buf, VFIELD_NAME_FORMAT, TYPE_NAME_STRING (type));
5055 return get_identifier (buf);
5056}
5057
5058void
5059print_class_statistics ()
5060{
5061#ifdef GATHER_STATISTICS

--- 10 unchanged lines hidden (view full) ---

5072 }
5073#endif
5074}
5075
5076/* Push an obstack which is sufficiently long-lived to hold such class
5077 decls that may be cached in the previous_class_values list. For now, let's
5078 use the permanent obstack, later we may create a dedicated obstack just
5079 for this purpose. The effect is undone by pop_obstacks. */
5504 sprintf (buf, VFIELD_NAME_FORMAT, TYPE_NAME_STRING (type));
5505 return get_identifier (buf);
5506}
5507
5508void
5509print_class_statistics ()
5510{
5511#ifdef GATHER_STATISTICS

--- 10 unchanged lines hidden (view full) ---

5522 }
5523#endif
5524}
5525
5526/* Push an obstack which is sufficiently long-lived to hold such class
5527 decls that may be cached in the previous_class_values list. For now, let's
5528 use the permanent obstack, later we may create a dedicated obstack just
5529 for this purpose. The effect is undone by pop_obstacks. */
5530
5080void
5081maybe_push_cache_obstack ()
5082{
5083 push_obstacks_nochange ();
5084 if (current_class_depth == 1)
5085 current_obstack = &permanent_obstack;
5086}
5531void
5532maybe_push_cache_obstack ()
5533{
5534 push_obstacks_nochange ();
5535 if (current_class_depth == 1)
5536 current_obstack = &permanent_obstack;
5537}
5538
5539/* Build a dummy reference to ourselves so Derived::Base (and A::A) works,
5540 according to [class]:
5541 The class-name is also inserted
5542 into the scope of the class itself. For purposes of access checking,
5543 the inserted class name is treated as if it were a public member name. */
5544
5545tree
5546build_self_reference ()
5547{
5548 tree name = constructor_name (current_class_type);
5549 tree value = build_lang_decl (TYPE_DECL, name, current_class_type);
5550 DECL_NONLOCAL (value) = 1;
5551 DECL_CONTEXT (value) = current_class_type;
5552 DECL_CLASS_CONTEXT (value) = current_class_type;
5553 CLASSTYPE_LOCAL_TYPEDECLS (current_class_type) = 1;
5554 DECL_ARTIFICIAL (value) = 1;
5555
5556 pushdecl_class_level (value);
5557 return value;
5558}
5559
5560/* Returns 1 if TYPE contains only padding bytes. */
5561
5562int
5563is_empty_class (type)
5564 tree type;
5565{
5566 tree t;
5567
5568 if (type == error_mark_node)
5569 return 0;
5570
5571 if (! IS_AGGR_TYPE (type))
5572 return 0;
5573
5574 if (flag_new_abi)
5575 return CLASSTYPE_SIZE (type) == integer_zero_node;
5576
5577 if (TYPE_BINFO_BASETYPES (type))
5578 return 0;
5579 t = TYPE_FIELDS (type);
5580 while (t && TREE_CODE (t) != FIELD_DECL)
5581 t = TREE_CHAIN (t);
5582 return (t == NULL_TREE);
5583}