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