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