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