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